var xmlhttp;

var imgcourante = new Image();
var imgcourante2 = new Image();

var diagnostiqueur_graphique_besoin = 0;
var diagnostiqueur_graphique_communication = 0;
var diagnostiqueur_graphique_pilotage = 0;
var diagnostiqueur_graphique_realisation = 0;




//************************SOLVEUR***************************//

//FONCTION DU SOLVEUR :
	
	//Fonction permettant d'appeler les fonctions d'affichage du graphique et de la fiche pratique
	function solveur_demande_graph_fiche(code_preocupation, code_pratique, langue)
	{
		if(solveur_demande_graphique(code_preocupation, code_pratique, langue)){
			solveur_demande_fiche_pratique(code_pratique, langue);
		}
	}

	//Fonction permettant l'affichage de la fiche descriptive d'un pratique
	function solveur_demande_fiche_pratique(code_pratique, langue)
	{
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="solveur_fiche_pratique.php";
	url=url+"?code_pratique="+code_pratique+"&lang="+langue;
	xmlhttp.onreadystatechange=state_changed_solveur_demande_fiche_pratique;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	}

	//Fonction permettant l'affichage des pratiques liées à une préocupation
	function solveur_demande_pratique(code_preocupation, langue)
	{
	vider_div("solveur_fiche_pratique");
	vider_div("solveur_graphique");

	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="solveur_pratique.php";
	url=url+"?code_preocupation="+code_preocupation+"&lang="+langue;
	url=url+"&sid="+Math.random();
	xmlhttp.onreadystatechange=state_changed_solveur_demande_pratique;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	}

	//Fonction permettant l'affichage du graphique
	function solveur_demande_graphique(code_preocupation, code_pratique, langue)
	{
	vider_div("solveur_fiche_pratique");
	vider_div("solveur_graphique");

	xmlhttp2=GetXmlHttpObject();
	if (xmlhttp2==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="solveur_graphique.php";
	url=url+"?code_preocupation="+code_preocupation+"&code_pratique="+code_pratique+"&lang="+langue;
	xmlhttp2.onreadystatechange=state_changed_solveur_demande_graphique;
	xmlhttp2.open("GET",url,true);
	xmlhttp2.send(null);
	return true;
	}




//CHARGEMENT DU DIV SOLVEUR :

	//Fonction permettant de mettre à jour le DIV solveur_liste_pratique
	function state_changed_solveur_demande_pratique()
	{
	if (xmlhttp.readyState==4)
	{
	document.getElementById("solveur_liste_pratique").innerHTML=xmlhttp.responseText;
	}
	}

	//Fonction permettant de mettre à jours le DIV solveur_fiche_pratique
	function state_changed_solveur_demande_fiche_pratique()
	{
	if (xmlhttp.readyState==4)
	{
	document.getElementById("solveur_fiche_pratique").innerHTML=xmlhttp.responseText;
	}
	}

	//Fonction permettant de mettre à jours le DIV solveur_graphique
	function state_changed_solveur_demande_graphique()
	{
	if (xmlhttp2.readyState==4)
	{
	document.getElementById("solveur_graphique").innerHTML=xmlhttp2.responseText;
	}
	}


	
	
	
	
	
//************************DIAGNOSTIQUEUR***************************//
	
	
//FONCTION DES DIAGNOSTIQUEUR :


	//Fonction permettant l'affichage du graphique
	function diagnostiqueur_demande_graphique(besoin, communication, pilotage, realisation, langue)
	{
	vider_div("diagnostiqueur_graphique");

	xmlhttp2=GetXmlHttpObject();
	if (xmlhttp2==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="diagnostiqueur_graphique.php";
	url=url+"?besoin="+besoin+"&communication="+communication+"&pilotage="+pilotage+"&realisation="+realisation+"&lang="+langue;
	xmlhttp2.onreadystatechange=state_changed_diagnostiqueur_demande_graphique;
	xmlhttp2.open("GET",url,true);
	xmlhttp2.send(null);
	return true;
	}

	//Fonction permettant l'affichage de la fiche descriptive d'un pratique
	function diagnostiqueur_demande_fiche_pratique(code_pratique, langue)
	{

	vider_div("diagnostiqueur_fiche_pratique");
	
	xmlhttp=GetXmlHttpObject();
	if (xmlhttp==null)
	  {
	  alert ("Browser does not support HTTP Request");
	  return;
	  }
	var url="diagnostiqueur_fiche_pratique.php";
	url=url+"?code_pratique="+code_pratique+"&lang="+langue;
	xmlhttp.onreadystatechange=state_changed_diagnostiqueur_demande_fiche_pratique;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
	}




//CHARGEMENT DES DIV DIAGNOSTIQUEUR :

	//Fonction permettant de mettre à jours le DIV diagnostiqueur_graphique
	function state_changed_diagnostiqueur_demande_graphique()
	{
	if (xmlhttp2.readyState==4)
	{
	document.getElementById("diagnostiqueur_graphique").innerHTML=xmlhttp2.responseText;
	}
	}

	//Fonction permettant de mettre à jours le DIV diagnostiqueur_pratique
	function state_changed_diagnostiqueur_demande_fiche_pratique()
	{
	if (xmlhttp.readyState==4)
	{
	document.getElementById("diagnostiqueur_fiche_pratique").innerHTML=xmlhttp.responseText;
	}
	}








//************************AFFICHAGE***************************//


//FONCTIONS D'AFFICHAGES POUR LA LISTE DES PREOCUPATIONS

	//Fonction permettant de definir l'image courante (la preocupation selectionnée)
	function imageCourante(img)
	{
		imgcourante = img;
	}

	//Fonction permettant de definir l'image passé en paramettre en tant que OK.png (icone de validation)
	function imageValider(img)
	{
			img.src="Image/OK.png";
	}

	//Fonction permettant de remettre l'image courante en tant que NOK.png (icone non valider)
	function imageCacher()
	{
			imgcourante.src="Image/NOK.png";
	}

	
//FONCTION D'AFFICHAGE POUR LA LISTE DES PRATIQUES

	//Fonction permettant de definir l'image courante (la preocupation selectionnée)
	function imageCourante2(img)
	{
		imgcourante2 = img;
	}

	//Fonction permettant de definir l'image passé en paramettre en tant que OK.png (icone de validation)
	function imageValider2(img)
	{
			img.src="Image/OK.png";
	}

	//Fonction permettant de remettre l'image courante en tant que NOK.png (icone non valider)
	function imageCacher2()
	{
			imgcourante2.src="Image/NOK.png";
	}


//FONCTION D'AFFICHAGE POUR LA LISTE DES PRATIQUES DU DIAGNOSITQUEUR

	function diagnostiqueur_image_graphique(img, besoin, communication, pilotage, realisation, langue){
		if(img.src.slice(-13)=="Image/NOK.png"){
		
			diagnostiqueur_graphique_besoin += besoin;
			diagnostiqueur_graphique_communication += communication;
			diagnostiqueur_graphique_pilotage += pilotage;
			diagnostiqueur_graphique_realisation += realisation;
			
			diagnostiqueur_demande_graphique(diagnostiqueur_graphique_besoin, diagnostiqueur_graphique_communication, diagnostiqueur_graphique_pilotage, diagnostiqueur_graphique_realisation, langue);
			img.src="Image/OK.png";
		
		}else{
			
			diagnostiqueur_graphique_besoin -= besoin;
			diagnostiqueur_graphique_communication -= communication;
			diagnostiqueur_graphique_pilotage -= pilotage;
			diagnostiqueur_graphique_realisation -= realisation;
			
			diagnostiqueur_demande_graphique(diagnostiqueur_graphique_besoin, diagnostiqueur_graphique_communication, diagnostiqueur_graphique_pilotage, diagnostiqueur_graphique_realisation, langue);
			img.src="Image/NOK.png";
			
		}
		}
	

//Fonction permettant de vider un DIV en passant son nom en parametre
	function vider_div(nom_div)
	{
		document.getElementById(nom_div).innerHTML = "&nbsp;" ;
	}




function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}
