initCombo=function()
{
   $.ajax({type: "GET",url: "ajax.php?liste=ville_r",success:
   function(xml)
   {
      var villexml   =  $("ville",xml);
      var combovr    =  $("#ville_r");

      $(villexml).each(function()
      {
         $(combovr).append("<option value='"+$(this).attr("id")+"'>"+$(this).attr("libelle")+"</option>")
      });
      $(combovr).prepend("<option value=''></option>")

      $(combovr).change(function()
      {
         var c=$(combovr).attr('value') ;
         $.ajax({type: "GET",url: "ajax.php?liste=secteur_r&ville="+c,success:
         function(xml)
         {
            var secteurxml =  $("secteur",xml);
            var combosr    =  $("#secteur_r");
            $(secteurxml).each(function(){$(combosr).append("<option value='"+$(this).attr("id")+"'>"+$(this).attr("libelle")+"</option>")})
            $(combosr).prepend("<option value=''></option>")

         }})
      })

   }});

   $.ajax({type: "GET",url: "ajax.php?liste=ville_p",success:
   function(xml)
   {
      var villexml   =  $("ville",xml);
      var combovp    =  $("#ville_p");

      $(villexml).each(function()
      {
         $(combovp).append("<option value='"+$(this).attr("id")+"'>"+$(this).attr("libelle")+"</option>")
      });
      $(combovp).prepend("<option value=''></option>")


      $(combovp).change(function()
      {
         var c=$(combovp).attr('value') ;
         $.ajax({type: "GET",url: "ajax.php?liste=secteur_r&ville="+c,success:
         function(xml)
         {
            var secteurxml =  $("secteur",xml);
            var combosp    =  $("#secteur_p");
            $(secteurxml).each(function(){$(combosp).append("<option value='"+$(this).attr("id")+"'>"+$(this).attr("libelle")+"</option>")})
            $(combosp).prepend("<option value=''></option>")

         }})
      })
   }});
}

selectVille=function(from)
{
   if(from == 'P')var combop    =  $("#paysp");else var combop    =  $("#paysr")
   var c=$(combop).attr('value') ;

   $.ajax({type: "GET",async:false,url: "ajax.php?liste=ville_r_from_pays&pays="+c,success:
   function(xml)
   {
      var villexml   =  $("ville",xml);
      if(from == 'P')var combov    =  $("#villep");else var combov    =  $("#viller");
      combov.attr('disabled','');
      $("option",combov).remove()
      $(villexml).each(function()
      {
         $(combov).append("<option value='"+$(this).attr("id")+"'>"+$(this).attr("libelle")+"</option>")
      });
      $(combov).prepend("<option value=''></option>")

      $(combov).change(function()
      {

         var c=$(combov).attr('value') ;
         $.ajax({type: "GET",url: "ajax.php?liste=secteur_r&ville="+c,success:
         function(xml)
         {
            var secteurxml =  $("secteur",xml);
            if(from == 'P')var combos    =  $("#secteurp");else var combos    =  $("#secteurr");
            $("option",combos).remove();
            $(secteurxml).each(function(){$(combos).append("<option value='"+$(this).attr("id")+"'>"+$(this).attr("libelle")+"</option>")})
            $(combos).prepend("<option value=''></option>")
         }})

      })
   }});
}

selectVilleVIP=function(from)
{
   if(from == 'P')var combop    =  $("#paysp");else var combop    =  $("#paysr")
   var c=$(combop).attr('value') ;

   $.ajax({type: "GET",async:false,url: "ajax.php?liste=ville_r_from_pays&pays="+c,success:
   function(xml)
   {
      var villexml   =  $("ville",xml);
      if(from == 'P')var combov    =  $("#villep");else var combov    =  $("#viller");
      combov.attr('disabled','');
      $("option",combov).remove()
      $(villexml).each(function()
      {
         $(combov).append("<option value='"+$(this).attr("id")+"'>"+$(this).attr("libelle")+"</option>")
      });
      $(combov).prepend("<option value=''></option>")
   }});
}

selectSecteur=function(from)
{
   if(from == "R" || from ==undefined)var c=$("#viller").val();
   else if(from == "P")var c=$("#villep").val();

   $.ajax({type: "GET",async:false,url: "ajax.php?liste=secteur_r&ville="+c,success:
   function(xml)
   {
      var secteurxml   =  $("secteur",xml);
      if(from == 'P')var combos    =  $("#secteurp");else var combos=$("#secteurr");

      $(secteurxml).each(function()
      {
         $(combos).append("<option value='"+$(this).attr("id")+"'>"+$(this).attr("libelle")+"</option>")
      });
   }});
}


selectedSecteur=function(val)
{
   selectSecteur();
   $("#secteurr option[@value="+val+"]").attr('selected','selected');

}

selectedVille=function(val)
{
   selectVille();
   $("#viller option[@value="+val+"]").attr('selected','selected');
}


updateFormPaiement=function(id)
{

   var id_zone=$("#viller").val();

	if(id_zone == "" || id_zone == 0 || id_zone == null )
   {
      alert("Vous devez choisir une zone pour votre abonnement");
   }
   else
   {
      $.ajax({type: "GET",url: "modules/eColoc/paieform.php?id="+id+"&id_zone="+id_zone,success:
      function(t)
      {
         $('#divpaiement').html(t);
      }});
   }
}

updateFormPaypal=function()
{
	var id_zone=$("#viller").val();

	if(id_zone == "" || id_zone == 0 || id_zone == null )
   	{
      alert("Vous devez choisir une zone pour votre abonnement");
   	}
   	else
   	{
		$("#submittopaypal").attr('style','visibility:visible');
   	}	
}

ajouteFavori=function(id)
{
   $.ajax({type: "GET",url: "ajaxaction.php?action=ajoute_favori&id_annonce="+id,success:
   function(t)
   {
      var reponse=$("retour",t);
      if(reponse.attr('code') != 0)
      {
         alert(reponse.attr('message'));
      }
   }});
}

ajouteFavoriVille=function(id)
{
   $.ajax({type: "GET",url: "ajaxaction.php?action=ajoute_favori_ville&id_zone="+id,success:
   function(t)
   {
      var reponse=$("retour",t);
      if(reponse.attr('code') != 0)
      {
         alert(reponse.attr('message'));
      }
   }});
}


