// Copyright Hippocampe 2001
browserVer = parseInt(navigator.appVersion);
browserName = navigator.appName;
browser = 0;
url = "" + document.location;

// Netscape ou IE
if ((browserName == 'Netscape') && (browserVer >= 2) && (browserVer != 5))
	browser = 1;
else
	browser = 2;

function goToPage(iOrdrePage, sCmdPage){
	if (iOrdrePage && sCmdPage) {
		document.formPage.cmd_page.value	= sCmdPage;
		document.formPage.ordre_page.value = iOrdrePage;
		document.formPage.submit();
		return true;
	}
	return false;
}
	
function setDate(tdId){
    var months=new Array(12);
    var days=new Array(7);
    var laDate;
	today = new Date;
    
    months[1]="Janvier";
	months[2]="Février";
	months[3]="Mars";
	months[4]="Avril";
	months[5]="Mai";
	months[6]="Juin";
	months[7]="Juillet";
	months[8]="Aout";
	months[9]="Septembre";
	months[10]="Octobre";
	months[11]="Novembre";
	months[12]="Décembre";

	days[1]="Lundi";
	days[2]="Mardi";
	days[3]="Mercredi";
	days[4]="Jeudi";
	days[5]="Vendredi";
	days[6]="Samedi";
	days[7]="Dimanche";
    
    var month=months[today.getMonth() + 1];
    var day=days[today.getDay()];
    var date=today.getDate();
    var year=today.getYear();
    
    year=year;
	laDate=day + " " + date + " " + month + " " + year;
	tdId.innerHTML = laDate;
}
	
function addHeader(){
	var buffer =null;
	buffer = "<html>\r\n";
	buffer += "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Transitional//EN'\r\n";
	buffer += "'http://www.w3.org/TR/html4/strict.dtd'>\r\n";
	buffer += "		<head>\r\n";
    buffer += "			<title>Impression</title>\r\n";
    buffer += "			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>\r\n";
    buffer += "			<meta name='robots' content='index,follow'>\r\n";
    buffer += "			<meta http-equiv='Expires' content='0'>\r\n";
    buffer += "		 	<meta http-equiv='Pragma' content='no-cache'>\r\n";
    buffer += "			<meta http-equiv='Cache-Control' content='no-cache'>\r\n";
    buffer += "			<link rel=stylesheet type='text/css' href='css/ie.css' title='Feuille de style du site'>\r\n";
    buffer += "		</head>\r\n";
	buffer += "		<body bgcolor='#ffffff' style='background-color: white;'>\r\n";
	return buffer;
}

function addFooter(){
	var buffer = null;
	buffer = "		</body>\r\n";
	buffer += "</html>\r\n";
	return buffer;
}

function imprime(){
	var bufferHtml = null;
	if (browser==1)
		window.print();
	else {
    	bufferHtml = addHeader();
    	bufferHtml += content.outerHTML+"\r\n";
    	bufferHtml += addFooter();
    	var win = open('', 'plateform_preview')
    	if (win) {
            win.document.open();
            win.moveTo(-1000, -1000);
            win.resizeTo(600, 400);
            
            win.document.write(bufferHtml);
            win.document.close();
            
            win.focus();
            win.print();
            win.close();
        }
	}
}

function imprimeContent(content){
	var bufferHtml = null;
	if (browser==1)
		window.print();
	else {
    	bufferHtml = addHeader();
    	bufferHtml += content.outerHTML+"\r\n";
    	bufferHtml += addFooter();
    	var win = open('', 'plateform_preview')
    	if (win) {
            win.document.open();
            win.moveTo(-1000, -1000);
            win.resizeTo(600, 400);
            
            win.document.write(bufferHtml);
            win.document.close();
            
            win.focus();
            win.print();
            win.close();
        }
	}
}

	/**
	 * Ouvre la popup url
	 *
	 * @param url de la page
	 */
	// si x==-1 et y==-1 alors centrage par rapport à l'écran
	var wPopWindow 				= null; // Popup
	function windowOpen(urlPage,x,y,w,h) {
		if (wPopWindow && !wPopWindow.closed) {
			wPopWindow.close();
			wPopWindow = null;
		}
    	if (x==-1) x = (screen.width / 2) - (w / 2);
    	if (y==-1) y = (screen.height / 2) - (h / 2);
    	wPopWindow = window.open(urlPage,'wPopWindow','width=' + w + ',height=' + h + ',left=' + x + ',top=' + y + ',resizable=yes,scrollbars=yes,toolbar=no,location=no,directories=no,status=NO');
    	wPopWindow.focus();
    	return false;
    }
	
	/**
	 * Set une valeur dans le champ caché specialCmd et envoit le formulaire
	 *
	 * @param <form>
	 * @param sCmd
	 */
	function setValueInSpecialCmd(form, sCmd)
	{
		form.specialCmd.value = sCmd;
		form.submit();
	}
	
	/**
	 * Ouvre la popup url
	 *
	 * @param url de la page
	 */
	// si x==-1 et y==-1 alors centrage par rapport à l'écran
	function windowOpenFixed(urlPage,x,y,w,h) {
		if (wPopWindow && !wPopWindow.closed) {
			wPopWindow.close();
			wPopWindow = null;
		}
    	if (x==-1) x = (screen.width / 2) - (w / 2);
    	if (y==-1) y = (screen.height / 2) - (h / 2);
    	wPopWindow = window.open(urlPage,'wPopWindow','width=' + w + ',height=' + h + ',left=' + x + ',top=' + y + ',resizable=no,scrollbars=yes,toolbar=no,location=no,directories=no,status=no');
    	wPopWindow.focus();
    	return false;
    }
	
	var champ;
			
	function checkEmpty(champ, str) {
		b = (champ.value != "");		
		if (!b) {
			alert("Le champ " + str + " est obligatoire.");
			champ.focus();
		}
			
		return b;
	}
	
	/**
	 * Vérifie de l'email : on vérifie la présence du @ et du .
	 * @param champ Le nom du champ
	 * @return True si le champ est bien rempli, False sinon
	 */
	function checkEmail(champ) {
		// Cible du FAF.SAB : Adresses e-mail de domaines en fr, et domaines non associés à un pays
		if (!(/[A-Za-z0-9\-\.\_]+\@[A-Za-z0-9\-\.\_]+\.(fr|com|net|org|info|biz)$/).test(champ.value)) {
			alert("Le format de l'adresse e-mail indiquée n'est pas correct.\nVeuillez le rectifier.");
			champ.focus();
			return false;
		}
		
		return true;
	}
