/* FORM-VALIDATION FUNCTIONS */
/* -------------------------------- */
	
	//specifies the background-color of erroneous input fields
	var alert_color = '#f1bcc9';
	
	//trims whitespace around a string
	//RETURNS: string
	function trim(str) {
	return str.replace(/^\s+|\s+$/g, '')
	}

	//simply checks if a string is empty or not
	//RETURN: boolean
	function mValidateEmpty(vString) {
		if(trim(vString.value) == '') {
			vString.style.backgroundColor = alert_color;
			return false;
		} else {
			vString.style.backgroundColor = '#ffffff';
			return true;
		}
	}
	
	
	//checks if given email address is in correct name@domain.com format
	//RETURN: boolean
	function mValidateEmail(vString) {
		var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/;
		if (!email.test(trim(vString.value))) {
			vString.style.backgroundColor = alert_color;
			return false;
		} else {
			vString.style.backgroundColor = '#ffffff';
			return true;
		}
	}
	
//-----------------------------------------------------------
	//returns false if user selected first item (default empty select field)
	//RETURN: boolean
	function mValidateSelect(vString) {
		if(vString.selectedIndex == 0) {
			vString.style.backgroundColor = alert_color;
			return false;
		} else {
			vString.style.backgroundColor = '#ffffff';
			return true;
		}
	}
	
	//checks equality of two strings (for email address, passwords, etc.)
	//RETURN: boolean
	function mValidateRepeat(vString1, vString2) {
		if(trim(vString1.value) != trim(vString2.value)) {
			vString1.style.backgroundColor = alert_color;
			vString2.style.backgroundColor = alert_color;
			return false;
		} else {
			return true;
		}
	}
//------------------------------------------------------------------------------------------
	
	function validateContactFormFields(_f)
	{
		if(_f.fullname.value == "")
		{
			alert("Please enter your full name.");
			_f.fullname.focus();
			return(false);
		}
		if(_f.fulladdress.value == "")
		{
			alert("Please enter your full postal address.");
			_f.fulladdress.focus();
			return(false);
		}
		if(_f.email.value == "")
		{
			alert("Please Enter Your Email Address.");
			_f.email.focus();
			return(false);
		}
		else if(!mValidateEmail(_f.email))
		{
			alert("Please enter a Valid Email Address.");
			_f.email.focus();
			return(false);
		}
		
		
			return(true);
	}

