// version 16	02/03/2005
var mES=null
var mSessionTimeOut=10
var mRollOver=true
//var mSiteName=''
//var mBaseURL=''
function init(sessionTimeOut,siteName,baseURL) {
	mSessionTimeOut=(sessionTimeOut==null)? 10 : sessionTimeOut
	mSiteName=(siteName==null)? '' : siteName
	mBaseURL=(baseURL==null)? '' : baseURL
	mES=document.images.entretienSession
	if (mES!=null) setTimeout('sessionContinue()',mSessionTimeOut*1000*60/2)
}

//entretien session
function sessionContinue() {
	mES.src="BO/images/blank.gif"
	mES.src="BO/entretienSession.asp"
	setTimeout('sessionContinue()',mSessionTimeOut*1000*60/2)
}

//chargement d'une image
function preloadIMG(url) {
	var img=new Image()
	img.src=url
	return img
}

//fenetrage
function popup(URL,NAME,WIDTH,HEIGHT,SCROLLBARS) {
	if (window.event) window.event.cancelBubble=true
	if (SCROLLBARS==null) SCROLLBARS='yes'
	if (SCROLLBARS=='no' & navigator.appName=='Opera') SCROLLBARS='yes'
	var majURL=URL.toUpperCase()
	if (majURL.indexOf('DOC.ASP')!=-1 | majURL.indexOf('.JPG')!=-1 | majURL.indexOf('.GIF')!=-1 | majURL.indexOf('.PNG')!=-1) {
		if (WIDTH==null) WIDTH=640
		if (HEIGHT==null) HEIGHT=480
		NAME=(NAME==null | NAME=='')? 'IMG' : NAME
		var w = window.open('',NAME,'left=50,TOP=50,width='+WIDTH+',height='+HEIGHT+',resizable=yes,scrollbars=yes')
		var svURL=URL
		with (w.document) {
			write("<html><head><title>"+mSiteName+" - img</title>\n")
			write('<base href="'+mBaseURL+'">\n')
			write('<link rel="stylesheet" href="default.css" type="text/css">\n')
			write('<link rel="stylesheet" href="popimg.css" type="text/css">\n')
			write("<script language='JavaScript'>\n")
			write("IE5=NN4=NN6=false;\n")
			write("if(document.all)IE5=true;\n")
			write("else if(document.getElementById)NN6=true;\n")
			write("else if(document.layers)NN4=true;\n")
			write("function autoSize() {\n")
			write("var H=document.images[0].height\n")
			write("H=(H>(screen.height*4/5))? (screen.height*4/5):H\n")

			write("var L=document.images[0].width\n")
			write("if(IE5) self.resizeTo(L+29,H+31);\n")
			write("if(NN6) self.resizeTo(L+23,H+29);\n")
			write("else window.resizeTo(L+29,H+31+21);\n")
			write("self.focus();\n")
			write("}\n</scri")
			write("pt>\n")
			write('</head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad="javascript:autoSize();">')
			write('<a href="javascript:window.close()"><img src="'+svURL+'" border=0 alt=Fermer ></a>')
			write("</body></html>")
			close()
		}
	}
	else {
		if (WIDTH==null) WIDTH=800
		if (HEIGHT==null) HEIGHT=480
		window.open(URL,NAME,'width='+WIDTH+',height='+HEIGHT+',location=no,toolbar=no,scrollbars='+SCROLLBARS+',resizable=yes')
	}
	return false
}

//barre de lecture
function over(obj) {
	obj.id=obj.id.replace(/Out/gi,'Over')
}
function out(obj) {
	obj.id=obj.id.replace(/Over/gi,'Out')
}

//mailForm
function mailFormVerif(myForm) {
	var ok=true
	var elm
	var mess=''
	var ctr=0
	var pubNom
	for (var x=0;x<myForm.elements.length;x++) {
		elm=myForm.elements[x]
		pubNom=elm.name.replace('_obligatoire','')
		if (elm.value=='') {
			if (elm.name.indexOf('_obligatoire')!=-1) {
				if (ctr==0) elm.focus()
				ok=false ; ctr=1
				mess+=pubNom+' doit être saisi.\n'
			}
		}
		else {
			if (elm.name.indexOf('eMail')!=-1) {
				//var reg=/\w{2,}\.?\w{1,}@\w{2,}\.\w{2,}/
				var reg=/^([a-zA-Z0-9]+([-_]?[a-zA-Z0-9]+)*.)*[a-zA-Z0-9]+([-_]?[a-zA-Z0-9]+)*@([a-zA-Z0-9]+([-_]?[a-zA-Z0-9]+)*.)+[a-zA-Z]{2,4}$/i
				if (!reg.test(elm.value)) {
					if (ctr==0) elm.focus()
					ok=false ; ctr=1
					mess+=pubNom+' n\'est pas correct.\n'
				}
			}
		}
	}
	if (!ok) alert(mess)
	return ok
}

//fenêtre modale + refresh
function modalDialog(URL) {
	if (showModalDialog) {
		var resolutionX=screen.availWidth*3/5
		var resolutionY=screen.availHeight*4/5
		if (resolutionX<800) resolutionX=800
		if (resolutionY<600) resolutionY=600
		args='dialogWidth:'+resolutionX+'px; dialogHeight:'+resolutionY+'px;edge: Sunken; center: Yes; help: Yes; resizable: Yes; status: No;'
		showModalDialog(URL,'',args)
		document.location.reload()
	}
	else {
		alert("IE est nécessaire")
	}
	return false
}

//gestion bottomMess s'il existe
var bottomMessTimeout=null
function moveBottomMess() {
	var obj=null
	obj=document.getElementById('bottomMess')
	if (obj) {
		with (obj.style) {
			position='absolute'
			width='100%'
			left=document.body.clientWidth+document.body.scrollLeft-obj.offsetWidth-1
			top=document.body.clientHeight+document.body.scrollTop-obj.offsetHeight-1
		}
		clearTimeout(bottomMessTimeout)
		bottomMessTimeout=setTimeout('moveBottomMess()',1000)
	}
}

//scroll up/down de la page
var okscroll=false
var godown
function scrollPage() {
	if (okscroll) {
		if (godown) {
			window.scrollBy(0,4)
		} 
		else {
			window.scrollBy(0,-4)
		}
		moveBottomMess()
		setTimeout('scrollPage()', 40)
	}
}

//mise en valeur résultat recherche
function rSearch(find) {
	try {
		if (find.length>1) {
			var range=document.selection.createRange()
			range.select()
			var bookMark=range.getBookmark()
			range.findText(find)
			while (range.boundingWidth>0) {
				range.select()
				range.pasteHTML('<span class=rSearch>'+range.text+'</span>')
				range.collapse(false)
				range.findText(find)
			}
			range.moveToBookmark(bookMark)
		}
	}
	catch (e) {}
}

// correctly handle PNG transparency in Win IE 5.5 or higher.
function correctPNG() {
	if (navigator.appName=='Microsoft Internet Explorer') {
		for(var i=0; i<document.images.length; i++) {
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				if (img.align == "left") imgStyle = "float:left;" + imgStyle
				if (img.align == "right") imgStyle = "float:right;" + imgStyle
				if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle		
				var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
				img.outerHTML = strNewHTML
				i = i-1
			}
		}
	}
}



//ajout de fonctions...
Date.prototype.getWeek = function() {
     var dayDiff=this-new Date(this.getFullYear(),0,0);
     var tempDays=Math.floor(dayDiff/86400000)-(this.getDay()-7)%7;
     return tempDays>365? 1: Math.ceil(tempDays/7);
}

//signature MD5
var hex_chr_MD5 = "0123456789ABCDEF";
function rhex_MD5(num)
{
  str = "";
  for(j = 0; j <= 3; j++)
    str += hex_chr_MD5.charAt((num >> (j * 8 + 4)) & 0x0F) +
           hex_chr_MD5.charAt((num >> (j * 8)) & 0x0F);
  return str;
}
function str2blks_MD5(str)
{
  nblk = ((str.length + 8) >> 6) + 1;
  blks = new Array(nblk * 16);
  for(i = 0; i < nblk * 16; i++) blks[i] = 0;
  for(i = 0; i < str.length; i++)
    blks[i >> 2] |= str.charCodeAt(i) << ((i % 4) * 8);
  blks[i >> 2] |= 0x80 << ((i % 4) * 8);
  blks[nblk * 16 - 2] = str.length * 8;
  return blks;
}
function add_MD5(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}
function rol_MD5(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}
function cmn_MD5(q, a, b, x, s, t)
{
  return add_MD5(rol_MD5(add_MD5(add_MD5(a, q), add_MD5(x, t)), s), b);
}
function ff_MD5(a, b, c, d, x, s, t)
{
  return cmn_MD5((b & c) | ((~b) & d), a, b, x, s, t);
}
function gg_MD5(a, b, c, d, x, s, t)
{
  return cmn_MD5((b & d) | (c & (~d)), a, b, x, s, t);
}
function hh_MD5(a, b, c, d, x, s, t)
{
  return cmn_MD5(b ^ c ^ d, a, b, x, s, t);
}
function ii_MD5(a, b, c, d, x, s, t)
{
  return cmn_MD5(c ^ (b | (~d)), a, b, x, s, t);
}
function MD5(str)
{
  x = str2blks_MD5(str);
  a =  1732584193;
  b = -271733879;
  c = -1732584194;
  d =  271733878;

  for(i = 0; i < x.length; i += 16)
  {
    olda = a;
    oldb = b;
    oldc = c;
    oldd = d;

    a = ff_MD5(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = ff_MD5(d, a, b, c, x[i+ 1], 12, -389564586);
    c = ff_MD5(c, d, a, b, x[i+ 2], 17,  606105819);
    b = ff_MD5(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = ff_MD5(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = ff_MD5(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = ff_MD5(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = ff_MD5(b, c, d, a, x[i+ 7], 22, -45705983);
    a = ff_MD5(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = ff_MD5(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = ff_MD5(c, d, a, b, x[i+10], 17, -42063);
    b = ff_MD5(b, c, d, a, x[i+11], 22, -1990404162);
    a = ff_MD5(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = ff_MD5(d, a, b, c, x[i+13], 12, -40341101);
    c = ff_MD5(c, d, a, b, x[i+14], 17, -1502002290);
    b = ff_MD5(b, c, d, a, x[i+15], 22,  1236535329);    

    a = gg_MD5(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = gg_MD5(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = gg_MD5(c, d, a, b, x[i+11], 14,  643717713);
    b = gg_MD5(b, c, d, a, x[i+ 0], 20, -373897302);
    a = gg_MD5(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = gg_MD5(d, a, b, c, x[i+10], 9 ,  38016083);
    c = gg_MD5(c, d, a, b, x[i+15], 14, -660478335);
    b = gg_MD5(b, c, d, a, x[i+ 4], 20, -405537848);
    a = gg_MD5(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = gg_MD5(d, a, b, c, x[i+14], 9 , -1019803690);
    c = gg_MD5(c, d, a, b, x[i+ 3], 14, -187363961);
    b = gg_MD5(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = gg_MD5(a, b, c, d, x[i+13], 5 , -1444681467);
    d = gg_MD5(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = gg_MD5(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = gg_MD5(b, c, d, a, x[i+12], 20, -1926607734);
    
    a = hh_MD5(a, b, c, d, x[i+ 5], 4 , -378558);
    d = hh_MD5(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = hh_MD5(c, d, a, b, x[i+11], 16,  1839030562);
    b = hh_MD5(b, c, d, a, x[i+14], 23, -35309556);
    a = hh_MD5(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = hh_MD5(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = hh_MD5(c, d, a, b, x[i+ 7], 16, -155497632);
    b = hh_MD5(b, c, d, a, x[i+10], 23, -1094730640);
    a = hh_MD5(a, b, c, d, x[i+13], 4 ,  681279174);
    d = hh_MD5(d, a, b, c, x[i+ 0], 11, -358537222);
    c = hh_MD5(c, d, a, b, x[i+ 3], 16, -722521979);
    b = hh_MD5(b, c, d, a, x[i+ 6], 23,  76029189);
    a = hh_MD5(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = hh_MD5(d, a, b, c, x[i+12], 11, -421815835);
    c = hh_MD5(c, d, a, b, x[i+15], 16,  530742520);
    b = hh_MD5(b, c, d, a, x[i+ 2], 23, -995338651);

    a = ii_MD5(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = ii_MD5(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = ii_MD5(c, d, a, b, x[i+14], 15, -1416354905);
    b = ii_MD5(b, c, d, a, x[i+ 5], 21, -57434055);
    a = ii_MD5(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = ii_MD5(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = ii_MD5(c, d, a, b, x[i+10], 15, -1051523);
    b = ii_MD5(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = ii_MD5(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = ii_MD5(d, a, b, c, x[i+15], 10, -30611744);
    c = ii_MD5(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = ii_MD5(b, c, d, a, x[i+13], 21,  1309151649);
    a = ii_MD5(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = ii_MD5(d, a, b, c, x[i+11], 10, -1120210379);
    c = ii_MD5(c, d, a, b, x[i+ 2], 15,  718787259);
    b = ii_MD5(b, c, d, a, x[i+ 9], 21, -343485551);

    a = add_MD5(a, olda);
    b = add_MD5(b, oldb);
    c = add_MD5(c, oldc);
    d = add_MD5(d, oldd);
  }
  return rhex_MD5(a) + rhex_MD5(b) + rhex_MD5(c) + rhex_MD5(d);
}

//menus en cascade
var idCount=0
var hTimers=new Array()
var sTimers=new Array()

function Menu(boolVisible) {
	this.options=new Array()
	this.build=menuBuild
	this.add=addOption
	this.id='menu'+idCount++
	this.obj=null
	this.visible=(boolVisible!=null)? boolVisible:true
}
function Option(strNom,strUrl) {
	this.nom=strNom
	this.url=strUrl
	this.menu=new Menu(false)
	this.build=optionBuild
	this.id='option'+idCount++
	this.obj=null
}
function menuBuild(strWidth,strClassMenu,strClassOption) {
	document.write('<div id="'+this.id+'"')
	if (this.visible) {
		document.write(' style="display:block;position:relative"')
	}
	else {
		document.write(' style="display:none;position:absolute;z-index:99"')
	}
	document.write(">")
	document.write('<table class="'+strClassMenu+'" cellpadding=0 cellspacing=0 style="width:'+strWidth+'">')
	for (var n=0;n<this.options.length;n++) {
		this.options[n].build(strClassOption)
	}
	document.write("</table>")
	document.write("</div>")
	this.obj=document.getElementById(this.id)
	if (document.all & !this.visible) {
		//permet d'afficher le menu sur une listebox ou un flash
		var mIframe=document.createElement('iframe')
		mIframe.style.display='block'
		mIframe.style.position='absolute'
		mIframe.style.zIndex=-1
		mIframe.style.border=0
		mIframe.style.left=0
		mIframe.style.top=0
		mIframe.style.width=0		//defini plus tard
		mIframe.style.height=0		//defini plus tard
		mIframe.style.filter='progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
		this.obj.appendChild(mIframe)
	}
}

function optionBuild(strClassOption) {
	document.write('<tr id="'+this.id+'" class="'+strClassOption+'Out"')
	if (this.url) document.write(' onclick="'+this.url+'"')
	document.write('><td style="white-space:nowrap;width:99%">')
	document.write('<div id="div'+this.id+'" class="'+strClassOption+'TextOut">&nbsp;'+this.nom+'</div>')
	this.obj=document.getElementById(this.id)
	this.obj.onmouseover=optionOver
	this.obj.onmouseout=optionOut
	this.obj.builder=this
	document.write('</td><td>')
	if (this.menu.options.length>0) {
		document.write('&nbsp;<img src="images/subMenu.gif" border=0 align=absmiddle>')
		document.write('</td><td valign=top>')
		this.menu.build('100%','subMenu','subOption')
	}
	else {
		document.write('&nbsp;</td><td valign=top>')
	}
	document.write("</td></tr>")
}

function optionOver() {
	this.className=this.className.replace(/Out/gi,'Over')
	var div=document.getElementById('div'+this.id)
	div.className=div.className.replace(/Out/gi,'Over')
	if (this.builder.menu.options.length>0) {
		clearTimeout(hTimers[this.builder.menu.obj.id])
		sTimers[this.builder.menu.obj.id]=setTimeout('menuShow("'+this.builder.menu.obj.id+'")',400)
	}
}
function optionOut() {
	this.className=this.className.replace(/Over/gi,'Out')
	var div=document.getElementById('div'+this.id)
	div.className=div.className.replace(/Over/gi,'Out')
	if (this.builder.menu.options.length>0) {
		clearTimeout(sTimers[this.builder.menu.obj.id])
		hTimers[this.builder.menu.obj.id]=setTimeout('menuHide("'+this.builder.menu.obj.id+'")',400)
	}
}
function menuHide(id) {
	var obj=document.getElementById(id)
	obj.style.display='none'
}
function menuShow(id) {
	var obj=document.getElementById(id)
	obj.style.display='block'
	if (obj.children.length==2) {
		obj.children[1].style.width=obj.offsetWidth
		obj.children[1].style.height=obj.offsetHeight
	}
	
}

function addOption(strNom,strUrl) {
	var option=new Option(strNom,strUrl,this)
	this.options[this.options.length]=option
	return option
}
