function verif_champs()
{
	var intitule = document.getElementById("intitule");
	var texte = document.getElementById("texte");
	var signature = document.getElementById("signature");
	var flag_alert = false;
	var message = '';

	if (texte.value == '')
	{
		message = message + "Le champ Texte est obligatoire\n"
		flag_alert = true;
		
	}
	if (intitule.value == '')
	{
		message = message + "Le champ Intitule est obligatoire  \n"
		flag_alert = true;
	}
	if (signature.value == '')
	{
		message = message + "Le champ Signature est obligatoire\n"
		flag_alert = true;
	}
	if (flag_alert == true)
	{
		alert(message);
		return false;
	}
	else
	{
		return true;
	}

}
function soumission(f_sort,f_dir)
{
    var formu = document.getElementById("form_moteur");
    var hidden_sort = document.getElementById("hidden_sort");
    var hidden_dir = document.getElementById("hidden_dir");
    var from_colonne = document.getElementById("from_colonne");
    hidden_sort.value = f_sort;
    hidden_dir.value = f_dir;
    from_colonne.value = "1";
    formu.submit();
}
function hide_engine()
{
        var moteur = document.getElementById("moteur");
        var masque_marche = document.getElementById("masque_marche");
        var masque_domaine = document.getElementById("masque_domaine");
        var flag_moteur = document.getElementById("flag_moteur");
	moteur.style.display="none";
	masque_marche.style.display="none";
	masque_domaine.style.display="none";
	flag_moteur.value = 0;
	return false;
}
function display_engine()
{
        var moteur = document.getElementById("moteur");
        var masque_marche = document.getElementById("masque_marche");
        var masque_domaine = document.getElementById("masque_domaine");
        var flag_moteur = document.getElementById("flag_moteur");
	moteur.style.display="block";
	flag_moteur.value = 1;
}
function hide_gestion_domaines()
{
        var gestion_domaines = document.getElementById("gestion_domaines");
	gestion_domaines.reset();
	gestion_domaines.style.display="none";
}
function hide_gestion_marches()
{
        var gestion_marches = document.getElementById("gestion_marches");
	gestion_marches.reset();
	gestion_marches.style.display="none";
}
function display_gestion_domaines()
{
        var gestion_domaines = document.getElementById("gestion_domaines");
        var gestion_marches = document.getElementById("gestion_marches");
        var sel_domaine = document.getElementById("sel_domaine");
	// Desactivation des 2 options inutiles dans ce contexte.
	// On ne le fait qu'une seule fois...

	if (sel_domaine.options[0].value == "0" && sel_domaine.options[1].value == "0")
	{
 		sel_domaine.options[0] = null;	
 		sel_domaine.options[0] = null;
	}
	if (gestion_domaines.style.display=="block")
	{
		gestion_domaines.style.display="none";
	}
	else
	{
		gestion_domaines.style.display="block";
	}
	gestion_marches.style.display="none";
}
function display_gestion_marches()
{
        var gestion_marches = document.getElementById("gestion_marches");
        var gestion_domaines = document.getElementById("gestion_domaines");
        var sel_marche = document.getElementById("sel_marche");
	// Desactivation des 2 options inutiles dans ce contexte.
	// On ne le fait qu'une seule fois...

	if (sel_marche.options[0].value == "0" && sel_marche.options[1].value == "0")
	{
 		sel_marche.options[0] = null;	
 		sel_marche.options[0] = null;	
	}
	if (gestion_marches.style.display=="block")
	{
		gestion_marches.style.display="none";
	}
	else
	{
		gestion_marches.style.display="block";
	}
	gestion_domaines.style.display="none";
}
function gerer_marches(mode)
{
        var http = null;
        var hidden_marche = document.getElementById("hidden_marche");
        var texte_marche = document.getElementById("texte_marche");
        var gestion_marches = document.getElementById("gestion_marches");
        var sel_marches = document.getElementById("sel_marches");
        var marche = document.getElementById("marche");
        var cr = document.getElementById("cr");

	id_marche = hidden_marche.value;
	libelle_marche = texte_marche.value;
	

	if (mode == "Supprimer")
	{
		if (libelle_marche == "")
		{
			alert("Vous devez s lectionner un march © dans la liste");
			return false;
		}
		if (!confirm("Confirmez-vous la suppression de\n"+  libelle_marche))
		{
			return false;
		}
	}
	if (mode == "Modifier" || mode == "Nouveau")
	{
		if (libelle_marche == "")
		{
			alert("Vous devez saisir un march © dans la zone de texte");
			return false;
		}
	}


        if(window.XMLHttpRequest)
        {
                 // Firefox
                http = new XMLHttpRequest();
        }
        else if(window.ActiveXObject) // Internet Explorer
                http = new ActiveXObject("Microsoft.XMLHTTP");
        else
        {
                // XMLHttpRequest non supporte par le navigateur
                alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
                return;
        }
	if (mode == "Modifier")
	{
        	http.open("GET", "/cgi-bin/gestion_marches.pl?id_marche="+ id_marche + "&mode="+ mode +"&libelle_marche="+ libelle_marche,true);
	}
	else if (mode == "Nouveau")
	{
        	http.open("GET", "/cgi-bin/gestion_marches.pl?mode="+ mode +"&libelle_marche="+ libelle_marche,true);
	}
	else if (mode == "Supprimer")
	{
        	http.open("GET", "/cgi-bin/gestion_marches.pl?mode="+ mode +"&id_marche="+ id_marche,true);
	}
        http.onreadystatechange=function()
        {
                if (http.readyState==4)
                {

        		var marche = document.getElementById("marche");
        		var sel_marche = document.getElementById("sel_marche");
        		var texte_marche = document.getElementById("texte_marche");

                        result = http.responseText.split(":");
			res_ret = result[0];
			res_mode = result[1];
			res_id_marche= result[2];
			res_libelle_marche = result[3];

			if (res_mode == "Modifier")
			{
				for (j = 0; j< marche.length; j++)
				{
					if (marche.options[j].value == res_id_marche)
					{
						marche.options[j].text = res_libelle_marche;
						marche.options.selectedIndex = j;
					}
				}
				for (j = 0; j< sel_marche.length; j++)
				{
					if (sel_marche.options[j].value == res_id_marche)
					{
						sel_marche.options[j].text = res_libelle_marche;
						sel_marche.options.selectedIndex = j;
					}
				}
				texte_marche.value='';
				cr.innerHTML = "Le march&eacute; a bien  t  modifi ";
			}
			if (res_mode == "Nouveau")
			{
			 	new_option = new Option(res_libelle_marche,res_id_marche);
                                marche.options[marche.options.length] = new_option;
			 	new_option = new Option(res_libelle_marche,res_id_marche);
                                sel_marche.options[sel_marche.options.length] = new_option;
				cr.innerHTML = "Le march&eacute; a bien  t  cr  ";
				texte_marche.value='';

			}
			if (res_mode == "Supprimer")
			{
				for (j = 0; j< marche.length; j++)
				{
					if (marche.options[j].value == res_id_marche)
					{
						marche.options[j] = null;
					}
				}
				for (j = 0; j< sel_marche.length; j++)
				{
					if (sel_marche.options[j].value == res_id_marche)
					{
						sel_marche.options[j] = null;
					}
				}
				texte_marche.value='';
				cr.innerHTML = "Le march&eacute; a bien  t  supprim ";
			}
                        gestion_marches.style.display="none";


                }
        }
        http.send(null);
	return (false);
}
function gerer_domaines(mode)
{
        var http = null;
        var hidden_domaine = document.getElementById("hidden_domaine");
        var texte_domaine = document.getElementById("texte_domaine");
        var gestion_domaines = document.getElementById("gestion_domaines");
        var sel_domaines = document.getElementById("sel_domaines");
        var domaine = document.getElementById("domaine");
        var cr = document.getElementById("cr");

	id_domaine = hidden_domaine.value;
	libelle_domaine = texte_domaine.value;
	

	if (mode == "Supprimer")
	{
		if (libelle_domaine == "")
		{
			alert("Vous devez s lectionner un domaine dans la liste");
			return false;
		}
		if (!confirm("Confirmez-vous la suppression de\n"+  libelle_domaine))
		{
			return false;
		}
	}
	if (mode == "Modifier" || mode == "Nouveau")
	{
		if (libelle_domaine == "")
		{
			alert("Vous devez saisir un domaine dans la zone de texte");
			return false;
		}
	}


        if(window.XMLHttpRequest)
        {
                 // Firefox
                http = new XMLHttpRequest();
        }
        else if(window.ActiveXObject) // Internet Explorer
                http = new ActiveXObject("Microsoft.XMLHTTP");
        else
        {
                // XMLHttpRequest non supporte par le navigateur
                alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
                return;
        }
	if (mode == "Modifier")
	{
        	http.open("GET", "/cgi-bin/gestion_domaines.pl?id_domaine="+ id_domaine + "&mode="+ mode +"&libelle_domaine="+ libelle_domaine,true);
	}
	else if (mode == "Nouveau")
	{
        	http.open("GET", "/cgi-bin/gestion_domaines.pl?mode="+ mode +"&libelle_domaine="+ libelle_domaine,true);
	}
	else if (mode == "Supprimer")
	{
        	http.open("GET", "/cgi-bin/gestion_domaines.pl?mode="+ mode +"&id_domaine="+ id_domaine,true);
	}
        http.onreadystatechange=function()
        {
                if (http.readyState==4)
                {

        		var domaine = document.getElementById("domaine");
        		var sel_domaine = document.getElementById("sel_domaine");
        		var texte_domaine = document.getElementById("texte_domaine");

                        result = http.responseText.split(":");
			res_ret = result[0];
			res_mode = result[1];
			res_id_domaine= result[2];
			res_libelle_domaine = result[3];

			if (res_mode == "Modifier")
			{
				for (j = 0; j< domaine.length; j++)
				{
					if (domaine.options[j].value == res_id_domaine)
					{
						domaine.options[j].text = res_libelle_domaine;
						domaine.options.selectedIndex = j;
					}
				}
				for (j = 0; j< sel_domaine.length; j++)
				{
					if (sel_domaine.options[j].value == res_id_domaine)
					{
						sel_domaine.options[j].text = res_libelle_domaine;
						sel_domaine.options.selectedIndex = j;
					}
				}
				texte_domaine.value='';
				cr.innerHTML = "Le domaine a bien  t  modifi ";
			}
			if (res_mode == "Nouveau")
			{
			 	new_option = new Option(res_libelle_domaine,res_id_domaine);
                                domaine.options[domaine.options.length] = new_option;
			 	new_option = new Option(res_libelle_domaine,res_id_domaine);
                                sel_domaine.options[sel_domaine.options.length] = new_option;
				cr.innerHTML = "Le domaine a bien  t  cr  ";
				texte_domaine.value='';

			}
			if (res_mode == "Supprimer")
			{
				for (j = 0; j< domaine.length; j++)
				{
					if (domaine.options[j].value == res_id_domaine)
					{
						domaine.options[j] = null;
					}
				}
				for (j = 0; j< sel_domaine.length; j++)
				{
					if (sel_domaine.options[j].value == res_id_domaine)
					{
						sel_domaine.options[j] = null;
					}
				}
				texte_domaine.value='';
				cr.innerHTML = "Le domaine a bien  t  supprim ";

			}
                        gestion_domaines.style.display="none";


                }
        }
        http.send(null);
	return (false);
}
function affiche_domaine()
{
        var sel_domaine = document.getElementById("sel_domaine");
        var texte_domaine = document.getElementById("texte_domaine");
        var hidden_domaine = document.getElementById("hidden_domaine");
        var hidden_mode = document.getElementById("hidden_mode");
	
	text_sel = sel_domaine.options[sel_domaine.options.selectedIndex].text;
	val_sel = sel_domaine.options[sel_domaine.options.selectedIndex].value;

	texte_domaine.value = text_sel;
	hidden_domaine.value = val_sel;
	hidden_mode.value = "Modifier";
	
}
function affiche_marche()
{
        var sel_marche = document.getElementById("sel_marche");
        var texte_marche = document.getElementById("texte_marche");
        var hidden_marche = document.getElementById("hidden_marche");
        var hidden_mode_mar = document.getElementById("hidden_mode_mar");
	
	text_sel = sel_marche.options[sel_marche.options.selectedIndex].text;
	val_sel = sel_marche.options[sel_marche.options.selectedIndex].value;

	texte_marche.value = text_sel;
	hidden_marche.value = val_sel;
	hidden_mode_mar.value = "Modifier";
	
}
function new_form(btnNew, formulaire,type)
{
    formulaire = document.getElementById(formulaire);

    if (formulaire.id == 'gestion_domaines')
    {
        var boutonValid = document.getElementById("bouton_validation");
        var legend      = document.getElementById("legend_domaines");
        var hidden_mode	= document.getElementById("hidden_mode");
        var sel_domaine	= document.getElementById("sel_domaine");
        var texte_domaine = document.getElementById("texte_domaine");

	if (type == "Nouveau")
	{
        	boutonValid.value="Cr er";
		sel_domaine.style.display="none";
	        legend.innerHTML = "Cr er un domaine";
		hidden_mode.value = "Nouveau";
       		btnNew.style.display="none";
	}
   }
    if (formulaire.id == 'gestion_marches')
    {
        var boutonValid = document.getElementById("bouton_validation_mar");
        var legend      = document.getElementById("legend_marches");
        var hidden_mode_mar	= document.getElementById("hidden_mode_mar");
        var sel_marche= document.getElementById("sel_marche");
        var texte_marche = document.getElementById("texte_marche");

	if (type == "Nouveau")
	{
        	boutonValid.value="Cr er";
		sel_marche.style.display="none";
	        legend.innerHTML = "Cr er un march&eacute;";
		hidden_mode_mar.value = "Nouveau";
       		btnNew.style.display="none";
	}
   }
}
function maj_form_sup(btnNew)
{
        var texte_domaine = document.getElementById("texte_domaine");
        var hidden_domaine = document.getElementById("hidden_domaine");
        var hidden_mode = document.getElementById("hidden_mode");
        var boutonValid = document.getElementById("bouton_validation");

	texte_domaine.style.display="none";
	texte_domaine.value="";
	boutonValid.style.display="none";
       	btnNew.style.display="none";

}

function reinit(formu)
{
        var select_domaine = document.getElementById("domaine");
        var select_marche = document.getElementById("marche");
        var masque_domaine = document.getElementById("masque_domaine");
        var masque_marche = document.getElementById("masque_marche");
        var date2	 = document.getElementById("span_date_2");
        var flag_moteur = document.getElementById("flag_moteur");
    formulaire = document.getElementById(formu);


	// On masque la deuxieme date
	date2.style.display="none";
    // on parcourt les ?ets du formulaire
    for (i=0;i<formulaire.elements.length;i++)
    {
        // on ?arte les ?ements inconnus et les boutons.
        if (formulaire.elements[i].type != null &&
            formulaire.elements[i].type != "button" &&
            formulaire.elements[i].type != "submit")
        {
            formulaire.elements[i].value = "";

            // Cases ?cocher
            if (formulaire.elements[i].type == "radio" || formulaire.elements[i].type == "checkbox")
                formulaire.elements[i].checked = false;

            // Dans le cas d'un champ select-multiple...
            else if (formulaire.elements[i].type == "select-multiple")
            {
                // ... on d?electionne chaque option.
                for(j=0;j<formulaire.elements[i].options.length;j++)
                {
                            // Ajout JK pour les besoins du moteur de recherches
                                if (j == 0)
                        		formulaire.elements[i].options[j].selected = true;
                                else
                        		formulaire.elements[i].options[j].selected = false;
                }
            }

            // ... pour un select, on se place sur le premier ?ement de la liste.
            else if (formulaire.elements[i].type == "select-one")
	    {
                	formulaire.elements[i].selectedIndex = 0;
	    }

        }
    }
    select_domaine.disabled= false;
    select_marche.disabled= false;
    masque_domaine.style.display="none";
    masque_marche.style.display="none";
    flag_moteur.value = 1;

    return false;
}
function neutralise_select2(select)
{
        var select_domaine = document.getElementById("domaine");
        var select_marche = document.getElementById("marche");
        var masque_domaine = document.getElementById("masque_domaine");
        var masque_marche = document.getElementById("masque_marche");
	var sp_domaine = document.getElementById("sp_domaine");
	var sp_marche = document.getElementById("sp_marche");
	var message = document.getElementById("message");

        select_marche.disabled=false;
        select_domaine.disabled=false;
    	masque_marche.style.display= "none";
    	masque_domaine.style.display= "none";

    // si on a cliqu  sur "marche", il faut desactiver "domaine", qui est le param tre pass 
        if (select == "domaine")
        {
                select_domaine.disabled=true;
                masque_domaine.style.display= "block";
		sp_domaine.style.textDecoration = "underline";
		sp_marche.style.textDecoration = "none";
		message.style.display="none";
        }
        if (select == "marche")
        {
                select_marche.disabled=true;
                masque_marche.style.display= "block";
		sp_marche.style.textDecoration = "underline";
		sp_domaine.style.textDecoration = "none";
		message.style.display="none";
        }
}

function neutralise_select(select)
{
	var select_domaine = document.getElementById("domaine");
	var select_marche = document.getElementById("marche");
	var sp_domaine = document.getElementById("sp_domaine");
	var sp_marche = document.getElementById("sp_marche");

	select_marche.disabled=false;
	select_domaine.disabled=false;
	if (select == "sp_domaine")
	{
		select_domaine.disabled=false;
		select_marche.disabled=true;
	}
	if (select == "sp_marche")
	{
		select_marche.disabled=false;
		select_domaine.disabled=true;
	}
}
function affiche_dates(val)
{
	var chk_avant 	= document.getElementById("avant");
	var chk_apres 	= document.getElementById("apres");
	var chk_entre 	= document.getElementById("entre");
	var span2 	= document.getElementById("span_date_2");

	if (chk_entre.checked == true)
	{
		span2.style.display = "inline";
	}
	else
	{
		span2.style.display = "none";
	}

}
function traite_selection(champ_select)
{

	var societe		= document.getElementById("societe");
	var produit		= document.getElementById("produit");
	var marque		= document.getElementById("marque");
	var activite		= document.getElementById("activite");
	var rech_mot		= document.getElementById("rech_mot");
	var select_rech_mot	= document.getElementById("select_rech_mot");

	if (champ_select == "societe")
	{
		produit.selectedIndex = 0;
		marque.selectedIndex = 0;
		activite.selectedIndex = 0;
		rech_mot.value = '';
		return true;
	}
	else if (champ_select == "marque")
        {
		societe.selectedIndex = 0;
		produit.selectedIndex = 0;
		activite.selectedIndex = 0;
		rech_mot.value = '';
		return true;
	}
	else if (champ_select == "produit")
        {
		societe.selectedIndex = 0;
		marque.selectedIndex = 0;
		rech_mot.value = '';
		return true;
	}
	else if (champ_select == "activite")
        {
		societe.selectedIndex = 0;
		marque.selectedIndex = 0;
		rech_mot.value = '';
		return true;
	}
	else if (rech_mot.value != '')
        {
		societe.selectedIndex = 0;
		marque.selectedIndex = 0;
		produit.selectedIndex = 0;
		activite.selectedIndex = 0;
		return true;
	}


}
function affiche_aide(zone)
{
        var http = null;
        var div = document.getElementById(zone);

	if (div.style.display == "none")
		div.style.display = "block";
	else
	{
		div.style.display = "none";
		return false;
	}


        if(window.XMLHttpRequest)
        {
                 // Firefox
                http = new XMLHttpRequest();
        }
        else if(window.ActiveXObject) // Internet Explorer
                http = new ActiveXObject("Microsoft.XMLHTTP");
        else
        {
                // XMLHttpRequest non supporte par le navigateur
                alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
                return;
        }
        http.open("GET", "../cgi-bin/affiche_aide.php?zone="+ zone ,true);
        http.onreadystatechange=function()
        {
                if (http.readyState==4)
                {
        		var div = document.getElementById(zone);
                        result = http.responseText;
			div.innerHTML = result;
                }
        }
        http.send(null);
	return (false);
}

