/****************************************************************/
/*							                                    */
/*					FONCTIONS javascript						*/
/*					                                            */
/****************************************************************/
var base_url = 'http://www.sogec-reporting.com/';
//var base_url = 'http://192.168.1.59/';
function verif_numeric(variable)
	{
	var exp = new RegExp("^[0-9.]+$","g");
	return exp.test(variable);
	} 

function findPos(objj) 
	{
	if (document.getElementById(objj))
		{
		var curleft = document.getElementById(objj).offsetLeft ;
		var curtop = document.getElementById(objj).offsetTop ;
		return {x:curleft,y:curtop};
		}
		else{
		return {x:0,y:0};// normalement le cas ne se présente pas
		}
	}

/****************************************************/
/*							                        */
/*		Fonction des listes déroulantes				*/
/*					                                */
/****************************************************/
function pos_liste()
	{
	
	var position = findPos('logoutil');
	var pos2 = findPos('global');
	//alert(position['y']);
	var y2 = parseInt(position['y'])+10;
	var x2 = parseInt(pos2['x'])+5;
	if (document.getElementById('liste_compte1'))
		{
		document.getElementById('liste_compte1').style.top = (position['y']-10)+'px';
		document.getElementById('liste_compte1').style.left = x2+'px';
		}
	if (document.getElementById('liste_compte2'))
		{
		document.getElementById('liste_compte2').style.top = y2+'px';
		document.getElementById('liste_compte2').style.left = x2+'px';
		}
	
	if(document.getElementById('bare_recherche'))
		{
		//var position = findPos('bare_recherche');
		//var pos2 = findPos('barre_recherche');
		var pos3 = findPos('global');
		//alert(pos3['x']);
		var y3 = parseInt(pos3['y'])+213;
		var x3 = parseInt(pos3['x'])+605;
		if (navigator.appName=="Microsoft Internet Explorer"){
			x3 = (x3+15);} 

		if (document.getElementById('liste_recherche'))
			{
			if (document.getElementById('menu'))
				{
				document.getElementById('liste_recherche').style.top = y3+'px';
				document.getElementById('liste_recherche').style.left = x3+'px';
				}
			else
				{
				document.getElementById('liste_recherche').style.top = y3+'px';
				document.getElementById('liste_recherche').style.left = x3-137+'px';
				}			
			}
		}
	}

function action_cpt(iddiv,divclose,limitheight)
	{
	if (document.getElementById(iddiv).style.display == 'none')
		{
		var act = 'block';
		
		if (limitheight == 1)
			{
			document.getElementById(iddiv).style.height = 300+'px';
			}
		}
	else
		{
		var act = 'none';
		}
		if (document.getElementById(divclose))
			{
			document.getElementById(divclose).style.display = 'none';
			}
		document.getElementById(iddiv).style.display = act;
		//alert(document.getElementById(iddiv).style.display);
		 //setTimeout("xx()",1000);
		// alert('test'+document.getElementById('liste_fabricant').style.height);
	}
/*function xx(){
alert('test'+document.getElementById('liste_fabricant').style.height);
}*/
function ferme_listes()
	{
	if (document.getElementById('liste_client'))
		{
		document.getElementById('liste_client').style.display = 'none';
		}
	if (document.getElementById('liste_fabricant'))
		{
		document.getElementById('liste_fabricant').style.display = 'none';
		}
	if (document.getElementById('bare_recherche'))
		{
		fermer_liste_recherche();
		}
	}

function survole_liste(etat,id)
	{
	var color = "transparent";
	var col = "#000000";
	var weight = "normal";
	if (etat == 1)
		{
		var color = "#EA6BA5";
		var col = "#ffffff";
		var weight = "normal";
		}
	document.getElementById(id).style.backgroundColor = color;
	document.getElementById(id).style.color = col;
	document.getElementById(id).style.fontWeight = weight;
	}
function survole_rec(etat,id)
	{
	var color = "transparent";
	var col = "#000000";
	var weight = "normal";
	if (etat == 1)
		{
		var color = "#EA6BA5";
		var col = "#ffffff";
		var weight = "normal";
		}
	document.getElementById(id).style.backgroundColor = color;
	document.getElementById(id).style.color = col;
	document.getElementById(id).style.fontWeight = weight;
	}
function rem_inputcpt(iddiv)
	{	
	var nb = iddiv.length;
	var nom = iddiv.substring(1,nb);
	//alert(nom);
	var content = document.getElementById(iddiv).innerHTML;
	document.getElementById('l_compteclient').value = content;
	document.getElementById('compteclient').value = nom;
	}
function rem_inputsscpt(iddiv)
	{
	var nb = iddiv.length;
	var nom = iddiv.substring(1,nb);
	/*if (iddiv == 'f0')
		{
		var valeur = 0;
		}
	else
		{
		var valeur = iddiv;
		}*/
	var content = document.getElementById(iddiv).innerHTML;
	document.getElementById('l_sscompteclient').value = content;
	document.getElementById('sscompteclient').value = nom;
	}
function resize_page(elem)
	{
	var choix = 0;
	var centre 		= findPos('bascentre');
	var autretop	= 0;
	var global 		= findPos('global');
	var glob_x		= global['x'];
	var centretop 	= centre['y'];
	
	//var menubas 	= findPos('bascentre');
	//var menubastop 	= centre['y'];

	var maxheight	= Math.max(centretop,autretop);/*centretop;*/
	//alert(maxheight);
	if (navigator.appName!="Microsoft Internet Explorer")
		{
		var globalajust 	= maxheight + 60;
		}
	else{
		var globalajust 	= maxheight + 330;
		}
	//alert(globalajust+'px');
	document.getElementById('global').style.height = globalajust+'px';//retourx;
	}

function affiche_tree()
	{
	document.getElementById("tree").className="voistree";
	document.getElementById("message").className="voispas";
	}

function cache_tree()
	{
	document.getElementById("tree").className="voispas";
	document.getElementById("message").className="voismessage";
	}

function GetId(id)
	{
	return document.getElementById(id);
	}

var i=false; // La variable i nous dit si la bulle est visible ou non

function move(e) 
	{
	if(i) 
		{// 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 + 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=20+event.x+document.documentElement.scrollLeft+"px";
				//GetId("curseur").style.top=10+event.y+document.documentElement.scrollTop+"px";
				GetId("curseur").style.left=20+window.event.clientX+document.documentElement.scrollLeft+"px";//+document.documentElement.scrollLeft+"px";
				GetId("curseur").style.top=10+window.event.clientY+document.documentElement.scrollTop+"px";//+document.documentElement.scrollTop+"px";
		/*		} 
			else 
				{
				GetId("curseur").style.left=20+event.x+document.body.scrollLeft+"px";
				GetId("curseur").style.top=10+event.y+document.body.scrollTop+"px";
			}*/
		}
	}
 }

function montreb(text) 
	{
	GetId("curseur").style.visibility="visible"; // Si il est cacher (la verif n'est qu'une securité) on le rend visible.
	GetId("curseur").innerHTML = text; // Cette fonction est a améliorer, il parait qu'elle n'est pas valide (mais elle marche)
	i=true;
	}

function cacheb() 
	{
	if(i==true) 
		{
		GetId("curseur").style.visibility="hidden"; // Si la bulle etais visible on la cache
		i=false;
		}
	}

var ajustement = 0;
function ouvrir_graphens(taille)
	{
	if (ajustement == 0)
		{
		document.getElementById('graphens').style.height = taille+'px';
		var glob = document.getElementById('global').style.height;
		glob = glob.substring(0,3);
		taille = parseInt(taille);
		glob = parseInt(glob);
		glob = glob+taille-200;
		var global 		= findPos('global');
		var glob_x		= global['x'];
		//alert(glob+'px');
		document.getElementById('global').style.height = glob+'px';//retourx;/**/
		ajustement = 1;
		}
	}
function fermer_graphens()
	{
	if (ajustement == 1)
		{
		
		taille=200;
		var hautgraph = document.getElementById('graphens').style.height;
		hautgraph = hautgraph.substring(0,3);
		hautgraph = parseInt(hautgraph);
		document.getElementById('graphens').style.height = taille+'px';
		var glob = document.getElementById('global').style.height;
		glob = glob.substring(0,4);
		taille = parseInt(taille);
		glob = parseInt(glob);
		glob = glob-hautgraph+200;
		var global 		= findPos('global');
		var glob_x		= global['x'];
	//	alert(glob+'px');
		document.getElementById('global').style.height = glob+'px';//retourx;/**/
		ajustement = 0;
		}
	}

document.onmousemove=move;

function tdb(afficher)
	{
	for (var boucle=1;boucle<15;boucle++)
		{
		if (('L'+boucle == afficher) && document.getElementById('L'+boucle) )
			{
			
			document.getElementById(afficher).style.display="block";
			/*document.getElementById(afficher).style.visibility="visible";*/
			document.getElementById('fond'+afficher+'').style.backgroundImage = 'url("' + base_url + 'images/interface/bout_tab2_m.jpg")';
			document.getElementById('LG'+boucle).style.backgroundImage = 'url("' + base_url + 'images/interface/bout_tab2_g.jpg")';
			document.getElementById('LD'+boucle).style.backgroundImage = 'url("' + base_url + 'images/interface/bout_tab2_d.jpg")';
			
			document.getElementById('lien'+afficher+'').style.color = '#E6308E';
			}
		else if (document.getElementById('fondL'+boucle) && ('L'+boucle != afficher) && document.getElementById('L'+boucle) )
			{
			
			document.getElementById('L'+boucle).style.display="none";
			/*document.getElementById(afficher).style.visibility="hidden";*/
			document.getElementById('fondL'+boucle+'').style.backgroundImage = 'url("' + base_url + 'images/interface/bout_tab_m.jpg")';
			document.getElementById('LG'+boucle).style.backgroundImage = 'url("' + base_url + 'images/interface/bout_tab_g.jpg")';
			document.getElementById('LD'+boucle).style.backgroundImage = 'url("' + base_url + 'images/interface/bout_tab_d.jpg")';
			document.getElementById('lienL'+boucle+'').style.color = '#FFFFFF';
			}
		}
	}
var xhr = null; 
function getXhr()
{
     if(window.XMLHttpRequest)xhr = new XMLHttpRequest(); 
else if(window.ActiveXObject)
  { 
  try{
     xhr = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) { 
		try {
			xhr = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e1) {
        xhr = null;
		}
	}
  }
else 
  {
  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
  xhr = false; 
  } 
}

function traitement_alertes(type,num,genre,etat)
{
	if (num != 0){
		getXhr();
		xhr.onreadystatechange = function()
			{
			 if(xhr.readyState == 4 && xhr.status == 200)
			 {
			  if (document.getElementById('alerte_titre'))
				{
				document.getElementById('alerte_titre').innerHTML= "SERVICES";
				}
			 }
			}
		if (document.getElementById('alerte_titre'))
			{
			document.getElementById('alerte_titre').innerHTML= "Chargement...";
			}
		xhr.open("GET",base_url + "index.php/bilan/ajax_alertes/"+type+"/"+num+"/"+genre+"/"+etat+"/"+new Date()*Math.random()+"/",false);
		xhr.send(null);
		}
	else{ 
		getXhr();
		xhr.onreadystatechange = function()
			{
			 if(xhr.readyState == 4 && xhr.status == 200)
			 {
			  document.innerHTML=xhr.responseText;
			 }
			}
		xhr.open("GET","<?=$base_url?>index.php/bilan/ajax_alertes/"+type+"/"+num+"/"+genre+"/"+etat+"/"+new Date()*Math.random()+"/",false);
		xhr.send(null);
	}
}

function action_alertes(elem,type,num,genre,divattente)
	{
	//alert(document.alertes.elements[elem].checked+'/'+elem);
	if (document.alertes.elements[elem].checked==true)
		{
		alert('Votre alerte a bien été enregistrée. Dès que nous aurons validé votre demande, vous serez informé de vos alertes sur votre page d\'accueil. \n\nVous pouvez consulter et/ou modifier la liste de vos alertes dans la rubrique Mon compte / Mes alertes');
		
		traitement_alertes(type,num,genre,'FALSE');
document.getElementById(divattente).style.visibility = "visible";
		}
	else if(document.alertes.elements[elem].checked==false)
		{
		alert('Alerte supprimée!');
		document.getElementById(divattente).style.visibility = "hidden";
		traitement_alertes(type,num,genre,'TRUE');	
		}
	
	}

function somme_ope()
	{
	var cpt=0;
	var remsom = 0;
	var budsom = 0;
	while(document.getElementById('div_rem_'+cpt))
		{
		if (document.coche_op.elements['check_'+cpt].checked == true)
		{
		if (verif_numeric(document.getElementById('div_rem_'+cpt).innerHTML))
			{
			var remval = document.getElementById('div_rem_'+cpt).innerHTML;
			remval = parseInt(remval);
			remsom += remval;

			var budval = document.getElementById('div_bud_'+cpt).innerHTML;
			budval = parseInt(budval);
			budsom += budval;
			}
		}
		cpt++;
		}
	document.getElementById('div_rem').innerHTML = remsom;
	document.getElementById('div_bud').innerHTML = budsom;
	}


function popup(url) 
	{
	 var width  = 405;
	 var height = 320;
	 var left   = (screen.width  - width)/2;
	 var top    = (screen.height - height)/2;
	 var params = 'width='+width+', height='+height;
	 params += ', top='+top+', left='+left;
	 params += ', directories=no';
	 params += ', location=no';
	 params += ', menubar=no';
	 params += ', resizable=no';
	 params += ', scrollbars=yes';
	 params += ', status=no';
	 params += ', toolbar=no';
	 newwin=window.open(url,'windowname5', params);
	 if (window.focus) {newwin.focus()}
	 return false;
	}
function loadimg()
	{
	scroll(0,0);
	document.getElementById('loading').style.display = "block";
	}
function loading()
	{
	document.getElementById('imgload').src= base_url + "images/barredechargement0.gif";
	setTimeout("loadimg()",500);
	}

function close_div(loc,divnum,parent)
	{
	if (loc == "g")
		{
		if(document.getElementById('div_g'+divnum).style.display == "block")// FERMETURE
			{	
			document.getElementById('div_g'+divnum).style.display = "none";
			document.getElementById('gimg'+divnum).src = base_url + "images/interface/aplus.gif";
			document.getElementById('gdos'+divnum).src = base_url + "images/icones/d_closed.gif";
			var i = 1;
			while (document.getElementById('div_sg'+divnum+'0'+i))
				{
				document.getElementById('div_sg'+divnum+'0'+i).style.display = "none";
				document.getElementById('sgimg'+divnum+'0'+i).src = base_url + "images/interface/aplus.gif";
				document.getElementById('sgdos'+divnum+'0'+i).src = base_url + "images/icones/d_closed.gif";
				i++;
				}
			}
		else// OUVERTURE
			{
			document.getElementById('div_g'+divnum).style.display = "block";
			document.getElementById('gimg'+divnum).src = base_url + "images/interface/aminus.gif";
			document.getElementById('gdos'+divnum).src = base_url + "images/icones/d_open.gif";
			}
		}
	else if(loc == "sg")
		{
		if(document.getElementById('div_sg'+parent+'0'+divnum).style.display == "block")// FERMETURE
			{	
			document.getElementById('div_sg'+parent+'0'+divnum).style.display = "none";
			document.getElementById('sgimg'+parent+'0'+divnum).src = base_url + "images/interface/aplus.gif";
			document.getElementById('sgdos'+parent+'0'+divnum).src = base_url + "images/icones/d_closed.gif";
			}
		else// OUVERTURE
			{
			document.getElementById('div_sg'+parent+'0'+divnum).style.display = "block";
			document.getElementById('sgimg'+parent+'0'+divnum).src = base_url + "images/interface/aminus.gif";
			document.getElementById('sgdos'+parent+'0'+divnum).src = base_url + "images/icones/d_open.gif";
			}
		}
	else if(loc == "ssg")
		{
		//alert('ssgimg'+parent+'0'+divnum);
		if(document.getElementById('div_ssg'+parent+'0'+divnum).style.display == "block")// FERMETURE
			{	
			document.getElementById('div_ssg'+parent+'0'+divnum).style.display = "none";
			document.getElementById('ssgimg'+parent+'0'+divnum).src = base_url + "images/interface/aplus.gif";
			document.getElementById('ssgdos'+parent+'0'+divnum).src = base_url + "images/icones/d_closed.gif";
			}
		else// OUVERTURE
			{
			document.getElementById('div_ssg'+parent+'0'+divnum).style.display = "block";
			document.getElementById('ssgimg'+parent+'0'+divnum).src = base_url + "images/interface/aminus.gif";
			document.getElementById('ssgdos'+parent+'0'+divnum).src = base_url + "images/icones/d_open.gif";
			}
		}

	resize_page('pieddepage');
	}

function apercu_br(chemin,w,h)
	{
	if (screen.width>w && screen.height>h)
		{
		var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		var TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
		window.open(base_url+"index.php/bons/miniaturez/"+chemin+"/"+w+"/"+h+"/","_blank","menubar=0,status=no, scrollbars=yes, location=no, width="+w+", height="+h+", left="+LeftPosition+", top="+TopPosition+"").window.focus();
		}
	else
		{
		var LeftPosition = (screen.width) ? (screen.width-(w/2))/2 : 0;
		var TopPosition = (screen.height) ? (screen.height-(h/2))/2 : 0; 
		window.open(base_url+"index.php/bons/miniaturez/"+chemin+"/"+w+"/"+h+"/","_blank","menubar=0,status=no, scrollbars=yes, location=no, width="+(w/2)+", height="+(h/2)+", left="+LeftPosition+", top="+TopPosition+"").window.focus();
		}
	/*document.getElementById('menu_bas').innerHTML = '<div style="position:absolute;top:100px;left:100px;width:100px;height:100px;overflow:auto;">test<div>';*/
	}

function apercu_webbr(chemin,w,h)
	{
	if (screen.width>w && screen.height>h)
		{
		var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		var TopPosition = (screen.height) ? (screen.height-h)/2 : 0; 
		window.open(base_url+"index.php/bons/miniaturew/"+chemin+"/"+w+"/"+h+"/","_blank","menubar=0,status=no, scrollbars=yes, location=no, width="+w+", height="+h+", left="+LeftPosition+", top="+TopPosition+"").window.focus();
		}
	else
		{
		var LeftPosition = (screen.width) ? (screen.width-(w/2))/2 : 0;
		var TopPosition = (screen.height) ? (screen.height-(h/2))/2 : 0; 
		window.open(base_url+"index.php/bons/miniaturew/"+chemin+"/"+w+"/"+h+"/","_blank","menubar=0,status=no, scrollbars=yes, location=no, width="+(w/2)+", height="+(h/2)+", left="+LeftPosition+", top="+TopPosition+"").window.focus();
		}
	/*document.getElementById('menu_bas').innerHTML = '<div style="position:absolute;top:100px;left:100px;width:100px;height:100px;overflow:auto;">test<div>';*/
	}

// REGIONS PERSONNALISEES

function focusradio(ind,nom)
	{
	/*alert(ind);*/
	var num=0;
	var signal = 0;
	while(document.getElementById('radiofocus_'+num))
		{
		signal = 1;
		document.getElementById('radiofocus_'+num).style.backgroundColor = "#FFFFFF";
		document.getElementById('namefocus_'+num).style.backgroundColor = "#FFFFFF";
		document.getElementById('deptfocus_'+num).style.backgroundColor = "#FFFFFF";
		document.getElementById('colfocus_'+num).style.backgroundColor = "#FFFFFF";
		document.getElementById('supfocus_'+num).style.backgroundColor = "#FFFFFF";
		document.getElementById('validerfocus_'+num).style.backgroundColor = "#FFFFFF";
		num++;
		}
	
	document.getElementById('radiofocus_200').style.backgroundColor = "#FFFFFF";
	document.getElementById('namefocus_200').style.backgroundColor = "#FFFFFF";
	document.getElementById('deptfocus_200').style.backgroundColor = "#FFFFFF";
	document.getElementById('colfocus_200').style.backgroundColor = "#FFFFFF";

	document.getElementById('validerfocus_200').style.backgroundColor = "#FFFFFF";

	document.getElementById('radiofocus_'+ind).style.backgroundColor = "#F3AB8D";
	document.getElementById('namefocus_'+ind).style.backgroundColor = "#F3AB8D";
	document.getElementById('deptfocus_'+ind).style.backgroundColor = "#F3AB8D";
	document.getElementById('colfocus_'+ind).style.backgroundColor = "#F3AB8D";
	if (ind != '200')
		{
		document.getElementById('supfocus_'+ind).style.backgroundColor = "#F3AB8D";
		}
	else
		{
		Today = new Date;
		Jour = Today.getDate();
		Mois = (Today.getMonth())+1;
		Annee = Today.getFullYear();
		Hour = Today.getHours();
		Min = Today.getMinutes();
		nom = document.getElementById('nomderegion_200').value;
		if (nom == '')
			{
			document.getElementById('nomderegion_200').value = 'Region '+num+' ('+Jour+'-'+Mois+'-'+Annee+' a '+Hour+':'+Min+')';
			nom = 'Region '+num;
			}
		if (signal == 0)
			{
			document.form_rp.rp_focus.checked = "true";
			}
		else
			{
			document.form_rp.rp_focus[num].checked = "true";
			}
		
		
		}
	//
	document.getElementById('validerfocus_'+ind).style.backgroundColor = "#F3AB8D";
	document.getElementById('info_focus').value = nom;
	}

function aj_dept(num)
	{
	var cpt = 0;
	var deja = false;
	var select = '100';
	
	// Vérifie sur quelle région est le focus
	while (document.form_rp.rp_focus[cpt])
		{
		
		if (document.form_rp.rp_focus[cpt].checked)
			{
			select = cpt;
			}
		cpt++;
		}
	if (!document.form_rp.rp_focus[1])
	{
		cpt = 1;
	}
	cpt--;
	
	//alert(document.form_rp.rp_focus.checked);
	if ((document.form_rp.rp_focus.checked)||(document.form_rp.rp_focus[cpt].checked))
		{
		select = 200;
		}
		// Si pas de section, il ne se passe rien, sinon:
		if (select != "100")
			{
			if (confirm('Etes vous sûr de vouloir ajouter cette région?'))
				{

				// Vérifie si le dept existe déjà dans la liste (prend le contenu du hidden qui lui est attaché)
				var hidden = document.getElementById('chaine_dept_'+select).value;
				var hidden_split = hidden.split(',');
				var lh = hidden_split.length;
				for(i=0;i<lh;i++)
					{
					if (num == hidden_split[i])
						{
						deja = true;
						}
					}
				// Si le dept n'existe pas dans la liste:
				if (deja == false)
					{
					// Récupère le contenu du div liste des régions
					var contenu = document.getElementById('groupe_dept_'+select).innerHTML;
					contenu += '<div onmouseover="montreb(\'Cliquez pour supprimer ce département\')" onmouseout="cacheb();" style="cursor:pointer;padding:2px;margin-left:2px;width:15px;height:15px;float:left;border:solid 1px #5F646B;background-color:#FFFFFF;" onclick="sup_dept(\''+num+'\',\''+select+'\');">'+num+'</div>';
					
					// Nouveau div créé:
					document.getElementById('groupe_dept_'+select).innerHTML = contenu;
					
					if (hidden == '')
						{
						var virgule = '';
						}
					else
						{
						var virgule = ',';
						}
					// Nouveau contenu du hidden de type: 45,21,45,87
					document.getElementById('chaine_dept_'+select).value = hidden+virgule+num;
					}
				}
		
			}
		else
			{
			alert('Vous devez cliquer sur une de vos régions personnalisées ou sur Créer une nouvelle région pour ajouter des départements.');
			}
	}


function sup_dept(num,select)
	{
	if (confirm('Etes vous sûr de vouloir supprimer cette région?'))
		{
		var contenu = '';
		var remhid = '';
		// Récupère la liste des départements dans le hidden
		var hidden = document.getElementById('chaine_dept_'+select).value;
		var hidden_split = hidden.split(',');
		var lh = hidden_split.length;
		for(i=0;i<lh;i++)
			{
			// vérifie dept correspond à élément balayé
			if (num != hidden_split[i])
				{
				// Construction des div
				contenu += '<div onmouseover="montreb(\'Cliquez pour supprimer ce département\')" onmouseout="cacheb();" style="cursor:pointer;padding:2px;margin-left:2px;width:15px;height:15px;float:left;border:solid 1px #5F646B;background-color:#FFFFFF;" onclick="sup_dept(\''+hidden_split[i]+'\',\''+select+'\');">'+hidden_split[i]+'</div>';
				remhid += hidden_split[i]+',';
				}
			}
			var tm = remhid.length-1;
		remhid = remhid.substring(0,tm);
		document.getElementById('chaine_dept_'+select).value = remhid;
		document.getElementById('groupe_dept_'+select).innerHTML = contenu;
		}

	}/**/

// CONVERSION HEX <-> RGB
function HexToR(h) {return parseInt((cutHex(h)).substring(0,2),16)}
function HexToG(h) {return parseInt((cutHex(h)).substring(2,4),16)}
function HexToB(h) {return parseInt((cutHex(h)).substring(4,6),16)}
function cutHex(h) {return (h.charAt(0)=="#") ? h.substring(1,7):h}	

function RGBtoHex(R,G,B) 
	{
	return toHex(R)+toHex(G)+toHex(B)
	}

function toHex(N) 
	{
	if (N==null) return "00";
	N=parseInt(N); if (N==0 || isNaN(N)) return "00";
	N=Math.max(0,N); N=Math.min(N,255); N=Math.round(N);
	return "0123456789ABCDEF".charAt((N-N%16)/16)
		+ "0123456789ABCDEF".charAt(N%16);
	}

function utf8_encode ( str_data ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)        
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
 
    str_data = str_data.replace(/\r\n/g,"\n");
    var tmp_arr = [], ac = 0;
 
    for (var n = 0; n < str_data.length; n++) {
        var c = str_data.charCodeAt(n);
        if (c < 128) {
            tmp_arr[ac++] = String.fromCharCode(c);
        } else if((c > 127) && (c < 2048)) {
            tmp_arr[ac++] = String.fromCharCode((c >> 6) | 192);
            tmp_arr[ac++] = String.fromCharCode((c & 63) | 128);
        } else {
            tmp_arr[ac++] = String.fromCharCode((c >> 12) | 224);
            tmp_arr[ac++] = String.fromCharCode(((c >> 6) & 63) | 128);
            tmp_arr[ac++] = String.fromCharCode((c & 63) | 128);
        }
    }
    
    return tmp_arr.join('');
}

function aj_reg_perso(numero,action)
	{
		var num = 100;
	// Récupération des informations :
	var nom		= document.getElementById('nomderegion_'+numero).value;
	//alert(nom);
	nom = AccentToNoAccent(nom);
	var hidden	= document.getElementById('chaine_dept_'+numero).value;
	var couleur = document.getElementById('myhexcode_'+numero).value;
	var Rgb = HexToR(couleur);
	var rGb = HexToG(couleur);
	var rgB = HexToB(couleur);
	var Lacouleur = Rgb+','+rGb+','+rgB;
	//alert(numero+'/'+nom+'/'+hidden+'/'+Rgb+','+rGb+','+rgB);
		if (num != 0)
			{
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
				//document.location.reload(true);
				//document.getElementById('alerte_titre').innerHTML= "SERVICES";
				 }
				}
			//document.getElementById('alerte_titre').innerHTML= "Chargement...";
			xhr.open("GET",base_url + "index.php/compte/ajax_aj_region/"+nom+"/"+hidden+"/"+Lacouleur+"/"+action+"/"+new Date()*Math.random()+"/",false);
			xhr.send(null);
			}
		else
			{ 
			//
			//
			}
	}


// DEMANDE DE CODE : MAJ liste sous rayon
function maj_ssrayon()
	{
		
	var num = 100;
	var rayon	= document.codeform.prod_rayon.options[document.codeform.prod_rayon.selectedIndex].value;
		if (num == '100'){
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
					var content = xhr.responseText;
					document.getElementById('liste_ssrayon').innerHTML=content;
				 }
				}
			document.getElementById('liste_ssrayon').innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
			xhr.open("GET",base_url + "index.php/complements_br/trouve_ssrayon/"+rayon+"/"+new Date()*Math.random()+"/",true);
			xhr.send(null);
			}
		else{ 
		}
		resize_page('pieddepage');
	}

// DEMANDE DE CODE : MAJ liste fabricant
function maj_list_fab(client,fabricant,appactive)
	{
	//	alert('i'+fabricant);
	var num = 100;
	if (!verif_numeric(client))
		{
		var fab	= document.codeform.list_cli.options[document.codeform.list_cli.selectedIndex].value;
		}
	else
		{
		var fab = client;
	
		}
	
	
		if (num == '100'){
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
					var content = xhr.responseText;
					//alert(content);
					document.getElementById('list_fab').innerHTML=content;
					
					maj_list_app(fabricant,appactive);
				 }
				}
			document.getElementById('list_fab').innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
			xhr.open("GET",base_url + "index.php/complements_br/list_fab/"+fab+"/"+fabricant+"/"+new Date()*Math.random()+"/",true);
			xhr.send(null);
			}
		else{ 
		}
		resize_page('pieddepage');
	}

var dern = 1;
function denierCout(sfabricant)
	{
	//	alert(sfabricant);
	if (typeof(sfabricant)!='undefined'){
	var fab = sfabricant.toString();
	var len = fab.length;
	//alert('longueur : '+len);
	var strnum = '';
	for (var u=len;u<5;u++)
		{
		strnum += '0';
		}
	//	alert('final : '+strnum);
	strnum += fab;
	fab = strnum;
	//alert('maintenance en cours (00457A)');
	getXhr();
	xhr.onreadystatechange = function()
		{
		//alert('test'+xhr.readyState);
		 if(xhr.readyState == 4 && xhr.status == 200)
		 {
			//alert('maintenance en cours');
			var ddd = xhr.responseText;
			if (ddd == "") ddd = 0;
			dern = ddd;
			//alert(dern);
		 }
		}
	//document.getElementById('list_app').innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
	xhr.open("GET",base_url + "index.php/complements_br/dernier_cout/"+fab+"/",true);
	xhr.send(null);
	}	}

// DEMANDE DE CODE : MAJ liste appartenance
function maj_list_app(fab,apact)
	{
	//alert(document.codeform.list_fab.options[document.codeform.list_fab.selectedIndex].value);
	var num = 100;
	if (!verif_numeric(fab))
		{
		var app	= document.codeform.list_fab.options[document.codeform.list_fab.selectedIndex].value;
		//alert(app);
		}
	else
		{
		var app = fab;
		}
//alert(app);
		if (num == '100'){
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
					var content = xhr.responseText;
					document.getElementById('list_app').innerHTML=content;
					//alert(app);
					nouv_appf();
					maj_list_ma(fab);
					//alert(dern+'_t');
					//app	= document.codeform.list_fab.options[document.codeform.list_fab.selectedIndex].value;
					//alert(app);
					setTimeout('denierCout(\''+app+'\')',2000);
					//alert('dernier cout = '+dern);
				 }
				}
			document.getElementById('list_app').innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
			xhr.open("GET",base_url + "index.php/complements_br/list_app/"+app+"/"+apact+"/"+new Date()*Math.random()+"/",true);
			xhr.send(null);
			}
		else{ 
		}
		
		resize_page('pieddepage');
	}
	

function nouv_appf()
	{
	//var etat = document.codeform.nouv_app.disabled;
	var etat = document.codeform.list_app.options[document.codeform.list_app.selectedIndex].value;
	//alert(etat);
	if (etat == '0')
		{
		document.codeform.nouv_app.disabled = '';
		}	
	else
		{
		document.codeform.nouv_app.disabled = 'disabled';
		document.codeform.nouv_app.value = '';
		}
	}

// DEMANDE DE CODE : MAJ liste MARQUES
function maj_list_ma(fab)
	{
	var num = 100;
		if (fab == "")
			var ma	= document.codeform.list_fab.options[document.codeform.list_fab.selectedIndex].value;
		else
			var ma = fab;
		if (num == '100'){
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
					var content = xhr.responseText;
					document.getElementById('list_ma').innerHTML=content;
					maj_ssrayon();
				 }
				}
			document.getElementById('list_ma').innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
			xhr.open("GET",base_url + "index.php/complements_br/list_ma/"+ma+"/"+new Date()*Math.random()+"/",true);
			xhr.send(null);
			}
		else{ 
		}
		resize_page('pieddepage');
	}


function maj_nom_alerte(ope,typope,retour)
	{
	//alert(document.codeform.list_fab.options[document.codeform.list_fab.selectedIndex].value);
	var nom = document.getElementById('al_nom'+retour).value;
	//alert(nom);
	var num = 100;
		if (num == '100'){
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
					//var content = xhr.responseText;
					document.getElementById('charge_nom'+retour).innerHTML='';
				 }
				}
			document.getElementById('charge_nom'+retour).innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
			xhr.open("GET",base_url + "index.php/compte/nom_alerte/"+ope+"/"+typope+"/"+nom+"/"+new Date()*Math.random()+"/",true);
			xhr.send(null);
			}
		else{ 
		}
	}

function maj_mail_alerte(ope,typope,retour)
	{
	//alert(document.codeform.list_fab.options[document.codeform.list_fab.selectedIndex].value);
	var nom = document.getElementById('al_mail'+retour).value;
	var num = 100;
		if (num == '100'){
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
					//var content = xhr.responseText;
					document.getElementById('charge_mail'+retour).innerHTML='';
				 }
				}
			//	alert(ope+'/'+typope+'/'+nom);
			document.getElementById('charge_mail'+retour).innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
			xhr.open("GET",base_url + "index.php/compte/mail_alerte/"+ope+"/"+typope+"/"+nom+"/"+new Date()*Math.random()+"/",true);
			xhr.send(null);
			}
		else{ 
		}
	}

function maj_confmail_alerte(ope,typope,thiselem)
	{
	//alert(document.codeform.list_fab.options[document.codeform.list_fab.selectedIndex].value);
	if (document.alertes.elements[thiselem].checked==true)
		{
		var nom = 1;
		}
	else
		{
		var nom = 0;
		}
	
	//var nom = document.getElementById('al_mail'+retour).value;
	var num = 100;
		if (num == '100'){
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
					//var content = xhr.responseText;
					alert('Modification effectuée');
					//document.getElementById('charge_mail'+retour).value=content;
				 }
				}
			//document.getElementById('charge_mail'+retour).innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
			xhr.open("GET",base_url + "index.php/compte/confmail_alerte/"+ope+"/"+typope+"/"+nom+"/"+new Date()*Math.random()+"/",true);
			xhr.send(null);
			}
		else{ 
		}
	}


	function focus_list()
		{	
		if (document.list_selection.choix_list[0].checked == true)
			{
			//alert('1');
			document.list_selection.nouv_liste.disabled=true;
			}
		else
			{
			document.list_selection.nouvelle_selection.value = "";
			document.list_selection.nouv_liste.disabled=false;
			}
		}

	function replaceAll(str, search, repl) 
		{
		while (str.indexOf(search) != -1)
		str = str.replace(search, repl);
		return str;
		}

	function AccentToNoAccent(str) 
		{
		var norm = new Array('À','Á','Â','Ã','Ä','Å','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï', 'Ð','Ñ','Ò','Ó','Ô','Õ','Ö','Ø','Ù','Ú','Û','Ü','Ý','Þ','ß', 'à','á','â','ã','ä','å','æ','ç','è','é','ê','ë','ì','í','î','ï','ð','ñ', 'ò','ó','ô','õ','ö','ø','ù','ú','û','ü','ý','ý','þ','ÿ','\'','"','/','\\');
		var spec = new Array('A','A','A','A','A','A','A','C','E','E','E','E','I','I','I','I', 'D','N','O','O','O','0','O','O','U','U','U','U','Y','b','s', 'a','a','a','a','a','a','a','c','e','e','e','e','i','i','i','i','d','n', 'o','o','o','o','o','o','u','u','u','u','y','y','b','y', '', '', '-', '-');
		for (var i = 0; i < spec.length; i++)
		str = replaceAll(str, norm[i], spec[i]);
		return str;
		} 

	function maj_selection(cdsogec,reffab,libcou,datedeb,datefin,dept,fab)
		{
		//alert(document.codeform.list_fab.options[document.codeform.list_fab.selectedIndex].value);
		if (document.list_selection.choix_list[0].checked == true)
			{
			var nom = document.list_selection.nouvelle_selection.value;
			}
		else
			{
			//alert(document.list_selection.nouv_liste.value);
			var nom = document.list_selection.nouv_liste.value;
			}
		nom = AccentToNoAccent(nom);
		//alert(nom);
		var num = 100;
			if (nom != ''){
				getXhr();
				xhr.onreadystatechange = function()
					{
					 if(xhr.readyState == 4 && xhr.status == 200)
					 {
						//var content = xhr.responseText;
						//document.getElementById('charge_nom'+retour).innerHTML='';
						//window.close();
						alert('Votre sélection a été ajoutée');
						document.getElementById('subliste').style.display = "none";
						document.getElementById('div_select').style.display = "none";
					 }
					}
				//document.getElementById('div_select').innerHTML= "Chargement en cours, la fenêtre se fermera automatiquement.<br /><br /><img src=\"" + base_url + "images/barredechargement2.gif\"  />";
				xhr.open("GET",base_url + "index.php/compte/maj_select/"+nom+"/"+cdsogec+"/"+reffab+"/"+libcou+"/"+datedeb+"/"+datefin+"/"+dept+"/"+fab+"/"+new Date()*Math.random()+"/",true);
				xhr.send(null);
				}
			else{ 
				alert('Vous devez écrire le nom d\'une liste.');
			}
		}

function affiche_divselect()
	{
	if (document.getElementById('div_select').style.display == "none")
		{
		document.getElementById('div_select').style.display = "block";
		document.getElementById('subliste').style.display = "block";
		}
	else
		{
		document.getElementById('div_select').style.display = "none";
		document.getElementById('subliste').style.display = "none";
		}
	
	}

function sup_selection(code,nomselection)
	{

		getXhr();
		xhr.onreadystatechange = function()
			{
			 if(xhr.readyState == 4 && xhr.status == 200)
			 {
				//var content = xhr.responseText;
				
				document.location.reload(true);
			 }
			}
		//	alert(ope+'/'+typope+'/'+nom);
		//document.getElementById('charge_mail'+retour).innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
		//alert(base_url + "index.php/compte/sup_selection/"+code+"/"+nomselection+"/"+(new Date()*Math.random()));
		xhr.open("GET", base_url + "index.php/compte/sup_selection/"+code+"/"+nomselection+"/"+(new Date()*Math.random()),true);
		xhr.send(null);


	}


		
	/****************************************************/
	/*							                        */
	/*			CALENDRIER POUR CHAMPS DATES			*/
	/*					                                */
	/****************************************************/
		
		moisX=["","Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"];
		JourM=["Di","Lu","Ma","Me","Je","Ve","Sa"];
		
		var fermable_microcal=true;
		var select_old= null;
		var select_old2= null;
		var startWeek=0;//debut de la semaine 0=dim,1=lun,...
		var jourPause={0:true,6:true}; //jour de pause de la semaine
		var jourFeriee={"1-1":"jour an","1-5":"fête du travail","8-5":"armistice","14-7":"fête nationale","15-8":"ascencion","1-11":"armistice","11-11":"toussain","25-12":"noel"};
		
		//structure la date
		function strucDate(dateX)
		{return {"pos":dateX.getDay(),"jour":dateX.getDate(),"mois":dateX.getMonth()+1,"annee":dateX.getFullYear()};}
		
		
		var dateS= strucDate(new Date());//date Selectionné
		var dnow= strucDate(new Date());//date actuelle
		
		
		//retourne le ième jour du 1er du mois
		function premJourMois(mois,annee)
		{return (new Date(annee,mois-1,1).getDay());}
		//retourne le jour max du mois
		function JmaxMois(mois,annee)
		{return (new Date(annee,mois,0).getDate());}
		
		
		/* Test une date si elle est correct...spécial killer*/
		function testTypeDate(dateEntree)
		{
		tst=false;
		try
		{rc=dateEntree.split("/");nd=new Date(rc[2],(rc[1]-1),rc[0]);
		tst=(rc[2]>1800&&rc[2]<2200&&rc[2]==nd.getFullYear()&&rc[1]==(nd.getMonth()+1)&&rc[0]==nd.getDate());
		} catch(e) {}
		return tst;
		}
		
		//selection de la zone avec la souris
		function choix(koi,code)
		{
		if (code)
		{ select_old= koi.style.background;
		select_old2= koi.style.color;
		   koi.style.background ='#e6308e';
			koi.style.color = '#ffffff';
		}
		else
		{
		koi.style.background =select_old;
		koi.style.color =select_old2;
		}
		}
		
		
		function testTravail(oldX,xx,jj,mm,aa)
		{
		styleX="font-family:Tahoma;font-size:10px;text-align:center;";
		styleX+=(oldX)?"":"color:#e0e0e0;";
		styleX+="cursor:pointer;border-right:1px #e0e0e0 solid;border-bottom:1px #e0e0e0 solid;";
		if (jourPause[xx]||jourFeriee[jj+"-"+mm]!=null) styleX+="background:#f0f0f0;";
		if (jj==dnow.jour&&mm==dnow.mois&&aa==dnow.annee) styleX+="border:2px red solid;";
		return styleX;
		}
		
		//test si année bissextile
		function bissextile(annee) {
		return (annee%4==0 && annee %100!=0 || annee%400==0);
		}
		
		//Retourne le nombre de jour depuis le 1er janvier (num de semaine)
		function nbJAnnee(dateX){
		var nb_mois=[,0,31,59,90,120,151,181,212,243,273,304,334];
		j=dateX.jour ; m=dateX.mois ; a=dateX.annee;
		nb=nb_mois[m]+j-1 ;
		if (bissextile(a) && m>2) nb++;
		return nb;
		}
		
		//affiche le calendrier
		function view_microcal(actif,ki,source,mxS,axS)
		{
		if (actif)
		{
		//decalage du mois su on clique sur -/+
		if (mxS!=-1)
		{
		clearTimeout(cc);
		document.getElementById(ki).focus();
		fermable_microcal=true;
		dateS.mois=mxS;
		dateS.annee=axS;
		if (dateS.mois<1) {dateS.annee--;dateS.mois+=12;}
		if (dateS.mois>12) {dateS.annee++;dateS.mois-=12;}
		}
		//init
		Dstart=(premJourMois(dateS.mois,dateS.annee)+7-startWeek)%7;
		jmaxi=JmaxMois(dateS.mois,dateS.annee);
		jmaxiAvant=JmaxMois((dateS.mois-1),dateS.annee);
		//si on veux ajouter le numero de la semaine ...
		//idxWeek=parseInt(nbJAnnee(strucDate(new Date(dateS.mois+'-01-'+dateS.annee)))/7,10)+1;
		
		ymaxi=parseInt((jmaxi+Dstart+1)/7,10);
		
		//generation du tableau
		//--entête
		htm="<table><tr style='font-size:10px;font-family:Tahoma;text-align:center;'>";
		htm+="<td style='cursor:pointer;' onclick=\"view_microcal(true,'"+ki+"','"+source+"',"+(dateS.mois-1)+","+dateS.annee+");\"><<</td>";
		htm+="<td colspan='5'> <b> "+moisX[dateS.mois]+"</b>&nbsp;"+dateS.annee+"</td>";
		htm+="<td style='cursor:pointer;' onclick=\"view_microcal(true,'"+ki+"','"+source+"',"+(dateS.mois+1)+","+dateS.annee+")\">>></td></tr>";
		//--corps
		htm+="<tr>";
		//affichage des jours DLMMJVS
		for (x=0;x<7;x++)
		htm+="<td style='font-size:10px;font-family:Tahoma;'><b>"+JourM[(x+startWeek)%7]+"</b></td>";
		htm+="</tr>"
		
		
		//------------------------
		for (y=0;y<=ymaxi;y++)
		{
		htm+="<tr>";
		for (x=0;x<7;x++)
		{
		idxP=y*7+x-Dstart+1; //numero du jour
		aa=dateS.annee;
		xx=(x+startWeek)%7;
		//jour du mois précedent
		if (idxP<=0)
		{
		jj=idxP+jmaxiAvant;mm=dateS.mois-1;
		if (mm==0)
		{mm=12;aa--;}
		htm+="<td style='"+testTravail(false,xx,jj,mm,aa)+"' onmouseover='choix(this,true)' onmouseout='choix(this,false)' onclick=\""+ki+".value='"+((jj<10)?"0":"")+jj+"/"+((mm<10)?"0":"")+mm+"/"+aa+"';"+ki+".style.color='black';\">"+jj+"</td>";
		}
		else if (idxP>jmaxi) //jour du mois suivant
		{
		jj=idxP-jmaxi;mm=dateS.mois+1;
		if (mm==13)
		{mm=1;aa++;}
		
		htm+="<td style='"+testTravail(false,xx,jj,mm,aa)+"' onmouseover='choix(this,true)' onmouseout='choix(this,false)' onclick=\"document.getElementById('"+ki+"').value='"+((jj<10)?"0":"")+jj+"/"+((mm<10)?"0":"")+mm+"/"+aa+"';document.getElementById('"+ki+"').style.color='black';\">"+jj+"</td>";}
		else //jour du mois en cours
		{
		jj=idxP;mm=dateS.mois;
		htm+="<td style='"+testTravail(true,xx,jj,mm,aa)+"' onmouseover='choix(this,true)' onmouseout='choix(this,false)' onclick=\"document.getElementById('"+ki+"').value='"+((jj<10)?"0":"")+jj+"/"+((mm<10)?"0":"")+mm+"/"+aa+"';document.getElementById('"+ki+"').style.color='black';\">"+jj+"</td>";}
		}
		htm+="</tr>"
		}//-------------------------
		htm+="</table>"
		//affiche le tableau
		document.getElementById(source).innerHTML=htm;
		document.getElementById(source).style.visibility="";
		} else
		{
		//ferme le calendrier
		if (fermable_microcal)
		   cc=setTimeout("document.getElementById('"+source+"').style.visibility='hidden'",500);
		}
		}
		
var xhr4 = null; 

function getXhr4()
{
     if(window.XMLHttpRequest)xhr4 = new XMLHttpRequest(); 
else if(window.ActiveXObject)
  { 
  try{
     xhr4 = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (e) { 
		try {
			xhr4 = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e1) {
        xhr4 = null;
		}
	}
  }
else 
  {
  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
  xhr4 = false; 
  } 
}
    
 function cherche()
	{
		getXhr4();
			xhr4.onreadystatechange = function()
				{
				 if(xhr4.readyState == 4 && xhr4.status == 200)
				 {
				document.getElementById('liste_recherche').style.visibility = 'visible';
				document.getElementById('liste_recherche').innerHTML=xhr4.responseText;
				 }
				}
			document.getElementById('liste_recherche').style.visibility = 'visible';
			document.getElementById('liste_recherche').innerHTML='aide à la recherche en cours...';
			xhr4.open("GET",base_url+"index.php/rechercher/aide/"+document.getElementById('search').value+"/",true);
			//xhr4.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=iso-8859-1");
			xhr4.send(null);
	}

function renseigner(titre)
{
document.getElementById('liste_recherche').style.visibility = 'visible';
document.getElementById('search').value = titre;
var temp = titre.split(" -");
document.getElementById('search2').value = temp[0];
document.getElementById('liste_recherche').style.visibility = 'hidden';

}

function valider()
{
if (document.getElementById('search2').value.length == 0)
	{
	document.getElementById('search2').value = document.getElementById('search').value;
	}

}

function fermer_liste_recherche()
{
	if (document.getElementById('liste_recherche'))
		{
		document.getElementById('liste_recherche').style.visibility = 'hidden';
		}	
}

function colorier(elt)
	{
	document.getElementById(elt).className = 'lienaideon';
	}

function decolorier(elt)
{
document.getElementById(elt).className = 'lienaideoff';
}

// ----------------------------------------------------------------------------------------

function focus_selection(div)
	{
	if (document.getElementById(div).style.display == "none")
		{
		document.getElementById(div).style.display = "block";
		}
	else
		{
		document.getElementById(div).style.display = "none";
		}
		resize_page('pieddepage');
	}
// GADGET ------------------------------------------------------------------------//
function div_attente()
	{
	var i;
	var carre = '<div style="width:60px;height:60px;">';
	for(i = 1;i<=9;i++)
		{
		carre += '<div id="d'+i+'" style="width:18px;height:18px;float:left;background-color:#E6308E;margin-left:1px;margin-top:1px;">&nbsp;</div>';	
		}
	carre += '</div>';
	document.getElementById('attentea').innerHTML = carre;
	var rrand = rand(1,9);
	setTimeout("passe_attente('d"+rrand+"')",10);
	
	}
function passe_attente(id)
	{
	var macouleur;
	if (document.getElementById(id).style.backgroundColor == '#E6308E') macouleur = '#ffffff';
	else macouleur = '#E6308E';
	document.getElementById(id).style.backgroundColor = macouleur;
	}
//---------------------------------------------------------------------------------//

function rand( min, max ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Leslie Hoare
    // *     example 1: rand(1, 1);
    // *     returns 1: 1
 
    if( max ) 
    	{
        return Math.floor(Math.random() * (max - min + 1)) + min;
    	} 
    else 
    	{
        return Math.floor(Math.random() * (min + 1));
    	}
	}

function rech_mod_diff()
	{
		
	var num = 100;
	var type;
	var meka = document.rech_av.mecanique.options[document.rech_av.mecanique.selectedIndex].value;
	if (meka == 'BR') type = 'BR';
	else if (meka == '0') type="0";
	else type = 'ODR';
		
		if (num == '100'){
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
				 	//alert('retour');
					var content = xhr.responseText;
					document.getElementById('div_mod_diff').innerHTML=content;
				 }
				}
			document.getElementById('div_mod_diff').innerHTML= "<img src=\"" + base_url + "images/barredechargement2.gif\"  />";
			xhr.open("GET",base_url + "index.php/rechercher/mod_diff_ajax/"+type+"/"+new Date()*Math.random()+"/",true);
			xhr.send(null);
			}
		else{ 
		}
		resize_page('pieddepage');
	}	
	
function date_auto(duree)
	{
	var num = 0;
	if ((document.getElementById('ope_dateconso').value != '') && (document.getElementById('ope_datedist').value == '') && (etat_loader == 1))	
		num = 100;
	var date = document.getElementById('ope_dateconso').value;
	date = date.replace('/','-');
	date = date.replace('/','-');
		if (num == '100'){
			getXhr();
			xhr.onreadystatechange = function()
				{
				 if(xhr.readyState == 4 && xhr.status == 200)
				 {
				 	//alert('retour');
					var content = xhr.responseText;
					document.getElementById('ope_datedist').value=content;
					document.getElementById('date_loader').innerHTML = "&nbsp;";
					etat_loader = 1;
				 }
				}
			etat_loader = 0;
			document.getElementById('date_loader').innerHTML = '<img src="'+base_url+'images/ajax-loader.gif" width="25" height="25" border="0" />';
			xhr.open("GET",base_url + "index.php/spec/date_plus_temps/"+date+"/"+duree+"/",true);
			xhr.send(null);
			}
		else{ 
		}
		resize_page('pieddepage');
	}		
	
