function change_phone()
{


if ($("shipping_country").value=="US")
{
//alert ("Please use international phone number field");


document.frm.phone1.disabled=false;
document.frm.phone2.disabled=false;
document.frm.phone3.disabled=false;

document.frm.intphone1.disabled=true;
document.frm.intphone2.disabled=true;
document.frm.intphone3.disabled=true;


document.frm.intphone1.value="";
document.frm.intphone2.value="";
document.frm.intphone3.value="";

//document.frm.int_phone.style.display='inline';
}
else
	{
	document.frm.phone1.disabled=true;
	document.frm.phone2.disabled=true;
	document.frm.phone3.disabled=true;
	
	
	document.frm.intphone1.disabled=false;
	document.frm.intphone2.disabled=false;
	document.frm.intphone3.disabled=false;
	document.frm.phone1.value="";
	document.frm.phone2.value="";
	document.frm.phone3.value="";
	}

}

function setStateProvince(sel) {
	
	if (sel =="US") {
		document.getElementById("state-province-txt").style.display='none';
		document.frm['state-province-usa'].style.display='inline';
		document.frm['state-province-can'].style.display='none';

	} else if (sel=="CA") {
		document.getElementById("state-province-txt").style.display='none';
		document.frm['state-province-usa'].style.display='none';
		document.frm['state-province-can'].style.display='inline';

	} else {
		document.getElementById("state-province-txt").style.display='inline';
		document.frm['state-province-usa'].style.display='none';
		document.frm['state-province-can'].style.display='none';

	}

}

function setStateProvince_billing(sel) {
	
	if (sel =="US") {
		document.getElementById("state-province-txt-billing").style.display='none';
		document.frm['state-province-usa-billing'].style.display='inline';
		document.frm['state-province-can-billing'].style.display='none';

	} else if (sel=="CA") {
		document.getElementById("state-province-txt-billing").style.display='none';
		document.frm['state-province-usa-billing'].style.display='none';
		document.frm['state-province-can-billing'].style.display='inline';

	} else {
		document.getElementById("state-province-txt-billing").style.display='inline';
		document.frm['state-province-usa-billing'].style.display='none';
		document.frm['state-province-can-billing'].style.display='none';

	}

}

function change_phone_div()
{
if ($("shipping_country").value=="US")
{
	$("intphone_place").style.display="none";
	$("usphone_place").style.display="inline";
	
	$("shipping_int_phone1").disabled=true;
	$("shipping_int_phone2").disabled=true;
	$("shipping_int_phone3").disabled=true;
	
	$("shipping_phone1").disabled=false;
	$("shipping_phone2").disabled=false;
	$("shipping_phone3").disabled=false;
}
else
{
	$("intphone_place").style.display="inline";
	$("usphone_place").style.display="none";
	
	$("shipping_phone1").disabled=true;
	$("shipping_phone2").disabled=true;
	$("shipping_phone3").disabled=true;
	
	$("shipping_int_phone1").disabled=false;
	$("shipping_int_phone2").disabled=false;
	$("shipping_int_phone3").disabled=false;
}

}

function change_phone_div_billing()
{

if ($("billing_country").value=="US")
{

	$("intphone_place_billing").style.display="none";
	$("usphone_place_billing").style.display="inline";
	
	$("billing_int_phone1").disabled=true;
	$("billing_int_phone2").disabled=true;
	$("billing_int_phone3").disabled=true;
	
	$("billing_phone1").disabled=false;
	$("billing_phone2").disabled=false;
	$("billing_phone3").disabled=false;
}
else
{
	
	$("intphone_place_billing").style.display="inline";
	$("usphone_place_billing").style.display="none";
	
	
	$("billing_phone1").disabled=true;
	$("billing_phone2").disabled=true;
	$("billing_phone3").disabled=true;
	
	$("billing_int_phone1").disabled=false;
	$("billing_int_phone2").disabled=false;
	$("billing_int_phone3").disabled=false;
	
}


}


function copy_data_to_shipping()
{

//if ($("samebilling").checked)
//{
	
	
	//var myform=document.frm;
	selchoice($("shipping_country"),$("billing_country").value);
	change_phone_div();
	setStateProvince($("billing_country").value);
	$("shipping_firstname").value=$("billing_firstname").value;
	$("shipping_lastname").value=$("billing_lastname").value;
	$("shipping_company").value=$("billing_company").value;
	$("shipping_city").value=$("billing_city").value;
	$("shipping_zip").value=$("billing_zip").value;
	$("shipping_address1").value=$("billing_address1").value;
	$("shipping_address2").value=$("billing_address2").value;

	
	
	if ($("billing_country").value=="US")
	{
		$("shipping_phone1").value=$("billing_phone1").value;
	$("shipping_phone2").value=$("billing_phone2").value;
	$("shipping_phone3").value=$("billing_phone3").value;
	selchoice($("state-province-usa"),$("state-province-usa-billing").value);
	}
else
	{
	$("state-province-txt").value=$("state-province-txt-billing").value;
			$("shipping_int_phone1").value=$("billing_int_phone1").value;
	$("shipping_int_phone2").value=$("billing_int_phone2").value;
	$("shipping_int_phone3").value=$("billing_int_phone3").value;
		
		}
	
//}
shipping_methods();
}

function selchoice(obj,selvalue) {
var sindex;
	for(i=0;i<=obj.options.length-1;i++) {
		if(obj.options[i].value == selvalue) {
			
			obj[i].selected = true;
			sindex=i;
			
		//break;
		}
	}
	
	obj.selectedIndex=sindex;
	//obj[1].selected=true;
	return true;
}
function reportError(request)
                                      {
                                        alert('Sorry. There was an error.');
                                      }
                                      
function handlerFunc(t)
{
	
//alert(t.responseText);
var err=false;
err=t.responseText.indexOf("Error");
//alert(err);
if(err>0)
{
	$('notification').style.display = "none";
	$('submit_button').disabled=true;
	$('paypal_button').style.display='none';
	$('paypal_button_fake').style.display='inline';
	$('submit_button_fake').style.display='inline';
	$('submit_button').style.display='none';
	
}
else
{
	$('notification').style.display = "none";
	$('submit_button').disabled=false;
	$('paypal_button_fake').style.display='none';
	$('paypal_button').style.display='inline';
	$('submit_button_fake').style.display='none';
	$('submit_button').style.display='inline';
	show_order_total();
	
}


}                                      
function getHTML(totweight,totdem,country,zip,free)
{
	var to_state;
	$('submit_block').style.display='none';
	if($("show_all_shipping").checked==true)
	{
	country = $("shipping_country").value;
	zip=$("shipping_zip").value;
	to_state_index=$("state-province-usa").selectedIndex;
	to_state=$("state-province-usa-billing")[to_state_index].value
}
else
	{
	country = $("billing_country").value;
	zip=$("billing_zip").value;
	to_state_index=$("state-province-usa-billing").selectedIndex;
	to_state=$("state-province-usa-billing")[to_state_index].value;
	}

	
	var sserv=$("method_service[]");
	/*var count=document.frm.elements.length;
for (g=0; g<count; g++)
{
alert(document.frm.elements[g].name+'='+document.frm.elements[g].value);
}*/
var url='shipping_request_new.php';
//var url='input.php';
var i=0;
var done=false;
var m_s=document.frm.method_service;

if (m_s.length)
{
for (i=0; i<m_s.length; i++)
	{
	if(m_s[i].checked==true) 
		{
		done=true;
		var	method_service_value=m_s[i].value;
		}
	}
}
else
{
if (m_s.checked==true)
{
		var	method_service_value=m_s.value;
done=true;
}
}

if (done==true)
{
$('submit_button').disabled=true;
	$('notification').style.display= "inline";
//var totweight=2;
//var totdem=1;
//var country='US';
//var zip='93727';
//var free='';

var pars = "method_service="+method_service_value+"&weight="+totweight+"&demweight="+totdem+"&country="+country+"&zip="+zip+"&free="+free+"&to_state="+to_state;

var myAjax = new Ajax.Updater(

{success: 'placeholder_'+method_service_value},
url,
{method: 'post', parameters: pars, onFailure: reportError, onSuccess:handlerFunc	
	});
	var myAjax2 = new Ajax.Updater(
	{success: 'calculated_shipping'},
url,
{method: 'post', parameters: pars, onFailure: reportError


	});
return true;
}
else
	{
  alert ("Please select shipping method");
	return false;
	}
 }
function check_form()
{

if ($("country").value!="US" && $("country").value!="CA")
	{
	if ($("taccept").checked==false )
		{
		alert ("Please accept our terms and conditions.");
		return false;
		}
	else
		{
		return true;
		}
	}
else
	{
	return true;
	}
}
function __submit()
{

var catched=getHTML();
if (catched==true)
{

document.frm.submit();
}
else

{

}

}
function WAtrimIt(theString,leaveLeft,leaveRight)  {
  if (!leaveLeft)  {
    while (theString.charAt(0) == " ")
      theString = theString.substring(1);
  }
  if (!leaveRight)  {
    while (theString.charAt(theString.length-1) == " ")
      theString = theString.substring(0,theString.length-1);
  }
  
  return theString;
}
function WAAddError(formElement,errorMsg,focusIt,stopIt)  {
	//alert(formElement.name);
  if (document.WAFV_Error)  {
	  document.WAFV_Error += "\n" + errorMsg;
  }
  else  {
    document.WAFV_Error = errorMsg;
  }
  if (!document.WAFV_InvalidArray)  {
    document.WAFV_InvalidArray = new Array();
  }
  document.WAFV_InvalidArray[document.WAFV_InvalidArray.length] = formElement;
  if (focusIt && !document.WAFV_Focus)  {
	document.WAFV_Focus = focusIt;
  }
  if (stopIt == 1)  {
	document.WAFV_Stop = true;
  }
  else if (stopIt == 2)  {
	formElement.WAFV_Continue = true;
  }
  else if (stopIt == 3)  {
	formElement.WAFV_Stop = true;
	formElement.WAFV_Continue = false;
  }
}
function checkPhones()
{
	if ($("billing_country").value=="US")
	{
	if ($("billing_phone1").value.length<3 || $("billing_phone2").value.length<3 || $("billing_phone3").value.length<4)
	{
		WAAddError($("billing_phone1"),"- enter billing phone correct number",$("billing_phone1"),3);
		
	}

}
else
	{
		
	if(($("billing_int_phone1").value.length+$("billing_int_phone2").value.length+$("billing_int_phone3").value.length)==0)
	{
			WAAddError($("billing_phone1"),"- your billing phone is empty",$("billing_phone1"),3);
	}
	if(($("billing_int_phone1").value.length+$("billing_int_phone2").value.length+$("billing_int_phone3").value.length)>14)
	{
			WAAddError($("billing_phone1"),"- your billing phone should be 14 numbers max",$("billing_phone1"),3);
	}
	}


}

function checkTerms()
{
	if ($("shipping_country").value!="US" && $("shipping_country").value!="CA")
		{
		if ($("checkterms").checked==false)
		{
			WAAddError($("checkterms")," - accept our shipping terms",$("checkterms"),3);
			
		}
}
	

}

function checkPhones_shipping()
{
	if ($("shipping_country").value=="US")
	{
		if ($("shipping_phone1").value.length<3 || $("shipping_phone2").value.length<3 || $("shipping_phone3").value.length<4)
		{
			WAAddError($("shipping_phone1")," - enter shipping phone correct number",$("shipping_phone1"),3);
			
		}
	
	/*if ($("billing_phone1").value!="")
	{
		if (($("billing_phone1").value.length+$("billing_phone2").value.length+$("billing_phone3").value.length)!=10)
		{
			WAAddError($("billing_phone1")," - enter correct number",true,true);
		
	}*/
}
else
	{
		
	if(($("shipping_int_phone1").value.length+$("shipping_int_phone2").value.length+$("shipping_int_phone3").value.length)==0)
	{
			WAAddError($("shipping_phone1"),"- your shipping phone is empty",$("shipping_phone1"),3);
	}
	if(($("shipping_int_phone1").value.length+$("shipping_int_phone2").value.length+$("shipping_int_phone3").value.length)>14)
	{
			WAAddError($("shipping_phone1"),"- your shipping phone should be 14 numbers max",$("shipping_phone1"),3);
	}
	}
}
function checkShippingmethod()
{
	var i;
	var met=document.frm.method_service;
		var checkvar=false;
		//alert(met[1].value);
		//alert(met[1].checked);
		for(i=0; i<met.length; i++)
		{
			if(met[i].checked==true) checkvar=true;
			met[i].value;
		}
		if(checkvar==false)
		{
			WAAddError($("method_service[]")," - choose shipping method",$("method_service[]"),3);
		}
	
	//alert(document.frm.method_service[2].value);	
	
	//if ($("method_service[]").checked==false)
//	{
//		WAAddError($("method_service[]")," - choose shipping method",$("method_service[]"),3);
		
//	}
}
function WAValidateRQ(formElement,errorMsg,focusIt,stopIt,trimWhite,inputType)  {
	//alert(document.WAFV_Stop);
  var isValid = true;
  if (!document.WAFV_Stop && !formElement.WAFV_Stop)  {
    if (inputType == "select")  { //alert(inputType); 
	  if (formElement.selectedIndex == -1)  { 
	    isValid = false;
	  }
	  else if (!formElement.options[formElement.selectedIndex].value || formElement.options[formElement.selectedIndex].value == "") { 
	    isValid = false;
	  }
	}
	else if (inputType == "checkbox")  { 
	  if (formElement.length)  {
	    isValid = false;
        focusIt = false;
	    for (var x=0; x<formElement.length ; x++)  {
	      if (formElement[x].checked && formElement[x].value!="")  {
		    isValid = true;
		    break;
		  }
	    }
	  }
      else if (!formElement.checked)
	    isValid = false;
	}
	else if (inputType == "radio")  {
	  isValid = false;
	  if (formElement.checked)
	    isValid = true;
	}
	else if (inputType == "radiogroup")  {
	  isValid = false;
	  for (var x=0; x<formElement.length; x++)  {
	    if (formElement[x].checked && formElement[x].value!="")  {
		  isValid = true;
		  break;
		}
	  }
	  formElement = formElement[0];
	}
	else  {
	  var value = formElement.value;
	  if (trimWhite)  { 
	    value = WAtrimIt(value);//alert(WAtrimIt(value));
	  }
	  if (value == "")  {
	    isValid = false;
	  }
	}
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}

function WAValidateZC(formElement,errorMsg,us5,us9,can6,uk,reformat,focusIt,stopIt,required)  {
  var value = formElement.value;
  var isValid = true;
  var allowed = "() -.\n\r";
  var hasLetters = false;
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value==""))  {
    var newVal = "";
	var charVal = "";
    for (var x=0; x<value.length; x++)  {
      var z = value.charAt(x);
      if ((z >= "0") && (z <= "9")) {
	    newVal += z;
		charVal += "N";
	  }
	  else  {
		if ((uk || can6) && ((z >= "a") && (z <= "z")) || ((z >= "A") && (z <= "Z"))) {
		  charVal += "A";
		  hasLetters = true;
		}
		else if (allowed.indexOf(z) < 0)  {
		  isValid = false;
		}
	  }
    }
	if ((uk || can6) && hasLetters)  {
	  var acceptPattern = "";
	  if (uk)  {
	    acceptPattern += ",ANNAA,ANNNAA,AANNAA,AANNNAA,ANANAA,AANANAA,";
	  }
	  if (can6)  {
	    acceptPattern += ",ANANAN,";
	  }
	  if (String(acceptPattern).indexOf(","+charVal+",") < 0)
	    isValid = false;
	}
	if (!((uk && (charVal.length >= 4 &&  charVal.length <= 8)) || (us5 && newVal.length == 5) || (us9 && newVal.length == 9) || (can6 && charVal.length == 6)))  {
	  isValid = false;
	}
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
  else  {
    if (reformat != "")  {
	  if (reformat != "t")  {
        for (var x=0; x<newVal.length; x++)  {
	      reformat = reformat.substring(0,reformat.indexOf("x")) + newVal.charAt(x) + reformat.substring(reformat.indexOf("x")+1);
	    }
	    if (reformat.indexOf("x")>=0)  {
	      reformat = reformat.substring(0,reformat.indexOf("x"));
		  while (reformat.charAt(reformat.length-1) == " " || reformat.charAt(reformat.length-1) == "-")
		    reformat = reformat.substring(0,reformat.length-1);
          z = reformat.charAt(reformat.length-1);
	    }
		if (newVal.length==6)
		  reformat = reformat.replace(/-/,"");
	  }
	  else  {
	    newVal = formElement.value;
		while (newVal.charAt(0) == " ")
		  newVal = newVal.substring(1);
		while (newVal.charAt(newVal.length-1) == " ")
		  newVal = newVal.substring(0,newVal.length-1);
		reformat = newVal;
	  }
      formElement.value = reformat;
	}
  }
}
function WAValidatePN(formElement,errorMsg,areaCode,international,reformat,focusIt,stopIt,required)  {
  var value = formElement.value;
  var isValid = true;
  var allowed = "*() -./_\n\r+";
  var newVal = "";
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value==""))  {
    for (var x=0; x<value.length; x++)  {
      var z = value.charAt(x);
      if ((z >= "0") && (z <= "9")) {
	    newVal += z;
	  }
	  else  {
		if (allowed.indexOf(z) < 0)  {
		  isValid = false;
		}
	  }
    }	
	if (international)  {
	  if  (newVal.length < 5)  {
	    isValid = false;
	  }
	}
	else if (newVal.length == 11)  {
	  if (newVal.charAt(0) != "1")	{
		isValid = false;
	  }
	}
	else if ((newVal.length != 10 && newVal.length != 7) || (newVal.length==7 && areaCode)) {
	  isValid = false;
	}
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
  else  {
    formElement.WAValid = true;
    if (reformat != "" && newVal != "")  {
      for (var x=0; x<newVal.length; x++)  {
	    reformat = reformat.substring(0,reformat.lastIndexOf("x")) + newVal.charAt(newVal.length-(x+1)) + reformat.substring(reformat.lastIndexOf("x")+1);
	  }
	  if (reformat.indexOf("x")>=0)  {
	    reformat = reformat.substring(reformat.lastIndexOf("x")+1);
        z = reformat.charAt(0);
	    while (((z < "0") || (z > "9")) && z != "(")  {
	      reformat = reformat.substring(1);
		  z = reformat.charAt(0);
		}
	  }
      formElement.value = reformat;
	}
  }
}
function WAAlertErrors(errorHead,errorFoot,setFocus,submitForm)  { 
  if (!document.WAFV_StopAlert)  { 
	  document.WAFV_StopAlert = true;
	  if (document.WAFV_InvalidArray)  {  
	    document.WAFV_Stop = true;
        var errorMsg = document.WAFV_Error;
	    if (errorHead!="")
		  errorMsg = errorHead + "\n" + errorMsg;
		if (errorFoot!="")
		  errorMsg += "\n" + errorFoot;
		document.MM_returnValue = false;
		if (document.WAFV_Error!="")
		  alert(errorMsg.replace(/&quot;/g,'"'));
		else if (submitForm)
		  submitForm.submit();
	    if (setFocus && document.WAFV_Focus)  {
		  document.tempFocus = document.WAFV_Focus;
          setTimeout("document.tempFocus.focus();setTimeout('document.WAFV_Stop = false;document.WAFV_StopAlert = false;',1)",1); 
        }
        else {
          document.WAFV_Stop = false;
          document.WAFV_StopAlert = false;
        }
        for (var x=0; x<document.WAFV_InvalidArray.length; x++)  {
	      document.WAFV_InvalidArray[x].WAFV_Stop = false;
	    }
	  }
	  else  {
        document.WAFV_Stop = false;
        document.WAFV_StopAlert = false;
	    if (submitForm)  {
	      submitForm.submit();
	    }
	    document.MM_returnValue = true;
	  }
      document.WAFV_Focus = false;
	  document.WAFV_Error = false;
	  document.WAFV_InvalidArray = false;
  }
}
function WA_isCreditCard(st) {
  if (st == 0)
    return (false);
  if (st.length > 19)
    return (false);
  sum = 0; mul = 1; l = st.length;
  for (i = 0; i < l; i++) {
    digit = st.substring(l-i-1,l-i);
    tproduct = parseInt(digit ,10)*mul;
    if (tproduct >= 10)
      sum += (tproduct % 10) + 1;
    else
      sum += tproduct;
    if (mul == 1)
      mul++;
    else
      mul--;
  }
  if ((sum % 10) == 0)
    return (true);
  else
    return (false);
}
function WAValidateCC(formElement,value,errorMsg,format,allow,focusIt,stopIt,required)  {
  var isValid = true;
  var accepted = "\r\n\t.- ";
  if ((!document.WAFV_Stop && !formElement.WAFV_Stop) && !(!required && value==""))  {
    var stripVal = "";
	for (var x=0; x<value.length; x++)  {
	  if (value.charCodeAt(x)>=48 && value.charCodeAt(x)<=57)
	    stripVal += value.charAt(x);
	  else if (accepted.indexOf(value.charAt(x))<0)  {
	    isValid = false;
	  }
	}
	if (isValid)  {
	  if (allow!="")  {
	    isValid = false;
	    allow = allow.split(":");
		for (var y=0; y<allow.length-1 && !isValid; y++)  {
		  if (stripVal.indexOf(allow[y])==0)
		    isValid = true;
		}
	  }
	}
	if (isValid)  {
	  isValid = WA_isCreditCard(stripVal);
	}
	if (isValid && format!="")  {
	  var newFormat = "";
	  while (format!="")  {
	    if (format.charAt(0) == "x") {
		  newFormat += stripVal.charAt(0);
		  stripVal = stripVal.substring(1);
		}
		else  {
		  newFormat += format.charAt(0);
		}
		format = format.substring(1);
	  }
	  formElement.value = newFormat;
	}
  }
  if (!isValid)  {
    WAAddError(formElement,errorMsg,focusIt,stopIt);
  }
}
function validate_checkout()
{
WAValidateRQ($("billing_firstname"),'- billing first name is required',$("billing_firstname"),3,true,'text');
WAValidateRQ($("billing_lastname"),'- billing last name is required',$("billing_lastname"),3,true,'text');
WAValidateRQ($("billing_address1"),'- billing address 1 is required',$("billing_address1"),3,true,'text');
WAValidateRQ($("billing_city"),'- billing city is required',$("billing_city"),3,true,'text');
WAValidateZC($("billing_zip"),'- invalid billing  zip code',true,true,true,true,'',$("billing_zip"),3,true);
WAValidateRQ($("billing_country"),'- billing  country is required',$("billing_country"),3,true,'select');
if ($("billing_country").value=="US")
{
WAValidateRQ($("state-province-usa-billing"),'- billing  state is required',$("state-province-usa-billing"),3,true,'select');
}
else if ($("billing_country").value=="CA")
	{
WAValidateRQ($("state-province-can-billing"),'- billing  state is required',$("state-province-can-billing"),3,true,'select');
	
	}
else
	{
	WAValidateRQ($("state-province-txt-billing"),'- billing state is required',$("state-province-txt-billing"),3,true,'text');
	}
	
if ($("show_all_shipping").checked==true)
{
WAValidateRQ($("shipping_firstname"),'- shipping first name is required',$("shipping_firstname"),3,true,'text');
WAValidateRQ($("shipping_lastname"),'- shipping last name is required',$("shipping_lastname"),3,true,'text');
WAValidateRQ($("shipping_address1"),'- shipping address 1 is required',$("shipping_address1"),3,true,'text');
WAValidateRQ($("shipping_city"),'- shipping city is required',$("shipping_city"),3,true,'text');
WAValidateZC($("shipping_zip"),'- invalid shipping  zip code',true,true,true,true,'',$("shipping_zip"),3,true);
WAValidateRQ($("shipping_country"),'- shipping  country is required',$("shipping_country"),3,true,'select');
if ($("shipping_country").value=="US")
{
WAValidateRQ($("state-province-usa"),'- shipping state is required',$("state-province-usa"),3,true,'select');
}
else if ($("shipping_country").value=="CA")
	{
WAValidateRQ($("state-province-can"),'- shipping state is required',$("state-province-can"),3,true,'select');
	
	}
else
	{
	WAValidateRQ($("state-province-txt"),'- shipping state is required',$("state-province-txt-billing"),3,true,'text');
	}

checkPhones_shipping();
}
WAValidateRQ($("card_fname"),'- credit card first name is required',$("card_fname"),3,false,'text');
WAValidateRQ($("card_lname"),'- credit card last name is required',$("card_lname"),3,true,'text');
WAValidateRQ($("card_cv2"),'- security no is required',$("card_cv2"),3,true,'text');
//WAValidateCC($("card_number"),'- invalid credit card number','','4:51:52:53:54:55:34:37:6011:',$("card_number"),3,true);

//alert($("card_rnum").value);
if ($("card_num").value=='')
{ 
	testCreditCard ($("scard_number").value,$("card_type").value);
}
else
	{
	//alert($("card_num").value);
	testCreditCard ($("card_num").value,$("card_type").value);
	
}
checkTerms();
checkPhones();	

checkShippingmethod();
WAAlertErrors('The following errors were found','Correct invalid entries to continue',true,document.frm);return document.MM_returnValue;

		return true;
}

function validate_checkout_shipping_club()
{
WAValidateRQ($("billing_firstname"),'- billing first name is required',$("billing_firstname"),3,true,'text');
WAValidateRQ($("billing_lastname"),'- billing last name is required',$("billing_lastname"),3,true,'text');
WAValidateRQ($("billing_address1"),'- billing address 1 is required',$("billing_address1"),3,true,'text');
WAValidateRQ($("billing_city"),'- billing city is required',$("billing_city"),3,true,'text');
WAValidateZC($("billing_zip"),'- invalid billing  zip code',true,true,true,true,'',$("billing_zip"),3,true);
WAValidateRQ($("billing_country"),'- billing  country is required',$("billing_country"),3,true,'select');
if ($("billing_country").value=="US")
{
WAValidateRQ($("state-province-usa-billing"),'- billing  state is required',$("state-province-usa-billing"),3,true,'select');
}
else if ($("billing_country").value=="CA")
	{
WAValidateRQ($("state-province-can-billing"),'- billing  state is required',$("state-province-can-billing"),3,true,'select');
	
	}
else
	{
	WAValidateRQ($("state-province-txt-billing"),'- billing state is required',$("state-province-txt-billing"),3,true,'text');
	}
	

WAValidateRQ($("card_fname"),'- credit card first name is required',$("card_fname"),3,false,'text');
WAValidateRQ($("card_lname"),'- credit card last name is required',$("card_lname"),3,true,'text');
WAValidateRQ($("card_cv2"),'- security no is required',$("card_cv2"),3,true,'text');
//WAValidateCC($("card_number"),'- invalid credit card number','','4:51:52:53:54:55:34:37:6011:',$("card_number"),3,true);


if ($("card_num").value=='')
{   
	//alert($("scard_num").value);
	testCreditCard ($("scard_number").value,$("card_type").value);
}
else
	{
	
	testCreditCard ($("card_num").value,$("card_type").value);
	
}
//checkTerms();
checkPhones();	


WAAlertErrors('The following errors were found','Correct invalid entries to continue',true,document.frm);return document.MM_returnValue;

		return true;
}


function validate_xco()
{
WAValidateRQ($("billing_firstname"),'- billing first name is required',$("billing_firstname"),3,true,'text');
WAValidateRQ($("billing_lastname"),'- billing last name is required',$("billing_lastname"),3,true,'text');
WAValidateRQ($("billing_address1"),'- billing address 1 is required',$("billing_address1"),3,true,'text');
WAValidateRQ($("billing_city"),'- billing city is required',$("billing_city"),3,true,'text');
WAValidateZC($("billing_zip"),'- invalid billing  zip code',true,true,true,true,'',$("billing_zip"),3,true);
WAValidateRQ($("billing_country"),'- billing  country is required',$("billing_country"),3,true,'select');

if ($("billing_country").value=="US")
{
WAValidateRQ($("state-province-usa-billing"),'- billing  state is required',$("state-province-usa-billing"),3,true,'select');
}
else if ($("billing_country").value=="CA")
	{
WAValidateRQ($("state-province-can-billing"),'- billing  state is required',$("state-province-can-billing"),3,true,'select');
	
	}
else
	{
	WAValidateRQ($("state-province-txt-billing"),'- billing state is required',$("state-province-txt-billing"),3,true,'text');
	}
	
if ($("show_all_shipping").checked==true) 
{
	
	WAValidateRQ($("shipping_firstname"),'- shipping first name is required',$("shipping_firstname"),3,true,'text');
	WAValidateRQ($("shipping_lastname"),'- shipping last name is required',$("shipping_lastname"),3,true,'text');
	WAValidateRQ($("shipping_address1"),'- shipping address 1 is required',$("shipping_address1"),3,true,'text');
	WAValidateRQ($("shipping_city"),'- shipping city is required',$("shipping_city"),3,true,'text');
	WAValidateZC($("shipping_zip"),'- invalid shipping  zip code',true,true,true,true,'',$("shipping_zip"),3,true);
	WAValidateRQ($("shipping_country"),'- shipping  country is required',$("shipping_country"),3,true,'select');
	if ($("shipping_country").value=="US")
	{
	WAValidateRQ($("state-province-usa"),'- shipping state is required',$("state-province-usa"),3,true,'select');
	}
	else if ($("shipping_country").value=="CA")
		{
	WAValidateRQ($("state-province-can"),'- shipping state is required',$("state-province-can"),3,true,'select');
		
		}
	else
		{
		WAValidateRQ($("state-province-txt"),'- shipping state is required',$("state-province-txt-billing"),3,true,'text');
		}
checkPhones_shipping();
}
WAValidateRQ($("card_fname"),'- credit card first name is required',$("card_fname"),3,false,'text');
WAValidateRQ($("card_lname"),'- credit card last name is required',$("card_lname"),3,true,'text');
WAValidateRQ($("card_cv2"),'- security no is required',$("card_cv2"),3,true,'text');

//WAValidateCC($("card_number"),'- invalid credit card number','','4:51:52:53:54:55:34:37:6011:',$("card_number"),3,true);

//checkTerms();
checkPhones();	


WAAlertErrors('The following errors were found','Correct invalid entries to continue',true,document.frm);
return document.MM_returnValue;

		return true;
}

function calculate_tax()
{
	
	if ($("state-province-usa-billing").value=="CA")
	{
		$("tax_charges_place").innerHTML="Calculated Tax:";
	var url='checkout.php';
	var pars='calculate_tax=yes';
var myAjax = new Ajax.Updater(
{success: 'tax_charges'},
url,
{method: 'post', parameters: pars, onFailure: reportError


	});
}
else
	{
	
	$("tax_charges_place").innerHTML="";
	$("tax_charges").innerHTML="";
	}
}
function __submit()
{
if (check_form()==true)
{
var catched=getHTML();
if (catched==true)
{
//alert("Ok!");
document.frm.submit();
}
else
//alert("Select method");
{

}
}
}


function getHTML_test(totweight,totdem,country,zip)
{
	alert("test");
var url='input.php';

var free='';
var totweight=2;
var totdem=1;
var country='US';
var zip='93727';
var method_service_value="USPS_EXPRESS";

var pars = "method_service=ddd";
//alert (pars);
//alert('placeholder_'+method_service_value);
var myAjax = new Ajax.Updater(

 'placeholder_USPS_Express',
url,
{method: 'post', parameters: pars,  onSuccess: function() {$('notification').style.display = "none";$('submit_button').disabled=false;	
        //alert('placeholder_'+method_service_value.innerHTML.value)
        
        }


	});
	
	
}	

function set_method_service(method_service)
{
	
	//var method_service="UPS_GND";
	var i;
	//alert(method_service);
	var met=document.forms[0].method_service;
	//var met=$("method_service[]");
		var checkvar=false;
		//alert(met[1].value);
		//alert(met.length);
		//alert(met[1].checked);
		for(i=0; i<met.length; i++)
		{
		
			if(met[i].value==method_service) met[i].checked=true;
			
		}
}


//credit card validation

function testCreditCard (myCardNo,  myCardType) {
  //alert(myCardNo);
  
  if (checkCreditCard (myCardNo,myCardType)) {
  
    //alert ("Credit card has a valid format")
  } 
  else {
  	//alert (ccErrors[ccErrorNo])
  	WAAddError($("scard_number"),ccErrors[ccErrorNo],$("scard_number"),3);
  	};
}

function hide_weights_total()
{
$("dimensional_weight_place").style.display="inline";
$("total_weight_place").style.display="none";
}

function hide_weights_dim()
{
$("dimensional_weight_place").style.display="none";
$("total_weight_place").style.display="inline";
}

function check_fields_paypal()
{
	WAValidateRQ($("billing_firstname"),'- billing first name is required',$("billing_firstname"),3,true,'text');
	WAValidateRQ($("shipping_firstname"),'- shipping first name is required',$("shipping_firstname"),3,true,'text');
WAValidateRQ($("shipping_lastname"),'- shipping last name is required',$("shipping_lastname"),3,true,'text');
WAValidateRQ($("shipping_address1"),'- shipping address 1 is required',$("shipping_address1"),3,true,'text');
WAValidateRQ($("shipping_city"),'- shipping city is required',$("shipping_city"),3,true,'text');
WAValidateZC($("shipping_zip"),'- invalid shipping  zip code',true,true,true,true,'',$("shipping_zip"),3,true);
WAValidateRQ($("shipping_country"),'- shipping  country is required',$("shipping_country"),3,true,'select');
if ($("shipping_country").value=="US")
{
WAValidateRQ($("state-province-usa"),'- shipping state is required',$("state-province-usa"),3,true,'select');
}
else if ($("shipping_country").value=="CA")
	{
WAValidateRQ($("state-province-can"),'- shipping state is required',$("state-province-can"),3,true,'select');
	
	}
else
	{
	WAValidateRQ($("state-province-txt"),'- shipping state is required',$("state-province-txt-billing"),3,true,'text');
	}
	checkPhones();	
checkPhones_shipping();
checkShippingmethod();
	WAAlertErrors('The following errors were found','Correct invalid entries to continue',true);
	return document.MM_returnValue;
	return true;
}

function check_fields_paypal_shipping_club()
{
	WAValidateRQ($("billing_firstname"),'- billing first name is required',$("billing_firstname"),3,true,'text');
	

	checkPhones();	

	WAAlertErrors('The following errors were found','Correct invalid entries to continue',true);
	return document.MM_returnValue;
	return true;
}

function check_fields_paypal_instore()
{
	WAValidateRQ($("billing_firstname"),'- billing first name is required',$("billing_firstname"),3,true,'text');
	
	

		checkPhones();	

		WAAlertErrors('The following errors were found','Correct invalid entries to continue',true);
		return document.MM_returnValue;
		return true;
}


function validate_instore()
{
WAValidateRQ($("billing_firstname"),'- billing first name is required',$("billing_firstname"),3,true,'text');
WAValidateRQ($("billing_lastname"),'- billing last name is required',$("billing_lastname"),3,true,'text');
WAValidateRQ($("billing_address1"),'- billing address 1 is required',$("billing_address1"),3,true,'text');
WAValidateRQ($("billing_city"),'- billing city is required',$("billing_city"),3,true,'text');
WAValidateZC($("billing_zip"),'- invalid billing  zip code',true,true,true,true,'',$("billing_zip"),3,true);
WAValidateRQ($("billing_country"),'- billing  country is required',$("billing_country"),3,true,'select');


if ($("billing_country").value=="US")
{
WAValidateRQ($("state-province-usa-billing"),'- billing  state is required',$("state-province-usa-billing"),3,true,'select');
}
else if ($("billing_country").value=="CA")
	{
WAValidateRQ($("state-province-can-billing"),'- billing  state is required',$("state-province-can-billing"),3,true,'select');
	
	}
else
	{
	WAValidateRQ($("state-province-txt-billing"),'- billing state is required',$("state-province-txt-billing"),3,true,'text');
	};


WAValidateRQ($("card_fname"),'- credit card first name is required',$("card_fname"),3,false,'text');
WAValidateRQ($("card_lname"),'- credit card last name is required',$("card_lname"),3,true,'text');
WAValidateRQ($("card_cv2"),'- security no is required',$("card_cv2"),3,true,'text');
//WAValidateCC($("card_number"),'- invalid credit card number','','4:51:52:53:54:55:34:37:6011:',$("card_number"),3,true);



checkPhones();	

WAAlertErrors('The following errors were found','Correct invalid entries to continue',true,document.frm);return document.MM_returnValue;

		return true;
}


function werwer()
{

if ($("show_all_shipping").checked==true)
	{
	clear_shipping();
	$("all_shipping").style.display="inline";
	
	//copy_data_to_shipping();
	
	}
if ($("show_all_shipping").checked==false)
{
//copy_data_to_shipping();
clear_shipping();
$("all_shipping").style.display="none";

}
}

function replace_button()
{
$("submit_button").style.display="none";	
$("notification_button").style.display="inline";
}

function show_order_total()
{
	//alert('calculating...');
	var url="checkout.php";
var pars = "mode=show_order_total";

var myAjax = new Ajax.Updater(

{success: 'order_total_place'},
url,
{method: 'get', parameters: pars,onSuccess:function(){$('submit_block').style.display='block';}, onFailure: reportError


	});
}

function clear_shipping()
{


$("shipping_firstname").value="";
$("shipping_lastname").value="";
$("shipping_company").value="";
$("shipping_address1").value="";
$("shipping_address2").value="";
$("shipping_city").value="";
$("state-province-txt").value="";
$("shipping_zip").value="";
$("shipping_phone1").value="";
$("shipping_phone2").value="";
$("shipping_phone3").value="";
$("shipping_phone1").disabled=false;
$("shipping_phone2").disabled=false;
$("shipping_phone3").disabled=false;
$("shipping_int_phone1").value="";
$("shipping_int_phone2").value="";
$("shipping_int_phone3").value="";
selchoice($("state-province-usa"),"");
selchoice($("state-province-can"),"");
selchoice($("shipping_country"),"US");
$("state-province-can").style.display="none";
$("state-province-usa").style.display="inline";
$("usphone_place").style.display="inline";
$("intphone_place").style.display="none";


}
