<!-- Progress Bar -->
<?php echo $this->progressBar;?>

<!-- Cart Summary -->
<?php echo $this->cartSummary;?>

<!-- Main Page -->

<script type="text/javascript">
var cartItem = null;
// Show an ExtJS alert box when deleting a cart item
function confirmCartDelete(itemName, itemID, isBundle) {

    if(isBundle) {
        var confirmMsg = "<?php echo $this->lang('Are you sure that you wish to remove the item from your cart? <br>Note: The associated domain will also be removed.');?>";
    } else {
        var confirmMsg = "<?php echo $this->lang('Are you sure that you wish to remove the item from your cart?');?>";
    }

    // Set the cart ID globally & show popup
    cartItem = itemID;
    bundleCartItem = isBundle;
    Ext.Msg.show({
       title: itemName,
       msg: confirmMsg,
       buttons: Ext.Msg.YESNO,
       fn: processRemoveResult,
       icon: Ext.MessageBox.QUESTION
    });
}
// Callback function for ExtJS delete popup
function processRemoveResult(btn) {

    // Check if we can remove the item
    if(btn == 'yes') {

        // Callback for recieved
        var received = function (response) {
            window.location='order.php?step=4';
	}

	Ext.Ajax.request({
	   url: 'index.php?fuse=admin&action=deleteCartItem',
	   success: received,
	   failure: received,
	   params: { cartItem: cartItem, bundleCartItem:bundleCartItem }
	});
    }
}

function showHideAddons(productId) {
    var el = document.getElementById('addons-' + productId);
    if ( el.style.display != 'none' ) {
        el.style.display = 'none';
        el.style.visibility = 'hidden';
    } else {
        el.style.display = 'block';
        el.style.visibility = 'visible'
    }

    if ( $('#toggle_addon_text_' + productId).html() == '+' ) {
        $('#toggle_addon_text_' + productId).html('-');
    } else {
        $('#toggle_addon_text_' + productId).html('+');
    }
    return false;
}

// Show popup for Coupon
function applyCoupon(itemID, couponCode) {
    Ext.Msg.prompt('Apply Coupon', '<?php echo $this->lang("Please enter the Coupon Code");?>:', function(btn, text){
    if (btn == 'ok'){
        validateCoupon(text, itemID);
    }
}, null, null, couponCode);
}

// Validate Coupon Code
function validateCoupon(couponCode, itemID) {
    var received = function (response) {
        var data = Ext.util.JSON.decode(response.responseText);
        if(data.error){
            Ext.Msg.show({
               title: '<?php echo $this->lang('Coupon Error');?>',
               msg: data.message,
               buttons: Ext.Msg.OK,
               icon: Ext.MessageBox.WARNING,
               minWidth: '300'
            });
        } else {
            window.location='order.php?step=4';
        }
    }
    Ext.Ajax.request({
       url: 'index.php?fuse=admin&action=validateCoupon',
       success: received,
       failure: received,
       params: { couponCode: couponCode, itemID: itemID }
    });
}
</script>


<script type="text/javascript" src="javascript/jquery.validate.min.js"></script>
<script type="text/javascript" src="javascript/jquery.passwordstrength.js"></script>

<!-- Main Page -->
<script type="text/javascript">

function toggleUsers(type) {
    if(type == 'existing') {
        document.getElementById('newUserFields').style.display = 'none';
        document.getElementById('newUserFields').style.visibility = 'hidden';

        <?php if ( count($this->paymentmethods) == 0 ) { ?>
        document.getElementById('paymentInformation').style.display = 'block';
        document.getElementById('paymentInformation').style.visibility = 'visible';
        <?php } else { ?>
        document.getElementById('paymentInformation').style.display = 'none';
        document.getElementById('paymentInformation').style.visibility = 'hidden';
        <?php } ?>
        document.getElementById('existingUserFields').style.display = 'block';
        document.getElementById('existingUserFields').style.visibility = 'visible';

        document.getElementById('userSelectionExisting').checked = true;
        document.getElementById('userSelectionNew').checked = false;

        allowSubmit = '1';

    } else {
        document.getElementById('newUserFields').style.display = 'block';
        document.getElementById('newUserFields').style.visibility = 'visible';

        document.getElementById('paymentInformation').style.display = 'block';
        document.getElementById('paymentInformation').style.visibility = 'visible';

        document.getElementById('existingUserFields').style.display = 'none';
        document.getElementById('existingUserFields').style.visibility = 'hidden';

        document.getElementById('userSelectionExisting').checked = false;
        document.getElementById('userSelectionNew').checked = true;

        allowSubmit = '0';
    }

    return false;
}

var selectedGateway = '<?php echo @$this->defaultGateway;?>';
function toggleGateway(gatewayName) {

    var el = document.getElementById(selectedGateway+'-extraFields');
    if(el) {
        el.style.display = 'none';
        el.style.visibility = 'hidden';
    }
    var el = document.getElementById(gatewayName+'-extraFields');
    if(el) {
        el.style.display = 'block';
        el.style.visibility = 'visible';
    }
    selectedGateway = gatewayName;
    $('#payment_desc').html(paymentDescs[gatewayName]);
}

function agreeTC() {
	if ($('#submitButton').hasClass('disabled'))
	{
		$('#submitButton').removeClass('disabled');
	}else{
		$('#submitButton').addClass('disabled');
	}
}

// Phone Digit Validation

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    return true;
}
function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

$.validator.addMethod("phone", function(phone_number, element) {
    var phoneNumberDelimiters = "- ext.";
    var validWorldPhoneChars = phoneNumberDelimiters + "+";
    var minDigitsInIPhoneNumber = 10;
    s=stripCharsInBag(phone_number,validWorldPhoneChars);
    return this.optional(element) || isInteger(s) && s.length >= minDigitsInIPhoneNumber;
}, "<?php echo $this->lang("Please enter a valid phone number in the format +#.##########");?>");

// Field Validation
$(document).ready(function(){
    $("#submitForm").validate({
       errorClass: "invalid",
       errorElement: "span",
       rules: {
        password: {
            required: true
            <?php if(isset($this->enforcePassword)){ ?>,
            minlength: <?php echo $this->minPassLength;?>
            <?php } ?>
        },
        password_again: {
            required: true,
            equalTo: "#password"
        },
        recaptcha_response_field: {
            required: true
        }
      },
      messages: {
        password_again: {
                equalTo: "<?php echo $this->lang("Passwords do not match");?>."
        }
     }
    });

    $('#password').keyup(function(){$('#result-password').html(passwordStrength($('#password').val()))})

});

var RecaptchaOptions = {
    theme : 'clean'
 };

var allowSubmit = '<?php echo $this->loggedIn; ?>';
function doSubmitForm() {
	if ($('#submitButton').hasClass('disabled')) return;
    if(allowSubmit == '1') {
        jQuery('#submitForm').unbind('submit').submit();
    } else {
        jQuery('#submitForm').submit();
    }
    return false;
}
var vatVAR = null;
// Function to update the tax information
function updateTax() {
    getTax();

    // Get the country and state information to pass to the view
    var selectedState = document.getElementById(stateVAR).value;
    var selectedCountry = document.getElementById(countryVAR).options[document.getElementById(countryVAR).selectedIndex].value;
    if(document.getElementById(vatVAR)) {
        var selectedVATNumber = document.getElementById(vatVAR).value;
    }

    var received = function (response) {
        $('#taxInformation').html(response.responseText);
    }
    Ext.Ajax.request({
       url: 'order.php?step=updateTax',
       success: received,
       failure: received,
       params: { state: selectedState, country: selectedCountry, vatNumber: selectedVATNumber }
    });
}


function confirmCartCancel() {

    Ext.Msg.show({
       title: "<?php echo $this->lang('Confirm Cancel Order');?>",
       msg: "<?php echo $this->lang('Are you sure that you wish to cancel this order?');?>",
       buttons: Ext.Msg.YESNO,
       fn: processConfirmCancel,
       icon: Ext.MessageBox.QUESTION
    });
}
// Callback function for ExtJS delete popup
function processConfirmCancel(btn) {

	//lets remove the cartitem via ajax
	if (btn=="yes") {
    	$.ajax({
		  url: "order.php?cleanCart=true",
		  context: document.body,
		  success: function(){
		    window.location = '<?php echo $this->cancelOrderURL;?>';
		  }
		});
	}

}
</script>

<div style="margin-right:220px; margin-bottom:20px;">

<form action="order.php?step=4" method="POST">
<h3><?php echo $this->lang("Order Summary");?></h3>
<p class="pagedesc"><?php echo $this->lang("Please review your order and make any necessary adjustments before proceeding to checkout.");?></p>
<table class="ts2" cellspacing="0" style="margin-bottom:0px;">
  <tr style="background:#E8F3F8;">
    <td><strong><?php echo $this->lang('Product');?></strong></td>
    <td></td>
    <td width="150" align="right" style="padding-right:17px;"><strong><?php echo $this->lang('Price');?></strong></td>
  </tr>
<?php if(is_array($this->cartItems)) { ?>
    <?php foreach($this->cartItems AS $item) { ?>
    <tr>
        <td><?php echo $item['groupName'];?> / <?php echo $item['name'];?> <?php if(@$item['titleText']) { echo $item['titleText'];}?>
			<?php if(@$item['isDomain']) { ?><br /> <em> <?php echo htmlentities($item['domainName']); ?> x <?php echo $item['term']; ?> <?php } ?></em>
            <?php if($item['associatedDomain'] != false) { ?><br /> <?php echo htmlentities($item['associatedDomain']);?> <?php } ?>
            <?php if($item['hasAddons']) {?>
                <a style="cursor: pointer;" onclick="showHideAddons('<?php echo $item['cartItemId'];?>');"><br /><span id="toggle_addon_text_<?php echo $item['cartItemId'];?>" style="width:15px;display:block;float:left;">+</span> <?php echo $this->lang('Addons');?></a>
                <div id="addons-<?php echo $item['cartItemId'];?>" style="visibility:hidden; display:none; font-size:smaller;">
                    <?php foreach($item['addons'] AS $addon) { ?>
                        <?php echo $addon['name']; ?><span style="width:15px;display:block;float:left;">-</span> <?php echo$addon['item']; ?><br/>
                    <?php } ?>
                </div>
            <?php } ?>
        </td>
        <td valign="top" align="left"> <?php if(!isset($item['hidden']['delete'])){?><a onclick="confirmCartDelete('<?php echo $item['safeGroupName'];?> / <?php echo $item['safeName'];?>', '<?php echo $item['cartItemId'];?>', '<?php if(isset($item['bundledDomainId'])) { echo $item['bundledDomainId'];}?>');" style="color:#900; cursor: pointer;"><?php echo $this->lang('Remove');?></a> <?php } ?><?php if(@$this->acceptCoupons) { ?><?php if(!isset($item['hidden']['delete'])){?>|<?php }?> <a onclick="applyCoupon('<?php echo $item['cartItemId'];?>', '<?php echo $item['appliedCoupon'];?>');" style="cursor: pointer;"><?php if(@$item['hasCoupon']) { echo $this->lang('Update Coupon'); } else { echo $this->lang('Apply Coupon'); }?></a><?php } ?></td>
        <td valign="top" align="right" style="padding-right:17px">
            <?php if(@$item['newTotal']) {
            		echo '<span style="text-decoration: line-through;color:#999;"> '.$item['totalFormatted'] .'</span> <span style="color:red;">'.$item['newTotal'].'</span>'; }
            	  else {
            	  	echo $item['totalFormatted']; }?><?php
            	  if(isset($item['isProRated']) && $item['isProRated']) {
            	  	echo "*"; } ?><?php
            	  if(@$item['newSetup']) {
            	  	//lets only show a line through the one time fee if the coupon applied and prices are different
            	  	if ($item['setupFormatted']!=$item['newSetup']) {
	            	  	echo '<br/><span style="text-decoration: line-through;"> '.$item['setupFormatted'] .' '.$this->lang('Setup Fee').'</span> <br/> <span style="color:red;">'.$item['newSetup'].' '.$this->lang('Setup Fee').'</span>';
            	  	} else {
	            	  	echo '<br/>'.$this->lang('Setup Fee')." ".$item['newSetup'];
            	  	}
            	  } elseif(@$item['setupFormatted']) {
            	  	echo "<br/> ".$this->lang('Setup Fee')." ".$item['setupFormatted']; } ?>
        </td>
    </tr>
	<?php } ?>

<?php } else {
		//should be redirected to order=0
	}
?>
</table>
</form>

<div style="border:1px solid #DBE6EC;text-align:right;border-top-width:0px;border-left-width:0px;border-right-width:0px; background:#f6f6f6; padding:15px;">
	<div id="taxInformation"></div>
</div>



<h3 style="padding-top:30px;"><?php echo $this->lang("Your Customer Information");?></h3>
<p class="pagedesc"><?php echo $this->lang("Please enter your profile and billing details below to continue.");?></p>


<form name="customerdata" action="order.php?step=process" method="POST" id="submitForm">

<div id="loggedInBox" style="border:1px solid #DBE6EC; margin:20px 0; padding:10px;-moz-border-radius: 5px;-webkit-border-radius: 5px; <?php if(!$this->loggedIn) { ?>visibility:hidden; display:none;<?php } ?>">
<strong><?php echo $this->lang("Logged in as");?> <span id="user-firstName"><?php echo @$this->gUserFirstName; ?></span> <span id="user-lastName"><?php echo @$this->gUserLastName; ?></span></strong>
<br><?php echo $this->lang("If this is not you");?> <a href="index.php?sessionHash=<?php echo $this->gHash;?>&fuse=newedge&action=Logout&redirTo=order.php?step=4" ><?php echo $this->lang("click here to logout!");?></a>

</div>


<div id="loggedOutBox" style="border:1px solid #DBE6EC; margin:20px 0; padding:10px;-moz-border-radius: 5px;-webkit-border-radius: 5px; <?php if($this->loggedIn) { ?>visibility:hidden; display:none;<?php } ?>">

    <?php echo $this->lang("I am a");?>&nbsp;&nbsp;
    <input id="userSelectionNew" type="radio" name="userSelection" value="new" checked onclick="toggleUsers('new');"> <?php echo $this->lang("New Customer");?>&nbsp;&nbsp;
    <input id="userSelectionExisting" type="radio" name="userSelection" value="existing" onclick="toggleUsers('existing');"> <?php echo $this->lang("Existing Customer");?>

</div>


<?php if(@$this->fieldError) { ?>
    <div style='border:1px solid #cdcdcd; background:#ffeded; color:#900; margin-bottom:20px; padding:10px;-moz-border-radius: 5px;-webkit-border-radius: 5px;'><?php echo $this->fieldError;?></div>
<?php } ?>

    <div id="existingUserFields" style="visibility:hidden; display:none;">
        <table class="ts2" cellspacing="0">
            <tr>
              <td class="label" valign="top"><?php echo $this->lang("E-mail Address");?>:</td>
              <td><input type="text" size="40" name="existingEmail"></td>
            </tr>
            <tr>
              <td class="label" valign="top"><?php echo $this->lang("Password");?>:</td>
              <td><input type="password" name="existingPassword"></td>
            </tr>
        </table>
    </div>

<?php if ( count($this->customFields) > 0) { ?>
    <div id="newUserFields" <?php if($this->loggedIn) { ?>style="visibility:hidden; display:none;"<?php } ?>>
        <table class="ts2" cellspacing="0">

            <!-- loop through the custom fields -->
            <?php foreach ($this->customFields as $customField) { ?>
                <tr>
                  <td class="label" valign="top"><?php echo $customField['rowLabel']; ?>:</td>
                  <td>

                      <?php if(@$customField['fieldType'] == 'text') { ?>

                      <input type="text" name='CT_<?php echo @$customField['fieldId'];?>' id='CT_<?php echo @$customField['fieldId'];?>' <?php if(@$customField['fieldSize']){ echo 'size="'.$customField['fieldSize'].'"'; } else { echo'size="25"'; } ?> value="<?php echo htmlentities(@$customField['value']); ?>"  <?php if(@$customField['isRequired']) {echo 'class="required"'; } ?> />

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'email') { ?>

                        <input type="text" name='CT_<?php echo @$customField['fieldId'];?>' id='CT_<?php echo @$customField['fieldId'];?>' size="40" value="<?php echo @$customField['value']; ?>"  class="required email" />

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'phone') { ?>

                        <input type="text" name='CT_<?php echo @$customField['fieldId'];?>' id='CT_<?php echo @$customField['fieldId'];?>' <?php if(@$customField['fieldSize']){ echo 'size="'.$customField['fieldSize'].'"'; } else { echo'size="25"'; } ?> value="<?php echo htmlentities(@$customField['value']); ?>" class="phone <?php if(@$customField['isRequired']) {echo 'required phone'; } ?>" />

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'language') { ?>

                        <select name='CT_<?php echo $customField['fieldId'];?>' id="CT_<?php echo $customField['fieldId'];?>">
                            <?php foreach ($customField['languages'] as $language) { ?>
                                <option value="<?php echo $language['typeLanguageOptionValue']; ?>" <?php echo $language['typeLanguageOptionSelected']; ?> ><?php echo $language['typeLanguageOptionLabel']; ?></option>
                            <?php } // end languages foreach ?>
                        </select>

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'yesno') { ?>

                        <select name='CT_<?php echo $customField['fieldId'];?>' id="CT_<?php echo $customField['fieldId'];?>">
                            <option value="1" <?php echo $customField['yesSelected']; ?> ><?php echo $this->lang("Yes"); ?>&nbsp;</option>
                            <option value="0" <?php echo $customField['noSelected']; ?> ><?php echo $this->lang("No"); ?>&nbsp;</option>
                        </select>

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'organization') { ?>

                        <input type="text" name='CT_<?php echo @$customField['fieldId'];?>' id='CT_<?php echo @$customField['fieldId'];?>' <?php if(@$customField['fieldSize']){ echo 'size="'.$customField['fieldSize'].'"'; } else { echo'size="25"'; } ?> value="<?php echo htmlentities(@$customField['value']); ?>"  <?php if(@$customField['isRequired']) {echo 'class="required"'; } ?> />&nbsp; <input type="checkbox" name="isOrganization" <?php if ($customField['checkedIsOrganization']) { echo "'checked=checked;'"; }?> />

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'date') { ?>

                        <span style="display: inline-block">
                            <input type="hidden" name='CTT_<?php echo $customField['fieldId'];?>' id="CTT_<?php echo $customField['fieldId'];?>" value="<?php echo $customField['typeDateConstant'];?>" />
                            <input type="text" name='CT_<?php echo $customField['fieldId'];?>' id="CT_<?php echo $customField['fieldId'];?>" value="<?php echo htmlentities($customField['value']); ?>" />
                            <script type="text/javascript">
                                $(document).ready(function(){
                                    datefields.push("CT_<?php echo $customField['fieldId'];?>");
                                });
                            </script>
                        </span>

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'textarea') { ?>

                         <textarea name='CT_<?php echo $customField['fieldId'];?>' id="CT_<?php echo $customField['fieldId'];?>" style="display: inline-block; width: 300px; vertical-align: top;" rows ="10" cols='30'></textarea>

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'dropdown') { ?>

                         <select name='CT_<?php echo $customField['fieldId'];?>' id="CT_<?php echo $customField['fieldId'];?>">
                            <?php foreach ($customField['dropdownoptions'] as $dropdown) { ?>
                                <option value="<?php echo $dropdown['typeDropdownOptionValue']; ?>" <?php echo $dropdown['typeDropdownOptionSelected']; ?> ><?php echo $dropdown['typeDropdownOptionLabel']; ?></option>
                            <?php } //end forloop dropdown ?>
                        </select>

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'country') { ?>

                          <script type="text/javascript">
                              countryVAR = 'CT_<?php echo $customField['fieldId'];?>';
                          </script>
                          <select name='CT_<?php echo $customField['fieldId'];?>' id="CT_<?php echo $customField['fieldId'];?>" onChange="updateTax();">
                              <?php echo $customField['countries']; ?>
                          </select>

                      <?php } ?>

                      <?php if(@$customField['fieldType'] == 'state') { ?>
                          <script type="text/javascript">
                              var stateVAR = 'CT_<?php echo $customField['fieldId'];?>';
                          </script>
                          <input type="text" name='CT_<?php echo @$customField['fieldId'];?>' id='CT_<?php echo @$customField['fieldId'];?>' <?php if(@$customField['fieldSize']){ echo 'size="'.$customField['fieldSize'].'"'; } else { echo'size="25"'; } ?> value="<?php echo htmlentities(@$customField['value']); ?>"  <?php if(@$customField['isRequired']) {echo 'class="required"'; } ?> onBlur="updateTax();" />
                      <?php } //isState ?>

                      <?php if(@$customField['fieldType'] == 'vat') { ?>

                          <script type="text/javascript">
                              var vatVAR = 'CT_<?php echo $customField['fieldId'];?>';
                          </script>
                          <input type="text" name='CT_<?php echo @$customField['fieldId'];?>' id='CT_<?php echo @$customField['fieldId'];?>' <?php if(@$customField['fieldSize']){ echo 'size="'.$customField['fieldSize'].'"'; } else { echo'size="25"'; } ?> value="<?php echo htmlentities(@$customField['value']); ?>"  <?php if(@$customField['isRequired']) {echo 'class="required"'; } ?> onBlur="updateTax();" />
                          <span id="vat_country"></span>
                          <span id="vat_valid" style="display:none"><?php echo $this->lang("Valid VAT Number"); ?></span>
                          <span id="vat_invalid" style="display:none"><?php echo $this->lang("Invalid VAT Number"); ?> <a style="cursor:pointer;" href="updateTax();"><?php echo $this->lang("Retry"); ?></a></span>
                          <span id="vat_error" style="display:none"><?php echo $this->lang("Unable to validate at the moment."); ?> <a style="cursor:pointer;" onclick="updateTax();"><?php echo $this->lang("Retry"); ?></a></span>

                      <?php } ?>
                      <?php if(@$customField['fieldType'] == 'password') { ?>

                         <input type="password" name='<?php echo @$customField['fieldId'];?>' id='<?php echo @$customField['fieldId'];?>' <?php if(@$customField['fieldSize']){ echo 'size="'.$customField['fieldSize'].'"'; } else { echo'size="25"'; } ?>  class="<?php echo $customField['validationClass'];?>" />
                         <div style="color:green; padding-top: 2px; padding-left: 2px;" id='result-<?php echo @$customField['fieldId'];?>'></div>
                      <?php } ?>

                      <?php if(@$customField['fieldDescription']) { ?>
                        <br />
                        <span style="font-size:11px; color:#666;"><?php echo @$customField['fieldDescription'];?></span>
                      <?php } ?>

                  </td>

                </tr>
            <?php } //end customField ?>
            <?php if(@$this->showCaptcha) { ?>
                <tr>
                  <td class="label"><?php echo $this->lang('Are you Human?');?></td>
                  <td><?php echo recaptcha_get_html($this->publickey); ?></td>
                </tr>
            <?php } ?>
        </table>
    </div>
<?php } ?>

<div id="paymentInformation" <?php if($this->loggedIn) { ?>style="visibility:hidden; display:none;"<?php } ?>>
<div style="border:2px solid #ddd; background:#f6f6f6; padding:15px; margin:20px 0;-moz-border-radius: 5px;-webkit-border-radius: 5px;">
    <?php if(count($this->paymentmethods) != 0) { ?>
        <?php echo $this->lang("Pay using");?>: <select name="paymentMethod" id="paymentMethod" onchange="toggleGateway(this.options[this.selectedIndex].value);">
            <?php foreach($this->paymentmethods AS $tmpKey => $key) { ?>
                <option id="<?php echo $key['paymentTypeOptionValue'];?>" value="<?php echo $key['paymentTypeOptionValue'];?>" <?php if($key['paymentTypeOptionSelected']) { $descKey = $tmpKey?> selected="selected" <?php } ?>><?php echo $key['paymentTypeOptionLabel'];?></option>
            <?php } ?>
        </select>
        <?php if ( isset($descKey) ) { ?>
        <div id="payment_desc" style="font-size:11px; color:#666;"><?php echo $this->paymentmethods[$descKey]['description']; ?></div>
        <?php } ?>
    <?php } else { ?>
        <strong><?php echo $this->lang('There are no Payment Processors configured!');?></strong>
    <?php } ?>
</div>


<!-- Handle the extra fields for payment processors -->
<?php foreach($this->paymentmethods AS $key) { ?>
    <?php if(@is_array($key['extraFields'])) { ?>
        <input type="hidden" name="<?php echo $key['paymentTypeOptionValue']."_autopayment"?>" value="<?php echo $key['autoPayment'];?>"></input>
        <div id="<?php echo $key['paymentTypeOptionValue'];?>-extraFields" <?php if(!$key['paymentTypeOptionSelected']) {?> style="visibility:hidden; display:none;" <?php } ?>>
            <table class="ts2" cellspacing="0">
             <?php foreach($key['extraFields'] AS $field) { ?>
                <tr>
                  <td class="label"><?php echo $field['fieldTitle'];?></td>
                  <td>
                      <?php if($field['fieldType'] == 'yesno') { ?>

                          <select name="<?php echo $field['fieldName'];?>" <?php if(@$field['fieldDisabled']) {?> disabled <?php } ?>>
                              <option value="1" <?php if($field['fieldValue'] == 1) { ?>selected="selected"<?php } ?>><?php echo $this->lang('Yes');?>&nbsp;</option>
                              <option value="0" <?php if($field['fieldValue'] == 0) { ?>selected="selected"<?php } ?>><?php echo $this->lang('No');?>&nbsp;</option>
                          </select>

                      <?php } elseif($field['fieldType'] == 'text') { ?>

                        <input name="<?php echo $field['fieldName'];?>" type="text" size="<?php echo @$field['fieldSize'];?>" value="<?php echo @$field['fieldValue'];?>" <?php if(@$field['fieldDisabled']) {?> disabled <?php } ?> />

                      <?php } elseif($field['fieldType'] == 'dropdown') { ?>

                          <select name="<?php echo $field['fieldName'];?>" <?php if(@$field['fieldDisabled']) {?> disabled <?php } ?>>
                              <?php foreach($field['fieldValue'] AS $value) { ?>
                                <option value="<?php echo $value['value'];?>" ><?php echo $value['text'];?>&nbsp;</option>
                              <?php } ?>
                          </select>

                      <?php } elseif($field['fieldType'] == 'weaccept') { ?>

                        <?php foreach($field['fieldValue'] AS $weAccept) { ?>
                            <img src="<?php echo $weAccept['img'];?>" id="<?php echo $weAccept['id'];?>" alt="<?php echo $weAccept['alt'];?>">
                        <?php } ?>

                      <?php } ?>

                      <?php if(@$field['fieldDescription']) { ?>
                        <br />
                        <span style="font-size:11px; color:#666;"><?php echo $field['fieldDescription'];?></span>
                      <?php } ?>
                  </td>
                </tr>
             <?php } ?>
            </table>
        </div>

    <?php } ?>
<?php } ?>

</div>

<p>
    <?php if(@$this->termsConditions) { ?>
        <input type="checkbox" onclick="agreeTC();" name="agree" value="1" style="margin-right: 5px;position:relative; left:2px;">
        <?php echo $this->lang('I Agree to the'); ?>
        <?php if($this->termsConditions == '-1') { ?>
            <a href="<?php echo @$this->termsConditionsUrl;?>" target="_blank"><?php echo $this->lang('Terms and Conditions');?></a>
        <?php } else { ?>
            <a onclick="javascript:GB_show('Terms & Conditions','terms',550,700);" href="#"><?php echo $this->lang('Terms and Conditions');?></a>
        <?php } ?>
        <br><br>
    <?php } ?>
<?php if(count($this->paymentmethods) != 0) { ?>

<a style="margin-left:0px;cursor:pointer;" class="button small white <?php if(@$this->termsConditions) { ?>disabled<?php } ?>" onclick="doSubmitForm();"  id="submitButton"> <?php echo $this->lang('Complete Order');?> &raquo; </a>


<?php } ?>
</p>
<div id="terms" style="display:none"><div id="termswrapper"><?php echo @$this->termsConditionsText;?></div></div>
<div class="clear"></div>

    <script type="text/javascript">
        var mainForm,paymentDescs = [];
  		$(document).ready(function() {
			mainForm = document.forms['customerdata'];
	        updateTax();
	        <?php if(@$this->validatingExisting) { ?> toggleUsers('existing'); <?php } ?>
	        <?php foreach($this->paymentmethods as $key) { ?>
	        paymentDescs['<?php echo $key['paymentTypeOptionValue']; ?>'] = '<?php echo $key['description']; ?>';
	        <?php } ?>
	        <?php if ( count($this->paymentmethods) == 1 && @$this->defaultGateway == '' ) { ?>
	        toggleGateway('<?php echo $this->paymentmethods[0]['paymentTypeOptionValue']; ?>');
	        <?php }  ?>
		});
    </script>
</form>
</div>
