//Demande une confirmation Suppression de XX
function AskDelete (UrlHereIGo, WhatToDelete)
{if(window.confirm('Confirmez vous la suppression de '+WhatToDelete+' ?'))window.location.href = UrlHereIGo;}

function isAnOkDate (DateStr){
  //Ne vérifie pas le format XX-XX-XXXX.
  //on considère X come étant un entier valide.
  var tYear  = DateStr.substring(6, 11);
  var tMonth = DateStr.substring(3, 5);
  var tDay   = DateStr.substring(0, 2);
  var NbJour = 31;

  //test des bornes "normales".
  if ((tMonth < 1) || (tMonth > 12) || (tDay < 1)){
     return false;
  }

  //création du nombre de jour max du mois
  if (tMonth == 4 || tMonth == 6 || tMonth == 9 || tMonth == 11){
     NbJour = 30;
  }

  if (tMonth == 2){
     //test bissecxtile.
     NbJour = 28;
     if (tYear % 4 == 0){
        if (tYear % 100 == 0){
           if (tYear % 400 == 0){
              NbJour = 29;
           }
        }else{
           NbJour = 29;
        }
     }
  }
  if (tDay > NbJour){
     return false;
  }
  return true;
}

var popingWindow = null;
function popUniq (url, w, h){
  if (popingWindow == null || popingWindow.closed) {
     popingWindow = window.open(url,'popup','resize=yes, scrollbars=yes,width='+w+',height='+h);
  }else{
     popingWindow.location = url;
  }
  popingWindow.moveBy(0, 0);
  popingWindow.focus ();
}

//************************************************************************
// renvoie true si le string est de type entier positif ou nul, sinon false
//************************************************************************
function isEntierStr(strValue) {
	if (strValue.indexOf(" ") >= 0) {
		return false;
	}
	if (isNaN(strValue) || strValue.indexOf(".")>=0 || strValue.indexOf(",")>=0 || strValue.indexOf("-")>=0) {
		return false;
	} else {
		return true;
	}
}

/*********************************************************************
* renvoie true si l'annee en parametre est bissextile
*********************************************************************/
function isBissextile(annee) {
	if (annee % 4 == 0) 	{
		if ((annee % 100 ==0) && (annee%400!=0))
			return false;
		else
			return true;
	} else
		return false;
}

//sDate au format jj/mm/aaaa
//************************************************************************
// renvoie true si la date est bien inférieure ou égale à la date courante
// la date doit etre au format DD/MM/YYYY (passée dans la fonction isBooleanDate)
//************************************************************************
function isDateBeforeToday(sDate) {
	var theStepA,theStepB;
	var theJour,theMois,theAnnee;
	var curJ, curM, curA;
	var curD;

	curD = new Date();
	theStepA = sDate.indexOf("/");
	theJour  = sDate.substring(0, theStepA);
	theStepA = theStepA+1;

	theStepB = sDate.indexOf("/", theStepA);
	theMois  = sDate.substring(theStepA, theStepB);
	theStepA = theStepB+1;
	theAnnee = sDate.substring(theStepA, sDate.length);

	curJ = curD.getDate();
	curM = (curD.getMonth() + 1)
	curA = curD.getFullYear()
	
	if (theAnnee > curA)
		return false;
	if (theAnnee < curA)
		return true;
		
	if (theMois > curM)
		return false;
	if (theMois < curM)
		return true;

	if (theJour > curJ)
		return false;
	else
		return true;
}

//************************************************************************
// renvoie true si la date est bien au format DD/MM/YYYY
//************************************************************************
function isBooleanDate(sDate) {
	var theStepA,theStepB;
	var theJour,theMois,theAnnee;
	var sDateCopy = sDate;

	if (sDate.length != 10)
		return false;

	if (sDate.indexOf("/") != 2)
		return false;

	theStepA = sDate.indexOf("/");
	theJour  = sDate.substring(0, theStepA);
	theStepA = theStepA+1;

	if (sDate.indexOf("/", theStepA) != 5)
		return false;

	theStepB = sDate.indexOf("/", theStepA);
	theMois  = sDate.substring(theStepA, theStepB);
	theStepA = theStepB+1;
	theAnnee = sDate.substring(theStepA, sDate.length);

	if (theAnnee.length != 4 || theMois.length != 2 || theJour.length != 2
					|| !isEntierStr(theJour) || !isEntierStr(theMois) || !isEntierStr(theAnnee))
		return false;
	else
		return (isBooleanDateJJMMAAAA(parseInt(theJour,10), parseInt(theMois,10), parseInt(theAnnee,10), sDateCopy));
}

//************************************************************************
// Verifie si l'utilisateur saisit bien une date au format DD/MM/YYYY : renvoie un booleen
//************************************************************************
function isBooleanDateJJMMAAAA(aJJ,aMM,aAAAA,sDate) {
	var longueur = sDate.length;
	
	if (longueur != 10) {
		return false;
	} 
	
	if (isNaN(aAAAA) || aAAAA < 1900 || aAAAA > 2100) {
		return false;
	}
	
	if (aMM==1 || aMM==3 || aMM==5 || aMM==7 || aMM==8 || aMM==10 || aMM==12) {
		if (aJJ<1 || aJJ>31)
			return false;
		else
			return true;
	}
	
	if (aMM==4 || aMM==6 || aMM==9 || aMM==11) {
		if (aJJ<1 || aJJ>30)
			return false;
		else
			return true;
	}
	
	if (aMM==2) {
		var nbj =28;
		if (isBissextile(aAAAA)) 
			nbj=29;

		if (aJJ<1 || aJJ>nbj)
			return false;
		else
			return true;
	}

	return false;
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function addFav() { 
	if (document.all) { 
		window.external.AddFavorite(location.href, document.title); 
	} else { 
		alert('Vous pouvez faire CTRL + D pour ajouter cette page dans vos signets, ou favoris.') 
	} 
} 

