<script> 
var selected;
var submitter = null;
var previousPaymentSelected='';
var singlepayment;
function showHint(str,target_id,id_to_hide,id_to_show,origin_id) {
    if (str.length == 0) { 
        document.getElementById(target_id).innerHTML = "<?php echo TEXT_COUPON_CODE_NEEDED;?>";
        return;
    } else {
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById(target_id).innerHTML = this.responseText;
				//check for a valid resposnse
				    var str = this.responseText;
                    var n = str.indexOf("<?php echo TEXT_COUPON_VALID;?>");
						if(n >=0){ 
						//valid coupon so hide the original field and offer new one
						 document.getElementById(id_to_hide).style.display = "none";
						 document.getElementById(id_to_show).style.display = "";
						  document.getElementById('click_text').innerHTML = "<?PHP echo TEXT_COUPON_CANCEL;?>";
						 
						
						}else{
							
							        var field= document.getElementById(origin_id);
                                     field.value= field.defaultValue;
						}
            }
        }
        xmlhttp.open("GET", "coupon_code_ajax.php?q="+str, true);
        xmlhttp.send();
    }
}
function remove_coupon(key){
	  if (key.length == 0) { 
        return;
    } else {
	    var target_id = "valid_code_"+key;
        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
				var element = document.getElementById(target_id);
				element.parentNode.removeChild(element);
 
            }
        }
        xmlhttp.open("GET", "coupon_code_ajax.php?x="+key, true);
        xmlhttp.send();
    }
}
function submitFunction(cnt) {
   submitter = 1;
   if(document.getElementById("credit")) var disp_coupon=document.getElementById("credit").innerHTML;
   if(!cnt) cnt=0;
   var cc_id="";
   var coupon="";
   var cot_gv='';
   var frm_credit=document.getElementById("credit");
   var frm_credit_result=document.getElementById("credit_result");
   var show_r0=document.getElementById("show_r0");
   var ss=document.getElementById("ss");
   //new code to get value
   var maxBoxes = <?php echo MAX_MULTI_COUPONS;?>;
   
for(i=0;i < maxBoxes;i++) {
         var boxValue = document.getElementById("gv_redeem_code"+i).value;
		 if (boxValue){
           cc_id += boxValue +"%7E";
		   }
}
///end
  // if(document.getElementById("gv_redeem_code")) cc_id=document.getElementById("gv_redeem_code").value;
   if(document.checkout_payment.coupon && document.checkout_payment.coupon.checked) coupon=document.checkout_payment.coupon.value;
   if(document.getElementById("cot_gv")) cot_gv=document.getElementById("cot_gv").value;
   if(!cnt){
     	command="<?php echo tep_href_link(FILENAME_CHECKOUT_CONFIRMATION,'do_action=get_counpon_details','SSL',true,false);?>&gv_redeem_code="+cc_id+"&coupon="+coupon+"&cot_gv=" + cot_gv;
     	do_get_command(command);
     	frm_credit_result.innerHTML="<?php echo '<span class=smalltext> '.TEXT_PROCESSING_COUPON.'</span>';?>";
     	frm_credit_result.style.display='';
     	frm_credit.style.display='none';	
        ss.style.display='';
		if(ss.style.display!='none' && ss.style.innerHTML!=''){
				show_r0.style.display='none';
				ss.style.display='none';
		}
   } 
   //////
   if(cnt==1)  {
   	frm_credit.style.display='';
   	if(document.checkout_payment.coupon)  document.checkout_payment.coupon.checked=false;
   	hide_credit();
   	if(document.getElementById("gv_chk")) document.getElementById("gv_chk").style.display='';
   	frm_credit_result.style.display='none';
   } 
   //////
}
function do_result(result){
  var frm_credit=document.getElementById("credit");
  var frm_credit_result=document.getElementById("credit_result");
  if(document.getElementById("loading_display")) document.getElementById("loading_display").style.display='none';
  if(frm_credit_result && result){
  	if(frm_credit_result) frm_credit_result.innerHTML=result;
  	frm_credit_result.style.display='';
 	if(result.indexOf('Uses Remaining')>0 && result.indexOf('Valid Until')>0) {
 		if(document.getElementById("gv_chk")) document.getElementById("gv_chk").style.display='none';
 		frm_credit.style.display='none';
 	}
 	else  {
 		if(document.getElementById("error_span")){
 			document.getElementById("error_span").style.display='';
 			document.getElementById("error_span").innerHTML=result;
 		} 
 		frm_credit_result.style.display='none';
 		frm_credit.style.display='';	
 	}	
  } 	
}
function selectRowEffect(object, buttonSelect,paymentSelected) {
  if (document.checkout_payment.payment[0]){
  	if (document.checkout_payment.payment[buttonSelect].disabled) return;
  } else {
    if (document.checkout_payment.payment.disabled) return;
  }
  if (!selected) {
    if (document.getElementById) {
      selected = document.getElementById('defaultSelected');
    } else {
      selected = document.all['defaultSelected'];
    }
  }
  if (selected) selected.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected = object;
// one button is not an array
  if (document.checkout_payment.payment[0]) {
    document.checkout_payment.payment[buttonSelect].checked=true;
      payment_value=document.checkout_payment.payment[buttonSelect].value;
  } else {
    document.checkout_payment.payment.checked=true;
  }
  if (previousPaymentSelected==paymentSelected) return;
  
  if (previousPaymentSelected!='' && document.getElementById(previousPaymentSelected)){
  	document.getElementById(previousPaymentSelected).style.display="none";
  }
  if (document.getElementById(paymentSelected)){
  	document.getElementById(paymentSelected).style.display="";
  }
  previousPaymentSelected=paymentSelected;
  
 //hide_credit();
}
function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
  
}
function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}
function hide_credit(){
    var show_r0=document.getElementById("show_r0");
    var ss=document.getElementById("ss");
 	if(document.getElementById("credit")) document.getElementById("credit").style.display="none";
	if(document.getElementById("error_span")) document.getElementById("error_span").innerHTML='';
	if(document.getElementById("credit_result")) document.getElementById("credit_result").style.display='none';
	if(document.checkout_payment.gv_redeem_code) document.checkout_payment.gv_redeem_code.value="";
	if(document.checkout_payment.coupon && document.checkout_payment.coupon.checked){
		if(document.checkout_payment.gv_redeem_amount ){document.checkout_payment.gv_redeem_amount.value ='';}
		if(document.getElementById("credit").style.display=='none' && document.getElementById("credit_result").style.display=='none') {
			document.getElementById("credit").style.display="";	
			show_r0.style.display='';
			//ss.style.display='';
		}else {
			document.getElementById("credit_result").style.display="none";	
			show_r0.style.display='';
			//ss.style.display='';
		}
	} else {location.reload();}
}
function startOver(){
	location.reload();
}
function show_field(xxx){ 
//consider a check here for an empty field
if(document.getElementById('show_r'+xxx))
{
    document.getElementById('show_r'+xxx).style.display='';
}
if(document.getElementById('tick_r'+xxx))
{
    document.getElementById('tick_r'+xxx).style.display='none';
}
}
function showHide(xyz) {
	try{
    var x = document.getElementById(xyz);
    if (x.style.display === 'none') {
        x.style.display = '';
    } else {
        x.style.display = 'none';
    }
	}
	catch(err){};
}
function doStuff(){
showHide('season'); 
showHide('coupon_table');
showHide('credit');
showHide('click_text1');
showHide('click_text2');
if(document.checkout_payment.gv_redeem_amount ){document.checkout_payment.gv_redeem_amount.value ='';}
}
function hideSeason(){
showHide('entry'); 
showHide('choose');
}
//--></script>
<?php echo $payment_modules->javascript_validation(); ?>