/* auteur: Francis LEROY */
/* Date de création: 17/12/2006 */

function ObjectDiv( div , content ) {

	if ( document.getElementById ( div )) {
		document.getElementById( div ).innerHTML = content;
	}else {
		if ( document.layers ) {
			if (document.div)
				document.div.innerHTML = content;
		}else {	    
			if (document.all.div)
				document.all.div.innerHTML = content;
		}
	}
}

function Goto( FILE , METHOD , DATA , div ) {

	if( METHOD == 'GET' && DATA != null ) {
		FILE += '?' + DATA;
		DATA = null;
	}

	var httpRequestM = null;

	if( window.XMLHttpRequest )	{ // Firefox
		httpRequestM = new XMLHttpRequest();
		SENS=true;
	}
	else if( window.ActiveXObject ) { // Internet Explorer
		httpRequestM = new ActiveXObject( "Microsoft.XMLHTTP" );
		SENS=true;
	}
	else { // XMLHttpRequest non supporté par le navigateur
		return "Votre navigateur ne supporte pas les objets XMLHTTPRequest...";
	}

	httpRequestM.open( METHOD , FILE , SENS );
	httpRequestM.onreadystatechange = function() {
		if( httpRequestM.readyState == 4 ) {
			// ObjectDiv( "loading" , "" );
			ObjectDiv( div , httpRequestM.responseText );
		}
	}

	if( METHOD == 'POST' ) {
		httpRequestM.setRequestHeader( "Content-type" , "application/x-www-form-urlencoded" );
	}

	httpRequestM.send( DATA );
}
  
function ViewContent( div , href , method , data ) {
//       var wait = "<div style='z-index:3'>" + 
//                  "<b><font style='color:red;'>Chargement en cours.....</font></b><br><br>" +
//       var wait =            "<img align=baseline src='./Javascript/loading.gif' border='0' height='21' width='150' alt='Chargement en cours....'>"; 
//                  "+ </div>";

//	ObjectDiv( "loading" , wait );
//	ObjectDiv( div , wait );
	Goto( href , method , data , div );
	return false;
}

function formater(nombre, taille) {
	if (isNaN(nombre)) return "";
	var chaine = nombre.toString();
	while (chaine.length < taille) chaine = "0" + chaine;
	return chaine;
}

function date_jour() {
	aujourdhui = new Date();
	j=aujourdhui.getDate();
	m=aujourdhui.getMonth();
	y=aujourdhui.getFullYear();
	return(formater(j,2)+"/"+formater((m+1),2)+"/"+formater((y-2000),2));
}

function verif_date(obj) {
	sel = document.getElementById(obj).value;
	if (sel!="" && sel.length!=6 && sel.length!=8) alert("Date incorrecte");
	else {
		a=sel.split("/");
		if (a.length==1) {
			if (sel.length==6) {
				val=sel.substr(0,2)+'/'+sel.substr(2,2)+'/'+sel.substr(4,2);
				test_date(val);
				document.getElementById(obj).value=val;
			}
			else {
				if (sel.length==8) {
					val=sel.substr(0,2)+'/'+sel.substr(2,2)+'/'+sel.substr(6,2);
					test_date(val);
					document.getElementById(obj).value=val;
				}
			}	
		}	
		else test_date(sel);	
	}	
}	

function test_date(dt) {
	mois=new Array();
	a=new Array();
	mois['01']=31;
	mois['02']=28;
	mois['03']=31;
	mois['04']=30;
	mois['05']=31;
	mois['06']=30;
	mois['07']=31;
	mois['08']=31;
	mois['09']=30;
	mois['10']=31;
	mois['11']=30;
	mois['12']=31;
	a=dt.split("/");
	if (a[0].length!=2 || a[1].length!=2 || a[2].length!=2) alert("Date incorrecte");
	if (a[2]%4==0) mois['02']=29;
	if (a[1]>12) alert("Date incorrecte");
	if (a[0]>mois[a[1]]) alert("Date incorrecte"); 
}	
