


function IsAlphaNumeric(sText)

{
   var ValidChars = "abcdefghijklmnopqrstuvqwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 @_-,.";
  
   var Char;

 
   for (i = 0; i < sText.length; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
		 alert('All fields may only contain letters, numbers and the following special characters: "@_-,.".');
         return false;
         }
      }
   return true;
   
   }


  function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
		 alert('Please enter a valid zip code.');
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }




function validateZip(){

	var x=document.forms["shipping_info" ]["zip"].value;
	
	var temp = x.length;
	
	IsNumeric(x);
	
	if (x.length!=5)
	  {
	   alert("Please enter a valid Zip code");
	  return false;
	  }
}



function validateForm()
{
var x=document.forms["shipping_info" ]["first_name"].value;
	if (IsAlphaNumeric(x));
	else return false;
	
	
	
	if (x==null || x=="")
	  {
	  alert("First name is required.");
	  return false;
	  }
	
  
var x=document.forms["shipping_info" ]["last_name"].value;

if (IsAlphaNumeric(x));
else return false;

if (x==null || x=="")
  {
  alert("Last name is required.");
  return false;
  }
  
  
var x=document.forms["shipping_info" ]["address1"].value;

if (IsAlphaNumeric(x));
else return false;

if (x==null || x=="")
  {
  alert("Address line 1 is required.");
  return false;
  }
  
  
  
var x=document.forms["shipping_info" ]["city"].value;

if (IsAlphaNumeric(x));
else return false;

if (x==null || x=="")
  {
  alert("City is required.");
  return false;
  }
  

  
var x=document.forms["shipping_info" ]["zip"].value;

if (IsAlphaNumeric(x));
else return false;

if (x==null || x=="")
  {
  alert("Zip code is required.");
  return false;
  }
  
var x=document.forms["shipping_info" ]["night_phone_a"].value;

if (IsAlphaNumeric(x));
else return false;

if (x==null || x=="")
  {
  alert("Phone number is required.");
  return false;
  }
  
  
  
var x=document.forms["shipping_info" ]["night_phone_b"].value;

if (IsAlphaNumeric(x));
else return false;

if (x==null || x=="")
  {
  alert("Phone number is required");
  return false;
  }
 
  
var x=document.forms["shipping_info" ]["night_phone_c"].value;

if (IsAlphaNumeric(x));
else return false;

if (x==null || x=="")
  {
  alert("Phone number is required");
  return false;
  }

  
var x=document.forms["shipping_info" ]["email"].value;

if (IsAlphaNumeric(x));
else return false;

if (x==null || x=="")
  {
  alert("Email is required");
  return false;
  }
  

var x=document.forms["shipping_info" ]["shippingChoice"].value;
if (x =='0')
  {
  alert("Please choose a shipping option.");
  return false;
  }


  
}










function showBilling(){

	var checkboxChecked = document.getElementById('bill');
	var bForm = document.getElementById('billing_form').style;
	
	if (checkboxChecked.checked){
		
		bForm.display ="none";
		}
	else{
		
		bForm.display ="block";
		}

}





function shipSummary(){
var x = document.getElementById("shippingChoice").value;

var y = document.getElementById("shippingSum");
var z = document.getElementById("total").value;

var a = document.getElementById("order_total");
var oTotal = parseFloat(x)+parseFloat(z);

oTotal = oTotal.toFixed(2);
oTotal = oTotal.toString();
y.innerHTML = x;
a.innerHTML = oTotal;
//shipSend.innerHTML = x;



var sChoice = document.getElementById("shippingChoice");
		//	sChoice.value = 
		
}




	function showShipping()
{
	var xmlhttp;
	var ship_zip = document.getElementById("zip").value;
	var ship_weight = document.getElementById("testWeight").value;
	var ship_country = document.getElementById("country").value;
	var ship_size = document.getElementById("total_size").value;
	var ship_zip = ship_zip.split(' ').join('');
	
	if (ship_country == 'United States'){
		
		if (ship_zip.length==5){
			
			if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
				
				//document.getElementById("shipping").innerHTML=xmlhttp.responseText;
			
				var priority = document.getElementById("ship1");
				var priorityStyle = priority.style;
				priorityStyle.display="block";
				
				var parcel = document.getElementById("ship2");
				var parcelStyle = parcel.style;
				parcelStyle.display="block";
				
				var flatRate = document.getElementById("ship3");
				
				
				var temp = xmlhttp.responseText;
			
				var temp2 = temp.split(',');
				
				var priorityValue = '$' + temp2[0];
				var parcelValue = '$' + temp2[1];
				var flatValue = '$' + temp2[2];
				//if (parcelValue == '$'){
					//alert("Please enter a valid zip code");
					//}
				
				if (temp2[2] != 'na'){
					var flatRateStyle = flatRate.style;
					flatRateStyle.display="block";
					flatRate.value = temp2[2];
					flatRate.innerHTML ="Flat Rate - " + flatValue;
				
				}
				
				parcel.innerHTML ="Parcel Post - " + parcelValue;
				parcel.value = temp2[1];
				
				priority.innerHTML ="Priority Mail - " + priorityValue;
				priority.value = temp2[0];

				}
			  }
			xmlhttp.open("GET","ship_call.php?zip="+ship_zip+"&weight="+ship_weight+"&total_size="+ship_size,true);
			xmlhttp.send();
			
		} else {
		alert('Please enter a valid zip code');
		}
	
	
	
	} else {
	
		if (window.XMLHttpRequest)
			  {// code for IE7+, Firefox, Chrome, Opera, Safari
			  xmlhttp=new XMLHttpRequest();
			  }
			else
			  {// code for IE6, IE5
			  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			  }
			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
				{
				
				//document.getElementById("shipping").innerHTML=xmlhttp.responseText;
			
				var priority = document.getElementById("ship1");
				var priorityStyle = priority.style;
				priorityStyle.display="block";
				
				var parcel = document.getElementById("ship2");
				var parcelStyle = parcel.style;
				parcelStyle.display="block";
				
				
				var temp = xmlhttp.responseText;
				var temp2 = temp.split(',');
				
				var priorityValue = '$' + temp2[0];
				var parcelValue = '$' + temp2[1];
				
				priority.innerHTML ="Priority Mail - " + priorityValue;
				priority.value = temp2[0];
				
				parcel.innerHTML ="Parcel Post - " + parcelValue;
				parcel.value=temp2[1];
				
				
				}
			  }
			xmlhttp.open("GET","ship_call_intl.php?country="+ship_country+"&weight="+ship_weight,true);
			xmlhttp.send();
			
	
		
	}
}







function cForm(){
var firstNameV= document.getElementById('first_name').value;
var lastNameV= document.getElementById('last_name').value;
var address1V= document.getElementById('address1').value;
var address2V= document.getElementById('address2').value;
var cityV= document.getElementById('city').value;
var stateV= document.getElementById('state').value;
var emailV= document.getElementById('email').value;
var zipV= document.getElementById('zip').value;
var countryV= document.getElementById('country').value;
var phone1V= document.getElementById('night_phone_a').value;
var phone2V= document.getElementById('night_phone_b').value;
var phone3V= document.getElementById('night_phone_c').value;


var fv = document.getElementById('first_name_billing');
	fv.value = firstNameV;
var lv = document.getElementById('last_name_billing');
	lv.value = lastNameV;
var a1v = document.getElementById('address1_billing');
	a1v.value = address1V;
var a2v = document.getElementById('address2_billing');
	a2v.value = address2V;
var cv = document.getElementById('city_billing');
	cv.value = cityV;
var sv = document.getElementById('state_billing');
	sv.value = stateV;
var ev = document.getElementById('email_billing');
	ev.value = emailV;
var zv = document.getElementById('zip_billing');
	zv.value = zipV;

var ctv = document.getElementById('country_billing');
	ctv.value = countryV;

	
	
var p1v = document.getElementById('phone1_billing');
	p1v.value = phone1V;
var p2v = document.getElementById('phone2_billing');
	p2v.value = phone2V;
var p3v = document.getElementById('phone3_billing');
	p3v.value = phone3V;
	
	
	
/*	
var ppf = document.getElementById('ppFirstName');
	ppf.value = firstNameV;
var ppl = document.getElementById('ppLastName');
	ppl.value = lastNameV;
var ppa1 = document.getElementById('ppAddress1');
	ppa1.value = address1V;
var ppa2 = document.getElementById('ppAddress2');
	ppa2.value = address2V;
var ppc = document.getElementById('ppCity');
	ppc.value = cityV;
var pps = document.getElementById('ppState');
	pps.value = stateV;
var ppe = document.getElementById('ppEmail');
	ppe.value = emailV;
	
var ppz = document.getElementById('ppZip');
	ppz.value = zipV;
	
var ppp1 = document.getElementById('ppPhone1');
	ppp1.value = phone1V;
var ppp2 = document.getElementById('ppPhone2');
	ppp2.value = phone2V;
var ppp3 = document.getElementById('ppPhone3');
	ppp3.value = phone3V;

	
	*/
	
	
}

