//------------------------------------------------------------------------------------------//
// Ce fichier contient l'ensemble des fonctions javascripts					//
// disponibles dans l'ensemble des pages php							//
// 												//
// Dans chaque fichier php souhaitant appeler ces 						//
// fonctions il faut insérer la ligne suivante:							//
//	<script language="JavaScript" type="text/javascript" src="include/script.js"></script>	//
//												//
//------------------------------------------------------------------------------------------//




//------------------------------------------------------//
// getDate()
// 		
// Cette fonction est utilisée retoourner la date
// du jour					
// 						
// en entrée:					
//						
// en sortie: date du jour (format: JJ/MM/AAAA)	
//						
//------------------------------------------------------//
function getDate(){
	Today = new Date;
	Jour = Today.getDate();
	Mois = (Today.getMonth())+1;
	Annee = Today.getFullYear();
	Message = Jour + "/" + Mois + "/" + Annee;
	return Message; 
}

//------------------------------------------------------//
// verifMail(email)
// 		
// Cette fonction est utilisée vérifier
// le format d'un email			
// 					
// en entrée: string email à vérifier	
//					
// en sortie: TRUE or FALSE		
//					
//------------------------------------------------------//
function verifMail(email)
{
  
   if ( ( email.indexOf("@") == -1 ) || ( email.indexOf("@") == 0 ) || ( email.indexOf("@") != email.lastIndexOf("@") ) || ( email.indexOf(".") == email.indexOf("@")-1 ) || ( email.indexOf(".") == email.indexOf("@") +1 ) || ( email.indexOf("@") == email.length -1 ) || ( email.indexOf (".") == -1 ) || ( email.lastIndexOf (".") == email.length -1 ) )
         return false;
   else
         return true;
   
}

//----------------------------------------------------------//
// checkConfirm(action,url)
// 			
// Cette fonction est utilisée demander confirmation
// d'une action						
// 							
// en entrée: - action ( possibilités : del,mod,sup,clone)
//			  - url				
//							
// en sortie: redirection vers la page demandée		
//							
//----------------------------------------------------------//
function checkConfirm(action,the_url)
{
	if(action=='del')
	{
		if(confirm('Voulez-vous supprimer cet élément ?'))
		document.location.href=the_url;
	}
	else if(action=='mod')
	{
		if(confirm('Voulez-vous modifier cet élément ?'))
		document.location.href=the_url;
	}
	else if(action=='add')
	{
		if(confirm('Voulez-vous ajouter cet élément ?'))
		document.location.href=the_url;
	}
	else if(action=='clone')
	{
		if(confirm('Voulez-vous dupliquer ce débiteur ?'))
		document.location.href=the_url;
	}
	
	
}

//----------------------------------------------------------//
// isDateValid(chaineDate)
// 			
// Cette fonction est utilisée demander vérifier la saisie 
// d'une date
// 							
// en entrée: - chaineDate
//				
//
//
//----------------------------------------------------------//
function isDateValid(d){

      var separateur="/"; // separateur entre jour/mois/annee
      var j=(d.mb_substring(0,2));
      var m=(d.mb_substring(3,5));
      var a=(d.mb_substring(6));
    
      var ok=1;

      if ( ((isNaN(j))||(j<1)||(j>31)) && (ok==1) ) {
         ok=0;
      }
      if ( ((isNaN(m))||(m<1)||(m>12)) && (ok==1) ) {
        ok=0;
      }
      if ( ((d.mb_substring(2,3)!=separateur)||(d.mb_substring(5,6)!=separateur)) && (ok==1) ) {
        ok=0;
      }
      if (ok==1) {
         var d2=new Date(a,m-1,j);
         j2=d2.getDate();
         m2=d2.getMonth()+1;
         a2=d2.getFullYear();

         if (a2<=100) {a2=1900+a2}
         if ( (j!=j2)||(m!=m2)||(a!=a2) ) {
            ok=0;
         }
      }
      	if(ok==0)
      	{
      		return false;
	}
	else
	{
		return true;
	}
}


//----------------------------------------------------------//
// popupCourrier()
// 			
// Cette fonction est utilisée pour ouvrir 
// la page de création des courriers
// 							
// en entrée: - chaineDate
//				
//
//
//----------------------------------------------------------//
function popupCourrier() 
{
	
	para = 'courrier_add.php';
	window.open(para,'','width=600,height=450,directories=no,scrollbars=1');
	
}


//----------------------------------------------------------//
// START
// AJAX: STAT EMAIL
// 			
//----------------------------------------------------------//

function ajaxStat(id_guide,mode)
{
	if(window.XMLHttpRequest) // FIREFOX
	xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
	xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
	return(false);
	ficajaxstat='../addon/ajaxstat.php?id_guide='+id_guide+'&mode='+mode;
	//alert(ficajaxstat);
	xhr_object.open("GET", ficajaxstat, false);
	xhr_object.send(null);

//if(xhr_object.readyState == 4) return(xhr_object.responseText);
//else return(false);
return(false);
}

//----------------------------------------------------------//
// END
// AJAX: STAT EMAIL
// 			
//----------------------------------------------------------//


//------------------------------------------------------//
// checkSearch()
//------------------------------------------------------//
function checkSearch4(strDefault)
{
	//var bReturn = false;
	var strInputSearch = document.getElementById('form_words').value;
	var exp_reg = /[<>]/gi; 
	if(exp_reg.test(strInputSearch) || (strInputSearch ===strDefault))
	{
         	return false;
   	}
   	else
   	{
        	return true;
	} 
}
