

function checkForm()
{

	  //checking for First Name
	  var fname = trimAll(document.frm.firstname.value); 	
	  if (fname == "" )
	  {
	   alert('Please enter your first name');  
	   document.frm.firstname.focus();
	   return false;	  
	  }

	  //checking for Last Name
	  var lname = trimAll(document.frm.lastname.value); 	
	  if (lname == "" )
	  {
	   alert('Please enter your last name');  
	   document.frm.lastname.focus();
	   return false;	  
	  }

	  //checking for Job Title
	  var jobt = trimAll(document.frm.job.value); 	
	  if (jobt == "" )
	  {
	   alert('Please enter your job title');  
	   document.frm.job.focus();
	   return false;	  
	  }

	  //checking for email
	  var email =  trimAll(document.frm.email.value);
	  if (email == "" )
	  {
	   alert('Please enter your email.');  
	   document.frm.email.focus();
	   return false;	  
	  }
	  else if (checkEmail(email) == false)
	  {
	   alert('Please enter the valid email address.');  
	   document.frm.email.focus();
	   return false;	  
	  }
	  
  	  //checking for Phone
	  var phone = trimAll(document.frm.phone.value); 	
	  if (phone == "" )
	  {
	   alert('Please enter your phone number');  
	   document.frm.phone.focus();
	   return false;	  
	  }


  	  //checking for Company
	  var company = trimAll(document.frm.companyname.value); 	
	  if (company == "" )
	  {
	   alert('Please enter your company');  
	   document.frm.companyname.focus();
	   return false;	  
	  }

	  //checking for Country
	  var ctlCountry = document.frm.CountryName;
	  var country = ctlCountry.options[ctlCountry.selectedIndex].text;
	  
	  if (country == "---Select One---" )
	  {
	   alert('Please select country');  
	   document.frm.CountryName.focus();
	   return false;	  
	  }


	  //checking for State
	  var ctlState = document.frm.StateName;
	  var state = ctlState.options[ctlState.selectedIndex].text;
	  
	  if (state == "---US/Canada Only ---" )
	  {
	   alert('Please select state');  
	   document.frm.StateName.focus();
	   return false;	  
	  }

	  //checking for Employee
	  var ctlEmployee = document.frm.EmployeeName;
	  var employee = ctlEmployee.options[ctlEmployee.selectedIndex].text;
	  
	  if (employee == "---Select One ---" )
	  {
	   alert('Please select employees');  
	   document.frm.EmployeeName.focus();
	   return false;	  
	  }

	  /*
	  //checking for subject
	  var subject =  trimAll(document.frm.subject.value);
	  if (subject == "" )
	  {
	   alert('Please enter subject.');  
	   document.frm.subject.focus();
	   return false;	  
	  }
  	  */
		
	  //checking the intrest
	  var chk1 =  document.getElementById('testdrive');
	  var chk2 = document.getElementById('channel');
	  if (chk1.checked == false  &&   chk2.checked == false )
	   {
		alert('Please select your intrest.');
		return false;
	   }

	 /*
	 //checking the mail message
	  var message =  trimAll(document.frm.message.value);
	  if (message == "" )
	  {
	   alert('Please enter the message.');  
	   document.frm.message.focus();
	   return false;	  
	  }
	  */

  return true;

}

 // Left and Right both trim function 
    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;
    }
	
	
 // valid email address
 
 function checkEmail(theAddress)
{	
	if (theAddress.indexOf('@')==0 || theAddress.indexOf('@') == -1)
	{	return false;
	}
	
	if (theAddress.indexOf(' ') != -1)
	{   return false;
	}

	atPosition=theAddress.indexOf('@');
	if (theAddress.indexOf('.', atPosition)<=atPosition+1)
	{	return false;
	}
	
	if (theAddress.charAt(theAddress.length-1) == '.')
	{   return false;
	}
	
	if (theAddress.indexOf('@')!=theAddress.lastIndexOf('@'))
	{   return false;
	}
	
    return true;
}
	
	
	