function check_cust_form() 
{
   var f = document.cust_add_mod_account; 

   if (!validateEmail(f.email.value)) {
      f.email.focus();
      alert ("Adresa E-Mail nu este valida.");
      return false;
   }

   if (f.pass.value.length < 4) { 
      f.pass.focus();
      alert ("Parola trebuie sa aibe cel putin 4 caractere."); 
      return false;
   } 

   if (!is_all_char_num_underscore(f.pass.value)) {
      f.pass.focus();
      alert ("Parola nu este valida! Numai litere, cifre, si underscore sint acceptate."); 
      return false;
   }

   if (f.pass.value != f.confirm_pass.value) {
      f.confirm_pass.focus();
      alert ("Parola si Parola de Verificare nu sint identice."); 
      return false;
   } 

   f.last_name.value = trim_multi_spaces(f.last_name.value);
   if (f.last_name.value.length < 1) { 
      f.last_name.focus();
      alert ("Numele este obligatoriu."); 
      return false;
   } 

   f.first_name.value = trim_multi_spaces(f.first_name.value);
   if (f.first_name.value.length < 1) { 
      f.first_name.focus();
      alert ("Prenumele este obligatoriu."); 
      return false;
   } 

   f.company_name.value = trim_multi_spaces(f.company_name.value);

   f.street1.value = trim_multi_spaces(f.street1.value);
   if (f.street1.value.length < 2) { 
      f.street1.focus();
      alert ("Strada este obligatorie si trebuie sa contina cel putin 2 caractere."); 
      return false;
   } 

   f.street2.value = trim_multi_spaces(f.street2.value);

   f.city.value = trim_multi_spaces(f.city.value);
   if ((f.city.value.length < 1) || (!is_all_char_num_space(f.city.value))) { 
      f.city.focus();
      alert ("Orasul este obligatoriu."); 
      return false;
   } 

   f.judet_state.value = trim_multi_spaces(f.judet_state.value);
   if ((f.judet_state.value.length < 2) || (!is_all_char_dot_space(f.judet_state.value))) { 
      f.judet_state.focus();
      alert ("Judetul este obligatoriu. Numai cifre si punct sint acceptate."); 
      return false;
   } 

   if (f.postal_code.value.length < 4) { 
      f.postal_code.focus();
      alert ("Codul postal necesita cel putin 4 caractere."); 
      return false;
   } 

   if (f.country.value.charAt(0) == "-") {
      f.country.focus()
      alert("Va rugam sa alegeti o Tara.")
      return false;
   }

   f.day_phone.value = trim_multi_spaces(f.day_phone.value);
   if (f.day_phone.value.length < 1) { 
      f.day_phone.focus();
      alert ("Numarul de telefon este obligatoriu.");
      return false;
   } 
   if (f.day_phone.value.length > 18) { 
      f.day_phone.focus();
      alert ("Numarul de telefon poate avea maximum 18 caractere.");
      return false;
   } 
   f.day_phone_ext.value = trim_multi_spaces(f.day_phone_ext.value);

   f.other_phone.value = trim_multi_spaces(f.other_phone.value);
   if (f.other_phone.value.length > 18) {
      f.other_phone.focus();
      alert ("Numarul de mobil poate avea maximum 18 caractere.");
      return false;
   } 
   f.other_phone_ext.value = trim_multi_spaces(f.other_phone_ext.value);

   f.fax_number.value = trim_multi_spaces(f.fax_number.value);
   if (f.fax_number.value.length > 18) {
      f.fax_number.focus();
      alert ("Numarul de fax poate avea maximum 18 caractere.");
      return false;
   } 

   return true;
}

function check_cust_info_addr_form() 
{
   var f = document.cust_info_addr_mod_account; 

   f.last_name.value = trim_multi_spaces(f.last_name.value);
   if (f.last_name.value.length < 1) { 
      f.last_name.focus();
      alert ("Numele este obligatoriu."); 
      return false;
   } 

   f.first_name.value = trim_multi_spaces(f.first_name.value);
   if (f.first_name.value.length < 1) { 
      f.first_name.focus();
      alert ("Prenumele este obligatoriu."); 
      return false;
   } 

   f.company_name.value = trim_multi_spaces(f.company_name.value);

   f.street1.value = trim_multi_spaces(f.street1.value);
   if (f.street1.value.length < 2) { 
      f.street1.focus();
      alert ("Strada este obligatorie si trebuie sa contina cel putin 2 caractere."); 
      return false;
   } 

   f.street2.value = trim_multi_spaces(f.street2.value);

   if ((f.city_pay_extra) && (f.city_pay_extra[1].checked)) {
      f.city.value = trim_multi_spaces(f.city.value);
      if ((f.city.value.length < 1) || (!is_all_char_num_space(f.city.value))) { 
         f.city.focus();
         alert ("Orasul este obligatoriu."); 
         return false;
      } 
   }

   f.judet_state.value = trim_multi_spaces(f.judet_state.value);
   if ((f.judet_state.value.length < 2) || (!is_all_char_dot_space(f.judet_state.value))) { 
      f.judet_state.focus();
      alert ("Judetul este obligatoriu. Numai cifre si punct sint acceptate."); 
      return false;
   } 

   if (f.postal_code.value.length < 4) { 
      f.postal_code.focus();
      alert ("Codul postal necesita cel putin 4 caractere."); 
      return false;
   } 

   if (f.country.value.charAt(0) == "-") {
      f.country.focus()
      alert("Va rugam sa alegeti o Tara.")
      return false;
   }

   f.day_phone.value = trim_multi_spaces(f.day_phone.value);
   if (f.day_phone.value.length < 1) { 
      f.day_phone.focus();
      alert ("Numarul de telefon este obligatoriu.");
      return false;
   } 
   if (f.day_phone.value.length > 18) { 
      f.day_phone.focus();
      alert ("Numarul de telefon poate avea maximum 18 caractere.");
      return false;
   } 
   f.day_phone_ext.value = trim_multi_spaces(f.day_phone_ext.value);

   f.other_phone.value = trim_multi_spaces(f.other_phone.value);
   if (f.other_phone.value.length > 18) {
      f.other_phone.focus();
      alert ("Numarul de mobil poate avea maximum 18 caractere.");
      return false;
   } 
   f.other_phone_ext.value = trim_multi_spaces(f.other_phone_ext.value);

   f.fax_number.value = trim_multi_spaces(f.fax_number.value);
   if (f.fax_number.value.length > 18) {
      f.fax_number.focus();
      alert ("Numarul de fax poate avea maximum 18 caractere.");
      return false;
   } 

   return true;
}

function check_cart_login_form()
{
   var f = document.cart_login; 

   if (f.email.value.length < 1) { 
      f.email.focus();
      alert ("Adresa E-Mail este obligatorie. Daca sinteti un client nou va rugam sa va inregistrati."); 
      return false;
   } 

   if (!validateEmail(f.email.value)) {
      f.email.focus();
      alert ("Adresa E-Mail nu este valida.");
      return false;
   }

   if (f.pass.value.length < 4) { 
      f.pass.focus();
      alert ("Parola trebuie sa aibe cel putin 4 caractere."); 
      return false;
   } 

   if (!is_all_char_num_underscore(f.pass.value)) {
      f.pass.focus();
      alert ("Parola nu este valida! Numai litere, cifre, si underscore sint acceptate."); 
      return false;
   }

   return true;
}

function check_pass_retrieve_email_form()
{
   var f = document.cart_pass_retrieve; 

   if (f.email.value.length < 1) { 
      f.email.focus();
      alert ("Adresa E-Mail este obligatorie. Daca sinteti un client nou va rugam sa va inregistrati."); 
      return false;
   } 

   if (!validateEmail(f.email.value)) {
      f.email.focus();
      alert ("Adresa E-Mail nu este valida.");
      return false;
   }

   return true;
}

function check_cust_change_login_info_form()
{
   var f = document.cust_change_login_info_form; 

   if (f.email.value.length < 1) { 
      f.email.focus();
      alert ("Noua Adresa E-Mail este obligatorie."); 
      return false;
   } 

   if (!validateEmail(f.email.value)) {
      f.email.focus();
      alert ("Adresa E-Mail nu este valida.");
      return false;
   }

   if (f.old_pass.value.length < 1) { 
      f.old_pass.focus();
      alert ("Parola curenta trebuie specificata pentru a schimba parola ori adresa E-Mail."); 
      return false;
   } 

   if (f.pass.value.length > 0) { 
      if (f.pass.value.length < 4) { 
         f.pass.focus();
         alert ("Parola trebuie sa aibe cel putin 4 caractere."); 
         return false;
      } 

      if (!is_all_char_num_underscore(f.pass.value)) {
         f.pass.focus();
         alert ("Parola nu este valida! Numai litere, cifre, si underscore sint acceptate."); 
         return false;
      }

      if (f.pass.value != f.confirm_pass.value) { 
         f.confirm_pass.focus();
         alert ("Parola de verificare trebuie sa fie identica cu parola noua."); 
         return false;
      }
   } 

   return true;
}
function cart_redeem_cupon()
{
   document.show_cart_form.redeem_flag.value = '1';
}

function cart_set_ship_addr() {
   /* Set the hidden variable radio_btn_click to 1 and submit */
   document.cart_delivery_form.radio_btn_click.value = '1';
   document.cart_delivery_form.submit();
}

function cart_clear_ship_addr() {
   /* Set the hidden variable radio_btn_click to 1 and submit */
   document.cart_delivery_form.radio_btn_click.value = '0';
   document.cart_delivery_form.submit();
}

function submit_payment_form(form) {
   for (idx = 0; idx<form.pay_method.length; idx++) {
      if (form.pay_method[idx].value == "ePayment") {
         if (!form.pay_method[idx].checked) {
            form.action=form.alt_route.value;
         }
         return;
      }
   }
}

function is_all_char_num_underscore(str) {
   var valid_chars =/^[a-z0-9_]{0,32}$/i;
   return valid_chars.test(str);
}

function is_all_char_num_space(str) {
   var valid_chars =/^[a-z][-a-z0-9 ]{0,32}$/i;
   return valid_chars.test(str);
}

function is_all_char_dot_space(str) {
   var valid_chars =/^[a-z][-a-z\. ]{0,32}$/i;
   return valid_chars.test(str);
}

function is_valid_phone_num(str) {
   var valid_chars =/(^[0-9]{5}-[0-9]{3}-[0-9]{3}$)|(^[0-9]{4}-[0-9]{3}-[0-9]{3}$)|(^[0-9]{3}-[0-9]{3}-[0-9]{4}$)/i;
   return valid_chars.test(str);
}

function trim_multi_spaces(str)
{
   var reg_exp = /\s+/g;
   str = TrimAll(str);
   return str.replace(reg_exp, " "); 
}

function validateEmail( strValue) {
   var objRegExp = /(^[a-z]([a-z0-9_\-\.]*)@([a-z0-9_\.]*)([.][a-z]{2,3})$)|(^[a-z]([a-z0-9_\.]*)@([a-z0-9_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

  //check for valid email
  return objRegExp.test(strValue);
}

function LTrim(str) {
   if (str==null){return null;}
   for(var i=0;str.charAt(i)==" ";i++);
   return str.substring(i,str.length);
}

function RTrim(str) {
   if (str==null){return null;}
   for(var i=str.length-1;str.charAt(i)==" ";i--);
   return str.substring(0,i+1);
}

function Trim(str) {return LTrim(RTrim(str));}

function LTrimAll(str) {
   if (str==null){return str;}
   for (var i=0; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i++);
   return str.substring(i,str.length);
}

function RTrimAll(str) {
   if (str==null){return str;}
   for (var i=str.length-1; str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t"; i--);
   return str.substring(0,i+1);
}

function TrimAll(str) {
   return LTrimAll(RTrimAll(str));
}

//Validates that a string a United States zip code in 5 digit format or zip+4 format.
// - example:  4444, 55555, 666666 or 55555-4444
// This API is not used because it is not complete.
function validateZip( strValue ) {
   var objRegExp  = /(^\d{4,5}$)|(^\d{6}$)|(^\d{5}-\d{4}$)/;
  return objRegExp.test(strValue);
}


