﻿function trim(s){
	while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r')){
		s = s.substring(1,s.length);
	}
	while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r')){
		s = s.substring(0,s.length-1);
	}
	return s;
}

var libJAen = "en";
var tbsemaine= new Array(7);
						var tbmois= new Array(12);
						tbmois[0]='Janvier';
						tbmois[1]='Février';
						tbmois[2]='Mars';
						tbmois[3]='Avril';
						tbmois[4]='Mai';
						tbmois[5]='Juin';
						tbmois[6]='Juillet';
						tbmois[7]='Août';
						tbmois[8]='Septembre';
						tbmois[9]='Octobre';
						tbmois[10]='Novembre';
						tbmois[11]='Décembre';
						tbsemaine[0]='Dimanche';
						tbsemaine[1]='Lundi';
						tbsemaine[2]='Mardi';
						tbsemaine[3]='Mercredi';
						tbsemaine[4]='Jeudi';
						tbsemaine[5]='Vendredi';
						tbsemaine[6]='Samedi';
						
function isDateValid(ladate) {
	
   if ((ladate.length != 3) || isNaN(parseInt(ladate[0])) || isNaN(parseInt(ladate[1])) || isNaN(parseInt(ladate[2]))) 
   	return false;
   var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]))
   return ((unedate.getDate() == eval(ladate[0])) && (unedate.getMonth() == eval(ladate[1]-1)) && (unedate.getFullYear() == eval(ladate[2])));
}

						

// Anti-mail non prévu.
// Usage : NoMail( 'fin DNS', 'compte', 'début DNS', 'title du lien' );
function NoMail( s1, s2, s3, title )
{
	document.write( "<a title='" + title + "' href='mailto:" + s2 + "@" + s3 + s1 + "'>" + s2 + "@" + s3 + s1 + "</a>" );
}

// Dessine un flash (correctif pour IE, afin d'éviter le cadre clignotant désagréable)
function draw_flash( name, width, height )
{
	document.write( "<object type=\"application/x-shockwave-flash\" data=\"" + name + "\" style=\"width: " + width + "px; height: " + height + "px\">" );
	document.write( "<param name=\"movie\" value=\"" + name + "\">" );
	document.write( "<param name=\"quality\" value=\"high\">" );
	document.write( "<param name=\"menu\" value=\"false\">" );
	document.write( "</object>" );
}

function recherche()
{
	texte = document.Recherche.Texte.value;
	valid = true;
	if (texte=="")
	{
		alert("Le champ de recherche est vide");
		document.Recherche.Texte.focus();
		valid=false;
	}
	if (valid)
	{
		document.location.href = document.location.href.split("?")[0] + "?p=Search&search="+texte;
	}

}
function fixPNG() {
	if(navigator.appName == 'Microsoft Internet Explorer') {
		var png = /\.png$/;
		var imgs = document.getElementsByTagName("img");
		for(var i = 0 ; i < imgs.length; i++) {
			if(imgs.item(i).src.indexOf(".png")>0) {
				imgs.item(i).style.width = imgs.item(i).offsetWidth;
				imgs.item(i).style.height = imgs.item(i).offsetHeight;
				imgs.item(i).style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + imgs.item(i).src + '\',sizingMethod=\'image\')';
				imgs.item(i).src = '/img/pix.gif';
			}
		}
	}
}

var ladate = new Date();
var Dmonts	= ladate.getMonth();
var Dday		= ladate.getDate();
var Dyear	= ladate.getFullYear();
var Dyear1	= Dyear + 1
	
function Reserv(){
	var monthR = document.forms[0].elements["month"].value
	var dayR = document.forms[0].elements["day"].value
	var yearR = document.forms[0].elements["year"].value
	var nightR = document.forms[0].elements["night"].value
	var adulteR = document.forms[0].elements["adulte"].value

	window.open("http://ldf.reservit.com/reservit/reserhotel.php?lg=u&hotelid=351&fday="+dayR+"&fmonth="+monthR+"&fyear="+yearR+"&nbnights="+nightR+"&nbadt="+adulteR+"");
	
			
}

function AffNbjArrv(){
	var a=leForm.ad.options[leForm.ad.selectedIndex].value;
	var m=leForm.md.options[leForm.md.selectedIndex].value;
	var d = new Date(a,m,0);
	var nbj=d.getDate();
	var i,j,o,sel;
	sel=leForm.jd.options.selectedIndex;
	//vidage de la liste
	leForm.jd.length=0;

	for (i=1;i<=nbj;i++){
		j=f(i,2);
		//création des options
		o=new Option(j,j);
		leForm.jd.options[leForm.jd.options.length]=o;
	}
	//sélection du jour en cours
	if ( (sel>0) && (leForm.jd.options[sel]) ){
		leForm.jd.options[sel].selected = 1; 
	}
}

function changeSel(f,s) {
	var maxduree=180;
	var c=s.name;
	var ladate=new Array(3);
	var testjma="";
	var dur=0;
	var j=0;
	var m=0;
	var a=0;
	switch(c) { 
		case "jd" : 
			j=s.options[s.options.selectedIndex].value;		
			m=f.md.options[f.md.options.selectedIndex].value; 
			a=f.ad.options[f.ad.options.selectedIndex].value; 
			testjma="Arrivee";
			break;
		case "md" : 
			m=s.options[s.options.selectedIndex].value;	
			j=f.jd.options[f.jd.options.selectedIndex].value; 
			a=f.ad.options[f.ad.options.selectedIndex].value; 
			testjma="Arrivee";
			break;
		case "ad" : 
			a=s.options[s.options.selectedIndex].value;
			j=f.jd.options[f.jd.options.selectedIndex].value; 
			m=f.md.options[f.md.options.selectedIndex].value; 
			testjma="Arrivee";
			break; 
		case "Sduree" : 
			a=f.ad.options[f.ad.options.selectedIndex].value; 
			j=f.jd.options[f.jd.options.selectedIndex].value; 
			m=f.md.options[f.md.options.selectedIndex].value; 
			testjma="Arrivee";
			break; 
		default : 
			break;	
	}	
	if (testjma != "") { 
		ladate[0]=j*1;
		ladate[1]=m*1;
		ladate[2]=a*1;
		if ( ladate[0] != libJAen    && (isDateValid(ladate))){
			d=new Date(ladate[2],ladate[1]-1,ladate[0]);
			dur=f.Sduree.value;
			d=new Date(ladate[2],ladate[1]-1,ladate[0]+Math.max(1,dur));
			leForm.jf.value=d.getDate();
			leForm.mf.value=d.getMonth()+1;
			leForm.af.value=d.getFullYear();
			AffJourDepart();
		}
	}
	if (f.name=='form1' | f.name=='form2' | f.name=='formto' ) { 
		f.benter.focus();	
	}	
}

function monBlurDuree(f,zone,coul){
	var num=zone.value;
	num=num.replace(/\D+/g,"");
	zone.value=num;
 	zone.style.backgroundColor=coul;
	if ( zone.name=="Sduree" && trim(zone.value) != "" && trim(zone.value) > 0  ) {
		changeSel(f,zone);   
	}		
}

function AffJourDepart(){
	var ladate=new Array(3);
	ladate[0]=leForm.jf.value.toString();
	ladate[1]=leForm.mf.value.toString();
	ladate[2]=leForm.af.value.toString();
	if (isDateValid(ladate)){
		d=new Date(ladate[2],ladate[1]-1,ladate[0]);
	}
}

function f(nombre, taille) {
  var chaine = nombre.toString();
  while (chaine.length < taille) chaine = "0" + chaine;
  return chaine;
}
