 
  //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 xcheckEmail(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;
	}
}


//************************************* Komal's code **************************************

//this function use to trim the spaces in text field
function trimspace(str){		
	var len = str.length;

	if (len != 0){
		for (var i=0;i<len;i++){	
			if(str.indexOf(" ")==0)
				str=str.substring(1,len);
		}
		var strtrim = str;
		return strtrim;
	}
	else {
		return str;
	}
}

// email format validation
function checkEmail(email) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email)){
		return (true)
	}
		alert(checkmail_msg)
		return (false)
}


// Validate US as well as india ZIP code.
function validateZipCode(string){
	var validZipCode = true;
	for (var n = 0; n < string.length; n++) {

		var c = string.charCodeAt(n);
		if(!(((c >= 48) && (c <= 57)) || ((c >= 65) && (c <= 90)) || ((c >= 97) && (c <= 122)) || (c == 45) || (c == 43) || (c == 32))){
			validZipCode = false;
		}
	}
	return validZipCode;
}
// Validate US as well as india phone no.
function validatePhoneNumber(string){
	var validPhoneNo = true;
	for (var n = 0; n < string.length; n++) {

		var c = string.charCodeAt(n);
		if(!(((c >= 48) && (c <= 57)) || (c == 46) || (c == 45) || (c == 43) || (c == 40) || (c == 41) || (c == 32))){
			validPhoneNo = false;
		}
	}
	return validPhoneNo;
}


function career_validation() {

	var fullName = document.getElementById('txtfname').value;
	var dobDay = document.getElementById('dobDay').value;
	var dobMonth = document.getElementById('dobMonth').value;
	var dobYear = document.getElementById('dobYear').value;
	var address = document.getElementById('txthomeaddress').value;
	var email = document.getElementById('txtemail').value;
	
	// Validate full name
	fullName = trimspace(fullName);
	if(fullName == '') {
		alert("Please enter your name");
		document.getElementById('txtfname').focus();
		return false;
	}
	// Validate dob Day
	if(dobDay == '') {
		alert("Please select your date of birth day");
		document.getElementById('dobDay').focus();
		return false;
	}
	// Validate dob Month
	if(dobMonth == '') {
		alert("Please select your date of birth month");
		document.getElementById('dobMonth').focus();
		return false;
	}
	// Validate dob Year
	if(dobYear == '') {
		alert("Please select your date of birth year");
		document.getElementById('dobMonth').focus();
		return false;
	}
	// Validate address
	address = trimspace(address);
	if(address == '') {
		alert("Please enter address");
		document.getElementById('txthomeaddress').focus();
		return false;
	}
	// Validate email
	email = trimspace(email);
	if(email == '') {
		alert("Please enter a valid email address");
		document.getElementById('txtemail').focus();
		return false;
	}
	if(!checkEmail(email)) {
		alert("Please enter a valid email address");
		document.getElementById('txtemail').focus();
		return false;
	}
	return true;
}


function feedback_validation() {

	var fullName = document.getElementById('txtfname').value;
	var address = document.getElementById('txthomeaddress').value;
	var city = document.getElementById('txtcity').value;
	var state = document.getElementById('txtstate').value;
	var country = document.getElementById('txtcountry').value;
	var txtzip = document.getElementById('txtzip').value;
	var email = document.getElementById('txtemail').value;
	var resiPhone = document.getElementById('txtresiphone').value;
	
	// Validate full name
	fullName = trimspace(fullName);
	if(fullName == '') {
		alert("Please enter your name");
		document.getElementById('txtfname').focus();
		return false;
	}
	// Validate address
	address = trimspace(address);
	if(address == '') {
		alert("Please enter address");
		document.getElementById('txthomeaddress').focus();
		return false;
	}
	// Validate city
	city = trimspace(city);
	if(city == '') {
		alert("Please enter your city");
		document.getElementById('txtcity').focus();
		return false;
	}
	// Validate state
	state = trimspace(state);
	if(state == '') {
		alert("Please enter your state");
		document.getElementById('txtstate').focus();
		return false;
	}
	// Validate country
	country = trimspace(country);
	if(country == '') {
		alert("Please select your country");
		document.getElementById('txtcountry').focus();
		return false;
	}
	// Validate zip
	txtzip = trimspace(txtzip);
	if(txtzip == '') {
		alert('Enter valid zip code');
		document.getElementById('txtzip').focus();
		return false;
	}
	// Validate zip
	if(!validateZipCode(txtzip)){
		alert('Enter valid zip code');
		document.getElementById('txtzip').focus();
		return false;
	}
	// Validate email
	email = trimspace(email);
	if(email == '') {
		alert("Please enter a valid email address");
		document.getElementById('txtemail').focus();
		return false;
	}
	if(!checkEmail(email)) {
		alert("Please enter a valid email address");
		document.getElementById('txtemail').focus();
		return false;
	}
	// Validate resi phone no.
	resiPhone = trimspace(resiPhone);
	if(resiPhone == '') {
		alert('Please enter a valid residence number');
		document.getElementById('txtresiphone').focus();
		return false;
	}
	// Validate resi phone no.
	if(!validatePhoneNumber(resiPhone)){
		alert('Please enter a valid residence number');
		document.getElementById('txtresiphone').focus();
		return false;
	}
	return true;
}


