if(window.event + "" == "undefined") event = null;

//netscape detection...
ie = (document.all)?(true):(false);
ns = (document.layers)?(true):(false);
ns6 = (document.getElementById && !document.all)?(true):(false);

//menu functions
activeMenu = null;

function comp()
{
if (document.im.complete=="false") {document.location="?a=random";}
}

function getObj(objId){
	if(ns) return eval("document." + objId);
	else return document.getElementById(objId);
}

function chVisibility(layerObj,state){
	if(!layerObj) return;
	if(ns) layerObj.visibility = ((state)?('show'):('hide'));
	else layerObj.style.visibility = ((state)?('visible'):('hidden'));
	if(state) activeMenu = layerObj;
	else activeMenu = null;
}

function getUL(e){
	if(ns) return e.target.y - 5;
	else if(ns6) return e.currentTarget.offsetTop;
	else{
		objId = e.srcElement;
		y = 0;
		while(objId.offsetParent != null && objId.offsetParent.tagName != "HTML"){
			y += objId.offsetTop;
			objId = objId.offsetParent;
		}
		y += objId.offsetTop;
		return y;
	}
}

function setUL(layerObj,value){
	if(ns) layerObj.top = value;
	else layerObj.style.top = value;
}

function mOver(e,menuId){
	chVisibility(activeMenu,false);
	upperLimit = getUL(e);
	setUL(getObj(menuId),upperLimit);
	chVisibility(getObj(menuId),true);
}

function clickDocument(e){
	chVisibility(activeMenu,false);
	return true;
}

function initMenu(){
	document.captureEvents(Event.MOUSEUP);
	document.onmouseup = clickDocument;
}

//preloading images
/*preloadImg0 = new Image();
preloadImg0.src = "/images/accueil-over.gif";
preloadImg1 = new Image();
preloadImg1.src = "/images/actualites-over.gif";
preloadImg2 = new Image();
preloadImg2.src = "/images/europe-over.gif";

preloadImg3 = new Image();
preloadImg3.src = "/images/epn-over.gif";

preloadImg4 = new Image();
preloadImg4.src = "/images/commune-over.gif";
preloadImg5 = new Image();
preloadImg5.src = "/images/concours-over.gif";
preloadImg6 = new Image();
preloadImg6.src = "/images/mission-over.gif";
preloadImg7 = new Image();
preloadImg7.src = "/images/forum-over.gif";
preloadImg8 = new Image();
preloadImg8.src = "/images/abonnez_vous-over.gif";
preloadImg9 = new Image();
preloadImg9.src = "/images/ok_button-over.gif";
preloadImg10 = new Image();
preloadImg10.src = "/images/votre_contact-over.gif";
preloadImg11 = new Image();
preloadImg11.src = "/images/top_button-over.gif";
*/

//insert hover images
function insertHover(img,lnk,preObj){
	document.write('<a href="'+lnk+'" onMouseOver="document.'+img+'.src='+preObj+'.src" onMouseOut="document.'+img+'.src=&quot;/images/'+img+'.gif&quot;"><img src="/images/'+img+'.gif" border="0" name="'+img+'"></a>');
}

//mailing list
function requestEmail(){
	if(retVal = prompt("Votre adresse:","E-mail...")){
		location = "/index.php?email=" + escape(retVal);
	}
}

function fillSMenu(contents){

  var part1 = '<table border="0" cellpadding="0" cellspacing="0" background="/images/smenu_background.gif">'+
			  '<tr><td colspan="3" align="right" background="/images/smenu_top_background.gif"><img src="/images/smenu_top.gif" width="18" height="5"></td>'+
			  '</tr><tr><td><img src="/images/spacer.gif" width="8" height="1"></td><td>'+
			  '<table border="0" cellspacing="0" cellpadding="3" align="center" class="navMenu"><tr><td bgcolor="#827D99" align="center">';
  var part2 = '</td></tr></table></td><td background="/images/smenu_background_02.gif"><img src="/images/spacer.gif" width="14" height="1"></td>'+
			  '</tr><tr><td colspan="3" background="/images/smenu_bottom_background.gif" align="right"><img src="/images/smenu_bottom.gif" width="18" height="5"></td></tr></table>';

	if(!SMenus[eval(contents)]) return;
	menuIndex = eval(contents);

	if(ns){
		document.SMenu.document.open();
		document.SMenu.document.write(part1+SMenus[menuIndex]+part2);
		document.SMenu.document.close();
	}
	else SMenu.innerHTML = part1+SMenus[menuIndex]+part2;
}

timeoutID = 0;
lastMenu = "";

function hideSMenu(){
	if(ns) document.SMenu.visibility = "hide";
	else SMenu.style.visibility = "hidden";
}

function menuOver(source,overColor,evnt){

	srcObj = (ns)?(document.links[source]):(document.all[source]);
	if(!ns){
		if((srcObj.children(0))&&(srcObj.children(0).tagName == "SPAN")) srcObj.children(0).style.color = "#FDCC6E";
		else srcObj.style.color = (overColor || "white");
		window.event.cancelBubble = true;
	}

if(ns){
	viState = document.SMenu.visibility;
	if((lastMenu == source) && (viState[0] != 'h')){
		clearTimeout(timeoutID);
		return false;
	}
	lastMenu = source;
}

	SMenuStyle = (ns)?(document.SMenu):(SMenu.style);
	deltaDif = (ns)?(evnt.pageY):(event.y + document.body.scrollTop);

	if(!isNaN(parseInt(eval("window."+source)))){
		if(SMenus[eval(source)]){
			fillSMenu(source);
			SMenuStyle.top = deltaDif-15;
			SMenuStyle.visibility = (ns)?("show"):("visible");
			clearTimeout(timeoutID);
		}else{
			hideSMenu();
		}
	}else{
		clearTimeout(timeoutID);
	}

	return false;
}

function menuOut(source){
	clearTimeout(timeoutID);
	if(!ns){
		srcObj = document.all[source];
		srcObj.style.color = "";
		if(srcObj.children(0)) srcObj.children(0).style.color = "";
	}
	timeoutID = setTimeout("hideSMenu()",1000);
}

function imprim(id)
{ window.open("imprim.php?id=" + id.toString(),"","scrollbars=1,width=650,height=500,resizable=1,menubar=1,status=1"); }

function envoi(id)
{ window.open("envoi.php?id=" + id.toString(),"","scrollbars=0,width=450,height=300,resizable=0,menubar=0,status=1"); }

// banner rotation

var banner_index = 0;
var banner_a, banner_img, banner_timer;

var banner_src = new Array(
	"/images/b_portail.jpg", "http://www.artesi-idf.com/article.php?artno=4112&headLine=actualites",
	"/images/b_methode.jpg", "http://www.artesi-idf.com/article.php?artno=4432&headLine=actualites",
	"/images/bandeau_assises.jpg", "http://www.artesi-idf.com/admin/admin_article_fiche.php?artNo=4584&pg=1",
	"/images/bandeaux/bandeau-anime.gif", "http://www.artesi-idf.com/article.php?artno=4840&headLine=actualites"
);

function initBanner()
{
	banner_a = document.getElementById("banner_target");
	banner_img = banner_a.firstChild;
	
	banner_img.src = banner_src[0];
	banner_a.href = banner_src[1];
	
	banner_timer = setInterval("rotateBanner()", 5000);
}

function rotateBanner()
{
	if ((++banner_index)*2 == banner_src.length) banner_index = 0;
	banner_img.src = banner_src[banner_index*2];
	banner_a.href = banner_src[banner_index*2 + 1];
}
