if (navigator.appVersion.indexOf("MSIE")>=0){
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if (version < 7){
		window.attachEvent("onload", correctPNG);
	}
}

function correctPNG() {// correctly handle PNG transparency in Win IE 5.5 & 6.
  var arVersion = navigator.appVersion.split("MSIE")
  var version = parseFloat(arVersion[1])
  if ((version >= 5.5) && (document.body.filters))
  {
     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
        }
     }
  }
}

function printBrique(id)
{
window.open('/modules/print.php?id=' + id,'print','scrollbars=yes,resizeable=yes,menubar=no');
}

function checkIframe(){
//	if(window.document.title!='glossaire' || !window.opener) { // on est dans une popup glossaire => pas de cadre!!!

		// on est en frontoffice

		if (this.document.location.href.indexOf("/content/") > 0){
			if (this.name == "awsiframe"){
					//todo bene
			}
			else{
				window.top.document.location.href = "/content/aws2006/inter.php?ifile=/"+getAccessPath();
			}
		} else {
			// on est en backoffice
			}

//	}


brique();
}

function getAccessPath(){
	var l_adresse = document.location.href;
	//on vire protocole ://
	l_adresse = l_adresse.substr(l_adresse.indexOf("://")+3);
	return l_adresse.substr(l_adresse.indexOf("/")+1);
}

// Ouverture du popup
function send(id) {
	srcHTML = window.opener.document.getElementById(id).innerHTML;
	document.getElementById('contenu').innerHTML = srcHTML;
}

function impression(id) {
	srcHTML = window.opener.document.getElementById(id).innerHTML;
	document.getElementById('contenu').innerHTML = srcHTML;
	window.print();
}

function printIt(obj) {
	divObj = getDivToProcess(obj);
	if(divObj!=null) {
		window.open('/modules/print.php?id=' + divObj.getAttribute('id'),'print','scrollbars=yes,resizeable=yes,menubar=no');
	} else {
		window.print();
	}
}

function sendIt(obj) {
	divObj = getDivToProcess(obj);
	if(divObj!=null) {
		window.open('/modules/sendfriend.php?id=' + divObj.getAttribute('id'),'send','scrollbars=yes,resizeable=yes,menubar=no');
	} else {
		window.alert('Fonctionnalité désactivée sur la page d\'impression');
	}
}

function getDivToProcess(obj) {
	val = null;
	while(obj.tagName!='div' && obj.tagName!='DIV' && obj.tagName!='body' && obj.tagName!='BODY') {
		obj = obj.parentNode;
	}
	id = obj.getAttribute('id');
	if (id == "" || id == null){
		return getDivToProcess(obj.parentNode);
	}
	
	if(id.match(/^div/) || id.match(/^bf/)) {
		val = obj;
	}
	return val;
}

function openbrwindow(theURL,winName,width,height,features,bCentre) {
  var window_width = width;
  var window_height = height;
  var newfeatures= "," + features;
  var window_top = (screen.height-window_height)/2;
  var window_left = (screen.width-window_width)/2;
	if(bCentre == 'false'){
		newWindow=window.open(''+ theURL + '',''+ winName +
'','width=' + window_width + ',height=' + window_height + newfeatures +
'');
	}else{
	  newWindow=window.open(''+ theURL + '',''+ winName +
'','width=' + window_width + ',height=' + window_height + ',top=' +
window_top + ',left=' + window_left + newfeatures + '');
	}
  newWindow.focus();
}
// Gestion des RollOvers
function img_RollOver(objSel, imgUrl){
	objSel.src = imgUrl;
}

// Gestion des RollOuts
function img_RollOut(objSel, imgUrl){
  objSel.src = imgUrl;
} 
	

// Gestion des RollOvers
function img_rollOver(objSel, imgUrl){
	objSel.src = imgUrl;
}

// Gestion des RollOuts
function img_rollOut(objSel, imgUrl){
  objSel.src = imgUrl;
} 
	
// Gestion du preload

function img_Preload(){
	var d=document;
	if(d.image){
		if(!d.tbImage) d.tbImage = new Array();
		var i,j=d.tbImage.length, a=img_preload.arguments;
		for(i=0;i<a.length;i++){
			if(a[i].indexOf("#")!=0){
					d.tbImage[j] = new Image;
					d.tbImage[j++].src=a[i];
			}
		}
	}
}

// les fonctions Js de dreamweaver
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/* // version Dhorizon
function MM_jumpMenu(targ,selObj,restore){ //v3.0
 
  		openBrWindow(selObj.options[selObj.selectedIndex].value,'site','600','400','toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes',true);

  if (restore) selObj.selectedIndex=0;
}
*/ 

function MM_jumpMenu(targ,selObj,restore){ //v3.0

//alert(selObj.options[selObj.selectedIndex].value);

   // si pas de value -> pas de lien
   if (selObj.options[selObj.selectedIndex].value != "") {
       eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
       if (restore) selObj.selectedIndex=0;
   }
} 
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function verifyCompatibleBrowser(){ 
    this.ver=navigator.appVersion 
    this.dom=document.getElementById?1:0 
    this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom)?1:0; 
    this.ie4=(document.all && !this.dom)?1:0; 
    this.ns5=(this.dom && parseInt(this.ver) >= 5) ?1:0; 
 
    this.ns4=(document.layers && !this.dom)?1:0; 
    this.bw=(this.ie5 || this.ie4 || this.ns4 || this.ns5) 
    return this 
} 
bw=new verifyCompatibleBrowser() 
 
 
var speed=50 
 
var loop, timer 
 
function ConstructObject(obj,nest){ 
    nest=(!nest) ? '':'document.'+nest+'.' 
    this.el=bw.dom?document.getElementById(obj):bw.ie4?document.all[obj]:bw.ns4?eval(nest+'document.'+obj):0; 
    this.css=bw.dom?document.getElementById(obj).style:bw.ie4?document.all[obj].style:bw.ns4?eval(nest+'document.'+obj):0; 
    this.scrollHeight=bw.ns4?this.css.document.height:this.el.offsetHeight 
    this.clipHeight=bw.ns4?this.css.clip.height:this.el.offsetHeight 
    this.up=MoveAreaUp;this.down=MoveAreaDown; 
    this.MoveArea=MoveArea; this.x; this.y; 
    this.obj = obj + "Object" 
    eval(this.obj + "=this") 
    return this 
} 
function MoveArea(x,y){ 
    this.x=x;this.y=y 
    this.css.left=this.x 
    this.css.top=this.y 
} 
 
function MoveAreaDown(move){
	if(this.y>-this.scrollHeight+objContainer.clipHeight){
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".down("+move+")",speed) 
	} 
} 
function MoveAreaUp(move){ 
	if(this.y<0){ 
    this.MoveArea(0,this.y-move) 
    if(loop) setTimeout(this.obj+".up("+move+")",speed) 
	} 
} 
 
function PerformScroll(speed){ 
	if(initialised){ 
		loop=true; 
		if(speed>0) objScroller.down(speed) 
		else objScroller.up(speed) 
	} 
} 
function CeaseScroll(){ 
    loop=false 
    if(timer) clearTimeout(timer) 
} 

var initialised; 
function InitialiseScrollableArea(strContent, strContainer){ 
    objContainer= new ConstructObject(strContainer); 
    objScroller=new ConstructObject(strContent, strContainer) 
    objScroller.MoveArea(0,0) 
    objContainer.css.visibility='visible' 
    initialised=true; 
} 

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function quizz(id) { 
if(id==3) window.opener.document.location='/content/situation%20energetique/énergies%20renouvelables/Panorama/';
if(id==2) window.opener.document.location='/content/situation%20energetique/bilans%20énergétiques/bilans%20départementaux%201999/';
if(id==1) window.opener.document.location='/content/Decouvrir%20energie/en%20savoir%20plus/';
window.close();
}
function awsprint() {
	printwindow=window.open('/content/espace/print.html','printAWS','width=580,height=490,status=yes');
	this.loadIsDone = false;
}
function awsprintnopopup() {
	if(bw.ns5) { // Correction BUG Moz
	// Impossible d'imprimer un long div positionné en absolu
	// Il es coupé.
		beforeprint()
		setTimeout("window.print(); afterprint()",1000)
	}
	else window.print();
/*	if(window.onafterprint==undefined) { // Moz and others
		beforeprint()
		setTimeout("window.print(); afterprint()",1000)
	}
	else { // IE
		window.print();
	}
*/
}
function fillPrintWindow(){
	htmlSource = opener.document.getElementById("content").innerHTML
	printDiv = document.getElementById("printzone");
 	printDiv.innerHTML = htmlSource;
	
	return true;
}

function beforeprint() {
/*	var tab_div = document.getElementsByTagName("DIV");
	for(elt in tab_div) {
		if(tab_div[elt].id) {
			var block = ""+tab_div[elt].id
			if(block=="content") tab_div[elt].style.overflow="visible"
			if(block=="space") tab_div[elt].style.overflow="visible"
			if(block.substring(0,3)=="div") tab_div[elt].style.overflow="visible"
			
			if(block=="content") tab_div[elt].style.position="relative"
			if(block=="space") tab_div[elt].style.position="relative"
			if(block.substring(0,3)=="div") tab_div[elt].style.position="relative"

			if(block.substring(0,3)=="div") tab_div[elt].style.top="0px"
			if(block.substring(0,3)=="div") tab_div[elt].style.left="0px"
		}
	}*/
}
function afterprint() {
	/*
	document.location = document.location.href
*/
}

if(window.onbeforeprint!="undefined") window.onbeforeprint=beforeprint
if(window.onafterprint!="undefined") window.onafterprint=afterprint

function brique() {
	if(eval(document.getElementById("content")) == null){
		return false; // pages non AWS - execution inutile
	}
	
	//alert("function brique()")
	var tab_div = document.getElementsByTagName("DIV");
	var previousButt = -9999;
	var previousEnd = -9999;
	var previousLeft = -9999;
	var previousIsZE = 0;
	for(elt in tab_div) {
		if(tab_div[elt].id) {
			var block = ""+tab_div[elt].id
			//if(block=="content") tab_div[elt].style.overflow="visible"
			//if(block=="space") tab_div[elt].style.overflow="visible"
			//if(block=="content") tab_div[elt].style.position="relative"
			//if(block=="space") tab_div[elt].style.position="relative"
			
			if(block.substring(0,2)=="ze"){
				
			}
			
			if(block.substring(0,2)=="bf"){
				if (previousIsZE == 1){
					if (tab_div[elt].offsetTop < previousButt){
						//alert(block + " BF\n" + tab_div[elt].id + ".offsetTop = " + tab_div[elt].offsetTop + " previousButt = " + previousButt + "\n" + tab_div[elt].parentNode.id  + " must move by : " + (previousButt-(tab_div[elt].offsetTop)));
						tab_div[elt].style.top=String(tab_div[elt].offsetTop + previousButt-tab_div[elt].offsetTop)+"px"
					}
				}
				previousIsZE = 0;
			}
			
			if(block.substring(0,3)=="div"){
				tab_div[elt].style.overflow="auto";
				if (previousIsZE == 1){
					if (tab_div[elt].parentNode.offsetTop < previousButt){
						
						if ((tab_div[elt].parentNode.offsetLeft < previousEnd) && ((tab_div[elt].parentNode.offsetLeft+tab_div[elt].parentNode.offsetWidth) > previousLeft)) {
							
							//alert(block + " ZE\n" + tab_div[elt].id + ".offsetTop = " + tab_div[elt].parentNode.offsetTop + " previousButt = " + previousButt + "\n" + tab_div[elt].parentNode.id  + " must move to : " + (tab_div[elt].parentNode.offsetTop+previousButt-(tab_div[elt].parentNode.offsetTop)));
							//alert(block + " ZE\n" + tab_div[elt].id + ".offsetLeft = " + tab_div[elt].parentNode.offsetLeft + " previousEnd = " + previousEnd + "\n" + tab_div[elt].parentNode.id  + " must move by : " + (previousEnd-(tab_div[elt].parentNode.offsetLeft)));
							tab_div[elt].parentNode.style.top = String(tab_div[elt].parentNode.offsetTop + (previousButt-tab_div[elt].parentNode.offsetTop))+"px";
						}
						
					}
				}
				
				if(tab_div[elt].scrollHeight > tab_div[elt].parentNode.scrollHeight){ // only si la brique a 'gonflé'	
					if ((tab_div[elt].parentNode.offsetTop + tab_div[elt].scrollHeight) > previousButt){ // si le butt est plus bas que le précédent
			 			previousButt = tab_div[elt].parentNode.offsetTop + tab_div[elt].scrollHeight;
						//alert(block + " ZE\n" + tab_div[elt].id + "scrollHeight = " + tab_div[elt].scrollHeight + " /  parentNode.scrollHeight = " + tab_div[elt].parentNode.scrollHeight + " \npreviousButt = " + previousButt);
					}
					else{
						// previousButt inchangé
						
					}
					
					previousEnd = tab_div[elt].parentNode.offsetLeft + tab_div[elt].scrollWidth;
					previousLeft = tab_div[elt].parentNode.offsetLeft;
					//alert(block + " ZE\n" + tab_div[elt].id + "scrollWidth = " + tab_div[elt].scrollWidth + " /  parentNode.scrollWidth = " + tab_div[elt].parentNode.scrollWidth + " \npreviousEnd = " + previousEnd);
				}
				else{
					//
				}
				tab_div[elt].style.overflow="visible";
				previousIsZE = 1;
			}
			
			if(block=="divhachures"){
				tab_div[elt].style.display="none";
			
			}
		}
		
	}
	if(previousButt < 0){
		previousButt = 360;
	}
	// content est à l'intérieur de space
	if (eval(document.getElementById('content')) != null){ 
		document.getElementById('content').style.height = previousButt+"px";
		document.getElementById('content').style.width = "810px";
		//document.getElementById('content').style.border = "dashed";
		document.getElementById('content').style["overflow-x"] = "hidden";

	}
	if (eval(document.getElementById('space')) != null){ 
		document.getElementById('space').style.height = previousButt+"px";
		document.getElementById('space').style.width = "810x";
		//document.getElementById('space').style.border = "dotted";
		document.getElementById('space').style["overflow-x"] = "hidden";
		document.getElementById('space').style["overflow-y"] = "hidden";
		document.getElementById('space').style["overflow"] = "hidden";
		document.getElementById('space').style.overflow = "visible";
	}

	
	return true;
}

function showprops(obj, obj_name) {
  for (var i in obj)

    document.write (obj_name+"."+i+"="+obj[i]+"<BR>")

}
function alertprops(obj, obj_name) {
	tempStr = "";
  for (var i in obj){

   tempStr = tempStr + (obj_name+"."+i+"="+obj[i]+" - ")
   }
   alert(tempStr);

}

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
	windowHeight = window.innerHeight;		
	}
	else{	   
		if (document.documentElement && document.documentElement.clientHeight){
				windowHeight = document.documentElement.clientHeight;
		}
		else if(document.body && (document.body.clientHeight > 1)){
        	windowHeight = document.body.clientHeight;
        }	
	}
	return windowHeight;
}