
var cookVilleDep='aucune';
var cookDateDep='aucune';

var toutesDest=0;
var tabMinPrix = new Array();
var tabMinVille = new Array();
var listeMois = new Array();
var listeMoisJour = new Array();
var listePrixJour = new Array();



var idLiens = 11206;
function changer(id_td)
{
tab=new Array("cal","avis","meteo");
for(i=0;i<3;i++)
{var td=tab[i]+"_td";
var div=tab[i]+"_div";
if(tab[i]==id_td)
{document.getElementById(td).background="http://www.zenvoyages.com/sejours/images/img03.gif";
document.getElementById(td).setAttribute("background","http://www.zenvoyages.com/sejours/images/img03.gif");
document.getElementById(td).className="titre_tab";
document.getElementById(td).setAttribute("class","titre_tab");
document.getElementById(div).className="vide";
document.getElementById(div).setAttribute("class","vide");
}
else
{document.getElementById(td).background="http://www.zenvoyages.com/sejours/images/img02.gif";
document.getElementById(td).setAttribute("background","http://www.zenvoyages.com/sejours/images/img02.gif");
document.getElementById(td).className="hotel_gris";
document.getElementById(td).setAttribute("class","hotel_gris");
document.getElementById(div).className="cache";
document.getElementById(div).setAttribute("class","cache");
}
}

}

/************************************////
function changer2(id_td)
{
tab=new Array("cal","avis","meteo");
for(i=0;i<3;i++)
{var td=tab[i]+"_td";
var div=tab[i]+"_div";
if(tab[i]==id_td)
{
document.getElementById(td).className="div_active";
document.getElementById(td).setAttribute("class","div_active");
document.getElementById(div).className="vide";
document.getElementById(div).setAttribute("class","vide");
}
else
{
document.getElementById(td).className="div_nonactive";
document.getElementById(td).setAttribute("class","div_nonactive");
document.getElementById(div).className="cache";
document.getElementById(div).setAttribute("class","cache");
}
}

}
////**********************************************//////////////////
function verif_form()
{
	if(document.form1.nom.value=="")
	{
	alert(' Entrez votre Nom, SVP!!');
	document.form1.nom.focus();
	return false; 
	}
	if(document.form1.prenom.value=="")
	{
	alert(' Entrez votre Prénom, SVP!!');
	document.form1.prenom.focus();
	return false; 
	 }
     if(document.form1.mail.value == "")
     {
     alert(' Entrez votre adresse Email, SVP !!');
      document.form1.mail.focus();
      return false; 
      }
	adresse = document.form1.mail.value;
	var place = adresse.indexOf("@",1);
	var point = adresse.indexOf(".",place+1);
	if ((place > -1)&&(adresse.length >2)&&(point > 1))
	  {
    }
    else
		{
		alert('Adresse email invalide!!');
        document.form1.mail.focus();
        return false;		
        }
	
}

////////////////fiche
var precVille="";
var precMois="";
var precJourPrix="";
var moinsCher = "";
var minPrix=99999;
var myDate=new Date();
var selectedMois = "";
String.prototype.toProperCase = function(){
return this.toLowerCase().replace(/\w+/g,function(s){
return s.charAt(0).toUpperCase() + s.substr(1);
})
}

function init_fiche() {
	var listeSej_array=listeSej.split("#");
	var trouve=0;
	
	if(cookVilleDep!=""){
		for(i=1;i<listeSej_array.length;i++){
			if(cookVilleDep==listeSej_array[i]){
				cacheDate(listeSej_array[i]);
				trouve=1;
			}
		}
	}
	
	if(trouve==0){
		cacheDate(listeSej_array[1]);
	}
	
	init_bestPrix();
}


//----------------------------------------------------------------------
// GESTION DES VILLES DE DEPART
//----------------------------------------------------------------------
function cacheDate(id) {
	precMois="";
	genereListeMois(id);
	initVille(id);
	var listeSej_array=listeSej.split("#");
	for ($k=1 ; $k < listeSej_array.length ; $k++) {
		if(listeSej_array[$k]!= "") {
			divId = "divVille_" + listeSej_array[$k];
			var leDiv=document.getElementById(divId);						
			leDiv.style.backgroundColor="#FFFFFF";
			leDiv.style.color="#656565";
			/*leDiv.class="divMois";*/	
			divId = "divVille2_" + listeSej_array[$k];
			var leDiv=document.getElementById(divId);	
			//leDiv.style.textDecoration="underline";
		}
	}
	divId = "divVille_" + id;
	var leDiv=document.getElementById(divId);		
	leDiv.style.backgroundColor="#f6fafd";
	leDiv.style.color="#2971c3";
	divId = "divVille2_" + id;
	var leDiv=document.getElementById(divId);		
	leDiv.style.textDecoration="none";
	precVille = "divVille_" + id;
}


function genereListeMois(idVille){
	var contenu="";
	var nbMois=0;
	var listeMois_array=listeMois[idVille].split("#");
	nbMois=listeMois_array.length;
	//if(nbMois>8){ nbMois=8; }
	for ($k=1 ; $k < nbMois ; $k++) {
		$tabTmp=listeMois_array[$k].split('@');
		contenu = contenu + '<div id="divMois_'+idVille+'_'+$k+'" class="divMois" onMouseOver="fond_on_mois(\'divMois_'+idVille+'_'+$k+'\')" onMouseOut="fond_off_mois(\'divMois_'+idVille+'_'+$k+'\')" onclick="detailMois('+idVille+','+$k+')">&nbsp;'+$tabTmp[0].toUpperCase()+'</div>';
	}
	document.getElementById('divMoisDepart').innerHTML=contenu;
}


function initVille(idVille){
	var bool_trouve=0;
	var prixMini=99999;
	var idMois2=0;
	var trouve=0;
	var jourCourant=parseInt(myDate.getDate());
	var moisCourant=parseInt((myDate.getMonth())+1);
	var moisSuivant=parseInt((myDate.getMonth())+2);
	if(moisSuivant==13){
		moisSuivant=1;
	}
	var tabMois=listeMois[idVille].split('#');
	if(selectedMois==""){
		
		if(cookDateDep!=""){		
			tabDateTmp=cookDateDep.split("-");
			for($kb=1 ; $kb < tabMois.length ; $kb++){
				var moisTmp = tabMois[$kb].split('@');
				if(parseInt(moisTmp[1])==parseInt(tabDateTmp[1])){
					detailMois(idVille,$kb);
					trouve=1;
				}
			}
		}
		
		if(trouve==0){
			for($kb=1 ; $kb < tabMois.length ; $kb++){
				var moisTmp = tabMois[$kb].split('@');
				if(jourCourant<20){
					if(parseInt(moisTmp[1])==moisCourant){
						detailMois(idVille,$kb);
						bool_trouve=1;
					}
				}else{
					if(parseInt(moisTmp[1])==moisSuivant){
						detailMois(idVille,$kb);
						bool_trouve=1;
					}
				}
			}
			if(bool_trouve==0){
				detailMois(idVille,1);
			}
		}
		
	}else{
		for($ka=1 ; $ka < tabMois.length ; $ka++){
			var moisTmp = tabMois[$ka].split('@');
			if(parseInt(moisTmp[1])==selectedMois){
				detailMois(idVille,$ka);
				bool_trouve=1;
			}
		}
		if(bool_trouve==0){
			selectedMois="";	
			initVille(idVille);
		}
	}
}

//----------------------------------------------------------------------
// GESTION DU CALENDRIER D'UN MOIS DE DEPART
//----------------------------------------------------------------------
function detailMois(idVille,idMois){
	
	maj_selectedMois(idVille,idMois);

	precJourPrix="";

	genereCalendrier(idVille,idMois);

	var listeSej_array=listeSej.split("#");
	var listeMoisNb_array=listeMoisNb.split("#");
	for ($k=1 ; $k < listeSej_array.length ; $k++) {
		if(listeSej_array[$k]== idVille) {
			for($m=1 ; $m<=listeMoisNb_array[$k] ; $m++){	
				divId = "divMois_" + listeSej_array[$k] + "_" + $m + "";
				var leDiv=document.getElementById(divId);						
				leDiv.style.backgroundColor="#FFFFFF";	
				leDiv.style.color="#666666";
			}
		}
	}
	divId = "divMois_" + idVille + "_" + idMois + "";
	var leDiv=document.getElementById(divId);						

	
	leDiv.style.backgroundColor="#f6fafd";	
	leDiv.style.color="#2773bf";
	var listeMois_array=listeMois[idVille].split("#");
	var libelleMois=listeMois_array[idMois].split(" ");
	document.getElementById('libelleMois').innerHTML=libelleMois[0];
	precMois="divMois_" + idVille + "_" + idMois + "";	
	initMois(idVille,idMois);	
}

function maj_selectedMois(idVille,idMois){
	var tabMois=listeMois[idVille].split('#');
	var moisTmp = tabMois[idMois].split('@');
	selectedMois = moisTmp[1];
}

function genereCalendrier(idVille,idMois){
	var contenu="";
	var precDateCal=0;
	var tmp=listeMoisJour[idVille][idMois].split("@");
	//nombre de jour de mois selectionner
	var infos_tab=tmp[0].split("#");
	
	var jours_tab=tmp[1].split("#");
	nbJours=parseInt(infos_tab[0]);
	FirstDay=parseInt(infos_tab[1]);
	contenu=contenu+'<table border="0" cellspacing="1" cellpadding="0" class="textenormal">';
	contenu=contenu+'<tr><td class="jourCal">L</td><td class="jourCal">M</td><td class="jourCal">M</td><td class="jourCal">J</td><td class="jourCal">V</td><td class="jourCal">S</td><td class="jourCal">D</td></tr>';
	contenu=contenu+'<tr>';
	for($i=1;$i<FirstDay;$i++){
	contenu=contenu+'<td>&nbsp;</td>';
	}
	for ($k=1 ; $k < jours_tab.length ; $k++) {
		
		jourCur=parseInt(jours_tab[$k]);
		for($j=(precDateCal+1) ; $j<jourCur ; $j++){
			contenu=contenu+'<td class="cal0">'+$j+'</td>';
			if((($j-1)+FirstDay)%7==0){
				contenu=contenu+'</tr><tr>';
			}
		}
		contenu=contenu+'<td class="cal2" id="cell_'+idVille+'_'+idMois+'_'+jourCur+'" onMouseOver="fond_on(\'cell_'+idVille+'_'+idMois+'_'+jourCur+'\')" onMouseOut="fond_off(\'cell_'+idVille+'_'+idMois+'_'+jourCur+'\')" onclick="detailPrix('+idVille+','+idMois+','+jourCur+')">'+jourCur+'</td>';
		precDateCal=parseInt(jourCur);
		if(((precDateCal-1)+FirstDay)%7==0){
			contenu=contenu+'</tr><tr>';
		}
	}
	precDateCal++;
	while((precDateCal+FirstDay)<42){
		if(precDateCal<=nbJours){
			contenu=contenu+'<td class="cal0">'+precDateCal+'</td>';
		}else{
			contenu=contenu+'<td class="calVide">&nbsp;</td>';
		}
		if(((precDateCal-1)+FirstDay)%7==0){
			contenu=contenu+'</tr><tr>';
		}
		precDateCal++;
	}
	contenu=contenu+'</tr></table>';	
	document.getElementById('divCalendrier').innerHTML=contenu;
}

function initMois(idVille,idMois){
	var bool_trouve=0;
	var minPrix=99999;
	var maxPart=0;
	var idJour=0;
	var trouve=0;
	
	if(cookDateDep!=""){		
		tabDateTmp=cookDateDep.split("-");
		
		var tabMois=listeMois[idVille].split('#');
		var moisTmp = tabMois[idMois].split('@');
		if(parseInt(moisTmp[1])==parseInt(tabDateTmp[1])){
		
			var tablisteJour=listeMoisJour[idVille][idMois].split("@");
			var tabIdJour=tablisteJour[1].split("#");
			for($n=1 ; $n<tabIdJour.length ; $n++){
				if(parseInt(tabIdJour[$n])==parseInt(tabDateTmp[2])){
					idJour=$n;
					trouve=1;
				}
			}
		}
	}
		
	if(trouve==0){
	
		var tablisteJour=listePrixJour[idVille][idMois].split("#");
		for($n=1 ; $n<tablisteJour.length ; $n++){
			var tablistePart=tablisteJour[$n].split("@");
			if(tablistePart.length>maxPart){
				maxPart=tablistePart.length;
				idJour=$n;	
				minPrix=99999;
				for($p=1 ; $p<tablistePart.length ; $p++){
					var tabInfoPrix=tablistePart[$p].split("-");
					prixTmp=tabInfoPrix[4];
					prixTmp=parseInt(prixTmp);
					if(prixTmp<minPrix){
						minPrix=prixTmp;
					}
				}
			}
			if(tablistePart.length==maxPart){	
				for($p=1 ; $p<tablistePart.length ; $p++){
					var tabInfoPrix=tablistePart[$p].split("-");
					prixTmp= tabInfoPrix[4];
					prixTmp=parseInt(prixTmp);
					if(prixTmp<minPrix){
						maxPart=tablistePart.length;
						idJour=$n;
						minPrix=prixTmp;
					}
				}
			}
		}
	}
	var tmp2=listeMoisJour[idVille][idMois].split("@");
	var jours_tab2=tmp2[1].split("#");
	detailPrix(idVille,idMois,jours_tab2[idJour]);
}

//----------------------------------------------------------------------
// GESTION DE LA LISTE DES PRIX D'UNE DATE
//----------------------------------------------------------------------
function detailPrix(idVille,idMois,idJour){
	genere_listePrix(idVille,idMois,idJour);
	if(precJourPrix!=""){
		fond_off2(precJourPrix);
	}
	document.getElementById('libelleDate').innerHTML=idJour+' '+document.getElementById('libelleMois').innerHTML;
	fond_on2("cell_" + idVille + "_" + idMois + "_" + idJour + "");
	precJourPrix="cell_" + idVille + "_" + idMois + "_" + idJour + "";
}


function genere_listePrix(idVille,idMois,idJour){
	var contenu="";
	var indiceJour="";
	var tmp=listeMoisJour[idVille][idMois].split("@");
	var jours_tab=tmp[1].split("#");
	for ($k=1 ; $k < jours_tab.length ; $k++) {
		if(jours_tab[$k]==idJour){
			indiceJour=$k;
		}
	}	
	var tmp=listePrixJour[idVille][idMois].split("#");
	var listePart=tmp[indiceJour];
	var listePart_tab=listePart.split("@");
	
	contenu=contenu+'<table width="220" class="textenormal" border="0" cellspacing="0" cellpadding="0" style="padding-bottom:1px"><tr><td width="80">&nbsp;</td><td></td><td align="center" style="color:#32556B"></td></tr>';
	for ($k=1 ; $k < listePart_tab.length ; $k++) {
		var infoPrixtab=listePart_tab[$k].split("**");
		id_agence=infoPrixtab[0];
		id_sejour=infoPrixtab[1];
		redf=infoPrixtab[2];
		taxes=infoPrixtab[3];
		prix_TTC=infoPrixtab[4];
		$url3=redf+'reference='+id_sejour;
		contenu=contenu+'<tr onmouseover="this.bgColor=\'#f6fafd\'" onmouseout="this.bgColor=\'#ffffff\'"><td width="80"><a href="'+$url3+'" target="_blank"><img src="'+id_agence+'" border=0></a></td>';
	if(taxes!="false")
			contenu=contenu+'<td > <img src="http://www.zenvoyages.com/image/b_zenvip2.gif" width="50" height="42"></td>';
			else
			zzz="ddd";//contenu=contenu+'<td align="center" width="50" height="35"> </td>';
			
		contenu=contenu+'<td align="center"><a href="'+$url3+'" target="_blank"><FONT color=#2874c0 style="font-size:14px"><b>'+prix_TTC+'&euro;</b> </font><font  color=#2874c0 style="font-size:11px">TTC</font></a></td>';
		
		contenu=contenu+'<td align="right"><a href="'+$url3+'" target="_blank"><img src="http://www.zenvoyages.com/images/voirdetail.gif" border="0"></a></td></tr>';
	}
	contenu=contenu+'</table>';
	document.getElementById('divListePrix').innerHTML=contenu;
}

//----------------------------------------------------------------------
// MISE EN FORME DES CELLULES
//----------------------------------------------------------------------
//lorsque on selectione une ville
function fond_on_ville(cel) {
	cellule = document.getElementById(cel);
	if(precVille!=cel){
		var zone = eval(cellule).style;
		zone.color = "#2a71c3";
	}
}
//lorsque on lache une ville

function fond_off_ville(cel) {
	cellule = document.getElementById(cel);
	if(precVille!=cel){
		var zone = eval(cellule).style;
		zone.color = "#666666";
	}
}
//lorsque on selectione une mois
function fond_on_mois(cel) {
	cellule = document.getElementById(cel);
	if(precMois!=cel){
		var zone = eval(cellule).style;
		zone.color = "#2a73c2";
	}
}
//lorsque on lache une ville
function fond_off_mois(cel) {
	cellule = document.getElementById(cel);
	if(precMois!=cel){
		var zone = eval(cellule).style;
		zone.color = "#32556B";
	}
}
//lorsque on selectione une cellule
function fond_on(cel) {
	cellule = document.getElementById(cel);
	if(precJourPrix!=cel){
		var zone = eval(cellule).style;
		zone.backgroundColor = "#f1f6f9";
		zone.color = "#2a71c1";
	}
}
//lorsque on slache une cellule
function fond_off(cel) {
	cellule = document.getElementById(cel);
	if(precJourPrix!=cel){
		var zone = eval(cellule).style;
		zone.backgroundColor = "#f1f6f9";
		zone.color = "#2a71c1";
	}
}

function fond_on2(cel) {
	cellule = document.getElementById(cel);
	var zone = eval(cellule).style;
	zone.backgroundColor = "#2a71c1";
	zone.color = "#ffffff";
}


function fond_off2(cel) {
	cellule = document.getElementById(cel);
	var zone = eval(cellule).style;
	zone.backgroundColor = "#f1f6f9";
	zone.color = "#2a71c1";
}
function redirige(lien)
{
	re=lien.split("-");
	//alert(re[0]);
	document.redirection.renuits.value=re[0];
		document.redirection.reformule.value=re[1];
	document.redirection.submit();
	}
	
	
	function  charger(im)
{
var tt="";
tt="b"+im;
document.getElementById(tt).style.display="";
for(i=0;i<6;i++)
{
var ttt="";
ttt="b"+i;
var a= document.getElementById(ttt);
if(i!=im && a)
a.style.display="none";
}
}
