function log_js_error(m,u,l)
{
	new Ajax.Request('erreur_js.php?msg='+m+'&line='+l+'&url='+u, { method:'post'})
	return true;	
}

window.onerror = log_js_error;

function logs(m,n)
{
	new Ajax.Request('reception_logs.php?log='+m+'&etape='+n, { method:'post'})
	return true;	
}

var tt=false;
var tempX = 0;
var tempY = 0;
var myWidth = 0, myHeight = 0;
var scrOfX = 0, scrOfY = 0;

var Flimite = new Array();
Flimite["emplois"] = 1000;
Flimite["cabinets"] = 1000;
Flimite["stages"] = 1000;
Flimite["saisonniers"] = 1000;

var alertMsg = "<b>ATTENTION</b> :";

TabActif = null;

function checkMail(x)
{
	var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(x)) return true;
	else return false;
}

function checkNum(x)
{
	var filter  = /^([0-9])+$/;
	if (filter.test(x)) return true;
	else return false;
}

function change_option(champs,text)
{
	if(text == "" && text != 0){return;}
	for(var i = 0; i < champs.length; i++)
	{
		if(champs.options[i].value == text)
		{
			champs.options[i].selected = true;
			return;
		}	
	}	
}

function change_option_text(champs,text)
{
	if(text == "" && text != 0){return;}
	for(var i = 0; i < champs.length; i++)
	{
		if(champs.options[i].text == text)
		{
			champs.options[i].selected = true;
			return;
		}	
	}	
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}

function EcrireCookie(nom, valeur)
{
var argv=EcrireCookie.arguments;
var argc=EcrireCookie.arguments.length;
var expires=(argc > 2) ? argv[2] : null;
var path=(argc > 3) ? argv[3] : null;
var domain=(argc > 4) ? argv[4] : null;
var secure=(argc > 5) ? argv[5] : false;
document.cookie=nom+"="+escape(valeur)+
((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
((path==null) ? "" : ("; path="+path))+
((domain==null) ? "" : ("; domain="+domain))+
((secure==true) ? "; secure" : "");
}

function getCookieVal(offset)
{
var endstr=document.cookie.indexOf (";", offset);
if (endstr==-1) endstr=document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function LireCookie(nom)
{
var arg=nom+"=";
var alen=arg.length;
var clen=document.cookie.length;
var i=0;
while (i<clen)
{
var j=i+alen;
if (document.cookie.substring(i, j)==arg) return getCookieVal(j);
i=document.cookie.indexOf(" ",i)+1;
if (i==0) break;

}
return null;
}


function getScrollXY() {
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else {
    if( document.body && ( document.body.scrollLeft >= 0 || document.body.scrollTop >= 0) ) {
      //DOM compliant
      scrOfY = document.body.scrollTop;
      scrOfX = document.body.scrollLeft;
    } else {
      if( document.documentElement &&
          ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      	//IE6 standards compliant mode
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
      }
    }
  }
}


function GetWinSize() {
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else {
    if( document.documentElement &&
        ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    } else {
      if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
    }
  }
 return true;
}

//
// On ouvre une fenetre a un emplacement donne
//
function setLyr(obj,lyr,evt)
{
	var newX;
	var newY;

	winList[lyr].restore();

	if(obj != "")
	{
		var newX = findPosX(obj);
		var newY = findPosY(obj);
	}
	else
	{	
	  if (browser.isIE) {
	    newX = window.event.clientX - 10;
	    newY = window.event.clientY - 10;
	  }
	  if (browser.isNS) {
	    newX = evt.pageX - 10;
	    newY = evt.pageY - 10;
	  }
	}
	
	var x = getObj(lyr);
	x.style.top = newY + 'px';
	x.style.left = newX + 'px';

 	GetWinSize();
 	getScrollXY();
 
 	var W = x.offsetWidth;
 	var H = x.offsetHeight;
 
// 	if(newX + parseInt(W) > myWidth) x.style.left = myWidth - parseInt(W) - 50;
// 	else x.style.left = newX;

 	if(newX + parseInt(W) > myWidth + scrOfX) x.style.left = myWidth  + scrOfX - parseInt(W) - 50;
 	else x.style.left = newX;

 	if(newY + parseInt(H) > myHeight + scrOfY) x.style.top = myHeight + scrOfY -parseInt(H);
	else x.style.top = newY+0;

	winList[lyr].open();
	winList[lyr].makeActive();
}

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 curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = 0;
var marked_row_status_dossier = 0;
var marked_row_status_code_produits = 0;
var old_marked_cell = null; 
var old_marked_color = null;
/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theStatusDossier, theStatusProduits, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row = theRowNum;
            marked_row_status_dossier = theStatusDossier;
            marked_row_status_code_produits = theStatusProduits;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row) == 'undefined' || marked_row != theRowNum || marked_row == null)) 
             {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row = theRowNum;
            marked_row_status_dossier = theStatusDossier;
            marked_row_status_code_produits = theStatusProduits;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row = (typeof(marked_row) == 'undefined' || marked_row == 0 || marked_row == null)
                                  ? theRowNum
                                  : 0;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
            	if(old_marked_cell && old_marked_row != marked_row) {old_marked_cell[c].setAttribute('bgcolor', old_marked_color, 0);}
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    if (theAction == 'click' && newColor)
    {
    	old_marked_cell = theCells;
    	old_marked_row = marked_row;
    	old_marked_color = theDefaultColor;
    }

//	window.status = theRowNum + " : " + marked_row;

    return true;
} // end of the 'setPointer()' function


/////////////////////////
//
// Popup Layer
//
/////////////////////////

var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

function popdscroff(){
if (DboX.style.visibility == "visible")
DboX.style.visibility = "hidden";
}

function popon(e,origine,A,B,C,D,E)
{
 var contHTML = "<TABLE BORDER=0>";
 if(origine == 1) // Calendrier Poseurs
 {
  if(D == "1")
  {DboX.style.background = "#FFFFAA";}
  else if(D == "2")
  {DboX.style.background = "#FFAAAA";}
  else
  {DboX.style.background = "#AAFFAA";}
  contHTML += "<TR><TD nowrap=on VALIGN=TOP>Jour : </TD><TD class=dbox><b>"+A+"</b></TD></TR>";
  contHTML += "<TR><TD nowrap=on VALIGN=TOP>Poseur : </TD><TD class=dbox><b>"+B+"</b></TD></TR>";
 }
 else if(origine == 2) // SAV General
 {
  contHTML += "<TR><TD nowrap=on VALIGN=TOP><B>Client</B> : </TD><TD class=dbox><FONT>"+C+"</FONT></TD></TR>";
  contHTML += "<TR><TD nowrap=on VALIGN=TOP><B>Proprio</B> : </TD><TD class=dbox><FONT>"+D+"</FONT></TD></TR>";
  contHTML += "<TR><TD nowrap=on VALIGN=TOP><B>Ville</B> : </TD><TD class=dbox><FONT>"+E+"</FONT></TD></TR>";
  contHTML += "<TR><TD nowrap=on VALIGN=TOP><B>Probleme</B> : </TD><TD class=dbox><FONT>"+A+"</FONT></TD></TR>";
  if(B != ""){contHTML += "<TR><TD nowrap=on VALIGN=TOP><B>Observations</B> : </TD><TD class=dbox><FONT>"+B+"</FONT></TD></TR>";}
 }
 else if(origine == 3) // Observation_pose
 {
  contHTML += "<TR><TD nowrap=on VALIGN=TOP><B>Observations</B> : </TD><TD class=dbox><FONT>"+A+"</FONT></TD></TR>";
 }
 else if(origine == 4) // SAV Dossier
 {
  contHTML += "<TR><TD nowrap=on VALIGN=TOP><B>Probleme</B> : </TD><TD class=dbox><FONT>"+A+"</FONT></TD></TR>";
  if(B != ""){contHTML += "<TR><TD nowrap=on VALIGN=TOP><B>Observations</B> : </TD><TD class=dbox><FONT>"+B+"</FONT></TD></TR>";}
 }
 else if(origine == 5) // Reponse recherche
 {
  contHTML += A;
 }
 contHTML += "</TABLE>";

 DboX.innerHTML = contHTML;

 GetWinSize();
 getScrollXY();
 
// window.status = scrOfX + " : " + scrOfY + " | " + myWidth + " : " + myHeight  + " | " + tempX + " : " + tempY ;
 
 if(tempX + parseInt(DboX.style.width) > myWidth + scrOfX - 50) DboX.style.left = myWidth + scrOfX - parseInt(DboX.style.width) - 50;
// if(tempX + parseInt(DboX.style.width) > myWidth - 50) DboX.style.left = myWidth - parseInt(DboX.style.width) - 50;
 else DboX.style.left = tempX - 10;

 if(tempY + parseInt(DboX.offsetHeight) > myHeight + scrOfY - 50 ) DboX.style.top = tempY-parseInt(DboX.offsetHeight);
 else DboX.style.top = tempY+15;
 DboX.style.visibility = "visible";
}

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  tempX += 10;
  return true
} 

/////////////////////////
//
// Function permettant de communiquer avec le serveur
// Simulant un socket
//
/////////////////////////
var IFrameObj = new Array(); // our IFrame object
function callToServer(id,URL) {
  if (!document.createElement) {return true};
  var IFrameDoc;
  if (!IFrameObj[id] && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame'+id);
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj[id] = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj[id] = document.frames['RSIFrame'+id];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame'+id+'" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj[id] = new Object();
      IFrameObj[id].document = new Object();
      IFrameObj[id].document.location = new Object();
      IFrameObj[id].document.location.iframe = document.getElementById('RSIFrame'+id);
      IFrameObj[id].document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj[id].contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer('+id+')',10);
    return false;
  }
  
  if (IFrameObj[id].contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj[id].contentDocument; 
  } else if (IFrameObj[id].contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj[id].contentWindow.document;
  } else if (IFrameObj[id].document) {
    // For IE5
    IFrameDoc = IFrameObj[id].document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}


function verification_date(chaineDate)
{
   if(chaineDate.value == ""){return;}
		
   var ladate = (chaineDate.value).split("/");
 
   if(ladate.length != 3){return;}

   if(ladate[2].length < 4)
   {
   	ladate[2] = parseInt(ladate[2]) + 2000;
   }

   chaineDate.value =  ladate[0]+"/"+ladate[1]+"/"+ladate[2];
	
}

function submitenter(myfield,e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (keycode == 13)
	{
//		myfield.form.submit();
		return false;
	}
	else
	return true;
}

function sp_get_checkList(f)
{
	liste = "";
	if($("listeID") == null) return liste;

	if(!f.listeID.length) return "|"+f.listeID.value;

	var len = f.listeID.length;

	for(i=0;i<len;i++)
	{
		if(!f.listeID[i].checked)
		{
			liste += "|-"+f.listeID[i].value;
		}
		else
		{
			liste += "|"+f.listeID[i].value;
		}
	}
	return liste;	
}

function sp_changeto(page,order)
{
	f = document.form_liste_soc;
	f.cs_page.value = page; 
	f.cs_order.value = order;

	f.cs_check.value =  sp_get_checkList(f);
	f.submit();
}

function sp_modifChoix(T)
{
	if(T.checked)
	{
		sp_NbChoix++;
		if(sp_NbChoix == 1001)
		{
			yuiAlert(alertMsg+"A la fin de votre s&eacute;lection, vous ne devrez pas d&eacute;passer le seuil de "+Flimite[FOrigine]+" soci&eacute;t&eacute;s par candidature");

			if(mode_allopass == 1)
			{
				T.checked = false;
				sp_NbChoix--;
			}
		}
	}
	else sp_NbChoix--;
	

	sp_monPere.cs_nb_check.value = sp_NbChoix;
	sp_monPere.cs_check.value = sp_get_checkList(document.form_liste_soc);
	document.getElementById("meschoix").innerHTML = sp_NbChoix;
	document.getElementById("meschoix_pre").style.display = 'none';

	if(document.getElementById("meschoix2") != null)
	{
		document.getElementById("meschoix2").innerHTML = sp_NbChoix;
	}
}

function sp_check_this2(obj)
{
	sp_check_this(obj);
	ecriture_code_allopass();
}


function sp_check_this(obj)
{
	checkbox = obj.getElementsByTagName( 'input' )[0];
	checkbox.checked = !checkbox.checked;
	sp_modifChoix(checkbox);
  if ( !checkbox.checked )
  {
		obj.className += ' marked';
  }
  else
  {
		obj.className = obj.className.replace(' marked', '');
  }

	if(mode_allopass == 1) ecriture_code_allopass();
}

function sp_annule_check(obj)
{
	obj.checked = !obj.checked;
}

function validerChoixGlobal(session)
{
	changeSeuil = document.getElementById("changeSeuilChoix").options[document.getElementById("changeSeuilChoix").selectedIndex].value;
	changeMax = document.getElementById("changeNombreChoix").options[document.getElementById("changeNombreChoix").selectedIndex].value;
	$("div_table_societe").innerHTML = "";
 	exec_ajax("liste_reponse_s_js.php","spsession="+session+"&cs_debut="+changeSeuil+"&cs_fin="+changeMax,"get");
 	return;
}

function aide_meschoix(choix)
{
	var Msg = "Pour assurer la fluidit&eacute; de l'envoi de votre candidature, vous devez vous limiter &agrave; 1000 soci&eacute;t&eacute;s &agrave; la fois.<br /><br />";
	Msg += "Sponteo a initialement s&eacute;lectionn&eacute; pour vous les "+choix+" premi&egrave;res soci&eacute;t&eacute;s de votre r&eacute;sultat de recherche.<br /><br />";
	Msg += "Vous pouvez modifier la s&eacute;lection : <br />";
	Msg += "&nbsp;&nbsp;- manuellement, avec les cases &agrave; cocher sur la liste affich&eacute;e ;<br />";
	Msg += "&nbsp;&nbsp;- par lots, en vous aidant des listes de s&eacute;lection se trouvant en bas &agrave; droite.";
	yuiAlert(Msg);
}

function gestionChangeSeuilChoix(max)
{
	obj1 = document.getElementById("changeSeuilChoix");
	obj2 = document.getElementById("changeNombreChoix");
	if(!obj1) return;

	nb = obj1.options[obj1.selectedIndex].value;

	for(i=1;i<=obj2.options.length;i++)
	{
			val = 100*i-1+parseInt(nb);
			if(val > max) {val = max;}
			obj2.options[i-1].value = val;
			obj2.options[i-1].text = val;
	}
}


function gestionChangePageChoix(session,cs_page)
{
	liste_soc = sp_get_checkList(document.form_liste_soc);
	$("div_table_societe").innerHTML = "";
 	exec_ajax("liste_reponse_s_js.php","spsession="+session+"&cs_page="+cs_page+"&cs_check="+liste_soc,"get");
}

function sp_footer()
{
	var hauteur = 130;
	if(!IE) hauteur = 110;
//	if (!IE) {			document.getElementById("bloc_conteneur").style.height = (document.body.scrollHeight-100)+"px";}
//	document.getElementById("pied").style.visibility = "visible";


//	document.getElementById("pied").style.display = "none";
//	document.getElementById("bloc_conteneur").style.height = "0px";
//	document.getElementById("bloc_conteneur").style.height = (document.body.scrollHeight-hauteur)+"px";
//	document.getElementById("pied").style.display = "";
//	document.getElementById("pied").style.visibility = "visible";

}

function ecritBouton(Titre,Func,Nom)
{
	document.writeln("<table border='0' cellpadding='0' cellspacing='0' onClick='"+Func+"'><tr><td id='"+Nom+"L' class='bouton_base_l bouton_l'></td><td id='"+Nom+"C' class='bouton_base_c bouton_c' nowrap>"+Titre+"</td><td id='"+Nom+"R' class='bouton_base_r bouton_r'></td></tr></table>");
}

function ecritBoutonClass(Titre,Func,Nom,Clase)
{
	document.writeln("<table border='0' cellpadding='0' cellspacing='0' onClick='"+Func+"'><tr><td id='"+Nom+"L' class='bouton_base_l bouton_l"+Clase+"'></td><td id='"+Nom+"C' class='bouton_base_c bouton_c"+Clase+"' nowrap>"+Titre+"</td><td id='"+Nom+"R' class='bouton_base_r bouton_r"+Clase+"'></td></tr></table>");
}

var BoutonEtatTimer = Array();

function activeBouton(Nom)
{
	
	BoutonEtat[Nom] = 1;
	document.getElementById(Nom+"L").className="bouton_base_l bouton_l";
	document.getElementById(Nom+"C").className="bouton_base_c bouton_c";
	document.getElementById(Nom+"R").className="bouton_base_r bouton_r";
	return;
}

function activeBoutonAnimate(Nom)
{
	BoutonEtat[Nom] = 0;
	BoutonAnimation(Nom);
	return;
}

function BoutonAnimation(Nom)
{
	if(BoutonEtatTimer[Nom] > 0)
	{
		clearTimeout(BoutonEtatTimer[Nom]);
		BoutonEtatTimer[Nom] = 0;
	}
	if(BoutonEtat[Nom] == 1)
	{
		BoutonEtat[Nom] = 0;
		document.getElementById(Nom+"L").className="bouton_base_l bouton_gris_l";
		document.getElementById(Nom+"C").className="bouton_base_c bouton_gris_c";
		document.getElementById(Nom+"R").className="bouton_base_r bouton_gris_r";
		BoutonEtatTimer[Nom] = setTimeout('BoutonAnimation("'+Nom+'")',100);
	}
	else if(BoutonEtat[Nom] == 0)
	{
		activeBouton(Nom);
		BoutonEtatTimer[Nom] = setTimeout('BoutonAnimation("'+Nom+'")',500);
	}
}	

function desactiveBouton(Nom)
{
	BoutonEtat[Nom] = -1;
	document.getElementById(Nom+"L").className="bouton_base_l bouton_gris_l";
	document.getElementById(Nom+"C").className="bouton_base_c bouton_gris_c";
	document.getElementById(Nom+"R").className="bouton_base_r bouton_gris_r";
	return;
}

function ecritTab(Titre,Nom,Func)
{
	document.writeln("<td class='tab_l' id='TAB"+Nom+"[0]' onClick='"+Func+"' onMouseOver='changeTabM(this,1)' onMouseOut='changeTabM(this,0)'></td>");
	document.writeln("<td class='tab_c' id='TAB"+Nom+"[1]' onClick='"+Func+"' onMouseOver='changeTabM(this,1)' onMouseOut='changeTabM(this,0)'>"+Titre+"</td>");
	document.writeln("<td class='tab_r' id='TAB"+Nom+"[2]' onClick='"+Func+"' onMouseOver='changeTabM(this,1)' onMouseOut='changeTabM(this,0)'></td>");
}

function changeTab(n)
{
		if(TabActif == n) {return;}

		var old = TabActif;
		TabActif = n;

		if(old != null)
		{
			changeTabM(document.getElementById("TAB"+old+"[0]"),0);
		}

		if(TabActif != null)
		{
			changeTabM(document.getElementById("TAB"+TabActif+"[0]"),1);
		}
}

function changeTabM(T,M)
{
	var name = T.id.substr(0,T.id.length-3);
	if(M == 1)
	{
		document.getElementById(name+"[0]").className = "tab_l tab_l_on";
		document.getElementById(name+"[1]").className = "tab_c tab_c_on";
		document.getElementById(name+"[2]").className = "tab_r tab_r_on";
	}
	else
	{
		if(name != "TAB"+TabActif)
		{
			document.getElementById(name+"[0]").className = "tab_l";
			document.getElementById(name+"[1]").className = "tab_c";
			document.getElementById(name+"[2]").className = "tab_r";
		}
	}
}

function exec_ajax(url,param,method)
{

	if($("reponse_ajax") == null)
	{
		window.noeud_element = document.createElement("div");
	  noeud_element.setAttribute("id","reponse_ajax");
		noeud_element.style.visibility = "hidden";
		noeud_element.style.display = "none";
  	document.body.appendChild(noeud_element);
	}

	new Ajax.Updater($("reponse_ajax"),url,
		{ method:method,
			parameters:param,
			evalScripts: true,
			insertion: Insertion.Bottom
			}
		);
}

function exec_ajax_js(myurl,param,method)
{
	new Ajax.Request(myurl,
		{ method:method,
			parameters:param
			}
		);
}

function ecriture_cadre_haut(origine,w,h)
{
	if(origine == 'ORIGINE') {origine = 'emplois';}
	document.writeln("<table cellpadding='0px' cellspacing='0px' style='padding:0px; width: "+w+"px; height: "+h+"px;'>");
	document.writeln("<tr>");
	document.writeln("<td class='paddingN' valign='top' align='left' style='height:9px;width:9px'><img src='Img/chg_"+origine+".gif' /></td>");
	document.writeln("<td class='border_top paddingN' style='width:"+(w-15)+"px;height:9px;'><div style='font-size:1px'>&nbsp;</div></td>");
	document.writeln("<td class='paddingN' valign='top' align='right' style='height:9px;width:9px'><img src='Img/chd_"+origine+".gif' /></td>");
	document.writeln("<td class='paddingN' rowspan='2' valign='top' align='right' style='background:#d9d9d9;width:5px'><img src='Img/chd_gris.gif' /></td>");
	document.writeln("</tr>");
	document.writeln("<tr>");
	document.writeln("<td class='border_left paddingN'>&nbsp;</td>");
	document.writeln("<td align='center'>");
}

function ecriture_cadre_bas(origine)
{
	if(origine == 'ORIGINE') {origine = 'emplois';}
	document.writeln("</td>");
	document.writeln("<td class='border_right paddingN'>&nbsp;</td>");
	document.writeln("</tr>");
	document.writeln("<tr>");
	document.writeln("<td class='paddingN' valign='bottom' style='height:9px;width:9px;'><img src='Img/cbg_"+origine+".gif'></td>");
	document.writeln("<td class='border_bottom paddingN' style='height:9px;'><div style='font-size:1px'>&nbsp;</div></td>");
	document.writeln("<td class='paddingN' valign='bottom' style='height:9px;width:9px'><img src='Img/cbd_"+origine+".gif'></td>");
	document.writeln("<td class='paddingN' valign='bottom' style='background:#d9d9D9;width:5px'><img src='Img/cbda_gris.gif'></td>");
	document.writeln("</tr>");
	document.writeln("<tr>");
	document.writeln("<td class='paddingN' colspan='2' valign='bottom' style='background:#d9d9D9;'><img src='Img/cbg_gris.gif'></td>");
	document.writeln("<td class='paddingN' colspan='2' valign='bottom' style='height:4px;'><img src='Img/cbd_gris.gif'></td>");
	document.writeln("</tr>");
	document.writeln("</table>");
	return;
}

function aideAutomatique(T)
{
	modeAideAuto = !T.checked;
	document.getElementById("checkAideAuto").checked = T.checked;
	exec_ajax_js("aide_automatique.php?mode="+modeAideAuto,'',"get");
// 	callToServer(4,"aide_automatique.php?mode="+modeAideAuto);
	return;
}

var CheckAstuces = "<br /><br /><form><input class='check2' type='checkbox' onClick='aideAutomatique(this)'> Desactiver l'aide automatique</form>";

function makeBoutons(Boutons,Box)
{
	var i = 0;
	var code = "<br /><br /><form style='text-align:right'>";
	if(Boutons.length == 1) Boutons[0]["isDefault"] = true;
	while(Boutons[i])
	{
		if(i > 0) code += " ";
		code += '<input type="button" value="'+Boutons[i]["text"]+'"';
		if(Boutons[i]["handler"] == "NO")
		{
			code += ' onClick="'+Box+'.hide();"';
		}
		else
		{
			code += ' onClick="'+Boutons[i]["handler"]+'"';	
		}
		if(Boutons[i]["isDefault"]) code += " class='inputDefault' id='defaultRep'";
		code += '>';
		i++;	
	}	
	return code;
}

function yuiAlert(Mesg)
{
		var codeBoutons = makeBoutons(([ { text:"OK", handler:"NO"}]),"YAHOO.example.simpledialog.confirm");

		YAHOO.example.simpledialog.confirm.setHeader("<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td><img src='Img/dia-hd-tl.gif'></td><td align='center' style='border-bottom:1px solid #aaaaaa; background :transparent url(Img/dia-hd.gif)' width=99%><img src='Img/sponteo_p.gif'></td><td><img src='Img/dia-hd-tr.gif'></td></tr></table>"); 
		YAHOO.example.simpledialog.confirm.setBody("<table><tr><td>"+Mesg+"</td></tr></table>"+codeBoutons);
		YAHOO.example.simpledialog.confirm.setFooter("<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td><img src='Img/dia-ft-bl.gif'></td><td align='center' style='background :transparent url(Img/dia-ft.gif)' width=99%></td><td><img src='Img/dia-ft-br.gif'></td></tr></table>"); 
		YAHOO.example.simpledialog.confirm.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_WARN);

		YAHOO.example.simpledialog.confirm.show();
		if(document.getElementById("defaultRep")) document.getElementById("defaultRep").focus();

}

function yuiConfirm(Mesg,Boutons,Mode)
{
		if(typeof(Mode) == 'undefined') Mode = 0;
		if(!modeAideAuto && Mode == 0) return;
		var codeBoutons = makeBoutons(Boutons,"YAHOO.example.simpledialog.confirm");
		YAHOO.example.simpledialog.confirm.setHeader("<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td><img src='Img/dia-hd-tl.gif'></td><td align='center' style='border-bottom:1px solid #aaaaaa; background :transparent url(Img/dia-hd.gif)' width=99%><img src='Img/sponteo_p.gif'></td><td><img src='Img/dia-hd-tr.gif'></td></tr></table>"); 
		MsgBody = "<table><tr><td>"+Mesg+"</td></tr></table>";
		if(Mode == 0) MsgBody += CheckAstuces;
		MsgBody += codeBoutons;
		YAHOO.example.simpledialog.confirm.setBody(MsgBody);
		YAHOO.example.simpledialog.confirm.setFooter("<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td><img src='Img/dia-ft-bl.gif'></td><td align='center' style='background :transparent url(Img/dia-ft.gif)' width=99%></td><td><img src='Img/dia-ft-br.gif'></td></tr></table>"); 
		YAHOO.example.simpledialog.confirm.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_TIP);
		YAHOO.example.simpledialog.confirm.show();
		if(document.getElementById("defaultRep")) document.getElementById("defaultRep").focus();
}

function yuiTip(Mesg)
{
		if(!modeAideAuto) return;
		var codeBoutons = makeBoutons(([ { text:"OK", handler:"NO"}]),"YAHOO.example.simpledialog.confirm");
		YAHOO.example.simpledialog.confirm.setHeader("<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td><img src='Img/dia-hd-tl.gif'></td><td align='center' style='border-bottom:1px solid #aaaaaa; background :transparent url(Img/dia-hd.gif)' width=99%><img src='Img/sponteo_p.gif'></td><td><img src='Img/dia-hd-tr.gif'></td></tr></table>"); 
		YAHOO.example.simpledialog.confirm.setBody("<table><tr><td>"+Mesg+"</td></tr></table>"+CheckAstuces+codeBoutons);
		YAHOO.example.simpledialog.confirm.setFooter("<table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td><img src='Img/dia-ft-bl.gif'></td><td align='center' style='background :transparent url(Img/dia-ft.gif)' width=99%></td><td><img src='Img/dia-ft-br.gif'></td></tr></table>"); 
		YAHOO.example.simpledialog.confirm.cfg.setProperty("icon",YAHOO.widget.SimpleDialog.ICON_TIP);
		YAHOO.example.simpledialog.confirm.show();
		if(document.getElementById("defaultRep")) document.getElementById("defaultRep").focus();
}
