//Translate Netscape Event fonction type to IE type
if(!window.event && window.captureEvents) {
  // set up event capturing for mouse events (add or subtract as desired)
  window.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT|Event.CLICK|Event.DBLCLICK);
  // set window event handlers (add or subtract as desired)
  window.onmouseover = WM_getCursorHandler;
  window.onmouseout = WM_getCursorHandler;
  window.onclick = WM_getCursorHandler;
  window.ondblclick = WM_getCursorHandler;
  // create an object to store the event properties 
  window.event = new Object;
}


function WM_getCursorHandler(e) {
  // set event properties to global vars (add or subtract as desired)
  window.event.clientX = e.pageX;
  window.event.clientY = e.pageY;
  window.event.x = e.layerX;
  window.event.y = e.layerY;
  window.event.screenX = e.screenX;
  window.event.screenY = e.screenY;
  // route the event back to the intended function
  if ( routeEvent(e) == false ) {
    return false;
  } else {
    return true;
  }
}
//END translation of event Netscape type

var ns4=document.layers;
var ns6=document.getElementById&&!document.all;
var ie4=document.all;

function GetObjectById(val){
	var obj;
	if(ns4)
		obj= "document." + val;
	else if(ns6){
		obj= "document.getElementById('" + val + "')";}
	else if(ie4)
		obj= "document.all."+ val;
	return obj;
}

if(ns4)
	subDiv= document.divSubMenu;
else if(ns6)
	subDiv= document.getElementById("divSubMenu");
else if(ie4)
	subDiv= document.all.divSubMenu;

//Add new directory here, also used to recognize Top Menu Instances
var dir= new Array(3);
dir[0]= "renovation";
dir[1]= "energie";
dir[2]= "patrimoine";
dir[3]= "education";

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~  CLASS AND EVENTS
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//public Attributes (to keep the current menuItem over when other onmouseover)
var currentTopMenuItem;
var overTopMenuItem;

//********************************
// Top Menu
//currentMenuDir is the directory of the div that is currently onmouseover
//the mouseover div is then avoid in the reset image process
function HideTopMenu(currentMenuDir){
	//alert(currentMenuDir);
	for(i=0; i<dir.length;i++){
		if(dir[i]!=currentMenuDir){ 
			eval("menu_" + dir[i] + ".InitTopMenuItem(false)");
		}
	}
}

//Set the appropriate topmenuitem to the mouseover style if page is reloaded


//Constructor
function TopMenuItemClass(objDiv, dir, aHref, aText, showSubMenu, aCssClass, divCssClass, srcImgArray){
	this.objDiv= objDiv;
	this.dir= dir;
	this.divCssClass= divCssClass;
	this.aCssClass=aCssClass;
	this.aHref= aHref;
	this.aText= aText;
	this.showSubMenu=showSubMenu;
	this.srcImgArray= srcImgArray;
	this.imgId= "img"+ dir;
	this.isMouseOver;
	this.isSubMenuOver;
	//Functions
	this.InitTopMenuItem= SetTopMenuItem;
	this.GetTopMenuItem= TopMenuItem;
	this.SetMouseOver= MouseOver;
}

function SetTopMenuItem(SetImgToOn){
	this.objDiv.innerHTML= this.GetTopMenuItem(SetImgToOn);
	this.SetMouseOver(false);
}

//Function that set the menuItem to mouseover style
function MouseOver(isOn){
	if(isOn){
		overTopMenuItem= eval("menu_" + this.dir);
		this.MouseOver=true;
		HideTopMenu(this.dir);
		if(this.showSubMenu) ShowSubMenu(this.dir);
		if(this.srcImgArray!= null && this.srcImgArray[1]!=null) {eval(GetObjectById(this.imgId)).src= this.srcImgArray[1];}
		if(this.divCssClass!=null) this.objDiv.className= this.divCssClass;
	}
}

function TopMenuItem(SetImgToOn){
	var aTag="";
	var imgTag="";
	var imgOn=""; //string used in the onmouseover to swap the image with position ON
	var mouseOver="";
	this.objDiv.className= ""; //cancel the assignment of the cssClass
	
	//if an off image is set 
	if(this.srcImgArray!=null){
		if(this.srcImgArray[0]!=null){
			imgTag= "<img id=\"" + this.imgId + "\" align=\"middle\" src=\""+ this.srcImgArray[0] + "\">";
		}
		
		//if an on image is set
		if(this.srcImgArray[1]!=null){
			imgOn= GetObjectById(this.imgId)+ ".src='" + this.srcImgArray[1] + "'";
		}
	}
	if(this.aHref=="#"){
		aTag="<font class=\""+ this.aCssClass+ "\">" + imgTag + this.aText + "</font>";
	}else if(!this.showSubMenu){ //Set: onmouseover=\"HideSubMenu();\" to disable menu hiding on mouseover
		aTag= "<a href=\""+ this.aHref + "\" onmouseover=\"\" class=\""+ this.aCssClass + 
			"\">"+ imgTag + this.aText + "</a>";
	}else{//this line if the mouseover event must show the sub menu: set: SetMouseOver(true)
		aTag= "<a href=\""+ this.aHref + "\" onmouseover=\"menu_"+ this.dir + ".SetMouseOver(false)\" onmouseout=\"HideCurrentMenu();\" class=\""+ this.aCssClass + 
			"\">"+ imgTag + this.aText + "</a>";
		//If the mouse over mus not show the sub menu (the click event will instead) 
		//aTag= "<a href=\""+ this.aHref + "\" class=\""+ this.aCssClass + "\">"+ imgTag + this.aText + "</a>";
	}
	return aTag ;
}


function HideCurrentMenu(){
	//alert(overTopMenuItem.aHref);
	if(currentTopMenuItem!=null && currentTopMenuItem != overTopMenuItem){
		setTimeout("ResetMenu()", 1000);
	}
}

function ResetMenu(){
	//If the mouse is not over a menu
	if(overSubMenuItem.IsMouseOver== false){
		HideTopMenu(null);
		HideSubMenu();
		currentTopMenuItem.SetMouseOver(true); //reset the appropriate menu corresponding to the url
	}
}


//********************************
// Handles SubMenu Event
function ShowSubMenu(dir){
	overSubMenuItem = eval("subMenu_" + dir);
	subDiv.innerHTML= overSubMenuItem.GetSubMenu();
	
	//Fade function for windows
	var os= navigator.userAgent.toLowerCase();
	if (os.indexOf("mac")==-1){
		//shiftOpacity("divSubMenu", 1000);
	}
}

function HideSubMenu(){
	subDiv.innerHTML="";
	subDiv.className="";
}

//*********************
//  SUB MENU CLASS
//,,,,,,,,,,,,,,,,,,,,,

//Constructor
function SubMenuClass(dir, divCssClass, linkCssClass, activeMenuCssClass){
	//the directory of the location
	this.dir= dir;
	this.divCssClass= divCssClass;
	this.linkCssClass= linkCssClass;
	this.activeMenu= activeMenuCssClass;
	this.IsMouseOver=false;
	
	//Store the textLink and the url in array
	this.text= new Array(7);
	this.href= new Array(7);
	
	//Function that enables to add link to the menu
	this.NewMenuItem= MenuItemClass;
	
	//Return a html string to fill the div.innerHTML
	this.GetSubMenu= GetSubMenu;
}

function MenuItemClass(text, href){
	for(i=0; i<this.text.length; i++){
		if(this.text[i]==null){
			this.text[i]= text;
			this.href[i]= href;
			break;
		}
	}
}

function GetSubMenu(){
	subDiv.className= this.divCssClass;
	var result;
	result= "<TABLE STYLE=\"border:solid 0px black\" width=\"\" onmouseout=\"overSubMenuItem.IsMouseOver= false;HideCurrentMenu();\" onmouseover=\"overSubMenuItem.IsMouseOver= true;\" CELLSPACING=\"0\" CELLPADDING=\"0\"><tr>";
	for (i=0; i< this.text.length; i++){
		if (this.text[i]!=null){
			var tag="";
			//if the location url is the same as the current href 
			//display a div in step of a href link
			if(location.href.indexOf(this.href[i])!=-1){
				tag="<div style=\"font-size:11px\" class=\""+ this.activeMenu +"\" >" + this.text[i] + "</div>";
			}else{
				tag= "<a href=\"" + this.href[i] + "\" class=\"" + this.linkCssClass +
					"\">" + this.text[i] + "</a>"
			}
			result+= "<td width=\"\" style=\"padding-right:15px;border:solid 0px black;\" align=\"left\">"+ tag +"</td>";
		}else break;
	}
	result+= "</tr></table>";
	return result;
}

//*********************
//  END MENU CLASS
//,,,,,,,,,,,,,,,,,,,,,

InitTopMenu(); //INITIALIZE THE VARIABLE IN THE JS PAGE MENU_NL.js

//********************************
// INITIALIZE TopMenu and SubMenu according to the url when the page is load
//   (After instantiation of SubMenu Classes load the approprite menu
//   according to the directory path)		
for(i=0; i<dir.length; i++){
	//If the url contain the dir param, then shows call then ShowSubMenu 
	//to display the right menu
	if(document.location.href.indexOf("/"+dir[i]+"/")!=-1){
		//
		
		currentTopMenuItem= eval("menu_"+ dir[i]);
		currentTopMenuItem.SetMouseOver(true);
		//alert(currentTopMenuItem.);
	}
}
//*********************
//  FADING EFFECT
//,,,,,,,,,,,,,,,,,,,,,

function opacity(id, opacStart, opacEnd, millisec) { 
	//speed for each frame 
	var speed = Math.round(millisec / 100); 
	var timer = 0; 

	//determine the direction for the blending, if start and end are the same nothing happens 
	if(opacStart > opacEnd) { 
		for(i = opacStart; i >= opacEnd; i--) { 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} else if(opacStart < opacEnd) { 
		for(i = opacStart; i <= opacEnd; i++) 
			{ 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} 
}
function shiftOpacity(id, millisec) { 
	//if an element is invisible, make it visible, else make it ivisible 
		opacity(id, 0, 100, millisec); 
}

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100); 
	object.MozOpacity = (opacity / 100); 
	object.KhtmlOpacity = (opacity / 100); 
	object.filter = "alpha(opacity=" + opacity + ")"; 
} 


//*********************
//  END FADING EFFECT
//,,,,,,,,,,,,,,,,,,,,,
	
function EmptyTxtBox(txt){
	if (txt.value=="Rechercher" || txt.value=="Zoeken" || txt.value=="Search"){
			txt.value="";
	}
}
function FillTxtBox(txt, value){
	if (txt.value=="")
		txt.value= value;
}

function SendForm(form){
	objForm= eval(GetObjectById(form));
	objForm.submit();
	return false;
}

function GoPrevious(server){
	prevLink=document.referrer;
	if(prevLink.indexOf("#")!=-1)prevLink= prevLink.substr(0, prevLink.indexOf("#")) ; 
	//alert(prevLink.indexOf(server));
	if(prevLink.indexOf(server)!=-1){
		window.history.back();
	}
}

function PrintPage(pageLink){
	if(pageLink.indexOf("#")!=-1)pageLink= pageLink.substr(0, pageLink.indexOf("#"));
	

	var qStr="?print=true";
	if(pageLink.indexOf("?")!=-1){qStr="&print=true";}
	
	
//// 	ua = navigator.userAgent.toLowerCase(); 
//// 	if (ua.indexOf("safari")!=-1) {
//// 		//pageLink="http://www.curbain.be/admin/processFiles.php?printMac="+ pageLink;
//// 		window.print();
//// 	}else
		window.open(pageLink + qStr,'Print','toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes, width=600, height=360');
}


//////////////////////
/// CLASS DES DIVS ///
//////////////////////

function ChangeLang(lang){
	var url= document.location.href;
	var arrUrl= url.split("/");
	var length= arrUrl.length;
	var newUrl="";
	
	for(i=0; i<length; i++){
		if(arrUrl[i]=="fr"||arrUrl[i]=="nl"||arrUrl[i]=="en"){
			newUrl+= lang+"/";
		}else{
			if(i== length-1){
				newUrl+= arrUrl[i];
			}else{
				newUrl+= arrUrl[i]+"/";
			}
		}
	}
	document.location.href= newUrl;
}

function ShowSubscribe(){
 	//aSubscribe is used in case there is a A tag with a + in the value text that have to be change in -
 	var divSubscribe= document.getElementById("divSubscribe");
 	//var aSubscribe= document.getElementById("aSubscribe");
 	//Get the X and Y position of the txtbox to ajust the position of the date window
 	if(divSubscribe.style.display=="block"){
 		divSubscribe.style.display="none";
 		//aSubscribe.innerHTML= "+" + aSubscribe.innerHTML.substr(1);
 	}else{
 		divSubscribe.style.display="block";
 		divSubscribe.style.left= "100px";
 		divSubscribe.style.top= "314px"; //eval("\""+(window.event.y-80)+"px\"");
 		//aSubscribe.innerHTML= "-" + aSubscribe.innerHTML.substr(1);
 		divSubscribe.style.position= "absolute";
 		divSubscribe.style.zIndex=100;
 	}
}
 
///////Suprimez pour cause de spam///////
//// function ShowSendFriend(){
//// 	var divSendFriend= document.getElementById("divSendFriend");
//// 	//var aSendFriend= document.getElementById("aSendFriend");
//// 	//Get the X and Y position of the txtbox to ajust the position of the date window
//// 	if(divSendFriend.style.display=="block"){
//// 		divSendFriend.style.display="none";
//// 		//aSendFriend.innerHTML= "+" + aSendFriend.innerHTML.substr(1);
//// 	}else{
//// 		divSendFriend.style.display="block";
//// 		divSendFriend.style.left= "300px";
//// 		divSendFriend.style.top= "155px";
//// 		//aSendFriend.innerHTML= "-" + aSendFriend.innerHTML.substr(1);
//// 		divSendFriend.style.position= "absolute";
//// 		divSendFriend.style.zIndex=100;
//// 	}
//// }
//// 

function ShowLinks(elem, TypeId){
	window.open("link.php?id=" + TypeId + "&ctrl=" + elem.id ,'link','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=300,top='+(window.event.screenY+15)+'px,left= '+ (window.event.screenX-300)+',height=400'); 
}

// CROSS BROSER WINDOW POSITION
function GetWindowHeight(){
	var windowHeight="";
	if(document.documentElement.offsetHeight){
		windowHeight=document.documentElement.offsetHeight;
	}else if(self.innerHeight!=null){
		windowHeight=self.innerHeight;
	}
	return windowHeight;
}

//GET THE HEIGHT OF THE WINDOW
var y;
if(ie4){
	y=document.documentElement.offsetHeight;
}else{
	y=self.innerHeight;
}
