// JavaScript Document
function initResLauncher(){

	// 
	domain = "https://reservations.SynXis.com"
	chainId = "6312";
	//frm = document.getElementById('resLauncher')
	frm = document.resLauncher;
	// ********************************
	
	//

	//
	var mnths = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
	
	currDt   = new Date();
	currMnth = currDt.getMonth();
	currYear = currDt.getFullYear();
	currDay  = currDt.getDate();
	
	var mt,yr,dy,mnthYr,len;
	
	// Iterate
	for (var mnthIdx=currMnth;mnthIdx<=currMnth+12;mnthIdx++) {
		yr = currYear;
		mt = mnthIdx;
		if (mt>11) {
			mt -= 12;
			yr += 1;
		}
		len  = frm.arrMnthYr.options.length;
		sel  = (yr==currYear && mt==currMnth) ? true : false;
		tmpDay = (yr==currYear && mt==currMnth) ? currDay : 1;
		tmpDt = new Date(yr,mt,tmpDay);
		
		// Create <option>
		frm.arrMnthYr.options[len] = new Option(mnths[mt] + " " + yr,tmpDt,sel,sel);
	}
	
	// Call Other Methods
	setDays(currDt);
	setDates();
}

// 
// Build the days of the CURRENT month (in the corresponding year)
// dt is sent as a JavaScript new Date() object
//
function setDays(dt) {
	var days,yr,mt,day,tm,len,sel,tmpDt;
	yr = dt.getFullYear();
	mt = dt.getMonth();
	day = (mt==currMnth && yr==currYear) ? dt.getDate() : 1;

	var tmpMt = mt+1;
	var tmpYr = yr;
	if (tmpMt>11) {
		var tmpMt = mt-11;
		var tmpYr = yr+1;
	}
	tmpDt = new Date(tmpYr,tmpMt);
	tm = tmpDt.getTime();
	tmpDt.setTime(tm-86400000);
	dayCnt = tmpDt.getDate();

	//
	// Begin creation of date <select>
	//
	
	// Remove all <select> data
	frm.arrDay.options.length = 0;
	// Iterate
	for (var i=day;i<=dayCnt;i++) {
		len   = frm.arrDay.options.length;
		tmpDt = new Date(yr,mt,i);
		sel   = (tmpDt == currDt) ? true : false;
		
		// Create <option>
		frm.arrDay.options[len] = new Option(i,tmpDt,sel,sel);
	}
}

function setDates(updateDays) {
	
	// When Changing Months we need to reset the
	// days to allow for for selection of any day
	if (updateDays) setDays(new Date(frm.arrMnthYr.options[frm.arrMnthYr.selectedIndex].value));
	
}

//
// Submit!
//
function launchBE() {
	//
	// Retrieve form variables
	//
	
	// Nights
	var nights = frm.nights.options[frm.nights.selectedIndex].value;
	// Month/Year
	var mnthYr   = new Date(frm.arrMnthYr.options[frm.arrMnthYr.selectedIndex].value);
	var thisMnth = mnthYr.getMonth();
	var thisYear = mnthYr.getFullYear();
	// Day
	var dt		= new Date(frm.arrDay.options[frm.arrDay.selectedIndex].value);
	var thisDay = dt.getDate();
	
	//
	// Create Arrival Date & Calculate Departure Date values
	//
	
	// Arrival Date
	arrivalDt = (thisMnth+1)+"/"+thisDay+"/"+thisYear;
	// Calculate
	tmpDt = new Date(thisYear,thisMnth,thisDay);
	tm    = tmpDt.getTime();
	tmpDt.setTime(tm+(86400000*nights));
	//Departure Date
	departureDt = (tmpDt.getMonth()+1)+"/"+tmpDt.getDate()+"/"+tmpDt.getFullYear();
	
	//
	// Create the URL String
	//
	//var features = frm.hsi.checked ? "width=790,height=590,scrollbars=yes,resizable" : "width=900,height=590,scrollbars=yes,resizable=no";
	var url = domain;
	url += frm.hsi.checked ? "/opbe/rez.aspx" : "/lbe/rez.aspx";
	url += "?Chain="+chainId;
	var hotelId,arrDt,depDt,adult,child,promo,iata;
	hotelId = frm.hotelId.value;
	arrDt = arrivalDt;
	depDt = departureDt;
	adult = frm.adult.value;
	child = frm.child.value;
	promo = frm.promo.value;
	iata = frm.iata.value;	
	url 
	+= "&Hotel="+hotelId	  
		+"&Arrive="+arrDt
		+"&Depart="+depDt
		+"&Adult="+adult
		+"&Child="+child
		+"&Promo="+promo
		+"&Iata="+iata
		//+"&pResvFlag=1"
		//+"&pHotelShell=1"
		+"&Src=ip"
        +"&Step=2";
		
	if (hotelId != '')
		if (frm.hsi.checked == true)
		location.href=(url);
		else
		location.href=(url);
}



