//
// global declarations and initialization
//

var htmlBuffer = '';
var FirstAvailDay = new Date(2009,6,1);
var LastAvailDay = new Date(2030,11,31);
var FirstDay = FirstAvailDay;
var LastDay = LastAvailDay;



function init () 
{
  theDate         = FirstDay;
  today           = FirstDay;
  currMonth       = today.getMonth();
  msPerDay        = 24*60*60*1000;

  dispMonth = currMonth;
  dispYear = GetTheYear(today);
  
  monthName     = new makeArray(12);
  monthName[1]  = "Janvier";
  monthName[2]  = "Février";
  monthName[3]  = "Mars";
  monthName[4]  = "Avril";
  monthName[5]  = "Mai";
  monthName[6]  = "Juin";
  monthName[7]  = "Juillet";
  monthName[8]  = "Août";
  monthName[9]  = "Septembre";
  monthName[10] = "Octobre";
  monthName[11] = "Novembre";
  monthName[12] = "Décembre";

}


//
// entry point
//



function OpenCalendar (dateFldname , formNumber) 
{

  if (dateFldname == 'begindate')
    {
      FirstDay = FirstAvailDay;
      LastDay = LastAvailDay;
    }
  else
    {
        setDate('DMY4');
	sBeginDate = String(eval("document.forms[" + formNumber + "].begindate.value")+"/");
//	sBeginDate = String(eval("document.forms[" + formNumber + "].elements['enddateday'].options[document.availinfo.elements['enddateday'].selectedIndex].value
debut=0;idx = sBeginDate.indexOf('/',debut);
numday=parseInt(sBeginDate.substr(debut,idx-debut),10);
debut=idx+1;
idx = sBeginDate.indexOf('/',debut);
nummonth=parseInt(sBeginDate.substr(debut,idx-debut),10);
debut=idx+1;
idx = sBeginDate.indexOf('/',debut);
numyear=parseInt(sBeginDate.substr(debut,idx-debut),10);
debut=idx+1;
      numday=numday+1;
      nummonth=nummonth-1;
      FirstDay = new Date(numyear,nummonth,numday);
      LastDay = LastAvailDay;
    }
 
     

  init();

  // champ de la page de depart
  formNum  = formNumber;
  dateFld  = dateFldname;

  windowOptions  = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=yes,width=275,height=290";
  calendarWindow = this.open("","calendarWindow",windowOptions);

  calendarWindow.callingForm = this;

  redraw();
}

//
// repaint the calendar
//
function redraw() 
{
  calendarWindow.callingForm = this;
  if (dispYear < 1900)
    firstOfMonth  = new Date(dispYear+1900,dispMonth,1);
  else
    firstOfMonth  = new Date(dispYear,dispMonth,1);

  calendarWindow.document.open();
  calTitle = "\n";
  calendarWindow.document.write(calTitle);
  drawCalendar(firstOfMonth);
  calendarWindow.document.write(htmlBuffer);
  calendarWindow.document.close();
  calendarWindow.callingForm = this;
  calendarWindow.focus();
}


//
// fill the calling forms date and month
//
function fillDate(day, month, year) 
{
  eval("document.forms[" + formNum + "]." + dateFld  + ".value="+"''+day+'/'+month+'/'+year+''");
  eval("document.forms[" + formNum + "]." + dateFld  + "day"+".value=\""+day+"\"");
  eval("document.forms[" + formNum + "]." + dateFld  + "month"+".value=\""+month+"\"");
  eval("document.forms[" + formNum + "]." + dateFld  + "year"+".value=\""+year+"\"");

   day--;
   year -= 2009;
  
   eval("document.forms[" + formNum + "]." + dateFld  + "day.selectedIndex=\""+day+"\"");
   eval("document.forms[" + formNum + "]." + dateFld  + "month.selectedIndex=\""+month+"\"");
   eval("document.forms[" + formNum + "]." + dateFld  + "year.selectedIndex=\""+year+"\"");


   if (dateFld != "enddate")
     {
       updateEndDate(document.availinfo.elements['begindateday'].options[document.availinfo.elements['begindateday'].selectedIndex].value,
		     document.availinfo.elements['begindatemonth'].options[document.availinfo.elements['begindatemonth'].selectedIndex].value,
		     document.availinfo.elements['begindateyear'].options[document.availinfo.elements['begindateyear'].selectedIndex].value,
		     document.availinfo.nbnight.value);
     }
   else
     {
       updateNbNight(
		     document.availinfo.elements['enddateday'].options[document.availinfo.elements['enddateday'].selectedIndex].value,
		     document.availinfo.elements['enddatemonth'].options[document.availinfo.elements['enddatemonth'].selectedIndex].value,
		     document.availinfo.elements['enddateyear'].options[document.availinfo.elements['enddateyear'].selectedIndex].value,
		     document.availinfo.elements['begindateday'].options[document.availinfo.elements['begindateday'].selectedIndex].value,
		     document.availinfo.elements['begindatemonth'].options[document.availinfo.elements['begindatemonth'].selectedIndex].value,
		     document.availinfo.elements['begindateyear'].options[document.availinfo.elements['begindateyear'].selectedIndex].value);
     }

  calendarWindow.close();
}


function isLeapYear (Year) {
    if (((Year % 4)==0) && ((Year % 100)!=0) || ((Year % 400)==0)) {
	return true;
    } 
    else {
	return false;
    }
}

function updateNbNight(day1,month1,year1,day2,month2,year2){
/*    
    date1 = new Date(year1,month1-1,day1);
    date2 = new Date(year2,month2-1,day2);

     var difference =
         Date.UTC(y2k(date1.getYear()),date1.getMonth(),date1.getDate(),0,0,0)
       - Date.UTC(y2k(date2.getYear()),date2.getMonth(),date2.getDate(),0,0,0);

     diff = difference/1000/60/60/24;
     if(diff > 0) eval("document.availinfo.nbnight.value=\""+diff+"\"");
*/
}

function setDate(dateformat){

    if(dateformat == 'DMY4'){
	
	eval("document.availinfo.begindate.value=\""+
	     document.availinfo.elements['begindateday'].options[document.availinfo.elements['begindateday'].selectedIndex].value
+"/"+ 
	     document.availinfo.elements['begindatemonth'].options[document.availinfo.elements['begindatemonth'].selectedIndex].value
+"/"+
	     document.availinfo.elements['begindateyear'].options[document.availinfo.elements['begindateyear'].selectedIndex].value

	     +"\"");

	eval("document.availinfo.enddate.value=\""+
	     document.availinfo.elements['enddateday'].options[document.availinfo.elements['enddateday'].selectedIndex].value
+"/"+ 
	     document.availinfo.elements['enddatemonth'].options[document.availinfo.elements['enddatemonth'].selectedIndex].value
+"/"+
	     document.availinfo.elements['enddateyear'].options[document.availinfo.elements['enddateyear'].selectedIndex].value

	     +"\"");
    }
    else{
	eval("document.availinfo.begindate.value=\""+
	     document.availinfo.elements['begindatemonth'].options[document.availinfo.elements['begindatemonth'].selectedIndex].value
+"/"+
	     document.availinfo.elements['begindateday'].options[document.availinfo.elements['begindateday'].selectedIndex].value
+"/"+ 
	     document.availinfo.elements['begindateyear'].options[document.availinfo.elements['begindateyear'].selectedIndex].value
	     +"\"");
	
	eval("document.availinfo.enddate.value=\""+
	     document.availinfo.elements['enddatemonth'].options[document.availinfo.elements['enddatemonth'].selectedIndex].value
+"/"+
	     document.availinfo.elements['enddateday'].options[document.availinfo.elements['enddateday'].selectedIndex].value
+"/"+ 
	     document.availinfo.elements['enddateyear'].options[document.availinfo.elements['enddateyear'].selectedIndex].value

	     +"\"");
    } 
    
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function updateYear(fieldmonth, fieldyear)
{
  month = document.availinfo.elements[fieldmonth].options[document.availinfo.elements[fieldmonth].selectedIndex].value;
  year = document.availinfo.elements[fieldyear].options[document.availinfo.elements[fieldyear].selectedIndex].value;

  if (fieldmonth == "begindatemonth")
    {
      if (month <= parseInt('07',10) && year == parseInt('2009',10) ) 
	{
	  document.availinfo.elements[fieldyear].selectedIndex++;
	  
	  updateEndDate(document.availinfo.elements['begindateday'].options[document.availinfo.elements['begindateday'].selectedIndex].value,
			document.availinfo.elements['begindatemonth'].options[document.availinfo.elements['begindatemonth'].selectedIndex].value,
			document.availinfo.elements['begindateyear'].options[document.availinfo.elements['begindateyear'].selectedIndex].value,
			document.availinfo.nbnight.value);
	  updateNbNight( document.availinfo.elements['enddateday'].options[document.availinfo.elements['enddateday'].selectedIndex].value,
			 document.availinfo.elements['enddatemonth'].options[document.availinfo.elements['enddatemonth'].selectedIndex].value,
			 document.availinfo.elements['enddateyear'].options[document.availinfo.elements['enddateyear'].selectedIndex].value,
			 document.availinfo.elements['begindateday'].options[document.availinfo.elements['begindateday'].selectedIndex].value,
			 document.availinfo.elements['begindatemonth'].options[document.availinfo.elements['begindatemonth'].selectedIndex].value,
			 document.availinfo.elements['begindateyear'].options[document.availinfo.elements['begindateyear'].selectedIndex].value);
	}
    }
}

function updateEndDate(myDay,myMonth,myYear,daysToAdd) {

  //savemyYear = myYear;
  //savemyYear = 
  savemyYear = document.availinfo.elements['enddateyear'].options[document.availinfo.elements['enddateyear'].selectedIndex].value;

  myMonth = myMonth - 1;
    convertDate = new Date(myYear,myMonth,myDay,8,0,0);
    newDate = new Date(convertDate.getTime() + daysToAdd*24*60*60*1000);
    
    if (convertDate.getDay() == newDate.getDay() && 
	convertDate.getMonth() == newDate.getMonth() && 
	convertDate.getFullYear() == newDate.getFullYear())
      {
	newDate = new Date(convertDate.getTime() + ((daysToAdd*24)+1)*60*60*1000);
      }

    CurDay = newDate.getDate();
    CurMonth = newDate.getMonth();
    CurYear = y2k(newDate.getYear()); 

    CurMonth = CurMonth +1;

    if (CurMonth<10)
	CurMonth = "0"+CurMonth;
    if (CurDay<10)
	CurDay = "0"+CurDay;

    if ((CurDay > 0) && (CurMonth > 0) && (CurYear >0)) 
      {
      
      try {

    	// DEV-#253: Todate = Fromdate + 1
    	document.availinfo.elements['enddateday'].selectedIndex=(CurDay - 1);
    	document.availinfo.elements['enddatemonth'].selectedIndex=(CurMonth-1);
    	if (savemyYear != CurYear)
    	  {
    	    if (savemyYear <= CurYear)
    	      document.availinfo.elements['enddateyear'].selectedIndex=(document.availinfo.elements['enddateyear'].selectedIndex +1);
    	    else
    	      
    	      document.availinfo.elements['enddateyear'].selectedIndex=(document.availinfo.elements['enddateyear'].selectedIndex -1);
    	  }

      } catch(e) {
      
      }
      

      }
}


//
// set the month
//
function changeMonth (increment) 
{
  nextMonth = dispMonth;
  nextYear = dispYear;

  if (increment == 1) 
    {
      nextMonth++ ;
      if (nextMonth>11)
	{
	  nextYear++;
	  nextMonth = 0;
	}
    } 
  else 
    {
      nextMonth-- ;
      if (nextMonth<0)
	{
	  nextMonth = 11;
	  nextYear--;
	}
    }

  if ((Date2_sup_Date1 (1,nextMonth,nextYear,1,LastDay.getMonth(),GetTheYear(LastDay))) && (Date2_sup_Date1 (1,FirstDay.getMonth() ,GetTheYear(FirstDay),1,nextMonth,nextYear)))
    {
      dispMonth = nextMonth;
      dispYear = nextYear;
      redraw();
    }

//  document.cookie="dispMonth="+nextMonth;
}


// compare 2 dates:
// vrai si date2 >= date1;

function Date2_sup_Date1 (Day1, Month1, Year1, Day2, Month2, Year2)
{

  if (Day1<=9)
    Day1 = '0'+Day1;
  if (Day2<=9)
    Day2 = '0'+Day2;
  if (Month1<=9)
    Month1 = '0'+Month1;
  if (Month2<=9)
    Month2 = '0'+Month2;

  if (Year2>Year1)
    return true;
  else
    {
      if (Year2 == Year1)
	{
	  if (Month2>Month1)
	    return true;
	  else
	    {
	      if (Month2 == Month1)
		{
		  if (Day2>=Day1)
		    return true;
		  else
		    return false;
		}
	      else 
		return false;
	    }
	}
      else 
	return false;
    }

}


function drawCalendar (theDate) 
{
  monthNum = theDate.getMonth() + 1;

  htmlBuffer  = "<HTML>\n";
  htmlBuffer += "<HEAD>\n";
  htmlBuffer += '';
  htmlBuffer += "\n<TITLE>Calendrier</TITLE></HEAD>\n";
  htmlBuffer += "</HEAD>\n\n";
  htmlBuffer += "<BODY bgcolor=\"white\">\n";
  htmlBuffer += "<FORM>\n";
  htmlBuffer += "<CENTER>\n<TABLE>\n";
  htmlBuffer += "<TH COLSPAN=\"2 \"class=\"backgroundtitle\">\n";
  htmlBuffer += "  <INPUT TYPE=BUTTON NAME=\"monthDn\" VALUE=\"<<\" onClick=callingForm.changeMonth(-1)>\n";
  htmlBuffer += "<TH COLSPAN=3 class=\"calendar_month\"> ";
  htmlBuffer += monthName[monthNum];
  tempYear = GetTheYear(theDate);
  htmlBuffer += " " + tempYear;
  htmlBuffer += "<TH COLSPAN=2 class=\"backgroundtitle\">\n<INPUT TYPE=\"button\" NAME=\"monthUp\" VALUE=\">>\" onClick=callingForm.changeMonth(1)>\n";

  htmlBuffer += "<TR class=\"calendar_date\">\n";
  htmlBuffer += "<TH WIDTH = 14.29% class=\"background\"><FONT class='calendar_date'><b>D</b></FONT>\n";
  htmlBuffer += "<TH WIDTH = 14.29%><FONT class='calendar_date'><b>L</b></FONT>\n";
  htmlBuffer += "<TH WIDTH = 14.29%><FONT class='calendar_date'><b>Ma</b></FONT>\n";
  htmlBuffer += "<TH WIDTH = 14.29%><FONT class='calendar_date'><b>Me</b></FONT>\n";
  htmlBuffer += "<TH WIDTH = 14.29%><FONT class='calendar_date'><b>J</b></FONT>\n";
  htmlBuffer += "<TH WIDTH = 14.29%><FONT class='calendar_date'><b>V</b></FONT>\n";
  htmlBuffer += "<TH WIDTH = 14.29% class=\"background\"><FONT class='calendar_date'><b>S</b></FONT><TR>\n";
  drawBody(theDate);
  htmlBuffer += "</TABLE>\n";
  htmlBuffer += "</BODY>\n</HTML>\n";
}


function drawBody (theDate) 
{
  thisYear = GetTheYear(theDate);
  thisMonth = theDate.getMonth();
  thisDate  = theDate.getDate();

  firstY = GetTheYear(FirstDay);
  firstM = FirstDay.getMonth();
  firstD = FirstDay.getDate();

  lastY = GetTheYear(LastDay);
  lastM = LastDay.getMonth();
  lastD = LastDay.getDate();
  
  firstSunday(theDate);

  for (w=0; w<6; w++) 
    {
      if ((theDate.getMonth() == thisMonth) || (w==0)) // Avoid the last line
	{
	  for (d=0; d<7; d++) 
	    {
	      date = theDate.getDate();

	      htmlBuffer   += "<TD ALIGN=CENTER HEIGHT = 30";
	      if ((d==0) || (d==6))
		htmlBuffer += " class=\"background\"";
	      htmlBuffer += "><FONT class='calendar_day'>";

	      // skip previous month
	      if (theDate.getMonth() != thisMonth) 
		{
		  htmlBuffer += "<BR>";
		} 
	      else 
		{
		  if (Date2_sup_Date1(firstD, firstM, firstY, date,thisMonth,thisYear) && Date2_sup_Date1(date,thisMonth,thisYear,lastD, lastM, lastY))
		    {
		      htmlBuffer += "<INPUT TYPE=BUTTON NAME=";
		      htmlBuffer += date;
		      htmlBuffer += " VALUE=";
		      if ( date < 10 ) 
			{
			  htmlBuffer += "0";
			}
		      htmlBuffer += date;
		      htmlBuffer += " onClick=callingForm.fillDate("+date+","+thisMonth+","+thisYear+")>";
		    }
		  else
		    {
		      if ( date < 10 ) 
			{
			  htmlBuffer += "0";
			}
		      htmlBuffer += date;
		    }
		}
	      htmlBuffer += "</TD>\n";
	      // increment the date
	      newTime = theDate.getTime() + msPerDay;
	      //theDate.setTime(newTime);

	      // check for DST 
	      theDate.setTime(newTime + 60*60*24);
	    }
	  htmlBuffer += "</TR>\n<TR HEIGHT = 40>\n";
	}
    }
  htmlBuffer += "</FORM>";
}

function makeArray(n) 
{
  this.length = n;
  return this;
}
function firstSunday (fromDate) 
{
  fromDate.setHours(22);
  while (fromDate.getDay() != 0) 
    {
      newTime = fromDate.getTime() - msPerDay;
      //fromDate.setTime(newTime);
      
      	fromDate.setTime(newTime + 60*60*24);
    }
}

function ExtractDate (field, portion)
{
  var date = new String(eval('document.availinfo.'+field+'.value'));
  var datearray = date.split('/');
  
  if (datearray.length<3)
    return 0;

  if (portion == 'day')
    return datearray[0];
  if (portion == 'month')
    return datearray[1];
  if (portion == 'year')
    return datearray[2];
    
}


function checkdate(d,m,y)
 {
   if (y < 100)
     {
       y = y+1900;
     }
   var yl=1990;   // least year to consider
   var ym=2010;   // most year to consider
   if (m<1 || m>12)  return(false);
   if (d<1 || d>31)  return(false);
   if (y<yl || y>ym) return(false);
   if (m==4 || m==6 || m==9 || m==11)
     if (d==31) return(false);
   if (m==2)
   {
     var b=parseInt(y/4);
     if (isNaN(b)) return(false);
     if (d>29)     return(false);
     if (d==29 && ((y/4)!=parseInt(y/4))) return(false);
   }
   return(true);
 }


function Verify()
{
  if (document.availinfo.currency && document.availinfo.currency.type == "select")
    {
      if (document.availinfo.currency.options[document.availinfo.currency.selectedIndex].value == "???")
	document.availinfo.currency.selectedIndex=0;
    }

  if (!availinfo_Validator(document.availinfo))
    {
      return false;
    }
  
  var str="";
  var nbchilds = 0;
  if (document.availinfo.nbchilds)
    {
      nbchilds = document.availinfo.nbchilds.value;
      if (nbchilds > 0)
	{
	  for (idxAge=1; idxAge<=nbchilds; idxAge++)
	    {
	      elem = eval("document.availinfo.elements['ages"+idxAge+"']");
	      if (elem == null || (elem != null && elem.value<=0))
		{
		  str += "\nEnfant "+idxAge;
		}
	    }
	  
	  if (str!="") { alert("Les ages des enfants suivants sont incorrects:"+str);  return false; }
	}
    }

var numRoom = parseInt(document.availinfo.nbroom.value);
var numAdults = parseInt(document.availinfo.numadult.options[document.availinfo.numadult.selectedIndex].value);
if (document.availinfo.numsenior) { numAdults += parseInt(document.availinfo.numsenior.options[document.availinfo.numsenior.selectedIndex].value); }
var numtotal = parseInt(document.availinfo.numadult.options[document.availinfo.numadult.selectedIndex].value);if (document.availinfo.numsenior) { numtotal += parseInt(document.availinfo.numsenior.options[document.availinfo.numsenior.selectedIndex].value); }
+ parseInt(document.availinfo.nbchilds.options[document.availinfo.nbchilds.selectedIndex].value);
var roomid = parseInt(document.availinfo.currentroomid.value);
      
      for (i = 0; i < document.availinfo.length; i++)
	{
	  var idx=1;
	  if (document.availinfo.elements[i].name == 'agepax'+idx)
	    {
	      idx++;
	      if (document.availinfo.elements[i].value != '')
		numtotal = numtotal + 1;
	    }
	}
      
      // si le champs nbre de chambre a reserver est = 0
      if (numRoom == 0)
	{
	  // JBG chambres multiples 
	  alert ("Vous devez réserver au moins une chambre !");
	  return false;
	}
      
      // Si on est à la première chambre et qu'on a mis aucun adulte
      if ( roomid == 1 && numAdults == 0)
	{
	  // JBG chambres multiples 
	  alert ("Au moins un adulte est requis pour cette chambre");
	  return false;
	}
      
      // Si il n'y a personne pour cette chambre
      if ( numtotal < 1 )
	{
	  // JBG chambres multiples 
	  alert ("Il faut au moins une personne pour cette chambre!");
	  return false;
	}
      
if (numtotal>5){alert ('Le nombre maximum de personne est: 5');return false;}   
	  var beginday = ExtractDate ('begindate', 'day');
	  var beginmonth = ExtractDate ('begindate', 'month');
	  var beginyear = ExtractDate ('begindate', 'year');
	  var endday = ExtractDate ('enddate', 'day');
	  var endmonth = ExtractDate ('enddate', 'month');
	  var endyear = ExtractDate ('enddate', 'year');
   
  

   if (!checkdate(beginday,beginmonth,beginyear))
     {
       alert ("Date d'arrivée erronée");
       return false;
     }

   if (!checkdate(endday,endmonth,endyear))
     {
       alert ("Date de départ erronée");
       return false;
     }


   if (!Date2_sup_Date1 (FirstAvailDay.getDate(),FirstAvailDay.getMonth()+1,GetTheYear(FirstAvailDay),beginday ,beginmonth ,beginyear ))
     {
       alert ("Cet établissement est indisponible pour les dates demandées");
       return false;
     }

   if (!Date2_sup_Date1 (endday, endmonth ,endyear,LastAvailDay.getDate(),LastAvailDay.getMonth()+1,GetTheYear(LastAvailDay)))
     {
       alert ("Cet établissement est indisponible pour les dates demandées");       
       return false;
     }


   if (Date2_sup_Date1 (endday, endmonth ,endyear,beginday,beginmonth,beginyear))
     {
       alert ("La date de départ doit être supérieure à celle d'arrivée.");
       return false;
     }
   
   if (document.availinfo.nbnight.value < 1)
     {
       alert ("Vous devez réservez au minimum pour 1 nuit(s)");
       return false;
     }

  return true;
}

function confirmAnnul()
{
  window.name = "availinfo";
  answer = window.confirm("Voulez-vous vraiment annuler la réservation ?");
  
  return answer;

  
}

function confirmRestart()
{
  window.name = "availinfo";
  answer = window.confirm("Etes-vous sur de vouloir recommencer la réservation en cours ?");
  
  return answer; 
}

function startdesc(action, userid)
{  
  windowOptions  = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=yes,scrollbars=yes,width=600,height=500";
  url = 'description.php?action=' + action + '&userid=' + userid;
  openNewWindow(url,'description',windowOptions);
  //window.open(url,'',windowOptions);
}


function Vide()
{
  for (j = 0; j < document.availinfo.length; j++)
    {
      switch (document.availinfo.elements[j].type)
	{
	case 'radio':
	    document.availinfo.elements[j].checked = false;
	    break;
	case 'text':
	    document.availinfo.elements[j].value = '';
	    break;
	case 'select-one':
	    document.availinfo.elements[j].value = '-1';
	    break;
	case 'checkbox':
	    document.availinfo.elements[j].checked = false;
	    break;
	}
    }

}


function UpdateSelectDateByCalendar(fieldname, pattern)
 {
   Today = new Date();       
   currentYear = y2k(Today.getYear());
   
   year = ExtractDate(fieldname,'year');
   month = ExtractDate(fieldname,'month');
   day = ExtractDate(fieldname,'day');
   
   document.availinfo.elements[fieldnameday].selectedIndex = day-1;
   document.availinfo.elements[fieldnamemonth].selectedIndex = month-1;
   document.availinfo.elements[fieldnameyear].selectedIndex = year-currentYear;
   document.availinfo.elements[pattern].value = document.availinfo.elements[fieldname].value;
   document.availinfo.nbnight.value=1; 

   if (pattern)
   updateEndDate(document.availinfo.elements[pattern+'day'].options[document.availinfo.elements[pattern+'day'].selectedIndex].value,
		 document.availinfo.elements[pattern+'month'].options[document.availinfo.elements[pattern+'month'].selectedIndex].value,
		 document.availinfo.elements[pattern+'year'].options[document.availinfo.elements[pattern+'year'].selectedIndex].value,
		 document.availinfo.nbnight.value) ;
   updateNbNight( document.availinfo.elements['enddateday'].options[document.availinfo.elements['enddateday'].selectedIndex].value,
		  document.availinfo.elements['enddatemonth'].options[document.availinfo.elements['enddatemonth'].selectedIndex].value,
		  document.availinfo.elements['enddateyear'].options[document.availinfo.elements['enddateyear'].selectedIndex].value,
		  document.availinfo.elements[pattern+'day'].options[document.availinfo.elements[pattern+'day'].selectedIndex].value,
		  document.availinfo.elements[pattern+'month'].options[document.availinfo.elements[pattern+'month'].selectedIndex].value,
		  document.availinfo.elements[pattern+'year'].options[document.availinfo.elements[pattern+'year'].selectedIndex].value);
 }
function UpdateSelectBeginDate(fid, item, fieldname)
    {
      Today = new Date();       
      currentYear = y2k(Today.getYear());

            year = ExtractDate(fieldname,'year');
      month = ExtractDate(fieldname,'month');
      day = ExtractDate(fieldname,'day');
            
      if (item == "begindate")
	{
	  document.availinfo.begindateday.selectedIndex = day-1;
	  document.availinfo.begindatemonth.selectedIndex = month-1;
	  document.availinfo.begindateyear.selectedIndex = year-currentYear;


	  document.availinfo.nbnight.value=1; 
	  updateEndDate(document.availinfo.elements['begindateday'].options[document.availinfo.elements['begindateday'].selectedIndex].value,
			document.availinfo.elements['begindatemonth'].options[document.availinfo.elements['begindatemonth'].selectedIndex].value,
			document.availinfo.elements['begindateyear'].options[document.availinfo.elements['begindateyear'].selectedIndex].value,
			document.availinfo.nbnight.value) ;
	  updateNbNight( document.availinfo.elements['enddateday'].options[document.availinfo.elements['enddateday'].selectedIndex].value,
			 document.availinfo.elements['enddatemonth'].options[document.availinfo.elements['enddatemonth'].selectedIndex].value,
			 document.availinfo.elements['enddateyear'].options[document.availinfo.elements['enddateyear'].selectedIndex].value,
			 document.availinfo.elements['begindateday'].options[document.availinfo.elements['begindateday'].selectedIndex].value,
			 document.availinfo.elements['begindatemonth'].options[document.availinfo.elements['begindatemonth'].selectedIndex].value,
			 document.availinfo.elements['begindateyear'].options[document.availinfo.elements['begindateyear'].selectedIndex].value)
	    
	}
      else
	{
	  document.availinfo.enddateday.selectedIndex = day-1;
	  document.availinfo.enddatemonth.selectedIndex = month-1;
	  document.availinfo.enddateyear.selectedIndex = year-currentYear;

	  updateNbNight( document.availinfo.elements['enddateday'].options[document.availinfo.elements['enddateday'].selectedIndex].value,
			 document.availinfo.elements['enddatemonth'].options[document.availinfo.elements['enddatemonth'].selectedIndex].value,
			 document.availinfo.elements['enddateyear'].options[document.availinfo.elements['enddateyear'].selectedIndex].value,
			 document.availinfo.elements['begindateday'].options[document.availinfo.elements['begindateday'].selectedIndex].value,
			 document.availinfo.elements['begindatemonth'].options[document.availinfo.elements['begindatemonth'].selectedIndex].value,
			 document.availinfo.elements['begindateyear'].options[document.availinfo.elements['begindateyear'].selectedIndex].value);
	    }
    }

function DisplayNbChilds(divname, fieldname, nbchilds, maxage)
  {
    DisplayAgeForChilds(divname, fieldname, nbchilds, maxage, 5);
  }

 function DisplayAgeForChilds(divname, fieldname, nbchilds, maxage, nbagebyline)
  {
    var strHTML = "";

    if (maxage>12 || maxage=="" || maxage==0) maxage = 12;

    if (nbchilds == 0) 
      {
	ShowCalc(divname,'none');
      }
    else
      {
	ShowCalc(divname,'block');
	for (idx=1; idx<=nbchilds; idx++)
	  {
	    strHTML += "<span><em>Enfant "+idx+" : </em>\n";
	    strHTML += "   <select name='ages"+idx+"'>\n";
	    strHTML += "     <option value='-1'>----</option>\n";
	    strHTML += "     <option value='1'> &lt; 1 </option>\n";
	    for (idxAge=1; idxAge<=maxage; idxAge++)
	      {
		strHTML += "     <option value='"+idxAge+"'>"+idxAge+"</option>\n";
	      }
	    strHTML += "   </select>\n ";
	    strHTML += "</span>\n";
	    if (idx%nbagebyline==0) strHTML += "<br>\n";
	  }		
	
	
	if (document.getElementById)
	  {
	    myelem = document.getElementById(fieldname);
	    if (myelem != null) myelem.innerHTML = strHTML;
	    //document.getElementById(fieldname).innerHTML = strHTML;
	  }
	else if (document.all)
	  {
	    document.all[fieldname].innerHTML = strHTML;
	  }
      }
  }
 
  function ChangeNbRooms(nbrooms)
   {
     ShowCalc("explainmultiroom", "none");
     if (nbrooms > 1)
       {
	 ShowCalc("explainmultiroom", "block");
       }
   } 
