// JavaScript Document
function checkForm(f){
	msg="";
	if (f.CustomerName.value.length < 3)
		msg+="Enter Name\n";
	if (f.BusinessAddress.value.length < 6)
		msg+="Enter Address.\n";
	if (f.BusinessCity.value.length < 3)
		msg+="Enter City.\n";
	if (f.BusinessState.selectedIndex < 1)
		msg+="Enter State.\n";
	if (f.BusinessZip.value.length < 5)
		msg+="Enter Zip.\n";
	validatePhoneNbr(f.PhoneNumber.value, "Phone Nbr");
	validateEmail(f.Email.value, "Email");
	if (f.Email.value != f.ConfirmEmail.value)
		msg+="Email's do not match.\n";
			   
// if Error display alert
	if (msg){
		alert("Fix these error(s):\n"+ msg);
		return false;
	}else{
		return true;
	}
}


function validatePhoneNbr(n, lit){
	if ((!n) || (n.length < 5))
		msg+="Please fill in "+ lit +" field.\n";
	else{
		j=0;
		for (k=0; k < n.length; k++){
			x=parseInt(n.charAt(k));
			if ((x < 10) && (x ==n.charAt(k))) {
				j++;
			}
		}
		if ((j < 10) || (n.length < 12))
			msg+="Please include Area Code with "+ lit +"\n            (i.e. 123-456-7890)\n";
	}
}

function validateEmail(e, lit){
// verify that the e-mail address has at least this format xx\@xx.xx
	i=e.indexOf('@',0)
	j=e.indexOf('.',i)
	if ((i < 2) || (j < 5) || (e.length < 7)){
		msg+="Enter a proper "+lit+" (i.e. joe\@abc.com)\n";
		return;
	}
	if (((j-i) < 3) || ((e.length - j) < 3)){
		msg+="Enter a proper "+lit+" (i.e. joe\@abc.com)\n";
		return;
	}
}
