//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;
		
 	if(hotelID == "DND8911"){
		document.form1.action="http://www.key-res.com/reserve.php?hid="+ hotelID +"&fymd="+theYear+theMonth+theDay+"&numnights="+ nights +"&numrooms=" + rooms + "&adults=2&children=0&lang=en";
	}
	else if(hotelID == "all"){
		
		document.form1.action="http://reservations.ihotelier.com/areasearch/default.cfm?PortalSymbol=SWH";
	}
	else{
		document.form1.action = "https://reservations.ihotelier.com/istay.cfm?DD1="+theDay+"&MM1="+theMonth+"&YY1="+theYear+"&DateIn="+DateIn+"&Length="+nights+"&Adults=2&Children=0&Rooms="+rooms+"&HotelID="+hotelID+"&LanguageID=1";
	}
}

function submitFunction2()
{
  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 = hotelSelect.options[hotelSelect.selectedIndex].value;
  	if(hotelID == "DND8911"){
		document.form1.action="http://www.key-res.com/reserve.php?hid="+ hotelID +"&fymd="+theYear+theMonth+theDay+"&numnights="+ nights +"&numrooms=" + rooms + "&adults=2&children=0&lang=en"; 
	}
	else if(hotelID == "all"){
	
		document.form1.action="http://reservations.ihotelier.com/areasearch/default.cfm?PortalSymbol=SWH";
	}
	else{
		document.form1.action = "https://reservations.ihotelier.com/istay.cfm?DD1="+theDay+"&MM1="+theMonth+"&YY1="+theYear+"&DateIn="+DateIn+"&Length="+nights+"&Adults=2&Children=0&Rooms="+rooms+"&HotelID="+hotelID+"&LanguageID=1";
	}
}

function submitFunctionGlobe()
{
  var theMonth= document.getElementById('MM1')[document.getElementById('MM1').selectedIndex].value;
  var theDay= document.getElementById('DD1')[document.getElementById('DD1').selectedIndex].value;
  var theYear= document.form1.fy[document.form1.fy.selectedIndex].text;
  var nights= document.form1.numnights[document.form1.numnights.selectedIndex].text;
  var adults = document.form1.adults[document.form1.adults.selectedIndex].text;
  var hotelSelect = document.form1.HotelID;
  var hotelID = hotelSelect.options[hotelSelect.selectedIndex].value;
  if(hotelID == "All Properties"){
	
		document.form1.action="http://www.globekey.com/reserve.php?mstcode=All+Properties&fd="+ theDay+"&fm="+ theMonth +"&fy="+ theYear +"&numnights="+ nights+"&adults="+ adults +"&settings1=daysinAdvance%3D1%3BnumberNights%3D2%3BnumberYears%3D4%3BnumberNightsMin%3D1%3B&settings2=wdDisplay%3D1%3BnumberNightsDisplay%3D1%3BdepartDateDisplay%3D0%3B&country=United+Kingdom&displaypref=RCA&showhead=yes&grp_code=swallow&limit=10&lang=en&search=Search+Now";
	}
	else{
		document.form1.action="http://www.globekey.com/reserve.php?mstcode="+ hotelID +"&fd="+ theDay+"&fm="+ theMonth +"&fy="+ theYear +"&numnights="+ nights+"&adults="+ adults +"&settings1=daysinAdvance%3D1%3BnumberNights%3D2%3BnumberYears%3D4%3BnumberNightsMin%3D1%3B&settings2=wdDisplay%3D1%3BnumberNightsDisplay%3D1%3BdepartDateDisplay%3D0%3B&country=United+Kingdom&displaypref=RCA&showhead=yes&grp_code=swallow&limit=10&lang=en&search=Search+Now";
	}
}

function submitFunctionGlobe2()
{
  var theMonth= document.getElementById('MM1')[document.getElementById('MM1').selectedIndex].value;
  var theDay= document.getElementById('DD1')[document.getElementById('DD1').selectedIndex].value;
  var theYear= document.form1.fy[document.form1.fy.selectedIndex].text;
  var nights= document.form1.numnights[document.form1.numnights.selectedIndex].text;
  var adults = document.form1.adults[document.form1.adults.selectedIndex].text;
  var hotelID = document.form1.HotelID.value;
 
		document.form1.action="http://www.globekey.com/reserve.php?mstcode="+ hotelID +"&fd="+ theDay+"&fm="+ theMonth +"&fy="+ theYear +"&numnights="+ nights+"&adults="+ adults +"&settings1=daysinAdvance%3D1%3BnumberNights%3D2%3BnumberYears%3D4%3BnumberNightsMin%3D1%3B&settings2=wdDisplay%3D1%3BnumberNightsDisplay%3D1%3BdepartDateDisplay%3D0%3B&country=United+Kingdom&displaypref=RCA&showhead=yes&grp_code=swallow&limit=10&lang=en&search=Search+Now";

}


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;

}






