function checkShippingInfo()
{
	error = "";
	
	if (document.shipping_form.firstname.value==""){
		error += "First Name\n";
	}
	if (document.shipping_form.lastname.value==""){
		error += "Last Name\n";
	}
	if (document.shipping_form.address1.value==""){
		error += "Address Line 1\n";
	}
	if (document.shipping_form.city.value==""){
		error += "City\n";
	}
	if (document.shipping_form.state.value==""){
		if (document.shipping_form.us_state.value=="")
			error += "State\n";
	}
	if (document.shipping_form.country.value==""){
		error += "Country\n";
	}
	if (document.shipping_form.postalcode.value==""){
		error += "Postal Code\n";
	}
	if (document.shipping_form.email.value==""){
		error += "Email\n";
	}
	else if(!emailcheck(document.shipping_form.email.value)){
		error += "A Valid Email\n";
	}
	if (document.shipping_form.phone.value==""){
		error += "Phone\n";
	}
	
	if (error == "") return true;
	else {
		alert("Please enter:\n"+error);
		return false;
	}
}

//for tell a friend's page
function checkContactForm(){
	error = "";
	if (document.tell_a_friend_form.sendername.value==""){
		error += "Your Name\n";
	}
	if (document.tell_a_friend_form.recipientname.value==""){
		error += "Your Friend's Name\n";
	}
	if (document.tell_a_friend_form.recipientemail.value==""){
		error += "Your Friend's Email Address\n";
	}
	else if(!emailcheck(document.tell_a_friend_form.recipientemail.value)){
		error += "A Valid Email\n";
	}
	if (error == "") return true;
	else {
		alert("Please enter:\n"+error);
		return false;
	}
}

//to display dropdown list of US's 50 states when user chooses country = US
function isUS(obj) { 
 if (!document.layers) { 
 	var other_state = document.getElementById("state"); 
	 var us_state = document.getElementById("us_state"); 
	 if (obj.value == "US") { 
		 us_state.style.display = "inline"; 
		 other_state.style.display = "none";		 
	 } else { 
		 us_state.style.display = "none"; 
		 other_state.style.display = "inline";
 	} 
 } 
} 

//to calculate the total charges for order
function printTotal(obj)
{
	var subTotal = document.getElementById("subTotal"); 
	var shipping = obj.value;
	var total = document.getElementById("total");
	var shipping_total = document.getElementById("shipping_total");
	var currency = document.getElementById("currency").value;
	var proceed = document.getElementById("proceed");
	
	if (shipping != -1){
		var sum = Math.round((parseFloat(subTotal.value) + parseFloat(shipping))*100)/100;
		total.innerHTML = subTotal.value + " + " + shipping + " = " + sum.toFixed(2) + " " + currency; 
		shipping_total.value = shipping;
		proceed.value = "";
	}
	else {
		total.innerHTML = "You cannot check out."; 
	}	
}

function validateCheckout()
{	
	if (document.getElementById("proceed").value=="false"){		
		error = "We cannot proceed with your shopping cart.\nPlease contact us at store@mybagspa.com.";
		alert(error);
		return false;
	}
	return true;
}

function emailcheck(str) { //check the validation of the email
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
}
