/* JavaScript Document */ 

/* function to remove spaces from front and end of string */
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;
} 

/* function to check special character in string */
function checkSpecialChars(parValue){
     var receivedValue = parValue;
  /*    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~`"; */   
     var iChars = "\\\';";
     for (var i = 0; i < receivedValue.length; i++) {
        if (iChars.indexOf(receivedValue.charAt(i)) != -1) {
            return -1;              	
      	}
    }
    return 1;    
}
/*var numb = '0123456789 ';*/ 
/*function isValid(parm,val) {*/ 
/*if (parm == "") return true; for (i=0; i*/

/* Function for email check. */
function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		var lastdot=str.lastIndexOf(dot)
		
    temp = (str.substring(lastdot+1,lstr));
		/*  alert(temp); */
		if (str.indexOf(at)==-1){
		   /* alert("Invalid E-mail ID") */
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   /* alert("Invalid E-mail ID") */
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    /* alert("Invalid E-mail ID") */
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    /* alert("Invalid E-mail ID") */
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    /* alert("Invalid E-mail ID") */
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    /* alert("Invalid E-mail ID") */
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    /* alert("Invalid E-mail ID") */
		    return false
		 }
		 
		 if(isNaN(temp))
		 {
        return true;
     }
     else
     {
        return false;
     }

 		 return true					
}
	
	
/*	Function for validating the contact form. */
function validateForm(){  /*alert("validateForm");*/
  var contact_name      = document.getElementById('contact_name').value;
  var contact_company   = document.getElementById('contact_company').value;
  var contact_city      = document.getElementById('contact_city').value;
  var contact_state     = document.getElementById('contact_state').value;
  var contact_email     = document.getElementById('contact_email').value;
  var contact_phone     = document.getElementById('contact_phone').value;
  var contact_message   = document.getElementById('contact_message').value;
  
  var error_msg='';
  
  
  /* check Contact name is blank or not */
  /*if(trimAll(contact_name) == ''){
  error_msg += "Contact name can not be blank.\n";
  }*/
  /* Check for special character in Company name. */
  /*if(trimAll(contact_name) != "") {
    if(checkSpecialChars(contact_name)==-1){
      error_msg += "Contact name can not take special characters(\\\';/).\n";
    }
  }*/
  
  /* check Company name is blank or not */
  /*if(trimAll(contact_company) == ''){
  error_msg += "Company name can not be blank.\n";
  }*/
  /* Check for special character in Company name. */
  /*if(trimAll(contact_company) != "") {
    if(checkSpecialChars(contact_company)==-1){
      error_msg += "Company name can not take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check City name is blank or not */
  if(trimAll(contact_city) == ''){
  error_msg += "City can not be blank.\n";
  }
  /* Check for special character in Website name. */
  /*if(trimAll(contact_city) != "") {
    if(checkSpecialChars(contact_city)==-1){
      error_msg += "City can not take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check State name is blank or not */
  /*if(trimAll(contact_state) == ''){
  error_msg += "State can not be blank.\n";
  }*/
  /* Check for special character in Contact 1 name. */
  /*if(trimAll(contact_state) != "") {
    if(checkSpecialChars(contact_state)==-1){
      error_msg += "State can not take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check Email is blank or not */
  if(trimAll(contact_email) == ''){
    error_msg += "Email can not be blank.\n";
  }
  /* check Email format */
  if(trimAll(contact_email) != "") {
    if(echeck(contact_email) != true)
    {
      error_msg += "Please enter valid email address.\n";
    }
  }
  
  
  /* check phone is blank or not */
  if(trimAll(contact_phone) == '') {
    error_msg += "Phone number can not be blank.\n";
  }
  
  /* check phone is blank or not */
  /*if((trimAll(phone1) == '') && (trimAll(phone2) == '') && (trimAll(phone3) == '')) {
    error_msg += "Phone number can not be blank.\n";
  }*/
  /*if((trimAll(phone1) == '') || (trimAll(phone2) == '') || (trimAll(phone3) == '')) {
    error_msg += "Phone number is not correct.\n";
  }*/
  /* Check for special character in phone. */
  /*if((trimAll(phone1) != '') || (trimAll(phone2) != '') || (trimAll(phone3) != '')) {
    if((isNaN(phone1)) || (isNaN(phone2)) || (isNaN(phone3)) ){
      error_msg += "Phone number can not take characters(A - Z) or (\\\';/).\n";
    }
  }*/
  
  
  /* check Message is blank or not */  
  if(trimAll(contact_message) == ''){
    error_msg += "Message can not be blank.\n";
  }
  
  
  if(error_msg != ""){
    alert (error_msg);
    return false;
  }
  else{
    /* alert("Record Inserted Successfully");
    document.account.submit();*/
    return true;
  }
}


/*	Function for validating the contact form. */
function validateRecForm(){  /*alert("validateForm");*/
  var contact_name      = document.getElementById('contact_name1').value;
  var contact_company   = document.getElementById('contact_company1').value;
  var contact_city      = document.getElementById('contact_city1').value;
  var address1      = document.getElementById('address1').value;
  var address2      = document.getElementById('address2').value;
  var contact_state     = document.getElementById('contact_state1').value;
  var zipcode      = document.getElementById('zipcode').value;
  var country      = document.getElementById('country').value;
  var contact_email     = document.getElementById('contact_email1').value;
  var contact_phone     = document.getElementById('contact_phone1').value;
  var contact_message   = document.getElementById('contact_message1').value;
  
  var error_msg='';
  
  
  /* check Contact name is blank or not */
  if(trimAll(contact_name) == ''){
  error_msg += "Contact name can not be blank.\n";
  }
  /* Check for special character in Company name. */
  /*if(trimAll(contact_name) != "") {
    if(checkSpecialChars(contact_name)==-1){
      error_msg += "Contact name can not take special characters(\\\';/).\n";
    }
  }*/
  
  /* check Company name is blank or not */
  if(trimAll(contact_company) == ''){
  error_msg += "Company name can not be blank.\n";
  }
  
  if(trimAll(address1) == ''){
  error_msg += "Address Line 1 can not be blank.\n";
  }
  
  /* Check for special character in Company name. */
  /*if(trimAll(contact_company) != "") {
    if(checkSpecialChars(contact_company)==-1){
      error_msg += "Company name can not take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check City name is blank or not */
 if(trimAll(contact_city) == ''){
  error_msg += "City can not be blank.\n";
  }
  /* Check for special character in Website name. */
  /*if(trimAll(contact_city) != "") {
    if(checkSpecialChars(contact_city)==-1){
      error_msg += "City can not take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check State name is blank or not */
  if(trimAll(contact_state) == ''){
  error_msg += "State can not be blank.\n";
  }
  
  if(trimAll(zipcode) == ''){
  error_msg += "Zip/Pin Code can not be blank.\n";
  }
  
  if(trimAll(country) == ''){
  error_msg += "Country can not be blank.\n";
  }
  /* Check for special character in Contact 1 name. */
  /*if(trimAll(contact_state) != "") {
    if(checkSpecialChars(contact_state)==-1){
      error_msg += "State can not take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check Email is blank or not */
  if(trimAll(contact_email) == ''){
    error_msg += "Email can not be blank.\n";
  }
  /* check Email format */
  if(trimAll(contact_email) != "") {
    if(echeck(contact_email) != true)
    {
      error_msg += "Please enter valid email address.\n";
    }
  }
  
  
  /* check phone is blank or not */
  /*if(trimAll(contact_phone) == '') {
    error_msg += "Phone number can not be blank.\n";
  }*/
  
  /* check phone is blank or not */
  /*if((trimAll(phone1) == '') && (trimAll(phone2) == '') && (trimAll(phone3) == '')) {
    error_msg += "Phone number can not be blank.\n";
  }*/
  /*if((trimAll(phone1) == '') || (trimAll(phone2) == '') || (trimAll(phone3) == '')) {
    error_msg += "Phone number is not correct.\n";
  }*/
  /* Check for special character in phone. */
  /*if((trimAll(phone1) != '') || (trimAll(phone2) != '') || (trimAll(phone3) != '')) {
    if((isNaN(phone1)) || (isNaN(phone2)) || (isNaN(phone3)) ){
      error_msg += "Phone number can not take characters(A - Z) or (\\\';/).\n";
    }
  }*/
  
  
  /* check Message is blank or not */  
  /*if(trimAll(contact_message) == ''){
    error_msg += "Message can not be blank.\n";
  }*/
  
  
  if(error_msg != ""){
    alert (error_msg);
    return false;
  }
  else{
    /* alert("Record Inserted Successfully");
    document.account.submit();*/
    return true;
  }
}
