
var containErrors = false;

function IsValidateEmail(Email) 
{
	var regEmail  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return regEmail.test(Email.replace(/\s/g, ""));
}

function ClearErrors()
{
	
	document.getElementById("divErrorBranch").style.display = "none";
	document.getElementById("divErrorName").style.display = "none";
	document.getElementById("divErrorAddress").style.display = "none";
	document.getElementById("divErrorContactNo").style.display = "none";
	document.getElementById("divErrorEmailAddress").style.display = "none";
	document.getElementById("divErrorSmoking").style.display = "none";
	document.getElementById("divErrorPets").style.display = "none";
	document.getElementById("divErrorFamilySize").style.display = "none";
	document.getElementById("divErrorWorking").style.display = "none";
	document.getElementById("divErrorJobTitle").style.display = "none";
	document.getElementById("divErrorLengthOfTenancy").style.display = "none";
	
	containErrors = false;
	
}

function SetError(divError, msg)
{
	
	document.getElementById(divError).style.display = "block";
	document.getElementById(divError).innerHTML = msg;
	
	containErrors = true;
}

function CheckRentalForm() 
{
	
	var form = document.getElementById("form1");
	var now = new Date();
	
	ClearErrors();
	
	if(form._account.selectedIndex <= 0)
		SetError("divErrorBranch", "You must select a branch");
	
	if(form.name.value.replace(/\s/g, "") == "")
		SetError("divErrorName", "You must enter your name");
	
	if(form.address.value.replace(/\s/g, "") == "")
		SetError("divErrorAddress", "You must enter your current postal address");
	
	if(form.contactNo.value.replace(/\s/g, "") == "")
		SetError("divErrorContactNo", "You must enter a contact number");
	
	else if(String(form.contactNo.value.replace(/\s/g,"")).search(/[^\d]/) > -1)
		SetError("divErrorContactNo", "Your contact number must only contain numbers without spaces");
	
	if(form.email.value.replace(/\s/g, "") == "")
		SetError("divErrorEmailAddress", "You must enter an email address");
	
	else if(!IsValidateEmail(String(form.email.value.replace(/\s/g,""))))
		SetError("divErrorEmailAddress", "Your have entered and invalid email address");
	
	if(document.getElementById("SmokingYes").checked == false && document.getElementById("SmokingNo").checked == false)
		SetError("divErrorSmoking", "You must select if any of the potential tenants smoke");
	
	if(document.getElementById("PetsYes").checked == false && document.getElementById("PetsNo").checked == false)
		SetError("divErrorPets", "You must select if you have a pet");
	
	if(form.familySize.value.replace(/\s/g, "") == "")
		SetError("divErrorFamilySize", "You must enter the size and ages of your family/other tenants");
	
	if(document.getElementById("Working").checked == false && document.getElementById("DHSS").checked == false)
		SetError("divErrorWorking", "You must select if you are working or DHSS");
	
	if(document.getElementById("LengthOfTenancy6Months").checked == false && document.getElementById("LengthOfTenancy12Months").checked == false && document.getElementById("LengthOfTenancy12PlusMonths").checked == false)
		SetError("divErrorLengthOfTenancy", "You must select the general length of your proposed tenancy");
	
	if(!containErrors)
		return true;
	else
		return false;
	
}
