// JavaScript Document
function infoCheck(formInfo){//1
	var chkName1;
	var chkName2;
	var	chkaddress;
	var chkCity;
	var chkZip;
	var chkEMail;
	var chkMessage;
	var chkQuestion;
	
	chkName1=document.getElementById("firstName");
	chkName2=document.getElementById("lastName");
	chkaddress=document.getElementById("address1");
	chkCity=document.getElementById("city");
	chkZip=document.getElementById("zip");
	chkEMail=document.getElementById("eMail");
	chkMessage=document.getElementById("message");
	chkQuestion=document.getElementById("question");
	//////////////////////////////////////////Function Check for character type////////////////////////////////////////1	
	function checkCharType(charToCheck)
	{//2
	var returnValue="";
	if(charToCheck=="")
	{
	returnValue="E"
	}
	else 
	{//3
	for(counter=0; counter<=charToCheck.length-1; counter++)
	{//4
	if (charToCheck.charCodeAt(counter) >="A".charCodeAt(0) && charToCheck.charCodeAt(counter)<="Z".charCodeAt(0))
	{
	returnValue="U"
	}
	else if(charToCheck.charCodeAt(counter) >="a".charCodeAt(0) && charToCheck.charCodeAt(counter)<="z".charCodeAt(0))
	{
	returnValue="L"
	}
	else if(charToCheck.charCodeAt(counter) >="0".charCodeAt(0) && charToCheck.charCodeAt(counter)<="9".charCodeAt(0))
	{
	returnValue="N"
	//break;
	}
	else
	{
	returnValue="o"
	//break;
	}
	}//4
	}//3
	return returnValue;
	}//2	
	//////////////////////////////////////Check form info values with above function//////////////////////////////////////////////////////////////////////
	var userInfo;
	
	if (checkCharType(chkName1.value)=="N")
	{
	alert("Numerical characters aren't allowed in the first name field.");
	userInfo="bad"
	}
	else if(checkCharType(chkName1.value)=="o")
	{
	alert("The first name field contains invalid characters.");
	userInfo="bad"
	}
	else if(checkCharType(chkName1.value)=="E")
	{
	alert("The first name field is empty.");
	userInfo="bad"
	}
	else if(checkCharType(chkName2.value)=="N")
	{
	alert("Numerical characters aren't allowed in the last name field.");
	userInfo="bad"
	}
	else if(checkCharType(chkName2.value)=="o")
	{
	alert("The last name field contains invalid characters.");
	userInfo="bad"
	}
	else if(checkCharType(chkName2.value)=="E")
	{
	alert("The last name field is empty.");
	userInfo="bad"
	}
	else if(checkCharType(chkQuestion.value)=="E")
	{
		alert("The question was not answered.");
		userInfo="bad"
	}
	else if(checkCharType(chkQuestion.value)!="N")
	{
		alert("The question needs to be answered with a number");
		userInfo="bad"
	}
/*	
	else if(checkCharType(chkCity.value)=="N")
	{
	alert("Numerical characters aren't allowed in the city field.");
	userInfo="bad"
	}
	else if(checkCharType(chkCity.value)=="o")
	{
	alert("The City field contains invalid characters.");
	userInfo="bad"
	}
	else if(checkCharType(chkCity.value)=="E")
	{
	alert("The city name field is empty.");
	userInfo="bad"
	}
	else if(checkCharType(chkZip.value)=="U"||checkCharType(chkZip.value)=="L")
	{
	alert("Letters aren't allowed in the zip code field.");
	userInfo="bad"
	}
	else if(checkCharType(chkZip.value)=="o")
	{
	alert("The zip code field contains invalid characters.");
	userInfo="bad"
	}	
*/	
	else{//5
	userInfo="good"
	}
	//////////////////////Function Check email address//////////////////////////////////////////////
	function validEmail(email){//a
	
	var invalidChars = "!#$%^&*()+=-[]\\\';,/{}|\":<>?";
	
	if(email==""){
	return false;
	
	}
	
	for(i=0; i<invalidChars.length; i++){
	badChar = invalidChars.charAt(i)
	if(email.indexOf(badChar,0) > -1){
	return false;
	}
	}
	
	atPos = email.indexOf("@",1);
	if(atPos == -1){
	return false;
	}
	
	if(email.indexOf("@",atPos+1) > -1){ 
	return false;
	}
	
	dotPos = email.indexOf(".",atPos);
	if(dotPos == -1 || dotPos == atPos+1){
	return false;
	}
	
	if(dotPos+3 > email.length){
	return false;
	}
	
	if(email.indexOf(".",0) < dotPos){
	return false;
	}
	return true;
	}//a
	//////////////////////////////Check E-Mail and userInfo///////////////////////////
	if(userInfo=="bad"){
	return false
	}
	else  if(!validEmail(chkEMail.value)){
	alert("Invalid email address")
	return false;
	}
	}//1
	///////////////////////////////////////End Script//////////////////////////////////////////////
	
	
