// JavaScript Document

function checkName (strng, s) {
	var error = "";
	if (strng.length == 0) {
		 error = "You must fill in your name please.\n"
	}
	return error;	
}  

function checkLastName (strng, s) {
	var error = "";
	if (strng.length == 0) {
		 error = "You must fill in your last name please.\n"
	}
	return error;	
}  

function checkFirstName (strng, s) {
	var error = "";
	if (strng.length == 0) {
		 error = "You must fill in your first name please.\n"
	}
	return error;	
}  

function checkDealerCode (strng, s) {
	var error = "";
	if (strng.length == 0) {
		 error = "You must fill in your dealer code please.\n"
	}
	return error;	
}  

function checkRepCode (strng, s) {
	var error = "";
	if (strng.length == 0) {
		 error = "You must fill in your rep code please.\n"
	}
	return error;	
}  

function checkCompany (strng, s) {
	var error = "";
	if (strng.length == 0) {
		 error = "You must fill in your company please.\n"
	}
	return error;	
}  

function checkCity (strng, s) {
	var error = "";
	if (strng.length == 0) {
		 error = "You must fill in your city please.\n"
	}
	return error;	
}  

function checkPostalCode (strng, s) {
	var error = "";
	if (strng == "") {
		 error = "You must fill in a proper postal code please.\n"
	} else {
	var postalFilter=/^[a-zA-Z][0-9][a-zA-Z][0-9][a-zA-Z][0-9]$/;
		if (!(postalFilter.test(strng))) { 
			error = "Please enter a valid postal code.\n";
		} else {
			//test code for illegal characters
			var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
			if (strng.match(illegalChars)) {
				error = "The postal code contains illegal characters.\n";
			}
		}
	}
	return error;
}  

function checkPassword (strng, s) {
	var error = "";
	if (strng.length == 0) {
		 error = "You must fill in your password please.\n"
	}
	return error;	
}  

function checkAddress (strng, s) {
	var error = "";
	if (strng.length == 0) {
		 error = "You must fill in your address please.\n"
	}
	return error;	
}  

function checkEmail (strng) {
	var error="";
	if (strng == "") {
	error = "You didn't enter an email address.\n";
	} else {
	var emailFilter=/^.+@.+\..{2,3}$/;
		if (!(emailFilter.test(strng))) { 
			error = "Please enter a valid email address.\n";
		} else {
			//test email for illegal characters
			var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/;
			if (strng.match(illegalChars)) {
				error = "The email address contains illegal characters.\n";
			}
		}
	}
	return error;    
}

function checkPhone (strng, s) {
	var error = "";
	if (strng == "") {
		 error = "You didn't enter a phone number.\n";
	} else {
		var stripped = strng.replace(/[\(\)\.\-\ ]/g, ''); //strip out acceptable non-numeric characters
	if (isNaN(parseInt(stripped))) {
	   error = "The phone number contains illegal characters.";
	}
	if (!(stripped.length == 10)) {
		error = "The phone number is the wrong length. Make sure you included an area code.\n";
		} 
	}
	return error;
}

function checkIdenticalPasswords (strng, strng2, s) {
	var error = "";
	if (strng != strng2) {
		 error = "Your passwords do not match.\n"
	}
	return error;	
}  

function checkForm(theForm) {
	var why = "";
	var checkvalue = "";
	
	why += checkEmail(theForm.txtEmail.value, "E-mail");
	why += checkPassword(theForm.txtPassword.value, "Password");
		
	if (why != "") {
		alert(why);
		return false;
	}
		return true;
}

function checkForm2(theForm) {
	var why = "";
	var checkvalue = "";
	
	why += checkLastName(theForm.txtLastName.value, "Last Name");
	why += checkFirstName(theForm.txtFirstName.value, "Last Name");
	why += checkDealerCode(theForm.txtDealerCode.value, "Dealer Code");
	why += checkRepCode(theForm.txtRepCode.value, "Rep Code");
	why += checkCompany(theForm.txtCompany.value, "Company");
	why += checkCity(theForm.txtCity.value, "City");
	why += checkPostalCode(theForm.txtPostalCode.value, "Postal Code");
	why += checkEmail(theForm.txtEmailRegister.value, "E-mail");
	why += checkPhone(theForm.txtPhone.value, "Phone");
	why += checkPassword(theForm.txtPassword1.value, "Password");
	why += checkPassword(theForm.txtPassword2.value, "Password");
	why += checkIdenticalPasswords(theForm.txtPassword1.value, theForm.txtPassword2.value, "Password");
	
	if (why != "") {
		alert(why);
		return false;
	}
		return true;
}

function checkForm3(theForm) {
	var why = "";
	var checkvalue = "";
	
	why += checkEmail(theForm.txtEmail.value, "E-mail");
		
	if (why != "") {
		alert(why);
		return false;
	}
		return true;
}

function checkForm4(theForm) {
	var why = "";
	var checkvalue = "";
	
	why += checkLastName(theForm.txtLastName.value, "Last Name");
	why += checkFirstName(theForm.txtFirstName.value, "Last Name");
	why += checkCompany(theForm.txtCompany.value, "Company");
	why += checkCity(theForm.txtCity.value, "City");
	why += checkPostalCode(theForm.txtPostalCode.value, "Postal Code");
	why += checkEmail(theForm.txtEmailSalesCall.value, "E-mail");
	why += checkPhone(theForm.txtPhone.value, "Phone");
	
	if (why != "") {
		alert(why);
		return false;
	}
		return true;
}
