// JavaScript Document

Array.prototype.uniq=function (){
if(!this.length)return;
this.sort();
for(i=1; i<this.length;)
if(this[i]==this[i-1])
this.splice(i,1);
else i++;
return this;
}
//##################################################
//Affichage des dates de validit矰our une ville
//##################################################
var mer_chouchou_load_date= function (monPays)
{
	$('label_ville').show();
	$('offreValide').show();
	var myAjaxDate = new Ajax.Request(chouchouXmlURL,
      { method: 'get',
        onSuccess: function (xhr)
          {
 			var nodeOffrePays = xhr.responseXML;
          	var nodesOffrePays = xhr.responseXML.getElementsByTagName('offre_pays');
			
			  for (i=0 ; i<nodesOffrePays.length ; i++)
          {
            var nodeOffrePay = nodesOffrePays[i];
			      var nodePays = nodeOffrePay.getElementsByTagName('pays')[0];
           var pays = nodePays.firstChild.nodeValue; 
           /*var ville = nodeVille.firstChild.nodeValue; */
			if (pays == monPays)
			{
				var nodeDateJourDebut = nodeOffrePay.getElementsByTagName('date_debut_validite_jour')[0];
              					$('offreDebutJour').innerHTML = nodeDateJourDebut.firstChild.nodeValue;
								
								var nodeDateMoisDebut = nodeOffrePay.getElementsByTagName('date_debut_validite_mois')[0];
              					$('offreDebutMois').innerHTML = nodeDateMoisDebut.firstChild.nodeValue;
								
								var nodeDateAnneeDebut = nodeOffrePay.getElementsByTagName('date_debut_validite_annee')[0];
              					$('offreDebutAnnee').innerHTML = nodeDateAnneeDebut.firstChild.nodeValue;
								
								var nodeDateJourFin = nodeOffrePay.getElementsByTagName('date_fin_validite_jour')[0];
              					$('offreFinJour').innerHTML = nodeDateJourFin.firstChild.nodeValue;
								
								var nodeDateMoisFin = nodeOffrePay.getElementsByTagName('date_fin_validite_mois')[0];
              					$('offreFinMois').innerHTML = nodeDateMoisFin.firstChild.nodeValue;
								
								var nodeDateAnneeFin = nodeOffrePay.getElementsByTagName('date_fin_validite_annee')[0];
              					$('offreFinAnnee').innerHTML = nodeDateAnneeFin.firstChild.nodeValue;
								$('offreValide').show();
				
			}
		  }
			
		} 						
      }	  
    );
}
//##################################################
//Selection des villes correspondants a un pays
//##################################################
var mer_chouchou_load_ville= function ()
{
	$('label_ville').show();
	$('offreValide').show();
var myAjaxVille = new Ajax.Request(chouchouXmlURL,
      { method: 'get',
        onSuccess: function (xhr)
          {
 			var nodeOffrePays = xhr.responseXML;
          	var nodesOffrePays = xhr.responseXML.getElementsByTagName('offre_pays');
 
			var output = '<select name="hotel_ou_ville" id="hotel_ou_ville" class="ch1" onchange="mer_chouchou_load_date(this.value);">\n<option value="0" selected="selected">-</option>';
		  	var villeArray=[];
          	$A(nodesOffrePays).each(function (nodeOffrePay)
            	{
					var nodePays = nodeOffrePay.getElementsByTagName('pays')[0];
					var pays = nodePays.firstChild.nodeValue;
					switch ($F('nom_pays')){
						case pays:
							var nodeVille = nodeOffrePay.getElementsByTagName('ville')[0];
              				var ville = nodeVille.firstChild.nodeValue;
							villeArray.push(ville);
						break;
						default:
						break;
					} 
            	});
		  	villeArray.uniq();
			villeArray.sort();
			$A(villeArray).each(function (maVille)
            {
				output += '<option value="'+maVille+'">'+maVille+'</option>';
			});
			output +='</select>';
          	$('listeVille').innerHTML = output;
		} 
      }
    );
}
//##################################################
//Initialisation des menus select du moteur chouchou
//##################################################
var mer_chouchou_init = function ()
{
	$('label_ville').hide();
	$('offreValide').hide();
	//Creation du menu pays
var myAjaxPays = new Ajax.Request(
      chouchouXmlURL,
      { method: 'get',
        onSuccess: function (xhr)
          {
          var nodeOffrePays = xhr.responseXML;
          var nodesOffrePays = xhr.responseXML.getElementsByTagName('offre_pays');
          var output = '<select name="nom_pays" id="nom_pays" class="ch1" onchange="mer_chouchou_load_date(this.value);mer_chouchou_load_ville();">\n<option value="0" selected="selected">-</option>';
		  var paysArray=[];
          $A(nodesOffrePays).each(function (nodeOffrePay)
            {
              	var nodePays = nodeOffrePay.getElementsByTagName('pays')[0];
              	var pays = nodePays.firstChild.nodeValue;  
 				paysArray.push(pays);
            });
		  	paysArray.uniq();
			paysArray.sort();
			$A(paysArray).each(function (monPays)
            {
				output += '<option value="'+monPays+'">'+monPays+'</option>';
			});
			output +='</select><br />';
          	$('listePays').innerHTML = output;
          }
      }
    );
}	


try {
	window.onload=function()
	{		
		calendrier_pro.affichage_calendrier(document.catalogue2);
	  calendrier_pro.mise_a_jour(document.catalogue2,'arrivee');
		mer_chouchou_init();
		
	}
}
catch(e){
	window.attachEvent("onload", mer_chouchou_init);
	}


