/* Date de création: 09/04/2008 */
//|----
var isOverElm = null;
var TimeoutID = null;
var isIE		= ((window.ActiveXObject)? true : false);//

function showRegInfo(oThis){
	isOverElm=1;
	document.getElementById("myspacetext").style.display = 'block';
	oThis.onmouseout = function () {
		isOverElm=null;
		TimeoutID = setTimeout("displayNone('myspacetext')", 750);
	}
}

function getFocus(oThis) {
	isOverElm=1;
	oThis.onmouseout = function () {
		isOverElm = null;
		TimeoutID = setTimeout("displayNone('myspacetext')", 750);
	}
}

function displayNone(id){
	if (isOverElm==null) {
		isOverElm = null;
		document.getElementById("myspacetext").style.display = 'none';
	}
}
//|---------------------------| operations sur page, navmenu selection
var axeMenuOn = null;
var opWork = {

	free :function(){
		document.getElementById("innercontainer").style.visibility = 'visible';
		document.getElementById("halo").style.display = 'block';

	},
	select : function(num){
		var groupNav = document.getElementById("navmenu").getElementsByTagName("a");
		var reg	= new RegExp(" on", "g");
	
		for(var i=0; i<groupNav.length; i++){
			var oldClassName  = groupNav[i].className;
			groupNav[i].className = oldClassName.replace(reg,"");
		}
		var oldClassName  = groupNav[num-1].className;
		groupNav[num-1].className = oldClassName+" on";
	},
	show : function(who){
		axeMenuOn = who;
//		document.getElementById('subnavmenu').style.zIndex = "10";
		document.getElementById(who).style.top = "0px";
		// JML : class for opened menu
		//document.getElementById(who).className += " _topmenuslide_down_locked";
		document.getElementById(who).className += " _topmenuslide_down_locked";

	}
}

//|---------------------------| topmenu slider
function topMenuSlide(idDiv){
	var set = new Array;
	var topElements= document.getElementById(idDiv).getElementsByTagName('a');
	var subnavmenu	= document.getElementById("subnavmenu");
	var traildiv	= document.getElementById("trail");
	var trailDisplay = ((isIE)? traildiv.currentStyle.display : getComputedStyle(traildiv, null).display);
	var selectTags	= document.getElementsByTagName("select");

	this.menu = function (i){
		this.timer = null;
		this.cleanOne = null;
		this.mouseOnIt = null;
		var subElmt = document.getElementById("submenuaxe"+(i+1));
		if (subElmt!=undefined) {
			var savedPos = parseFloat((isIE)? subElmt.currentStyle.top : getComputedStyle(subElmt, null).top);
			topElements[i].parentNode.onmouseover = function(){
				if (isIE) hideSelect();
				traildiv.style.display = 'none';
				subnavmenu.style.zIndex="1500";

				clearOthers(i,0);
				if (axeMenuOn!="submenuaxe"+(i+1)) {
					set[i].mouseOnIt = 1;
					getDown();
					if (subElmt.id!=axeMenuOn){
						subElmt.onmouseover = function(){
							clearTimeout(set[i].cleanOne);
							set[i].mouseOnIt = 1;
						}
						subElmt.onmouseout = function(){
							set[i].mouseOnIt = null;
							clearOne(i);
						}
					}
				}
			}
			topElements[i].parentNode.onmouseout = function(){
				set[i].mouseOnIt = null;
				clearOne(i);
			}
		}
		function clearOne(){
			clearTimeout(set[i].cleanOne);
			set[i].cleanOne  = setTimeout("clean("+i+")", 750);
			this.clean = function () {
				if (set[i].mouseOnIt==null) {
					var subElmt2 = document.getElementById("submenuaxe"+(i+1));
					getUp();
				}
			}
		}
		function clearOthers(a,call){
			for(var z=0;z<topElements.length;z++){
				if ((z!=a) && axeMenuOn!="submenuaxe"+(z+1)) {
		 			var subElmt2 = document.getElementById("submenuaxe"+(z+1));
					if (subElmt2!=undefined) {
						clearInterval(set[z].timer);
						subElmt2.style.top = "-409px";
					}
				}
			}
		}
		function getDown(){
			clearInterval(set[i].timer);
			set[i].timer = setInterval( 'goindown()', 30);
			subElmt.style.zIndex = "1000";
			this.goindown = function(){
				var actualTop = parseFloat((isIE)? subElmt.currentStyle.top : getComputedStyle(subElmt, null).top);
				var dx =  (0 - actualTop);
				var doMath = Math.ceil(actualTop+(0.2*dx));
				if (actualTop<0) {
					subElmt.style.top = doMath+"px";
				} else {
					clearInterval(set[i].timer);
					subElmt.style.zIndex = "1000";
					subnavmenu.style.zIndex="105";
					 // jml : needed for scrollbar
					//if(subElmt.className.indexOf("_topmenuslide_down")==-1) subElmt.className+= " _topmenuslide_down";
					var over=document.getElementById(subElmt.id+'_over')
					if(over){
						over.style.overflowY="visible";
					}
					// integration des scrollbars JS
					if(window.jmlScrollbar!=undefined){
						window.jmlScrollbar.refresh();
					}
					
				}
			}
		}
		function getUp(){
			clearInterval(set[i].timer);
			set[i].timer = setInterval( 'goinUp()', 30);
//			subElmt.className = subElmt.className.replace(" _topmenuslide_down",""); // jml : needed for scrollbar
			var over=document.getElementById(subElmt.id+'_over')
			if(over){
				over.style.overflowY="hidden";
			}
			
			this.goinUp = function(){
				var actualTop = parseFloat((isIE)? subElmt.currentStyle.top : getComputedStyle(subElmt, null).top);
				var dx =  (savedPos - actualTop);
				var doMath = Math.floor(actualTop+(0.2*dx));
				if (actualTop>savedPos) {
					subElmt.style.top = doMath+"px";
				} else {
					checkForOpenMenu();
					clearInterval(set[i].timer);
				}
			}
		}
		function hideSelect() {
		for (var i=0; i< selectTags.length; i++) {
				selectTags[i].style.visibility = 'hidden';
			}
		}
		function showSelect(){
			for (var i=0; i< selectTags.length; i++) {
				selectTags[i].style.visibility = '';
			}
		}

		function checkForOpenMenu(){
			var noZindexRetrun=0;
			for(var z=0;z<topElements.length;z++){
	 			var subElmt2 = document.getElementById("submenuaxe"+(z+1));
				if (subElmt2!=undefined) {
					if ( (parseFloat(subElmt2.style.top)==0) || (set[z].mouseOnIt==1)) {
						noZindexRetrun++;
					}
				}
			}
			if ((noZindexRetrun==0)) {
				subnavmenu.style.zIndex="0";
					traildiv.style.display = trailDisplay;
					if (isIE) showSelect()
			}
		}
	}
	
	for (var i=0;i<topElements.length;i++) {
		set[i] = new this.menu(i);
	}

}

//|---------------------------| quick search
function qsearch(oThis){
//	var savedvalue = oThis.value;
	if (oThis.value==oThis.title) oThis.value = "";
	oThis.onblur = function (){
		if (this.value=='')
			this.value = this.title;
	}
}
//|---------------------------| menu slide
function menuSlide(idDiv){
//window.alert('menuSlide : '+idDiv);

	var subPanier = new Array();
	var panierHeight = new Array();
	var divPush = new Array();
	var divPushOffset = new Array();
	var saveOriginalPos;

	this.iObj = function (oThis, num){ //oThis = objet parent (cet objet)

		this.timer = null;
		function getPadding(elm){
			var padTop = parseFloat((isIE)? elm.currentStyle.paddingTop : getComputedStyle(elm, null).paddingTop);
			var padBot = parseFloat((isIE)? elm.currentStyle.paddingBottom : getComputedStyle(elm, null).paddingBottom);
			return(padTop+padBot);
		}
		this.glob =  oThis;
		this.obj = oThis.frm[num]; // obj = <li> considéré.
		this.subLevelA	= this.obj.getElementsByTagName("a");
//window.alert('this.iObj->this.obj : '+this.obj.tagName+'['+this.subLevelA[0].innerHTML+'] : '+num);
		var subLevelALength = this.subLevelA.length;

		if (this.subLevelA.length > 1) {

			this.subLevelA[0].onclick = function(){

				//this.removeAttribute('href');// suppression du href des <A>
				var classNameState = oThis.frm[num].className;

				if (classNameState == "on") {
//					closeAllBlocs();
				} else {
					var Sparents=Array();
//					window.alert('xxx : '+this.tagName+' : '+this.getAttribute('parent_items'));
//					return false;
					if(this.getAttribute('parent_items').length){Sparents=this.getAttribute('parent_items').split(" ");}
					var t=1;
					closeAllBlocs(Sparents);
					openOneBlock( num);
				}
				return false;
			}
		}
	}

	/******/
	function openOneBlock(num){
		var timeoutVarOpen;
		var sObj = subPanier[num].obj;
		sObj.className = "on";

		// check parents
		if(sObj.parentNode.parentNode.tagname=="LI"){
			sObj.parentNode.parentNode.className = "on";
		}

		var subs=sObj.getElementsByTagName('ul');
		//window.alert(subs.length);
		if(subs.length){
			for(var z=0;z<subs.length;z++){
				subs[z].style.display="block";
			}
		}


		var thisClsName = sObj.className;
		var goingToHeight = panierHeight[num];

		sObj.style.overflow = "hidden";
		var actualPadding = parseFloat((isIE)? sObj.currentStyle.paddingTop : getComputedStyle(sObj, null).paddingTop);
		var actualBorder = parseFloat((isIE)? sObj.currentStyle.borderTopWidth : getComputedStyle(sObj, null).borderTopWidth);

		var pushDiv = subPanier[num].pushDiv;
		var oOffsetTop = parseFloat(sObj.offsetTop);

		sObj.parentNode.style.height ="auto";

		subPanier[num].timer = setInterval( 'slowOpen()', 30);

		this.slowOpen = function(){
			var actualHeight = parseFloat((isIE)? sObj.currentStyle.height : getComputedStyle(sObj, null).height);
			actualHeight = actualHeight+actualPadding+actualBorder;

			var dx =  (goingToHeight - actualHeight);
			var doMath = Math.ceil(actualHeight+(0.2*dx));
			if (actualHeight<goingToHeight) {
				sObj.style.height = doMath+"px";
			} else {
				clearInterval(subPanier[num].timer); // stop recursion
				sObj.style.overflow = 'visible';
				sObj.style.height = 'auto';
				sObj.parentNode.style.height =null;
				
				// integration des scrollbars JS
				if(window.jmlScrollbar!=undefined){
					window.jmlScrollbar.refresh();
				}
			}
		}
//window.alert('slowOpen['+num+'] : '+sObj.tagName+'#'+sObj.id+' : '+(actualPadding+(parseFloat((isIE)? sObj.currentStyle.height : getComputedStyle(sObj, null).height))+actualBorder)+'px=>'+goingToHeight+'px');
		slowOpen();
	}


	function closeThatBloc(k){
		var timeoutVarClose;
		var fb1 = subPanier[k].obj;


		if (fb1.className =='on'){

			var fixedVarK = k;
			var workon = fb1;
			workon.style.overflow = "hidden";
			workon.className = '';

			subPanier[fixedVarK].timer = setInterval( 'slowClose('+fixedVarK+')', 30);//slowClose(fixedVarK)
		}
	}

	function isBlocToBeClosed(bloc, unless){
		if(unless.length){
			for(var z=0;z<unless.length;z++){
				if(bloc.id==unless[z]){
					return false;
				}
			}
			return true;
		} else {
			return true;
		}
	}


	function closeAllBlocs(unless){
//		window.alert('closeAllBlocs called');
		// unless est une liste d'ids de LI à ne pas fermer.

		for(var k=0;k<subPanier.length;k++) {
			if(isBlocToBeClosed(subPanier[k].obj, unless)){
				closeThatBloc(k);
			}
		}


		 this.slowClose = function(fxVarK) {
			var workon = subPanier[fxVarK].obj;
			var actualPadding = parseFloat((isIE)? workon.currentStyle.paddingTop : getComputedStyle(workon, null).paddingTop);
			var actualBorder = parseFloat((isIE)? 0 : getComputedStyle(workon, null).borderTopWidth);//pas de bordure pour IE

			var actualHeight = parseFloat((isIE)? workon.currentStyle.height : getComputedStyle(workon, null).height);
			var dx =  (minHeight - actualHeight);
			var doMath = Math.floor(actualHeight+(0.2*dx))-(actualPadding+actualBorder);

			if (actualHeight>minHeight) {

				workon.style.height = doMath+"px";
			} else {
				var subs=workon.getElementsByTagName('ul');
				//window.alert(subs.length);
				if(subs.length){
					for(var z=0;z<subs.length;z++){
						subs[z].style.display="none";
					}
				}
				clearInterval(subPanier[fxVarK].timer);
				// integration des scrollbars JS
				if(window.jmlScrollbar!=undefined){
					window.jmlScrollbar.refresh();
				}
			}
		}
	}
	/******/

	this.frm = document.getElementById(idDiv);
//	window.alert('construct root elem : '+this.frm.tagName+'#'+this.frm.id);
	zeDiv=this.frm;


	// Just find a bunch of LIs
	this.frm = this.frm.getElementsByTagName("li");

	// Setting id for LIs based on numeric index computed in the frm Array
	for(var i=0;i<this.frm.length;i++){
		var zeItem=this.frm[i];
		zeItem.setAttribute('id','frm_'+i);
	}


	// Assign parent information (space separated LI id list) in a custom property of the A tag
	for(var i=0;i<this.frm.length;i++){
		var zeItem=this.frm[i];
		var zeLink=this.frm[i].getElementsByTagName("a")[0];
		var parents=new Array();
		if(zeItem.parentNode.parentNode.tagName=="LI"){
			parents.push(zeItem.parentNode.parentNode.id);
			if(zeItem.parentNode.parentNode.parentNode.parentNode.tagName=="LI"){
				parents.push(zeItem.parentNode.parentNode.parentNode.parentNode.id);
				if(zeItem.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.tagName=="LI"){
					parents.push(zeItem.parentNode.parentNode.parentNode.parentNode.parentNode.parentNode.id);
				}
			}
		}
		var parents_string='';
		if(parents.length){
			//window.alert('parent detected');
			parents_string=parents.join(' ');
		}
		zeLink.setAttribute('parent_items',parents_string);
	}


/*
	this.frm=new Array();
	
	if(zeDiv.tagName=="DIV"){ //window.alert('yeah1');
		for(var i=0;i<zeDiv.childNodes.length;i++){ //window.alert('yeah2 : '+zeDiv.childNodes[i].tagName);
	 		if(zeDiv.childNodes[i].tagName=="DIV"){
	 			//window.alert('yeah3');
	    		for(var j=0;j<zeDiv.childNodes[i].childNodes.length;j++){ 
	    			//window.alert('yeah4 : '+zeDiv.childNodes[i].childNodes[j].tagName);
	 	      		if(zeDiv.childNodes[i].childNodes[j].tagName=="UL"){
			 			//window.alert('yeah5');
			 			for(var k=0;k<zeDiv.childNodes[i].childNodes[j].childNodes.length;k++){ 
			 				if(zeDiv.childNodes[i].childNodes[j].childNodes[k].tagName=="LI"){
			 					//window.alert('yeah6');
				 				this.frm.push(zeDiv.childNodes[i].childNodes[j].childNodes[k]);
				 			}
			 			}
	 	      		}
	 	    	}
	 		}
	 	}
	} else { // We have a <ul> as root node
		for(var i=0;i<zeDiv.childNodes.length;i++){ //window.alert('yeah2 : '+zeDiv.childNodes[i].tagName);
	 		if(zeDiv.childNodes[i].tagName=="LI"){
 				this.frm.push(zeDiv.childNodes[i]);
			}
		}	
	}
*/

	this.NbLi = this.frm.length;// nombre de LI
	
//	window.alert('['+zeDiv.tagName+'] : '+this.NbLi+' children lis found');
	var minHeight = parseFloat((isIE)? this.frm[0].currentStyle.minHeight : getComputedStyle(this.frm[0], null).minHeight);

	for(var i=0; i<this.NbLi; i++) { // affectation des proprietes de l'objet aux LI
//		window.alert('dbg nb.'+i);
		subPanier[i] = new this.iObj(this, i);
		panierHeight[i] = this.frm[i].scrollHeight;//save each height

		//this.frm[i].setAttribute("offset_height",panierHeight[i]);
		//this.frm[i].setAttribute("scroll_height",this.frm[i].scrollHeight);

		// on ferme tout le monde sauf ceux qui ont la classe "on"
		if (this.frm[i].className.indexOf("on")<0) {
			this.frm[i].className = "";
			this.frm[i].style.height = minHeight+"px";
/*
			var subs=this.frm[i].getElementsByTagName('ul');
			//window.alert(subs.length);
			if(subs.length){
				for(var z=0;z<subs.length;z++){
					subs[z].style.display="none";
				}
			}*/
		} else {
			this.frm[i].style.height = panierHeight[i]+"px";
		}
		/*
		// On fait une récursion si le lien est suivi d'un sous-menu
		var nextUL=false;
		var next_1=this.frm[i].nextSibling; if((next_1!=undefined) && (next_1.tagName==undefined)) next_1=next_1.nextSibling;
		if(next_1!=undefined){
//			window.alert('test1 : '+next_1.tagName+'#'+next_1.id+' !');
			if(next_1.tagName=="UL"){window.alert('UL!!!! next1');
				nextUL=next_1;
			} else {
				var next_2=next_1.nextSibling; if((next_2!=undefined) && (next_2.tagName==undefined)) next_2=next_2.nextSibling;
				if(next_2!=undefined){
//					window.alert('test2 : '+next_2.tagName+'#'+next_2.id+' !');
					if(next_2.tagName=="UL"){window.alert('UL!!!! next2');
						nextUL=next_2;
					}
				}
			}
		}

		// récursion pour chaque UL trouvé !
		if(nextUL){window.alert('recursion3 : #'+nextUL.id+' !');
			var plop=new menuSlide(nextUL.id);
		} */
	}
}

// popin + alpha background
function showAlphaPopin(){

	var selectTags	= document.getElementsByTagName("select");
	function hideSelect() {
	for (var i=0; i< selectTags.length; i++) {
			selectTags[i].style.visibility = 'hidden';
		}
	}
	function showSelect(){
		for (var i=0; i< selectTags.length; i++) {
			selectTags[i].style.visibility = '';
		}
	}

	var comefromForm = (typeof thisIsAnAjaxForm!='undefined')? true : false;
	if (document.getElementById("mediacontent")) {
		document.getElementById("mediacontent").style.visibility = 'hidden';
	}
	
	hideSelect()
	
	var oTell = document.getElementById(alphapopin);
	var state = ((isIE)? oTell.currentStyle.display : getComputedStyle(oTell, null).display);
	if (state=='none') {
		oTell.style.display ="block";
	} else {
		oTell.style.display ="none";
		if (comefromForm) getAjaxAnswer.resetForm();
	}
}