

function getNewDivToBody(ident,classe){
	var objBody  = document.getElementsByTagName("body").item(0);
	return getNewDivChild(objBody,ident,classe);
}

function getNewDivChild(objParent,ident,classe){
	var newdiv = document.createElement("DIV");
	newdiv.id=ident;
	setClassForObj(newdiv,classe);
    objParent.appendChild(newdiv);
	return newdiv;
}


function getLargeurWindow(){
	var w;
	if (getVersionIE()<6)w=(document.documentElement.clientWidth);
	else{
		if(getVersionIE()<9)w=(document.body.offsetWidth);
		else w=(window.innerWidth);
	}
	return parseInt(w);
}
function getHauteurWindow(){
	var h;
	if (getVersionIE()<6)h=(document.documentElement.clientHeight);
	else{
		if(getVersionIE()<9)h=(document.body.offsetHeight);
		else h=(window.innerHeight);
	}
	
	if(h<40 && getVersionIE()<9 && getVersionIE()>5) h=(document.documentElement.clientHeight);
	
	return parseInt(h);
}
function getLargeurReelleImage(objImg){
	var l;
	if (getVersionIE()<9){
		l=objImg.clientWidth;
	}else l=objImg.naturalWidth;
	return parseInt(l);
}
function getHauteurReelleImage(objImg){
	var h;
	if (getVersionIE()<9)h=objImg.clientHeight;
	else h=objImg.naturalHeight;
	return parseInt(h);
}

function afficheDivAvecTransparence(html,w,h,suffixe){
	if (!suffixe || suffixe==undefined)suffixe="";

	var hW=getHauteurWindow();
	var lW=getLargeurWindow();
	if(hW<40) hW=40;
	if(lW<40) lW=40;
	if (h>hW)h=hW-40;
	if (w>lW)w=lW-40;
	var divGene=document.getElementById("divGraph_affFenetre"+suffixe);
	if (!divGene)divGene=getNewDivToBody("divGraph_affFenetre"+suffixe,"divGraph"+suffixe);
	
	if (getVersionIE()<9)divGene.style.position="absolute";
	else divGene.style.position="fixed";
	
	
	if (getVersionIE()<9){
		var objBody  = document.getElementsByTagName("body").item(0);
		objBody.style.height="100%";
	}
	
	divGene.style.zIndex="900000";
	divGene.style.left="0px";
	divGene.style.top="0px";
	divGene.style.width="100%";
	divGene.style.height="100%";
	divGene.style.opacity=0.2;
	divGene.style.backgroundColor="#000000";
	divGene.style.display="block";

	/*** IE 7 ***/
	divGene.style.filter="alpha(opacity=70)";
	
	var divMsg=document.getElementById("divGraph_fenetre"+suffixe);
	if (!divMsg)divMsg=getNewDivToBody("divGraph_fenetre"+suffixe,"divGraph"+suffixe);

	if (getVersionIE()<9)divMsg.style.position="absolute";
	else divMsg.style.position="fixed";


	divMsg.style.zIndex="1000000";
	divMsg.style.backgroundColor="#FFFFFF";
	divMsg.style.width=w+"px";
	divMsg.style.height=h+"px";
	divMsg.style.opacity=1;
	divMsg.style.marginLeft="-"+(w/2)+"px";
	divMsg.style.marginTop="-"+(h/2)+"px";
	divMsg.style.left="50%";
	divMsg.style.top="50%";
	divMsg.style.display="block";


	/*** IE6 : gestion du scroll ***/
	if (getVersionIE()<9){
		divGene.style.minHeight="1px";
		var yscroll=document.body.scrollTop;
		if (!yscroll)yscroll=document.documentElement.scrollTop;
		divGene.style.top=yscroll+"px";
		divMsg.style.marginTop=null;
		divMsg.style.top=(yscroll+50)+"px";
		
		
		function setForScroll(evt){
			var yscroll=document.body.scrollTop;
			if (!yscroll)yscroll=document.documentElement.scrollTop;
			var divGene=document.getElementById("divGraph_affFenetre"+suffixe);
			var divMsg=document.getElementById("divGraph_fenetre"+suffixe);
			divGene.style.top=yscroll+"px";
			
			divMsg.style.marginTop=null;
			divMsg.style.top=parseInt(yscroll+50)+"px";
		}
		
		document.onmousewheel=setForScroll;
		window.onscroll=setForScroll;
		
	}
	divMsg.innerHTML=unescape(html);
	
	if (window.Effect)new Effect.Opacity($(divGene), {from: 0.2, to: 0.7 });
	
	if (getVersionIE()<9){
		var tabObjSelect=document.getElementsByTagName("SELECT");
		for (var i=0;i<tabObjSelect.length && tabObjSelect[i];i++)tabObjSelect[i].style.visibility="hidden";
	}	
}


function effaceDivAvecTransparence(suffixe){
	if (!suffixe || suffixe==undefined)suffixe="";

	var divGene=document.getElementById("divGraph_affFenetre"+suffixe);
	var divMsg=document.getElementById("divGraph_fenetre"+suffixe);
	//if (divGene)divGene.style.display="none";
	if (divMsg)divMsg.style.display="none";
	if (divGene)divGene.style.display="none";
	

	if (getVersionIE()<7){
		var tabObjSelect=document.getElementsByTagName("SELECT");
		for (var i=0;i<tabObjSelect.length && tabObjSelect[i];i++)tabObjSelect[i].style.visibility="visible";
	}	

}
function effaceDivAvecTransparenceFondu(){
	effaceDivAvecTransparence();
}

function alertAMalibu(msg,foncQdFini){
	msg = unescape(msg);
	var html = "<div id='div_msgErr'>";
	html+= "<span id='span_msgErr'>"+msg+"</span>";
	html+= "<span id='span_btnRetour'>OK</span>";
	html+= "</div>";
	
	afficheDivAvecTransparence(html,"250","100");
	
	document.getElementById("div_msgErr").style.fontFamily = "Arial";
	document.getElementById("div_msgErr").style.fontSize = "11px";
	document.getElementById("div_msgErr").style.margin = "10px";
	document.getElementById("span_msgErr").style.display = "block";
	document.getElementById("span_msgErr").style.paddingBottom = "20px";
	document.getElementById("span_btnRetour").style.display = "block";
	document.getElementById("span_btnRetour").style.textAlign = "center";
	document.getElementById("span_btnRetour").style.fontWeight = "bold";
	document.getElementById("span_btnRetour").style.color = "white";
	document.getElementById("span_btnRetour").style.cursor = "pointer";
	document.getElementById("span_btnRetour").style.margin = "auto";
	document.getElementById("span_btnRetour").style.width = "42px";
	document.getElementById("span_btnRetour").style.lineHeight = "21px";
	document.getElementById("span_btnRetour").style.backgroundImage = "url(/config_v3/imgs_defaut/bt_ok.gif)";
	document.getElementById("span_btnRetour").style.backgroundRepeat = "no-repeat";
	document.getElementById("span_btnRetour").onclick=function (evt){
		effaceDivAvecTransparence();
		//if(window.foncQdFini)foncQdFini();
		if(foncQdFini)foncQdFini();
	}
}

function alertAMalibuAvecActionRetour(msg,onclick){
	msg = unescape(msg);
	var html = "<div id='div_msgErr'>";
	html+= "<span id='span_msgErr'>"+msg+"</span>";
	html+= "<span id='span_btnRetour' onclick='"+onclick+"'>OK</span>";
	html+= "</div>";
	
	afficheDivAvecTransparence(html,"250","100");
	
	document.getElementById("div_msgErr").style.fontFamily = "Arial";
	document.getElementById("div_msgErr").style.fontSize = "11px";
	document.getElementById("div_msgErr").style.margin = "10px";
	document.getElementById("span_msgErr").style.display = "block";
	document.getElementById("span_msgErr").style.paddingBottom = "20px";
	document.getElementById("span_btnRetour").style.display = "block";
	document.getElementById("span_btnRetour").style.textAlign = "center";
	document.getElementById("span_btnRetour").style.fontWeight = "bold";
	document.getElementById("span_btnRetour").style.color = "white";
	document.getElementById("span_btnRetour").style.cursor = "pointer";
	document.getElementById("span_btnRetour").style.margin = "auto";
	document.getElementById("span_btnRetour").style.width = "42px";
	document.getElementById("span_btnRetour").style.lineHeight = "21px";
	document.getElementById("span_btnRetour").style.backgroundImage = "url(/config_v3/imgs_defaut/bt_ok.gif)";
	document.getElementById("span_btnRetour").style.backgroundRepeat = "no-repeat";
}


function affMsgAttenteInDiv(nomDiv){
	var elem=document.getElementById(nomDiv);	
	if (elem){
		elem.innerHTML+="<div id=divChargement><table id=tabRechargement width=100%><tr><td align=center id=tdChargement><img id=imgRechargement style='margin:auto' width=16 height=16 src=/config_v3/imgs_defaut/loading/roue16x16.gif /></td></tr></table></div>";
		var divCharg=document.getElementById("divChargement");

		divCharg.style.position="relative";
		divCharg.style.width=elem.offsetWidth+"px";
		divCharg.style.height=elem.offsetHeight+"px";
		//divCharg.style.top=elem.offsetTop+"px";
		//divCharg.style.left=elem.offsetLeft+"px";
		divCharg.style.top="0px";
		divCharg.style.left="0px";

		if (elem.positionedOffset){
			var pos=elem.positionedOffset();
			divCharg.style.top=pos.top;
			divCharg.style.left=pos.left;
		}		
		
		divCharg.style.opacity=0.6;
		divCharg.style.background="#FFFFFF";
	}
}

function affMsgAttenteParDessusInDiv(nomDiv,suffixe,txt){
	var elem=$(nomDiv);	
	if (!suffixe)suffixe="";
	if (!txt)txt="";

	if (elem){
		var divCharg=getNewDivChild(elem,"divChargementParDessus"+suffixe,"chargement");
		divCharg.style.position="absolute";
		divCharg.style.zIndex=120;
		divCharg.style.width=elem.offsetWidth+"px";
		if (elem.offsetHeight>0)divCharg.style.height=elem.offsetHeight+"px";
		else divCharg.style.height="100%";
		divCharg.style.top=elem.offsetTop+"px";
		divCharg.style.left=elem.offsetLeft+"px";
		divCharg.style.opacity=0.6;
		divCharg.style.background="#FFFFFF";
		if (elem.positionedOffset){
			var pos=elem.positionedOffset();
			divCharg.style.top=pos.top;
			divCharg.style.left=pos.left;
		}
		
		if(!txt)txt="<img id=imgRechargement style='margin:auto' width=16 height=16 src=/config_v3/imgs_defaut/loading/roue16x16.gif />";		
		divCharg.innerHTML+="<div id=divRechargementParDessus"+suffixe+" ><table width='100%' height='100%'><tr valign='middle'><td align='center'><div id='divChargementParDessusMsg'>"+txt+"</div></td></tr></table></div>";
		
		
		
		return $("divChargementParDessusMsg");
		//return divCharg;
	}
	return null;
}
function effaceMsgAttenteParDessus(suffixe){
	if (!suffixe)suffixe="";
	var elem=$("divChargementParDessus"+suffixe);
	if (elem)elem.parentNode.removeChild(elem);
}


function affDefileRechercheCommune(nomdiv,ldep){
	appelAjaxToFunc("lib/listes/communes.php",(ldep)?"dpts="+ldep:"",
		function(reponse){
			var json=new String(reponse);
			var lstCommune=json.evalJSON();
			var alea=Math.random()*lstCommune.length;

			setInterval(function(){
				nomCommune=lstCommune[parseInt(Math.random()*lstCommune.length)];
				if ($("spanRechercheCommuneNom"))$("spanRechercheCommuneNom").update(nomCommune);
				else $(nomdiv).insert("<div class='rechercheCommune'><span class=spanRechercheCommuneLib>Commune : <span><span class=spanRechercheCommuneNom id=spanRechercheCommuneNom>"+nomCommune+"</span></div>");
			},Math.random()*150);
		}
	);
}



function getHtmlForFlash(urlFic,idObj){
	var html='<object align="middle" id="'+idObj+'" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">';
	html+='<param value="sameDomain" name="allowScriptAccess"/>';
	html+='<param value="false" name="allowFullScreen"/>';
	html+='<param value="'+urlFic+'" name="movie"/>';
	html+='<param value="high" name="quality"/>';
	html+='<param value="#ffffff" name="bgcolor"/>';
	html+='<param value="transparent" name="wmode"/>';
	html+='<embed align="middle" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="false" allowscriptaccess="sameDomain" name="'+idObj+'" bgcolor="#ffffff" quality="high" ';
	html+=' src="'+urlFic+'"/>';
	html+=' </object>';
	return html;
}
/*
function listeByAjaxFromCGI(cgis){
	var xhr_local=creeObjHttpRequest();
	var url="/liste";
	
	xhr_local.onreadystatechange = function(){
		if(xhr_local.readyState == 4 && xhr_local.status == 200){
			var contenuVisuStruct=xhr_local.responseText;	
			
			var xhr_fenetre=creeObjHttpRequest();
			xhr_fenetre.onreadystatechange = function(){
				if(xhr_fenetre.readyState == 4 && xhr_fenetre.status == 200){
					var contenuPage=xhr_fenetre.responseText;	
					document.getElementById("page").innerHTML=contenuPage;
				}
			}
			
			xhr_fenetre.open("POST","/lib/ajax/contenuFenetre.php",true);
			xhr_fenetre.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
			xhr_fenetre.send("typeInfo=PAGE");
	
	
			var xhr_head=creeObjHttpRequest();
			xhr_head.onreadystatechange = function(){
				if(xhr_head.readyState == 4 && xhr_head.status == 200){
					var contenuHead=xhr_head.responseText;	
					document.ByTagName("head").item(0).innerHTML=contenuHead;
				}
			}
			
			xhr_fenetre.open("POST","/lib/ajax/contenuFenetre.php",true);
			xhr_fenetre.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
			xhr_fenetre.send("typeInfo=HEAD");
		
		}
	}
			
	xhr_local.open("POST",url,true);
	xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_local.send(cgis);
}
*/

function getDivCentreeWithHtml(html){
	var divGene=document.getElementById("divGeneCentreeMsg");
	if (!divGene){
		var body  = document.getElementsByTagName("body").item(0);
		var divGene = document.createElement("DIV");
		divGene.id="divGeneCentreeMsg";
		setClassForObj(divGene,"divGeneCentreeMsg");
    	body.appendChild(divGene);
    }
    divGene.innerHTML=html;
	    
	var largPanel=divGene.offsetWidth;
	var hautPanel=divGene.offsetHeight;

	var largScreen=window.outerWidth;
	var hautScreen=window.outerHeight;
		
	var marginLarg=((largScreen-largPanel))/2;
	var marginHaut=((hautScreen-hautPanel))/2;
	if (marginHaut<0)marginHaut=25;	

	
	divGene.style.position="absolute";
	divGene.style.opacity=1;
	divGene.style.left=marginLarg+"px";
	divGene.style.top=marginHaut+"px";
	divGene.style.display="block";
	divGene.style.visibility="visible";

	return divGene;
}

function effaceDivSurPage(){
	var divGene=document.getElementById("divSurPage");
	var divMsg=document.getElementById("divMsgSurPage");

	if (divGene)divGene.parentNode.removeChild(divGene);
	if (divMsg)divMsg.parentNode.removeChild(divMsg);
	
}



function getDivSurPageWithHtml(html){
	var divGenerale=document.getElementById("general");
	var divGene=document.getElementById("divSurPage");
	var divPage=document.getElementById("page");
	
	if (!divGene){
		var body  = document.getElementsByTagName("body").item(0);
		var divGene = document.createElement("DIV");
		divGene.id="divSurPage";
		setClassForObj(divGene,"divGraph");
      	body.appendChild(divGene);
	}
	
	divGene.style.zIndex="9001";
	divGene.style.position="absolute";
	divGene.style.left=(divGenerale.offsetLeft+divPage.offsetLeft)+"px";
	divGene.style.top=(divGenerale.offsetTop+divPage.offsetTop)+"px";
	divGene.style.width=divPage.offsetWidth+"px";
	divGene.style.height=divPage.offsetHeight+"px";
	divGene.style.opacity=0.7;
	/*** IE 7 ***/
	divGene.style.filter="alpha(opacity=70)";
	/*** IE 6 ***/
	divGene.style.minHeight="1px";
	divGene.style.backgroundColor="#FFFFFF";
	divGene.style.display="block";
	
	
	var divMsg=document.getElementById("divMsgSurPage");
	if (!divMsg){
		var body  = document.getElementsByTagName("body").item(0);
		var divMsg = document.createElement("DIV");
		divMsg.id="divMsgSurPage";
		setClassForObj(divMsg,"divGraph");
      	body.appendChild(divMsg);
	}
	
	divMsg.innerHTML=html;
	w=200;
	h=100;
	divMsg.style.zIndex="9002";
	divMsg.style.position="absolute";
	divMsg.style.backgroundColor="#FFFFFF";
	divMsg.style.width=w+"px";
	divMsg.style.height=h+"px";
	divMsg.style.opacity=1;
	divMsg.style.border="1px solid #000000";
	divMsg.style.marginLeft="-"+(w/2)+"px";
	//divMsg.style.marginTop="-"+(h/2)+"px";
	//divMsg.style.marginTop="-"+(h/2)+"px";
	divMsg.style.left=((divGenerale.offsetLeft+divPage.offsetLeft)+(divPage.offsetWidth-w)/2)+"px";
	divMsg.style.top=((divGenerale.offsetTop+divPage.offsetTop)+200)+"px";
	divMsg.style.display="block";
	divMsg.style.opacity=0.7;
	
}



function setPositionObjBySouris(evt,obj,decalX,decalY){
    var xMouse,yMouse,x,y;

	if (!decalX)decalX=0;
	if (!decalY)decalY=0;

    if (navigator.appName!="Microsoft Internet Explorer"){
    	xMouse=evt.pageX+1;
        yMouse=evt.pageY+1;
        var ww = window.innerWidth;
        var wh = window.innerHeight;
	}else{
		var de = document.documentElement;
        var b = document.body;
        xMouse = evt.clientX + (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        yMouse = evt.clientY + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
        var ww = b.clientWidth;
        var wh = b.clientHeight;
    }
    
    
    var yMax=wh-obj.offsetHeight;
    if (yMouse>yMax)y=yMouse-obj.offsetHeight;
    else y=yMouse;   
     
    var xMax=ww-obj.offsetWidth;
    if (xMouse>xMax)x=xMouse-obj.offsetWidth;
    else x=xMouse;    
    
    
    obj.style.left = (x+decalX) + "px";
    obj.style.top = (y+decalY) + "px";
}


function afficheBulle(evt,txt,largMax){
	var bulle=document.getElementById("divInfoBulle");
	if (!bulle)bulle=getNewDivToBody("divInfoBulle","divInfoBulle");
	
	bulle.style.backgroundColor="#FFFFFF";
	bulle.style.border="1px solid #000000";
	bulle.style.padding="3px";
	
	bulle.style.position="absolute";
	bulle.style.color="#000000";
	bulle.style.zIndex="10000001";
	
	bulle.innerHTML=unescape(txt);
	bulle.style.visibility="visible";
	setPositionObjBySouris(evt,bulle,15,25);
}


function effaceBulle(evt){
	var bulle=document.getElementById("divInfoBulle");
	if (bulle)bulle.style.visibility="hidden";
}


function afficheImageOnBulle(evt,path_img,largMax){
	var txt="<img src="+path_img+" width="+largMax+" />";
	afficheBulle(evt,txt,largMax);
	
}


