function valEmail(el) {
	var invalidChars = " /:,;";
 	if (el.value == "") {
   		alert("Please enter your email address.");
		el.focus();
		return (true);
	}
	for (i=0; i<invalidChars.length; i++) {
		badChar = invalidChars.charAt(i);
    	if (el.value.indexOf(badChar,0) != -1) {
		   	alert("Your email address contains an invalid character, please correct it.");
			el.focus();
			return (true);
	    }
	}
	atPos = el.value.indexOf("@",1);
	if (atPos == -1) {
	   	alert("The email address you entered is invalid.");
		el.focus();
		return (true);
	}
	if (el.value.indexOf("@",atPos+1) != -1) {
	   	alert("The email address you entered is invalid.");
		el.focus();
		return (true);
	}
	periodPos = el.value.indexOf(".",atPos);
	if (periodPos == -1) {
	   	alert("The email address you entered is invalid.");
		el.focus();
		return (true);
	}
	if (periodPos+3 > el.value.length) {
	   	alert("The email address you entered is invalid.");
		el.focus();
		return (true);
	}
	return (false);
}
function checkZip(value)
{
	var first = value.substring(0,1); 
	var second = value.substring(1,2); 
	var third = value.substring(2,3); 
	var fourth = value.substring(3,4); 
	var fifth = value.substring(4,5); 
	switch (first) 
	{
	case "0": break;
	case "1": break;
	case "2": break;
	case "3": break;
	case "4": break;
	case "5": break;
	case "6": break;
	case "7": break;
	case "8": break;
	case "9": break;
	default: return false;
	}
	switch (second) 
	{
	case "0": break;
	case "1": break;
	case "2": break;
	case "3": break;
	case "4": break;
	case "5": break;
	case "6": break;
	case "7": break;
	case "8": break;
	case "9": break;
	default: return false;
	}
	switch (third) 
	{
	case "0": break;
	case "1": break;
	case "2": break;
	case "3": break;
	case "4": break;
	case "5": break;
	case "6": break;
	case "7": break;
	case "8": break;
	case "9": break;
	default: return false;
	}
	switch (fourth) 
	{
	case "0": break;
	case "1": break;
	case "2": break;
	case "3": break;
	case "4": break;
	case "5": break;
	case "6": break;
	case "7": break;
	case "8": break;
	case "9": break;
	default: return false;
	}
	switch (fifth) 
	{
	case "0": break;
	case "1": break;
	case "2": break;
	case "3": break;
	case "4": break;
	case "5": break;
	case "6": break;
	case "7": break;
	case "8": break;
	case "9": break;
	default: return false;
	}
	return true;
}
	
function validateZip(zipelement)
	{
		zipelement.style.backgroundColor = 'white';
		
	//alert("hello from validate zip");
	        len=zipelement.value.length
           if(len < 5 || len > 10)
                {
                 alert("Zip code is not the correct length")
				 	zipelement.focus();
					zipelement.style.backgroundColor = 'red';
					return false;
				}
            first5digits = zipelement.value.substr(0,5)
            //if (first5digits != parseInt(first5digits))
			if (!checkZip(first5digits))
            {
				//alert(!checkZip(first5digits))
                alert("The first five digits of the zip code have to be numeric")
					zipelement.focus();
					zipelement.style.backgroundColor = 'red';
					return false;
			}
	
	}
function checkout(){
ordForm =  document.getElementById('orderform');
ordForm.first_name.style.backgroundColor = 'white';
ordForm.last_name.style.backgroundColor = 'white';
ordForm.address.style.backgroundColor = 'white';
ordForm.city.style.backgroundColor = 'white';
ordForm.state.style.backgroundColor = 'white';
ordForm.zip.style.backgroundColor = 'white';
ordForm.phone.style.backgroundColor = 'white';
ordForm.email.style.backgroundColor = 'white';


    if(ordForm.first_name.value == "")
	{
		alert("First name is required.");
		ordForm.first_name.focus();
		ordForm.first_name.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.last_name.value == "")
	{
		alert("Last name is required.");
		ordForm.last_name.focus();
		ordForm.last_name.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.address.value == "")
	{
		alert("Address is required.");
		ordForm.address.focus();
		ordForm.address.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.city.value == "")
	{
		alert("City is required.");
		ordForm.city.focus();
		ordForm.city.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.state.value == "")
	{
		alert("You must select a state.");
		ordForm.state.focus();
		ordForm.state.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.zip.value == "")
	{
	    
		alert("Zip code is required.");
		ordForm.zip.focus();
		ordForm.zip.style.backgroundColor = 'red';
		return false;
	}
	else 
	{if (validateZip(ordForm.zip) == false )
	            	return false;
	}
	phn = ordForm.phone.value;
	//alert(phn.length);
	if(phn.length < 10)
	{
	    
		alert("A valid Phone number is required.");
		ordForm.phone.focus();
		ordForm.phone.style.backgroundColor = 'red';
		return false;
	}
	if(ordForm.email.value == "")
	{
	    
		alert("Email is required.");
		ordForm.email.focus();
		ordForm.email.style.backgroundColor = 'red';
		return false;
	}
	else{if(valEmail(ordForm.email) == true)
	{
		ordForm.email.style.backgroundColor = 'red';
		return(false);
	}}
	ordForm.submit();
}