<!--



// }}}
// {{{

/**
 * Indique si une année est bisextile ou non
 */
function anneebisextile(a) {
	return (((a % 4 == 0) && (a % 100 != 0)) || (a % 400 == 0));
}

// }}}
// {{{

/**
 * Vérifie qu'une date est valide
 */
function checkdate(val){
	// Vérifie un format de date jj/mm/aa ou jj/mm/aaaa
	var expr = /^[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4,4}$/;
	if(expr.test(val)) {
		// Le format de la date est bon -> vérif si valeur cohérente
		t = val.split("/");
		j = parseInt(t[0], 10);
		m = parseInt(t[1], 10);
		a = parseInt(t[2], 10);

		if( m <= 0 || m > 12) return false;
		if( j <= 0 ) return false;
		if( a <= 0 ) return false;

		switch(m){
			// Février
			case 2:
				b = anneebisextile(a);// année bisextile
				if( b && j > 29) return false;
				if( !b && j > 28) return false;
				break;
			// Mois à 31 jours
			case 1 :
			case 3 :
			case 5 :
			case 7 :
			case 8 :
			case 10:
			case 12:
				if( j > 31) return false;
				break;
			// Mois à 30 jours
			default:
				if( j > 30) return false;
		}
		return true;
	}
	return false;
}

// }}}
// {{{

/**
 * Vérifie qu'une valeur est un entier
 */
function is_int(pval) {
	return (parseInt(pval, 10) == pval);
}

// }}}
// {{{

/**
 * Verification d'un champs email format minimum xx@x.xx
 * @param string nomform
 * @param string nomchp
 * @todo remplacer les 2 paramètres par 1 seul qui contiendrait l'email à vérifier
 */
function verif_mail(pval){
		var a         = trim(pval);
		var posarr    = a.indexOf('@');
		var pos_point = a.lastIndexOf('.');
		var longueur  = a.length;
		if(    (longueur<6)
		    || (posarr<2)
		    || (pos_point<(posarr+2))
		    || (pos_point>(longueur-3))
		    || ((pos_point+1)<(longueur-3))) {

		  return false;
		}
		else {
		  return true;
		}
}

	// }}}
	// {{{

	/**
	 * Retourne la chaine val sans tag HTML
	 * @param string val
	 */
	function strip_tag(val) {
		return remplace(/<[a-zA-Z\/]+[^<]*>/,'', val);
	}

	// }}}
	// {{{

	/**
	 * Retourne la chaine val sans caractère d'échapement (retour à la ligne...)
	 * @param string val
	 */
	function strip_echap(val){
		return remplace(/\n|\s|\t/, '', val);
	}

	// }}}
	// {{{

	/**
	 * Retourne la chaine val avec les caractères remplacés
	 * @param string regExpr 	expression régulière javascript de ce qu'il y a à remplacer
	 * @param string rempl 		expression de remplacement
	 * @param string val 		chaine "source"
	 */
	function remplace(regExpr, rempl, val) {
		var i = 0;
		var p = -1;
		while ( regExpr.test(val) ) {
			val = val.replace(regExpr, rempl);
		}
		return val;
	}

	// }}}
	// {{{

  /**
   * Vire les espaces et &nbsp; en début et fin de chaine (fonction trim traditionnelle)
   * @param 	string val 		valeur à trimer
   * @return 	string 			valeur trimée
   */
  function trim(val) {
    while(val.substring(0, 1) == ' ') {
      val = val.substring(1, val.length);
    }
    while(val.substring(val.length-1,val.length) == ' '){
      val = val.substring(0, val.length-1)
    }

    // on vire les &nbsp;
    while(val.substring(0, 5) == '&nbsp;') {
      val = val.substring(6, val.length);
    }
    while(val.substring(val.length-6,val.length) == '&nbsp;'){
      val = val.substring(0, val.length-6)
    }

    return val;
  }

  // }}}
  // {{{

  /**
   * Ouvre une popup au milieu de l'écran
   * @param string 	url 			url du contenu de la popup
   * @param int 		largeur
   * @param int 		hauteur
   * @param string 	param 		paramètres JS supplémentaires
   * @param string 	nom 			titre de la popup
   * @param boolean 	maximiser 	true ouvre la popup en plein écran (maximisé)
   */
  function openWin(url, largeur, hauteur, param, nom, maximiser, fermer){
		if ( eval( 'maximiser' ) == true ) {
			var x = 0;
			var y = 0;
			var win = window.open(url,nom,param+(param!="" ? "," : "")+"width="+(screen.availWidth-15)+",height="+(screen.availHeight-15)+",left="+x+",top="+y);
		}
		else {
			var x = (screen.availWidth-largeur)/2;
			var y = (screen.availHeight-hauteur)/2;
			if ( parseFloat(x) != x ) x = 0;
			if ( parseFloat(y) != y ) y = 0;
			var win = window.open(url,nom,param+(param!="" ? "," : "")+"width="+largeur+",height="+hauteur+",left="+x+",top="+y);
		}
		if ( eval ( 'fermer' ) > 0 ) {
			//setInterval("eval('win').close()", "+fermer+");
			//win.document.write("<HTML><HEAD><TITLE>"+nom+"</TITLE>");
			//win.document.write("<SCRIPT language=javascript> function fermer() { self.close(); } </SCRIPT></HEAD><BODY onload='self.setInterval(fermer, "+fermer+");'></BODY></HTML>");
			//win.document.close();
			//win.close();
		}
		return win;
	}

	// }}}
	// {{{

	/**
	 * Idem openWin utilisé pour des raison de compatibilité
	 */
	function popup(url, largeur, hauteur, param, nom, maximiser){
		openWin(url, largeur, hauteur, param, nom, maximiser);
	}

	// }}}
	// {{{

	/**
	 * Ouvre une popup à la taille de l'image qu'elle contient et l'affiche au centre de l'écran
	 * @param string img 	url de l'image à chargé dans la popup
	 * @param string titre 	titre de la popup
	 */
	function PopupImage(img, titre) {
		w = open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');
		w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
		w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+26,document.images[0].height+60); window.moveTo(parseInt((screen.availWidth-(document.images[0].width+26))/2), parseInt((screen.availHeight-(document.images[0].height+60))/2)); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
		w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><a href='#' onclick='javascript:self.close()'><IMG src='"+img+"' border=0></a>");
		w.document.write("");
		w.document.write("</BODY></HTML>");
		w.document.close();
	}

	// }}}
	// {{{

	/**
	 * Affiche une popup contenant une carte avec la position marqué par un icone
	 * @param string img 	chemin relatif de l'image
	 * @param string titre 	titre de la popup et de la page
	 * @param int outy 		position en y (ordonné)
	 * @param int outx 		position en x (abscisse)
	 */
	function PopupCarto(img, titre, outy, outx) {
		var w=open("", "",'width=400,height=400,statusbar=no,toolbar=no,scrollbars=no,resizable=yes');
		w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
		w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+30,document.images[0].height+80); window.focus(); positionne(); window.moveTo(parseInt((screen.availWidth-(document.images[0].width+12))/2), parseInt((screen.availHeight-(document.images[0].height+60))/2));} else { setTimeout('check()',250) } } function positionne() { document.getElementById('Layer0').style.top="+outy+"; document.getElementById('Layer0').style.left="+outx+"; }</"+"SCRIPT>");
		w.document.write("<BODY onload='checksize();' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0 style='top:0px;left:0px;'>");
		w.document.write("<IMG src='"+img+"' border=0>");
		w.document.write("<DIV id='Layer0' style='position: absolute; left: "+(outx+16)+"px; top: "+(outy+16)+"px;z-index:1 '>");
		w.document.write("<IMG name='icone' SRC='/img/picto-cible.gif' border='0'>");
		w.document.write("</DIV> ");
		w.document.write("<center><button type='custom'  onclick='window.close()'>Fermer</button></center>");
		w.document.write("");
		w.document.write("<script language=javascript></script></BODY></HTML>");
		w.document.close();
	}
	function PopupCarto2(img, titre, outy, outx) {
		var w=open("", "",'width=400,height=400,statusbar=no,toolbar=no,scrollbars=no,resizable=yes');
		var reg=new RegExp("[ ,;#]+", "g");
		var out_x=outx.split(reg);
		var out_y=outy.split(reg);
		w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
		w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+30,document.images[0].height+80); window.focus(); positionne(); window.moveTo(parseInt((screen.availWidth-(document.images[0].width+12))/2), parseInt((screen.availHeight-(document.images[0].height+60))/2));} else { setTimeout('check()',250) } } ");
		w.document.write("function positionne() {");
		for (var l=0; l<out_x.length; l++)
			{	
			w.document.write("document.getElementById('Layer"+l+"').style.top="+out_y[l]+"; ");
			w.document.write("document.getElementById('Layer"+l+"').style.left="+out_x[l]+"; ");
			}
		w.document.write("}</"+"SCRIPT>");
		w.document.write("<BODY onload='checksize();' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0 style='top:0px;left:0px;'>");
		w.document.write("<IMG src='"+img+"' border=0>");
		for (var l=0; l<out_x.length; l++)
			{
			//alert(out_x[l]);
			var nb=l+1;
			w.document.write("<DIV id='Layer"+l+"' style='position: absolute; left: "+(out_x[l]+16)+"px; top: "+(out_y[l]+16)+"px;z-index:"+nb+" '>");
			w.document.write("<IMG name='icone' SRC='/img/picto-cible.gif' border='0'>");
			w.document.write("</DIV> ");
			}
		w.document.write("<center><button type='custom'  onclick='window.close()'>Fermer</button></center>");
		w.document.write("");
		w.document.write("<script language=javascript></script></BODY></HTML>");
		w.document.close();
	}

	// }}}
	// {{{

	/**
	 * Affiche la popup d'aide appropriée
	 * @param string id 	nom de la constante LANG_AIDE_*
	 */
	function PopupAide(id) {
		if ( trim(id) == '' ) return;
		popup('/pages/aide.php?id='+id, 400, 400, 'statusbar=no,toolbar=no,scrollbars=yes,resizable=no', "Aide", false);
	}


//-->