var inverse = 0;
var listAffichee = 1;

function positionnelayer(val) {

	Efface_Position_On_Layer ();

	if (document.getElementById("left_ombre_sup")) {

		document.getElementById("menuhaut_li_" + val).className = "menuhaut_li menuhaut_li_" + val + "_on" ;

		if (document.getElementById("Menu" + val)) {
			
			obj_ombr_width	= document.getElementById("left_ombre_sup").offsetWidth;

			if (document.getElementById("menuhaut").parentNode.id == "lapartiedroite_home") {
				obj_left_width = document.getElementById("lapartiegauche_home").offsetWidth;
			} else if (document.getElementById("menuhaut").parentNode.id == "lapartiedroite_site") {
				obj_left_width = document.getElementById("lapartiegauche_site").offsetWidth;
			} else {
				obj_left_width = 0;
			}
			obj_left_menu	= document.getElementById("menuhaut_li_" + val).offsetLeft;
			obj_height_head = 0
			
			leftmenu		= document.getElementById("menuhaut").offsetLeft;

			obj_height_menu	= document.getElementById("menuhaut_li_" + val).offsetHeight;
			
			if (document.getElementById("header_content")) {
				obj_height_head	= document.getElementById("header_content").offsetHeight;
			}
			
			position_left	= obj_ombr_width + obj_left_width + obj_left_menu + leftmenu;
			position_height = obj_height_menu + obj_height_head + bottommenu;
			document.getElementById("SousMenu").innerHTML = document.getElementById("Menu" + val).innerHTML;
			
			document.getElementById("SousMenu").style.left = position_left + "px";
			document.getElementById("SousMenu").style.top =  position_height + "px";
			
		} else {
			
			document.getElementById("SousMenu").style.left = "-1000px";
			
		}
	}
}

function positionneslayer(obj,new_obj) {

	var obj_right 	= document.getElementById(obj).offsetLeft + document.getElementById(obj).offsetWidth;
	var obj_top 	= document.getElementById(obj).offsetTop;	
	
	checknode(document.getElementById(obj));
	
	positionleft = document.getElementById("SousMenu").style.left
	positionleft = positionleft.replace("px","");

	if (((parseInt(positionleft) + (2*parseInt(document.getElementById(obj).offsetWidth))) > screen.width) || (inverse == "1")) {
		document.getElementById(new_obj).style.left = (document.getElementById(obj).offsetLeft - document.getElementById(obj).offsetWidth) + "px";
		inverse = 1;
	 } else {
		document.getElementById(new_obj).style.left = obj_right + "px";
	}
	document.getElementById(new_obj).style.top = obj_top + "px";	
	document.getElementById(new_obj).style.display = "block";	
	document.getElementById(new_obj).style.position = "absolute";		
	
}

function montrelayercacher (id,css,obj) {

	if (document.getElementById(obj).style.display == "block") {
		document.getElementById(obj).style.display = "none";	
		document.getElementById(id).className = css + "_adeploier";			
	} else {
		document.getElementById(obj).style.display = "block";	
		document.getElementById(id).className = css + "_areploier";					
	}
	
}

function checknode(obj) {

	node = obj.parentNode;

	if (node.id != "SousMenu") {
		/*
		 * Dois remontre d'un cran car le premier est le div englobant
		 */
		node = obj.parentNode;
	}

	for (x=0;x<node.childNodes.length;x++)	{
						
		if (node.childNodes[x].tagName == "DIV") {						

			noeud_fils = node.childNodes[x];
						
			for (xx=0;xx<noeud_fils.childNodes.length;xx++)	{

				if (noeud_fils.childNodes[xx].tagName == "DIV") {			
					
					noeud_fils.childNodes[xx].style.display = "none";
					inverse = 0;
					
				}
	
			}

		}

	}
	
}

function DetectBrowser() {
	
	position = browsername.indexOf("Microsoft");
	
	if(position > -1) {
		browsernom ="Microsoft";
	} else {
		browsernom ="Autre";
	}
	AjusteMenu();
	
}

function CalculWindow() {
	if (document.getElementById("footer_table")) {
		if (document.getElementById("body").offsetHeight > document.documentElement.clientHeight) {
			document.getElementById("footer_table").style.position = "static";
		} else {
			document.getElementById("footer_table").style.position = "fixed";
		}
	}
}

/*function GotoUrl(theurl,arg) {
	if (arg == "l") {
		var array = theurl.split("_");
		if(array.length > 1){
			var target  = array[0];
			var newurl	= array[1];		
			window.open (newurl,target);		
		}else{
			window.open (array[0],"_blank");		
		}
	} else {
		if(arg == "c"){
			loadCategoryFromCatalogue(theurl);
		} else if(arg == "p"){
			loadPredefined(theurl);	
		} else if(arg == "v"){
			loadCollectionFromCatalogue(theurl);
		} else {
			loadCenterSite(theurl,arg);
			//document.location.href=theurl;
		}
	}
}*/

function GotoUrl(theurl){
	//alert(theurl);
	if(theurl.indexOf('/')!= 0){
		window.open (theurl,"_blank");
	}else{
		setTimeout("document.location.href='"+theurl+"'","0");		
	}
}

function loadCategoryFromCatalogue(theurl){
	var array = theurl.split("_");
	var target = array[0];
	if(target == ''){
		target = 'toc';
	}
	var filtre = array[1];
	var id = array[2];
	var color = array[3];
	
	var str = '&target='+target+'&filtre='+filtre+'&id='+id+'&color='+color;
	window.location.hash = theurl;	
	var xhr_object = null ;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

	xhr_object.onreadystatechange  = function(){ 
		if(xhr_object.readyState  == 4){
			if (xhr_object.status  == 200) {
				ret = xhr_object.responseText;
				document.getElementById('lapartiegauche').innerHTML = ret;
				//clearLineSelect();
			}
		}
	}

	xhr_object.open( "POST","./ajax/load_categorie.php", true ); 
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_object.send(str);
}


function loadCollectionFromCatalogue(theurl){
	var array = theurl.split("_");

	var target  = array[0];
	var filtre  = array[1];
	var id 		= array[2];
	var color 	= array[3];
	var cat_id 	= array[4];
		
	var str = '&target='+target+'&filtre='+filtre+'&collection_id='+id+'&color='+color+'&cat_id='+cat_id;
	window.location.hash = theurl;	
	var xhr_object = null ;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

	xhr_object.onreadystatechange  = function(){ 
		if(xhr_object.readyState  == 4){
			if (xhr_object.status  == 200) {
				ret = xhr_object.responseText;
				document.getElementById('lapartiegauche').innerHTML = ret;
				//clearLineSelect();
			}
		}
	}

	xhr_object.open( "POST","./ajax/load_collection.php", true ); 
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_object.send(str);
}

function loadPredefined(theurl){
	var array = theurl.split("_");

	var target  = array[0];
	var id 		= array[1];
		
	var str = '&target='+target+'&id='+id;
	window.location.hash = theurl;	
	var xhr_object = null ;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

	xhr_object.onreadystatechange  = function(){ 
		if(xhr_object.readyState  == 4){
			if (xhr_object.status  == 200) {
				ret = xhr_object.responseText;
				document.getElementById('lapartiegauche').innerHTML = ret;
				//clearLineSelect();
			}
		}
	}

	xhr_object.open( "POST","./ajax/load_predefined.php", true ); 
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_object.send(str);
}

function loadCenterSite(theurl,arg){
	var str = '&theurl='+theurl+"&arg="+arg;
	window.location.hash = theurl;	
	var xhr_object = null ;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

	xhr_object.onreadystatechange  = function(){ 
		if(xhr_object.readyState  == 4){
			if (xhr_object.status  == 200) {
				ret = xhr_object.responseText;
				var arrayRet = ret.split("###");
				//document.getElementById('lapartiegauche').innerHTML = arrayRet[0];
				//document.getElementById('lapartiedroite').innerHTML = arrayRet[1];
				document.getElementById('lapartiegauche').innerHTML = arrayRet[1];
				document.getElementById('lapartiedroite').innerHTML = arrayRet[2];
				setTimeout("executeJavascript('"+arrayRet[0]+"')",0500);	
				//setTimeout("executeJavascript('')",0500);			
			}
		}
	}

	xhr_object.open( "POST","./ajax/load_centersite.php", true ); 
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_object.send(str);
}

function executeJavascript(methodes){
	if(methodes != ""){
		var array = methodes.split("]]]");
		for(i=0 ; i<array.length ; i++){
			var methode = array[i];
			eval(methode);
		}
	}
	//eval(jsToLoadBookshelf());	
}

function showList(list){
	if(listAffichee != 0){
		document.getElementById('livre_list_'+listAffichee).style.display = 'none';		
	}	
	document.getElementById('livre_list_'+list).style.display = 'block';
	listAffichee = list;	
}

function clearLineSelect(){
	if(!document.getElementById('line_select_2')){
		document.getElementById('line_select_1').style.display = 'none';
	}else{
		var i = 1;
		while(document.getElementById('line_select_'+i)){
			i++;
		}
		if(i > 10){
			var j = 1;
			while(document.getElementById('line_select_'+j)){
				var jstring = "line_select_"+j;
				if(j <= 5 || j >= i-5){
					document.getElementById(jstring).style.display = 'block';
				}else{
					document.getElementById(jstring).style.display = 'none';
				}
				j++;
			}
		}
	}
}

function setSessionVar(name,value,key){
	//On appelle un ajax qui va placer la variable de session.
	//Ensuite, on relance la page sur laquelle on se trouve ou la page redirect.
	var str = '&name='+name+"&value="+value+"&key="+key;
	var xhr_object = null ;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

	xhr_object.onreadystatechange  = function(){ 
		if(xhr_object.readyState  == 4){
			if (xhr_object.status  == 200) {
				ret = xhr_object.responseText;
				var href = document.location.href;
				document.location.href = href;
			}
		}
	}

	xhr_object.open( "POST","./ajax/setSessionVar.php", true ); 
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_object.send(str);
}

function setSessionVarCata(name,value,key,redirect){
	//On appelle un ajax qui va placer la variable de session.
	//Ensuite, on relance la page sur laquelle on se trouve ou la page redirect.
	var str = '&name='+name+"&value="+value+"&key="+key;
	var xhr_object = null ;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

	xhr_object.onreadystatechange  = function(){ 
		if(xhr_object.readyState  == 4){
			if (xhr_object.status  == 200) {
				GotoUrl(redirect);
			}
		}
	}

	xhr_object.open( "POST","./ajax/setSessionVar.php", true ); 
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_object.send(str);
}

function setSessionVarValue(name,value,redirect){
	//On appelle un ajax qui va placer la variable de session.
	//Ensuite, on relance la page sur laquelle on se trouve ou la page redirect.
	var str = '&name='+name+"&value="+value+"&key=0";
	var xhr_object = null ;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

	xhr_object.onreadystatechange  = function(){ 
		if(xhr_object.readyState  == 4){
			if (xhr_object.status  == 200) {
				GotoUrl(redirect);
			}
		}
	}

	xhr_object.open( "POST","./ajax/setSessionVar.php", true ); 
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_object.send(str);
}

function setSessionVarNewsletter(name,redirect){
	//On appelle un ajax qui va placer la variable de session.
	var str = '&name='+name+"&value="+document.getElementById(name).value+"&key=0";
	var xhr_object = null ;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

	xhr_object.onreadystatechange  = function(){ 
		if(xhr_object.readyState  == 4){
			if (xhr_object.status  == 200) {
				ret = xhr_object.responseText;
				//alert(ret);
				GotoUrl(redirect);
			}
		}
	}

	xhr_object.open( "POST","./ajax/setSessionVar.php", true ); 
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_object.send(str);
}

function setSessionVarSearch(name,field,redirect){
	//On appelle un ajax qui va placer la variable de session.
	var str = '&name='+name+"&value="+document.getElementById(field).value+"&key=0";
	var xhr_object = null ;
	if(window.XMLHttpRequest) // FIREFOX
		xhr_object = new XMLHttpRequest();
	else if(window.ActiveXObject) // IE
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP");
	else
		return(false);

	xhr_object.onreadystatechange  = function(){ 
		if(xhr_object.readyState  == 4){
			if (xhr_object.status  == 200) {
				ret = xhr_object.responseText;
				//alert(ret);
				GotoUrl(redirect);
			}
		}
	}

	xhr_object.open( "POST","./ajax/setSessionVar.php", true ); 
	xhr_object.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xhr_object.send(str);
}