function arata_subcategorii(element, nr_total, nr_curent)
{

  for(i=0; i<nr_total; i++) {
   if(document.getElementById(element+i) != undefined && i!=nr_curent)
    document.getElementById(element+i).style.display='none';
  }


  if(document.getElementById(element+nr_curent).style.display == 'none')
          document.getElementById(element+nr_curent).style.display='';
  else
    document.getElementById(element+nr_curent).style.display='none';

}





function IsNumeric(sText){

   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;

}

function IsTelephone(sText){

   var ValidChars = "0123456789- ";
   var IsNumber=true;
   var Char;

   for (k = 0; k < sText.length && IsNumber == true; k++) {
      Char = sText.charAt(k);
      if (ValidChars.indexOf(Char) == -1){
         IsNumber = false;
      }
   }
   return IsNumber;

}

function echeck(str) {
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
     alert("Adresa de email incorecta")
     return false
  }
  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
     alert("Adresa de email incorecta")
     return false
  }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Adresa de email incorecta")
      return false
  }
   if (str.indexOf(at,(lat+1))!=-1){
      alert("Adresa de email incorecta")
      return false
   }
   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Adresa de email incorecta")
      return false
   }
   if (str.indexOf(dot,(lat+2))==-1){
      alert("Adresa de email incorecta")
      return false
   }
   if (str.indexOf(" ")!=-1){
      alert("Adresa de email incorecta")
      return false
   }
   return true;
}


function validarenewuser() {

        if (document.getElementById('user_email').value == '') {
                alert('Va rugam sa completati adresa de email');
                document.getElementById('user_email').focus();
                return false;
        }
        if (echeck(document.getElementById('user_email').value)==false){
               document.getElementById('user_email').value="";
               document.getElementById('user_email').focus();
               return false;
        }
        if (document.getElementById('parola').value.length < 6) {
                alert('Parola trebuie sa aibe cel putin 6 caractere');
                document.getElementById('parola').focus();
                return false;
        }
        if (document.getElementById('parola').value != document.getElementById('parola1').value ) {
                alert('Parolele nu corespund!');
                document.getElementById('parola1').focus();
                return false;
        }
        if (document.getElementById('checkbox').value==''){
                                 alert('Trebuie sa acceptati termenii si conditiile');
                                 return false;
        }
    return true;
}

function validareAdaugareCont() {

        if (document.getElementById('user_last_name').value == '') {
                alert('Va rugam sa completati numele');
                document.getElementById('user_last_name').focus();
                return false;
        }
        if (document.getElementById('user_first_name').value == '') {
                alert('Va rugam sa completati prenumele');
                document.getElementById('user_first_name').focus();
                return false;
        }
        if (document.getElementById('user_cnp').value == '') {
                alert('Va rugam sa completati C.N.P.');
                document.getElementById('user_cnp').focus();
                return false;
        }
        if (document.getElementById('county_id').value == '') {
                alert('Va rugam sa selectati judetul');
                document.getElementById('county_id').focus();
                return false;
        }
        if (document.getElementById('city_id').value == '') {
                alert('Va rugam sa selectati localitatea');
                document.getElementById('city_id').focus();
                return false;
        }
        if (document.getElementById('address_street').value == '') {
                alert('Va rugam sa completati adresa');
                document.getElementById('address_street').focus();
                return false;
        }
        if (document.getElementById('zip_code').value == '') {
                alert('Va rugam sa completati codul postal');
                document.getElementById('zip_code').focus();
                return false;
        }
        if (IsNumeric(document.getElementById('zip_code').value) == false) {
                alert('Campul cod postal trebuie sa contina doar numere');
                 document.getElementById('zip_code').focus();
                return false;
       }
        if ((document.getElementById('user_phone').value == '')&&
            (document.getElementById('user_mobile_phone').value == '')) {
                alert('Va rugam sa completati cel putin un numar de telefon');
                document.getElementById('user_phone').focus();
                return false;
        }

    return true;
}

function validareAdresaUser() {

        if (document.getElementById('county_id').value == '') {
                alert('Va rugam sa selectati judetul');
                document.getElementById('county_id').focus();
                return false;
        }
        if (document.getElementById('city_id').value == '') {
                alert('Va rugam sa selectati localitatea');
                document.getElementById('city_id').focus();
                return false;
        }
        if (document.getElementById('address_street').value == '') {
                alert('Va rugam sa completati adresa');
                document.getElementById('address_street').focus();
                return false;
        }
        if (document.getElementById('zip_code').value == '') {
                alert('Va rugam sa completati codul postal');
                document.getElementById('zip_code').focus();
                return false;
        }
         if (IsNumeric(document.getElementById('zip_code').value) == false) {
                alert('Campul cod postal trebuie sa contina doar numere');
                document.getElementById('zip_code').focus();
                return false;
       }
    return true;
}

function validareAdaugareFirma() {

        if (document.getElementById('id_caen').value == '') {
                alert('Va rugam sa alegeti codul caen principal al firmei');
                document.getElementById('id_caen').focus();
                return false;
        }

        if (document.getElementById('company_name').value == '') {
                alert('Va rugam sa completati numele firmei');
                document.getElementById('company_name').focus();
                return false;
        }
        if (document.getElementById('company_function').value == '') {
                alert('Va rugam sa completati functia dvs la firma');
                document.getElementById('company_function').focus();
                return false;
        }
        if (document.getElementById('county_id').value == '') {
                alert('Va rugam sa selectati judetul');
                document.getElementById('county_id').focus();
                return false;
        }
        if (document.getElementById('city_id').value == '') {
                alert('Va rugam sa selectati localitatea');
                document.getElementById('city_id').focus();
                return false;
        }
        if (document.getElementById('address_street').value == '') {
                alert('Va rugam sa completati adresa');
                document.getElementById('address_street').focus();
                return false;
        }
        if (document.getElementById('zip_code').value == '') {
                alert('Va rugam sa completati codul postal');
                document.getElementById('zip_code').focus();
                return false;
        }
        if (IsNumeric(document.getElementById('zip_code').value) == false) {
                alert('Campul cod postal trebuie sa contina doar numere');
                 document.getElementById('zip_code').focus();
                return false;
       }
       if (document.getElementById('company_fiscal_code').value == '') {
                alert('Va rugam sa completati codul fiscal');
                document.getElementById('company_fiscal_code').focus();
                return false;
        }

       if (document.getElementById('company_registry_commerce').value == '') {
                alert('Va rugam sa completati registrul comertului');
                document.getElementById('company_registry_commerce').focus();
                return false;
        }

        if ((document.getElementById('company_phone').value == '')&&
            (document.getElementById('company_mobile_phone').value == '')) {
                alert('Va rugam sa completati cel putin un numar de telefon');
                document.getElementById('company_phone').focus();
                return false;
        }

    return true;
}

function validareAdresaFirma() {

        if (document.getElementById('company_id').value == '') {
                alert('Va rugam sa selectati numele firmei');
                document.getElementById('company_id').focus();
                return false;
        }
        if (document.getElementById('address_street').value == '') {
                alert('Va rugam sa completati adresa');
                document.getElementById('address_street').focus();
                return false;
        }
        if (document.getElementById('county_id').value == '') {
                alert('Va rugam sa selectati judetul');
                document.getElementById('county_id').focus();
                return false;
        }
        if (document.getElementById('city_id').value == '') {
                alert('Va rugam sa selectati localitatea');
                document.getElementById('city_id').focus();
                return false;
        }
        if (document.getElementById('zip_code').value == '') {
                alert('Va rugam sa completati codul postal');
                document.getElementById('zip_code').focus();
                return false;
        }
        if (IsNumeric(document.getElementById('zip_code').value) == false) {
                alert('Campul cod postal trebuie sa contina doar numere');
                document.getElementById('zip_code').focus();
                return false;
       }
    return true;
}
function validatePassword() {
  if (document.getElementById('user_password').value.length < 5) {
      alert('Parola trebuie sa aibe cel putin 5 caractere');
      document.getElementById('user_password').focus();
      return false;
  }
  if (document.getElementById('user_password').value != document.getElementById('user_password1').value ) {
      alert('Parolele nu corespund!');
      document.getElementById('user_password1').focus();
      return false;
  }
  return true;
}

function validareLogin() {

        if (document.getElementById('email').value == '') {
                alert('Va rugam sa completati adresa de email');
                document.getElementById('email').focus();
                return false;
        }
         if (document.getElementById('parola_utilizator').value == '') {
                alert('Va rugam sa completati parola');
                document.getElementById('parola_utilizator').focus();
                return false;
        }


    return true;
}

function validareEmail1(camp) {

  if (document.getElementById(camp).value == '') {
    alert('Va rugam sa completati campul "Email"');
    document.getElementById(camp).focus();
    return false;
  }

  if (echeck(document.getElementById(camp).value)==false){
    document.getElementById(camp).value="";
    document.getElementById(camp).focus();
    return false;
  }
   return true;
}

function validareRecomanda() {

        if (document.getElementById('user_name').value == '') {
                alert('Va rugam sa completati numele');
                document.getElementById('user_name').focus();
                return false;
        }
       if (document.getElementById('user_email').value == '') {
                alert('Va rugam sa completati adresa de email');
                document.getElementById('user_email').focus();
                return false;
        }
       if (echeck(document.getElementById('user_email').value)==false){
               document.getElementById('user_email').value="";
               document.getElementById('user_email').focus();
               return false;
       }

       if (document.getElementById('friend_email').value == '') {
                alert('Va rugam sa completati adresa de email');
                document.getElementById('friend_email').focus();
                return false;
        }
       if (echeck(document.getElementById('friend_email').value)==false){
               document.getElementById('user_email').value="";
               document.getElementById('friend_email').focus();
               return false;
       }

    return true;
}

function validareCategorie(){

  if (document.getElementById('category_name').value == '') {
     alert('Va rugam sa completati numele categoriei');
     document.getElementById('category_name').focus();
     return false;
  }
  return true;
}

function validareMeta(id){

 if (document.getElementById(id).value.length > 255) {
               alert('Campul "Meta description" trebuie sa contina cel mult 255 de caractere');
               document.getElementById(id).focus();
               return false;
            }
    return true;
}

function validareComment(id){

 if (document.getElementById(id).value.length > 300) {
               alert('Comentariul trebuie sa contina cel mult 300 de caractere');
               document.getElementById(id).focus();
               return false;
            }
 if (document.getElementById(id).value.length == 0) {
               alert('Introduceti un comentariu');
               document.getElementById(id).focus();
               return false;
            }

    return true;
}

function showdiv(parameter){
  if (document.getElementById(parameter).style.visibility == 'hidden'){
      document.getElementById(parameter).style.visibility ='visible';
      document.getElementById(parameter).style.display ='block';
  }
  else {
      document.getElementById(parameter).style.visibility ='hidden';
      document.getElementById(parameter).style.display ='none';
  }
}
