var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
/*** ***** Utiliser ***** ***/

function getRef(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) 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 mailing_valider() {
	mail = document.mailing.mail.value;
	if(mail == "" || mail.indexOf("@") == "-1" || mail.indexOf(".") == "-1") {
		alert("Vous n'avez pas saisi de mail correct.\n");
		document.mailing.mail.focus();
		return;
		}
	if(document.mailing.cp.value != "" && IsNumeric(document.mailing.cp.value) == false) {
		alert("Votre code postal est incorrect.");
		document.mailing.cp.focus();
		return;
		}
	if(document.mailing.tel.value != "" && IsNumeric(document.mailing.tel.value) == false || document.mailing.tel.value != "" && document.mailing.tel.value.length < 10 ) {
		alert("Votre numéro de téléphone est incorrect.");
		document.mailing.tel.focus();
		alert("'"+ document.mailing.tel.value +"'");
		return;
		}
	// OPTION 1
//	popup("mailing_valid.php?mail="+ mail,320,220);
//	document.mailing.mail.value = "votre e-mail";

	// OPTION 2
//	document.location.href = "mailing_valid.php?mail="+ mail;

	// OPTION 3
	loaded();
	document.mailing.submit();

	}

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 repondre_adm(id,table) {
	pleft = (window.screen.availWidth - 550) / 2;
	ptop = (window.screen.availheight - 450) / 2;
	openwindow('../myadmin/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;
               }
        }

function loaded(color) { // version 1.2
        document.getElementById("nowLoading").innerHTML = "<font color='"+ color +"'>TRAITEMENT EN COURS</font>";
        }

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

function popup(pop_url,pop_width,pop_height) {
        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=yes,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 width='600' 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();'>Fermer la fen&ecirc;tre</a>");
	pop_win.document.write("</font></td></tr>");
	pop_win.document.write("</table>");
	pop_win.document.write("</body>");
	pop_win.document.close();
	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];
			}
		}
	}

function valider(form) {
	if(form.name == "reservation_promo") {
		chambre_quantite = 0;
		debut_heure = 1;
		fin_heure = 1;
		nom = 1;
		tel = 1;
		fax = 1;
		mail = 1;
		personnes = 1;
		}
	else if(form.name == "reservation") {
		chambre_quantite = 1;
		debut_heure = 1;
		fin_heure = 1;
		nom = 1;
		tel = 1;
		fax = 1;
		mail = 1;
		personnes = 0;
		}
	var email = form.mail.value;
	if(chambre_quantite == 1) {
		if(form.chambre_quantite.value == "" || form.chambre_quantite.value == "0" || IsNumeric(form.chambre_quantite.value) == false) {
			alert("Vous devez préciser le nombre de chambres à réserver.");
			form.chambre_quantite.focus();
			return;
			}
		}
	if(debut_heure == 1) {
		if(form.debut_heure.value == "" || form.debut_heure.value == "00" || IsNumeric(form.debut_heure.value) == false) {
			alert("Vous devez préciser une heure d'arrivée correcte.");
			form.debut_heure.focus();
			return;
			}
		}
	if(fin_heure == 1) {
		if(form.fin_heure.value == "" || form.fin_heure.value == "00" || IsNumeric(form.fin_heure.value) == false) {
			alert("Vous devez préciser une heure de départ correcte.");
			form.fin_heure.focus();
			return;
			}
		}
	if(nom == 1) {
		if(form.nom.value == "") {
			alert("Vous navez pas saisi de Nom");
			form.nom.focus();
			return;
			}
		}
	if(tel == 1) {
		if(form.tel.value == "" || IsNumeric(form.tel.value) == false || form.tel.value.length < 10 ) {
			alert("Vous devez préciser un numéro de téléphone correct.");
			form.tel.focus();
			return;
			}
		}
	if(fax == 1) {
		if(form.fax.value != "" && IsNumeric(form.fax.value) == false) {
			alert("Vous devez préciser un numéro de fax correct.");
			form.fax.focus();
			return;
			}
		}
	if(mail == 1) {
		if(email.indexOf("@") == "-1" || email.indexOf(".") == "-1" || email == "" ) {
			alert("Vous navez pas saisi de Mail");
			form.mail.focus();
			return;
			}
		}
	if(personnes == 1) {
		if(form.personnes.value == "") {
			alert("Vous navez pas saisi le nombre de personne");
			form.personnes.focus();
			return;
			}
		}
	loaded();
	form.submit();
	}

/*
var infullscreen;

function fullscreen(full) {
	if(isDOM) {
		if(navigator.appName == "Microsoft Internet Explorer") {
			if(full) {
				infullscreen = window.open("index.php","SiteWindow","fullscreen");
				}
			else {
				parent.opener.window.location.href = document.location.href;
				window.close();
				}
			}
		}
	}

function screen_button(boo) {
	if(boo == 1) {
		getRef("screenButton").innerHTML = "<a href=\"javascript:fullscreen(false);\">fermer</a>";
		}
	else {
		getRef("screenButton").innerHTML = "";
		}
	}
*/