xml = false;
xsl = false;
carListXML = false;
carListXSL = false;
detail_xml = false;
detail_xsl = false;
detail_panelID = false;
errMsg = false;
objBookedCar = false;

//*****************************************************
//*** Load LOCAL XML/XSL Doc into Dom		        ***
//*****************************************************
function loadXMLDoc(fname){
	var xmlDoc;
	// code for IE
	if (window.ActiveXObject)
	  {
	  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	  {
	  xmlDoc=document.implementation.createDocument("","",null);
	  }
	xmlDoc.async=false;
	xmlDoc.load(fname);
	return(xmlDoc);
}
//*****************************************************
//*** CAR RENTAL FUNCTIONS					        ***
//*****************************************************
var getCarList_success = function(o){
	errMsg = false;
	if(o.responseText !== undefined){
		var root = o.responseText;
		var xRoot = o.responseXML;
		var successFlag = xRoot.getElementsByTagName("Message")[0].attributes.getNamedItem("Code").value;
		if(successFlag!='000'){
			var errDesc = xRoot.getElementsByTagName("Description")[0].childNodes[0].nodeValue;
			errMsg = '<div class="textPanel"><h2>' + errDesc + '</h2><p>Sorry, we are unable to find any cars that match your search criteria. Please alter your Pick-up/Drop-off points and/or times and try again.</p></div>';
		}
		try {
			xml = new ActiveXObject("Microsoft.XMLDOM");
			xml.loadXML(root);
			} catch(e) {
  		try {
			parser = new DOMParser();
			xml = parser.parseFromString(root,"text/xml");
			} catch(e) {
			alert(e.message)}
		}
		renderCarList(xml);
	}
}

var getCarDetail_success = function(o){
	if(o.responseText !== undefined){
		var root = o.responseText;
		try {
			detail_xml = new ActiveXObject("Microsoft.XMLDOM");
			detail_xml.loadXML(root);
			} catch(e) {
  		try {
			parser = new DOMParser();
			detail_xml = parser.parseFromString(root,"text/xml");
			} catch(e) {
			alert(e.message)}
		}
		renderCarDetail();
	}
}	


var failure = function(o){
	alert('Connection Error!' + o.responseText);
}
var callback = {
  success: getCarList_success,
  failure: failure,
  argument: ['foo','bar']
}
var callback_detail = {
  success: getCarDetail_success,
  failure: failure,
  argument: ['foo','bar']
}

function formatDate(theDate){
	var arrMonths = new Array('NULL','JAN','FEB','MAR','APR','MAY','JUN','JUL','AUG','SEP','OCT','NOV','DEC');
	var arrDate = theDate.split('/');
	var monthIndex = Number(arrDate[1])
	var tmpMonth = arrMonths[monthIndex];
	if(arrDate[0].length<2) arrDate[0] = '0' + arrDate[0];
	var tmpDate = arrDate[0] + '-' + tmpMonth + '-' + arrDate[2];
	return tmpDate;
}

//---***
function getCarList(){
	strUpdating = '<div class="textPanel"><img src="/system/images/ani_connecting.gif" /></div>';
	document.getElementById("carList").innerHTML=strUpdating;
	
	var sFunc				=	'getList';
	var pu_locationName 	=	document.getElementById('ctl00_mainContent_sPickupPoint').value;
	var pu_date				=	document.getElementById('ctl00_mainContent_tPickUpDate').value;
	var pu_time				=	document.getElementById('ctl00_mainContent_sPickUpTime').value;
	var do_locationName		=	document.getElementById('ctl00_mainContent_sDropoffPoint').value;
	var do_date				=	document.getElementById('ctl00_mainContent_tDropOffDate').value;
	var do_time				=	document.getElementById('ctl00_mainContent_sDropOffTime').value;
	var driverAge			=	document.getElementById('ctl00_mainContent_tDriverAge').value;
	var postData = null;
	
	var sUrl = '';
	sUrl += 'proxy_getCarList.aspx?pu_locationName=' + pu_locationName + '&pu_date=' + pu_date
	sUrl += '&pu_time=' + pu_time + '&do_locationName=' + do_locationName + '&do_date=' + do_date
	sUrl += '&do_time=' + do_time + '&driverAge=' + driverAge;
	sUrl += '&sFunc=' + sFunc;
	
	carListXSL=loadXMLDoc("/Booking/xsl/CarList.xsl");
	carListXML=YAHOO.util.Connect.asyncRequest('GET', sUrl, callback, postData);
	
	document.getElementById('ctl00_mainContent_btnContinue').style.display = '';
}

function renderCarList(xml){
	if(errMsg!=false){
		document.getElementById("carList").innerHTML = errMsg;
	} else {
		var curr = readCookie('curr');
		var rate = parseFloat(readCookie('currRate'));
		if(window.ActiveXObject){
			xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
			xslDoc.async = false;
			xslDoc.load(carListXSL);
			docCache = new ActiveXObject("MSXML2.XSLTemplate");
			docCache.stylesheet = xslDoc;
			docProcessor = docCache.createProcessor();
			docProcessor.input = xml;
			docProcessor.addParameter("curr", curr);
			docProcessor.addParameter("currRate", rate)
			docProcessor.transform();
			document.getElementById('carList').innerHTML = docProcessor.output;		
		} else {;
			docProcessor = new XSLTProcessor();
			docProcessor.importStylesheet(carListXSL);
			docProcessor.setParameter(null, "curr", curr);
			docProcessor.setParameter(null, "currRate", rate);
			docFragment = docProcessor.transformToFragment(xml,document);
			document.getElementById('carList').innerHTML = '';
			document.getElementById('carList').appendChild(docFragment);
		}
	}
}

function loadCarDetails(panelID, carCode, pickUpCode, dropOffCode, supplierCode, price){
	detail_panelID = panelID
	
	//Build querystring to pass to proxy
	var pu_locationCode 	=	pickUpCode;
	var pu_date				=	document.getElementById('ctl00_mainContent_tPickUpDate').value;
	var pu_time				=	document.getElementById('ctl00_mainContent_sPickUpTime').value;
	var do_locationCode		=	dropOffCode;
	var do_date				=	document.getElementById('ctl00_mainContent_tDropOffDate').value;
	var do_time				=	document.getElementById('ctl00_mainContent_sDropOffTime').value;
	var vehicleCode			=	carCode;
	var productCode			=	'3'; //Constant
	var postData = null;
	
	
	var sUrl = '';
	sUrl += 'proxy_getCarDetail.aspx?pu_locationCode=' + pu_locationCode + '&pu_date=' + pu_date
	sUrl += '&pu_time=' + pu_time + '&do_locationCode=' + do_locationCode + '&do_date=' + do_date
	sUrl += '&do_time=' + do_time + '&vehicleCode=' + vehicleCode + '&productCode=' + productCode + '&supplierCode=' + supplierCode;
	
	detail_xsl=loadXMLDoc("/Booking/xsl/CarDetail.xsl");
	
	//Save details to strBookedCar for use if this car is selected
	
	objBookedCar = {
		PickUpInfo: pu_locationCode,
		DropOffInfo: do_locationCode,
		SupplierCode: supplierCode,
		Price: price
		}
	
	detail_xml=YAHOO.util.Connect.asyncRequest('GET', sUrl, callback_detail, postData);
}

function renderCarDetail(){	
	var curr = readCookie('curr');
	var rate = parseFloat(readCookie('currRate'));
	// code for IE
	if (window.ActiveXObject)
	  {
	  	xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
		xslDoc.async = false;
		xslDoc.load(detail_xsl);
		docCache = new ActiveXObject("MSXML2.XSLTemplate");
		docCache.stylesheet = xslDoc;
		docProcessor = docCache.createProcessor();
		docProcessor.input = detail_xml;
		docProcessor.addParameter("curr", curr);
		docProcessor.addParameter("currRate", rate)
		docProcessor.transform();
		document.getElementById(detail_panelID).innerHTML = docProcessor.output;		
	  }
	// code for Mozilla, Firefox, Opera, etc.
	else if (document.implementation && document.implementation.createDocument)
	  {
	  xsltProcessor=new XSLTProcessor();
	  xsltProcessor.importStylesheet(detail_xsl);
	  xsltProcessor.setParameter(null, "curr", curr);
	  xsltProcessor.setParameter(null, "currRate", rate);
	  resultDocument = xsltProcessor.transformToFragment(detail_xml,document);
	  var carPanel = document.getElementById(detail_panelID);
	  //carPanel.parentNode.replaceChild(resultDocument,carPanel);
	  document.getElementById(detail_panelID).innerHTML = '';
	  document.getElementById(detail_panelID).appendChild(resultDocument);
	  //document.getElementById(detail_panelID).innerHTML = resultDocument;
	  }
}	


function toggleCarDetails(callerId, pos, carCode, pickUpCode, dropOffCode, supplierCode, price){
	var detailPanel = document.getElementById(pos);
	if(detailPanel.style.display == ''){
		loadCarDetails(pos, carCode, pickUpCode, dropOffCode, supplierCode, price);	
	}		
	if(detailPanel.style.display != 'block'){
		callerId.innerHTML = 'Hide';
		callerId.className = 'arrowUp';
		detailPanel.style.display='block';
	} else {
		callerId.innerHTML = 'Show';
		callerId.className = 'arrowDown';
		detailPanel.style.display='none';	
	}

}
var tmpCarCode

function bookCar(carCode){
	var dateStart = document.getElementById('ctl00_mainContent_tPickUpDate').value;
	dateStart += ' ' + document.getElementById('ctl00_mainContent_sPickUpTime').value;
	var dateEnd = document.getElementById('ctl00_mainContent_tDropOffDate').value;
	dateEnd += ' ' + document.getElementById('ctl00_mainContent_sDropOffTime').value;
	var totalPrice = document.getElementById(carCode + '_price').value;
	if(document.getElementById(carCode + '_cbAddWaiver')!=null)
	{
	if(document.getElementById(carCode + '_cbAddWaiver').checked) {
		var cdwCost = document.getElementById(carCode + '_cbAddWaiver').value;
		totalPrice = parseInt(cdwCost) + parseInt(totalPrice);
	}
	}

	var carDesc = document.getElementById(carCode + '_desc').value;
	var supplierCode = document.getElementById(carCode + '_supplierCode').value;
	var pickUpCode = document.getElementById(carCode + '_pickUpCode').value;
	var dropOffCode = document.getElementById(carCode + '_dropOffCode').value;
	var pickUpTime = document.getElementById('ctl00_mainContent_sPickUpTime').value;
	var dropOffTime = document.getElementById('ctl00_mainContent_sDropOffTime').value;
	document.getElementById('ctl00_mainContent_hfCarCode').value = carCode;
	document.getElementById('ctl00_mainContent_hfDateStart').value = dateStart;
	document.getElementById('ctl00_mainContent_hfDateEnd').value = dateEnd;	
	document.getElementById('ctl00_mainContent_hfTotalPrice').value = totalPrice;
	document.getElementById('ctl00_mainContent_hfCarDesc').value = carDesc;
	document.getElementById('ctl00_mainContent_hfSupplierCode').value = supplierCode;
	document.getElementById('ctl00_mainContent_hfPickUpCode').value = pickUpCode;
	document.getElementById('ctl00_mainContent_hfDropOffCode').value = dropOffCode;
	document.getElementById('ctl00_mainContent_hfPickUpTime').value = pickUpTime;
	document.getElementById('ctl00_mainContent_hfDropOffTime').value = dropOffTime;
//	alertBox.setHeader("Booking Confirmation");
	if(document.getElementById('ctl00_mainContent_carRental').value != 1){
	  	//alertBox.setBody("Your Car Hire request has been made.");		
	} 
	else {
//	  	alertBox.setBody("Your Car Hire request has been made.<br /><br />Please note that your previous request has been cancelled.");
//	  	alertBox.show();
		removeCar(tmpCarCode);
	}
	updateCarHireSessions(totalPrice,carDesc,dateStart,dateEnd);	
	//window.location = 'quotation.aspx';
	document.getElementById('ctl00_mainContent_btnContinue').value = 'Continue with Car';
	document.getElementById('ctl00_mainContent_btnNoCar').value = 'Continue with Car';
	document.getElementById('btn_'+carCode).className = 'hidden';
	document.getElementById('btn_remove_'+carCode).className='btn';
	if(document.getElementById(carCode+'_cbAddWaiver')!=null){
	document.getElementById(carCode+'_cbAddWaiver').disabled='true';
	}
	document.getElementById('ctl00_mainContent_carRental').value = 1;
	tmpCarCode = carCode;
}
function removeCar(carCode){
    var totalPrice = document.getElementById(carCode + '_price').value;
    var carDesc = document.getElementById(carCode + '_desc').value;

	document.getElementById('ctl00_mainContent_btnContinue').value = 'Continue without Car';
	document.getElementById('ctl00_mainContent_btnNoCar').value = 'Continue without Car';
	document.getElementById('ctl00_mainContent_carRental').value = 0;
	if(document.getElementById(carCode+'_cbAddWaiver')!=null)
	{
	//    	document.getElementById(carCode+'_cbAddWaiver').disabled='';
	    if(document.getElementById(carCode + '_cbAddWaiver').checked) {
		    var cdwCost = document.getElementById(carCode + '_cbAddWaiver').value;
		    totalPrice = parseInt(totalPrice) + parseInt(cdwCost);
		    document.getElementById(carCode + '_cbAddWaiver').checked = false;
	    }
	    document.getElementById(carCode+'_cbAddWaiver').disabled='';
	}
	document.getElementById('btn_'+carCode).className = 'btn';
	document.getElementById('btn_remove_'+carCode).className='hidden';
	
	removeCarHireSessions(totalPrice,carDesc);
}

function setField(theField){
	txtDate1 = document.getElementById(theField);
}

function toggleTerms(termsID)
{
    msgBoxCheckIn(document.getElementById(termsID).innerHTML);
//	if(document.getElementById(termsID).style.display != 'block'){
//		document.getElementById(termsID).style.display = 'block';	
//	} else {
//		document.getElementById(termsID).style.display = 'none';
//	}
}		

//*****************************************************
//*** FLIGHT AND ROOM DISPLAY FUNCTIONS 	        ***
//*****************************************************
arrFilterTimes = new Array();
sRouting = 0;

var flightsXSL
var flightsXML
var flightsXSL_alt
var selectedFlight = 1;

function getFlightList_success(strFlightsXML){
		var root = strFlightsXML
		var strFlightID = document.getElementById('ctl00_mainContent_hfFlightID').value;
		var price = document.getElementById('ctl00_mainContent_hfFlightPrice').value;
		try {
			flightsXML = new ActiveXObject("Microsoft.XMLDOM");
			flightsXML.loadXML(root);
			} catch(e) {
  		try {
			parser = new DOMParser();
			flightsXML = parser.parseFromString(root,"text/xml");
			} catch(e) {
			alert(e.message)}
		}
		renderFlightList();
		if(strFlightID != 1)
		{
			updateFlightPrev(strFlightID,price);
		}
}
var callback_flights = {
  success: getFlightList_success,
  failure: failure,
  argument: ['foo','bar']
  
}
function getFlightList(){
	strUpdating = '<div class="textPanel"><img src="/system/images/ani_connecting.gif" /></div>';
	document.getElementById("container_default").innerHTML=strUpdating;
	flightsXSL = loadXMLDoc("/Booking/xsl/FlightsXSL_default.xsl");
	flightsXSL_alt = loadXMLDoc("/Booking/xsl/FlightsXSL_alt.xsl");
	strFlightsXML = document.getElementById('ctl00_mainContent_hfFlights').value;//YAHOO.util.Connect.asyncRequest('GET', sUrl, callback_flights);
	getFlightList_success(strFlightsXML);
}

function clearAltFlights()
{
    document.getElementById('altFlights').className = 'hidden';
}
function clearAltRooms()
{
    document.getElementById('altRooms').className = 'hidden';
}
function clearAltHotels()
{
    document.getElementById('altHotels').className = 'hidden';
}
var carrierFilters

function renderFlightList(){
//First, isolate a single instance of each carrier
var carriers = flightsXML.getElementsByTagName('Flight');
var strCarriers = '';
var tmpCarCode
var tmpCarName
	for(i=0;i<carriers.length;i++){
		if(carriers[i].getAttribute('CarrierName')){
			tmpCarCode = carriers[i].attributes.getNamedItem('CarrierCode').value
			tmpCarName = carriers[i].attributes.getNamedItem('CarrierName').value
			if(strCarriers.indexOf(tmpCarCode) < 0){
				strCarriers += 	tmpCarName + '~';
				strCarriers +=  tmpCarCode + '#';
			}
		}
	}	
document.getElementById('container_default').innerHTML = '';
//Split them out into an array and create the filter form checkboxes
var arrCarriers = strCarriers.split('#');
var strCarrierFilters = '';
for(i=0;i<arrCarriers.length-1;i++){
	tmpArr = arrCarriers[i].split('~');
	tmpCarrierName = tmpArr[0];
	tmpCarrierCode = tmpArr[1];
	strCarrierFilters += '<input name="carrier" id="filter_' + tmpCarrierCode +'" type="checkbox" onclick="filterFlights()" value="' + tmpCarrierCode + '" checked="true" />'
	strCarrierFilters += '&nbsp;<label for="filter_' + tmpCarrierCode + '">' + tmpCarrierName + '</label><br />'
}	
//Write the form snippet to the filter form
document.getElementById('airlineFilters').innerHTML = '<p>' + strCarrierFilters + '</p>';
// code for IE
if (window.ActiveXObject){
	if(errMsg!=false){
		output = errMsg;
	} else {
	 	output = flightsXML.transformNode(flightsXSL);
		alt = flightsXML.transformNode(flightsXSL_alt);
	}
  document.getElementById("container_default").innerHTML = output;
  document.getElementById("container_alt").innerHTML = alt;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument){
	if(errMsg!=false){
		document.getElementById("container_default").innerHTML = errMsg;
	} else {
	  xsltProcessor = new XSLTProcessor();
	  xsltProcessor.importStylesheet(flightsXSL);
	  resultDocument = xsltProcessor.transformToFragment(flightsXML,document);
	  document.getElementById("container_default").innerHTML = '';
	  document.getElementById("container_default").appendChild(resultDocument);
	  xsltProcessor_alt = new XSLTProcessor();
	  xsltProcessor_alt.importStylesheet(flightsXSL_alt);
	  resultDocument_alt = xsltProcessor_alt.transformToFragment(flightsXML,document);
	  document.getElementById("container_alt").innerHTML = '';
	  document.getElementById("container_alt").appendChild(resultDocument_alt);
	} 
  }
// If booking a package, hide the alt flight button
//	if(document.getElementById('ctl00_mainContent_hfIsPackage').value == "Yes"){
//		document.getElementById('altFlightBtn').style.display = 'none';
//	}
}

function renderAltFlights(flightId){
 document.getElementById('container_alt').innerHTML = '<div class="textPanel"><p><img src="/images/ani_updating.gif" /></p></div>'
 toggleFlightsRooms('flights');
 var curr = readCookie('curr');
 var rate = parseFloat(readCookie('currRate'));
 var selectedFlightPrice = document.getElementById('ctl00_mainContent_hfFlightPrice').value;
 var xslDocURL = flightsXSL_alt;
 // try the following
 try
 {
   // instantiate and load the xml document
   xmlDoc = flightsXML;
   xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
   xslDoc.async = false;
   xslDoc.load(xslDocURL);
   docCache = new ActiveXObject("MSXML2.XSLTemplate");
   docCache.stylesheet = xslDoc;
   docProcessor = docCache.createProcessor();
   docProcessor.input = flightsXML;
   docProcessor.addParameter("flightId", flightId, "");
   docProcessor.addParameter("selectedFlightPrice", selectedFlightPrice, "");
   docProcessor.addParameter("curr", curr, "");
   docProcessor.addParameter("rate", rate, "");
   docProcessor.transform();
   // divID.innerHTML = docProcessor.output;
   document.getElementById('container_alt').innerHTML = docProcessor.output;
 }
 // catch any errors from the above code
 catch(e)
 {
   // try the following
   try
   {
     xmlDoc = flightsXML
     xslDoc = flightsXSL_alt;
     // instantiate the document processor and submit the xsl document
     docProcessor = new XSLTProcessor();
     docProcessor.importStylesheet(xslDoc);
     // add parameters to the xsl document
     docProcessor.setParameter(null, "flightId", flightId);
	 docProcessor.setParameter(null, "selectedFlightPrice",selectedFlightPrice);
	 docProcessor.setParameter(null, "curr", curr);
	 docProcessor.setParameter(null, "rate", rate);
     // clear the passed div if anything was in it
     document.getElementById('container_alt').innerHTML = "";
     // process the documents into html and submit to the passed div
     docFragment = docProcessor.transformToFragment(xmlDoc, document);
     document.getElementById('container_alt').appendChild(docFragment);
   }
   // catch any errors from the above code
   catch(e)
   {
     alert("Mozilla Error: " + e.description);
	 alert(docRequest.status);
   }
 }
 document.location="#flights";
}

function filterFlights(){
	var filterEls	= document.getElementsByTagName("input")
	var sCarriers	= '';
	var sTimeOut_1_lb	= false;
	var sTimeOut_1_ub	= false;
	var sTimeOut_2_lb	= false;
	var sTimeOut_2_ub	= false;
	var sTimeOut_3_lb	= false;
	var sTimeOut_3_ub	= false;
	var sTimeOut_4_lb	= false;	
	var sTimeOut_4_ub	= false;

	var sTimeRet_1_lb	= false;
	var sTimeRet_1_ub	= false;
	var sTimeRet_2_lb	= false;
	var sTimeRet_2_ub	= false;
	var sTimeRet_3_lb	= false;
	var sTimeRet_3_ub	= false;
	var sTimeRet_4_lb	= false;	
	var sTimeRet_4_ub	= false;
	
	for(var i = 0; i < filterEls.length; i++){
		//---Carriers
		if(filterEls[i].name == 'carrier'){
			if(!filterEls[i].checked){
				sCarriers += (filterEls[i].value + '/');	
			}
		}
		//---Routing
		if(filterEls[i].name == 'routing'){
			if(filterEls[i].checked){
				sRouting = 0;//filterEls[i].value;;
			} else {
				sRouting = 99;	
			}
		}
		//---Timings - Outbound
		if(filterEls[i].name == 'outTime'){
			if(filterEls[i].checked){
				if(filterEls[i].id == 'filter_outTime_1'){
					sTimeOut_1_lb = '1';
					sTimeOut_1_ub = '800';
				} else if (filterEls[i].id == 'filter_outTime_2'){
					sTimeOut_2_lb = '801';
					sTimeOut_2_ub = '1200';
				} else if (filterEls[i].id == 'filter_outTime_3'){
					sTimeOut_3_lb = '1201';
					sTimeOut_3_ub = '1800';
				} else if (filterEls[i].id == 'filter_outTime_4'){	
					sTimeOut_4_lb = '1801';
					sTimeOut_4_ub = '2400';
				}
			} else {
				if(filterEls[i].id == 'filter_outTime_1'){
					sTimeOut_1_lb = '9999';
					sTimeOut_1_ub = '-1';
				} else if (filterEls[i].id == 'filter_outTime_2'){
					sTimeOut_2_lb = '9999';
					sTimeOut_2_ub = '-1';
				} else if (filterEls[i].id == 'filter_outTime_3'){
					sTimeOut_3_lb = '9999';
					sTimeOut_3_ub = '-1';
				} else if (filterEls[i].id == 'filter_outTime_4'){	
					sTimeOut_4_lb = '9999';
					sTimeOut_4_ub = '-1';
				}
			}
		}
		//---Timings - Inbound
		if(filterEls[i].name == 'inTime'){
			if(filterEls[i].checked){
				if(filterEls[i].id == 'filter_inTime_1'){
					sTimeRet_1_lb = '1';
					sTimeRet_1_ub = '800';
				} else if (filterEls[i].id == 'filter_inTime_2'){
					sTimeRet_2_lb = '801';
					sTimeRet_2_ub = '1200';
				} else if (filterEls[i].id == 'filter_inTime_3'){
					sTimeRet_3_lb = '1201';
					sTimeRet_3_ub = '1800';
				} else if (filterEls[i].id == 'filter_inTime_4'){	
					sTimeRet_4_lb = '1801';
					sTimeRet_4_ub = '2400';
				}
			} else {
				if(filterEls[i].id == 'filter_inTime_1'){
					sTimeRet_1_lb = '9999';
					sTimeRet_1_ub = '-1';
				} else if (filterEls[i].id == 'filter_inTime_2'){
					sTimeRet_2_lb = '9999';
					sTimeRet_2_ub = '-1';
				} else if (filterEls[i].id == 'filter_inTime_3'){
					sTimeRet_3_lb = '9999';
					sTimeRet_3_ub = '-1';
				} else if (filterEls[i].id == 'filter_inTime_4'){	
					sTimeRet_4_lb = '9999';
					sTimeRet_4_ub = '-1';
				}
			}
		}
	}
	//---Select Timing Pattern and Create Filters Accordingly - 
	var fTimeOut = false;
		arrFilterTimes.push('fTimeOut_1_lb');
		arrFilterTimes.push(sTimeOut_1_lb)
		arrFilterTimes.push('fTimeOut_1_ub');
		arrFilterTimes.push(sTimeOut_1_ub);
		arrFilterTimes.push('fTimeOut_2_lb');
		arrFilterTimes.push(sTimeOut_2_lb);
		arrFilterTimes.push('fTimeOut_2_ub');
		arrFilterTimes.push(sTimeOut_2_ub);
		arrFilterTimes.push('fTimeOut_3_lb');
		arrFilterTimes.push(sTimeOut_3_lb);
		arrFilterTimes.push('fTimeOut_3_ub');
		arrFilterTimes.push(sTimeOut_3_ub);
		arrFilterTimes.push('fTimeOut_4_lb');
		arrFilterTimes.push(sTimeOut_4_lb);
		arrFilterTimes.push('fTimeOut_4_ub');
		arrFilterTimes.push(sTimeOut_4_ub);

		arrFilterTimes.push('fTimeRet_1_lb');
		arrFilterTimes.push(sTimeRet_1_lb)
		arrFilterTimes.push('fTimeRet_1_ub');
		arrFilterTimes.push(sTimeRet_1_ub);
		arrFilterTimes.push('fTimeRet_2_lb');
		arrFilterTimes.push(sTimeRet_2_lb);
		arrFilterTimes.push('fTimeRet_2_ub');
		arrFilterTimes.push(sTimeRet_2_ub);
		arrFilterTimes.push('fTimeRet_3_lb');
		arrFilterTimes.push(sTimeRet_3_lb);
		arrFilterTimes.push('fTimeRet_3_ub');
		arrFilterTimes.push(sTimeRet_3_ub);
		arrFilterTimes.push('fTimeRet_4_lb');
		arrFilterTimes.push(sTimeRet_4_lb);
		arrFilterTimes.push('fTimeRet_4_ub');
		arrFilterTimes.push(sTimeRet_4_ub);
	//alert(sCarriers);
	//alert(sRouting);
	//alert(fTimeOut);
	//doFilter('/XML_Sandbox/FlightsXML_full.xml','/XML_Sandbox/FlightsXSL_alt_filter.xsl','container_alt', 'fCarrier', sCarriers )
	doFilter('container_alt', 'fCarrier', sCarriers );
}


function doFilter(divID, paramName, paramValue){
var xmlDoc = flightsXML;
 var curr = readCookie('curr');
 var rate = parseFloat(readCookie('currRate'));
 var selectedFlightPrice = document.getElementById('ctl00_mainContent_hfFlightPrice').value;
var xslDocURL = '/Booking/xsl/FlightsXSL_alt_filter.xsl';
 document.getElementById(divID).innerHTML = '<div class="textPanel"><p><img src="/images/ani_updating.gif" /></p></div>'
 // declare the local variables
 var xmlDoc, xslDoc, docProcessor, docCache, DocRequest, docFragment;
 // try the following
 try
 {
   // instantiate and load the xml document
   //xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
   //xmlDoc.async = false;
   //xmlDoc.load(xmlDocURL);
   xmlDoc = flightsXML;
   // instantiate and load the xsl document
   xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
   xslDoc.async = false;
   xslDoc.load(xslDocURL);
   // prepare the xsl document for transformation
   docCache = new ActiveXObject("MSXML2.XSLTemplate");
   docCache.stylesheet = xslDoc;
   // instantiate the document processor and submit the xml document
   docProcessor = docCache.createProcessor();
   docProcessor.input = xmlDoc;
   // add selected flight to the xsl document
   docProcessor.addParameter("flightId", selectedFlight, "")
   // add Carrier parameter to the xsl document
   docProcessor.addParameter("fCarrier", paramValue, "")
   // add Routing parameter
   docProcessor.addParameter("fRouting", sRouting, "")
   // add Time filters;
   var numOfFilters = arrFilterTimes.length;
	for(var i=0; i<numOfFilters; i+=2){
		//alert(arrFilterTimes[i] + ':' + arrFilterTimes[i+1]);
		docProcessor.addParameter(arrFilterTimes[i],arrFilterTimes[i+1]);
	}
	// add Currency Conversion params
	docProcessor.addParameter("curr", curr, "")
	docProcessor.addParameter("rate", rate, "")
	docProcessor.addParameter("selectedFlightPrice", selectedFlightPrice, "")
   // process the documents into html and submit to the passed div box
   docProcessor.transform();
   // divID.innerHTML = docProcessor.output;
   document.getElementById(divID).innerHTML = docProcessor.output;
   if(document.getElementById(divID).innerHTML==''){
	 document.getElementById(divID).innerHTML = '<p class="strong">No matching flights found!</p><p>Please adjust the filter values and try again.</p>';
   }
 }
 // catch any errors from the above code
 catch(e)
 {
   // try the following
   try
   {	 
     // instantiate and load the xml document
     //docRequest = new XMLHttpRequest();
     //docRequest.open("GET", xmlDocURL, false);
     //docRequest.send(null);
     xmlDoc = flightsXML//docRequest.responseXML;
     // instantiate and load the xsl document
     docRequest = new XMLHttpRequest();
     docRequest.open("GET", xslDocURL, false);
     docRequest.send(null);
     xslDoc = docRequest.responseXML;
     // instantiate the document processor and submit the xsl document
     docProcessor = new XSLTProcessor();
     docProcessor.importStylesheet(xslDoc);
     // add parameters to the xsl document
	 docProcessor.setParameter(null, "flightId", selectedFlight); 
     docProcessor.setParameter(null, "fCarrier", paramValue);
	 docProcessor.setParameter(null, "fRouting", sRouting);
   	 var numOfFilters = arrFilterTimes.length;
	 for(var i=0; i<numOfFilters; i+=2){
		docProcessor.setParameter(null, arrFilterTimes[i], arrFilterTimes[i+1]);
	 }
     docProcessor.setParameter(null, "curr", curr);
     docProcessor.setParameter(null, "rate", rate);
     docProcessor.setParameter(null, "selectedFlightPrice", selectedFlightPrice);
     // clear the passed div if anything was in it
     document.getElementById(divID).innerHTML = "";
     // process the documents into html and submit to the passed div
     docFragment = docProcessor.transformToFragment(xmlDoc, document);
     document.getElementById(divID).appendChild(docFragment);
   if(document.getElementById(divID).innerHTML==''){
	 document.getElementById(divID).innerHTML = '<p class="strong">No matching flights found!</p><p>Please adjust the filter values and try again.</p>';
   }
   }
   // catch any errors from the above code
   catch(e)
   {
     alert("Mozilla Error: " + e.description);
	 alert(docRequest.status);
   }
 }
}

function setDefaultFlight(flightId)
{
 selectedFlight = flightId;
 document.getElementById('ctl00_mainContent_hfFlightID').value = flightId;
 document.cookie = "flightId = " + document.getElementById('ctl00_mainContent_hfFlightID').value
 document.getElementById('container_default').innerHTML = '<div class="textPanel"><p><img src="/images/ani_updating.gif" /></p></div>'
 var xmlDoc, xslDoc, docProcessor, docCache, DocRequest, docFragment;
 var xslDocURL = '/Booking/xsl/FlightsXSL_update.xsl';
 // try the following
 try
 {
   // instantiate and load the xml document
   //xmlDoc = new ActiveXObject("MSXML2.DOMDocument");
   //xmlDoc.async = false;
   //xmlDoc.load(xmlDocURL);
   xmlDoc = flightsXML;
   xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
   xslDoc.async = false;
   xslDoc.load(xslDocURL);
   docCache = new ActiveXObject("MSXML2.XSLTemplate");
   docCache.stylesheet = xslDoc;
   docProcessor = docCache.createProcessor();
   docProcessor.input = flightsXML;
   docProcessor.addParameter("flightId", flightId, "")
   docProcessor.transform();
   // divID.innerHTML = docProcessor.output;
   document.getElementById('container_default').innerHTML = docProcessor.output;
 }
 // catch any errors from the above code
 catch(e)
 {
   // try the following
   try
   {
     // instantiate and load the xml document
     //docRequest = new XMLHttpRequest();
     //docRequest.open("GET", xmlDocURL, false);
     //docRequest.send(null);
     xmlDoc = flightsXML///docRequest.responseXML;
     // instantiate and load the xsl document
     docRequest = new XMLHttpRequest();
     docRequest.open("GET", xslDocURL, false);
     docRequest.send(null);
     xslDoc = docRequest.responseXML;
     // instantiate the document processor and submit the xsl document
     docProcessor = new XSLTProcessor();
     docProcessor.importStylesheet(xslDoc);
     // add parameters to the xsl document
     docProcessor.setParameter(null, "flightId", flightId);
     // clear the passed div if anything was in it
     document.getElementById('container_default').innerHTML = "";
     // process the documents into html and submit to the passed div
     docFragment = docProcessor.transformToFragment(xmlDoc, document);
     document.getElementById('container_default').appendChild(docFragment);
   }
   // catch any errors from the above code
   catch(e)
   {
     alert("Error Setting Default Flight: " + e.description);
	 //alert(docRequest.status);
   }
 }
}

//*****************************************************
//*** ROOM DISPLAY FUNCTIONS 	                    ***
//*****************************************************
var roomsXSL
var roomsXML
var roomsXSL_alt
var roomsXSL_update
var roomsXSL_selected
var selectedFlight = 1;
var rooms

function getRoomsList(){
//	strUpdating = '<div class="textPanel"><img src="/images/ani_connecting.gif" /></div>';
//	document.getElementById("rooms_default").innerHTML=strUpdating;	
	roomsXSL = loadXMLDoc("/Booking/xsl/roomsXSL_default.xsl");
	roomsXSL_alt = loadXMLDoc("/Booking/xsl/roomsXSL_alt.xsl");
	roomsXSL_update = loadXMLDoc("/Booking/xsl/roomsXSL_update.xsl");
	roomsXSL_selected = loadXMLDoc("/Booking/xsl/roomsXSL_Selected.xsl");
	strRoomsXML = document.getElementById('ctl00_mainContent_hfRooms').value;
    rooms = document.getElementById('ctl00_mainContent_hfNumOfRooms').value;
	getRoomsList_success(strRoomsXML);
}

function getRoomsList_success(strRoomsXML){
		var root = strRoomsXML
		try {
			roomsXML = new ActiveXObject("Microsoft.XMLDOM");
			roomsXML.loadXML(root);
			} catch(e) {
  		try {
			parser = new DOMParser();
			roomsXML = parser.parseFromString(root,"text/xml");
			} catch(e) {
			alert(e.message)}
		}
		//renderRoomsList();
//		if(document.getElementById("ctl00_mainContent_hfRoom1_Selected").value!="")
//		{
//		    renderSelectedRoom();
//		}
//		else
//		{
//		    renderDefaultRoom();
//		}
		
		renderAlternateRoomsList();
		updateOccupancy();
}



//function renderRoomsList(){
//	var curr = readCookie('curr');
//	var rate = parseFloat(readCookie('currRate'));
//	var xmlDoc = roomsXML;
//	var xslDocURL = "/System/xsl/roomsXSL_default.xsl"
//	var xslDoc_altURL = "/System/xsl/roomsXSL_alt.xsl"
//	var numOfRooms = document.getElementById('ctl00_mainContent_hfNumOfRooms').value;	
//	for(i = 1; i<=numOfRooms;i++){
//		window["room" + i + "_boardBasis"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "_BoardBasis").value;
//		window["room" + i + "_boardBasisCode"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "_BoardBasisCode").value;
//		window["room" + i + "_price"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "Price").value;
//	}
//	//Get selected 
//	try {
//		xslDoc = new ActiveXObject("MSXML2.FreeThreadedDomDocument");
//		xslDoc.async = false;
//		xslDoc.load(xslDocURL);
//		docCache = new ActiveXObject("MSXML2.XSLTemplate");
//		docCache.stylesheet = xslDoc;
//		docProcessor = docCache.createProcessor();
//		docProcessor.input = xmlDoc;
//		for(i=1;i<=numOfRooms;i++){
//			docProcessor.addParameter("Room" + i + "_boardBasis", window["room" + i + "_boardBasis"], "");
//			docProcessor.addParameter("Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"], "");		
//			docProcessor.addParameter("Room" + i + "_price", window["room" + i + "_price"], "");	
//		}
//		docProcessor.transform();
//		document.getElementById("rooms_default").innerHTML = docProcessor.output;
//		//Alt Rooms
//		xslDoc_alt = new ActiveXObject("MSXML2.FreeThreadedDomDocument");
//		xslDoc_alt.async = false;
//		xslDoc_alt.load(xslDoc_altURL);
//		docCache_alt = new ActiveXObject("MSXML2.XSLTemplate");
//		docCache_alt.stylesheet = xslDoc_alt;
//		docProcessor_alt = docCache_alt.createProcessor();
//		docProcessor_alt.input = xmlDoc;
//		for(i=1;i<=numOfRooms;i++){
//			docProcessor_alt.addParameter("Room" + i + "_boardBasis", window["room" + i + "_boardBasis"], "");
//			docProcessor_alt.addParameter("Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"], "");		
//			docProcessor_alt.addParameter("Room" + i + "_price", window["room" + i + "_price"], "");	
//		}
//		docProcessor_alt.transform();
//		document.getElementById("rooms_container_alt").innerHTML = '';
//		document.getElementById("rooms_container_alt").innerHTML = docProcessor_alt.output;
//		}  catch(e) {
//try {
//		docProcessor = new XSLTProcessor();
//		docProcessor.importStylesheet(roomsXSL);
//		document.getElementById('rooms_default').innerHTML = '';
//		docFragment = docProcessor.transformToFragment(xmlDoc, document);
//		document.getElementById('rooms_default').appendChild(docFragment);		
//		docProcessor = new XSLTProcessor();
//		docProcessor.importStylesheet(roomsXSL_alt);
//		for(i=1;i<=numOfRooms;i++){
//			docProcessor.setParameter(null, "Room" + i + "_boardBasis", window["room" + i + "_boardBasis"]);
//			docProcessor.setParameter(null, "Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"]);				
//			docProcessor.setParameter(null, "Room" + i + "_price", window["room" + i + "_price"]);
//		}
//		docFragment = docProcessor.transformToFragment(xmlDoc, document);
//		document.getElementById('rooms_container_alt').innerHTML = '';
//		document.getElementById('rooms_container_alt').appendChild(docFragment);			
//		} catch(e) { 
//		alert("Error Rendering Rooms: " + e.description);
//		}
//	}
//  updateOccupancy();
//}
function renderSelectedRoom()
{
var xmlDoc = roomsXML;
var xslDocURL = "/Booking/xsl/RoomsXSL_Selected.xsl"
var numOfRooms = document.getElementById('ctl00_mainContent_hfNumOfRooms').value;	
	//Get selected 
	for(i = 1; i<=numOfRooms;i++){
	// ctl00$hfRoom1_Selected
		window["room" + i + "_roomCategoryCode"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "_Selected").value;
		window["room" + i + "_boardBasisCode"] = document.getElementById("ctl00_mainContent_hfBasis" + i + "_Selected").value;
	}
	//Get selected 
	try {
		//Alt Rooms
		xslDoc_alt = new ActiveXObject("MSXML2.FreeThreadedDomDocument");
		xslDoc_alt.async = false;
		xslDoc_alt.load(xslDocURL);
		docCache_alt = new ActiveXObject("MSXML2.XSLTemplate");
		docCache_alt.stylesheet = xslDoc_alt;
		docProcessor_alt = docCache_alt.createProcessor();
		docProcessor_alt.input = xmlDoc;
		for(i=1;i<=numOfRooms;i++){
			docProcessor_alt.addParameter("selectedRoom" + i, window["room" + i + "_roomCategoryCode"], "");
			docProcessor_alt.addParameter("Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"], "");		
		}
		docProcessor_alt.transform();
		document.getElementById("rooms_default").innerHTML = '';
		document.getElementById("rooms_default").innerHTML = docProcessor_alt.output;
		}  catch(e) {
try {
		
		docProcessor = new XSLTProcessor();
		docProcessor.importStylesheet(roomsXSL_selected);
		for(i=1;i<=numOfRooms;i++){
			docProcessor.setParameter(null, "selectedRoom" + i, window["room" + i + "_roomCategoryCode"], "");
			docProcessor.setParameter(null, "Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"]);				
		}
		docFragment = docProcessor.transformToFragment(xmlDoc, document);
		document.getElementById('rooms_default').innerHTML = '';
		document.getElementById('rooms_default').appendChild(docFragment);			
		} catch(e) { 
		alert("Error Rendering Rooms: " + e.description);
		}
	}
}

function renderDefaultRoom()
{
var xmlDoc = roomsXML;
var xslDocURL = "/Booking/xsl/roomsXSL_default.xsl"
var numOfRooms = document.getElementById('ctl00_mainContent_hfNumOfRooms').value;	
	//Get selected 
	try {
		xslDoc = new ActiveXObject("MSXML2.FreeThreadedDomDocument");
		xslDoc.async = false;
		xslDoc.load(xslDocURL);
		docCache = new ActiveXObject("MSXML2.XSLTemplate");
		docCache.stylesheet = xslDoc;
		docProcessor = docCache.createProcessor();
		docProcessor.input = xmlDoc;
		docProcessor.transform();
		document.getElementById("rooms_default").innerHTML = docProcessor.output;
		}  catch(e) {
try {
		docProcessor = new XSLTProcessor();
		docProcessor.importStylesheet(roomsXSL);
		document.getElementById('rooms_default').innerHTML = '';
		docFragment = docProcessor.transformToFragment(xmlDoc, document);
		document.getElementById('rooms_default').appendChild(docFragment);		
		} catch(e) { 
		alert("Error Rendering Rooms: " + e.description);
		}
	}
}

function renderAlternateRoomsList(){
	var curr = readCookie('curr');
	var rate = parseFloat(readCookie('currRate'));
	var xmlDoc = roomsXML;
	var xslDoc_altURL = "/Booking/xsl/roomsXSL_alt.xsl"
	var numOfRooms = document.getElementById('ctl00_mainContent_hfNumOfRooms').value;	
	for(i = 1; i<=numOfRooms;i++){
		window["room" + i + "_roomCategoryCode"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "_CategoryCode").value;
		window["room" + i + "_boardBasis"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "_BoardBasis").value;
		window["room" + i + "_boardBasisCode"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "_BoardBasisCode").value;
		window["room" + i + "_price"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "Price").value;
	}
	//Get selected 
	try {
		//Alt Rooms
		xslDoc_alt = new ActiveXObject("MSXML2.FreeThreadedDomDocument");
		xslDoc_alt.async = false;
		xslDoc_alt.load(xslDoc_altURL);
		docCache_alt = new ActiveXObject("MSXML2.XSLTemplate");
		docCache_alt.stylesheet = xslDoc_alt;
		docProcessor_alt = docCache_alt.createProcessor();
		docProcessor_alt.input = xmlDoc;
		for(i=1;i<=numOfRooms;i++){
			docProcessor_alt.addParameter("Room" + i + "_roomCategoryCode", window["room" + i + "_roomCategoryCode"], "");
			docProcessor_alt.addParameter("Room" + i + "_boardBasis", window["room" + i + "_boardBasis"], "");
			docProcessor_alt.addParameter("Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"], "");		
			docProcessor_alt.addParameter("Room" + i + "_price", window["room" + i + "_price"], "");	
		}
		docProcessor_alt.addParameter("curr", curr, "")
		docProcessor_alt.addParameter("rate", rate, "")
		docProcessor_alt.transform();
		document.getElementById("rooms_container_alt").innerHTML = '';
		document.getElementById("rooms_container_alt").innerHTML = docProcessor_alt.output;
		}  catch(e) {
try {
		
		docProcessor = new XSLTProcessor();
		docProcessor.importStylesheet(roomsXSL_alt);
		for(i=1;i<=numOfRooms;i++){
			docProcessor.setParameter(null, "Room" + i + "_roomCategoryCode", window["room" + i + "_roomCategoryCode"], "");
			docProcessor.setParameter(null, "Room" + i + "_boardBasis", window["room" + i + "_boardBasis"]);
			docProcessor.setParameter(null, "Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"]);				
			docProcessor.setParameter(null, "Room" + i + "_price", window["room" + i + "_price"]);
		}
		docProcessor.setParameter(null, "curr", curr);
		docProcessor.setParameter(null, "rate", rate);
		docFragment = docProcessor.transformToFragment(xmlDoc, document);
		document.getElementById('rooms_container_alt').innerHTML = '';
		document.getElementById('rooms_container_alt').appendChild(docFragment);			
		} catch(e) { 
		alert("Error Rendering Rooms: " + e.description);
		}
	}
}

function renderRoomsList(){
	var curr = readCookie('curr');
	var rate = parseFloat(readCookie('currRate'));
	var xmlDoc = roomsXML;
	var xslDocURL = "/Booking/xsl/roomsXSL_default.xsl"
	var xslDoc_altURL = "/Booking/xsl/roomsXSL_alt.xsl"
	var numOfRooms = document.getElementById('ctl00_mainContent_hfNumOfRooms').value;	
	for(i = 1; i<=numOfRooms;i++){
		window["room" + i + "_roomCategoryCode"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "_CategoryCode").value;
		window["room" + i + "_boardBasis"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "_BoardBasis").value;
		window["room" + i + "_boardBasisCode"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "_BoardBasisCode").value;
		window["room" + i + "_price"] = document.getElementById("ctl00_mainContent_hfRoom" + i + "Price").value;
	}
	//Get selected 
	try {
		xslDoc = new ActiveXObject("MSXML2.FreeThreadedDomDocument");
		xslDoc.async = false;
		xslDoc.load(xslDocURL);
		docCache = new ActiveXObject("MSXML2.XSLTemplate");
		docCache.stylesheet = xslDoc;
		docProcessor = docCache.createProcessor();
		docProcessor.input = xmlDoc;		
		for(i=1;i<=numOfRooms;i++){
			docProcessor.addParameter("Room" + i + "_roomCategoryCode", window["room" + i + "_roomCategoryCode"], "");
			docProcessor.addParameter("Room" + i + "_boardBasis", window["room" + i + "_boardBasis"], "");
			docProcessor.addParameter("Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"], "");		
			docProcessor.addParameter("Room" + i + "_price", window["room" + i + "_price"], "");	
		}
		docProcessor.addParameter("curr", curr, "")
    	docProcessor.addParameter("rate", rate, "")

		docProcessor.transform();
		document.getElementById("rooms_default").innerHTML = docProcessor.output;
		//Alt Rooms
		xslDoc_alt = new ActiveXObject("MSXML2.FreeThreadedDomDocument");
		xslDoc_alt.async = false;
		xslDoc_alt.load(xslDoc_altURL);
		docCache_alt = new ActiveXObject("MSXML2.XSLTemplate");
		docCache_alt.stylesheet = xslDoc_alt;
		docProcessor_alt = docCache_alt.createProcessor();
		docProcessor_alt.input = xmlDoc;
		for(i=1;i<=numOfRooms;i++){
			docProcessor_alt.addParameter("Room" + i + "_roomCategoryCode", window["room" + i + "_roomCategoryCode"], "");
			docProcessor_alt.addParameter("Room" + i + "_boardBasis", window["room" + i + "_boardBasis"], "");
			docProcessor_alt.addParameter("Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"], "");		
			docProcessor_alt.addParameter("Room" + i + "_price", window["room" + i + "_price"], "");	
		}
		docProcessor_alt.addParameter("curr", curr, "")
		docProcessor_alt.addParameter("rate", rate, "")
		docProcessor_alt.transform();
		document.getElementById("rooms_container_alt").innerHTML = '';
		document.getElementById("rooms_container_alt").innerHTML = docProcessor_alt.output;
		}  catch(e) {
try {
		docProcessor = new XSLTProcessor();
		docProcessor.importStylesheet(roomsXSL);
		document.getElementById('rooms_default').innerHTML = '';
		docFragment = docProcessor.transformToFragment(xmlDoc, document);
		document.getElementById('rooms_default').appendChild(docFragment);		
		docProcessor = new XSLTProcessor();
		docProcessor.importStylesheet(roomsXSL_alt);
		for(i=1;i<=numOfRooms;i++){
			docProcessor.setParameter(null, "Room" + i + "_roomCategoryCode", window["room" + i + "_roomCategoryCode"], "");
			docProcessor.setParameter(null, "Room" + i + "_boardBasis", window["room" + i + "_boardBasis"]);
			docProcessor.setParameter(null, "Room" + i + "_boardBasisCode", window["room" + i + "_boardBasisCode"]);				
			docProcessor.setParameter(null, "Room" + i + "_price", window["room" + i + "_price"]);
		}
		docProcessor.setParameter(null, "curr", curr);
		docProcessor.setParameter(null, "rate", rate);
		docFragment = docProcessor.transformToFragment(xmlDoc, document);
		document.getElementById('rooms_container_alt').innerHTML = '';
		document.getElementById('rooms_container_alt').appendChild(docFragment);			
		} catch(e) { 
		alert("Error Rendering Rooms: " + e.description);
		}
	}
}

function updateOccupancy(){
   for(i=1;i<=rooms;i++){
		var strOccupancy = document.getElementById("ctl00_mainContent_hfRoom" + i + "Occupancy").value;
		document.getElementById("room" + i + "_occupants").innerHTML = '';
		document.getElementById("room" + i + "_occupants").innerHTML = window['room' + i + '_occStr'];
  }	
}

function setSelectedRoom(){
		arrRadio = document.getElementsByTagName('input');
		for(x=0;x<arrRadio.length;x++){
			if(arrRadio[x].type == 'radio'){
				for(t=1;t<=rooms;t++){
					if(arrRadio[x].name == 'room_' + t){
						if(arrRadio[x].value == window['room_' + t + '_default']){
							arrRadio[x].checked = true;					
						}
					}
				}
			}
		}
updateRooms();
toggleFlightsRooms('rooms');
}
function updateRooms(){
		arrRadio = document.getElementsByTagName('input');
		for(x=0;x<arrRadio.length;x++){
			if(arrRadio[x].type == 'radio'){
				for(t=1;t<=rooms;t++){
					if(arrRadio[x].name == 'Room' + t){
						if(arrRadio[x].checked){
							window['room_' + t + '_default'] = arrRadio[x].value;	
							var roomRoot = roomsXML.firstChild.childNodes[t-1]
							var tmpRoom = roomRoot.childNodes[arrRadio[x].value-1];
							var categoryCode = tmpRoom.attributes.getNamedItem("code").value;
							var roomStatus = tmpRoom.attributes.getNamedItem("status").value;
							var boardBasis_code = tmpRoom.firstChild.childNodes[0].attributes.getNamedItem("code").value;					
							var boardBasis_desc = tmpRoom.firstChild.childNodes[0].attributes.getNamedItem("desc").value;
							var roomType = tmpRoom.childNodes[1].firstChild.childNodes[0].nodeValue;
							document.getElementById('ctl00_mainContent_hfRoom'+t+'_RoomType').value = roomType;
							//document.cookie = 'room'+t+'_RoomType = ' + document.getElementById('ctl00_mainContent_hfRoom'+t+'_RoomType').value;
							document.getElementById('ctl00_mainContent_hfRoom'+t+'_CategoryCode').value = categoryCode;
							//document.cookie = 'room' + t + 'CategoryInfoCode = ' + document.getElementById('ctl00_mainContent_hfRoom'+t+'_CategoryCode').value;
							document.getElementById('ctl00_mainContent_hfRoom'+t+'_BoardBasis').value = boardBasis_desc;
							//document.cookie = 'room'+t+'_BoardBasis = ' + document.getElementById('ctl00_mainContent_hfRoom'+t+'_BoardBasis').value;
							document.getElementById('ctl00_mainContent_hfRoom'+t+'_BoardBasisCode').value = boardBasis_code;
							//document.cookie = 'room' + t + 'BoardBasisCode = ' + document.getElementById('ctl00_mainContent_hfRoom'+t+'_BoardBasisCode').value;
							document.getElementById('ctl00_mainContent_hfRoom'+t+'_Status').value = roomStatus;
							updateRoomsDetails(t);
														
						}
					}
				}
			}
		}
document.getElementById('rooms_default').innerHTML = '';
toggleFlightsRooms('none');
renderRooms(1, window['room_1_default']);
updateOccupancy();
}

    function hideRooms(numRooms){
	    for(i=2;i<=5;i++){
		    if(i<=numRooms){
			    document.getElementById("room"+i).style.display='block';
		    } else {
			    document.getElementById("room"+i).style.display='none';
		    }
	    }	
    }


var activeChildSelector;
var activeRoomNum;
var childNum;

function popChildAgeForm(roomNum){
	activeRoomNum = roomNum;
	activeChildSelector = document.getElementById(['ctl00_mainContent_sRoom' + roomNum + '_children']);
	childNum = document.getElementById(['ctl00_mainContent_sRoom' + roomNum + '_children']).value;
	if(childNum==0){
		for(i=1; i<=3; i++){
			document.getElementById(['room' + roomNum + '_age' + i]).className = 'hidden';			
		}
	}
	for(i=1; i<=3; i++){
		if(i<=childNum){
			document.getElementById(['room' + roomNum + '_age' + i]).className = '';
		} else {
			document.getElementById(['room' + roomNum + '_age' + i]).className = 'hidden';
		}
	}

 //retrieveChildAges()
}
    function toggleFlight(){
	    var flightStatus = document.getElementById("ctl00_mainContent_sDepartAirport").disabled;
	    if(flightStatus){
		    document.getElementById("ctl00_mainContent_sDepartAirport").disabled = false;
		    document.getElementById("ctl00_mainContent_sClass").disabled = false;
		    if(eval(document.getElementById("ctl00_mainContent_btnToggleFlight"))){
		        document.getElementById("ctl00_mainContent_btnToggleFlight").value = 'I don\'t need a flight';
		    }
		    if(eval(document.getElementById("btnToggleFlight"))){
    		    document.getElementById("btnToggleFlight").value = 'I don\'t need a flight';
    		}
		    document.getElementById("checkIn_label").innerHTML = 'Your departure date is';
		    document.getElementById("checkOut_label").innerHTML = 'Your return date is';
		    document.getElementById("ctl00_mainContent_hfUserSelection").value = 'flightsRooms';
	    } else {	
		    document.getElementById("ctl00_mainContent_sDepartAirport").disabled = true;
		    document.getElementById("ctl00_mainContent_sClass").disabled = true;
		    if(eval(document.getElementById("ctl00_mainContent_btnToggleFlight"))){
		        document.getElementById("ctl00_mainContent_btnToggleFlight").value = 'I need a flight';
		    }
		    if(eval(document.getElementById("btnToggleFlight"))){
		        document.getElementById("btnToggleFlight").value = 'I need a flight';
		    }
		    document.getElementById("checkIn_label").innerHTML = 'Your check-in date is';
		    document.getElementById("checkOut_label").innerHTML = 'Your check-out date is';
		    document.getElementById("ctl00_mainContent_hfUserSelection").value = 'rooms';
	    }
    }
	  
function renderRooms(roomNum,selectedRoom){
 var xslDocURL = "/Booking/xsl/roomsXSL_update.xsl";
 // try the following
 try
 {
   xmlDoc = roomsXML;
   xslDoc = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
   xslDoc.async = false;
   xslDoc.load(xslDocURL);
   docCache = new ActiveXObject("MSXML2.XSLTemplate");
   docCache.stylesheet = xslDoc;
   docProcessor = docCache.createProcessor();
   docProcessor.input = xmlDoc;
   docProcessor.addParameter("roomNum", roomNum, "")
   docProcessor.addParameter("selectedRoom", selectedRoom, "")   
   docProcessor.transform();
   document.getElementById('room'+roomNum+'_default').innerHTML = '';
   document.getElementById('room'+roomNum+'_default').innerHTML = docProcessor.output;
 }
 // catch any errors from the above code
 catch(e)
 {
   // try the following
   try
   {
     xmlDoc = roomsXML;
     docRequest = new XMLHttpRequest();
     docRequest.open("GET", xslDocURL, false);
     docRequest.send(null);
     xslDoc = docRequest.responseXML;
     docProcessor = new XSLTProcessor();
     docProcessor.importStylesheet(xslDoc);
     docProcessor.setParameter(null, "roomNum", roomNum);
     docProcessor.setParameter(null, "selectedRoom", selectedRoom);
     docFragment = docProcessor.transformToFragment(xmlDoc, document);
	 document.getElementById('room'+roomNum+'_default').innerHTML = '';
     document.getElementById('room'+roomNum+'_default').appendChild(docFragment);
   }
   // catch any errors from the above code
   catch(e)
   {
     alert("Mozilla Error: " + e.description);
	 alert(docRequest.status);
   }
 }
   for(i=1;i<=rooms;i++){
	//var strOccupancy = document.getElementById("ctl00_mainContent_hfRoom" + i + "Occupancy").value;
	//document.getElementById("room" + i + "_occupancy").innerHTML = strOccupancy;
  }
updateRoomPrice('Room'+roomNum);
	if(roomNum<rooms){
		tmpRoomNum = roomNum+1
		tmpSelectedRoom = window['room_' + (roomNum+1) + '_default'];
		renderRooms(tmpRoomNum,tmpSelectedRoom);
	}
	renderAlternateRoomsList();
}

function toggleFlightsRooms(category){
	if(category=='none'){
		document.getElementById("altFlights").className="hidden";
		document.getElementById("altRooms").className='hidden';
        document.getElementById("altHotels").className='hidden';
		return false;
	}
	if(category=='flights'){
		document.getElementById("altFlights").className='';
		document.getElementById("altRooms").className='hidden';
        document.getElementById("altHotels").className='hidden';
		document.location="#flights";
	} else if(category=='hotels'){
		document.getElementById("altFlights").className='hidden';
		document.getElementById("altRooms").className='hidden';
        document.getElementById("altHotels").className='';
        renderTabPanels();
		document.location="#hotels";
	} else {
		document.getElementById("altFlights").className="hidden";
		document.getElementById("altRooms").className='';
        document.getElementById("altHotels").className='hidden';
		//renderRoomsList();
		document.location="#rooms";
	}
	sIFR_repeat();
}

function updateFlightPrev(flightId,price)
{
    document.getElementById('ctl00_mainContent_hfFlightPrice').value = price;
	setPrice();
	toggleFlightsRooms('none');
	setDefaultFlight(flightId);
}

function updateFlight(flightId,price,outdeparttime,outarrtime,indepartime,inarrtime,outdeptdate,outarrdate,indeptdate,inarrdate,toDepTerminal,toArrTerminal,fmDepTerminal,fmArrTerminal,toArrAirport,fmDepAirport){
	document.getElementById('ctl00_mainContent_hfFlightPrice').value = price;
	setTimes(outdeparttime,outarrtime,indepartime,inarrtime,outdeptdate,outarrdate,indeptdate,inarrdate);
	setTerminal(toDepTerminal,toArrTerminal,fmDepTerminal,fmArrTerminal,toArrAirport,fmDepAirport);
	setPrice();
	toggleFlightsRooms('none');
	setDefaultFlight(flightId);
}
    
	function getCityCode(selObj) {
        document.getElementById('ctl00_mainContent_hfOriginCity').value = selObj.options[selObj.options.selectedIndex].value;
        var cityName = document.getElementById('ctl00_mainContent_hfOriginCity').value;
        var myArray = cityName.split('#');
        cityName = myArray[1];
        var cityCode = myArray[0];
        document.getElementById('ctl00_mainContent_hfOriginCity').value = cityName;
        document.getElementById('ctl00_mainContent_hfOriginCityCode').value = cityCode;
    }   

//*****************************************************
//*** DISPLAY PRINTABLE ITINERARY                   ***
//*****************************************************
function popItin(){
        if(eval(document.getElementById("ctl00_mainContent_RightItinerary1_lblPackagePrice"))){
            var price  = document.getElementById('ctl00_mainContent_RightItinerary1_lblPackagePrice').innerHTML;
            var curr = document.getElementById('currAbr').innerHTML;
            if(eval(document.getElementById("ctl00_mainContent_sAirportTransfer"))){
                var selectedIndex = document.getElementById('ctl00_mainContent_sAirportTransfer').selectedIndex;
                var transfer = document.getElementById('ctl00_mainContent_sAirportTransfer').options[selectedIndex].text;
                var qString = 'printItinerary.aspx?price=' + price  + '&curr=' + curr + '&transfer=' + transfer;
            }
            else
            {
                var qString = 'printItinerary.aspx?price=' + price + '&curr=' + curr;
            }
        }
        else
        {
            var curr = document.getElementById('ctl00_mainContent_RightItinerary1_lblFlightCurr').innerHTML;
            var price  = document.getElementById('ctl00_mainContent_RightItinerary1_lblFlightPrice').innerHTML;
            var qString = 'printItinerary.aspx?price=' + price + '&curr=' + curr;
        }
		window.open(qString,'itin','width=527,height=600,scrollbars=yes');	
}
//Fnction below used before totalPackagePrice Session is set on Results Page
function popItin_results(){
		price = addCommas(totalPackagePrice)
		window.open('printItinerary.aspx?price='+price,'itin','width=527,height=600,scrollbars=yes');	
}

//Load Inflight Meals
function loadFlightMeals(){
	var mealXML = loadXMLDoc("/Booking/xml/InFlightMeal.xml");
	var meals = mealXML.getElementsByTagName('Meal');
	var strMeals = '';
	var tmpMealCode
	var tmpMealName
	
	for(i=0;i<meals.length;i++){
		if(meals[i].getAttribute('Code')){
			tmpMealCode = meals[i].getAttribute('Code')
			tmpMealName = meals[i].firstChild.nodeValue
			if(strMeals.indexOf(tmpMealCode) < 0){
				document.getElementById('sec_sInflightMeal').options[document.getElementById('sec_sInflightMeal').length] = new Option(tmpMealName, tmpMealCode);				
				document.getElementById('sInflightMeal').options[document.getElementById('sInflightMeal').length] = new Option(tmpMealName, tmpMealCode);				
			}
		}
	}
}

// Focusing calendar textboxes

function ClearText(value,object)
{
   if(object.value=="Select from calendar")
    {
     object.value="";
    }
}

function focusTextBox(value){
    if(value == 'checkin'){
        if(eval(document.getElementById("checkIn_label"))){
            //document.getElementById("checkIn_label").style.color  = "#f92408";
            //document.getElementById("checkIn_label").style.fontWeight  = "bold";
             document.getElementById("checkIn_label").className = "bold";
        }
        if(eval(document.getElementById("checkOut_label"))){
            //document.getElementById("checkOut_label").style.color = "#2ca3c5";
             document.getElementById("checkOut_label").className="";
        }
        if(eval(document.getElementById("ctl00_mainContent_checkIn_label"))){
            //document.getElementById("ctl00_mainContent_checkIn_label").style.color  = "#f92408";
            //document.getElementById("ctl00_mainContent_checkIn_label").style.fontWeight  = "bold";
            document.getElementById("ctl00_mainContent_checkIn_label").className="bold";
        }
        if(eval(document.getElementById("ctl00_mainContent_checkOut_label"))){
            //document.getElementById("ctl00_mainContent_checkOut_label").style.color = "#2ca3c5";
            //document.getElementById("ctl00_mainContent_checkOut_label").style.fontWeight  = "normal";
            document.getElementById("ctl00_mainContent_checkOut_label").className="";
        }
    }
    else if(value == 'checkout'){

        if(eval(document.getElementById("checkIn_label"))){
            //document.getElementById("checkIn_label").style.color  = "#2ca3c5";
            //document.getElementById("checkIn_label").style.fontWeight  = "normal";
            document.getElementById("checkIn_label").className="";
        }
        if(eval(document.getElementById("checkOut_label"))){
            //document.getElementById("checkOut_label").style.color = "#f92408";
            //document.getElementById("checkOut_label").style.fontWeight  = "bold";
            document.getElementById("checkOut_label").className = "bold";
        }
        if(eval(document.getElementById("ctl00_mainContent_checkIn_label"))){
            //document.getElementById("ctl00_mainContent_checkIn_label").style.color  = "#2ca3c5";
            //document.getElementById("ctl00_mainContent_checkIn_label").style.fontWeight  = "normal";
            document.getElementById("ctl00_mainContent_checkIn_label").className="";
        }
        if(eval(document.getElementById("ctl00_mainContent_checkOut_label"))){
            //document.getElementById("ctl00_mainContent_checkOut_label").style.color = "#f92408";
            //document.getElementById("ctl00_mainContent_checkOut_label").style.fontWeight  = "bold";
            document.getElementById("ctl00_mainContent_checkOut_label").className="bold";
        }
    }
    else if(value == 'pickup'){
        if(eval(document.getElementById("tDropOffDate_label"))){
            //document.getElementById("tDropOffDate_label").style.color  = "#2ca3c5";
            //document.getElementById("tDropOffDate_label").style.fontWeight  = "normal";
            document.getElementById("tDropOffDate_label").className="";
        }
        if(eval(document.getElementById("tPickUpDate_label"))){
            //document.getElementById("tPickUpDate_label").style.color = "#f92408";
            //document.getElementById("tPickUpDate_label").style.fontWeight  = "bold";
             document.getElementById("tPickUpDate_label").className="bold"
        }
    }
    else if(value == 'dropoff'){
        if(eval(document.getElementById("tPickUpDate_label"))){
            //document.getElementById("tPickUpDate_label").style.color  = "#2ca3c5";
            //document.getElementById("tPickUpDate_label").style.fontWeight  = "normal";
            document.getElementById("tPickUpDate_label").className="";
        }
        if(eval(document.getElementById("tDropOffDate_label"))){
            //document.getElementById("tDropOffDate_label").style.color = "#f92408";
            //document.getElementById("tDropOffDate_label").style.fontWeight  = "bold";
            document.getElementById("tDropOffDate_label").className="bold";
        }
    }
}
