// This function will validate a form
// Written by: Thi Thach
// Date: 16 May 2007 9:06am

function validateForm(theform, formname)
{
	pass = 1; //assume everything is ok
	msg = "The following problem was found in trying to submit this form:\n\n";
	
	
	//Check enquiry form or contact us form
	//======================================

	//make sure required fields are not empty
	if (isEmpty(theform.Name.value))
	{
		msg = msg + "- Name cannot be empty\n";
		pass = 0;
	}

	
	if (isEmpty(theform.from.value))
	{
		msg = msg + "- Email address cannot be empty\n";
		pass = 0;
	}		
	else
	{		
		//validate the email address
		if (!(isEmail(theform.from.value)))
		{
			msg = msg + "- You must enter a valid email address\n";
			pass = 0;
		}
		
		
		//else
		//{
		//	theform.recipient.value = theform.Email.value;
		//}
	}
	
	
	
	if (isEmpty(theform.Comment.value))
	{
		msg = msg + "- Comment field cannot be empty\n";
		pass = 0;
	}	
	
		
	
	if (pass == 1)
	{
		return true;
	}
	else
	{
		alert(msg);
		return false;
	}
  
}

function isEmpty (s) {
	var p = /\S+/;
	return !p.test(s);
}

function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}