function trim(inputString) 
{
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
	
   var retValue = inputString;

   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }

   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }

   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

function fnValid()
{
	var fr=document.frmContact;
	//  checking if name is not a nll
	if(fr.txtFirstName.value=='')
	{
	   alert("Please Enter First Name ");
	   fr.txtFirstName.focus();
	   return false;
	}
	if(fr.txtLastName.value=='')
	{
	   alert("Please Enter Last Name ");
	   fr.txtLastName.focus();
	   return false;
	}
	if(fr.txtCompany.value=='')
	{
	   alert("Please Enter Company Name ");
	   fr.txtCompany.focus();
	   return false;
	}
	if(fr.txtCompany.value=='')
	{
	   alert("Please Enter Company Name ");
	   fr.txtCompany.focus();
	   return false;
	}
	
	var Temp     = fr.txtEmail;
	var AtSym    = Temp.value.indexOf('@');
	var Period   = Temp.value.lastIndexOf('.');
	var Space    = Temp.value.indexOf(' ');
	var Length   = Temp.value.length - 1;
  //checking if email id  is not a nll
  if(trim(fr.txtEmail.value) == '')
  {
  	alert("Please Enter Email Address");
	fr.txtEmail.focus();
	return false;
  }
  
   //checking if email id  is a valid
  if (AtSym < 1 || Period <= AtSym+1 || Period == Length)                  
  {  
	 alert('Please enter a valid e-mail address!');
	 Temp.focus();
	 return false;
  }
  if(fr.txtCompany.value=='')
	{
	   alert("Please Enter Company Name ");
	   fr.txtCompany.focus();
	   return false;
	}
	if(fr.txtPhone.value=='')
	{
	   alert("Please Enter Phone Number");
	   fr.txtPhone.focus();
	   return false;
	}
	
	fr.act.value='Send';
	fr.action = "contact_mail.php"
	fr.submit(); 
}
