 
  //remove leading whitespaces
  function LTrim( value ) {

	 var re = /\s*((\S+\s*)*)/;
	 return value.replace(re, "$1");

   }
  // Removes ending whitespaces
  function RTrim( value ) {
	
   var re = /((\s*\S+)*)\s*/;
   return value.replace(re, "$1");
	
  }
  // Removes leading and ending whitespaces
  function trim(value) {

   return LTrim(RTrim(value));
 }

 //check the paramter is int ot not
  function isInteger(s){  
	var i;
	for (i = 0; i < s.length; i++)
		{   
		   // Check that current character is number.
		   var c = s.charAt(i);
		   if (((c < "0") || (c > "9"))) return false;
		}
   // All characters are numbers.
  return true;
  }

  // email format validation
    function checkEmail(email) {
       	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
   		    return true;
        }
	 //  alert("Please enter valid email id.");
	  // return false;
    }
 
function validate(){
	var firstName = document.getElementById("FirstName");
	var lastName = document.getElementById("LastName");
	var companyName = document.getElementById("CompanyName");
	var address = document.getElementById("Address");
	var cityName = document.getElementById("City");
	var zipCode = document.getElementById("Zip");
	var state = document.getElementById("State");
	var emailId = document.getElementById("EmailId");
	var telephone = document.getElementById("Telephone");
	
	//check null value
	if(firstName.value == ""){
		alert("Please enter your first name");
		firstName.focus();
		return false;
	}

	//check is there any no. in name field
	if(isInteger(firstName.value)){
		alert("Please enter only character value in first name field.");
		firstName.focus();
		return false;
	}

	//check null value
	if(lastName.value == ""){
		alert("Please enter your last name");
		lastName.focus();
		return false;
	}

	//check is there any no. in name field
	if(isInteger(lastName.value)){
		alert("Please enter only character value in last name field.");
		lastName.focus();
		return false;
	}

	//check null value
	if(companyName.value == ""){
		alert("Please enter your company name");
		companyName.focus();
		return false;
	}

	//check is there any no. in name field
/*	if(isInteger(lastName.value)){
		alert("Please enter only character value in company field.");
		companyName.focus();
		return false;
	}
*/

	//check null value
	if(address.value == ""){
		alert("Please enter your address");
		address.focus();
		return false;
	}

	//check null value
	if(cityName.value == ""){
		alert("Please enter your city");
		cityName.focus();
		return false;
	}

	//check null value
	if(zipCode.value == ""){
		alert("Please enter your zip code");
		zipCode.focus();
		return false;
	}

	//check is there any no. in name field
	if(!isInteger(zipCode.value)){
		alert("Please enter proper zip code.");
		zipCode.focus();
		return false;
	}

	//check null value
	if(state.value == ""){
		alert("Please enter your state");
		state.focus();
		return false;
	}

	//check is there any no. in name field
	if(isInteger(state.value)){
		alert("Please enter proper state name.");
		state.focus();
		return false;
	}

	//check null value
	if(emailId.value == ""){
		alert("Please enter your email id");
		emailId.focus();
		return false;
	}

	if(!checkEmail(emailId.value)){
		alert("Please enter valid email id");
		emailId.focus();
		return false;
	}

	//check null value
	if(telephone.value == ""){
		alert("Please enter your telephone no");
		telephone.focus();
		return false;
	}
	
	//check is there any no. in name field
	if(!isInteger(telephone.value)){
		alert("Please enter valid telephone no.");
		telephone.focus();
		return false;
	}
}
