//#################################################################################################################################
//#################################################################################################################################

function ajax(conteneur,methode,script,parametres)
{
    try
    {
        xhr=new XMLHttpRequest();
    }
    catch(e)
    {
	try
	{
	    xhr=new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e1)
	{
	    alert("Objet non supporté!");
	}
    }
    xhr.onreadystatechange=function()
		                   {
                              if(xhr.readyState==4)
			                  {
			                      document.getElementById(conteneur).innerHTML=xhr.responseText;
			                  }
			                  else
			                  {
				                  document.getElementById(conteneur).innerHTML="<center>Veuillez patienter ! <br/><img src='images/ProgressBar.gif' /></center>";
			                  }
			              }
    xhr.open(methode,script,true);
    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xhr.send(parametres);
}
//#################################################################################################################################

function ajax_msg(conteneur,methode,script,parametres,msg)
{
    try
    {
        xhr=new XMLHttpRequest();
    }
    catch(e)
    {
	try
	{
	    xhr=new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e1)
	{
	    alert("Objet non supporté!");
	}
    }
    xhr.onreadystatechange=function()
		                   {
                              if(xhr.readyState==4)
			                  {
			                      alert(msg);
			                  }
			              }
    xhr.open(methode,script,true);
    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xhr.send(parametres);
}

//#################################################################################################################################

function executer(module,action)
{
    ajax("contenu","post","executer.php","module="+module+"&action="+action);
}

//#################################################################################################################################

function to_menu(module,action)
{
	var conteneur = "menu" ;
	var methode = "post" ;
	var script = "menu.php" ;
	var parametres = "module="+module+"&action="+action ;
	//*********************
    try
    {
        xhr=new XMLHttpRequest();
    }
    catch(e)
    {
	try
	{
	    xhr=new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e1)
	{
	    alert("Objet non supporté!");
	}
    }
    xhr.onreadystatechange=function()
		                   {
                              if(xhr.readyState==4)
			                  {
			                      document.getElementById(conteneur).innerHTML=xhr.responseText;
                                  ajax("contenu","post","executer.php","module="+module+"&action="+action);
			                  }
			                  else
			                  {
				                  document.getElementById(conteneur).innerHTML="<center>Veuillez patienter ! <br/><img src='images/ProgressBar.gif' /></center>";
			                  }
			              }
    xhr.open(methode,script,true);
    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xhr.send(parametres);
}

//#################################################################################################################################

function logout()
{
	 document.location.href="logout.php";	
}

//#################################################################################################################################

function verifier_login()
{
    var msg="";
	var jslogin=document.frm.login.value;
	var jspass=document.frm.pass.value;
	if(jslogin=="")
	{
	    document.frm.login.style.background = "#fecfcf";	
		msg="Remplir les champs obligatoires !";
	}
	else
	{
	    document.frm.login.style.background = "";
	}
	
	if(jspass=="")
	{
	    document.frm.pass.style.background = "#fecfcf";	
		msg="Remplir les champs obligatoires !";
	}
	else
	{
	    document.frm.pass.style.background = "";
	}
	
	if(msg=="")
	{
        return true;
	}
	else
	{
		document.getElementById("msgerreur").innerHTML=msg;
        return false;
	}	
}

//#################################################################################################################################

function verifier_login_prop()
{
    var msg="";
	var jslogin=document.frm.login.value;
	var jspass1=document.frm.pass1.value;
	var jspass2=document.frm.pass2.value;
	if(jslogin=="")
	{
	    document.frm.login.style.background = "#fecfcf";	
		msg="Remplir les champs obligatoires !";
	}
	else
	{
	    document.frm.login.style.background = "";
	}
	
	if(jspass1=="")
	{
	    document.frm.pass1.style.background = "#fecfcf";	
		msg="Remplir les champs obligatoires !";
	}
	else
	{
	    document.frm.pass1.style.background = "";
	}
	
	if(jspass2=="")
	{
	    document.frm.pass2.style.background = "#fecfcf";	
		msg="Remplir les champs obligatoires !";
	}
	else
	{
	    document.frm.pass2.style.background = "";
	}
	
	if(msg=="")
	{
        return true;
	}
	else
	{
		document.getElementById("msgerreur").innerHTML=msg;
        return false;
	}	
}




//#################################################################################################################################

function ajax_sans_chargement(conteneur,methode,script,parametres)
{
    try
    {
        xhr=new XMLHttpRequest();
    }
    catch(e)
    {
	try
	{
	    xhr=new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch(e1)
	{
	    alert("Objet non supporté!");
	}
    }
    xhr.onreadystatechange=function()
		           {
                               if(xhr.readyState==4)
			       {
			           		   document.getElementById(conteneur).innerHTML=xhr.responseText;
			       }
			       else
			       {
				   			  // document.getElementById(conteneur).innerHTML="<center>Veuillez patienter ! <br/><br/><img src='images/ProgressBar.gif' /></center>";
			       }
			   }
    xhr.open(methode,script,true);
    xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xhr.send(parametres);
}




//#################################################################################################################################

//#################################################################################################################################

function ajouter(module,action)
{
    ajax("contenu","post","executer.php","module="+module+"&action="+action);
}
//#################################################################################################################################
 
function afficher(module,action)
{
    ajax("contenu","post","executer.php","module="+module+"&action="+action);
}

//#################################################################################################################################

function modifier(module,action,id)
{
    ajax("contenu","post","executer.php","module="+module+"&action="+action+"&id="+id);
}

//#################################################################################################################################

function afficher_avec_id(module,action,id)
{
    var id_logement = document.reservation_add.id_logement.value ;
    ajax_sans_chargement("ca","post","executer.php","module="+module+"&action="+action+"&id_logement="+id_logement) ;
}

//#################################################################################################################################

function selection_chambre(module,action,id_logement)
{
	var id_logement = document.reservation_add.id_logement.value ;
    ajax("contenu","post","executer.php","module="+module+"&action="+action+"&id_logement="+id_logement) ;
}

//#################################################################################################################################

function attacher(module,action1,action2,obj1,obj2,idcheck)
{
	
	if (document.getElementById(idcheck).checked)
	{
		//alert("ok ");
		ajax_msg("contenu","post","executer.php","module="+module+"&action="+action1+"&obj1="+obj1+"&obj2="+obj2,"attachement effectue !");
	}
	else
	{
		//alert("non ");
		ajax_msg("contenu","post","executer.php","module="+module+"&action="+action2+"&obj1="+obj1+"&obj2="+obj2,"dettachement effectue !");
	}    
}

function att(idcheck)
{
	
	if (document.getElementById(idcheck).checked)
	{
		alert("ok ");
		//ajax_msg("contenu","post","executer.php","module="+module+"&action="+action+"&obj1="+obj1+"&obj2="+obj2,"attachement effectue !");
	}
	else
	{
		alert("non ");
		//ajax_msg("contenu","post","executer.php","module="+module+"&action="+action+"&obj1="+obj1+"&obj2="+obj2,"dettachement effectue !");
	}    
}

//#################################################################################################################################



function exe_supprimer(module,action,id)
{
    if(confirm("Voulez vous vraiment supprimer cette "+module+" ?"))
    {
        ajax("contenu","post","executer.php","module="+module+"&action="+action+"&id="+id);
    }
}


//#################################################################################################################################

function toto(id_div,id_chambre,nbr_chambre,nbr_personne,module,action)
	{
	    //var nbr_chambre=document.getElementById("nbr_chambre").value;
		//alert (id) ;
    	ajax_sans_chargement(id_div,"post","executer.php","module="+module+"&action="+action+"&id_chambre="+id_chambre+"&nbr_chambre="+nbr_chambre+"&nbr_personne="+nbr_personne);

	}
	
function recup_chambre()
{
		var id_logement=document.getElementById("id_logement").value;
		
		var id_logement=document.getElementById("id_logement").value;
		
}