// JavaScript Document


function hideErrors(){
	hideEmailError();
	hideZipError();
}

function hideEmailError(){
	var x = document.getElementsByTagName('div');	
	for (var i=0;i<x.length;i++){
		if (x[i].className == 'emailError'){
			x[i].style.display = 'none';
		}
	}	
}
function hideZipError(){
	var x = document.getElementsByTagName('div');	
	for (var i=0;i<x.length;i++){
		if (x[i].className == 'zipError'){
			x[i].style.display = 'none';
		}
	}	
}


function checkForm(){
	var isGood = true;
	if(checkEmail() != "good"){
		isGood = false;
	}
	if(checkZip() != "good"){
		isGood = false;
	}
	if(isGood){
		$('form').submit();
	}else{
		return false;
	}
}

function checkEmail() {
		
		isGood = true;
		
		str = document.Form.emailAddress.value;
		//alert("Please enter your first name.");
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.length < 3){
		   //alert("Invalid E-mail ID")
		   isGood = false
		}

		if (str.indexOf(at)==-1){
		   //alert("Invalid E-mail ID")
		   isGood = false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   //alert("Invalid E-mail ID")
		   isGood = false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    //alert("Invalid E-mail ID")
		    isGood = false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //alert("Invalid E-mail ID")
		    isGood = false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //alert("Invalid E-mail ID")
		    isGood = false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //alert("Invalid E-mail ID")
		    isGood = false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    //alert("Invalid E-mail ID")
		    isGood = false
		 }
		 
		 
		var x = document.getElementsByTagName('div');

		if(!isGood){
			for (var i=0;i<x.length;i++){
				if (x[i].className == 'emailError'){
					x[i].style.display = 'block';
				}
			}
			return false;
		}else{
	
			for (var i=0;i<x.length;i++){
				if (x[i].className == 'emailError'){
					x[i].style.display = 'none';
				}
			}
 		return "good";					
	}

		//document.theForm.submit();
	}

function checkZip(field) {
	isGood = true;
	/*field = document.Form.ShipTo.value;
	
	var valid = "0123456789-";
	var hyphencount = 0;
	
	if (field.length!=5 && field.length!=10) {
	//return("Please enter your 5 digit or 5 digit+4 zip code.");
	isGood = false;
	}
	for (var i=0; i < field.length; i++) {
	temp = "" + field.substring(i, i+1);
	if (temp == "-") hyphencount++;
	if (valid.indexOf(temp) == "-1") {
	//return("Invalid characters in your zip code.  Please try again.");
	isGood = false;
	}
	if ((hyphencount > 1) || ((field.length==10) && ""+field.charAt(5)!="-")) {
	//return("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
	isGood = false;
	   }
	}
	var x = document.getElementsByTagName('div');	

	if(!isGood){
		for (var i=0;i<x.length;i++){
			if (x[i].className == 'zipError'){
				x[i].style.display = 'block';
			}
		}
	}else{
		for (var i=0;i<x.length;i++){
			if (x[i].className == 'zipError'){
				x[i].style.display = 'none';
			}
		}
	}*/
	
	return "good";
	
}


	
	
	
	
