// ------------------------------------------------------------------

	function getXmlHttpRequest()
	{
		var httpRequest = null;
		try
		{
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				httpRequest = null;
			}
		}

		if (!httpRequest && typeof XMLHttpRequest != "undefined")
		{
			httpRequest = new XMLHttpRequest();
		}

		return httpRequest;
	}

// ------------------------------------------------------------------

	function execOnSuccess(handleStateChange)
	{
		return function(xmlHttpReq)
		{
			if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200)
			{
				handleStateChange(xmlHttpReq);
			}
			else
			{
				return false;
			}
		};
	}

// ------------------------------------------------------------------

	function getUrl(url, handleStateChange)
	{
		var xmlhttp = getXmlHttpRequest();
		if (xmlhttp)
		{
			if (xmlhttp.readyState==4 || xmlhttp.readyState==0)
			{ // if xmlhttp shows "loaded"
				xmlhttp.onreadystatechange=function()
				{
					handleStateChange(xmlhttp);
				};
				xmlhttp.open("GET", url, true);
				xmlhttp.send(null);
			}
			else
			{
				return false;
			}
		}
		else {
			return false;
		}
	}

// ------------------------------------------------------------------

	function getViaAjax(handleStateChange, ajax_form, ajax_err_field, ajax_err_response, dataQueryType)
	{
		var str='';
		var url='';
		var args=getViaAjax.arguments;

		if (args.length > 5) {
			for (i=5; i<args.length; i++) {
				str+='var'+(i-4)+'='+escape(args[i])+'&';
			}
			str=str.substring(0,str.length-1);

			url = 'lib/getViaAjax.asp?dataQueryType='+dataQueryType
				+'&ajax_handler='+handleStateChange
				+'&ajax_form='+ajax_form
				+'&ajax_err_field='+ajax_err_field
				+'&ajax_err_response='+escape(ajax_err_response)
				+'&'+str;

			getUrl(url, execOnSuccess(eval(handleStateChange)));
		}
		return false;
	}

// ------------------------------------------------------------------

	function showAjaxErrMsg(xmlhttp)
	{
//	control fields
//		pNode[0].childNodes[0].firstChild.nodeValue	//ajax_form
//		pNode[0].childNodes[1].firstChild.nodeValue	//ajax_err_field

		var xmlDoc = xmlhttp.responseXML;

		if (xmlDoc != undefined) {
			var pNode = xmlDoc.getElementsByTagName("ajax_record");
			if (pNode[0].hasChildNodes()) {

				var frm = pNode[0].childNodes[0].firstChild.nodeValue;
				var fld = pNode[0].childNodes[1].firstChild.nodeValue;

				if (pNode[0].childNodes.length > 2) { // an error message is available (over an beyond the control fields)
					oErrMsg.addErrorMsg (pNode[0].childNodes[2].firstChild.nodeValue);
					oErrMsg.setError(document[frm][fld]);
					oErrMsg.dispErrMsgs();
				}
				else {
					var response = validate(); // continue with regular JS form validation
					if (response) document[frm].submit(); // if true then submit the form
				}

			}
		}
	}

// ------------------------------------------------------------------

	function lookupViaAjax(strIdentifier, strSearch)
	{
		return getUrl("lib/getViaAjax.asp?dataQueryType="+strIdentifier+"&var1="+escape(strSearch), execOnSuccess(eval(strIdentifier)));
	}

// ------------------------------------------------------------------

	function room_type_by_hotel(xmlhttp)
	{
		var f = document.frmForm;
		var xmlDoc = xmlhttp.responseXML;
		var pNode = xmlDoc.getElementsByTagName("ajax_record");
		var elVal = '';

		while (f.mod_reg_hotel_room_type.length) {
			f.mod_reg_hotel_room_type.remove(0);
		}
		while (f.mod_reg_hotel_checkin.length) {
			f.mod_reg_hotel_checkin.remove(0);
		}
		while (f.mod_reg_hotel_checkout.length) {
			f.mod_reg_hotel_checkout.remove(0);
		}
		while (f.mod_reg_hotel_occupancy.length) {
			f.mod_reg_hotel_occupancy.remove(0);
		}

		var el = document.createElement("option");
		f.mod_reg_hotel_room_type.appendChild(el);
		el.value = ''; el.text = '-----';
		var el = document.createElement("option");
		f.mod_reg_hotel_checkin.appendChild(el);
		el.value = ''; el.text = '-----';
		var el = document.createElement("option");
		f.mod_reg_hotel_checkout.appendChild(el);
		el.value = ''; el.text = '-----';
		var el = document.createElement("option");
		f.mod_reg_hotel_occupancy.appendChild(el);
		el.value = ''; el.text = '-----';

		if (pNode.length > 0) {

			for (i = 0; i < pNode.length; i++) {
				var el = document.createElement("option");
				f.mod_reg_hotel_room_type.appendChild(el);

				elVal = pNode[i].getElementsByTagName("hotel_room_type_id");
				el.value = elVal[0].firstChild.nodeValue;
				elVal = pNode[i].getElementsByTagName("hotel_room_type_name");
				el.text = elVal[0].firstChild.nodeValue;
			}
		}

		return true;
	}

// ------------------------------------------------------------------

	function room_by_room_type(xmlhttp)
	{
		var f = document.frmForm;
		var xmlDoc = xmlhttp.responseXML;
		var elVal = '';

		while (f.mod_reg_hotel_checkin.length) {
			f.mod_reg_hotel_checkin.remove(0);
		}
		while (f.mod_reg_hotel_checkout.length) {
			f.mod_reg_hotel_checkout.remove(0);
		}
		while (f.mod_reg_hotel_occupancy.length) {
			f.mod_reg_hotel_occupancy.remove(0);
		}

		var el = document.createElement("option");
		f.mod_reg_hotel_checkin.appendChild(el);
		el.value = ''; el.text = '-----';
		var el = document.createElement("option");
		f.mod_reg_hotel_checkout.appendChild(el);
		el.value = ''; el.text = '-----';
		var el = document.createElement("option");
		f.mod_reg_hotel_occupancy.appendChild(el);
		el.value = ''; el.text = '-----';

		//check-in, check-out
		var pNode = xmlDoc.getElementsByTagName("ajax_record");
		if (pNode.length > 0) {

			//check-in is record 0 to n - 1
			for (i = 0; i < pNode.length - 1; i++) {

				var el = document.createElement("option");
				f.mod_reg_hotel_checkin.appendChild(el);
				elVal = pNode[i].getElementsByTagName("hotel_room_date_value");
				el.value = elVal[0].firstChild.nodeValue;
				elVal = pNode[i].getElementsByTagName("hotel_room_date_display");
				el.text = elVal[0].firstChild.nodeValue;

			}
			//check-out is record 1 to n
			for (i = 1; i < pNode.length; i++) {

				var el = document.createElement("option");
				f.mod_reg_hotel_checkout.appendChild(el);
				elVal = pNode[i].getElementsByTagName("hotel_room_date_value");
				el.value = elVal[0].firstChild.nodeValue;
				elVal = pNode[i].getElementsByTagName("hotel_room_date_display");
				el.text = elVal[0].firstChild.nodeValue;

			}
		}

		//occupancy
		var pNode = xmlDoc.getElementsByTagName("occupancy");
		if (pNode.length > 0) {
			for (i = 0; i < pNode.length; i++) {

				var el = document.createElement("option");
				f.mod_reg_hotel_occupancy.appendChild(el);
				elVal = pNode[i].getElementsByTagName("hotel_occupancy_id");
				el.value = elVal[0].firstChild.nodeValue;
				elVal = pNode[i].getElementsByTagName("hotel_occupancy_name");
				el.text = elVal[0].firstChild.nodeValue;

			}
		}

		return true;
	}

// ------------------------------------------------------------------
