function checkForm(form){

	var errors = new Array;
	
	with (form){
	
		if (Trim(Fname.value) == "") errors.push("Fname");
		if (Trim(Lname.value) == "") errors.push("Lname");
		if (Trim(Email.value) == "") errors.push("Email");
		if (Trim(ConfirmEmail.value) == "") errors.push("ConfirmEmail");
		if (CheckPhone(DayArea.value,3)) errors.push("DayArea");
		if (CheckPhone(DayPrefix.value,3)) errors.push("DayPrefix");
		if (CheckPhone(DaySuffix.value,4)) errors.push("DaySuffix");
		//if (CheckPhone(DayExtension.value)) errors.push("DayExtension");
		if (Trim(Addr1.value) == "") errors.push("Addr1");
		if (Trim(City.value) == "") errors.push("City");
		if (Trim(State.selectedIndex) == 0) errors.push("State");
		if (Trim(Zip.value) == "" || Zip.value.length != 5) errors.push("Zip");
		if (Trim(EngineNo.value) == "" || EngineNo.value.length != 3) errors.push("EngineNo");
		if (Trim(AuthCode.value) == "" || AuthCode.value.length != 8) errors.push("AuthCode");
		
		if (Trim(Email.value) == ""){
			errors.push("Email");
		}
		else if (BadEmail(Email.value)){
			errors.push("Email");
		}
		else if(Email.value != ConfirmEmail.value ){
			errors.push("Email");
			errors.push("ConfirmEmail");
			document.getElementById("errorConfirmEmail").style.display = "block";
		}
	}
	
	if (errors.length){
	
		resetFields();
		illuminateFields(errors);
		
		document.getElementById("error").style.display = "block";
			
		return false;
	}
	else {
		return true;
	}
}

function resetFields (){

	var fields = new Array("Fname","Lname","Email","ConfirmEmail","DayArea","DayPrefix","DaySuffix","DayExtension","Addr1","City","State","Zip","EngineNo","AuthCode");
	var len = fields.length;
	
	for (var i = 0; i < len; i++) 
	{
		var elm = document.getElementById(fields[i])
		elm.className = "";
	}
}


function illuminateFields (errors){

	var len = errors.length;
	for (var i = 0; i < len; i++) 
	{
		var elm = document.getElementById(errors[i]);
		elm.className = "error";
	}
}

function CheckPhone(str,len){

	// len is optional. If we don't supply it, we don't check the length
	
	// strip out acceptable non-numeric characters
	var stripped = str.replace(/[\(\)\.\-\ ]/g, '');
	
	// numeric check
	if (isNaN(parseInt(stripped))) {
	   return true;
	}
	else if (len) {
		// Length Check
		if (stripped.length != len){
			return true;
		}
	}
}

function BadEmail(str){
	var regexp = "";
	regexp = /@.*@/;
	if (regexp.test(str)) return true;
	regexp = /[, ;]/;
	if (regexp.test(str)) return true;
	regexp = /.+@[A-Za-z0-9\-]+\.[A-Za-z0-9\-.]*$/;
	if (regexp.test(str)) return false;
	return true;
}

function Trim(str){
	var regexp = "";
	regexp = / $/;
	while (regexp.test(str)) str = str.substr(0,str.length - 1);
	regexp = /^ /;
	while (regexp.test(str)) str = str.substr(1);
	return str;
}