// JavaScript Document
function trim( instr ) {

    	var reFirst = /\S/;		// regular expression for first non-white char
    	var reLast = /\s+$/;	// regular expression for first white char after last non-white char
    	var firstChar = instr.search(reFirst);
    	var lastChar = instr.search(reLast);
    	
    	if( lastChar == -1 ) 
			lastChar = instr.length;    	
    	outstr = instr.substring( firstChar, lastChar );
    	return outstr;
}
function isValidEmail (emailIn){

	var isEmailOk = false;
//	var filter = /^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9-]+(\.[a-zA-Z][a-zA-Z-]+)+$/
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;


	if(emailIn.search(filter) != -1)
		isEmailOk = true;
	if(emailIn.indexOf("..") != -1)
		isEmailOk = false;
	if(emailIn.indexOf(".@") != -1)
		isEmailOk = false;
	if(emailIn.indexOf("'") != -1 || emailIn.indexOf("''") != -1 || emailIn.indexOf("\"") != -1 || emailIn.indexOf("\"\"") != -1 || emailIn.indexOf("(") != -1  || emailIn.indexOf(")") != -1 || emailIn.indexOf("[") != -1 || emailIn.indexOf("]") != -1 || emailIn.indexOf("{") != -1  || emailIn.indexOf("}") != -1 || emailIn.indexOf(",") != -1 || emailIn.indexOf(",,") != -1 || emailIn.indexOf(":") != -1 || emailIn.indexOf(";") != -1 || emailIn.indexOf("#") != -1 || emailIn.indexOf("mailto:") != -1)
		isEmailOk = false;

	return isEmailOk;
} // Ends 
function CheckValidation(objValue,strError)
{
   if(eval(objValue.value.length) == 0) 
   { 
      if(!strError || strError.length ==0) 
      { 
        strError =  "Required Field"; 
      } 
      alert(strError); 
      return false; 
   }
   return true;
}
function checkmail(email)
{

// a very simple email validation checking. 
/* you can add more complex email checking if it helps */
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false; 
}
function validateemail(email)
{
	var strError;
	
		   if(!checkmail(email)) 
               { 
                    alert("Enter valid Email address "); 
                    document.getElementById('email').focus();
	                return false; 
               }
               return true;
}
function validateMe(){
    var firstname=document.getElementById('firstname').value;
	var email=document.getElementById('email').value;
	var phone=document.getElementById('phoneno').value;
	var message=document.getElementById('message').value;
    //var frm	= document.forms['0'];
	//alert(frm);
	//alert(frm.firstname);
	if(firstname=="")
	{
		alert("Name is compulsory");
		document.getElementById('firstname').focus();
		return false;
	}
	
	else if(email=="")
	{
		alert("Enter Email address");
		document.getElementById('email').focus();
		return false;
	}	
	else if (!validateemail(email))
	{
		return false;
	}
	
	else if(phone=="")
	{
		alert("Enter Phone Number");
		document.getElementById('phoneno').focus();
		return false;

	}
	else if(CheckNumber(phone)==false)
	{		
		alert("Phone Number shoould be Numeric");
		document.getElementById('phoneno').focus();
		document.getElementById('phoneno').value="";
		return false;
		
	}

}

function valid(webadd)
{
	var v = new RegExp("^(http:\/\/www.|www.|https:\/\/www.|[0-9A-Za-z].){1}([0-9A-Za-z]+\.){2}[A-Za-z0-9-_]+$");
    if (!v.test(webadd)) 
	{
		alert("You must supply a valid Web Address.");
        return false;
    }
	return true;
}


function CheckNumber(val)
{
	
  if (val.match(/^[0-9.\s]+$/))
   {
	   
      return true;
   }
   else
   {
	  
      return false;
   }   
}
