/**
 *
 * Can show a tooltip over an element
 * Content of tooltip is the title attribute value of the element
 * copyright 2004 Laurent Jouanneau. http://ljouanneau.com/soft/javascript
 * release under LGPL Licence
 * works with dom2 compliance browser, and IE6. perhaps IE5 or IE4.. not Nestcape 4
 *
 * To use it :
 * 1.include this script on your page
 * 2.insert this element somewhere in your page
 *       <div id="tooltip"></div>
 * 3. style it in your CSS stylesheet (set color, background etc..). You must set
 * this two style too :
 *     div#tooltip { position:absolute; visibility:hidden; ... }
 * 4.the end. test it ! :-)
 *
 */

var ie4 = (document.all)? true:false;		// check if ie4
var ie5 = false;
if(ie4) ie5 = (navigator.userAgent.indexOf('MSIE 5')>0 || navigator.userAgent.indexOf('MSIE 6')>0 || navigator.userAgent.indexOf('MSIE 7')>0);
var dom2 = ((document.getElementById) && !(ie4||ie5))? true:false; // check the W3C DOM level2 compliance. ie4, ie5, ns4 are not dom level2 compliance !! grrrr >:-(

// create the tooltip object
function tooltip(){}
// setup properties of tooltip object
tooltip.id="tooltip";
tooltip.offsetx = 10;
tooltip.offsety = 10;
tooltip.x = 0;
tooltip.y = 0;
tooltip.snow = 0;
tooltip.tooltipElement=null;
tooltip.title_saved='';
tooltip.saveonmouseover=null;
tooltip.ie4 = (document.all)? true:false;		// check if ie4
tooltip.ie5 = false;
if(tooltip.ie4) tooltip.ie5 = (navigator.userAgent.indexOf('MSIE 5')>0 || navigator.userAgent.indexOf('MSIE 6')>0 || navigator.userAgent.indexOf('MSIE 7')>0);
tooltip.dom2 = ((document.getElementById) && !(tooltip.ie4||tooltip.ie5))? true:false; // check the W3C DOM level2 compliance. ie4, ie5, ns4 are not dom level2 compliance !! grrrr >:-(


/**
* Open ToolTip. The title attribute of the htmlelement is the text of the tooltip
* Call this method on the mouseover event on your htmlelement
* ex :  <div id='myHtmlElement' onmouseover='tooltip.show(this)'...></div>
*/
tooltip.show = function (htmlelement) {

   if ( this.ie4 || this.dom2 ) {
      // we save text of title attribute to avoid the showing of tooltip generated by browser
      text=htmlelement.getAttribute("title");
      this.title_saved=text;
      htmlelement.setAttribute("title","");
   }
	if(this.dom2){
		this.tooltipElement = document.getElementById(this.id);
      this.saveonmouseover=document.onmousemove;
		document.onmousemove = this.mouseMove;
	}else if ( this.ie4 ) {
      this.tooltipElement = document.all[this.id].style;
      this.saveonmouseover=document.onmousemove;
      document.onmousemove = this.mouseMove;
	}

   if ( this.ie4 || this.dom2 ) {
      if(this.ie4) document.all[this.id].innerHTML = text;
      else if(this.dom2) document.getElementById(this.id).innerHTML=text;

      this.moveTo(this.x + this.offsetx , this.y + this.offsety);

      if(this.ie4) this.tooltipElement.visibility = "visible";
      else if(this.dom2) this.tooltipElement.style.visibility ="visible";
   }
   return false;
}

/**
* hide tooltip
* call this method on the mouseout event of the html element
* ex : <div id="myHtmlElement" ... onmouseout="tooltip.hide(this)"></div>
*/
tooltip.hide = function (htmlelement) {
	if ( this.ie4 || this.dom2 ) {
	  if (this.title_saved!=""){
      	htmlelement.setAttribute("title",this.title_saved);
      	this.title_saved="";
	   }
		if(this.ie4) this.tooltipElement.visibility = "hidden";
      else if(this.dom2) this.tooltipElement.style.visibility = "hidden";

      document.onmousemove=this.saveonmouseover;
	}
}



// Moves the tooltip element
tooltip.mouseMove = function (e) {
   // we don't use "this", but tooltip because this method is assign to an event of document
   // and so is dreferenced


   if(tooltip.ie4 || tooltip.dom2){

      if(tooltip.dom2){
         tooltip.x = e.pageX;
         tooltip.y = e.pageY;
      }else{

         if(tooltip.ie4) { tooltip.x = event.x; tooltip.y = event.y; }
         if(tooltip.ie5) { 
	           D=document;
			   db=!D.documentElement.clientWidth?D.body:D.documentElement //quirk IE6
			   gk=window.Event?1:0/*Gecko*/;
			   sy=gk?pageYOffset:db.scrollTop;  
			   sx=gk?pageYOffset:db.scrollLeft; 
         	   tooltip.x = event.x + sx ;
               tooltip.y = event.y + sy ; }
      }
      tooltip.moveTo( tooltip.x +tooltip.offsetx , tooltip.y + tooltip.offsety);
   }
}

// Move the tooltip element
tooltip.moveTo = function (xL,yL) {

	if(this.dom2){
		   if (xL+150 < window.innerWidth  )
		this.tooltipElement.style.left = xL +"px";
		      else 
		this.tooltipElement.style.left = xL-150 +"px";
      this.tooltipElement.style.top = yL +"px";
	}else if(this.ie4){
		D=document;
	   db=!D.documentElement.clientWidth?D.body:D.documentElement //quirk IE6
	   if (xL+150 < db.clientWidth  )
  	      this.tooltipElement.left = xL;
  	      else 
  	      this.tooltipElement.left = xL-150;
      this.tooltipElement.top = yL;
   }
}
function PopupAide(pMod,pAct,pChamp) {

	var pHtml = "index.php";
	pHtml += "?mod=Aide";
	pHtml += "&ac=aide";
	pHtml += "&faire=Aide";
	pHtml += "&Module="+pMod;
	pHtml += "&Action="+pAct;
	pHtml += "&Champ="+pChamp;
    var obj_calwindow = window.open(pHtml,"Aide","width=500,height=400,status=no,toolbar=no,menubar=no,location=yes,scrollbars=yes");
    obj_calwindow.opener = window;
    obj_calwindow.focus();
}


	function AfficheDiv(pDiv,pImg){
		if(ie4) {
		  if (document.all[pDiv].style.display== "none") {
			    document.all[pDiv].style.display= "block";
			    etat='0';
		    }else {
		    	document.all[pDiv].style.display= "none";
			    etat='1';
		   }
		} else if(dom2) { 
		  	if (document.getElementById(pDiv).style.display== "none"){
			    etat='0';
			   	document.getElementById(pDiv).style.display= "block";
		   	} else {
		   		document.getElementById(pDiv).style.display= "none";
			    etat='1';
			}
		}
		if (pImg){
			imgSrc=eval('Img'+pImg+'_'+etat+'.src');
			document.images['Img'+pImg].src = imgSrc;
			findObj('Etat'+pImg).value=etat;
			//alert('Etat'+pImg+" => "+findObj('Etat'+pImg).value);
		}
	}

	function DivDisplay(pDiv,pDisplay){
		//alert(pDiv);
		if(ie4) {
			//alert(document.all[pDiv]+" : "+pDisplay);
	  		if (pDisplay==1) 
			    {document.all[pDiv].style.display= "block";} 
	    	else 
		  		if (pDisplay==2) 
				    {document.all[pDiv].style.display= "inline";} 
	    		else 
	    			{document.all[pDiv].style.display= "none";}
		} else 
			if(dom2) { 
				//alert(document.getElementById(pDiv)+" : "+pDisplay);
			  	if (pDisplay==1)
			  		{document.getElementById(pDiv).style.display= "block";}
			   	else 
				  	if (pDisplay==2)
				  		{document.getElementById(pDiv).style.display= "inline";}
				   	else 	
			   		{document.getElementById(pDiv).style.display= "none";}
			}
	}	
function AfficheTousDiv(pDiv,pAffi){
	if(pAffi) {Affi="block"} else {Affi="none"}
	var Divs=document.getElementsByTagName("div");
  	for(var i=0;i<Divs.length;i++) {
		if (Divs.item(i).id.indexOf(pDiv)==0){
			if(ie4) {
			    Divs.item(i).style.display= Affi;
			} else if(dom2) { 
			   	Divs.item(i).style.display= Affi;
				}		
  		}
	}
}

function swapImgRestore() { //v3.0
  var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function preloadImages(pName) { //v3.0
  var d=document;
  if(d.images){
    if(!d.p) {d.p=new Array();}
    var i,j=d.p.length,a=preloadImages.arguments;
        for(i=0; i<a.length; i++) {
            if (a[i].indexOf("#")!=0){
                d.p[j]=new Image;
                
                d.p[j++].src=a[i];
                }
            }
    }
}

function findObj(n, d) { //v3.0
  var p,i,x;
  if(dom2) { 
 		x=document.getElementById(n);
  } else {
  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=findObj(n,d.layers[i].document); 
  }
  //alert(dom2 +" "+n+" "+x);
  return x;
}

function swapImage() { //v3.0
  var i,j=0,x,a=swapImage.arguments;
  document.sr=new Array; 
  for(i=0;i<(a.length-2);i+=3)
  	 if ((x=findObj(a[i]))!=null) {
  	 	document.sr[j++]=x; 
  	 	if(!x.oSrc) 
  	 		x.oSrc=x.src; 
  	 		x.src=a[i+2];
  	 	}
}

function applyClass(oElement,sCSSClass)
{
     oElement.className = sCSSClass;
}

function isNum(pChamp,pType,pMin,pMax) {

      if (isNaN(pChamp.value))
      {
        alert("Saisie numérique uniquement");
        pChamp.focus();
        return false;
      } else {
		if (pType=="I" && parseFloat(pChamp.value)!=parseInt(pChamp.value)) {
	        alert("Saisie entier uniquement");
    	    pChamp.focus();
        	return false;
		} else {
	      	if (pMin!=null && pMax!=null){
				// alert (pMax+" "+parseFloat(pChamp.value)+" "+(parseFloat(pChamp.value)>pMax));
	      		if ((parseFloat(pChamp.value)<pMin) || (parseFloat(pChamp.value)>pMax)){
	      		    alert("Doit être compris entre "+pMin+" et "+pMax);
			        pChamp.focus();
	        		return false;
	      		} 
	      	} else {
		      	if (pMin!=null ){
	    	  		if (parseFloat(pChamp.value)<pMin ){
	      		    alert("Doit être supérieur ? "+pMin);
			        pChamp.focus();
	        		return false;
	      			} 
	      		
	      		} else {
		      		if (pMax!=null){
	    	  			if (parseFloat(pChamp.value)<pMin ){
	      			    	alert("Doit être inférieur ? "+pMax);
				    	    pChamp.focus();
	    	    			return false;
		    	  		} 
	      			}
	      		}
	      	}
		}
	}
	return true;
}

function RazChamps(pRes){
	document.formulaire.ID_ResRaz.value=pRes;
	//alert(document.formulaire.ID_ResRaz.value);
	Faire("Refresh");
}

function SupLien(pFaire,pID_Evt,pSens){
	if (pFaire=="ModifLien"){
		window.location='index.php?mod=FranceFer&ac=modif&faire='+pFaire+'&Sens='+pSens+'&ID_Evt='+pID_Evt;
	} else { 
		if (pFaire=="SupLienData")
			txt="Vous allez supprimer ce lien et cet enregistrement.";
		else
			txt="Vous allez supprimer ce lien."; 	
		if (confirm(txt+"\nEtes vous sûr ? ")){
			window.location='index.php?mod=FranceFer&ac=modif&faire='+pFaire+'&Sens='+pSens+'&ID_Evt='+pID_Evt;
		}
	}
}

function ToucheEnter(pEvent){
if (pEvent==null){
	pEvent=window.event;
	}
	//alert(pEvent);
 return (pEvent.keyCode.type == "keydown" && pEvent.keyCode==13);
 }
