<script language="javascript"><!--
var shipping='<?php echo ($shipping?1:0);?>';
var selected,selected_s,selected_shipping,selected_payment,send_to=0;
var previousPaymentSelected;

function selectRowEffect(object, buttonSelect) {
  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.billing_address.address[0]) {
    document.billing_address.address[buttonSelect].checked=true;
  } else {
    document.billing_address.address.checked=true;
  }
}
function selectRowEffect2(object, buttonSelect) {
  if (!selected_s) {
   		if(document.getElementById)
      		selected_s =  document.getElementById("defaultSelected_s");
		else
      		selected_s =  document.all["defaultSelected_s"];
  }
  if (selected_s) selected_s.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected_s = object;
// one button is not an array
  if (document.shipping_address.address[0]) {
    document.shipping_address.address[buttonSelect].checked=true;
  } else {
    document.shipping_address.address.checked=true;
  }
}
function selectRowEffect_shipping(object, buttonSelect) {
  if (!selected_shipping) {
   		if(document.getElementById)
      		selected_shipping =  document.getElementById("defaultSelected_shipping");
		else
      		selected_shipping =  document.all["defaultSelected_shipping"];
  }
  if (selected_shipping) selected_shipping.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected_shipping = object;
// one button is not an array
  if (document.checkout_shipping.shipping[0]) {
    document.checkout_shipping.shipping[buttonSelect].checked=true;
  } else {
    document.checkout_shipping.shipping.checked=true;
  }
}
function selectRowEffect_payment(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_payment) {
    if (document.getElementById) {
      selected_payment = document.getElementById('defaultSelected_payment');
    } else {
      selected_payment = document.all['defaultSelected_payment'];
    }
  }

  if (selected_payment) selected_payment.className = 'moduleRow';
  object.className = 'moduleRowSelected';
  selected_payment = 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;
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function do_init_action(billto,sendto)
{
	if(shipping=='1')
		send_to=sendto;

	do_bill_edit(billto,'P');
}
function do_bill_edit(add_id,mode)
{
	if(mode=="S")
		current_state_form="shipping_address";
	else
		current_state_form="billing_address";
	var frm=document.forms[current_state_form];
	if(frm.gender)
	{
		if(frm.elements['gender' + add_id])
		{
			if(frm.elements['gender' + add_id].value=="m")
				frm.gender[0].checked=true;
			else
				frm.gender[1].checked=true;
		}
	}
	if(frm.firstname)
		frm.firstname.value=(frm.elements['firstname' + add_id])?frm.elements['firstname' + add_id].value:'';
	if(frm.lastname)
		frm.lastname.value=(frm.elements['lastname' + add_id])?frm.elements['lastname' + add_id].value:'';
	if(frm.company)
		frm.company.value=(frm.elements['company' + add_id])?frm.elements['company' + add_id].value:'';
	if(frm.street_address)
		frm.street_address.value=(frm.elements['street_address' + add_id])?frm.elements['street_address' + add_id].value:'';
	if(frm.suburb)
		frm.suburb.value=(frm.elements['suburb' + add_id])?frm.elements['suburb' + add_id].value:'';
	if(frm.postcode)
		frm.postcode.value=(frm.elements['postcode' + add_id])?frm.elements['postcode' + add_id].value:'';
	if(frm.city)
		frm.city.value=(frm.elements['city' + add_id])?frm.elements['city' + add_id].value:'';
	if(frm.country && frm.elements['country' + add_id])
	{
		for(ik=0;ik<frm.country.options.length;ik++)
			if(frm.country.options[ik].value==frm.elements['country' + add_id].value)
			{
				frm.country.options[ik].selected=true;
				show_state();
				break;
			}
	}
	if(frm.state && frm.elements['state_' + add_id])
	{
		frm.state1.value=frm.elements['state_' + add_id].value;
		for(ik=0;ik<frm.state.options.length;ik++)
			if(frm.state.options[ik].value==frm.elements['state_' + add_id].value)
			{
				frm.state.options[ik].selected=true;
				break;
			}
	}
}
//--></script>
<?php
  include(DIR_WS_INCLUDES.'javascript/http.js');
?>
<script language="javascript">
   var current_state_form="";
   var form = "";
var submitted = false;
var error = false;
var error_message = "";

   function set_form(mode)
   {
		if(mode=="S")
			current_state_form="shipping_address";
		else
			current_state_form="billing_address";
   }
	function show_state(){
		var frm=document.forms[current_state_form];
		var this_=frm.country;
		id=this_.options[this_.selectedIndex].value;
		var qry_str="";
		if(id){
			command="<?php echo tep_href_link(FILENAME_CHECKOUT_SINGLE,'command=show_state','NONSSL',true,false);?>&country_id="+id;
			do_get_command(command);	
		}
	} 
	function do_result(result){
	 if(result!='' && result.substr(result.indexOf('show_state'),10)=='show_state'){
	   result=result.substr(result.indexOf('show_state')+10,result.length);
	   var textArr=new Array();
		var valueArr=new Array();
		splt=result.split("^");
		valueArr=splt[2].split(",");		
		textArr=splt[2].split(",");
		var frm=document.forms[current_state_form];
		var sel=frm.state;
		var sta1=frm.state1;
		if(valueArr.length==1) {
			if(sta1)sta1.style.display="";
			if(sel)sel.style.display="none";
		}else {
			if(sta1) sta1.style.display="none";
			if(sel){
				sel.style.display="";
				sta1.value="";
			}
			optionElement=sel;
			// clear the previous details
			while(optionElement.options.length>0){
				optionElement.remove(optionElement.options.length - 1);
			}
			//create the new details
			for (icnt=0;icnt<textArr.length;icnt++){
			  var option = document.createElement('option');
			  option.text = textArr[icnt];
			  option.value = valueArr[icnt];
			  try {
				optionElement.add(option, null); // standards compliant; doesn't work in IE
			  }
			  catch(ex) {
				optionElement.add(option); // IE only
			  }
			}
		}
		if(send_to>0)
		 {
			do_bill_edit(send_to,'S');
			send_to=0;
		 }
	  }	 
	  //==================
	  submitted = false;
	  if(result!='' && result.substr(0,7)=='command')
	  {
	    command_splt=result.split('{}');
		for(icnt=0;icnt<command_splt.length;icnt++)
		{
			res=command_splt[icnt].split('||');
			switch(res[0])
			{
				case 'billing_address_error':
					do_inf_expand('billing_information',1);
					document.getElementById('billing_address_error_display').style.display="";
					document.getElementById('billing_address_error_display').innerHTML=res[1];
					break;
				case 'billing_address_display':  //right side address display
					document.getElementById('billing_address_display').style.display="";
					document.getElementById('billing_address_display').innerHTML=res[1];
					break;
				case 'show_shipping_address':
					document.getElementById('billing_address_error_display').style.display="none";
					do_inf_expand('billing_information',0);
					do_inf_expand('shipping_information',1);
					break;
				case 'shipping_address_error':
					do_inf_expand('payment_information',1);
					document.getElementById('shipping_address_error_display').style.display="";
					document.getElementById('shipping_address_error_display').innerHTML=res[1];
					break;
				case 'shipping_address_display':  //right side address display
					document.getElementById('shipping_address_display').style.display="";
					document.getElementById('shipping_address_display').innerHTML=res[1];
					break;
				case 'show_shipping_method':
					//document.getElementById('shipping_address_error_display').style.display="";
					do_inf_expand('shipping_information',0);
					do_inf_expand('shipping_method',1);
					break;
				case 'shipping_method_error':
					do_inf_expand('shipping_method',1);
					document.getElementById('shipping_method_error_display').style.display="";
					document.getElementById('shipping_method_error_display').innerHTML=res[1];
					break;
				case 'shipping_method_display':  //right side display
					document.getElementById('shipping_method_display').style.display="";
					document.getElementById('shipping_method_display').innerHTML=res[1];
					break;
				case 'show_payment_method':
					if(document.getElementById('shipping_method_error_display'))
						document.getElementById('shipping_method_error_display').style.display="none";
					do_inf_expand('billing_information',0);
					do_inf_expand('shipping_method',0);
					do_inf_expand('payment_method',1);
					break;
				case 'payment_error':
					do_inf_expand('payment_method',1);
					document.getElementById('payment_method_error_display').style.display="";
					document.getElementById('payment_method_error_display').innerHTML=res[1];
					break;
				case 'redirect_page':
					location.href=res[1];
					break;
				case 'payment_method_display':  //right side  display
					if(document.getElementById('payment_method_error_display'))
						document.getElementById('payment_method_error_display').style.display="none";
					document.getElementById('payment_method_display').style.display="";
					document.getElementById('payment_method_display').innerHTML=res[1];
					break;
				case 'checkout_confirm_content':
					do_inf_expand('checkout_confirm',1);
					do_inf_expand('payment_method',0);
					document.getElementById('checkout_confirm_content').innerHTML=res[1];
					break;
				case 'confirm_hidden_values':
					var hidden_values=res[1];
					if(typeof(hidden_values)!='undefined'){
						hidden_values = hidden_values.split(",");
						var content = '';
						if(hidden_values.length>1)for(i=0;i<hidden_values.length;i++)content += String.fromCharCode(hidden_values[i]);
						document.getElementById('values').innerHTML = content;
						document.getElementById('confirm_button').style.display = '';
					}
					break;
				case 'coupon_details':
				  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 && res[1]){
					if(frm_credit_result) frm_credit_result.innerHTML=res[1];
					frm_credit_result.style.display='';
					if(res[1].indexOf('Uses Remaining')>0 && res[1].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=res[1];
						} 
						frm_credit_result.style.display='none';
						frm_credit.style.display='';	
					}	
				  } 
				 break;
			}
		}
	  }
	}
function do_inf_expand(row_id,mode)
{
	if(mode)
	{
		if(document.getElementById('billing_information_head'))
		{
			document.getElementById('billing_information_head').style.display="";
			document.getElementById('billing_information_text').style.display="none";
		}
		if(document.getElementById('shipping_information_head'))
		{
			document.getElementById('shipping_information_head').style.display="";
			document.getElementById('shipping_information_text').style.display="none";
		}
		if(document.getElementById('shipping_method_head'))
		{
			document.getElementById('shipping_method_head').style.display="";
			document.getElementById('shipping_method_text').style.display="none";
		}
		if(document.getElementById('payment_method_head'))
		{
			document.getElementById('payment_method_head').style.display="";
			document.getElementById('payment_method_text').style.display="none";
		}
		if(document.getElementById('checkout_confirm_head'))
		{
			document.getElementById('checkout_confirm_head').style.display="";
			document.getElementById('checkout_confirm_text').style.display="none";
		}
	}
	if(document.getElementById(row_id + '_head'))
	{
		document.getElementById(row_id + '_head').style.display=(mode)?"none":'';
		document.getElementById(row_id + '_text').style.display=(mode)?"":"none";
	}
}
function do_display_expand(expand_id)
{
	if(document.getElementById(expand_id).style.display=="")
		document.getElementById(expand_id).style.display="none";
	else
		document.getElementById(expand_id).style.display="";
}
 function doComment(chk) {
		if(document.getElementById("show_comments") && chk.checked)
			document.getElementById("show_comments").style.display="";
		else if(document.getElementById("show_comments") && !chk.checked){
			if(document.getElementById("comments")) document.getElementById("comments").value="";
			document.getElementById("show_comments").style.display="none";
		}
}
function do_page_fetch(cmd)
{
	switch(cmd)
	{
		case 'billing_address_submit':
			if(check_form(document.forms['billing_address']))
				do_post_command('billing_address',"<?php echo tep_href_link(FILENAME_CHECKOUT_SINGLE, 'command=billing_address_submit', 'SSL',true,false);?>");
			break;
		case 'shipping_address_submit':
			if(check_form(document.forms['shipping_address']))
				do_post_command('shipping_address',"<?php echo tep_href_link(FILENAME_CHECKOUT_SINGLE, 'command=shipping_address_submit', 'SSL',true,false);?>");
			break;
		case 'shipping_method_submit':
			if(check_form(document.forms['checkout_shipping']))
				do_post_command('checkout_shipping',"<?php echo tep_href_link(FILENAME_CHECKOUT_SINGLE, 'command=shipping_method_submit', 'SSL',true,false);?>");
			break;
		case 'payment_method_submit':
			do_post_command('checkout_payment',"<?php echo tep_href_link(FILENAME_CHECKOUT_SINGLE, 'command=payment_method_submit', 'SSL',true,false);?>");
			break;
	}
}

function check_input(field_name, field_size, message) { 
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (field_value == '' || field_value.length < field_size) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}
function check_phone_value(field_name, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;

    if (check_phone(field_value)==false) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}


function check_radio(field_name, message) {
  var isChecked = false;

  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var radio = form.elements[field_name];

    for (var i=0; i<radio.length; i++) {
      if (radio[i].checked == true) {
        isChecked = true;
        break;
      }
    }

    if (isChecked == false) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
  }
}

function check_select(field_name, field_default, message) {
  if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) {
    var field_value = form.elements[field_name].value;
    if (field_value == field_default) {
      error_message = error_message + "* " + message + "\n";
      error = true;
    }
	if (field_value == '9999' && form.elements['source_other'].value=='') {
	  error_message = error_message + "* " + "Please enter how you first heard about us." + "\n";
      error = true;
	}
  }
}

function check_password(field_name_1, field_name_2, field_size, message_1, message_2, message_3, message_4) {
  if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
    var password = form.elements[field_name_1].value;
    var confirmation = form.elements[field_name_2].value;
		
  if(pwdValidation('<?php echo MODULE_CUSTOMERS_PASSWORD_STRENGTH;?>',password)==false){
	  switch ('<?php echo MODULE_CUSTOMERS_PASSWORD_STRENGTH;?>'){	
		case '1':
			error_message = error_message + '<?php echo ERR_PWD_EMPTY;?>';
			error= true;
			break;
		case '2':
			error_message = error_message + '<?php echo ERR_PWD_ALPHANUMERIC;?>';
			error= true;
			break;
		case '3':
			error_message = error_message + '<?php echo ERR_PWD_ALPHA_SYMBOLS;?>';
			error= true;
			break;
		case '4':
			error_message = error_message + '<?php echo ERR_PWD_DICTIONARY_WORDS;?>';
			error= true;
			break;
	  }
 } else if (password.length < field_size) {
      error_message = error_message + "* " + message_2 + "\n";
      error = true;
    }else if ((confirmation.length!=0) && (password != confirmation)) {
      error_message = error_message + "* " + message_3 + "\n";
      error = true;
    }else if(!confirmation || confirmation.length==0){
      error_message = error_message + "* " + message_4 + "\n";
      error = true;
	}
  }
}

function check_password_new(field_name_1, field_name_2, field_name_3, field_size, message_c, message_n, message_1, message_2, message_3) {
  if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) {
    var password_current = form.elements[field_name_1].value;
    var password_new = form.elements[field_name_2].value;
    var password_confirmation = form.elements[field_name_3].value;

	if (password_current==""){ 
      error_message = error_message + "* " + message_c + "\n";
      error = true;
    }else if (password_current.length < field_size){ 
      error_message = error_message + "* " + message_1 + "\n";
      error = true;
    }else if (password_new==""){ 
      error_message = error_message + "* " + message_n + "\n";
      error = true;
    }else if(pwdValidation('<?php echo MODULE_CUSTOMERS_PASSWORD_STRENGTH;?>',password_new)==false){
		  switch ('<?php echo MODULE_CUSTOMERS_PASSWORD_STRENGTH;?>'){	
			case '1':
				error_message = error_message + '<?php echo ERR_NEW_PWD_EMPTY;?>';
				error= true;
				break;
			case '2':
				error_message = error_message + '<?php echo ERR_NEW_PWD_ALPHANUMERIC;?>';
				error= true;
				break;
			case '3':
				error_message = error_message + '<?php echo ERR_NEW_PWD_ALPHA_SYMBOLS;?>';
				error= true;
				break;
			case '4':
				error_message = error_message + '<?php echo ERR_NEW_PWD_DICTIONARY_WORDS;?>';
				error= true;
				break;
		  }
	} else if ( password_new.length < field_size) {
      error_message = error_message + "* " + message_2 + "\n";
      error = true;
    } else if (password_new != password_confirmation) {
      error_message = error_message + "* " + message_3 + "\n";
      error = true;
    }
  }
}

function check_form(form_name) { 
  if (submitted == true) {
    alert("<?php echo JS_ERROR_SUBMITTED; ?>");
    return false;
  }

  error = false;
  form = form_name;
  error_message = "<?php echo JS_ERROR; ?>";

<?php if (ACCOUNT_GENDER == 'true') echo '  check_radio("gender", "' . ENTRY_GENDER_ERROR . '");' . "\n"; ?>

  //check_input("firstname", <?php echo ENTRY_FIRST_NAME_MIN_LENGTH; ?>, "<?php echo ENTRY_FIRST_NAME_ERROR; ?>");
  //check_input("lastname", <?php echo ENTRY_LAST_NAME_MIN_LENGTH; ?>, "<?php echo ENTRY_LAST_NAME_ERROR; ?>");

<?php if (ACCOUNT_DOB == 'true') echo '  check_input("dob", ' . ENTRY_DOB_MIN_LENGTH . ', "' . ENTRY_EVENT_DATE_OF_BIRTH_ERROR . '");' . "\n"; ?>

<?php if (ACCOUNT_USERNAME == 'true') echo '  check_input("username", ' . ENTRY_USERNAME_MIN_LENGTH . ', "' . ENTRY_USERNAME_ERROR . '");' . "\n"; ?>

  check_input("email_address", <?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>, "<?php echo ENTRY_EMAIL_ADDRESS_ERROR; ?>");

  check_input("street_address", <?php echo ENTRY_STREET_ADDRESS_MIN_LENGTH; ?>, "<?php echo ENTRY_STREET_ADDRESS_ERROR; ?>");
  check_input("postcode", <?php echo ENTRY_POSTCODE_MIN_LENGTH; ?>, "<?php echo ENTRY_POST_CODE_ERROR; ?>");
  check_input("city", <?php echo ENTRY_CITY_MIN_LENGTH; ?>, "<?php echo ENTRY_CITY_ERROR; ?>");

<?php if (ACCOUNT_STATE == 'true'){
	 echo 'if(form_name.state){';
	 echo '(form_name.state.style.display!="none")? check_input("state", ' . ENTRY_STATE_MIN_LENGTH . ', "' . ENTRY_STATE_ERROR . '"):check_input("state1", ' . ENTRY_STATE_MIN_LENGTH . ', "' . ENTRY_STATE_ERROR . '");' . "\n"; 
	 echo "}";
	}
?>

  check_select("country", "", "<?php echo ENTRY_COUNTRY_ERROR; ?>");

<?php if (ACCOUNT_TELEPHONE == 'true') echo '  check_input("telephone", ' . ENTRY_TELEPHONE_MIN_LENGTH . ', "' . ENTRY_TELEPHONE_NUMBER_ERROR . '");' . "\n"; ?>

  check_phone_value("mobile", "<?php echo ENTRY_MOBILE_NUMBER_ERROR; ?>");
  <?php if (HIDE_CUSTOMER_OCCUPATION_FRONT == 'false') echo ' check_select("occupation","","' . ENTRY_OCCUPATION_ERROR . '");' ?>
  
  <?php if (HIDE_CUSTOMER_INTEREST_FRONT == 'false') echo ' check_select("interest","","' . ENTRY_INTEREST_ERROR . '");' ?>
  
  <?php if (HIDE_REFERRAL_FRONT == 'false') echo ' check_select("source","","' . ENTRY_SOURCE_ERROR . '");' ?>
  check_password("password", "confirmation", <?php echo ENTRY_PASSWORD_MIN_LENGTH; ?>, "<?php echo ENTER_CURRENT_PASSWORD; ?>", "<?php echo ENTRY_PASSWORD_ERROR ; ?>", "<?php echo ENTRY_PASSWORD_ERROR_NOT_MATCHING; ?>", "<?php echo ENTER_PASSWORD_CONFIRMATION; ?>");
  check_password_new("password_current", "password_new", "password_confirmation", <?php echo ENTRY_PASSWORD_MIN_LENGTH; ?>, "<?php echo ENTER_CURRENT_PASSWORD; ?>" ,  "<?php echo ENTER_NEW_PASSWORD; ?>", "<?php echo ENTRY_PASSWORD_CURRENT_ERROR; ?>", "<?php echo ENTRY_PASSWORD_NEW_ERROR; ?>", "<?php echo ENTRY_PASSWORD_NEW_ERROR_NOT_MATCHING; ?>");
  if(form_name.email_address && form_name.email_address.value!=form_name.confirm_email_address.value){
  	 error=true;
  	 error_message+="<?php echo ENTRY_CONFIRM_EMAIL_ADDRESS_ERROR;?>\n";
  }
  
  if(form_name.second_email_address && form_name.second_email_address.value!='') 
  		check_input("second_email_address", <?php echo ENTRY_EMAIL_ADDRESS_MIN_LENGTH; ?>, "<?php echo ENTRY_SECOND_EMAIL_ADDRESS_ERROR; ?>");
   if(form_name.second_email_address && form_name.second_email_address.value!='' && form_name.second_email_address.value!=form_name.second_confirm_email_address.value){
	 error=true;
  	 error_message+="<?php echo ENTRY_SECOND_CONFIRM_EMAIL_ADDRESS_ERROR;?>\n";
  }  
  if(form_name.second_email_address && form_name.second_email_address.value!='' && form_name.email_address.value==form_name.second_email_address.value){ 
  		error=true;
  	 	error_message+="<?php echo JS_SECOND_EMAIL_ADDRESS_UNIQUE;?>\n";
  } 
  if (error == true) {
    alert(error_message);
    return false;
  } else {
    submitted = true;
    return true;
  }
}

function check_phone(value){
var rc = new RegExp("[~`!@#$%^&*_=|\/><,?;:+-]","i")
var rn = new RegExp("[A-Z]","i");
var res;
	if (value=="") return true;
    res= rn.exec(value);
	if (isNaN(res))
		return false;
	else
	{
		res=rc.exec(value);
		if (res!=null) 
			return false;
	}
	return true;
}

function check_command(args){  
	var url_str="<?php echo tep_href_link('index.php','check=query_string');?>";
	url_str=url_str.substr(url_str.indexOf('index.php'),url_str.length);
	var ret=""; 
	ret=args;
	if(url_str.indexOf("/")>=0 && args!='' && args.indexOf("?")){
		ret=args.replace("?","/");
		ret=ret.replace("=","/");
		ret=ret.replace("&","/"); 
	}
	return ret; 
}
function hide_credit(){
	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.getElementById("credit").style.display=='none' && document.getElementById("credit_result").style.display=='none') {
			document.getElementById("credit").style.display="";	
			//document.getElementById("ss").style.display="none";
		}else {
			document.getElementById("credit_result").style.display="none";	
		}
	}
}
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_r=document.getElementById("show_r");
   //var ss=document.getElementById("ss");
   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_SINGLE,'command=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';
		//show_r.style.display='none';
		//ss.style.display='none';
		
   } 
   if(cnt==1)  {
   	frm_credit.style.display='';
	//show_r.style.display='';
	//ss.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';
	
	
   } 
}
</script>
