﻿//Change the gif that displays when AyncRefresh happen
//Extend the timeout of the refreshpanel to two minutes - if too short then nothing displays
function WebAsyncRefreshPanel_InitializePanel(oPanel){
  // for checking that javascript is enabled
  document.getElementById('JavaScriptEnabled').value='enabled';
  var pi = oPanel.getProgressIndicator();
  //use configurable progress indicator for the rooms list panel
  var url = "/IRMNet/Images/RDP_Processing.gif";
  var hdn = document.getElementById('hdnProcessingGif');
  if (hdn) {
     if (hdn.value.length > 0) {
     url = "/IRMNet/Images/" + hdn.value;
     }
  }   
  pi.setImageUrl(url);
	//pi.setLocation(ig_Location.MiddleCenter);
	//pi.setRelativeContainer(document.body);
  ig_shared.getCBManager()._timeLimit = 120000;
}
	
function WebAsyncRefreshPanel2_InitializePanel(oPanel){
  var pi = oPanel.getProgressIndicator();
  // use the small progress indicator for the search criteria panel
  var url = "/aspnet_client/Infragistics/Images/ig_ProgressIndicator.gif";
 pi.setImageUrl(url);

}	


function CalcDeparture(oCalendar, newValue, oEvent){
	var dtDeparture = new Date();
	var oDeparture = GetControlByID("wdcDeparture", true);
	if (!oDeparture) return false;

	var oNights = GetControlByID("wcNights_input", false);
	if (!oNights) return false;
	var iNights = oNights.value;

	var msPerDay = 24 * 60 * 60 * 1000;
	dtDeparture.setTime(newValue.getTime() + (iNights * msPerDay));
	oDeparture.setValue(dtDeparture);
	
	document.getElementById('<%=lblSearchCriteria.ClientID%>').innerText = 'Search for availability on these dates.';
	}

function SetDeparture(webComboId){
	var dtArrival = new Date();
	var oArrival = GetControlByID("wdcArrival", true);
	if (!oArrival) return false;

	var dtDeparture = new Date();
	var oDeparture = GetControlByID("wdcDeparture", true);
	if (!oDeparture) return false;

	var oNights = GetControlByID("wcNights_input", false);
	if (!oNights) return false;
	var iNights = oNights.value;

	var msPerDay = 24 * 60 * 60 * 1000;
	dtArrival.setTime(oArrival.getValue());
	if (isNaN(dtArrival)) return false;
	dtDeparture.setTime(dtArrival.getTime() + (iNights * msPerDay));
	oDeparture.setValue(dtDeparture);
}
function SetNights(oCalendar, newValue, oEvent){
	var dtArrival = new Date();
	var oArrival = GetControlByID("wdcArrival", true);
	if (!oArrival) return false;

	var dtOldDeparture = new Date();
	var dtDeparture = new Date();
	var oDeparture = GetControlByID("wdcDeparture", true);
	if (!oDeparture) return false;

	var msPerDay = 24 * 60 * 60 * 1000;
	dtArrival.setTime(oArrival.getValue());
	dtDeparture.setTime(newValue.getTime());
	dtOldDeparture.setTime(oDeparture.getValue());

	if (dtDeparture < dtArrival) {
		alert ("Departure date cannot be prior to Arrival date");
		oEvent.cancel = true;
	} else {
		var iNights = (dtDeparture.getTime() - dtArrival.getTime()) / msPerDay;
		var oNights = GetControlByID("wcNights_input", false);
		if (!oNights) return false;
		oNights.value = Math.round(iNights);
	};
}


function GetControlByID(sName, bCombo){
	var ctl
	if (bCombo){
		ctl = igdrp_getComboById(sName);
	} else {
		ctl = document.getElementById(sName);
	}; 
	if (ctl) return ctl;

	//did not find the control by typical name
	var allElms = document.body.getElementsByTagName("*");
	for (var c=0; c< allElms.length; c++){
		var itm = allElms[c];
		if (itm.id){
			if (itm.id.length > sName.length){
				if (itm.id.substring(itm.id.length-sName.length).toLowerCase() == sName.toLowerCase()){
					if (bCombo){
						ctl = igdrp_getComboById(itm.id);
						if (ctl) return ctl;
				  } else {
 						return itm;
					};
				};
			};
		};
	};
	
	return null;
}


//cancels postback if hide room type choices & hide room number choices are configured
function wcLocations_AfterSelectChange(webComboID)
{
return true;
}