/* 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 cannot be blank.\n";
  }*/
  /* Check for special character in Company name. */
  /*if(trimAll(contact_name) != "") {
    if(checkSpecialChars(contact_name)==-1){
      error_msg += "Contact name cannot take special characters(\\\';/).\n";
    }
  }*/
  
  /* check Company name is blank or not */
  /*if(trimAll(contact_company) == ''){
  error_msg += "Company name cannot be blank.\n";
  }*/
  /* Check for special character in Company name. */
  /*if(trimAll(contact_company) != "") {
    if(checkSpecialChars(contact_company)==-1){
      error_msg += "Company name cannot take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check City name is blank or not */
  if(trimAll(contact_city) == ''){
  error_msg += "City cannot be blank.\n";
  }
  /* Check for special character in Website name. */
  /*if(trimAll(contact_city) != "") {
    if(checkSpecialChars(contact_city)==-1){
      error_msg += "City cannot take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check State name is blank or not */
  /*if(trimAll(contact_state) == ''){
  error_msg += "State cannot be blank.\n";
  }*/
  /* Check for special character in Contact 1 name. */
  /*if(trimAll(contact_state) != "") {
    if(checkSpecialChars(contact_state)==-1){
      error_msg += "State cannot take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check Email is blank or not */
  if(trimAll(contact_email) == ''){
    error_msg += "Email cannot 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 cannot be blank.\n";
  }
  
  /* check phone is blank or not */
  /*if((trimAll(phone1) == '') && (trimAll(phone2) == '') && (trimAll(phone3) == '')) {
    error_msg += "Phone number cannot 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 cannot take characters(A - Z) or (\\\';/).\n";
    }
  }*/
  
  
  /* check Message is blank or not */  
  if(trimAll(contact_message) == ''){
    error_msg += "Message cannot 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 validateContactUsForm(){  /*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 contact_state     = document.getElementById('contact_state1').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 contact_captcha   = document.getElementById('formcaptcha').value;
  
  var error_msg='';
  
  
  /* check Contact name is blank or not */
  if(trimAll(contact_name) == ''){
  error_msg += "Contact name cannot be blank.\n";
  }
  /* Check for special character in Company name. */
  /*if(trimAll(contact_name) != "") {
    if(checkSpecialChars(contact_name)==-1){
      error_msg += "Contact name cannot take special characters(\\\';/).\n";
    }
  }*/
  
  /* check Company name is blank or not */
  if(trimAll(contact_company) == ''){
  error_msg += "Company name cannot be blank.\n";
  }
  /* Check for special character in Company name. */
  /*if(trimAll(contact_company) != "") {
    if(checkSpecialChars(contact_company)==-1){
      error_msg += "Company name cannot take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check City name is blank or not */
  /*if(trimAll(contact_city) == ''){
  error_msg += "City cannot be blank.\n";
  }*/
  /* Check for special character in Website name. */
  /*if(trimAll(contact_city) != "") {
    if(checkSpecialChars(contact_city)==-1){
      error_msg += "City cannot take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check State name is blank or not */
  /*if(trimAll(contact_state) == ''){
  error_msg += "State cannot be blank.\n";
  }*/
  /* Check for special character in Contact 1 name. */
  /*if(trimAll(contact_state) != "") {
    if(checkSpecialChars(contact_state)==-1){
      error_msg += "State cannot take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check Email is blank or not */
  if(trimAll(contact_email) == ''){
    error_msg += "Email cannot 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 cannot be blank.\n";
  }*/
  
  /* check phone is blank or not */
  /*if((trimAll(phone1) == '') && (trimAll(phone2) == '') && (trimAll(phone3) == '')) {
    error_msg += "Phone number cannot 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 cannot take characters(A - Z) or (\\\';/).\n";
    }
  }*/
  
  
  /* check Message is blank or not */  
  /*if(trimAll(contact_message) == ''){
    error_msg += "Message cannot be blank.\n";
  }*/
  
/* check captcha is blank or not */
  if(trimAll(contact_captcha) == ''){
    error_msg += "Please fill in verification by typing what appears in the image.\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 validateIntContactUsForm(){  /*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 contact_state     = document.getElementById('contact_state1').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 contact_captcha   = document.getElementById('formcaptcha').value;
  
  var error_msg='';
  
  
  /* check Contact name is blank or not */
  if(trimAll(contact_name) == ''){
  error_msg += "Contact name cannot be blank.\n";
  }
  /* Check for special character in Company name. */
  /*if(trimAll(contact_name) != "") {
    if(checkSpecialChars(contact_name)==-1){
      error_msg += "Contact name cannot take special characters(\\\';/).\n";
    }
  }*/
  
  /* check Company name is blank or not */
  if(trimAll(contact_company) == ''){
  error_msg += "Company name cannot be blank.\n";
  }
  /* Check for special character in Company name. */
  /*if(trimAll(contact_company) != "") {
    if(checkSpecialChars(contact_company)==-1){
      error_msg += "Company name cannot take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check City name is blank or not */
  if(trimAll(contact_city) == ''){
  error_msg += "City cannot be blank.\n";
  }
  /* Check for special character in Website name. */
  /*if(trimAll(contact_city) != "") {
    if(checkSpecialChars(contact_city)==-1){
      error_msg += "City cannot take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check State name is blank or not */
  if(trimAll(contact_state) == ''){
  error_msg += "Country cannot be blank.\n";
  }
  
  /* Check for special character in Contact 1 name. */
  /*if(trimAll(contact_state) != "") {
    if(checkSpecialChars(contact_state)==-1){
      error_msg += "State cannot take special characters(\\\';/).\n";
    }
  }*/
  
  
  /* check Email is blank or not */
  if(trimAll(contact_email) == ''){
    error_msg += "Email cannot 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 cannot be blank.\n";
  }*/
  
  /* check phone is blank or not */
  /*if((trimAll(phone1) == '') && (trimAll(phone2) == '') && (trimAll(phone3) == '')) {
    error_msg += "Phone number cannot 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 cannot take characters(A - Z) or (\\\';/).\n";
    }
  }*/
  
  
  /* check Message is blank or not */  
  /*if(trimAll(contact_message) == ''){
    error_msg += "Message cannot be blank.\n";
  }*/
  
/* check captcha is blank or not */
  if(trimAll(contact_captcha) == ''){
    error_msg += "Please fill in verification by typing what appears in the image.\n";
  }
  
  if(error_msg != ""){
    alert (error_msg);
    return false;
  }
  else{
    /* alert("Record Inserted Successfully");
    document.account.submit();*/
    return true;
  }
}

//Function to validate promotion page form
function validatePromoForm(lang){  

//alert(lang); 

  var contact_name      = document.getElementById('contact_name1').value;
  var last_name         = document.getElementById('contact_name2').value;
  var contact_company   = document.getElementById('contact_company1').value;
  var contact_address   = document.getElementById('contact_address1').value;
  var contact_city      = document.getElementById('contact_city1').value;
  var contact_state     = document.getElementById('contact_state1').value;
  var contact_zip       = document.getElementById('contact_zip1').value;
  var contact_email     = document.getElementById('contact_email1').value;
  var contact_phone     = document.getElementById('contact_phone1').value;
  var contact_referral  = document.getElementById('contact_referral').value;
  var contact_other     = document.getElementById('contact_other1').value;
  var contact_agree     = document.getElementById('agree').checked;
  var contact_captcha   = document.getElementById('formcaptcha').value;
  
  var error_msg='';
  
  /* check Contact name is blank or not */
  if((trimAll(contact_name) == '') || (trimAll(last_name) == '')){
      if(lang=="en")
           error_msg += "Name fields cannot be blank.\n";
      if(lang=="es")
          error_msg += "Los campos para tu nombre y apellido no deben permanecer en blanco.\n";
  }
  /* Check for special character in Company name. */
  if(trimAll(contact_name) != "") {
    if(checkSpecialChars(contact_name)==-1){
      error_msg += "First Name cannot take special characters(\\\';/).\n";
    }
  }
  if(trimAll(last_name) != "") {
    if(checkSpecialChars(last_name)==-1){
      error_msg += "Last Name cannot take special characters(\\\';/).\n";
    }
  }
  
  /* check Company name is blank or not */
  if(trimAll(contact_company) == ''){
      if(lang=="en")
           error_msg += "Company name cannot be blank.\n";
      if(lang=="es")
           error_msg += "El campo para el nombre de la compañía no debe permanecer en blanco.\n";
  }
  /* Check for special character in Company name. */
  if(trimAll(contact_company) != "") {
    if(checkSpecialChars(contact_company)==-1){
      error_msg += "Company name cannot take special characters(\\\';/).\n";
    }
  }
  
  /* check Address name is blank or not */
  if(trimAll(contact_address) == ''){
     if(lang=="en")
         error_msg += "Address cannot be blank.\n";
     if(lang=="es")
         error_msg += "El campo para tu dirección no debe permanecer en blanco.\n";
  }
  
  /* check City name is blank or not */
  if(trimAll(contact_city) == ''){
      if(lang=="en")
         error_msg += "City cannot be blank.\n";
      if(lang=="es")
         error_msg += "El campo para la ciudad no debe permanecer en blanco.\n";
  }
  /* Check for special character in Website name. */
  if(trimAll(contact_city) != "") {
    if(checkSpecialChars(contact_city)==-1){
      error_msg += "City cannot take special characters(\\\';/).\n";
    }
  }

  /*check State name is blank or not */
  if(trimAll(contact_state) == ''){
      if(lang=="en")
          error_msg += "State cannot be blank.\n";
      if(lang=="es")
          error_msg += "El campo para el estado no debe permanecer en blanco.\n";
  }
 
/* check zip name is blank or not */
  if(trimAll(contact_zip) == ''){
      if(lang=="en")
          error_msg += "Zip Code cannot be blank.\n";
      if(lang=="es")
          error_msg += "El campo para el código postal no debe permanecer en blanco.\n";
  }

  /* check Email is blank or not */
  if(trimAll(contact_email) == ''){
      if(lang=="en")
          error_msg += "Email cannot be blank.\n";
      if(lang=="es")
          error_msg += "El campo para tu correo electrónico (email) no debe permanecer en blanco.\n";
  }
  /* check Email format */
  if(trimAll(contact_email) != "") {
    if(echeck(contact_email) != true)
    {
        if(lang=="en")
           error_msg += "Please enter a valid email address.\n";
        if(lang=="es")
           error_msg += "Entre por favor una correo electrónico válidas.\n";
    }
  }
  
  /* Check for special character in phone. */
  if(trimAll(contact_phone) != '')  {
    if(checkSpecialChars(contact_phone)==-1){
      error_msg += "Phone number cannot take characters(A - Z) or (\\\';/).\n";
    }
  }

  /* check referral is blank or not */
  if(trimAll(contact_referral) == 'blank'){
      if(lang=="en")
          error_msg += "You must select how you heard about this promotion.\n";
      if(lang=="es")
          error_msg += "Es necesario que indiques cómo te enteraste de esta promoción.\n";
  }

  /* check other is blank or not */
  if((trimAll(contact_referral) == 'Other:') && (trimAll(contact_other) == '')) {
      if(lang=="en")
         error_msg += "You must enter a response if you have selected \'Other\'.\n";
      if(lang=="es")
         error_msg += "Usted debe entrar una respuesta si usted escogió \'Otro\'.\n";
  }

  /* check agreement has been checked */
  if(!contact_agree){
      if(lang=="en")
          error_msg += "You must agree to the terms and conditions of this promotion.\n";
      if(lang=="es")
          error_msg += "Es necesario que estés de acuerdo con los términos y condiciones de esta promoción.\n";
  }
  if(error_msg != ""){
    alert (error_msg);
    return false;
  }
  else{    
 
    /*document.contact_us_frm.submit();
    document.contact_us_frm.action="index.php?id=346";*/
    return true;
  }
}