
var gOldDiv = 0;

function OpenDiv ( vDivId  ) {
   if ( gOldDiv != 0 ) {
		document.getElementById( "divpays" + gOldDiv ).className = "paysclose";
		document.getElementById( "divvilles" + gOldDiv ).className = "villesclose";
	}
	if ( gOldDiv != vDivId ) {
		document.getElementById( "divpays" + vDivId ).className = "paysopen";
		document.getElementById( "divvilles" + vDivId ).className = "villesopen";
		gOldDiv = vDivId;
	} else {
		gOldDiv = 0;
	}
}

function DoImage ( vImageId  ) {
	var vDiv;
	
	for ( var i = 1 ; i < 20 ; i++ ) {
		vDiv = document.getElementById( "divimage" + i );
		if ( vDiv != null ) {
			vDiv.className = "imagevisibleFalse";
		}
	}
	
	vDiv = document.getElementById( "divimage" + vImageId );
	vDiv.className = "imagevisibleTrue";
}

function DoSelecteur ( select1 , select2  ) {
	if (  document.getElementById( select1 ).selectedIndex > document.getElementById( select2 ).selectedIndex ) {
		document.getElementById( select2 ).selectedIndex = document.getElementById( select1 ).selectedIndex;
	}
}

function hhoteldistrib (distnum, lg, codetrack, codetx , firstdate, roomname , currency) 
{ 
            var waction = "http://portal.fastbooking-sa.fr/fiche/resa.phtml?DistNum="+distnum;
            if (lg != "") waction += "&langue="+lg;
            waction += "&style=DIRECT";
            waction += "&FSTBKNGCode="+codetx; 
            waction += "&FSTBKNGTrackLink="+codetrack;
			if (firstdate != "") waction += "&FirstDate="+firstdate;
			if(roomname != "") waction += "&FirstRoomName="+roomname;
			if(currency != "") waction += "&CurrencyLabel="+ currency;
            window.open(waction,"reservation","toolbar=no,width=700,height=700,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
}

function WindowCancel (language) {
	if ( language == 'fr' ) {
		waction = "/popup.aspx?url=/fiche/cancel.phtml";
	} else {
		waction = "/popup.aspx?url=/fiche/cancel.phtml?language=uk";
	}
	
	window.open(waction,"cancel","location=0,toolbar=no,width=750,height=550,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
	//return false;
}

function WindowDetails(language) {
	if ( language == 'fr' ) {
		waction = "/popup.aspx?url=/fiche/history.phtml";
	} else {
		waction = "/popup.aspx?url=/fiche/history.phtml?language=uk";
	}
	
	window.open(waction,"history","location=0,toolbar=no,width=750,height=550,menubar=no,scrollbars=yes,resizable=yes,alwaysRaised=yes");
	//return false;
}


//=====================================================================================================
//=====================================================================================================

moisX=["","Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre"];
JourM=["Di","Lu","Ma","Me","Je","Ve","Sa"];
CloseTexte="Fermer le calendrier";

var fermable_microcal=true;
var select_old= null;
var startWeek=1;//debut de la semaine 0=dim,1=lun,...
var jourPause={0:true,6:true}; //jour de pause de la semaine
//structure la date 
function strucDate(dateX) {
	return {"pos":dateX.getDay(),"jour":dateX.getDate(),"mois":dateX.getMonth(),"annee":dateX.getFullYear()};
}

function strucDateNow(dateX) {
	return {"pos":dateX.getDay(),"jour":dateX.getDate(),"mois":dateX.getMonth()+1,"annee":dateX.getFullYear()};
}

var oDivId ='';
var oDayId;
var oMonthId;
var oDayDepartId;
var oMonthDepartId;
var oIsDepart;

var dateSS;
var dateS= strucDate(new Date());//date Selectionné
var dnow= strucDateNow(new Date());//date actuelle
var dmindate= strucDate(new Date());//date actuelle

//retourne le ième jour du 1er du mois
function premJourMois(mois,annee) {
	return (new Date(annee,mois-1,1).getDay());
}
	
//retourne le jour max du mois
function JmaxMois(mois,annee) {
	return (new Date(annee,mois,0).getDate());
}
	
/* Test une date si elle est correct...spécial killer*/
function testTypeDate(dateEntree) {
	tst=false;
	try {
		rc=dateEntree.split("/");nd=new Date(rc[2],(rc[1]-1),rc[0]);
		tst=(rc[2]>1800&&rc[2]<2200&&rc[2]==nd.getFullYear()&&rc[1]==(nd.getMonth())&&rc[0]==nd.getDate());
	} catch(e) {}
	return tst;
}

//selection de la zone avec la souris
function choix(koi,code) {
	
	if (code) {  
		select_old = koi.className;
		koi.className = "cellactiveselected";
	} else {
		koi.className = select_old;
	}
}

function testTravail(oldX,xx,jj,mm,aa) {
	return "cellactive";
}

//test si année bissextile
function bissextile(annee) {
	return (annee%4==0 && annee %100!=0 || annee%400==0);
}

//Retourne le nombre de jour depuis le 1er janvier (num de semaine)
function nbJAnnee(dateX){
	var nb_mois=[,0,31,59,90,120,151,181,212,243,273,304,334];
	j=dateX.jour ; m=dateX.mois ; a=dateX.annee;
	nb=nb_mois[m]+j-1 ;
	if (bissextile(a) && m>2) nb++;
	return nb;
}

function DoClick(jjs,mms,aas) {
	if ( oIsDepart == '0') {
		document.getElementById( oDayId ).value = jjs;
		document.getElementById( oMonthId).value = mms + ' ' + aas;
		
		if ( document.getElementById( oMonthDepartId ).selectedIndex <  document.getElementById( oMonthId).selectedIndex ) {
			document.getElementById( oMonthDepartId).selectedIndex =  document.getElementById( oMonthId ).selectedIndex;
		} 
		
		if ( document.getElementById( oMonthDepartId ).selectedIndex <=  document.getElementById( oMonthId).selectedIndex &&
			document.getElementById( oDayDepartId ).selectedIndex <  document.getElementById( oDayId ).selectedIndex ) {
			document.getElementById( oDayDepartId ).selectedIndex =  document.getElementById( oDayId ).selectedIndex + 1;
		} 
		
	} else {
		document.getElementById( oDayDepartId ).value = jjs;
		document.getElementById( oMonthDepartId).value = mms + ' ' + aas;
	}
	view_microcal(false,0,0);
}

function CalendrierInit (actif,mxS,axS,DivId,DayId,MonthId,DayDepartId,MonthDepartId,IsDepart) {
	
	if ( oDivId.length > 0 ) {
		 document.getElementById(oDivId).style.display='none';
	}

	oDivId = DivId;
	oDayId = DayId;
	oMonthId = MonthId;
	oDayDepartId = DayDepartId;
	oMonthDepartId = MonthDepartId;
	oIsDepart = IsDepart;
	
	if ( oIsDepart == '0') {
		var MonthYear = document.getElementById( oMonthId ).value;
		MonthYear = MonthYear.split(' ');
	
		dateS = strucDate( new Date( parseInt ( MonthYear[1]) ,  parseInt (MonthYear[0]) , parseInt (document.getElementById( oDayId ).value) ));
		dateSS = strucDate( new Date( parseInt ( MonthYear[1]) ,  parseInt (MonthYear[0]) , parseInt (document.getElementById( oDayId ).value) ));
		dmindate = strucDateNow(new Date());
		
	} else {
		var MonthYear = document.getElementById( oMonthDepartId ).value;
		MonthYear = MonthYear.split(' ');
	
		dateS = strucDate( new Date( parseInt ( MonthYear[1]) ,  parseInt (MonthYear[0]) , parseInt (document.getElementById( oDayDepartId ).value) ));
		dateSS = strucDate( new Date( parseInt ( MonthYear[1]) ,  parseInt (MonthYear[0]) , parseInt (document.getElementById( oDayDepartId ).value) ));
		
		MonthYear = document.getElementById( oMonthId ).value;
		MonthYear = MonthYear.split(' ');
		dmindate = strucDate( new Date( parseInt ( MonthYear[1]) ,  parseInt (MonthYear[0]) , parseInt (document.getElementById( oDayId ).value) ));
	}
	
	view_microcal(actif,mxS,axS);
}

//affiche le calendrier
function view_microcal(actif,mxS,axS) {
	if (actif) {
		//decalage du mois su on clique sur -/+
		if (mxS!=-1) {
			//clearTimeout(cc);
			fermable_microcal=true;
			dateS.mois=mxS;
			dateS.annee=axS;
			if (dateS.mois<1) {
				dateS.annee--;dateS.mois+=12;
			}
			if (dateS.mois>12) {
				dateS.annee++;dateS.mois-=12;
			}
		}
		//init
		Dstart=(premJourMois(dateS.mois,dateS.annee)+7-startWeek)%7;
		jmaxi=JmaxMois(dateS.mois,dateS.annee);
		jmaxiAvant=JmaxMois((dateS.mois-1),dateS.annee);
		//si on veux ajouter le numero de la semaine ...
		//idxWeek=parseInt(nbJAnnee(strucDate(new Date(dateS.mois+'-01-'+dateS.annee)))/7,10)+1;
		ymaxi=parseInt((jmaxi+Dstart+1)/7,10);
		//generation du tableau
		//--entête
		htm="<table class='calendrier' cellpadding='0' cellspacing='0' border='0'><tr>";
		htm+="<td  class='classhand'><a href=\"javascript:view_microcal(true,"+(dateS.mois-1)+","+dateS.annee+");\"><img src=\"/images/flecheG.gif\" border=\"0\"></a></td>";
		htm+="<td colspan='5'><span class='celltitre'>"+moisX[dateS.mois]+"&nbsp;"+dateS.annee+"</span></td>";
		htm+="<td  class='classhand'><a href=\"javascript:view_microcal(true,"+(dateS.mois+1)+","+dateS.annee+");\"><img src=\"/images/flecheD.gif\" border=\"0\"></a></td>";
		//--corps
		htm+="<tr>";
		//affichage des jours DLMMJVS
		for (x=0;x<7;x++) 
			htm+="<td><span class='celltitre'>"+JourM[(x+startWeek)%7]+"</span></td>";
			
		htm+="</tr>"
		//------------------------
		for (y=0;y<=ymaxi;y++) {
			htm+="<tr>";
			for (x=0;x<7;x++) {
				idxP=y*7+x-Dstart+1;   //numero du jour
				aa=dateS.annee;
				xx=(x+startWeek)%7;
				//jour du mois précedent
				if (idxP<=0) {
					jj=idxP+jmaxiAvant;mm=dateS.mois-1;
					if (mm==0) {
						mm=12;aa--;
					}
					htm+="<td class='celldisable'>"+jj+"</td>";
				} else if (idxP>jmaxi) { //jour du mois suivant
					jj=idxP-jmaxi;mm=dateS.mois+1;
					if (mm==13) {
						mm=1;aa++;
					}
					htm+="<td class='celldisable'>"+jj+"</td>";
				} else { //jour du mois en cours
					jj=idxP;mm=dateS.mois;
					//alert ('e');
					//alert ( jj + mm * 100 + aa * 10000 );
					//alert ( dmindate.jour + dmindate.mois * 100 + dmindate.annee * 10000 );
					if ( jj + mm * 100 + aa * 10000 < dmindate.jour + dmindate.mois * 100 + dmindate.annee * 10000) {
						htm+="<td class='celldisable'>"+jj+"</td>";
					} else if ( dateSS.mois == mm && dateSS.annee == aa && dateSS.jour == jj )  {
						htm+="<td class='cellselected' onmouseover='choix(this,true)' onmouseout='choix(this,false)'  onclick=\"DoClick('"+jj+"','"+mm+"','"+aa+"')\">"+jj+"</td>";			
					} else {
						htm+="<td class='"+testTravail(true,xx,jj,mm,aa)+"' onmouseover='choix(this,true)' onmouseout='choix(this,false)'  onclick=\"DoClick('"+jj+"','"+mm+"','"+aa+"')\"><a href=\"#\">"+jj+"</a></td>";			
					} 
				}
			}
			htm+="</tr>"
		}//-------------------------
		htm+="<tr>";
		htm+="<td colspan='7'><a href=\"javascript:view_microcal(false,"+(dateS.mois+1)+","+dateS.annee+")\" class='celltitre2'>" + CloseTexte + "</a></td>";
		htm+="</tr>";

	
		htm+="</table>"
		
		document.getElementById( oDivId ).innerHTML=htm;
		document.getElementById( oDivId ).style.display='block';
		
	} else { //ferme le calendrier
		if (fermable_microcal) {
			 document.getElementById( oDivId ).style.display='none';
		}
	}
}

function bulle ( evt , name ) {
 
	var xfenetre,yfenetre,xpage,ypage,element=null;
	var offset= 15;
	
	if ( document.getElementById == false ) {
		return;
	}
		
	divKeyword = document.getElementById( name );

	divKeyword.style.left = (evt.clientX + 15) + "px";
	divKeyword.style.top = evt.clientY + "px";
	divKeyword.style.visibility = "visible";
}

function ferme ( name ){
	document.getElementById( name ).style.visibility = "hidden";
}