<?php
/**
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the GNU General Public License (GPL 3)
 * that is bundled with this package in the file LICENSE.txt
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Payone_Core to newer
 * versions in the future. If you wish to customize Payone_Core for your
 * needs please refer to http://www.payone.de for more information.
 *
 * @category        Payone
 * @package         design_frontend_base_default
 * @subpackage      template
 * @copyright       Copyright (c) 2012 <info@noovias.com> - www.noovias.com
 * @author          Matthias Walter <info@noovias.com>
 * @license         <http://www.gnu.org/licenses/> GNU General Public License (GPL 3)
 * @link            http://www.noovias.com
 */

/** @var $this Payone_Core_Block_Payment_Method_Form_Creditcard */

    $hideCvcTypes = $this->getHideCvcTypes();
    $hideCcTypeSelector = $this->getHideCreditCardSelectorConfig();
    $cvcLength = $this->getCvcLength();

    $code = $this->getMethodCode();
    $iCheckValidation = (int)$this->showCvcInput();
    $payoneCreditCardCheckValidation = $this->getPayoneCreditCardCheckValidation();
    $useCustomerSaveData = $payoneCreditCardCheckValidation == 0 && $this->getPaymentConfig()->getCustomerFormDataSave();
?>
<script type="text/javascript">
    payone.ccTypeAutoRecognition = '<?php echo $this->getCreditCardRecognitionConfig() ?>';
    payone.configActivatedCcTypes = '<?php echo implode(',', $this->getRawCcType()) ?>';
    payone.configCvcLength = JSON.parse('<?php echo json_encode($cvcLength) ?>');
    payone.translatedErrorMessages.ccOwnerErrorMessage = '<?= $this->__('CREDITCARD_INVALID_OWNER_ERROR_MESSAGE') ?>';
</script>
<fieldset class="form-list">
    <?php if($this->getCCRequestType() == 'AJAX') { ?>
        <ul id="payment_form_<?php echo $code ?>" style="display:none">
            <!-- Card owner : -->
            <li>
                <div class="input-box">
                    <label for="<?php echo $code; ?>_cc_owner">
                        <?php echo $this->__('Credit Card Owner'); ?>&nbsp;<span class="required">*</span>
                    </label><br class="clear"/>
                    <input type="text" id="<?php echo $code; ?>_cc_owner"
                           value=""
                           name="payment[cc_owner]" title="<?php echo $this->__('Credit Card Owner'); ?>"
                           class="input-text validate-payone-cc-owner no-submit"
                    />
                </div>
            </li>
            <!-- Credit card type : -->
            <li>
                <div class="input-box">
                    <label for="<?php echo $code; ?>_cc_type"><?php echo $this->__('Credit Card Type'); ?>
                        <span class="required">*</span>
                    </label><br class="clear"/>
                    <?php
                        $creditCardType = $this->getCreditCardType();
                    ?>
                    <select id="<?php echo $code ?>_cc_type_select" name="<?php echo $code ?>_cc_type_select"
                            onchange=" payone.displayCheckCvc(this);payoneChangedCreditCardInfo();" class="no-submit required-entry">
                        <option value=""><?php echo $this->__('--Please Select--') ?></option>
                        <?php
                        foreach ($this->getTypes() as $key => $type) :
                            $selected = '';
                            if($payoneCreditCardCheckValidation == '0' && $creditCardType == $type['code']) {
                                $selected =  'selected="selected"';
                            }
                            ?>
                            <option value="<?php echo $key ?>" <?php echo $selected; ?>>
                                <?php echo $type['name'] ?><span><?php echo $type['fee']; ?></span>
                            </option>
                            <?php endforeach; ?>
                    </select>
                    <input type="hidden" id="<?php echo $code ?>_cc_type" name="payment[cc_type]" value="<?php echo $this->getCreditCardType();?>" class=""/>
                </div>
            </li>
            <!-- Credit card number : -->
            <li>
                <div class="input-box">
                    <label for="<?php echo $code; ?>_cc_number">
                        <?php echo $this->__('Credit Card Number'); ?>&nbsp;<span class="required">*</span>
                    </label><br class="clear"/>
                    <input type="text" id="<?php echo $code; ?>_cc_number"
                           value="<?php if($payoneCreditCardCheckValidation == '0') echo $this->getCreditCardNumberEnc();?>"
                           name="payment[cc_number]" title="<?php echo $this->__('Credit Card Number'); ?>"
                           class="input-text <?php echo ($payoneCreditCardCheckValidation == 0)?'':'validate-cc-number'?> validate-payone-cc-type no-submit"
                           onchange="inputToNumbers(this); payoneChangedCreditCardInfo();"
                           oninput="inputToNumbers(this); payoneChangedCreditCardInfo();"/>
                </div>
            </li>
            <!-- Credit card expiration date : -->
            <li>
                <div class="input-box">
                    <label for="<?php echo $code ?>_expiration">
                        <?php echo $this->__('Expiration Date') ?>&nbsp;<span class="required">*</span>
                    </label><br class="clear"/>

                    <div class="v-fix">
                        <select id="<?php echo $code ?>_cc_expiration_month" name="payment[cc_exp_month]"
                                style="width:140px;"
                                onchange="payoneChangedCreditCardInfo();"
                                class="required-entry no-submit month validate-payone-cc-validity-period ">
                            <?php
                                $creditCardExpireMonth = $this->getCreditCardExpireMonth();
                            ?>
                            <?php foreach ($this->getCcMonths() as $key => $month): ?>
                            <option value="<?php echo $key ? $key : '' ?>"<?php if ($payoneCreditCardCheckValidation == '0' && $key == $creditCardExpireMonth): ?>
                                    selected="selected"<?php endif ?>><?php echo $month ?></option>
                            <?php endforeach ?>
                        </select>
                    </div>
                    <div class="v-fix" style="padding-left:5px;">
                        <select id="<?php echo $code ?>_cc_expiration_year" name="payment[cc_exp_year]"
                                style="width:103px;"
                                onchange="payoneChangedCreditCardInfo();"
                                class="year required-entry no-submit">
                            <?php
                                $creditCardExpireYear = $this->getCreditCardExpireYear();
                            ?>
                            <?php foreach ($this->getCcYears() as $key => $year): ?>
                            <option value="<?php echo $key ? $key : '' ?>"<?php if ($payoneCreditCardCheckValidation == '0' && $key == $creditCardExpireYear): ?>
                                    selected="selected"<?php endif ?>><?php echo $year ?></option>
                            <?php endforeach ?>
                        </select>
                    </div>
                </div>
            </li>
            <!-- Credit card cvc : -->
            <li style="clear:both;">
                <div class="input-box" id="<?php echo $code ?>_cc_cid_div"
                     style="display: none">
                    <label for="<?php echo $code ?>_cc_cid">
                        <?php echo $this->__('Card Verification Number') ?>&nbsp;<span class="required">*</span>
                    </label><br class="clear"/>
                    <input type="text" title="<?php echo $this->__('Card Verification Number') ?>"
                           class="required-entry input-text no-submit" id="<?php echo $code ?>_cc_cid"
                           name="payment[cc_cid]" style="width:3em;"
                           value="<?php echo $this->getCreditCardCid();?>" autocomplete="off" maxlength="4"
                           onchange="inputToNumbers(this)"
                           oninput="inputToNumbers(this)"/>
                    &nbsp;
                    <a href="#" class="cvv-payone-what-is-this"><?php echo $this->__('What is this?') ?></a>

                    <div class="tool-tip" id="payment-tool-tip-payone" style="display:none;">
                        <div class="tool-tip-payone-content">
                            <img src="<?php echo $this->getSkinUrl('images/payone/cvv.gif') ?>" alt="<?php echo Mage::helper('core')->quoteEscape($this->__('Card Verification Number Visual Reference')) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Card Verification Number Visual Reference')) ?>" />
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <input type="hidden" id="payone_pseudocardpan" name="payment[payone_pseudocardpan]" value="<?php echo $this->getPayonePseudocardpan();?>"/>
                <input type="hidden" id="payone_truncatedcardpan" name="payment[cc_number_enc]" value="<?php echo $this->getCreditCardNumberEnc();?>"/>
                <input type="hidden" id="<?php echo $code ?>_config_id" name="payment[payone_config_payment_method_id]"
                       value="<?php echo $this->getPayoneConfigPaymentMethodId();?>"/>
                <input type="hidden" id="<?php echo $code ?>_config" name="payment[payone_config]"
                       value="<?php echo $this->escapeHtml($this->getClientApiConfigAsJson()); ?>" class=""/>
                <input type="hidden" id="<?php echo $code ?>_config_cvc" name="payment[payone_config_cvc]"
                       value="<?php echo $this->escapeHtml($this->getCvcJson()); ?>" class=""/>
                <input type="hidden" id="payone_cc_check_validation" value="<?php echo $iCheckValidation; ?>"/>
                <input type="hidden" id="payone_cc_check_validation_types" value="<?php echo $this->escapeHtml(($hideCvcTypes)); ?>"/>
            </li>
        </ul>
    <?php } else { ?>
        <ul id="payment_form_<?php echo $code ?>" style="display:none">
            <li>
                <div style="display:none" id="payone_creditcard_hosted_error" class="validation-advice">
                    <?php echo $this->__('Please fill in all required fields'); ?>.
                    <?php if ($iCheckValidation == 1) {?>
                        <br />
                        <?php echo $this->__('Please check also CVC length'); ?>.
                    <?php } ?>
                </div>
            </li>
            <!-- Card owner : -->
            <li>
                <div class="input-box">
                    <label for="<?php echo $code; ?>_cc_owner">
                        <?php echo $this->__('Credit Card Owner'); ?>&nbsp;<span class="required">*</span>
                    </label><br class="clear"/>
                    <input type="text" id="<?php echo $code; ?>_cc_owner"
                           value="<?php if ($useCustomerSaveData) { echo $this->getCreditCardOwner(); } ?>"
                           name="payment[cc_owner]" title="<?php echo $this->__('Credit Card Owner'); ?>"
                           class="input-text validate-payone-cc-owner no-submit"
                        <?php if ($useCustomerSaveData && !empty($this->getCreditCardOwner())) { echo 'style="display:none;"'; } ?>
                    />
                </div>

                <?php if ($useCustomerSaveData && !empty($this->getCreditCardOwner())) { ?>
                    <span class="savedCustomerDataField"><?php if($payoneCreditCardCheckValidation == '0') echo $this->getCreditCardOwner();?></span>
                <?php } ?>

            </li>
            <li>
                <div class="input-box">
                    <label for="cardpanInput"><?php echo $this->__('Credit Card Number'); ?>&nbsp;<span class="required">*</span></label>
                    <br class="clear"/>
                    <span class="inputIframe" id="cardpan" <?php if ($useCustomerSaveData) { echo 'style="display:none;"'; } ?>></span>

                    <?php if ($useCustomerSaveData) { ?>
                        <span class="savedCustomerDataField"><?php if($payoneCreditCardCheckValidation == '0') echo $this->getCreditCardNumberEnc();?></span>
                    <?php } ?>

                    <span id="<?php echo $code ?>_cc_type_logo"><img style="display: inline; padding-bottom: 4px" src="" /></span>
                </div>
            </li>
            <li <?php if($hideCcTypeSelector) { echo 'style="display:none;"'; } ?>>
                <?php
                    $savedCreditCardType = $this->getCreditCardType();
                    $selectedCreditCartType = [];
                    foreach ($this->getTypes() as $key => $type) {
                        if ($savedCreditCardType == $type['code']) {
                            $selectedCreditCartType = [
                                'type' => $type['code'],
                                'name' => $type['name']
                            ];
                            break;
                        }
                    }
                ?>

                <div class="input-box">
                    <label for="<?php echo $code; ?>_cc_type">
                        <?php echo $this->__('Credit Card Type'); ?>
                        <span class="required">*</span>
                    </label><br class="clear"/>
                    <select id="<?php echo $code ?>_cc_type_select" name="<?php echo $code ?>_cc_type_select"
                            class="no-submit required-entry" <?php if ($useCustomerSaveData) { echo 'style="display:none;"'; } ?>>
                        <option value=""><?php echo $this->__('--Please Select--') ?></option>
                        <?php foreach ($this->getTypes() as $key => $type) { ?>
                            <?php $selectedCard = isset($selectedCreditCartType['type']) && $selectedCreditCartType['type'] == $type['code']; ?>
                            <option value="<?php echo $key ?>" <?php if ($selectedCard) echo 'selected="selected"'; ?>>
                                <?php echo $type['name'] ?><span><?php echo $type['fee']; ?></span>
                            </option>
                        <?php } ?>
                    </select>

                    <?php if ($useCustomerSaveData) { ?>
                        <span class="savedCustomerDataField"><?php if($payoneCreditCardCheckValidation == '0') echo isset($selectedCreditCartType['name']) ? $selectedCreditCartType['name'] : ''; ?></span>
                    <?php } ?>

                    <input type="hidden" id="<?php echo $code ?>_cc_type" name="payment[cc_type]" value="<?php echo $this->getCreditCardType();?>" class=""/>
                </div>
            </li>
            <li>
                <div class="input-box" id="<?php echo $code ?>_cc_cid_div">
                    <label for="cvcInput"><?php echo $this->__('Card Verification Number') ?>&nbsp;<span class="required">*</span></label><br class="clear"/>
                    <span id="cardcvc2" class="inputIframe" <?php if ($useCustomerSaveData) { echo 'style="display:none;"'; } ?>></span>

                    <?php if ($useCustomerSaveData) { ?>
                        <span class="savedCustomerDataField"><?php if($payoneCreditCardCheckValidation == '0') echo 'XXXXXX'; ?></span>
                    <?php } ?>

                    <a href="#" class="cvv-payone-what-is-this"><?php echo $this->__('What is this?') ?></a>

                    <div class="tool-tip" id="payment-tool-tip-payone" style="display:none;">
                        <div class="tool-tip-payone-content">
                            <img src="<?php echo $this->getSkinUrl('images/payone/cvv.gif') ?>" alt="<?php echo Mage::helper('core')->quoteEscape($this->__('Card Verification Number Visual Reference')) ?>" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Card Verification Number Visual Reference')) ?>" />
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="input-box">
                    <label for="expireInput"><?php echo $this->__('Expiration Date') ?>&nbsp;<span class="required">*</span></label>
                    <br class="clear"/>
                    <span id="expireInput" class="inputIframe" <?php if ($useCustomerSaveData) { echo 'style="display:none;"'; } ?>>
                        <div class="v-fix"><span id="cardexpiremonth"></span></div>
                        <div class="v-fix" style="padding-left:5px;"><span id="cardexpireyear"></span></div>
                    </span>
                    <?php if ($useCustomerSaveData) { ?>
                        <span class="savedCustomerDataField">
                            <?php if($payoneCreditCardCheckValidation == '0') {
                                echo $this->getCreditCardExpireMonth() . '/' . $this->getCreditCardExpireYear();
                            } ?>
                        </span>
                    <?php } ?>
                </div>
            </li>
            <li>
                <div id="errorOutput"></div>
                <input type="hidden" id="<?php echo $code; ?>_cc_number" value=""/>
                <input type="hidden" id="<?php echo $code; ?>_cc_owner" value="<?php if ($useCustomerSaveData) { echo $this->getCreditCardOwner(); } ?>"/>
                <input type="hidden" id="payone_pseudocardpan" name="payment[payone_pseudocardpan]" value="<?php if ($useCustomerSaveData) { echo $this->getPayonePseudocardpan(); } ?>"/>
                <input type="hidden" id="payone_cardexpiredate" name="payment[payone_cardexpiredate]" value="<?php if ($useCustomerSaveData) { echo $this->getCreditCardExpireYear().$this->getCreditCardExpireMonth(); } ?>"/>
                <input type="hidden" id="payone_truncatedcardpan" name="payment[cc_number_enc]" value="<?php if ($useCustomerSaveData) { echo $this->getCreditCardNumberEnc(); } ?>"/>
                <input type="hidden" id="<?php echo $code ?>_config_id" name="payment[payone_config_payment_method_id]"
                       value="<?php echo $this->getPayoneConfigPaymentMethodId();?>"/>
                <input type="hidden" id="<?php echo $code ?>_config" name="payment[payone_config]"
                       value="<?php echo $this->escapeHtml($this->getHostedClientApiConfigAsJson()); ?>" class=""/>
                <input type="hidden" id="<?php echo $code ?>_config_cvc" name="payment[payone_config_cvc]"
                       value="<?php echo $this->escapeHtml($this->getCvcJson()); ?>" class=""/>
                <input type="hidden" id="payone_cc_check_validation" value="<?php echo $useCustomerSaveData ? '0' : '1'; ?>"/>
                <input type="hidden" id="payone_cc_use_cvc" value="<?php echo $iCheckValidation; ?>"/>
                <input type="hidden" id="payone_cc_check_validation_types" value="<?php echo $this->escapeHtml(($hideCvcTypes)); ?>"/>
            </li>
            <?php if ($useCustomerSaveData) { ?>
                <li>
                    <a href="#" class="cc-form-payone-new-data"><?php echo $this->__('New payment data') ?></a>
                </li>
            <?php } ?>
        </ul>
        <script>
            var request, fieldconfig, ccTypeAutoRecognition;
            ccTypeAutoRecognition = payone.ccTypeAutoRecognition;
            supportedCardtypes = payone.getSupportedCardTypes();

            <?php
            $aTranslations = $this->getTranslations();
            $aProcessedKeys = array();
            foreach ($aTranslations as $sVarname => $sValue) {
                // MAGE-468 : Ensure that custom translation are taken in account
                // for languaage not natively supported by payone
                $aLang = explode('.', $sVarname);
                if (count($aLang) >= 4) {
                    $aEntry = array_slice($aLang, 3);
                    for ($i = 0 ; $i <= count($aEntry) - 2 ; $i++) {
                        $FieldName = $aEntry[$i];
                        $sPreKey = join('.', array_slice($aLang, 0, $i + 4));
                        if (!in_array($sPreKey,$aProcessedKeys)) {
                            echo "if ('undefined' === typeof $sPreKey) { $sPreKey = {}; }";
                            $aProcessedKeys[] = $sPreKey;
                        }
                    }
                }
                echo $sVarname." = '".$sValue."';";
            }
            ?>

            fieldconfig = {
                fields: {
                    cardpan: {
                        selector: "cardpan", // put name of your div-container here
                        type: "<?php echo $this->getHostedParam('Number_type'); ?>", // text (default), password, tel
                        size: "<?php echo $this->getHostedParam('Number_count'); ?>",
                        maxlength: "<?php echo $this->getHostedParam('Number_max'); ?>",
                        <?php if($this->getHostedParam('Number_style') == "custom") { ?>
                            style: "<?php echo $this->getHostedParam('Number_css'); ?>",
                        <?php } ?>
                        <?php if($this->getHostedParam('Number_iframe') == "custom") { ?>
                            iframe: {
                                width: "<?php echo $this->getHostedParam('Number_width'); ?>",
                                height: "<?php echo $this->getHostedParam('Number_height'); ?>"
                            }
                        <?php } ?>
                    },
                    cardcvc2: {
                        selector: "cardcvc2", // put name of your div-container here
                        type: "<?php echo $this->getHostedParam('CVC_type'); ?>", // text (default), password, tel
                        size: "<?php echo $this->getHostedParam('CVC_count'); ?>",
                        maxlength: "<?php echo $this->getHostedParam('CVC_max'); ?>",
                        <?php if($this->getHostedParam('CVC_style') == "custom") { ?>
                            style: "<?php echo $this->getHostedParam('CVC_css'); ?>",
                        <?php } ?>
                        <?php if($this->getHostedParam('CVC_iframe') == "custom") { ?>
                            iframe: {
                                width: "<?php echo $this->getHostedParam('CVC_width'); ?>",
                                height: "<?php echo $this->getHostedParam('CVC_height'); ?>"
                            },
                        <?php } ?>
                        <?php if ($iCheckValidation == 1) {?>
                            length: <?php echo json_encode($cvcLength); ?>
                        <?php } ?>
                    },
                    cardexpiremonth: {
                        selector: "cardexpiremonth", // put name of your div-container here
                        type: "<?php echo $this->getHostedParam('Month_type'); ?>",
                        size: "<?php echo $this->getHostedParam('Month_count'); ?>",
                        maxlength: "<?php echo $this->getHostedParam('Month_max'); ?>",
                        <?php if($this->getHostedParam('Month_style') == "custom") { ?>
                            style: "<?php echo $this->getHostedParam('Month_css'); ?>",
                        <?php } ?>
                        <?php if($this->getHostedParam('Month_iframe') == "custom") { ?>
                            iframe: {
                                width: "<?php echo $this->getHostedParam('Month_width'); ?>",
                                height: "<?php echo $this->getHostedParam('Month_height'); ?>"
                            }
                        <?php } ?>
                    },
                    cardexpireyear: {
                        selector: "cardexpireyear", // put name of your div-container here
                        type: "<?php echo $this->getHostedParam('Year_type'); ?>",
                        size: "<?php echo $this->getHostedParam('Year_count'); ?>",
                        maxlength: "<?php echo $this->getHostedParam('Year_max'); ?>",
                        <?php if($this->getHostedParam('Year_style') == "custom") { ?>
                            style: "<?php echo $this->getHostedParam('Year_css'); ?>",
                        <?php } ?>
                        <?php if($this->getHostedParam('Year_iframe') == "custom") { ?>
                            iframe: {
                                width: "<?php echo $this->getHostedParam('Year_width'); ?>",
                                height: "<?php echo $this->getHostedParam('Year_height'); ?>"
                            }
                        <?php } ?>
                    }
                },
                defaultStyle: {
                    input: "<?php echo $this->getHostedParam('Standard_input'); ?>",
                    select: "<?php echo $this->getHostedParam('Standard_selection'); ?>",
                    iframe: {
                        width: "<?php echo $this->getHostedParam('Iframe_width'); ?>",
                        height: "<?php echo $this->getHostedParam('Iframe_height'); ?>"
                    }
                },
                autoCardtypeDetection: {
                    supportedCardtypes: supportedCardtypes,
                    callback: function(detectedCardtype) {
                        detectedCardtype = detectedCardtype.toString();
                        var elementCcType = $('payone_creditcard_cc_type_select');
                        var pattern = '.*_' + detectedCardtype;

                        if (supportedCardtypes.include(detectedCardtype)) {
                            for(i = 0; i < elementCcType.options.length; i++){
                                var value = elementCcType.options[i].value;
                                if (value.match(pattern)) {
                                    elementCcType.value = value;
                                    elementCcType.onchange();

                                    break;
                                }
                            }
                        }
                    },
                    deactivate: (ccTypeAutoRecognition != 1)
                },

                <?php if($this->getHostedParam('Errors_active') == "true") { ?>
                    error: "errorOutput", // area to display error-messages (optional)
                <?php } ?>
                <?php if($this->getTranslationLanguage()) { ?> 
                    language: Payone.ClientApi.Language.<?php echo $this->getTranslationLanguage(); ?> 
                <?php } else { ?>
                    <?php if($this->getHostedParam('Errors_lang') == "de") { ?>
                        language: Payone.ClientApi.Language.de // Language to display error-messages
                    <?php } else { ?>
                        language: Payone.ClientApi.Language.en 
                    <?php } ?>
                <?php } ?>
            };

            var iframes = payone.initHosted(fieldconfig, '<?php echo $code ?>_cc_type_select');
        </script>
    <?php } ?>
    <script>
        function toggleToolTipPayone(event)
        {
            var tooltip = $('payment-tool-tip-payone');
            if(tooltip){
                tooltip.toggle();
            }
            Event.stop(event);
        }

        function switchIframes(event)
        {
            // Update hidden values
            $('payone_pseudocardpan').value = '';
            $('payone_cardexpiredate').value = '';
            $('payone_truncatedcardpan').value = '';
            $('payone_cc_check_validation').value = '1';

            var elementCcType = $('<?php echo $code ?>_cc_type_select');
            if (elementCcType != undefined) {
                elementCcType.value = '';
                updateCcLogo('');
            }

            var elementCcOwner = $('<?php echo $code ?>_cc_owner');

            // Toggle fields visibility
            $$('.savedCustomerDataField').forEach(function(element) {
                element.hide()
            });
            $$('.inputIframe').forEach(function(element) {
                element.show()
            });
            elementCcType.show();
            elementCcOwner.show();

            Event.stop(event);
        }

        $$('.cc-form-payone-new-data').each(function(element){
            Event.observe(element, 'click', switchIframes);
        });
        $$('.cvv-payone-what-is-this').each(function(element){
            Event.observe(element, 'click', toggleToolTipPayone);
        });
        $$('#payment-tool-tip-payone').each(function(element){
            Event.observe(element, 'click', toggleToolTipPayone);
        });
    </script>
</fieldset>