/*

***************************************************************

* opodo.co.uk - Calendar_v4.js - English version - 04/07/2002 * 

***************************************************************

*/





/*

--------------------------------------------------

Calendar functions

Those functions are used to do the popup calendar

--------------------------------------------------

*/





function getDayOfWeekLabel(day) 

{

switch (day) {case 1 :return "Mon";break;case 2 :return "Tue";break;case 3 :return "Wed";break;case 4 :return "Thu";break;case 5 :return "Fri";break;case 6 :return "Sat";break;case 7 :return "Sun";break;}

}



function getMonthLabel(month) 

{

switch (month) {case 1 :return "January";break;case 2 :return "February";break;case 3 :return "March";break;case 4 :return "April";break;case 5 :return "May";break;case 6 :return "June";break;case 7 :return "July";break;case 8 :return "August";break;case 9 :return "September";break;case 10 :return "October";break;case 11 :return "November";break;case 12 :return "December";break;}

}





function initStrCal () 

{

txtCalendar = "calendar";



if (dayFld == "CD")

    txtSelectDate = "Select date of arrival at ILecci Villas";

else

    txtSelectDate = "Select a date to leave ILecci Villas";



txtClose = "close";

txtNext = "Next";

txtPrevious = "Previous";

isSecure = 0;



monthName = new Array(12);

monthName[1]  = getMonthLabel(1);

monthName[2]  = getMonthLabel(2);

monthName[3]  = getMonthLabel(3);

monthName[4]  = getMonthLabel(4);

monthName[5]  = getMonthLabel(5);

monthName[6]  = getMonthLabel(6);

monthName[7]  = getMonthLabel(7);

monthName[8]  = getMonthLabel(8);

monthName[9]  = getMonthLabel(9);

monthName[10] = getMonthLabel(10);

monthName[11] = getMonthLabel(11);

monthName[12] = getMonthLabel(12);



dayName = new Array(7);

dayName[1] = getDayOfWeekLabel(7);

dayName[2] = getDayOfWeekLabel(1);

dayName[3] = getDayOfWeekLabel(2);

dayName[4] = getDayOfWeekLabel(3);

dayName[5] = getDayOfWeekLabel(4);

dayName[6] = getDayOfWeekLabel(5);

dayName[7] = getDayOfWeekLabel(6);

}







// Calendar global declarations and initialization

function init (monthAhead) 

{

initStrCal();



today 			= new Date();

currDay         = today.getDate();

currMonth       = today.getMonth();

currYear	    = today.getYear();

if (currYear < 1000) currYear += 1900;



today			= new Date(currYear, currMonth, currDay);

nextYear	    = new Date(currYear, currMonth, currDay);

nextYear.setDate (nextYear.getDate() + 365);



// Get the date that is selected on the pull down menus if any.

var d;

var m;

var y;



eval("d=document.forms['" + formName + "']." + dayFld  + ".selectedIndex");

eval("m=document.forms['" + formName + "']." + monthFld  + ".selectedIndex");

eval("y=document.forms['" + formName + "']." + yearFld  + ".selectedIndex");



if (d == 0 && m == 0 && y == 0) 

	displayMonth = currMonth;

else 

	{

    if (d == 0) d = 1;		// set defaults

    if (m == 0) m = 1;

    if (y == 0) y = currYear;

    else y = currYear + y - 1;	// translate year index */

	if (monthAhead) m+=monthAhead;

	

    var tempDate = new Date (y, m - 1, d);

    if (tempDate.getTime() < today.getTime()) 

		tempDate.setDate(today.getDate());

    else if (tempDate.getTime() >= nextYear.getTime()) 

		tempDate.setDate(nextYear.getDate() - 1);



    displayMonth = tempDate.getMonth();



    var displayYear = tempDate.getYear();

    if (displayYear < 1000) displayYear += 1900;



    tempDate = new Date(displayYear, displayMonth + 1, 1);

    if (tempDate.getTime() >= nextYear.getTime()) displayMonth -= 1;

    if (displayYear > currYear) displayMonth += 12;

    }

}





function openCalendarWin() 

{

var windowOptions  = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=yes,width=525,height=310";

calendarWindow = this.open("","calendarWindow",windowOptions);

calendarWindow.callingForm = this;    

calendarWinOpen = true;

}







function closeCalendarWindow() 

{

if (calendarWinOpen) 

	{

    calendarWinOpen = false;

    calendarWindow.close();

    }

}







// Calendar main entry point

function popUpCalendar (dayFldName, monthFldName, yearFldName, formFldName, monthAhead) 

{

dayFld  = dayFldName;

monthFld = monthFldName;

yearFld = yearFldName;

formName  = formFldName;

init(monthAhead);

openCalendarWin();

redrawCalendar();

}







// repaint the calendar

function redrawCalendar() 

{

calendarWindow.callingForm = this;

calendarWindow.document.open();

var firstOfMonth = new Date(currYear, displayMonth, 1);

drawCalendar(firstOfMonth);

calendarWindow.document.write(htmlBuffer);

calendarWindow.document.close();

calendarWindow.callingForm = this;

calendarWindow.focus();

}









// fill the calling forms date and month

function fillDate(returnDay, returnMonth, returnYear) 

{

var d = returnDay - 1;

var m = returnMonth - 1;

var y = returnYear - 1;

eval("document.Fsearch." + yearFld + ".selectedIndex=" + y);

eval("document.Fsearch." + monthFld + ".selectedIndex=" + m);

eval("computeDays(document.Fsearch." + monthFld  + ", document.Fsearch." + dayFld + ", document.Fsearch." + yearFld + ")");

eval("document.Fsearch." + dayFld  + ".selectedIndex=" + d);

closeCalendarWindow();



if (dayFld == "CD")

	changeCheckIn_day();

else

	changeCheckOut_day();

}







// set the month

function changeMonth (increment) 

{

var nextMonth = displayMonth;



if (increment == 1) nextMonth++ ;

else nextMonth-- ;



if ((nextMonth - currMonth >= 13) || (nextMonth < currMonth))  

    nextMonth = currMonth;



displayMonth = nextMonth;

redrawCalendar();

}









// generate the calendar document

function drawCalendar (theDate) 

{

var y = theDate.getYear();

if (y < 1000) y += 1900;

var monthNum = theDate.getMonth();

var nextDate = new Date(y, monthNum + 1, 1);



htmlBuffer  = '<html>\n';

htmlBuffer += '<head><title>' + txtCalendar + '</title></head>\n';

htmlBuffer += '<body bgcolor="#e7e7cd" marginwidth="10" marginheight="10" style="margin:10px">\n';

htmlBuffer += '<table width="100%" border="0" cellspacing="0" cellpadding="0">\n';

htmlBuffer += '<tr><td><FONT COLOR=#000000 FACE=verdana SIZE=-1><B>'+txtSelectDate+'</B></FONT></td>\n';

htmlBuffer += '<td align="right">';

   

// Get the last day of the month before the first month we drew.

var tempDate = new Date (y, monthNum, 1);

tempDate.setDate(tempDate.getDate() - 1);



if (tempDate.getTime() >= today.getTime()) 

	htmlBuffer += '<a href="javascript:callingForm.changeMonth(-1)"><img src="/calendar/cal_back.gif" width="11" height="11" alt="" border="0" align="middle" hspace="4"><FONT FACE=verdana SIZE=-2 color=#990033>'+txtPrevious+'</font></a>';

    

// Get the first day of the month after the last month we drew.

tempDate = new Date (y, monthNum + 2, 1);



if (tempDate.getTime() < nextYear.getTime()) 

    htmlBuffer += '&nbsp;&nbsp;&nbsp;<a href="javascript:callingForm.changeMonth(1)"><FONT FACE=verdana SIZE=-2 color=#990033>'+txtNext+'</font><img src="/calendar/cal_next.gif" width="11" height="11" alt="" border="0" align="middle" hspace="4"></a> ';

    

htmlBuffer += '</td></tr><tr><td colspan="2" bgcolor="#006600"><img border="0" src="http';

if (isSecure == 1) htmlBuffer += "s";

htmlBuffer += '://www.ilecci-villas.com/calendar/clear.gif"></td></tr></table><br>\n\n';



htmlBuffer += '<table border="0" width="100%"><tr>\n';



htmlBuffer += '<td width="50%" align="middle">\n';

drawOneMonth(theDate);

htmlBuffer += '</td>';



htmlBuffer += '<td width="50%" align="middle">';

drawOneMonth(nextDate);

htmlBuffer += "</td></tr>";

 

htmlBuffer += '<tr><td colspan="3" align="right" valign="bottom">&nbsp;<br><a href="javascript:callingForm.closeCalendarWindow();"><FONT FACE=verdana SIZE=-2 color=#990033>'+txtClose+'</font><img src="/calendar/cal_close.gif" width="20" height="20" alt="" border="0" align="middle" hspace="4"></a></td></tr>';

htmlBuffer += '</table>\n</body>\n</html>';

}











function drawOneMonth(theDate) 

{

var d;

var monthNum = theDate.getMonth();

var dispYear = theDate.getYear();

if (dispYear < 1000) dispYear += 1900;



htmlBuffer += '<table border="0" cellspacing="0" cellpadding="0">\n';

htmlBuffer += '<tr><td><img src="/calendar/caltl_cnr.gif" width="13" height="11" alt="" border="0"></td><td colspan="7" background="/calendar/cal_top.gif"><spacer type="block" width="1" height="1"></td><td><img src="/calendar/caltr_cnr.gif" width="11" height="11" alt="" border="0"></td></tr>\n'

htmlBuffer += '<tr><td background="/calendar/cal_left.gif"><spacer type="block" width="1" height="1"></td><td colspan="7" bgcolor="ffffff"> <p style="margin:0px 0px 5px 60px;"><FONT COLOR=#000000 FACE=verdana SIZE=-1><B>'+monthName[monthNum+1]+' '+dispYear+'</B></FONT></p>  </td><td background="/calendar/cal_right.gif"><spacer type="block" width="1" height="1"></td></tr>\n'



htmlBuffer += '<tr><td background="/calendar/cal_left.gif"><spacer type="block" width="1" height="1"></td>\n';

for (d = 1; d <= 7; d++) htmlBuffer += '<td width="30" height="20" align="left" bgcolor="ffffff"><FONT SIZE=1 FACE=verdana color=#000000><strong>'+dayName[d]+'</strong></font></td>\n';

htmlBuffer += '<td background="/calendar/cal_right.gif"><spacer type="block" width="1" height="1"></td></tr>\n';



drawBody(theDate);



htmlBuffer += '<tr><td><img src="/calendar/calbl_cnr.gif" width="13" height="12" alt="" border="0"></td><td colspan="7" background="/calendar/cal_bottom.gif"><spacer type="block" width="1" height="1"></td><td><img src="/calendar/calbr_cnr.gif" width="11" height="12" alt="" border="0"></td></tr>\n'

htmlBuffer += "</table>\n";



}





// generate the calendar body

function drawBody (theDate) 

{

var w;

var d;

var y = theDate.getYear();

if (y < 1000) y += 1900;



var myDate = new Date (y, theDate.getMonth(), 1);

var monthNum = myDate.getMonth();



firstSunday (myDate);



for (w=0; w<6; w++) 

	{

    htmlBuffer += '<tr><td background="/calendar/cal_left.gif"><spacer type="block" width="1" height="1"></td>';

    for (d=0; d<7; d++) 

		{

        htmlBuffer += '<td height="20" align="left" bgcolor="ffffff">';

	    if (myDate.getMonth() != monthNum) 

			{

	        htmlBuffer+='<FONT FACE=verdana SIZE=1 color=#000000>&nbsp;</font>';// this square on the calendar is not part of the month

	        }

        else 

			{

            var date = myDate.getDate();

	        var date_str;



    	    if (date < 10) date_str = "0" + date;

	        else date_str = "" + date;



    	    if (myDate.getTime() >= today.getTime() && myDate.getTime() < nextYear.getTime())

		        {

            	y = (myDate.getYear() - today.getYear()) + 1;

            	var m = myDate.getMonth() + 1;

                htmlBuffer += '&nbsp;<a href="javascript:callingForm.fillDate('+date+','+m+','+y+')"><FONT FACE=verdana SIZE=1 color=#990033>'+date_str+'</font></a>';

                }

    	    else 

				{

            	htmlBuffer += '<FONT FACE=verdana SIZE=1 color=#000000 bgcolor="ffffff">&nbsp;'+date_str+'</font>';

        		}

	        }

		htmlBuffer   += "</td>\n";

        myDate.setDate(myDate.getDate() + 1);

        }

	htmlBuffer += '<td background="/calendar/cal_right.gif"><spacer type="block" width="1" height="1"></td></tr>\n';

	}

}





function firstSunday (fromDate) 

{

while (fromDate.getDay() != 0) 

    fromDate.setDate(fromDate.getDate() - 1);

}





function thisWindowOnFocus() 

{

closeCalendarWindow();

}



/*

------------------------- 

end of calendar functions

-------------------------

*/


















/*

-----------------------------

General date functions

They are used in the dropdowns (check-in and check-out dates)

-----------------------------

*/



// Adds some days, months or years to a given date

// returns the new date

function dateAdd(startDate, numDays, numMonths, numYears)

{

	var returnDate = new Date();

	returnDate.setTime(startDate.getTime());

	var yearsToAdd = numYears;

	var month = returnDate.getMonth()	+ numMonths;

	if (month > 11)

		{

		yearsToAdd = Math.floor((month+1)/12);

		month -= 12*yearsToAdd;

		yearsToAdd += numYears;

		}

	returnDate.setMonth(month);

	returnDate.setFullYear(returnDate.getFullYear()	+ yearsToAdd);

	returnDate.setTime(returnDate.getTime()+60000*60*24*numDays);

	return returnDate;

}



// Returns a date in US format (mm/dd/yyyy)

function formatDate(date)

{

	day=date.getDate();

	day=((day<10)?"0":"")+day;

	month=date.getMonth()+1;

	month=((month<10)?"0":"")+month;

	yy=date.getYear();

	year = (yy < 1000) ? yy + 1900 : yy;

	str=month+"/"+day+"/"+year;

	return str;

}



// Changes the number of days visible in the dropdown, according to the selected month

function computeDays(sSelectMonth, sSelectDay, sSelectYear)

{

	var nMonthValue = sSelectMonth.options[sSelectMonth.selectedIndex].value;

	var sYear = sSelectYear.options[sSelectYear.selectedIndex].value;

	var nDays = 31;

	switch (nMonthValue)

		{

	    case "4":

	    case "6":

	    case "9":

	    case "11":

	    	nDays = 30;

			if (sSelectDay.selectedIndex==30) sSelectDay.selectedIndex=29;

	        sSelectDay.options[30] = null;

	        sSelectDay.options[30] = null;  

	        break;

		case "2":

	        nDays = (sYear%4 == 0 ? 29: 28);

			if (sSelectDay.selectedIndex>=nDays) sSelectDay.selectedIndex=nDays-1;

			for (var less = 30; less >= nDays; less --)

				{

	            sSelectDay.options[less] = null;

	            sSelectDay.options[less] = null;  	

				}

		    break;

	    }	

	nbVisibleDays=sSelectDay.options.length;

	for ( var count =0; count <nbVisibleDays; count ++)

		{

	    sSelectDay.options[count].value = count + 1;

	    sSelectDay.options[count].text = count + 1;  

	    }

	var index=sSelectDay.selectedIndex;

	for ( var count =nbVisibleDays; count <nDays; count ++)

		{

		newDay = new Option(count+1,count+1);

	    sSelectDay.options[count]=newDay;

	    }

	sSelectDay.selectedIndex=index;

}



// Returns true if date1 is strictly before date2

function isEarlier(date1, date2)

{

	if (date1.getTime()<date2.getTime() && !(date1.getDate()==date2.getDate() && date1.getMonth()==date2.getMonth() && date1.getYear()==date2.getYear())) 

		return true;

	else return false;

}



// this function is called when changing the number of nights or the check in date

// it will calculate the new check-out date

function updateCheckOut()

{

	var nights=parseInt(document.Fsearch.numofnights.selectedIndex)+1;

	var date_in=new Date(parseInt(document.Fsearch.CY.selectedIndex)+baseYear,parseInt(document.Fsearch.CM.selectedIndex),parseInt(document.Fsearch.CD.selectedIndex)+1 );

	var date_out=dateAdd(date_in, nights,0,0);

	document.Fsearch.month_out.selectedIndex = date_out.getMonth();

	var yy=date_out.getYear();

	var year = (yy < 1000) ? yy + 1900 : yy;

	document.Fsearch.year_out.selectedIndex = year-baseYear;

	computeDays(document.Fsearch.month_out, document.Fsearch.day_out, document.Fsearch.year_out);

	document.Fsearch.day_out.selectedIndex = date_out.getDate()-1;

}







// Changes the check-in displayed date

function updateCheckIn(date)

{

	var day_in  = date.getDate();

	var month_in = date.getMonth();

	var yy = date.getYear();

	var year_in = (yy < 1000) ? yy + 1900 : yy;

	document.Fsearch.CM.selectedIndex=month_in;

	document.Fsearch.CY.selectedIndex=year_in-baseYear;

	document.Fsearch.CD.selectedIndex=day_in-1;

	computeDays(document.Fsearch.CM, document.Fsearch.CD, document.Fsearch.CY);

}









// called when the day is changed in the check-in date

function changeCheckIn_day()

{

	var date_in=new Date();

	date_in.setYear(parseInt(document.Fsearch.CY.selectedIndex)+baseYear);

	date_in.setMonth(parseInt(document.Fsearch.CM.selectedIndex));

	date_in.setDate(parseInt(document.Fsearch.CD.selectedIndex)+1);

	if (isEarlier(date_in, today))

		{

		date_in=dateAdd(date_in, 0, 1, 0);

		}

	updateCheckIn(date_in);

	//document.Fsearch.checkindate.value=formatDate(date_in);

	updateCheckOut();

}









// called when the month is changed in the check-in date

function changeCheckIn_month()

{

	computeDays(document.Fsearch.CM, document.Fsearch.CD, document.Fsearch.CY);

	var date_in=new Date();

	date_in.setYear(parseInt(document.Fsearch.CY.selectedIndex)+baseYear);

	date_in.setMonth(parseInt(document.Fsearch.CM.selectedIndex));

	date_in.setDate(parseInt(document.Fsearch.CD.selectedIndex)+1);

	if (isEarlier(date_in, today)) 

		{

		date_in=dateAdd(date_in, 0, 0, 1);

		}

	updateCheckIn(date_in);

	//document.Fsearch.checkindate.value=formatDate(date_in);

	updateCheckOut();

}











// called when the year is changed in the check-in date

function changeCheckIn_year()

{

	computeDays(document.Fsearch.CM, document.Fsearch.CD, document.Fsearch.CY);

	var date_in=new Date();

	date_in.setYear(parseInt(document.Fsearch.CY.selectedIndex)+baseYear);

	date_in.setMonth(parseInt(document.Fsearch.CM.selectedIndex));

	date_in.setDate(parseInt(document.Fsearch.CD.selectedIndex)+1);

	if (isEarlier(date_in, today)) 

		{

	    alert("The check-in date cannot be set to any date earlier than today");

		var yy=date_in.getYear();

		var year = (yy < 1000) ? yy + 1900 : yy;

		date_in.setYear(year+1);

		}

	updateCheckIn(date_in);

	//document.Fsearch.checkindate.value=formatDate(date_in);

	updateCheckOut();

}







function verifNbNights(date_in,date_out)

{

	var nMillsec  = date_out.getTime() - date_in.getTime();

	var nNights   = Math.floor(nMillsec /1000/60/60/24);

	if ( nNights > 99) 

		{

		alert("Sorry, you can't book more than 99 nights");

		document.Fsearch.numofnights.selectedIndex = 0;

		}

	else

		{

		document.Fsearch.numofnights.selectedIndex = nNights-1;

		}

	updateCheckOut();

}





// called when the day is changed in the check-out date

function changeCheckOut_day()

{

	var date_in=new Date();

	date_in.setYear(parseInt(document.Fsearch.CY.selectedIndex)+baseYear);

	date_in.setMonth(parseInt(document.Fsearch.CM.selectedIndex));

	date_in.setDate(parseInt(document.Fsearch.CD.selectedIndex)+1);

	var date_out=new Date();

	date_out.setYear(parseInt(document.Fsearch.year_out.selectedIndex)+baseYear);

	date_out.setMonth(parseInt(document.Fsearch.month_out.selectedIndex));

	date_out.setDate(parseInt(document.Fsearch.day_out.selectedIndex)+1);

	

	if (date_out<=date_in) 

		{

		date_out=dateAdd(date_out, 0, 1, 0);

		document.Fsearch.year_out.selectedIndex = date_out.getYear()-baseYear;

		document.Fsearch.month_out.selectedIndex = date_out.getMonth();

		document.Fsearch.day_out.selectedIndex = date_out.getDate()-1;

		}



	verifNbNights(date_in,date_out);

}











// called when the month is changed in the check-out date

function changeCheckOut_month()

{

	var date_in=new Date();

	date_in.setYear(parseInt(document.Fsearch.CY.selectedIndex)+baseYear);

	date_in.setMonth(parseInt(document.Fsearch.CM.selectedIndex));

	date_in.setDate(parseInt(document.Fsearch.CD.selectedIndex)+1);

	var date_out=new Date();

	date_out.setYear(parseInt(document.Fsearch.year_out.selectedIndex)+baseYear);

	date_out.setMonth(parseInt(document.Fsearch.month_out.selectedIndex));

	date_out.setDate(parseInt(document.Fsearch.day_out.selectedIndex)+1);

	

	if (date_out<=date_in) 

		{

		date_out=dateAdd(date_out, 0, 0, 1);

		var nMillsec  = date_out.getTime() - date_in.getTime();

		var nNights   = Math.floor(nMillsec /1000/60/60/24);

		if (nNights<=99)

			{

			document.Fsearch.year_out.selectedIndex = date_out.getYear()-baseYear;

			document.Fsearch.month_out.selectedIndex = date_out.getMonth();

			document.Fsearch.day_out.selectedIndex = date_out.getDate()-1;

			}

		}

	

	verifNbNights(date_in,date_out);

}











// called when the year is changed in the check-out date

function changeCheckOut_year()

{

	var date_in=new Date();

	date_in.setYear(parseInt(document.Fsearch.CY.selectedIndex)+baseYear);

	date_in.setMonth(parseInt(document.Fsearch.CM.selectedIndex));

	date_in.setDate(parseInt(document.Fsearch.CD.selectedIndex)+1);

	var date_out=new Date();

	date_out.setYear(parseInt(document.Fsearch.year_out.selectedIndex)+baseYear);

	date_out.setMonth(parseInt(document.Fsearch.month_out.selectedIndex));

	date_out.setDate(parseInt(document.Fsearch.day_out.selectedIndex)+1);

	

	if (date_out<=date_in) 

		{

		alert("You cannot set the checkout date to be earlier than the check-in date");

		updateCheckOut();

		}

	else

		{

		verifNbNights(date_in,date_out);

		}

} 











// Set the check in date for today

// Set numofnights to 1

function set_defaults() 

{

	var today=new Date();

	var yy=today.getYear();

	var baseYear=(yy < 1000) ? yy + 1900 : yy;

	

	document.Fsearch.CY[0]=new Option(baseYear,baseYear);

	document.Fsearch.CY[1]=new Option(baseYear+1,baseYear+1);

		

	document.Fsearch.year_out[0]=new Option(baseYear,baseYear);

	document.Fsearch.year_out[1]=new Option(baseYear+1,baseYear+1);

	document.Fsearch.year_out[2]=new Option(baseYear+2,baseYear+2);

	

	var nights = 1;

	var date_in=today;

    updateCheckIn(date_in);

	//document.Fsearch.checkindate.value=formatDate(date_in);

    document.Fsearch.numofnights.selectedIndex = nights-1;

    updateCheckOut();

}











/*

--------------------------------------

init stuff (will execute all the time)

--------------------------------------

*/



var today=new Date();

var yy=today.getYear();

var baseYear=(yy < 1000) ? yy + 1900 : yy;

	

var calendarWinOpen = false;

var calendarWindow = null;


