
function sureDel(what,act1){
	if (confirm("Esti sigur ca vrei sa stergi "+what+"?")==true) window.location.replace(act1);
}

function confirmare(url, msg){
	if (confirm(msg)==true) window.location.replace(url);
}

function msgCheckNumber(number, msg){
   if(number.length>0){
    if(!isNaN(number)) return true
    else{
    	alert(msg)
      return false
    }
   }
   else{
   		alert(msg)
      return false
   }
}

function checkNumber(number){
   if(number.length>0){
    if(!isNaN(number)) return true
    else{
      return false
    }
   }
   else{
      return false
   }
}


function numberOf(chr,text){
  	var nr=0;
    for(var i=0;i<text.length;i++){
      if(text.charAt(i)==chr){
         nr++
      } 
    }
    return nr
}

function lastIndex(chr,text){
  	var nr=-1;
    for(var i=0;i<text.length;i++){
      if(text.charAt(i)==chr){
         nr=i
      } 
    }
    return nr
}



function checkMail(email){
    if(email.length<7){ 
    	return false
    }	
    else{
       if((email.indexOf('@')==-1)||(email.indexOf('.')==-1)){
          return false
       }
       else{
       	 last = lastIndex('.', email);
         if((email.indexOf('@')==0)||(last>(email.length-3))||(email.indexOf('@')>lastIndex('.', email))){
            return false
         }
         else{
           var nr=numberOf('@', email)
           var nr2=numberOf('.', email)
           if((nr>1)||(nr2>5)){
              return false
           }
           else return true
         }
       } 
    }
}






function checkDate(dt, format, minYear, maxYear){
   if(dt.length==format.length){
 //------------------ Check for csv ------------------------ 		
  	  for(i=0;i<format.length;i++){
  	  	if((format.charAt(i)!='d')&&(format.charAt(i)!='m')&&(format.charAt(i)!='y')&&
  	  	  (format.charAt(i)!=dt.charAt(i))){
  	  		return false
  	  	}	
  	  }

 //------ Puth values of day, month, year in variables----------------- 
  	  var day=''
  	  var month=''
  	  var year=''
 
  	  for(i=0;i<format.length; i++){
        if((format.charAt(i)=='d')&&(format.charAt(i+1)=='d')){
        	day=dt.charAt(i)+dt.charAt(i+1)
        }
        if((format.charAt(i)=='m')&&(format.charAt(i+1)=='m')){
        	month=dt.charAt(i)+dt.charAt(i+1)
        }
        if((format.charAt(i)=='y')&&(format.charAt(i+1)=='y')&&(format.charAt(i+2)=='y')&&
        (format.charAt(i+3)=='y')){
            year=dt.charAt(i)+dt.charAt(i+1)+dt.charAt(i+2)+dt.charAt(i+3)
        }
      }
      
  //-----------First check of the variables---------------------
      if((isNaN(day)||(isNaN(month))||(isNaN(year)))){
        return false
      }

      if((year<minYear)||(year>maxYear)){
        return false            
      }
      
      if((month<1)||(month>12)){
        return false      
      }

      if((day<1)||(day>31)){
        return false      
      }

  //----------------Analize date-------------------------------------------------
  
      //------Check of the year it's parseEnglish(bisect) or not------    
      var bisect=0
      if((year%4)==0) bisect=1
      
      if((!bisect) && (month==2) &&(day>28)){
        return false            
      }          

      if((bisect) && (month==2) &&(day>29)){
        return false            
      }

      //-------------Check the day of the month-----------
      var bigMonthValues="01,03,05,07,08,10,12"
      if((bigMonthValues.indexOf(month)==-1)&&(day>30)){
        return false            
      }
      else return true
   }
   else{
  	 return false
   }
}  






function test_cont_nou(){
	
	for(i = 1; i <= 11; i++){
		
		val = document.getElementById(i).value;
		if(val.length == 0){
			alert('Completati va rog toate campurile obligatorii!');
			document.getElementById(i).focus();
			return false;
		}
		
	}
	
	email = document.getElementById('3').value;
	if(!checkMail(email)){
		alert('Adresa de email introdusa nu este valida!');
		document.getElementById('3').focus();
		return false;
	}
	
	data = document.getElementById('9').value;
	if(!checkDate(data, "dd/mm/yyyy", 1850, 2005)){
		alert('Introduceti data nasterii corecta in format zz/ll/aaaa!');
		document.getElementById('9').focus();
		return false;
	}
	
	parola = document.getElementById('10').value;
	confirmare = document.getElementById('11').value;
	
	if(parola != confirmare){
		alert('Campurile Parola si Confirmare parola trebuie sa contina aceeasi parola!');
		document.getElementById('10').value = '';
		document.getElementById('11').value = '';
		document.getElementById('10').focus();
		return false;
	}
	
	livrare = document.getElementById('area').value;
	if((document.getElementById('check').checked == false) && (livrare.length == 0)){
		alert('Introduceti adresa de livrare in cazul in care este diferita de cea de facturare');
		document.getElementById('area').focus();
		return false;
	}
	
	return true;
}


function test_cont_firma(){
	
	for(i = 1; i <= 15; i++){
		
		val = document.getElementById(i).value;
		if(val.length == 0){
			alert('Completati va rog toate campurile obligatorii!');
			document.getElementById(i).focus();
			return false;
		}
		
	}
	
	email = document.getElementById('8').value;
	if(!checkMail(email)){
		alert('Adresa de email introdusa nu este valida!');
		document.getElementById('8').focus();
		return false;
	}
	
	
	parola = document.getElementById('14').value;
	confirmare = document.getElementById('15').value;
	
	if(parola != confirmare){
		alert('Campurile Parola si Confirmare parola trebuie sa contina aceeasi parola!');
		document.getElementById('14').value = '';
		document.getElementById('15').value = '';
		document.getElementById('14').focus();
		return false;
	}
	
	livrare = document.getElementById('area').value;
	if((document.getElementById('check').checked == false) && (livrare.length == 0)){
		alert('Introduceti adresa de livrare in cazul in care este diferita de cea de facturare');
		document.getElementById('area').focus();
		return false;
	}
	
	return true;
}

function testActivare(){

	for(i = 1; i <= 2; i++){
		val = document.getElementById(i).value;
		if(val.length == 0){
			alert('Adresa de email si codul de activare nu pot fi nule!');
			document.getElementById(i).focus();
			return false;
		}
		
	}
	mail = document.getElementById('1').value;
	if(!checkMail(mail)){
		alert('Adresa de email introdusa ne este valida!');
		document.getElementById('1').focus();
		return false;
	}
	
	return true;
	
}

function retrimiteCod(){

	mail = document.getElementById('1').value;
	
	if(mail.length == 0){
		alert('Campul Adresa de email nu poate fi gol!');
		return false;
	}
	
	if(!checkMail(mail)){
		alert('Adresa de email introdusa ne este valida!');
		document.getElementById('1').focus();
		return false;
	}
	
	location.replace('activare_cont.php?retrimite=da&mail='+mail);	
	
}



function recuperareParola(){

	mail = document.getElementById('1').value;
	
	if(mail.length == 0){
		alert('Campul Adresa de email nu poate fi gol!');
		return false;
	}
	
	if(!checkMail(mail)){
		alert('Adresa de email introdusa ne este valida!');
		document.getElementById('1').focus();
		return false;
	}
	
	return true;	
}


function checkNewsMail(){

	mail = document.getElementById('news').value;
	
	if(mail.length == 0){
		alert('Adresa de email nu poate fi nula!');
		document.getElementById('news').focus();
		return false;
	}
	
	if(!checkMail(mail)){
		alert('Adresa de email introdusa ne este valida!');
		document.getElementById('news').focus();
		return false;
	}
	
	return true;	
}



function checkContact(){
	
	for(i = 1; i < 4; i++){
		val = document.getElementById(i).value;
		if(val.length == 0){
			alert('Toate campurile din acest formular sunt necesare!');
			document.getElementById(i).focus();
			return false;
		}
	}
	
	mail = document.getElementById('2').value;
	if(!checkMail(mail)){
		alert('Adresa de email introdusa ne este valida!');
		document.getElementById('2').focus();
		return false;
	}
	
	return true;
}

function showMessage(msg){
	alert(msg);
}

function redirect(cale, mesaj){
	alert(mesaj);
	location.replace(cale);
}