function getHTTPObject() // Function pour créer l'objet xmlhttprequest //
     {
         var XMLhttp=null;
         try
         {
               XMLhttp = new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch (e)
         {
             try
             {
                 XMLhttp = new ActiveXObject("Microsoft.XMLHTTP");
             }
             catch (e)
             {
                 XMLhttp = false;
             }
         }
         
         if (!XMLhttp && typeof XMLHttpRequest != "undefined")
         {
             XMLhttp = new XMLHttpRequest();
         }
         return XMLhttp;
     }
	 
//fonction permettant de vider le cache
// résolvant un bug sous IE
function vider_cache(XMLhttp){
  var XMLhttp = XMLhttp;
  XMLhttp.setRequestHeader("Pragma","no-cache");
  XMLhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  XMLhttp.setRequestHeader("Content-type", "charset=iso-8859-1");
}


//verif login
function select_cat(id){
	var XMLhttp = getHTTPObject();
			
    XMLhttp.open("GET","../include/select_cat.php?id="+id);
    vider_cache(XMLhttp);
	
    XMLhttp.onreadystatechange = function() {
           if (XMLhttp.readyState == 4 && XMLhttp.status == 200) {
			   var reponse = XMLhttp.responseText;
			   if(reponse != ""){
				   document.getElementById('list_cat').innerHTML = reponse;
			   } 
          }
   }
   XMLhttp.overrideMimeType('text/html; charset=iso-8859-1');
   XMLhttp.send(null);

}

//select article
function read_Article(id)
{
	var XMLhttp = getHTTPObject();
			
    XMLhttp.open("GET","./include/select_article.php?id="+id);
    vider_cache(XMLhttp);
	document.getElementById('detailArt').innerHTML = '<div align="center"><img src="./images/ajax-loader.gif" width="16" height="16" /><span align="center" style="font-weight:blod">chargement en cours...</span></div><br><br>';
    XMLhttp.onreadystatechange = function() {
           if (XMLhttp.readyState == 4 && XMLhttp.status == 200) {
			   var reponse = XMLhttp.responseText;
			   if(reponse != ""){
				   document.getElementById('detailArt').innerHTML = reponse;
			   } 
          }
   }
   XMLhttp.send(null);
}


//ouvrir les sous-menu
function open_subMenu(div,id)
{
	if(document.getElementById(div).style.display == 'none')
	{

		document.getElementById(div).style.display = 'block';
		
		//AJAX
		var XMLhttp = getHTTPObject();
		XMLhttp.open("GET","./include/select_art.php?id="+id);
		vider_cache(XMLhttp);
		
		XMLhttp.onreadystatechange = function() {
			   if (XMLhttp.readyState == 4 && XMLhttp.status == 200) {
				   
				   var reponse = XMLhttp.responseText;

				   if(reponse != ""){
					   document.getElementById(div).innerHTML = reponse;
				   } 
			  }
	   }
	   XMLhttp.send(null);
	   
	}
	else
	{
		document.getElementById(div).style.display = 'none';
	}
	
}

//afficher bulletin
function affichBulletin()
{
	var content = document.getElementById('content').value;
	var auteur = document.getElementById('auteur').value;
	var mois = document.getElementById('mois').value;
	var annee = document.getElementById('annee').value;
	
	
	
	//vérification
	if(content!="" || auteur!="" || mois!="-1" || annee!="-1")
	{
		var XMLhttp = getHTTPObject();
				
		XMLhttp.open("GET","./include/affich_Bulletin.php?content="+content+"&auteur="+auteur+"&mois="+mois+"&annee="+annee);
		vider_cache(XMLhttp);
		document.getElementById('result').innerHTML = '<div align="center"><img src="./images/ajax-loader.gif" width="16" height="16" /><span align="center" style="font-weight:blod">chargement en cours...</span></div>';
		XMLhttp.onreadystatechange = function() {
			   if (XMLhttp.readyState == 4 && XMLhttp.status == 200) {
				   var reponse = XMLhttp.responseText;
				   if(reponse != ""){
					   document.getElementById('result').innerHTML = reponse;
				   } 
			  }
	   }
	   XMLhttp.send(null);
	}
	else
	 alert("Il faut au moins renseigner un champs..");
}
