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

function sureDelImg(act1){
	if (confirm("Esti sigur ca vrei sa stergi aceasta imagine?")==true) window.location.replace(act1);
}

function sureDelVideo(act1){
	if (confirm("Esti sigur ca vrei sa stergi aceasta inregistrare video?")==true) window.location.replace(act1);
}

function sureDelAudio(act1){
	if (confirm("Esti sigur ca vrei sa stergi aceasta inregistrare audio?")==true) window.location.replace(act1);
}


function msgCheckNumber(number, msg){
   if(number.length>0){
    if(!isNaN(number)) return true
    else{
    	alert(msg)
      return false
    }
   }
   else{
   		alert(msg)
      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 checkFiliala(){
	
	for(i = 1; i <= 4; i++){
		
		val = document.getElementById(i).value;
		if(!val.length){
			
			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;
	}
	
	return true;
	
}


function checkPartener(){
	
		
	val = document.getElementById('1').value;
	if(!val.length){
		
		alert("Introduceti va rog numele!");
		document.getElementById('1').focus();
		return false;
			
	}
	
	return true;
	
}

function checkEveniment(){
	
		
	val = document.getElementById('1').value;
	if(!val.length){
		
		alert("Introduceti va rog titlul evenimentului!");
		document.getElementById('1').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;
}

