

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 afficheDivAvecTransparence(html,w,h){


	var divGene=document.getElementById("divGraph_affFenetre");
	if (!divGene)divGene=getNewDivToBody("divGraph_affFenetre","divGraph");
	
	if (getVersionIE()<8)divGene.style.position="absolute";
	else divGene.style.position="fixed";
	
	
	if (getVersionIE()<7){
		var objBody  = document.getElementsByTagName("body").item(0);
		objBody.style.height="100%";
	}
	
	divGene.style.zIndex="9000";
	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");
	if (!divMsg)divMsg=getNewDivToBody("divGraph_fenetre","divGraph");

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

	divMsg.style.zIndex="10000";
	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()<8){
		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";
		
		document.onmousewheel=function(event){
			var yscroll=document.body.scrollTop;
			if (!yscroll)yscroll=document.documentElement.scrollTop;
			var divGene=document.getElementById("divGraph_affFenetre");
			var divMsg=document.getElementById("divGraph_fenetre");
			divGene.style.top=yscroll+"px";
			
			divMsg.style.marginTop=null;
			divMsg.style.top=parseInt(yscroll+50)+"px";
		}
	}
	divMsg.innerHTML=unescape(html);
	
	$(divGene).tween("opacity",0.2,0.7);
	
	//if (getVersionIE()<7){
		var tabObjSelect=document.getElementsByTagName("SELECT");
		for (var i=0;i<tabObjSelect.length;i++)tabObjSelect[i].style.visibility="hidden";
	//}	
}


function effaceDivAvecTransparence(){
	var divGene=document.getElementById("divGraph_affFenetre");
	var divMsg=document.getElementById("divGraph_fenetre");
	//if (divGene)divGene.style.display="none";
	if (divMsg)divMsg.style.display="none";
	if (divGene)$(divGene).fade(0);

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

}
function effaceDivAvecTransparenceFondu(){
	effaceDivAvecTransparence();
}

function alertAMalibu(msg){
	msg = unescape(msg);
	var html = "<div id='div_msgErr'>";
	html+= "<span id='span_msgErr'>"+msg+"</span>";
	html+= "<span id='span_btnRetour' onclick='effaceDivAvecTransparence()'>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 appelAdrAjaxInDivAvecTransparence(adr,sending,msg,w,h){
	var html_init="<div id='divChargementAjx'><img src=/config_v3/imgs_defaut/rouegrise.gif /><br />"+msg+"</div>";
	
	if(!w) w=200;
	if(!h) h=150;
	afficheDivAvecTransparence(html_init,w,h);

	var objStatus=document.getElementById("divChargementAjx");
	var xhr_local=creeObjHttpRequest();
  	xhr_local.onreadystatechange = function(){
		if(xhr_local.readyState == 4 && xhr_local.status == 200){
			reponse = xhr_local.responseText;
			objStatus.innerHTML=reponse;
			}
		}
	xhr_local.open("POST",adr,true);
 	xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_local.send(sending);
	
	
}

function affMsgAttenteInDiv(nomDiv){
	var elem=document.getElementById(nomDiv);	
	if (elem){
		
		elem.innerHTML+="<div id=chargement><table width=100%><tr><td align=center><img style='margin:auto' width=20 height=20 src=/config_v3/imgs_defaut/rouegrise_fond.gif /></td></tr></table></div>";
		var divCharg=document.getElementById("chargement");
		divCharg.style.position="absolute";
		divCharg.style.width=elem.offsetWidth;
		divCharg.style.height=elem.offsetHeight;
		divCharg.style.top=elem.offsetTop;
		divCharg.style.left=elem.offsetLeft;
		divCharg.style.opacity=0.6;
		divCharg.style.background="#FFFFFF";
	}
}


function affUrlInDiv(nomDiv,url,vars,msgAttente){
	var idx=url.indexOf("?");
	if (idx>0){
		vars += url.substr(idx+1);
		url = url.substr(0,idx);
	}
	vars+=getInfoSession("PHPSESSID");
	
	var xhr_local=creeObjHttpRequest();		
	xhr_local.onreadystatechange = function(){
		if(xhr_local.readyState == 4 && xhr_local.status == 200){
		
			var reponse = xhr_local.responseText;
			var elem=document.getElementById(nomDiv);					
			if (elem)elem.innerHTML=reponse;				
		}
	}
	var elem=document.getElementById(nomDiv);
	
	if (elem && msgAttente)elem.innerHTML=msgAttente;		
	else affMsgAttenteInDiv(nomDiv);			
	xhr_local.open("POST",url,true);
	xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_local.send(vars);
}

function affUrlInDivFromHtml(html){
	var data=html;
	var idx_debhtml=data.indexOf("-->");
	if (idx_debhtml>0){
		var js = data.substr(4,idx_debhtml-4);
		if (js.substr(0,14)=="JS_affUrlInDiv"){
			var tabInfos=js.split("&#164;");
			affUrlInDiv(tabInfos[1],tabInfos[2],tabInfos[3]);
		}
	}

}


function affUrlSsTourInDivAvecMsgAttente(nomDiv,url,query_string,html_attente){
	var xhr_local=creeObjHttpRequest();
	xhr_local.onreadystatechange = function(){
		if(xhr_local.readyState == 4 && xhr_local.status == 200){
			var contenu=xhr_local.responseText;	
			document.getElementById(nomdiv).innerHTML=contenu;
		}
	}
			
	xhr_local.open("POST",url,true);
	xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_local.send(query_string);
}

function chargeAdresseHTMLDansDiv(nomdiv,url,query_string){
	var xhr_local=creeObjHttpRequest();
	xhr_local.onreadystatechange = function(){
		if(xhr_local.readyState == 4 && xhr_local.status == 200){
			var contenu=xhr_local.responseText;	
			document.getElementById(nomdiv).innerHTML=contenu;
		}
	}
			
	xhr_local.open("POST",url,true);
	xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_local.send(query_string);
}
 
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 urlCentreByAjaxFromCGI(url,cgis,htmlAttente){
	var xhr_local=creeObjHttpRequest();

	if (htmlAttente)var objMsg=getDivSurPageWithHtml(htmlAttente);
	
	
	xhr_local.onreadystatechange = function(){
		if(xhr_local.readyState == 4 && xhr_local.status == 200){
			var contenuVisuStruct=xhr_local.responseText;	
			//document.getElementById("page").innerHTML=contenuVisuStruct;
			
			var xhr_head=creeObjHttpRequest();
			xhr_head.onreadystatechange = function(){
				if(xhr_head.readyState == 4 && xhr_head.status == 200){
					var contenuHead=xhr_head.responseText;	
					document.getElementsByTagName("head").item(0).innerHTML=contenuHead;
					document.getElementById("page").innerHTML=contenuVisuStruct;
					effaceDivSurPage();
				}
			}
			
			xhr_head.open("POST","/lib/ajax/contenuFenetre.php",true);
			xhr_head.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
			xhr_head.send("typeInfo=HEAD");		
		}
	}
			
	xhr_local.open("POST",url,true);
	xhr_local.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_local.send(cgis+"&JUSTE_LE_CENTRE=JLC");
}

function listeByAjaxFromCGI(cgis,htmlAttente){
	urlCentreByAjaxFromCGI("/liste",cgis,htmlAttente);
}

function listeByAjaxFromForm(idForm,htmlAttente){
	var objForm=document.getElementById(idForm);
	if (!objForm)return;

	var tabForm=getTabChmpForm(objForm);
	var query="";
	
	for (var i=0;i<tabForm.length;i++){
		query+="&"+tabForm[i].id+"="+tabForm[i].value;	
	}
	urlCentreByAjaxFromCGI("/liste",query,htmlAttente);
}


function urlDsPageCurrByAjaxAvecMsgAttente(url,cgi,htmlAttente){

}


function affichePageByAjax(numeroPage){
	var adr="/lib/ajax/contenuFenetre.php";
	var sendingLst="element=objProd&typeInfo=visu_struct-"+numeroPage+getInfoSession("PHPSESSID");
	var sendingNavig="element=objProd&typeInfo=navig"+getInfoSession("PHPSESSID");
	affUrlInDiv("lst",adr,sendingLst);
	affUrlInDiv("div_navigListe_haut",adr,sendingNavig,document.getElementById("div_navigListe_haut").innerHTML);
}


