/************************** isRef 1.0 2005-02-15
 *
 * Auteur : Sébastien Poubelle
 *
 * Retourne la référence du navigateur : 'DOM', 'IE4' ou 'NS4'.
 *
 */

function isRef() {
	if(document.getElementById) return "DOM";
	if(document.all) return "IE4";
	if(document.layers) return "NS4";
	}

/************************** getRef 1.3 2005-02-15
 *
 * Auteur : Sébastien Poubelle
 *
 * Retourne l'appelle javascript d'un identifiant 'id' de la page HTML
 *
 */

function getRef(id) {
	if(isRef() == "DOM") return document.getElementById(id);
	if(isRef() == "IE4") return document.all[id];
	if(isRef() == "NS4") return document.layers[id];
	}

function ejs_img_fx(img) {
	if(img && img.filters && img.filters[0]) {
		img.filters[0].apply();
		img.filters[0].play();
		}
	}

function loadOne() {
        window.location.reload();
        }

function openwindow(url,name,width,height,ptop,pleft) {
	window.open(url,name,'toolbar=0,menubar=0,scrollbars=yes,resizable=0,width=' + width + ',height=' + height + ',top=' + ptop + ',left=' + pleft);
	}

/************************** supprimer
 *
 * Version : 1.2 2003-09-04
 * Auteur : Sebastien Poubelle
 *
 * Appelle la page supprimer.php qui permet de supprimer
 * l'enregistrement 'id' de la table 'table' de la base
 * de donnée courante.
 * 'url' est l'adresse de retour et 'arg' est la chaine
 * de caractères correspondant aux argument à retourner.
 *
 */

function supprimer(id,table,url,arg) {
	if(confirm("Confirmez-vous la suppression définitive ?\n")) {
		location = "/supprimer.php?id="+ id +"&table="+ table +"&url="+ url +"&arg=&"+ arg;
		}
	}

function ajouter(id,url) {
	pleft = (window.screen.availWidth - 550) / 2;
	ptop = (window.screen.availheight - 450) / 2;
	openwindow(url+'_modifier.php?id='+id,'modifier',550,450,ptop,pleft);
	}

function repondre(id,table) {
	pleft = (window.screen.availWidth - 550) / 2;
	ptop = (window.screen.availheight - 450) / 2;
	openwindow('/repondre.php?id='+id+'&table='+table,'repondre',550,450,ptop,pleft);
	}

function fiche(id,table)
{
        pleft = (window.screen.availWidth - 550) / 2;
        ptop = (window.screen.availheight - 450) / 2;
        openwindow('/fiche.php?id='+id+'&table='+table,'fiche',550,450,ptop,pleft);
}

function traiter(id,table) {
        pleft = (window.screen.availWidth - 550) / 2;
        ptop = (window.screen.availheight - 450) / 2;
        openwindow('/traiter.php?id='+id+'&table='+table,'traiter',550,450,ptop,pleft);
        }

function valider_traitement(color,id,table) { // version 1.1
        if(confirm("Confirmez-vous le traitement ?")) {
                document.getElementById("nowLoading").innerHTML = "<font color='"+ color +"'>TRAITEMENT EN COURS</font>";
                document.location.href = "/traiter_valid.php?id="+ id +"&table="+ table;
               }
        }

/************************** loaded 2.0 2005-03-29
 *
 * Auteur : Jérôme Demyttenaere, Sébastien Poubelle
 *
 *
 */

function loaded(color) {
	reloaded(color,"nowLoading");
	}

/************************** reloaded 1.0 2005-02-15
 *
 * Auteur : Sébastien Poubelle
 *
 *
 */

function reloaded(color,id) { // version 1.2
	getRef(id).innerHTML = "<font color='"+ color +"'>TRAITEMENT EN COURS</font>";
	}

/************************** IsNumeric 3.0
 *
 * Auteur : Jérôme Demyttenaere
 *
 *
 */

function IsNumeric(strString)
// check for valid numeric strings
{
        var strValidChars = "0123456789.- ";
        var strChar;
        var blnResult = true;

        if (strString.length == 0) return false;

        // test strString consists of valid characters listed above
        for (i = 0; i < strString.length && blnResult == true; i++)
        {
                strChar = strString.charAt(i);
                if (strValidChars.indexOf(strChar) == -1) blnResult = false;
        }
        return blnResult;
}

/************************** popup 3.0 2005-03-29
 *
 * Auteur : Sébastien Poubelle
 *
 * void popup( String pop_url , Int pop_width , Int pop_height [ , String pop_bar ] )
 *
 * pop_url : url de la page pop-up.
 * pop_width : largeur de la fenêtre en pixel.
 * pop_height : hauteur de la fenêtre en pixel.
 * pop_bar : affichage de la scrollbar, option : 'yes' / 'no'.
 *
 */

function popup(pop_url,pop_width,pop_height) {
	var pop_bar = "yes", pop_arg = popup.arguments;
	if(pop_arg.length == 4) pop_bar = pop_arg[3];
	pop_name = pop_url.substring(0,pop_url.indexOf("."));
	pop_left = (window.screen.availWidth / 2) - (pop_width / 2);
	pop_top = (window.screen.availHeight / 2) - (pop_height / 2);
	window.open(pop_url,pop_name,"left=" + pop_left + ",top=" + pop_top + ",width=" + pop_width + ",height=" + pop_height + ",scrollbars="+ pop_bar +",noresize");
	}

function agrandir(img_src,link_color,bg_color) {
	var pop_width = 640;
	var pop_height = 480;
	var pop_img = new Image();
	pop_img.src = img_src;
	pop_win = window.open("","","width="+ pop_width +",height="+ pop_height +",scrollbars=no");
	pop_win.document.open();
	pop_win.document.write("<head><title>"+ pop_img.src +"</title></head>");
	pop_win.document.write("<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0");
	pop_win.document.write(" link='"+ link_color +"' alink='"+ link_color +"' vlink='"+ link_color +"' bgcolor='"+ bg_color +"'>");
	pop_win.document.write("<table width='100%' height='100%' border=0>");
	pop_win.document.write("<tr><td align=center valign=middle><img src='"+ pop_img.src +"'></td></tr>");
	pop_win.document.write("<tr><td align=center valign=middle><font size='1' face='Verdana, Arial, Helvetica, sans-serif'>");
	pop_win.document.write("<a href='javascript:window.close();'>Close window</a>");
	pop_win.document.write("</font></td></tr>");
	pop_win.document.write("</table>");
	pop_win.document.write("</body>");
	pop_win.document.close();
	if(pop_img.width != 0 || pop_img.height != 0) {
		pop_width = pop_img.width + 40;
		pop_height = pop_img.height + 80;
		pop_win.resizeTo(pop_width,pop_height);
		}
	pop_left = (window.screen.availWidth / 2) - (pop_width / 2);
	pop_top = (window.screen.availHeight / 2) - (pop_height / 2);
	pop_win.moveTo(pop_left,pop_top);
	}

function print_image(img_src) {
	var pop_width = 640;
	var pop_height = 480;
	var pop_img = new Image();
	pop_img.src = img_src;
	pop_win = window.open("","window_print_image","width=0,height=0,scrollbars=no");
	pop_win.document.open();
	pop_win.document.write("<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>");
	pop_win.document.write("<img src='"+ pop_img.src +"'>");
	pop_win.document.write("</body>");
	pop_win.document.close();
	if(pop_img.width != 0 || pop_img.height != 0) {
		pop_width = pop_img.width;
		pop_height = pop_img.height;
		pop_win.resizeTo(pop_width,pop_height);
		}
	pop_win.print();
	pop_win.close();
	}

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];
			}
		}
	}

/************************** calque_open 1.0 2006-03-17
 *
 * Auteur : Sébastien Poubelle
 *
 */


function calque_open(id) {
	if(getRef(id).style.visibility == 'hidden') {
		getRef(id).style.visibility = 'visible';
//		setTimeout("calque_close('"+id+"')",9000);
		}
	else getRef(id).style.visibility = 'hidden';
	}


/************************** calque_close 1.0 2006-03-17
 *
 * Auteur : Sébastien Poubelle
 *
 */


function calque_close(id) {
	getRef(id).style.visibility = 'hidden';
	}



/************************** calendar 2.0 2006-03-21
 *
 * Auteur : Sébastien Poubelle
 *
 */


function calendar(id, buttoncolor, bgcolor, color, langue, fonction_input, m_plus) {
	var str = "";
	var flg = 0;
	M_fr = new Array("Janvier","Fevier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre");
	D_fr = new Array("Dim","Lun","Mar","Mer","Jeu","Ven","Sam");
	M_uk = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	D_uk = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");

	M = M_uk;
	D = D_uk;
	if(langue == "fr") {
		M = M_fr;
		D = D_fr;
		}

	if(m_plus < 0) m_plus = 0;
	if(m_plus > 12) m_plus = 12;

	pdy = new Date();        // today
	pmo = pdy.getMonth();    // present month
	pyr = pdy.getYear();     // present year
	if(pyr < 1000) pyr += 1900;

	yr = pyr;                // present year
	mo = pmo + m_plus;       // present month
	if(mo > 11) {
		mo = mo - 12;
		yr++;
		}

	bgn = new Date(M_uk[mo] + " 1," + yr); // assign to date

	dy = bgn.getDay();
	yr = eval(yr);
	d = "312831303130313130313031";
	if (yr / 4 == Math.floor(yr / 4)){
		d = d.substring(0,2) + "29" + d.substring(4,d.length);
		}
	pos = (mo*2);
	ld = eval(d.substring(pos,pos+2));

	str += ""
	+ "<TABLE align=\"left\" bgcolor=\""+ bgcolor +"\" cellpadding=\"1\" cellspacing=\"2\" style=\"border:1px solid "+ color +";\">"
	+ "<TR><TD width=\"15%\" align=\"center\" bgcolor=\""+ buttoncolor +"\" style=\"cursor:pointer;font-size:12px;font-family:Verdana,sans-serif;color:"+ color +";\" onclick=\"calendar('"+ id +"','"+ buttoncolor +"','"+ bgcolor +"','"+ color +"','"+ langue +"','"+ fonction_input +"',"+ (m_plus-1) +");\"><B>&#171;</B></TD><TD width=\"70%\" align=\"center\" colspan=\"5\" style=\"font-size:10px;font-family:Verdana,sans-serif;color:"+ color +";\"><B>"+ M[mo] +" "+ yr +"</B></TD><TD width=\"15\" align=\"center\" bgcolor=\""+ buttoncolor +"\" style=\"cursor:pointer;font-size:12px;font-family:Verdana,sans-serif;color:"+ color +";\" onclick=\"calendar('"+ id +"','"+ buttoncolor +"','"+ bgcolor +"','"+ color +"','"+ langue +"','"+ fonction_input +"',"+ (m_plus+1) +");\"><B>&#187;</B></TD></TR>"
	+ "<TR>";
	for (var i=0;i<7;i++){
		str += "<TD width=\"15%\" style=\"font-size:10px;font-family:Verdana,sans-serif;color:"+ color +";\" align=\"center\">"+ D[i] +"</TD>";
		}
	str += "</TR><TR>";
	ctr = 0;
	for(var i = 0; i < 7; i++) {
		if (i < dy){
			str += "<TD width=\"15%\"></TD>";
			}
		else{
			ctr++;
			jour = ""+ ctr; 
			if(jour.length < 2) jour = "0"+ jour;
			mois = ""+ (mo+1); 
			if(mois.length < 2) mois = "0"+ mois;
			str += "<TD width=\"15%\" bgcolor=\""+ buttoncolor +"\" align=\"center\" style=\"cursor:pointer;font-size:10px;font-family:Verdana,sans-serif;color:"+ color +";\" onclick=\""+ fonction_input +"('"+ jour +"','"+ mois +"','"+ yr +"');calque_close('"+ id +"');\">"+ ctr +"</TD>";
			}
		}
	str += "</TR><TR>";
	while (ctr < ld){
		for (var i = 0; i < 7; i++){
			ctr++;
			if (ctr > ld){
				str += "<TD width=\"15%\"></TD>";
				}
			else{
				jour = ""+ ctr; 
				if(jour.length < 2) jour = "0"+ jour;
				mois = ""+ (mo+1); 
				if(mois.length < 2) mois = "0"+ mois;
				str += "<TD width=\"15%\" bgcolor=\""+ buttoncolor +"\" align=\"center\" style=\"cursor:pointer;font-size:10px;font-family:Verdana,sans-serif;color:"+ color +";\" onclick=\""+ fonction_input +"('"+ jour +"','"+ mois +"','"+ yr +"');calque_close('"+ id +"');\">"+ ctr +"</TD>";
				}
			}
		str += "</TR><TR>";
		}
	str += "</TR></TABLE>";
	getRef(id).innerHTML = str;
//	alert(str);
	}


/************************** mailto 1.1 2007-06-22
 *
 * Auteur : Sébastien Poubelle
 *
 */


function mailto(user,domaine,style) {
	var at = "@"
	document.write("<a href=\"mailto:"+ user + at + domaine +"\" style=\""+ style +"\">");
	document.write(user + at + domaine +"</a>");
	}


