function iFrameHeight(id) {
	var h = 0;
	if ( !document.all ) {
		h = document.getElementById(id).contentDocument.height;//alert(document.getElementById(id).contentDocument);
		document.getElementById(id).style.height = h + 60 + 'px';
	} else if( document.all ) {
		h = document.frames(id).document.body.scrollHeight;
		eval("document.all."+id+".style.height = h + 60 + 'px';");
	}
}

// affichage du zoom sur les images

var t_zoom_image= new Array();

function zoom_image_over(id,w_min,h_min,w_max,h_max){
 	i=t_zoom_image.length;
	if(i>0)z=t_zoom_image[i-1]["zindex"]+1;
	else z=2;
	document.getElementById("conteneur_"+id).style.zIndex=z;
	t_zoom_image[i]=new Array();
	t_zoom_image[i]["id"]=id;
	t_zoom_image[i]["w_min"]=w_min;
	t_zoom_image[i]["h_min"]=h_min;
	t_zoom_image[i]["w_max"]=w_max;
	t_zoom_image[i]["h_max"]=h_max;
	t_zoom_image[i]["boucle"]=0;
	t_zoom_image[i]["zindex"]=z;
	t_zoom_image[i]["interval"]=setInterval("zoom_image_anim_over("+i+")",20);
}

function zoom_image_anim_over(i){
	//i=t_zoom_image.length-1;
	t_zoom_image[i]["boucle"]++;
	
	w_augmentation=Math.round((t_zoom_image[i]["w_max"]-t_zoom_image[i]["w_min"])/10*t_zoom_image[i]["boucle"]);
	h_augmentation=Math.round((t_zoom_image[i]["h_max"]-t_zoom_image[i]["h_min"])/10*t_zoom_image[i]["boucle"]);
	document.getElementById(t_zoom_image[i]["id"]).style.left=(-Math.round(w_augmentation/2))+"px";
	document.getElementById(t_zoom_image[i]["id"]).style.top=(-Math.round(h_augmentation/2))+"px";
	document.getElementById(t_zoom_image[i]["id"]).style.width = (t_zoom_image[i]["w_min"]+w_augmentation)+"px";
	document.getElementById(t_zoom_image[i]["id"]).style.height = (t_zoom_image[i]["h_min"]+h_augmentation)+"px";

	if(t_zoom_image[i]["boucle"]==10){
		clearInterval(t_zoom_image[i]["interval"]);
		
	}
}

function zoom_image_out(){
	i=t_zoom_image.length-1;
	clearInterval(t_zoom_image[i]["interval"]);
	t_zoom_image[i]["interval"]=setInterval("zoom_image_anim_out("+i+")",20);
}

function zoom_image_anim_out(i){
	//i=t_zoom_image.length-1;
	t_zoom_image[i]["boucle"]--;
	
	if(t_zoom_image[i]["boucle"]>0){
		w_augmentation=Math.round((t_zoom_image[i]["w_max"]-t_zoom_image[i]["w_min"])/10*t_zoom_image[i]["boucle"]);
		h_augmentation=Math.round((t_zoom_image[i]["h_max"]-t_zoom_image[i]["h_min"])/10*t_zoom_image[i]["boucle"]);
		document.getElementById(t_zoom_image[i]["id"]).style.left=(-Math.round(w_augmentation/2))+"px";
		document.getElementById(t_zoom_image[i]["id"]).style.top=(-Math.round(h_augmentation/2))+"px";
		document.getElementById(t_zoom_image[i]["id"]).style.width = (t_zoom_image[i]["w_min"]+w_augmentation)+"px";
		document.getElementById(t_zoom_image[i]["id"]).style.height = (t_zoom_image[i]["h_min"]+h_augmentation)+"px";
	}
	else{
		clearInterval(t_zoom_image[i]["interval"]);
		document.getElementById("conteneur_"+t_zoom_image[i]["id"]).style.zIndex=1;
		document.getElementById(t_zoom_image[i]["id"]).style.left="0px";
		document.getElementById(t_zoom_image[i]["id"]).style.top="0px";
		document.getElementById(t_zoom_image[i]["id"]).style.width = t_zoom_image[i]["w_min"]+"px";
		document.getElementById(t_zoom_image[i]["id"]).style.height = t_zoom_image[i]["h_min"]+"px";
	}
}



// editeur de liens

var obj_lien="";
var obj_fenetre="";

function set_lien(lien,fenetre){
	obj_lien.value=lien;
	obj_fenetre.value=fenetre;
}

function editer_lien(lien,fenetre){
	obj_lien=lien;
	obj_fenetre=fenetre;
	if(obj_fenetre.value==0)fenetre="false";
	else fenetre="true";
	MM_openBrWindow('../editeur/pop_liens.php?lien='+obj_lien.value+'&fenetre='+fenetre,'','status=yes,width=450,height=180')
}

//gestion de la popup de date

function set_date(d,chemin,envoi,forme,id){
	if(id==1)
	{
		elem = document.getElementById(chemin);
		elem.value=d;
	}
	else
		eval(chemin+".value='"+d+"';");
	if(envoi==1) eval("document."+forme+".submit();")
}

//d = la date en cours, chemin = si id=1, id du champ pour permettre les noms de champs en tableau, sinon le name du champs
//envoi = si 1 alors envoi du formulaire qui porte le nom se trouvant dans le parametre forme
//id = si 1 on affecte selon l'id se trouvant dans chemin, sinon on affecte suivant le name
function pop_date(d,chemin,envoi,forme,id){
	MM_openBrWindow('calendrier.php?date_origine='+d+'&chemin='+chemin+'&envoi='+envoi+'&forme='+forme+'&id='+id,'','width=200,height=167')
}

// fonction de recherche de coordonnée absolue

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curleft += obj.y;
	return curleft;
}

// fonction de macromedia

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

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_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&&id.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}


// affichage des flashs

/*****************************************************************************
* BackToTheHtml Command
*///**************************************************************************
function BackToTheHtml(node)
{
	if(node == null)
		this.node = document; 
	else
		this.node = node; 
};
BackToTheHtml.prototype.node = null;

BackToTheHtml.prototype.execute = function()
{
	this.activateObject();
}

BackToTheHtml.prototype.activateObject = function(domObject)
{
	var aDomObject = this.node.getElementsByTagName('object');
	var activationObject;
	for(var i=0; i<aDomObject.length; i++)
		if
		(
			aDomObject[i].getAttributeNode('BackToTheHtml') == null
			&&
			(activationObject = this.getActivationObject(aDomObject[i])) != null
		)
			activationObject.execute();
};

BackToTheHtml.prototype.getActivationObject = function(domObject)
{
	var classid = domObject.classid.toUpperCase().substr('clsid:'.length);
	var mimeType = domObject.type.toLowerCase();

	switch(true)
	{
		case 
			classid == 'D27CDB6E-AE6D-11CF-96B8-444553540000' 
			||
			mimeType == 'application/x-shockwave-flash'
		:
			return new ActivateObjectFlash(domObject);

		default :
			return null;
	}
};

BackToTheHtml.uniqueID = function(prefix)
{
	var sPrefix;
	if(prefix == null)
		sPrefix = 'uniqueId';
	else
		sPrefix = prefix;
		
	var i=0;
	while(document.getElementById(sPrefix + (i++)))
		;
	return sPrefix + (i-1);
};

BackToTheHtml.isParentOf = function(parent,child)
{
	var found = false;
	for(var i=0; i<parent.childNodes.length; i++)
		if(parent.childNodes[i] == child)
			return true;
		else
			found = arguments.callee(parent.childNodes[i],child);

	return found;
}

/*****************************************************************************
* ActivateObject Command
*///**************************************************************************
function ActivateObject(domObject)
{
	this.domObject = domObject;
}

ActivateObject.prototype.domObject = null;
ActivateObject.prototype.classid = null;
ActivateObject.prototype.aHtmlAttribute = ['accessKey','align','alt','archive','border','code','codeBase','codeType','declare','dir','height','hideFocus','hspace','lang','language','name','standby','tabIndex','title','useMap','vspace','width'];
ActivateObject.prototype.aObjectProperty = null;

ActivateObject.prototype.execute = function()
{
	this.xndObjectId = BackToTheHtml.uniqueID();
	this.setTextHtml();
	this.writeObject();

	this.xndObject = document.getElementById(this.xndObjectId);
	this.setSpecialProperties();
	this.removeOriginalObject();
}

ActivateObject.prototype.setTextHtml = function()
{
	var str = '';
	str += '<object BackToTheHtml ' + '\n';
	str += ' classid="clsid:' + this.classid + '" ' + '\n';

	//Add HTML attributes to the <object> tag
	for(var i=0; i<this.aHtmlAttribute.length; i++)
	{
		var name = this.aHtmlAttribute[i];
		if(typeof this.domObject[name] != 'undefined' && this.domObject[name].toString() != '')
			str += '\t' + name + '="' + this.domObject[name].toString() + '" ' + '\n';
	}

	str += 'id="' + this.xndObjectId + '" ' + '\n';
	str += '>';

	for(var i=0; i<this.aObjectProperty.length; i++)
	{
		var name = this.aObjectProperty[i];
		if(typeof this.domObject[name] != 'undefined' && this.domObject[name].toString() != '' )
			str += '\t<param name="' + name + '" value="' + this.domObject[name].toString() + '"></param>' + '\n';
	}
	str += '</object>';

	this.textHtml = str;
};

ActivateObject.prototype.writeObject = function()
{
	this.domObject.insertAdjacentHTML("afterEnd",this.textHtml);
};

ActivateObject.prototype.setSpecialProperties = function()
{
	if(typeof this.domObject.className != 'undefined' && this.domObject.className.toString() != '')
		this.xndObject.className = this.domObject.className

	if(typeof this.domObject.style.cssText != 'undefined' && this.domObject.style.cssText.toString() != '')
		this.xndObject.style.cssText = this.domObject.style.cssText;

	if(typeof this.domObject.SWRemote != 'undefined' && this.domObject.SWRemote.toString() != '')
		this.xndObject.FlashVars = this.domObject.SWRemote;

	if(typeof this.domObject.codebase == 'undefined' || this.domObject.codebase.toString() == '')
		this.xndObject.codebase = 'http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,24,0';

	if(typeof this.domObject.id != 'undefined' && this.domObject.id.toString() != '')
		this.xndObject.id = this.domObject.id;

};

ActivateObject.prototype.removeOriginalObject = function()
{
	this.domObject.parentNode.removeChild(this.domObject);
};

/*****************************************************************************
* ActivateObjectFlash Command
*///**************************************************************************
function ActivateObjectFlash(domObject)
{
	ActivateObject.call(this,domObject);
}
ActivateObjectFlash.prototype = new ActivateObject;
ActivateObjectFlash.prototype.aObjectProperty = ['FrameNum','Playing','Quality','Quality2','Scalemode','Scale','AlignMode','SAlign','BackgroundColor','BGColor','Loop','Movie','WMode','Base','DeviceFont','EmbedMovie','SWRemote','FlashVars','AllowScriptAccess'];
ActivateObjectFlash.prototype.classid = 'D27CDB6E-AE6D-11CF-96B8-444553540000';


/*****************************************************************************
* Script initialisation
*///**************************************************************************
if(typeof ActiveXObject != 'undefined' && typeof Function.call != 'undefined')
{
	var styleId = BackToTheHtml.uniqueID();
	document.write('<style id="' + styleId + '" ></style>');
	var domStyle = document.getElementById(styleId);

	var isHead = false;
	var aHead = document.getElementsByTagName('head');
	for(var i=0; i<aHead.length; i++)
		if(BackToTheHtml.isParentOf(aHead[i],domStyle))
			isHead = true;

	if(isHead)
	{
		document.write('<style type="text/css">OBJECT{visibility:hidden;}</style>');
		document.onreadystatechange = function()
		{
			if(document.readyState == 'complete')
			{
				new BackToTheHtml().execute();
				document.styleSheets[document.styleSheets.length-1].addRule("OBJECT","visibility:visible;");
				//alert('head');
				//alert(document.body.innerHTML);
			}
		}
	}
	else
	{
		new BackToTheHtml().execute();
		//alert('body');
		//alert(document.body.innerHTML);
	}
	
	domStyle.parentNode.removeChild(domStyle);
}

// info bulle
function GetId(id)
{
	return document.getElementById(id);
}
var bulle_visible=false; // La variable bulle_visible nous dit si la bulle est visible ou non
var position_gauche=0;
function move(e) {
	
	if(bulle_visible) {  // Si la bulle est visible, on calcul en temps reel sa position ideale
		if (navigator.appName!="Microsoft Internet Explorer") { // Si on est pas sous IE	
			GetId("curseur").style.left=e.pageX -position_gauche+5+"px";
			GetId("curseur").style.top=e.pageY + 10+"px";
		}
		else { // Modif proposé par TeDeum, merci à lui
		
			if(document.documentElement.clientWidth>0){
				GetId("curseur").style.left=-position_gauche+5+event.x+document.documentElement.scrollLeft+"px";
				GetId("curseur").style.top=10+event.y+document.documentElement.scrollTop+"px";
			}
			else {
				
				GetId("curseur").style.left=-position_gauche+5+event.x+document.body.scrollLeft+"px";
				GetId("curseur").style.top=10+event.y+document.body.scrollTop+"px";
			}
		}
	}
}

function infobulle(texte, classe, largeur, position, marge, opacite) {
	if(texte==''){
		if(bulle_visible==true) {
			GetId("curseur").style.visibility="hidden"; // Si la bulle etais visible on la cache
			GetId("curseur").style.left="-5000px";
			GetId("curseur").style.top="-5000px";
			bulle_visible=false;
			position_gauche=0;
		}
	}
 	else if(bulle_visible==false) {
		GetId("curseur").style.visibility="visible"; // Si il est cacher (la verif n'est qu'une securité) on le rend visible.
		GetId("curseur").style.filter = "alpha(opacity="+opacite+")";
      	GetId("curseur").style.MozOpacity = ""+opacite/100+"";
      	GetId("curseur").style.KhtmlOpacity = ""+opacite/100+"";
		if(classe!='')GetId("curseur").className=classe;
		else GetId("curseur").className="infobulle";
		if(marge!='')GetId("curseur").style.padding=marge+"px";
		else GetId("curseur").style.padding="";
		if(largeur!='')GetId("curseur").style.width=largeur+"px";
		else GetId("curseur").style.width='';
		//if(position!='') GetId("curseur").style.position=absolut;
	
		GetId("curseur").innerHTML = texte; // Cette fonction est a améliorer, il parait qu'elle n'est pas valide (mais elle marche)
		bulle_visible=true;
		position_gauche=position;
 	 }
}
document.onmousemove=move; // des que la souris bouge, on appelle la fonction move pour mettre a jour la position de la bulle.

// calculatrice
function verification(entree) {
  var seulement_ceci ="0123456789[]()-+*%/.";
  for (var i = 0; i < entree.length; i++)
   if (seulement_ceci.indexOf(entree.charAt(i))<0 ) return false;
  return true;
 }

 function resultat() {
   var x = 0;
  if (verification(window.document.calculatrice.calculatrice_affiche.value))
     x = eval(window.document.calculatrice.calculatrice_affiche.value);
   window.document.calculatrice.calculatrice_affiche.value = x;
 }

 function ajouter(caracteres) {
   window.document.calculatrice.calculatrice_affiche.value =
   window.document.calculatrice.calculatrice_affiche.value + caracteres;
 }

 function fonction_speciale(fonction) {
   if (verification(window.document.calculatrice.calculatrice_affiche.value)) {
     if(fonction == "sqrt") {
       var x = 0;
     x = eval(window.document.calculatrice.calculatrice_affiche.value);
     window.document.calculatrice.calculatrice_affiche.value = Math.sqrt(x);
   }
   if(fonction == "pow") {
     var x = 0;
     x = eval(window.document.calculatrice.calculatrice_affiche.value);
     window.document.calculatrice.calculatrice_affiche.value = x * x;
   }
   if(fonction == "log") {
     var x = 0;
     x = eval(window.document.calculatrice.calculatrice_affiche.value);
     window.document.calculatrice.calculatrice_affiche.value = Math.log(x);
   }
  } else window.document.calculatrice.calculatrice_affiche.value = 0
}

var t_memorise_formulaire=new Array();

function memorise_formulaire(nom_form,cible)
{
	if(nom_form!=""){
		if(cible==undefined)w=window;
		else eval("w=window."+cible+";");
		
		t_memorise_formulaire[nom_form]=new Array();

		// Recuperation des inputs
		nb=w.document[nom_form].length;
		for(i=0;i<nb;i++){
			name=w.document[nom_form].elements[i].name;
			if(w.document[nom_form].elements[i].type=='radio' && w.document[nom_form].elements[i].checked==true){
					t_memorise_formulaire[nom_form][name]=w.document[nom_form].elements[i].value;
			}
			if(w.document[nom_form].elements[i].type=='checkbox' && w.document[nom_form].elements[i].checked==true){
					t_memorise_formulaire[nom_form][name]=w.document[nom_form].elements[i].value;
			}
			if(w.document[nom_form].elements[i].type!='radio' && w.document[nom_form].elements[i].type!='checkbox'){
					t_memorise_formulaire[nom_form][name]=w.document[nom_form].elements[i].value;
			}
		}
	}
}

function compare_formulaire(nom_form,cible)
{
	//alert("nom form "+nom_form);
	if(nom_form!=""){
		if(cible==undefined)w=window;
		else eval("w=window."+cible+";");
		
		t=new Array();
		k=0;
		// Recuperation des inputs
		nb=w.document[nom_form].length;
		for(i=0;i<nb;i++){
			name=w.document[nom_form].elements[i].name;
			if(w.document[nom_form].elements[i].type=='radio' && w.document[nom_form].elements[i].checked==true){
					t[k]=new Array();
					t[k]['name']=name;
					t[k]['value']=w.document[nom_form].elements[i].value;
					k++;
			}
			if(w.document[nom_form].elements[i].type=='checkbox' && w.document[nom_form].elements[i].checked==true){
					t[k]=new Array();
					t[k]['name']=name;
					t[k]['value']=w.document[nom_form].elements[i].value;
					k++;
			}
			if(w.document[nom_form].elements[i].type!='radio' && w.document[nom_form].elements[i].type!='checkbox'){
					t[k]=new Array();
					t[k]['name']=name;
					t[k]['value']=w.document[nom_form].elements[i].value;
					k++;
			}
			
		}
		
		for(i=0;i<t.length;i++){
			if(t[i]['value']!=t_memorise_formulaire[nom_form][t[i]['name']])return false;
		}
		return true;
		

	}
	return true;
}

function check_form(cible,message_erreur){
	if(cible==undefined || cible=="")w=window;
	else eval("w=window."+cible+";");
	
	bool=true;
	if(typeof w.get_champ_obligatoire == "function"){
		t=w.get_champ_obligatoire();
		for(i=0;i<t.length;i++){
			if(w.document.getElementById(t[i]["champ"])!=undefined && w.document.getElementById(t[i]["label"])!=undefined){
				if(w.document.getElementById(t[i]["champ"]).value==""){
					w.document.getElementById(t[i]["label"]).style.color="#FF0000";
					bool=false;
				}
				else{
					w.document.getElementById(t[i]["label"]).style.color="";
				}
				w.document.getElementById(t[i]["champ"]).onchange=function(){w.check_form()};
			}
		}
	}
	if(message_erreur==1 && !bool)alert("Tous les champs obligatoires ne sont pas remplis.");
	return bool;
}