var initialiser = false ;
var timeID1 = null ;
var timeID2 = null ;
var nbMenus = 8 ;
var nbCalques = 5 ;

//onresize=rechargerPage

is = new BrowserCheck() ;
pf = new PlateformeCheck() ;

function init() {
	initialiser=true ;
		//alert("toto");
	//if (menuDefaut>0) changerImage2Defaut() ;
	//if (menuextraDefaut>0) changerImage3Defaut() ;
	//if (smenuDefaut>0) changerImageDefaut() ;
	//prechargementmenus() ;
}

function confirmDeleteFiche() {
	if (confirm("Etes vous sure de vouloir effacer cette fiche ?")) {
		document.FormEdition.effacer.value=1 ;
		document.FormEdition.submit() ;
	}
}

function BrowserCheck() {
	var b = navigator.appName
	if (b=="Netscape") this.b = "ns"
	else if (b=="Microsoft Internet Explorer") this.b = "ie"
	else this.b = b
	this.version = navigator.appVersion
	this.v = parseInt(this.version)
	this.ns = (this.b=="ns" && this.v>=4)
	this.ns4 = (this.b=="ns" && this.v==4)
	this.ns5 = (this.b=="ns" && this.v>=5)
	this.ie = (this.b=="ie" && this.v>=4)
	this.ie4 = (this.version.indexOf('MSIE 4')>0)
	this.ie5 = (this.version.indexOf('MSIE 5')>0)
	this.min = (this.ns || this.ie)
	this.plateforme = "plateforme" + navigator.platform
	this.pc = (this.plateforme.indexOf('Win')>0)
	this.mac = (this.plateforme.indexOf('Mac')>0)
	return this
}

function PlateformeCheck() {
	this.plateforme = "plateforme" + navigator.platform
	this.pc = (this.plateforme.indexOf('Win')>0)
	this.mac = (this.plateforme.indexOf('Mac')>0)
	return this
}

function prechargementmenus() {
	for (i=1 ; i<=8 ; i++) {
		image = "m3_"+i ;
		src = "../images/web/m_"+i+".gif" ;
		prechargement(image,src) ;
		image2 = "m2_"+i ;
		src2 = "../images/web/m_"+i+"-over.gif" ;
		prechargement(image2,src2) ;
	}
	//prechargement("menu1_1","../images/templates/menu_1-over.gif")
}

function prechargement(imgObj,imgSrc) {
	if (document.images) {
		eval(imgObj+' = new Image()') ;
		eval(imgObj+'.src = "'+imgSrc+'"') ;
	}
}
function wop(url) {
	window.open(url,"_self") ;
}
function ouvrirFenetre(url,w,h) {
	ouvrirFenetre2(url, "width="+w+",height="+h+",scrollbars=1") ;
}
function ouvrirFenetre2(url, options) {
	window.open(url,"_blank",options) ;
}
function redirigerVers(lien) {
	window.open(lien, "_self") ;
}
function imprimer(){
	window.print() ;
	//window.close() ;
}
function rechargerPage() {
	if (initialiser==true) {
		history.go(0);
	}
}

function changerImage(num) {
	if (initialiser) {
		clearTimeout(timeID2) ;
		//alert("toto");
		for (i=1 ; i<=8 ; i++) {
			onoff = (num!=i) ? "" : "-over" ;
			image = "m_"+i ;
			document[image].src = "../images/web/m_"+i+onoff+".gif" ;
		}
	}
}

function changerImageDefaut() {
	timeID2 = setTimeout("changerImage(menuDefaut)",20) ;
}

/*
function changerImage3(num) {
	if (initialiser) {
		clearTimeout(timeID2) ;
		for (i=1 ; i<=3 ; i++) {
			onoff = (num!=i) ? "" : "-over" ;
			image = "menuextra"+i ;
			document[image].src = "../images/extranet/menuextra"+i+onoff+".gif" ;
		}
	}
}

function changerImage3Defaut() {
	timeID2 = setTimeout("changerImage3(menuextraDefaut)",20) ;
}
*/
function getValPx(valAsStr) {
	if (is.ns4) return valAsStr ;
	posPx = valAsStr.indexOf("px") ;
	if (posPx!=-1) {
		val = parseInt(valAsStr.substring(0,posPx));
		return val ;
	} else {
		return parseInt(valAsStr) ;
	}
}
function defautCalque() {
	downHandler() ;
}
function overHandler() {
	clearTimeout(timeID2) ;
}
function downHandler() {
	timeID2 = setTimeout("montrerCalque(menuDefaut)",200) ;
}
function montrerCalque(num) {
	clearTimeout(timeID2) ;
	var texte = "" ;
	var bgColor = "#e4e4e4" ;
	if (num==1) {
		texte="" ;
		bgColor="#e1eb7f" ;
	} else if (num==2) {
		texte="<a class='onglet' href='../offres/rech-offre.php'>TOUTES LES OFFRES</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a class='onglet' href='../offres/crea-offre.php'>NOUVELLE OFFRE</a>" ;
		bgColor="#c5e9fa" ;
	} else if (num==3) {
		texte="<img src='../images/spacer.gif' width=200 height=15 align='absmiddle'><a class='onglet' href='../clients/rech-client.php'>TOUS LES CLIENTS</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a class='onglet' href='../clients/crea-client.php'>NOUVEAU CLIENT</a>" ;
		bgColor="#d5c6fa" ;
	} else if (num==4) {
		texte="<div align='right'><a class='onglet' href='../mandants/rech-mandant.php'>TOUS LES MANDANTS</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a class='onglet' href='../mandants/crea-mandant.php'>NOUVEAU MANDANT</a><img src='../images/spacer.gif' width=50 height=15 align='absmiddle'></div>" ;
		bgColor="#fae3c5" ;
	} else if (num==5) {
		texte="<div align='right'><a class='onglet' href='../actions/actions.php'>TOUTES LES ACTIONS</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a class='onglet' href='../preferences/preferences.php'>PR&Eacute;FERENCES</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<a class='onglet' href='../home/home2.php?logout=1'>LOGOUT</a><img src='../images/spacer.gif' width=10 height=15 align='absmiddle'></div>" ; //<a class='onglet' href='../actions/repertoire.php'>CARNET D'ADRESSES</a>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;
		bgColor="#fac5c5" ;
	}
	var element = null ;
	var element2 = null ;
	var element3 = null ;
	var id = "sousmenusdyn" ;
	var id2 = "sousmenusdyn2" ;
	var id3 = "sousmenusdyn3" ;
	if (document.getElementById) {
		element = document.getElementById(id);
		element2 = document.getElementById(id2);
		element3 = document.getElementById(id3);
	} else if (document.all) {
		element = document.all[id] ;
		element2 = document.all[id2] ;
		element3 = document.all[id3] ;
	} 
	if (element) {
		element.innerHTML=texte ;
		element.style.backgroundColor=bgColor ;
		element2.style.backgroundColor=bgColor ;
		element3.style.backgroundColor=bgColor ;
	}
	if (initialiser) {
		for (i=1 ; i<=5 ; i++) {
			onoff = (num!=i) ? "" : "-on" ;
			image = "m_"+i ;
			document[image].src = "../images/"+image+onoff+".gif" ;
		}
	}

	/*
	if (initialiser) {
	cacherTousCalques(0) ;
	for (i=1 ; i<=nbCalques ; i++) {
		idCalque = "calqueMenuDHTML"+i ;
		if (is.ns5) objCalque = document.getElementById(idCalque).style ;
		else if (is.ns) objCalque = document.layers[idCalque] ;
		else objCalque = document.all[idCalque].style ;
		if (num==i) {
			if (getValPx(objCalque.left)<0) {
			if (is.ns5) {
				objCalque.visibility = "visible" ;
				objCalque.left = getValPx(objCalque.left) + 2000 ;
				//document.getElementById(idCalque).onmouseout = downHandler
				//document.getElementById(idCalque).onmouseover = overHandler			
			} else if (is.ns) {
				objCalque.visibility = "show" ;
				objCalque.left = getValPx(objCalque.left) + 2000 ;
				//document.layers[idCalque].captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSEMOVE)
				//document.layers[idCalque].onmouseout = downHandler
				//document.layers[idCalque].onmouseover = overHandler
			} else {
				objCalque.visibility = "visible" ;
				objCalque.left = getValPx(objCalque.left) + 2000 ;
				//document.all[idCalque].onmouseout = downHandler
				//document.all[idCalque].onmouseover = overHandler
			}
			}
		}
	}
	}*/
}
function cacherTousCalques(sauf) {
	for (i=1 ; i<=nbCalques ; i++) {
		idCalque = "calqueMenuDHTML"+i ;
		if (is.ns5) objCalque = document.getElementById(idCalque).style ;
		else if (is.ns) objCalque = document.layers[idCalque] ;
		else {
			objCalque = document.all[idCalque].style ;
			alert(idCalque+"test"+objCalque.left) ;
		}
		if (i!=sauf) {
			/*
			if (is.ns5) document.getElementById(idCalque).style.visibility = "hidden" ;
			else if (is.ns) document.layers[idCalque].visibility = "hide" ;
			else document.all[idCalque].style.visibility = "hidden" ;
			*/
			if (getValPx(objCalque.left)>0) {
				objCalque.left = getValPx(objCalque.left) - 2000 ;
			}
		}
	}
}

