var LAYER__Open=false;
var TIME_OUT_MENU=false;
var CURRENT_RUB=false;
var MOUSE_OVER_MENU=false;
var TIME_OUT_MENU_NOT_OVER=false;
var POS_LAYER_LEFT=0;
var POS_LAYER_TOP=0;
var LOCKED_MENU=false;

//dlib_debug();

function initMenu(/*strMenuName,lockMenu*/){
	strMenuName=(typeof arguments[0]!="undefined")?arguments[0]:"";
	lockMenu=(typeof arguments[1]!="undefined")?arguments[1]:"";
	dlib_anchors("posLayers");
	setTimeout("launchScriptMenu('"+strMenuName+"','"+lockMenu+"')",2);
}

function launchScriptMenu(/*strMenuName,lockMenu*/){
	strMenuName=(typeof arguments[0]!="undefined")?arguments[0]:"";
	lockMenu=(typeof arguments[1]!="undefined")?arguments[1]:"";
	POS_LAYER_LEFT=dlib_anchors("posLayers", LEFT);
	POS_LAYER_TOP=dlib_anchors("posLayers", TOP);
	layerMenuPosition("Particulier");
	layerMenuPosition("Pro");
	layerMenuPosition("Entreprise");
	layerMenuPosition("ToutSurLCL",138);
	if(strMenuName!="") {
		if (lockMenu==false) {
			LOCKED_MENU=strMenuName;
		}
		openMenu(strMenuName);
	}
}

function layerMenuPosition(strMenuName /*, offsetMenu*/){
	offsetMenu=(typeof arguments[1]!="undefined")?arguments[1]:"";
	LAYER_WIDTH=dlib_layers(strMenuName, WIDTH);
	LAYER_LEFT=parseInt(POS_LAYER_LEFT-(LAYER_WIDTH/2));
	if (offsetMenu!="") LAYER_LEFT=LAYER_LEFT+offsetMenu;
	dlib_layers(strMenuName, LEFT, LAYER_LEFT);
	dlib_layers(strMenuName, TOP, POS_LAYER_TOP);
}

function openMenu(strMenuName){
	//alert("open menu " + strMenuName);
	if(LAYER__Open){
		//alert("calling dlib_layers(" + LAYER__Open + ", VISIBLE, false)");
		dlib_layers(LAYER__Open, VISIBLE, false);
		dlib_images("img"+LAYER__Open, ROLLOVER, false);

		if(!LOCKED_MENU || LOCKED_MENU!=LAYER__Open){
			dlib_layers(LAYER__Open, RELEASE_EVENT, [MOUSE_OUT, "timeOutMenu"]);
			dlib_layers(LAYER__Open, RELEASE_EVENT, [MOUSE_OVER, "clearTimeOutMenu"]);
		}

		if(TIME_OUT_MENU) clearTimeout(TIME_OUT_MENU);
		if(TIME_OUT_MENU_NOT_OVER) clearTimeout(TIME_OUT_MENU_NOT_OVER);
	}
	//alert("calling dlib_layers(" + strMenuName + ", VISIBLE, true)");
	dlib_layers(strMenuName, VISIBLE, true);
	dlib_images("img"+strMenuName, ROLLOVER, true);

	switchMenuImage(strMenuName);

	if(!LOCKED_MENU || LOCKED_MENU!=strMenuName){
		//alert("calling dlib_layers(" + strMenuName + ", CAPTURE_EVENT, [MOUSE_OUT, 'timeOutMenu'])");
		dlib_layers(strMenuName, CAPTURE_EVENT, [MOUSE_OUT, "timeOutMenu"]);
		dlib_layers(strMenuName, CAPTURE_EVENT, [MOUSE_OVER, "clearTimeOutMenu"]);
	}

	LAYER__Open=strMenuName;
}

function switchMenuImage(strMenuName) {
	var imgMenuBar = 'url(/img/bg_nav_top_general_gen.gif)';
	if (strMenuName=="Particulier") {
		imgMenuBar = 'url(/img/bg_nav_top_general_par.gif)';
	} else if (strMenuName=="Pro") {
		imgMenuBar = 'url(/img/bg_nav_top_general_pro.gif)';
	} else if (strMenuName=="Entreprise") {
		imgMenuBar = 'url(/img/bg_nav_top_general_cle.gif)';
	}
	document.getElementById("menuBar").style.backgroundImage=imgMenuBar;
}

function checkMenuMouseOut(strMenuName){
	if(TIME_OUT_MENU_NOT_OVER) clearTimeout(TIME_OUT_MENU_NOT_OVER);
	if(LAYER__Open) {
		TIME_OUT_MENU_NOT_OVER=setTimeout("sub_checkMenuMouseOut('"+strMenuName+"')", 1000);
	}
	//remiseMenu();
	timeOutMenu(strMenuName);
}

function sub_checkMenuMouseOut(strMenuName){
	if(TIME_OUT_MENU_NOT_OVER) clearTimeout(TIME_OUT_MENU_NOT_OVER);
	if(!MOUSE_OVER_MENU){
		TIME_OUT_MENU_NOT_OVER=setTimeout("hideMenu('"+strMenuName+"')", 1000);
	}
}

function clearTimeOutMenu(){
	if(TIME_OUT_MENU) clearTimeout(TIME_OUT_MENU);
	if(TIME_OUT_MENU_NOT_OVER) clearTimeout(TIME_OUT_MENU_NOT_OVER);
	MOUSE_OVER_MENU=true;
}

function clearMouseOutMenuTimeout(strMenuName /*, lockMenu */){
	lockMenu=(typeof arguments[1]!="undefined")?arguments[1]:"";
	if(strMenuName==LAYER__Open){
		MOUSE_OVER_MENU=false;
		if(TIME_OUT_MENU) clearTimeout(TIME_OUT_MENU);
		if(TIME_OUT_MENU_NOT_OVER) clearTimeout(TIME_OUT_MENU_NOT_OVER);
	}
	// Ajout AHA 12/2007
	initMenu(strMenuName, lockMenu);
	//LOCKED_MENU=false;
}

function timeOutMenu(strMenuName){
	TIME_OUT_MENU=setTimeout("hideMenu('"+strMenuName+"')", 1000);
	MOUSE_OVER_MENU=false;
}

function hideMenu(strMenuName){
	if(LOCKED_MENU){
		if(LOCKED_MENU!=strMenuName) openMenu(LOCKED_MENU);
	}
	else if(strMenuName==LAYER__Open){
		if(TIME_OUT_MENU) clearTimeout(TIME_OUT_MENU);
		if(TIME_OUT_MENU_NOT_OVER) clearTimeout(TIME_OUT_MENU_NOT_OVER);

		dlib_layers(strMenuName, VISIBLE, false);
		dlib_images("img"+strMenuName, ROLLOVER, false);
		dlib_layers(strMenuName, RELEASE_EVENT, [MOUSE_OUT, "timeOutMenu"]);
		dlib_layers(strMenuName, RELEASE_EVENT, [MOUSE_OVER, "clearTimeOutMenu"]);

		LAYER__Open=false;
		MOUSE_OVER_MENU=false;
	}
}


function rollOver(imgName){
	ImgSrc=document.images[imgName].src;
	document.images[imgName].src=(ImgSrc.indexOf("_off.")!=-1)?ImgSrc.replace(/_off./gi,"_on."):ImgSrc.replace(/_on./gi,"_off.");
}


function twAller(_url,_target) {
	window.open(_url,_target);
}

var timeId;
_form=null;
_cible=null;

function go2Timer(_this,_latarget)
{
   clearTimeout(timeId);
  _form=_this;
  _cible=_latarget;
  timeId = setTimeout("gotoUrl()",500);
}
function gotoUrl()
{
  if(_form.options[_form.selectedIndex].value!=0)
  {
	  var go2selec=_form.options[_form.selectedIndex].value;
	  var lacible='_blank';

	  if(_cible!=null)
	  {
		lacible=_cible;
	  }
	  else
	  {
		lacible=(go2selec.indexOf('http')!=-1)?'_blank':'_self';
	  }
	  window.open(_form.options[_form.selectedIndex].value, lacible);
  }
}
