//gestion des POPUP
var opacite=100;
var fade_out;
var fade_in;
var timer_deroule;
var timer_enroule;
var bLocked=false;
	

function getVal(id){
	if(document.getElementById(id)){
		return document.getElementById(id).value;
	}
}
function hidePopupDiv(nom,timing){									
	if(bLocked==false){	
		bLocked=true;
		opacite=70;
		fade_out=setTimeout("mask('"+nom+"',100)",10);			
	}				
}

function mask(nom,opacity){
	//if(bLocked==true){		
		opacity-=10;		
		document.getElementById(nom).style.MozOpacity = (opacity/100);
		document.getElementById(nom).style.filter = "alpha(opacity="+opacity+")";
		if(opacity<=0){				
			opacity=100;
			clearTimeout(fade_out);
			document.getElementById(nom).style.visibility='hidden';
			document.getElementById(nom).style.MozOpacity = (opacity/100);
			document.getElementById(nom).style.filter = "alpha(opacity="+opacity+")";
			document.getElementById(nom).style.opacity = (opacity/100);
			document.getElementById(nom).style.KhtmlOpacity = (opacity/100);
			bLocked=false;
			if(nom=="menu1" || nom=="menu2" || nom=="menu3"){
				aEtat[nom]="ferme";
			}
		} else {		
			fade_out=setTimeout("mask('"+nom+"',"+opacity+")",10);	
		}
	//}		
}
function show(nom,opacity){	
	//if(bLocked==true){
		bLocked=true;
		opacity+=10;		
		document.getElementById(nom).style.MozOpacity = (opacity/100);
		document.getElementById(nom).style.filter = "alpha(opacity="+opacity+")";	
		if(opacity>=90){				
			opacity=100;
			clearTimeout(fade_in);		
			document.getElementById(nom).style.MozOpacity = (opacity/100);
			document.getElementById(nom).style.filter = "alpha(opacity="+opacity+")";
			document.getElementById(nom).style.opacity = (opacity/100);
			document.getElementById(nom).style.KhtmlOpacity = (opacity/100);
			bLocked=false;
			if(nom=="menu1" || nom=="menu2" || nom=="menu3"){
				aEtat[nom]="ouvert";
				if(sMenuEnCours!=nom){
					menuFerme(nom);
				}
			}
		} else {		
			document.getElementById(nom).style.visibility='visible'
			fade_in=setTimeout("show('"+nom+"',"+opacity+")",10);	
		}
	//}
		
}
function showPopupDiv(nom,e,timing) {
	if(bLocked==false){
	bLocked=true;
	var posx = 0;
	var posy = 0;
	if (!e)	{
		var e = window.event;
	} else {
		if (e.pageX || e.pageY){
			posx = e.pageX;
			posy = e.pageY;
		} else if (e.clientX || e.clientY) {
			posx = e.clientX + document.documentElement.scrollLeft;
			posy = e.clientY + document.documentElement.scrollTop;
		}
	}
	with (document.getElementById(nom).style) {
		left = (posx+7)+'px';
		top = (parseInt(posy)+7)+'px';
	}
	opacite=0;
	fade_in=setTimeout("show('"+nom+"',0)",10);		
	}
}
function showToolTip(nom,e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY){
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		posx = e.clientX + document.documentElement.scrollLeft;
		posy = e.clientY + document.documentElement.scrollTop;
	}
	
	with (document.getElementById(nom).style) {
		left = (posx+7)+'px';
		top = (parseInt(posy)+7)+'px';
	}
	document.getElementById(nom).style.visibility='visible';		
}
function showToolTipAjax(nom,e,position) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY){
		posx = e.pageX;
		posy = e.pageY;
	} else if (e.clientX || e.clientY) {
		posx = e.clientX + document.documentElement.scrollLeft;
		posy = e.clientY + document.documentElement.scrollTop;
	}
	var posx=posx-position;
	with (document.getElementById(nom).style) {
		left = (parseInt(posx))+'px';		
		top = (parseInt(posy)+10)+'px';
	}
	document.getElementById(nom).style.visibility='visible';		
}
function hideToolTip(nom,timing){				
					document.getElementById(nom).style.visibility='hidden';				
}



//rool-OVER Macromedia
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];}
}
		
//ajout d'evenement onLoad
function addLoadEvent(func){   
 	var oldonload = window.onload; 
    if (typeof window.onload != 'function') { 
        window.onload = func; 
    } else { 
        window.onload = function() 
    	{ 
            oldonload(); 
            func(); 
        } 
    } 
} 
function addUnloadEvent(func){   
 	var oldonunload = window.onunload; 
    if (typeof window.onunload != 'function') { 
        window.onunload = func; 
    } else { 
        window.onunload = function() 
    	{ 
            oldonunload(); 
            func(); 
        } 
    } 
} 
//onction music
/*function switchMusic(nom_div){	
				var Chaine="vide";
				var div;
				Chaine=String(parent.frames["musicFrame"].window.location);	
				if(!Chaine){
					Chaine="vide";
				}
				div=document.getElementById(nom_div);
				
				if( Chaine.indexOf("off")>0 ){
					div.innerHTML="ON";					
					document.getElementById('eQmusic').src='img/general/musique/EQon.gif';
					parent.frames["musicFrame"].window.location="../music_on.php";
				} else {
					div.innerHTML="OFF";					
					document.getElementById('eQmusic').src='img/general/musique/EQoff.gif';
					parent.frames["musicFrame"].window.location="../music_off.php";
				}
				
	}	
var test1;
var test2;
var test3;
check_music = function() { 			
	if (top.location != self.document.location){
		var nom_div='musicDIV';
		var Chaine=String(parent.frames["musicFrame"].window.location);
		var Sous_Chaine="off";			
		var div=document.getElementById(nom_div);
		if( Chaine.indexOf(Sous_Chaine)< 0 ){
			div.innerHTML="ON";					
			document.getElementById('eQmusic').src='img/general/musique/EQon.gif';			
		} else {
			div.innerHTML="OFF";					
			document.getElementById('eQmusic').src='img/general/musique/EQoff.gif';			
		}
	} else {
		document.location="../index.php";
	}
	
}*/
	
//addLoadEvent(check_music);

//popup//*************************************
function get_left(size) {
	var x=0;
	var ecran=screen.width;
	return Math.round((ecran/2)-(size/2));	
}

function get_top(size) {
	var y=0;
	var ecran=screen.height;
	return Math.round((ecran/2)-(size/2));	
}

function popup(theURL,winName,width,height) { //v2.0
  fen=window.open(theURL,winName,"resize=no,scrollbar=yes,left="+get_left(width)+"px,top="+get_top(height)+"px,width="+width+"px,height="+height+"px" );
  fen.focus();
}
//popup//*************************************
	
//bouton**************************

	
var sBtnActif;
var sChampActif;
function setFocusBtn(bouton,last){
		
		sBtnActif=bouton;		
		sChampActif=last;
	}	
function killFocusBtn(bouton,last){
		
		sBtnActif="";		
		sChampActif=last;
}	
	function activeBtn(){	
	
		if(document.getElementById(sBtnActif)){		
			if(sBtnActif=="btnSearchRef"){
				refSearch(document.getElementById('search_ref').value);
			} else {
				func=document.getElementById(sBtnActif).onclick
				func();
			}
		}
	}
	
	
	if (document.layers)
		document.captureEvents(Event.KEYPRESS)

	function process_keypress(e) {
		if(window.event){
			if (window.event.type == "keypress" & window.event.keyCode == 13)				
				activeBtn();
		}
		if(e)
		{
	if (e.type == "keypress" & e.keyCode == 13)
		activeBtn();
	}
}
document.onkeypress = process_keypress;


/*function refSearch(id) {		
				url="ajax/search.php";
				param="search_ref="+id;
                http_request = false;
                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { // IE
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                    }
                }
                if (!http_request) {
                    alert('Cannot create an XMLHTTP instance');
                    return false;
                }
				if(!param){
					param="vide=vide"
				}
                http_request.onreadystatechange =function() { resultSearch(http_request); };
				 http_request.open("GET",url+"?"+param,true);					     			
                http_request.send(null);
            }
		function resultSearch(http_request) {
        	try {
           		 if (http_request.readyState == 4) {
                	if (http_request.status == 200) {
                   	 	var reponse = http_request.responseText;
						//var reponseXML=http_request.responseXml;
						page= reponse.toString();
						//var page=reponseXML.getElementsByTagName('url');
						if(page.substring(page.length -7)!="#search" && page!="" ){	
							//page=page.replace(/(\%0A)/gi,"");
							//page=page.replace(/(\%0A)/gi,"");
							document.location=page;
						} else {
							document.getElementById('erreur_search').style.visibility='visible';
						}					
                	} else {
                    	alert('Un problème est survenu au cours de la requête.');
                	}
            	}
        	}
        	catch( e ) {
            	alert("Une exception s'est produite : " + e.description);
        	}

   	 	}*/
		
		
		function refSearch(id) {		
				url="ajax/searchXML.php";
				param="search_ref="+id;
                http_request = false;
                if (window.XMLHttpRequest) { // Mozilla, Safari,...
                    http_request = new XMLHttpRequest();
                    if (http_request.overrideMimeType) {
                        http_request.overrideMimeType('text/xml');
                    }
                } else if (window.ActiveXObject) { // IE
                    try {
                        http_request = new ActiveXObject("Msxml2.XMLHTTP");
                    } catch (e) {
                        try {
                        http_request = new ActiveXObject("Microsoft.XMLHTTP");
                        } catch (e) {}
                    }
                }
                if (!http_request) {
                    alert('Cannot create an XMLHTTP instance');
                    return false;
                }
				if(!param){
					param="vide=vide"
				}
                http_request.onreadystatechange =function() { resultSearch(http_request); };
				 http_request.open("GET",url+"?"+param,true);					     			
                http_request.send(null);
            }
		function resultSearch(http_request) {			
        	try {
           		 if (http_request.readyState == 4) {
                	if (http_request.status == 200) {  											
						var resXML= http_request.responseXML;
						//lecture XML					
						var page_node = resXML.getElementsByTagName('page').item(0);											
						var url_node=page_node.getElementsByTagName('url').item(0);					
						if(url_node.getAttribute("value")!="#search"){	
							var page=url_node.getAttribute("value");
							page=page.replace("&#38;","&");
						  	document.location.href = page;						
						} else {
							document.getElementById('erreur_search').style.visibility='visible';
						}
                	} else {
                    		//alert('Un problème est survenu au cours de la requête.');
                	}
            	}
        	}  	catch( e ) {
            //alert("Une exception s'est produite : " + e.description);
        	}

   	 	}
