
/* JavaScript functions for validating form */

function validData(contactFrm){
	
	
	var error_string = "";
	
	// check the name fields
	if ((document.contactFrm.realname.value == '')|| (document.contactFrm.realname.value.length <=1)){
		error_string += "Your name.\n";
		document.getElementById("nameLbl").style.color="#FF0000";
			
	}else{	
		document.getElementById("nameLbl").style.color="#000";
	}


	//check address field
	if ((document.contactFrm.address.value =='')||(document.contactFrm.address.value.length <=1)){
		error_string += "Your address.\n";
		document.getElementById("addrLbl").style.color="#FF0000";
	}else{	
		document.getElementById("addrLbl").style.color="#000";
	}


	//check city field
	if ((document.contactFrm.city.value =='')||(document.contactFrm.city.value.length <=1)){
		error_string += "Your city.\n";
		document.getElementById("cityLbl").style.color="#FF0000";
	}else{	
		document.getElementById("cityLbl").style.color="#000";
	}
	
	//check state information
	if(isChosen(document.contactFrm.state)==false){
		
		error_string += "Your state.\n";
		document.getElementById("steLbl").style.color="#FF0000";
	}else{
		document.getElementById("steLbl").style.color="#000";
	}	
	
	//check zipcode
	
	if (checkZip(document.contactFrm.zip.value)== true){
		error_string += "Your zipcode.\n";
		document.getElementById("zipLbl").style.color="#FF0000";
	}else{	
		document.getElementById("zipLbl").style.color="#000";
	}
	
	//check phone
	if (checkPhone(document.contactFrm.phone.value) == true){
		error_string += "Your phone number.\n";
		document.getElementById("phoneLbl").style.color="#FF0000";
	}else{	
		document.getElementById("phoneLbl").style.color="#000";			
		}
	
	//check e-mail
		
		if (checkEmail(document.contactFrm.email.value) == true){
			error_string += "Your e-mail address.\n";	
			document.getElementById("emailLbl").style.color="#FF0000";
		}else{	
		document.getElementById("emailLbl").style.color="#000";
	}
	
	
     

		
	if(error_string ==""){


		return true;
	}
	
	else{
		error_string = "Some information was not filled out. Please complete the form.: \n" +error_string;
		alert(error_string);
		document.contactFrm.realname.focus();
		return false;
	}
}	
	
	
function checkPhone(numString){
	
	var regex=/^\(?\d{3}\)?-?\s*\d{3}\s*?-?\d{4}$/;
	
	if(!(regex.test(numString))){
		return true;
	}
	
}


function checkEmail(addy){
	
	var regex=/^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
	if (!(regex.test(addy)))
	{
		return true;
	}

}


function checkZip(zipcode){
	var regex=/^\d{5}$/;
	if(regex.test(zipcode)==false)
	{
		return true;
	}
	
}


//validate select element
function isChosen(select){
	if(select.selectedIndex==0){
		return false;
	}else{
		return true;
	}
}
