//Function to trim the space in the left side of the string
function ltrim ( s )
{
    return s.replace( /^\s*/, "" );
}
//Function to trim the space in the right side of the string
function rtrim ( s )
{
    return s.replace( /\s*$/, "" );
}
//Function to trim the space in the  string
function trim(s)
{
    var temp = s;
       return temp.replace(/^\s+/,'').replace(/\s+$/,'');
}


function isInteger(s)
{
    var i;
    for (i = 0; i < s.length; i++)
    {
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function validateEmail(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 formValidation()
{
    var name=document.getElementById('name').value;
    var email=document.getElementById('email').value;
    var enquiry=document.getElementById('enquiry').value;
    
    document.getElementById('nameErr').innerHTML="";
    document.getElementById('emailErr').innerHTML="";
    document.getElementById('enquiryErr').innerHTML="";
    
    if(trim(name)=="")
    {   
        //alert("Name is required!!");
        document.getElementById('nameErr').innerHTML="Name is required";
        document.getElementById('name').focus();
        return false;
    }
    if(trim(email)=="")
    {   
        //alert("Email id is required!!");
        document.getElementById('emailErr').innerHTML="Email-Id is required";
        document.getElementById('email').focus();
        return false;
    }
	 if(trim(name)=="")
    {   
        //alert("Name is required!!");
        document.getElementById('companyErr').innerHTML="company is required";
        document.getElementById('company').focus();
        return false;
    }
	if(trim(name)=="")
    {   
        //alert("Name is required!!");
        document.getElementById('websiteErr').innerHTML="website is required";
        document.getElementById('website').focus();
        return false;
    }
    else if(!validateEmail(email))
    {
        //alert("Enter valid email id!!");
        document.getElementById('emailErr').innerHTML="Enter valid Email-Id";
        document.getElementById('email').value="";
        document.getElementById('email').focus();
        return false;
    }
    if(trim(enquiry)=="")
    {
        //alert("Fill up the enqiry box");
        document.getElementById('enquiryErr').innerHTML="Fill up enqiry box";
        document.getElementById('enquiry').focus();
        return false;
    }
    
    return true;
    
}// JavaScript Document