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 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 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 validareAddManufacturer(){
 if (document.getElementById('manufacturer_name').value=='') {
    alert('Completati campul "Nume"');
    document.getElementById('manufacturer_name').focus();
    return false;
 }

 return true;
}

function validareLogin(){
 if (document.getElementById('user_name').value=='') {
    alert('Completati campul "User name"');
    document.getElementById('user_name').focus();
    return false;
 }

  if (document.getElementById('user_password').value=='') {
    alert('Completati campul "Parola"');
    document.getElementById('user_password').focus();
    return false;
 }

 if (document.getElementById('user_password').value.length<5) {
    alert('Campul "Parola" trebuie sa contina cel putin 5 caractere');
    document.getElementById('user_password').focus();
    return false;
 }

 return true;
}

function validareLoginError(){
 if (document.getElementById('user_name1').value=='') {
    alert('Completati campul "User name"');
    document.getElementById('user_name1').focus();
    return false;
 }

  if (document.getElementById('user_password1').value=='') {
    alert('Completati campul "Parola"');
    document.getElementById('user_password1').focus();
    return false;
 }

 if (document.getElementById('user_password1').value.length<5) {
    alert('Campul "Parola" trebuie sa contina cel putin 5 caractere');
    document.getElementById('user_password1').focus();
    return false;
 }

 return true;
}

function validareAddCarPart(){
 if (document.getElementById('part_name').value=='') {
    alert('Completati campul "Nume"');
    document.getElementById('part_name').focus();
    return false;
 }

  if (document.getElementById('part_code2').value=='') {
    alert('Completati campul "Cod piesa 2"');
    document.getElementById('part_code2').focus();
    return false;
 }

 return true;
}

function validareAddPage(){

 if (document.getElementById('page_title').value=='') {
    alert('Completati campul "Titlu"');
    document.getElementById('page_title').focus();
    return false;
 }

  if (document.getElementById('page_details').value=='') {
    alert('Completati campul "Continut"');
    document.getElementById('page_details').focus();
    return false;
 }

 if (document.getElementById('page_position').value=='') {
    alert('Completati campul "Pozitia in site"');
    document.getElementById('page_position').focus();
    return false;
 }
 return true;
}


function validareAddClient(){

 if (document.getElementById('company_name').value=='') {
    alert('Completati campul "Nume"');
    document.getElementById('company_name').focus();
    return false;
 }

  if (document.getElementById('company_fiscal_code').value=='') {
    alert('Completati campul "Cod fiscal"');
    document.getElementById('company_fiscal_code').focus();
    return false;
 }

 if (document.getElementById('company_registry_commerce').value=='') {
    alert('Completati campul "Registrul comertului"');
    document.getElementById('company_registry_commerce').focus();
    return false;
 }

  if (document.getElementById('county_id').value=='') {
    alert('Alegeti un judet');
    document.getElementById('county_id').focus();
    return false;
 }

 if (document.getElementById('city_id').value=='') {
    alert('Alegeti un oras');
    document.getElementById('city_id').focus();
    return false;
 }
  /*
  if (document.getElementById('address_street').value=='') {
    alert('Completati campul "Strada"');
    document.getElementById('address_street').focus();
    return false;
 }

 if (document.getElementById('adress_flat').value=='') {
    alert('Completati campul "Bloc"');
    document.getElementById('adress_flat').focus();
    return false;
 }

 if (document.getElementById('adress_stair').value=='') {
    alert('Completati campul "Scara"');
    document.getElementById('adress_stair').focus();
    return false;
 }

  if (document.getElementById('apartment_no').value=='') {
    alert('Completati campul "Apartament"');
    document.getElementById('apartment_no').focus();
    return false;
 }

  if (document.getElementById('zip_code').value=='') {
    alert('Completati campul "Cod postal"');
    document.getElementById('zip_code').focus();
    return false;
 }
 */

  if ((document.getElementById('company_phone').value!='') && IsTelephone(document.getElementById('company_phone').value)==false) {
    alert('Introduceti un numar de telefon valid');
    document.getElementById('company_phone').focus();
    return false;
 }

 if ((document.getElementById('company_mobile_phone').value!='') && IsTelephone(document.getElementById('company_mobile_phone').value)==false) {
    alert('Introduceti un numar de telefon valid');
    document.getElementById('company_mobile_phone').focus();
    return false;
 }

  if ((document.getElementById('company_fax').value!='') && IsTelephone(document.getElementById('company_fax').value)==false) {
    alert('Introduceti un numar de fax valid');
    document.getElementById('company_fax').focus();
    return false;
 }

 if ((document.getElementById('company_email').value!='') && echeck(document.getElementById('company_email').value)==false) {
    alert('Introduceti o adresa de email valida');
    document.getElementById('company_email').focus();
    return false;
 }

 if (document.getElementById('discount_procent').value=='') {
    alert('Completati campul "Procent discount"');
    document.getElementById('discount_procent').focus();
    return false;
 }

  if (document.getElementById('user_name').value=='') {
    alert('Completati campul "User name"');
    document.getElementById('user_name').focus();
    return false;
 }

 if (document.getElementById('user_password').value=='') {
    alert('Completati campul "Parola"');
    document.getElementById('user_password').focus();
    return false;
 }

 if (document.getElementById('user_password').value.lenght<5) {
    alert('Campul "Parola" trebuie sa aiba cel putin 5 caractere');
    document.getElementById('user_password').focus();
    return false;
 }
 return true;
}


function validareAddAdmin(){
 if (document.getElementById('admin_last_name').value=='') {
    alert('Va rugam completati campul "Nume"');
    document.getElementById('admin_last_name').focus();
    return false;
 }

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

 if ((document.getElementById('admin_phone').value!='') && IsTelephone(document.getElementById('admin_phone').value)==false) {
    alert('Introduceti un numar de telefon valid');
    document.getElementById('admin_phone').focus();
    return false;
 }

  if (document.getElementById('admin_email').value=='') {
    alert('Completati campul "Email"');
    document.getElementById('admin_email').focus();
    return false;
 }

 if ((document.getElementById('admin_email').value!='') && echeck(document.getElementById('admin_email').value)==false) {
    alert('Introduceti o adresa de email valida');
    document.getElementById('admin_email').focus();
    return false;
 }

 if (document.getElementById('admin_password').value=='') {
    alert('Completati campul "Parola"');
    document.getElementById('admin_password').focus();
    return false;
 }
 return true;
}
