function confirmation (avertissement, adresse)
{
	var phrase = ''
	if (avertissement == 'modification')
		phrase = 'Attention !\nVous allez perdre toutes les modifications\nfaites sur ce formulaire.\n\n'

	phrase = phrase + 'Veuillez confirmer.'
	var answer = confirm (phrase)
	if (answer)
		window.location=adresse
}

function popup (adresse, largeur, hauteur)
{
	positionX=(screen.width)/4
	positionY=(screen.height)/4

	window.open (adresse,"","width="+largeur+",height="+hauteur+",top="+positionY+",left="+positionX+",location=no,resizable=yes,scrollbars=no,status=no");
}

function popup_centered (adresse, largeur, hauteur)
{
	positionX=(screen.width-largeur)/2
	positionY=(screen.height-hauteur)/2
	
	window.open (adresse,"","width="+largeur+",height="+hauteur+",top="+positionY+",left="+positionX+",location=no,resizable=yes,scrollbars=no,status=no");
}

function popup_centered_sb (adresse, largeur, hauteur)
{
	positionX=(screen.width-largeur)/2
	positionY=(screen.height-hauteur)/2
	
	window.open (adresse,"","width="+largeur+",height="+hauteur+",top="+positionY+",left="+positionX+",location=no,resizable=yes,scrollbars=yes,status=no");
}

function popup_apercu (text, largeur, hauteur)
{
	positionX=(screen.width-largeur)/2
	positionY=(screen.height-hauteur)/2

	newWindow = window.open ("vide.htm","","width="+largeur+",height="+hauteur+",top="+positionY+",left="+positionX+",location=no,resizable=yes,scrollbars=no,status=no");
	newWindow.document.write('<html><head><title>Aperçu</title><link rel="stylesheet" href="styles/styles.css" type="text/css"></head><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor="white" onClick="self.close()">');
	newWindow.document.write(text);
/*	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Cliquez sur l\'image pour fermer la fen&ecirc;tre" >');
	newWindow.document.write('</td></tr></table>'+title2+');
	newWindow.document.write('</body></html>');
*/
	newWindow.document.close();
	newWindow.focus();
}

function popup_photo (adresse, largeur, hauteur)
{	largeur = largeur +20;
	hauteur = hauteur +20;
	window.open(adresse,"","width="+largeur+",height="+hauteur+",resizable=no,scrollbars=no");
}

function imprime_fenetre()
{
   bV = parseInt (navigator.appVersion)
   if (bV >= 4) window.print()
}

function y2k(number)
{
	return (number < 1000) ? number + 1900 : number;
}

Date.prototype.twDate=function (langage)
{
	var heures = this.getHours();
	var minutes = this.getMinutes();
	var jour = this.getDay();
	var date = this.getDate();
	var mois = this.getMonth();
	var annee = y2k(this.getYear());
	var sTemp = "";

	switch (langage.toLowerCase())
	{
	case "fr" :
		date = (date=="1") ? date + "er" : date;
		moisFR = new Array('janvier','février','mars','avril','mai','juin','juillet','août','septembre','octobre','novembre','décembre');
		jourFR = new Array('dimanche','lundi','mardi','mercredi','jeudi','vendredi','samedi');
		sTemp = jourFR[jour] + ' ' + date + ' ' + moisFR[mois] + ' ' + annee;
		break;

	case "en" :
		if (date=="1" || date=="21" || date=="31")
		{
			date = date + "st";
		}
		else if (date=="2" || date=="22")
		{
			date = date + "nd";
		}
		else if (date=="3" || date=="23")
		{
			date = date + "rd";
		}
		else
		{
			date = date + "th";
		}

		moisEN = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
		jourEN = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
		sTemp = jourEN[jour] + ', ' + moisEN[mois] + ' ' + date + ' ' + annee;
		break;

	case "es" :
		moisES = new Array('enero', 'febrero', 'marzo','abril','mayo','junio','julio','agosto','septiembre','octubre','noviembre','deciembre');
		jourES = new Array('domingo', 'lunes', 'martes', 'miércoles', 'jueves', 'viernes','sábado');
		sTemp = jourES[jour] + ', ' + date + ' de ' + moisES[mois] + ' de ' + annee;
		break;

	case "de" :
		moisDE = new Array('Januar', 'Februar', 'März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember');
		jourDE = new Array('Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag','Sonnabend');
		sTemp = jourDE[jour] + ', ' + date + '. ' + moisDE[mois] + ' ' + annee;
		break;
	}
	return sTemp;
}

function affiche_derniere_modification (langage)
{
	var dDate = new Date(document.lastModified);
	document.write(dDate.twDate(langage));
}

function affiche_barre_construction (langage)
{
	var content = "";

	document.write('<div align="center">');
	document.write('<h3>&nbsp;</h3>');
	document.write('<h3>&nbsp;</h3>');
	document.write('<img src="images/barre_construction.png">');
	if (langage == "fr")
		content = "Page actuellement en cours de construction";
	else if (langage == "en")
		content = "Page currently in construction";
	else if (langage == "es")
		content = "P&aacute;gina en proceso de construcci&oacute;n"
	else if (langage == "de")
		content = "Seite im Bau";
	
	document.write('<h3><span style="letter-spacing: 4pt;">' + content + '</span></h3>');
	document.write('</div>');
}

function AfficheImage(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  

	if (bgcolor=="")
	{
	  bgcolor="#FFFFFF";
	}
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;
	
	if(w<740)
	{
	  var lift=0.90;
	}
	if(w>=740 & w<835){
	  var lift=0.91;
	}
	if(w>=835){
	  var lift=0.93;
	}
	if (imageWidth>w)
	{
	  byFactor = w / imageWidth;
	  imageWidth = w;
	  imageHeight = imageHeight * byFactor;
	}
	if (imageHeight>h-adj)
	{
	  byFactor = h / imageHeight;
	  imageWidth = (imageWidth * byFactor);
	  imageHeight = h;
	}
	
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;
	
	if (imageHeight>scrHeight)
	{
	  imageHeight=imageHeight*lift;
	  imageWidth=imageWidth*lift;
	}
	
	var posLeft=0;
	var posTop=0;
	
	if (hugger == "hug image")
	{
	  if (hugMargin == "")
	  {
	    hugMargin = 0;
	  }
	  var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
	  if (scrHeightTemp < scrHeight)
	  {
	    scrHeight = scrHeightTemp;
	  }
	  var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
	  if (scrWidthTemp < scrWidth)
	  {
	    scrWidth = scrWidthTemp;
	  }
	
	  if (scrHeight<100){scrHeight=100;}
	  if (scrWidth<100){scrWidth=100;}
	
	  posTop =  ((h-(scrHeight/lift)-adj)/2);
	  posLeft = ((w-(scrWidth)-adj)/2);
	}
	
	if (imageHeight > (h*lift)-adj || imageWidth > w-adj)
	{
	  imageHeight=imageHeight-adj;
	  imageWidth=imageWidth-adj;
	}
	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);
	scrWidth = parseInt(scrWidth);
	scrHeight = parseInt(scrHeight);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1)
	{
	  var args= new Array();
	  args[0]='parent';
	  args[1]=imageName;
	  var i ; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	}
	else
	{
	  var title1 = "";
	  var title2 = "";
	  var scrHeight1 = scrHeight;
	  if (alt != "")
	  {
		  title1 = ' - [' +alt+ ']';
		  title2 = '<h3 align="center"><font color="#FFFFFF">- '+alt+' -</font></h3>';
		  scrHeight1+=30;
	  }
	  newWindow = window.open("vide.htm","",'location=0,status=0,width='+scrWidth+',height='+scrHeight1+',left='+posLeft+',top='+posTop);
	  newWindow.document.write("<html><head><title>La M&eacute;tairie d'en Bor"+title1+'</title><link rel="stylesheet" href="styles/styles.css" type="text/css"></head><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onClick="self.close()">');
	  newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	  newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Cliquez sur l\'image pour fermer la fen&ecirc;tre" >');
	  newWindow.document.write('</td></tr></table>'+title2+'</body></html>');
	  newWindow.document.close();
	  newWindow.focus();
	}
}

function progress ()
{
	var texte = null
	var image = null;
	var btn_envoyer = null;
	var btn_photo = null;
	var id_texte = "texte_progress";
	var id_image = "image_progress";
	var content  = "<b>&nbsp;<br>Téléchargement en cours,<br>veuillez patienter...<br>&nbsp;</b>";
	var imagesrc = "images/bouton_ok_s.png";

	if (document.getElementById)
	{
		texte = document.getElementById (id_texte);
		image = document.getElementById (id_image);
		btn_envoyer = document.getElementById ("envoyer");
	}
	else if (document.all)
	{
		texte = document.all [id_texte];
		image = document.all [id_image];
		btn_envoyer = document.all ["envoyer"];
	} 

	if (texte)
	{
    	texte.innerHTML = content;
		texte.style.color = "#BB0000";
		texte.style.backgroundColor = "#FFAAAA";
		texte.style.border="1px solid #BB0000";
	}

	if (btn_envoyer)
		btn_envoyer.disabled='disabled';
}

function flag_over (langage, space)
{
	var texte = null
	var image = null;
	var id_texte = "title"
	var id_image = "";
	var content  = "";
	var imagesrc = "";
	var car = "<br>";

	if (space)
		car = " ";

	if (langage == "fr")
	{
		id_image = "flag_fr";
		content  = "<b>French</b><br>La M&eacute;tairie d\'en Bor" + car + "d'un coup d'oeil";
		imagesrc = "images/drapeau_francais.png";
	}
	else if (langage == "en")
	{
		id_image = "flag_en";
		content  = "<b>English</b><br>La M&eacute;tairie d\'en Bor" + car + "at a glance";
		imagesrc = "images/drapeau_anglais.png";
	}
	else if (langage == "es")
	{
		id_image = "flag_es";
		content  = "<b>Castellano</b><br>La M&eacute;tairie d\'en Bor" + car + "en un vistazo";
		imagesrc = "images/drapeau_espagnol.png";
	}
	else if (langage == "de")
	{
		id_image = "flag_de";
		content  = "<b>Deutsch</b><br>La M&eacute;tairie d\'en Bor" + car + "auf einen Blick";
		imagesrc = "images/drapeau_allemand.png";
	}

	if (document.getElementById)
	{
		texte = document.getElementById (id_texte);
		image = document.getElementById (id_image);
	}
	else if (document.all)
	{
		texte = document.all [id_texte];
		image = document.all [id_image];
	} 

	if (texte)
	{
		if (texte.innerHTML == "&nbsp;<BR>&nbsp;<BR>&nbsp;")
		{
			content = content.replace ("#", "<br>");
		}
		else
		{
			content = content.replace ("#", " ");
		}
    	texte.innerHTML = content;
    }

	if (image)
	{
    	image.src = imagesrc;
    }
}
   		
function flag_out (langage, space)
{
	var texte = null
	var image = null;
	var id_texte = "title"
	var id_image = "";
	var content  = "";
	var imagesrc = "";
	
	if (langage == "fr")
	{
		id_image = "flag_fr";
		imagesrc = "images/drapeau_francais_clair.png";
	}
	else if (langage == "en")
	{
		id_image = "flag_en";
		imagesrc = "images/drapeau_anglais_clair.png";
	}
	else if (langage == "es")
	{
		id_image = "flag_es";
		imagesrc = "images/drapeau_espagnol_clair.png";
	}
	else if (langage == "de")
	{
		id_image = "flag_de";
		imagesrc = "images/drapeau_allemand_clair.png";
	}

	if (document.getElementById)
	{
		texte = document.getElementById (id_texte);
		image = document.getElementById (id_image);
	}
	else if (document.all)
	{
		texte = document.all [id_texte];
		image = document.all [id_image];
	} 

	if (texte)
	{
		if (space)
		{
			content = "&nbsp;<br>&nbsp;";
		}
		else
		{
			content = "&nbsp;<br>&nbsp;<br>&nbsp;";
		}
    	texte.innerHTML = content;
    }

	if (image)
	{
    	image.src = imagesrc;
    }
}

function flag_over_small (langage)
{
	var image = null;
	var id_image = "";
	var imagesrc = "";

	if (langage == "fr")
	{
		id_image = "flag_fr_small";
		imagesrc = "images/drapeau_francais_petit.png";
	}
	else if (langage == "en")
	{
		id_image = "flag_en_small";
		imagesrc = "images/drapeau_anglais_petit.png";
	}
	else if (langage == "es")
	{
		id_image = "flag_es_small";
		imagesrc = "images/drapeau_espagnol_petit.png";
	}
	else if (langage == "de")
	{
		id_image = "flag_de_small";
		imagesrc = "images/drapeau_allemand_petit.png";
	}

	if (document.getElementById)
		image = document.getElementById (id_image);
	else if (document.all)
		image = document.all [id_image];

	if (image)
    	image.src = imagesrc;
}
   		
function flag_out_small (langage)
{
	var image = null;
	var id_image = "";
	var imagesrc = "";
	
	if (langage == "fr")
	{
		id_image = "flag_fr_small";
		imagesrc = "images/drapeau_francais_petit_clair.png";
	}
	else if (langage == "en")
	{
		id_image = "flag_en_small";
		imagesrc = "images/drapeau_anglais_petit_clair.png";
	}
	else if (langage == "es")
	{
		id_image = "flag_es_small";
		imagesrc = "images/drapeau_espagnol_petit_clair.png";
	}
	else if (langage == "de")
	{
		id_image = "flag_de_small";
		imagesrc = "images/drapeau_allemand_petit_clair.png";
	}

	if (document.getElementById)
		image = document.getElementById (id_image);
	else if (document.all)
		image = document.all [id_image];

	if (image)
    	image.src = imagesrc;
}

var timerID = 0;
var state = true;
var texte_source = "";
var delay_on  = 1000;
var delay_off = 500;

function UpdateTimer()
{
	var texte = null;
	var timerval = 0;
	var texte_info = "";

	if (timerID)
	{
		clearTimeout(timerID);
		clockID  = 0;
	}

	if (document.getElementById)
		texte = document.getElementById ("information");
	else if (document.all)
		texte = document.all ["information"];
		
	if (texte)
	{
		state = ! state;
		if (state)
		{
			texte.innerHTML = texte_source;
			timerval = delay_on;
		}
		else
		{
			texte.innerHTML = '<font style="color:#FFFFFF">' + texte_source + '</font>';
			timerval = delay_off;
		}
	}
	
	timerID = setTimeout("UpdateTimer()", timerval);
}

function Start()
{
   	if (document.getElementById)
		texte = document.getElementById ("information");
	else if (document.all)
		texte = document.all ["information"];

	if (texte)
	{
		texte_source = texte.innerHTML;
		timerID  = setTimeout("UpdateTimer()", delay_on);
	}
}

function Stop()
{
	if (timerID)
	{
		clearTimeout(timerID);
		timerID  = 0;
	}
}

function today (formulaire, champ)
{
	mydate = new Date;

	jj = mydate.getDate();
	if (jj < 10)
		jj = "0" + jj;

	mm = mydate.getMonth(); mm++;
	if (mm < 10)
		mm = "0" + mm;

	aa = mydate.getFullYear();
	
	document.forms[formulaire].elements[champ+"_jour"].value=jj;
	document.forms[formulaire].elements[champ+"_mois"].value=mm;
	document.forms[formulaire].elements[champ+"_année"].value=aa;
}

function empty_date (formulaire, champ)
{
	document.forms[formulaire].elements[champ+"_jour"].value="";
	document.forms[formulaire].elements[champ+"_mois"].value="";
	document.forms[formulaire].elements[champ+"_année"].value="";
}

function insert_field (field)
{	
	with(document.courrier)
	{
		if (message.createTextRange) 
		{
			var text;
			message.focus(message.caretPos);
			message.caretPos = document.selection.createRange().duplicate();
			message.caretPos.text = field;
		}
		else
			message.value += field;
	}
}

function insert_smiley (smiley)
{	
	with(document.reponse)
	{
		if (contenu.createTextRange) 
		{
			var text;
			contenu.focus(contenu.caretPos);
			contenu.caretPos = document.selection.createRange().duplicate();
			contenu.caretPos.text = ' ' + smiley + ' ';
		}
		else
			contenu.value += ' ' + smiley + ' ';
	}
}

function insert_marker (tag, defaultText) 
{
	startTag = '[' + tag + ']';
	endTag = '[/' + tag + ']';

   with(document.reponse)
   {
      if (contenu.createTextRange) 
      {
         var text;
         contenu.focus(contenu.caretPos);
         contenu.caretPos = document.selection.createRange().duplicate();
         if(contenu.caretPos.text.length>0)
         {
            //gère les espace de fin de sélection. Un double-click sélectionne le mot
            //+ un espace qu'on ne souhaite pas forcément...
            var sel = contenu.caretPos.text;
            var fin = '';
            while(sel.substring(sel.length-1, sel.length)==' ')
            {
               sel = sel.substring(0, sel.length-1)
               fin += ' ';
            }
            contenu.caretPos.text = startTag + sel + endTag + fin;
         }
         else
            contenu.caretPos.text = startTag+defaultText+endTag;
      }
      else contenu.value += startTag+defaultText+endTag;
   }
}

function PutCursorIdentification ()
{
	var field = "password";

	if (document.getElementById ('id_login'))
		if (document.getElementById ('id_login').value == '')
			field = "login";

	if (document.getElementById)
		if (document.getElementById ('id_'+field))
			document.getElementById ('id_'+field).focus();
	else if (document.all)
		if (document.all ['id_'+field])
		document.all ['id_'+field].focus();
}

function PutCursor (field)
{
	if (document.getElementById)
		if (document.getElementById ('id_'+field))
			document.getElementById ('id_'+field).focus();
	else if (document.all)
		if (document.all ['id_'+field])
		document.all ['id_'+field].focus();
}

