function trim(s)
{
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
}

function validate_form (theForm)
{
	var emailFilter=/^.+@.+\..{2,3}$/;
	valid = true;
	var errorstr = "";
    if ( trim(theForm.contact_name.value) == "" )
        {
			errorstr += "Please enter your name\n";
        }
	if (!(emailFilter.test(theForm.contact_email.value)))
		{ 
			errorstr +=  "Please enter a valid email address\n";
		}
    if ( trim(theForm.contact_message.value) == "" )
        {
			errorstr += "Please enter your message\n";
        }
    if (errorstr != "")
		{
			valid = false;
			alert(errorstr);
	    }
     return valid;
}

