// JavaScript Document
 function trimAll(sString){

    while (sString.substring(0,1) == ' '){
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' '){
        sString = sString.substring(0,sString.length-1);
    }
    
    return sString;
  }

var numb = '0123456789';
function isValid(parm,val)
{
    //if (parm == "") return true;
    for (i=0; i<parm.length; i++)
    {
      if (val.indexOf(parm.charAt(i)) == -1)
      {
        //alert("Pleasegjhhirst Name' box.");
        return false;
      }
    }
    return true;
}
function isNum(parm)
{
    return isValid(parm,numb);
}



function validateForm()
{
    //checking Name
    if (trimAll(document.getElementById('name').value) =='') {
        alert('Name required.');
        document.getElementById('name').focus();
        return false;
    }
    
    
     
  
    //checking phone1 number
     
    if (trimAll(document.getElementById('phone').value)=='') {
        alert('Phone Number required');
        document.getElementById('phone').focus();
        return false;
    }
    else
    {
        var ret = isNum(document.getElementById('phone').value);
        if(ret==false)
        {
          alert("Please Enter only Numerical Letters in 'your Phone Number' box.");
          document.getElementById('phone').focus();
          return false;
        }
    }
	
	
	
	
	//checking email.
     var  email = trimAll(document.getElementById('email').value);
    if (email =='') {
        alert('E-mail required');
        document.getElementById('email').focus();
        return false;
    } 
    
    var str = email;
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot); 

    if (str.indexOf(at)==-1) {
        alert("Invalid E-mail address.");
       document.getElementById('email').focus();
        return false;
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) {
        alert("Invalid E-mail address..");
        document.getElementById('email').focus();
        return false;
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) {
        alert("Invalid E-mail address.");
        document.getElementById('email').focus();
        return false;
    }
    if (str.indexOf(at,(lat+1))!=-1){
        alert("Invalid E-mail address.");
        document.getElementById('email').focus();
        return false;
    }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) {
        alert("Invalid E-mail address.");
        document.getElementById('email').focus();
        return false;
    }
    if (str.indexOf(dot,(lat+2))==-1) {
        alert("Invalid E-mail address.");
        document.getElementById('email').focus();
        return false;
    }
    if (str.indexOf(" ")!=-1) {
        alert("Invalid E-mail address.");
        document.getElementById('email').focus();
        return false;
    }
    if (str.substring(ldot+2,ldot+1)=='') {
        alert("Invalid E-mail address.");
        document.getElementById('email').focus();
        return false;
    }
    
   
return true;  
}
