//alert("loading ");



function fAddListItem(strDate,caller) {



	var dl=document.calendarDisplay.dateList;

	dl.options[dl.options.length]=new Option(strDate,strDate);

	//// determine the length of items selected

	numdates = dl.options.length;

	if ( numdates >= 1 )	{

		//if (numdates >= 4) { alert("Please select one 2 dates at a time"); }

		if (numdates >= 3) { 

		//parent.right_frame.document.form1.text1.value='Me

		document.getElementById('ratedisplay').src = "" ;

		

		/// when the 3rd item is checked, clear the calendar selections

		gfFlat_1.fClearAll();

		gfFlat_1.fRepaint();

		gfFlat_2.fRepaint();

		gfFlat_2.fClearAll();

		return false;

		}

		/// use the first date found as the arrival

		var dl2=document.forms[2];

		

		//Set 1 day in milliseconds

		var one_day=1000*60*60*24



		//Calculate difference btw the two dates, and convert to days

		

		//Set the two dates

		firstday= new Date(  dl.options[0].value.split("/")[0],   dl.options[0].value.split("/")[1]-1,  dl.options[0].value.split("/")[2])

		lastday = new Date(  dl.options[numdates-1].value.split("/")[0],   dl.options[numdates-1].value.split("/")[1]-1,  dl.options[numdates-1].value.split("/")[2])

		//alert("firstday  " + firstday)

            //alert("lastday  " + lastday)

		//// determine the length of items selected

		numdates = dl.options.length;

		span = Math.ceil((lastday.getTime()-firstday.getTime())/(one_day))

		//dl2.nights.value=numdates;

		//alert("span  " + span)

		dl2.nights.value=Math.abs(span);

		// if arrival - departure dates were typed in reverse then need to adjust lowest arrival date

		if (span <= 0) {

		arryr =dl.options[numdates-1].value.split("/")[0]

		arrmo =dl.options[numdates-1].value.split("/")[1]

		arrday=dl.options[numdates-1].value.split("/")[2]

		}

		else

		{

		arryr =dl.options[0].value.split("/")[0]

		arrmo =dl.options[0].value.split("/")[1]

		arrday=dl.options[0].value.split("/")[2]

		}

		dl2.arrmonth.value =arrmo;    

		dl2.arrday.value   =arrday;

		dl2.arryear.value  =arryr;

		

		/// only submit form when we have 2 dates, arrival and departure

		if (numdates == 2) {

		//alert(" span  " + span)

		document.forms[2].submit();

		}

       	

	}

	numdates = 0;      //// reset to zero for "clear all" function



}

function fRemoveListItem(strDate,caller) {

	var dl=document.calendarDisplay.dateList;

	for (var i=0;i<dl.options.length;i++)

		if (strDate==dl.options[i].value) break;

	dl.options[i]=null;



	numdates = dl.options.length;

	if ( numdates >= 1 )	{

		if (numdates == 1 ) {

		document.getElementById('ratedisplay').src = "" ;

		}

		/// use the first date found as the arrival

		var dl2=document.forms[2];

		arryr =dl.options[0].value.split("/")[0]

		arrmo =dl.options[0].value.split("/")[1]

		arrday=dl.options[0].value.split("/")[2]

		dl2.arrmonth.value=arrmo;    

		dl2.arrday.value=arrday;

		dl2.arryear.value=arryr;

		//// determine the length of items selected

		numdates = dl.options.length;

		//alert(" number of dates " + numdates);

		dl2.nights.value=numdates;

		

	}

	numdates = 0;         //// reset to zero for "clear all" function

	

}

// The above 2 functions are called from within the plugins2.js when adding dates into the selected ranges. We use them to add dates explicitly to the <select> list.

// These 2 have to be defined in the same page with the <select> tag, otherwise a bug of IE5.0 will prevent the list from getting new options. IE5.5+ doesn't have this bug.

// param strDate has a format of yyyy/mm/dd, you may modify this format in function fDateString in the plugins2.js



function submitByDates(fm) {	// construct the selected dates in the hidden form field allSelected

	fm.allSelected.value="";

	for (var i=0; i<fm.dateList.length; i++) {

		if (i>0) fm.allSelected.value+=",";

		fm.allSelected.value+=fm.dateList.options[i].value;

		

	}

	// fm.action="ByDate.php";

	//alert(fm.allSelected.value); // in your app you should call fm.submit() instead so that the allSelected.value can be submitted.

}



function submitByRanges(fm) {	// construct the selected date ranges in the hidden form field allSelected

	fm.allSelected.value="";

	var _cxp_pds=gfFlat_1.fGetPDS();

	for (var i=0; i<_cxp_pds.length; i++) {

		var d0=new Date(_cxp_pds[i][0]);

		var d1=new Date(_cxp_pds[i][1]);

		fm.allSelected.value+="["+d0.getUTCFullYear()+"/"+(d0.getUTCMonth()+1)+"/"+d0.getUTCDate()

			+","

			+d1.getUTCFullYear()+"/"+(d1.getUTCMonth()+1)+"/"+d1.getUTCDate()+"]";

	}

	// fm.action="ByRange.php";

	//alert(fm.allSelected.value); // in your app you should call fm.submit() instead so that the allSelected.value can be submitted.

}



function fInitAgenda() {



	// the following presets the date range selected

	with (gfFlat_1) {

		//fAddRange(gToday[0],gToday[1],5,false);

		//fAddRange(gToday[0],gToday[1],10,true);

		//fAddRange(gToday[0],gToday[1],15,false);

		//fAddRange(gToday[0],gToday[1],16,false);

		fRepaint();

	}



}





function  drawCalendars(propertycode) {

document.writeln('<link href="/calendars/FRSbooking/avail.css" rel="stylesheet" type="text/css">');



document.writeln('<form name="calendarDisplay">');

document.writeln('<table border="0"><tr> ');

document.writeln('<td valign=top> ');

document.writeln('	<iframe width=174 height=172 name="gToday:normal:/calendars/FRSbooking/agendareader2.js:gfFlat_1:/calendars/FRSbooking/plugins2.js" id="gToday:normal:/calendars/FRSbooking/agendareader2.js:gfFlat_1:/calendars/FRSbooking/plugins2.js"                                 src="/calendars/FRSbooking/iflateng.htm?selectunit=' + propertycode + '" scrolling="no" frameborder="0"></iframe> ');

document.writeln('</td> ');

document.writeln('<td> ');

document.writeln('    <iframe width=174 height=172 name="[gToday[0],gToday[1]+1]:normal:agendareader2.js:gfFlat_2:plugins2.js" id="[gToday[0],gToday[1]+1]:normal:agendareader2.js:gfFlat_2:plugins2.js" src="/calendars/FRSbooking/iflateng.htm?selectunit=' + propertycode + '" scrolling="no" frameborder="0"></iframe>  	 ');

document.writeln('</td></tr> ');

document.writeln('<tr> ');

document.writeln('<td class="info"> ');

document.writeln('<ul><li>Click On ARRIVAL Date</li> ');

document.writeln('<li>Click on DEPARTURE Date</li> ');

document.writeln('<li>RATE will appear on the right</li></ul> ');

document.writeln('<div style="visibility: hidden;">  ');

document.writeln('<select name="dateList" size="0"> ');

document.writeln('<option value="-">-----------------</option> ');

document.writeln('</select> ');

document.writeln('</div>   ');

document.writeln('</td>');

document.writeln('</form> ');

document.writeln('<td align=center class="info2" valign="top">&nbsp; Rate: ');

document.writeln('<iframe width=111 height=32  name="ratedisplay" class="rate"                            id="ratedisplay"       vspace="0" hspace="0" marginheight="0"  align="center"                    scrolling="no" frameborder="0"></iframe> ');

document.writeln('<div class="info">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Includes all taxes and fees.</div> ');

document.writeln('</td></tr></table>');

document.writeln(' <script defer> ');

document.writeln(' document.calendarDisplay.dateList.options[0]=null; // remove the "-------" line. this is a trick to expand the listbox width in NN4.  ');

document.writeln(' </script> ');



//// this form gets dates plugged into it

document.writeln('<form name="calendarSelections">    ');

document.writeln('<input  type="hidden" name="allSelected">  ');

document.writeln('</form> ');



//// this form gets dates that are submitted for rates

document.writeln('<form  name="calendarSelections2" method="GET" action="http://24.182.63.154:9004" target="ratedisplay">  ');

document.writeln('<input name="type"       type="hidden" value="RSAVAILSINGLE">  ');

document.writeln('<input name="arrmonth"   type="hidden"  value="">  ');

document.writeln('<input name="arrday"     type="hidden" value="">  ');

document.writeln('<input name="arryear"    type="hidden" value="">  ');

document.writeln('<input name="nights"     type="hidden" value="">  ');

document.writeln('<input name="unitlimit"     type="hidden" value="1">  ');

document.writeln('<input name="selectunit" type="hidden" value="' + propertycode + '">  ');

document.writeln('</form>  ');







}











