// form validation - core validation routine
function setupValidation()
{
	if(document.getElementById("quotes"))
	{
		setupQuoteForm();
	}
	else if(document.getElementById("callback"))
	{
		var frmvalidator = new Validator("callback");
			
		frmvalidator.addValidation("fullname", "req", "Please enter your name");
		frmvalidator.addValidation("phonenumber", "req", "Please enter your phone number");
	}
	else if(document.getElementById("enquiry"))
	{
		var frmvalidator = new Validator("enquiry");
		
		frmvalidator.addValidation("fullname", "req", "Please enter your name(s)");
		frmvalidator.addValidation("address", "req", "Please enter your postal address");	
		frmvalidator.addValidation("postcode", "req", "Please enter your postcode");	
		frmvalidator.addValidation("phonenumber", "req", "Please enter your phone number");	
	}
}

function setupQuoteForm()
{
	var frmvalidator = new Validator("quotes");
	frmvalidator.addValidation("fullname", "req", "Please enter your name(s)");

	frmvalidator.addValidation("email", "req", "Please enter a valid email address");	
	frmvalidator.addValidation("email", "email", "Please enter a valid email address");

	frmvalidator.addValidation("address", "req", "Please enter your postal address");	
	frmvalidator.addValidation("postcode", "req", "Please enter your postcode");	

	frmvalidator.addValidation("namecrem", "req", "Please enter the name of the Cemetery or Crematorium");
	
	frmvalidator.setAddnlValidationFunction("customQuoteValidation");
/*	frmvalidator.addValidation("dateofarrival", "req", "Please enter the date of arrival");	
	frmvalidator.addValidation("numberofnights", "req", "Please enter the duration of your stay");	
	frmvalidator.addValidation("typeofroom", "req", "Please select the type of room required");		
	frmvalidator.addValidation("howdidyoufindus", "req", "Please tell us how you found us");		*/

}

function customQuoteValidation()
{
	frm = document.forms["quotes"];
	
	// require either email contact or postal address
	if(frm.email.length == 0 && 
		(frm.address.length == 0 && frm.postcode.length == 0))
	{
		alert("Please enter either an email address or postal address");
		return false;
	}
	
	// require at least one phone number
	if(frm.phonenumber.length == 0 &&
		frm.eveningnumber.length == 0 &&
		   frm.mobilenumber.length == 0)
	{
		alert("Please enter at least one phone number");
		return false;
	}
	
	// no errors found throughout
	return true;
}



// global startup function
/////////////////////////////////////////////////
if(document.getElementById && document.createTextNode)
{
	addEvent(window, 'load', function(e)
	{
		setupValidation();
	});
}