//Javascript for Booking Component//


function submitFunction()
{
  var theMonth= document.getElementById('MM1')[document.getElementById('MM1').selectedIndex].value;
  var theDay= document.getElementById('DD1')[document.getElementById('DD1').selectedIndex].value;
  var theYear= document.form1.YY1[document.form1.YY1.selectedIndex].text;
  var nights= document.form1.Length[document.form1.Length.selectedIndex].text;
  var rooms= document.form1.Rooms[document.form1.Rooms.selectedIndex].text;
  var hotelSelect = document.form1.HotelID;
  var DateIn = theMonth +"%2F"+ theDay + "%2F" +theYear;
  var hotelID = document.form1.HotelID.value;

	document.form1.action = "https://booking.ihotelier.com/istay/istay.jsp?DD1="+theDay+"&MM1="+theMonth+"&YY1="+theYear+"&DateIn="+DateIn+"&Length="+nights+"&Adults=2&Children=0&Rooms="+rooms+"&HotelID="+hotelID+"&LanguageID=1";						
	document.form1.method="post";
}

function updateStart(cal)
{
    var date = document.getElementById("DateIn");
    var arr = date.value.split("/");
    var selectedYear = "";
    
    document.getElementById('MM1').selectedIndex = arr[0]-1;
    document.getElementById('DD1').selectedIndex = arr[1]-1;
  
    for(i=0; i<2; i++){
    if(document.getElementById('YY1').options[i].text == arr[2]){
           
          document.getElementById('YY1').selectedIndex = i;
      }
   }
}

function assembleDate() {
         var theMonth= document.getElementById('MM1')[document.getElementById('MM1').selectedIndex].value;
         var theDay= document.getElementById('DD1')[document.getElementById('DD1').selectedIndex].value;
         var theYear= document.form1.YY1[document.form1.YY1.selectedIndex].text;

         document.getElementById('DateIn').value = theMonth + "/" + theDay + "/" + theYear;

}

   /* function openCalendar(FormElement) {
        var calendarwindow;
        url = "calendar_1.html?formname=form1&formelement=" + FormElement; 
        calendarwindow = window.open(url)//,"thewindow","toolbar=no,LEFT=300,TOP=250,WIDTH=170, HEIGHT=140,status=no,scrollbars=no,resize=no,menubar=no");
        calendarwindow.focus();
}*/


//set todays date

Now = new Date();

NowDay = Now.getDate();

NowMonth = Now.getMonth();

NowYear = Now.getYear();

if (NowYear < 2000) NowYear += 1900; //for Netscape



// set tomorrows date

var tomorrow = new Date(Now.getTime() + (1 * 86400000));

tDay = tomorrow.getDate();

tMonth = tomorrow.getMonth();

tYear = tomorrow.getYear();

if (tYear < 2000) tYear += 1900; //for Netscape



//function for returning how many days there are in a month including leap years

function DaysInMonth(WhichMonth, WhichYear)

{

var DaysInMonth = 31;

if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;

if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))DaysInMonth = 28;

if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))DaysInMonth = 29;

return DaysInMonth;

}



//function to change the available days in a months

function ChangeOptionDays()

{

DaysObject = eval("document.form1.DD1");

MonthObject = eval("document.form1.MM1");

YearObject = eval("document.form1.YY1");



Month = MonthObject[MonthObject.selectedIndex].text;

Year = YearObject[YearObject.selectedIndex].text;



DaysForThisSelection = DaysInMonth(Month, Year);

CurrentDaysInSelection = DaysObject.length;

if (CurrentDaysInSelection > DaysForThisSelection)

{

for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)

{

DaysObject.options[DaysObject.options.length - 1] = null

}

}

if (DaysForThisSelection > CurrentDaysInSelection)

{

for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)

{

NewOption = new Option(DaysObject.options.length + 1);

DaysObject.options.add(NewOption);

}

}

if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;


assembleDate();
}



//function to set options to tomorrow

function SetToToday()

{

DaysObject = eval("document.form1.DD1");

MonthObject = eval("document.form1.MM1");

YearObject = eval("document.form1.YY1");



YearObject[0].selected = true;

MonthObject[tMonth].selected = true;

ChangeOptionDays();

DaysObject[tDay-1].selected = true;

assembleDate();
}



//function to write option years plus x

function WriteYearOptions(YearsAhead)

{

line = "";

for (i=0; i<YearsAhead; i++)

{

line += "<OPTION>";

line += NowYear + i;

line += "</OPTION>";

}

return line;

}


/*//underline main nav folder links
window.onload = function() {
var findFolder = document.getElementById("primarynavwrapper").getElementsByTagName("A");
var URL = window.location.href;
alert(findFolder[0]+" "+findFolder[1]+" "+findFolder[2])
for (i=0; i<findFolder.length; i++) {
var pageURL = findFolder[i].toString();
alert("?")
	if(URL.indexOf(pageURL)!= -1){
	alert("!")
		findFolder[i].className+=" current";
	}
}
}*/


