var today = new Date();
var iWDay = today.getDay();
var iMDay = today.getDate();
var iYDay = today.getDate();
var iMonth = today.getMonth()+1;
var iYear = today.getFullYear();
var tMDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31); // nb de jours d'un mois, celui de février est 29 si iYear bissextile
var tRien = new Array(undefined, null,"");


/**   Remplace des caracteres dans une chaine
 * @param   string   _zNeedle    chaine de caracteres a remplacer
 * @param   string   _zRepl    chaine de caracteres de remplacement
 * @param   string   _bStuck    Détermine si remplacement par caractère (false) ou par chaîne
 * @return  string   zRet        chaine de caractere obtenu
 **/
String.prototype.multiReplace = function(_zNeedle, _zRepl, _bStuck){
		var ret = "";
		if (_zNeedle!=undefined && _zNeedle!=null)  {
			if (_zRepl==undefined || _zRepl==null) {
				_zRepl = "";
			}
			if (_bStuck!=undefined && _bStuck!=null && _bStuck) { //remplacer les occurrences de _zNeedle
				ret = this.split(_zNeedle);
				ret = ret.join(_zRepl);
			} else { //remplacer les occurrences de chaque caractère de _zNeedle
				for (b=0; b<this.length; b++) {
			   	if ((c = _zNeedle.indexOf(this.charAt(b)))!=-1) {
						if (c<_zRepl.length) {
							ret += _zRepl.charAt(c);
						} else {
							if (_zRepl.length>0) {
								ret += _zRepl.charAt(_zRepl.length-1);
							} else {
								if (_zRepl!='') {
									ret += this.charAt(b);
								}
							}
						}
					} else {
						ret += this.charAt(b);
					}
			   }
			}
		}
// 		alert(this + "\n" + ret);
		return ret;
	};
// end method multiReplace()

/**
* Fonction de formatage de date FR en date EN (format mysql)
*
* @param 	String 	_zDatefr Date FR
* @return	String	zDatesql Date UK (ou NULL)
*/
function toDateSQL(_zDateFr) {
// 	alert(_zDateFr);
	zDateFr = _zDateFr.multiReplace(" ");
	tDate = zDateFr.split('/');
// 	alert(tDate);
	if (tDate[0]!="") {
		return tDate[2] + "-" + tDate[1] + "-" + tDate[0];
	}
	return zDateFr;
}

/**   Transforme en une chaîne date au format spécifié les données
 *
 *
 **/
function dateFormat(_iYear, _iMonth, _iDate, _zFormat) {
	if (_zFormat==undefined || _zFormat==null || _zFormat=="") {
	   _zFormat = "d/m/Y";
	}
	if (_iYear==undefined || _iYear==null || _iYear=="") {
	   _iYear = iYear;
	}
	if (_iYear%4==0) {
		tMDays[1] = 29;
	}
	
	if (_iMonth==undefined || _iMonth==null || _iMonth=="" || _iMonth<0 || _iMonth>11) {
		_iMonth = iMonth;
	}
	if (_iDate==undefined || _iDate==null || _iDate=="" || _iDate<1 || _iDate>tMDays[_iMonth]) {
	   _iDate = iMDay;
	}
	
	zYear = ""+_iYear;
	zMonth = (_iMonth<10) ?"0"+_iMonth :_iMonth;
	zDate = (_iDate<10) ?"0"+_iDate :_iDate;
	
	switch (_zFormat) {
	   case "d/m/Y":
	      return zDate+"/"+zMonth+"/"+zYear;
	      break;
	   case "m/d/Y":
	      return zMonth+"/"+zDate+"/"+zYear;
	      break;
		default :
		   alert("format inconnu");
		   return;
		   break;
	}
}