var requete;
function creerRequete()
{
    try
    {
        /* On tente de créer un objet XmlHTTPRequest */
        requete = new XMLHttpRequest();
    }
    catch (microsoft)
    {
        /* Microsoft utilisant une autre technique, on essays de créer un objet ActiveX */
        try
        {
            requete = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch(autremicrosoft)
        {
            /* La première méthode a échoué, on en teste une seconde */
            try
            {
                requete = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch(echec)
            {
                /* À ce stade, aucune méthode ne fonctionne... mettez donc votre navigateur à jour ;) */
                requete = null;
            }
        }
    }
    if(requete == null)
    {
        alert('Impossible de créer l\'objet requête,\nVotre navigateur ne semble pas supporter les object XMLHttpRequest.');
    }
}

function upload_page(page){

	document.getElementById('update_load').innerHTML = '<center><font color="#e59654"><b>En cours de chargement</b></font><br/><img src="/assistant/ajax-loader.gif" alt="load"/><br/><br/></center>';

	var bool = 1;
	var choix1 = document.forms['tri_config'].choix1.value;
	var choix2 = document.forms['tri_config'].choix2.value;
	var choix3 = document.forms['tri_config'].choix3.value;
	var choix4 = document.forms['tri_config'].choix4.value;;


	var url = '/assistant/update_liste.php?choix1='+choix1+'&choix2='+choix2+'&choix3='+choix3+'&choix4='+choix4+'&page='+page;

	
	

	creerRequete();
	requete.open('GET', url, true);	
	
	requete.onreadystatechange = function(){
      
        	if(requete.readyState == 4){
         		if(requete.status == 200){
            			document.getElementById('update').innerHTML = requete.responseText;
         		}
      		}		
   	};
   
   	requete.send(null);

	window.scrollTo(10,350);
	

}

function upload(numero_choix,ref_critere){

	document.getElementById('update_load').innerHTML = '<center><font color="#e59654"><b>En cours de chargement</b></font><br/><img src="/assistant/ajax-loader.gif" alt="load"/><br/><br/></center>';

	var bool = 1;
	var choix1 = document.forms['tri_config'].choix1.value;
	var choix2 = document.forms['tri_config'].choix2.value;
	var choix3 = document.forms['tri_config'].choix3.value;
	var choix4 = document.forms['tri_config'].choix4.value;;

	if(numero_choix ==1){
		var ref_critere_c1 = document.forms['tri_config'].choix1.value;
		if(ref_critere == 1999){
			document.forms['tri_config'].choix1.value = 0;
			choix1 = 0;
			bool = 0;		
		}
		else if(ref_critere_c1 == ref_critere){
			document.forms['tri_config'].choix1.value = 0;
			choix1 = 0;
			bool = 0;
		}
		else{
			document.forms['tri_config'].choix1.value = ref_critere;
			choix1 = ref_critere;
		}
		if(ref_critere_c1 != 0) document.getElementById('div_tri_td_'+ref_critere_c1).style.backgroundColor="#fff";
	}
	else if(numero_choix ==2){
		var ref_critere_c2 = document.forms['tri_config'].choix2.value;
		if(ref_critere == 2999){
			document.forms['tri_config'].choix2.value = 0;
			choix2 = 0;
			bool = 0;		
		}
		else if(ref_critere_c2 == ref_critere){
	
			document.forms['tri_config'].choix2.value = 0;
			choix2=0;
			bool = 0;
		}
		else{
			document.forms['tri_config'].choix2.value = ref_critere;
			choix2 = ref_critere;
		}
		if(ref_critere_c2 != 0) document.getElementById('div_tri_td_'+ref_critere_c2).style.backgroundColor="#fff";
	}
	else if(numero_choix ==3){
		var ref_critere_c3 = document.forms['tri_config'].choix3.value;
		if(ref_critere == 3999){
			document.forms['tri_config'].choix3.value = 0;
			choix3 = 0;
			bool = 0;		
		}
		else if(ref_critere_c3 == ref_critere){
			document.forms['tri_config'].choix3.value = 0;
			choix3=0;
			bool = 0;
		}
		else{
			document.forms['tri_config'].choix3.value = ref_critere;
			choix3 = ref_critere;
		}
		if(ref_critere_c3 != 0) document.getElementById('div_tri_td_'+ref_critere_c3).style.backgroundColor="#fff";
	}
	else if(numero_choix ==4){
		var ref_critere_c4 = document.forms['tri_config'].choix4.value;
		if(ref_critere == 4999){
			document.forms['tri_config'].choix4.value = 0;
			choix4 = 0;
			bool = 0;		
		}
		else if(ref_critere_c4 == ref_critere){
			document.forms['tri_config'].choix4.value = 0;
			choix4=0;
			bool = 0;
		}
		else{
			document.forms['tri_config'].choix4.value = ref_critere;
			choix4 = ref_critere;
		}
		if(ref_critere_c4 != 0) document.getElementById('div_tri_td_'+ref_critere_c4).style.backgroundColor="#fff";
	}

	var url = '/assistant/update_liste.php?choix1='+choix1+'&choix2='+choix2+'&choix3='+choix3+'&choix4='+choix4;

	
	if(bool == 1) document.getElementById('div_tri_td_'+ref_critere).style.backgroundColor="#eee";


	creerRequete();
	requete.open('GET', url, true);	
	
	requete.onreadystatechange = function(){
      
        	if(requete.readyState == 4){
         		if(requete.status == 200){
            			document.getElementById('update').innerHTML = requete.responseText;
         		}
      		}		
   	};
   
   	requete.send(null);

	window.scrollTo(10,350);
	

}




function supprimerCookie(name){
	var expires = new Date();
	var today = new Date();
        expires.setTime(today.getTime() - (365*24*60*60*1000));
        document.cookie = name + "=" + escape("") + ";expires=" + expires.toGMTString();

}


function afficherLigneTr(i){

	var numero = document.getElementById('numero_detail').value;
	if(numero == i) {
		document.getElementById('ligne_numero'+i).style.display='table-row';
	}
	else document.getElementById('ligne_numero'+i).style.display='none';
}


function afficherLigne(i){
	var k = 0;
	for(k=0; k < 20; k++){
		
		if(document.getElementById('ligne_numero'+k)){
			if(i == k) document.getElementById('ligne_numero'+k).style.display='table-row';
			else document.getElementById('ligne_numero'+k).style.display='none';
		}
	}
	document.getElementById('numero_detail').value = i;
}



function supprimerLigne(i){
	
	
		if(document.getElementById('ligne_numero'+i)){
			document.getElementById('ligne_numero'+i).style.display='none';
		}
	
}

function griserChecks(){

	var nbConfigs = document.getElementById('nb_configs').value;
	var l=1;
	for(l=1; l < nbConfigs; l++){
		if(document.getElementById('check'+l)){
			if(document.getElementById('check'+l).checked){
				document.getElementById('divcheck'+l).style.color="#154766";
				document.getElementById('divcheck'+l).style.fontStyle="normal";
			}
			else{
				document.getElementById('divcheck'+l).style.color="#ccc";
				document.getElementById('divcheck'+l).style.fontStyle="italic";
				document.getElementById('check'+l).disabled=true;
			}
		}
	}
}

function degriserChecks(){
	var nbConfigs = document.getElementById('nb_configs').value;
	var l=1;
	for(l=1; l <= nbConfigs; l++){
		if(document.getElementById('check'+l)){
			document.getElementById('divcheck'+l).style.color="#154766";
			document.getElementById('divcheck'+l).style.fontStyle="normal";			
			document.getElementById('check'+l).disabled=false;
		}

	}
}

function supprimer2(i){
	var numero = document.getElementById('suppression0').value;
	var numeroo = document.getElementById('suppression1').value;
	var suppression = 0;
	
	if(i == numero){
		document.getElementById('update_comparaison1').innerHTML = '';
		document.getElementById('suppression0').value = -1;
		supprimerCookie("comparaison1");
		suppression=1;
	}
	else if(i == numeroo){
		document.getElementById('update_comparaison2').innerHTML = '';
		document.getElementById('suppression1').value = -1;
		supprimerCookie("comparaison2");
		suppression=1;
	}
	
	if(suppression){
		var nombreEnCours = document.getElementById('nb_configs_active').value;
		nombreEnCours--;
		document.getElementById('nb_configs_active').value = nombreEnCours;
		if(document.getElementById('check'+i))
			document.getElementById('check'+i).checked=false;
		if(nombreEnCours >= 2) griserChecks();
		else degriserChecks();	

	}
	
}

function ajouter2(i){
	var libre = 1;	
	var nombreEnCours = document.getElementById('nb_configs_active').value;	
	var numero = document.getElementById('suppression0').value;
	var numeroo = document.getElementById('suppression1').value;

	
	if(numero == -1){
		numero = i;
	}
	else if(numeroo == -1){
		numeroo = i;
		libre++;
	}		
	
	ajouterCookie("comparaison"+libre,document.getElementById('numeroconfig'+i).value);
	
	var url = '/assistant/update_comparaison.php?numconfig='+document.getElementById('numeroconfig'+i).value+'&numero='+i;
			
	nombreEnCours++;	
	
	creerRequete();
	
	requete.open('GET', url, true);	
	
	requete.onreadystatechange = function(){
      
        	if(requete.readyState == 4){
         		if(requete.status == 200){
            			document.getElementById('update_comparaison'+libre).innerHTML = requete.responseText;
			}		
   		};
   	}
               		
   	requete.send(null);

        document.getElementById('update_comparaison'+libre).innerHTML = '';
	
	if(nombreEnCours == 2) griserChecks();
	else degriserChecks();
	
	document.getElementById('nb_configs_active').value = nombreEnCours; 
	
	
	document.getElementById('suppression0').value=numero;
	document.getElementById('suppression1').value=numeroo;	
	

}

function verifierCheck(i){
	
	if(!document.getElementById('check'+i).checked){
		supprimer2(i);
	}
	else{
		ajouter2(i);
	}	
	
}

function ajouterCookie(name, value){
	document.cookie="javahere=yes; path=/";
	document.cookie=name+"="+escape(value)+";path=/";
}
	




