// JavaScript Document

function validate()
{
var a=document.contact;

    if(!trimString(a.name.value))
	{
	 alert("Please Enter Name") ;
	 a.name.focus();
	 return false;
	}

	if(!trimString(a.email.value))
	{
	 alert("Please Enter Email Address") ;
	 a.email.focus();
	 return false;
	}
	else
	{
		 if(isEmail(a.email.value)==false)
			  {
				 alert("Please Enter Valid Email Address") ;
				 a.email.focus();
				 return false;
			  }
			 
	}

   

	 if(a.tel.value!="")
	{
	   var str = "0123456789 ()-+";
		var pr =a.tel.value;
		var ok = true;
		
		for (var i=0;i<pr.length;i++)
		{
			
			ch = pr.charAt(i);
			for (var j=0;j<str.length;j++)
			if (ch == str.charAt(j))
			break;
			if (j==str.length)
			{
				ok=false;
				break;
			}
		}
		if (!ok)
		{
			alert("Please Enter Valid Telephone Number");
			a.tel.focus();
			return false;
		}	
	}
	

	
	
	 if(!trimString(a.message.value))
	{
	 alert("Please Enter Message") ;
	 a.message.focus();
	 return false;
	}
	
	
	

}
function trimString(str) {
		str= this != window? this : str;
		return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
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;
}
