<!--

var READY_STATE_UNINITIALIZED = 0;
var READY_STATE_LOADING = 1;
var READY_STATE_LOADED = 2;
var READY_STATE_INTERACTIVE = 3;
var READY_STATE_COMPLETE = 4;

var req = null;
var ajaxURL = "";

var gLocIndex = -1;
var gHtlIndex = -1;

function initXMLHTTPRequest() {
	var xRequest = null;
	if (window.XMLHttpRequest) {
		xRequest = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xRequest;
}

function listLocation(areaCode,country,city) {
	var obj;

	obj = document.getElementById("sLocation");
	for (i=obj.options.length-1; i>=0; i--) {
  	obj.options[i] = null;
  }
	obj.options[0] = new Option("=== 載入中,請稍候 ===","");
		
	obj = document.getElementById("sHotel");
	for (i=obj.options.length-1; i>=0; i--) {
  	obj.options[i] = null;
  }
	obj.options[0] = new Option("=== 載入中,請稍候 ===","");
			
	var	HttpMethod = "GET";
	var myURL = ajaxHome + "/LocHotel.aspx?type=location&area=" + areaCode + "&country=" + country + "&city=" + city;
	req = initXMLHTTPRequest();
	if (req) {
		req.onreadystatechange = onReadyState1;
		req.open(HttpMethod,myURL,true);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.send("");
	}
}

function onReadyState1() {
	var ready = req.readyState;
	var data = null;
	var obj = null;
	if (ready == READY_STATE_COMPLETE) {
		data = req.responseText;
		fillLocHotel(data);
	} else {

	}
}

function fillLocHotel(data) {  
  var arr = data.split("^");
  var opt;
  
  var loc = arr[0].split("|");
  obj = document.getElementById("sLocation");
  for (j=0; j<loc.length; j++) {
  	opt = loc[j].split(";");
  	if (opt[0] != "") obj.options[j] = new Option(opt[0],opt[1]);
  }
  obj.options[obj.options.length] = new Option("::請選擇參考位置::","");
  if (gLocIndex > -1) {
  	obj.selectedIndex = gLocIndex;
  	gLocIndex = -1;
  } else {
  	obj.selectedIndex = obj.options.length - 1;
	}
  
  var htl = arr[1].split("|");
  obj = document.getElementById("sHotel");
  for (j=0; j<htl.length; j++) {
  	opt = htl[j].split(";");
  	if (opt[0] != "") obj.options[j] = new Option(opt[0],opt[1]);
  }
  obj.options[obj.options.length] = new Option("::請選擇飯店名稱::","");
  if (gHtlIndex > -1) {
  	obj.selectedIndex = gHtlIndex;
  	gHtlIndex = -1;
  } else {
  	obj.selectedIndex = obj.options.length - 1;
	}
}

function listHotel(areaCode,country,city,locCode) {
	var obj = document.getElementById("sHotel");
	for (i=obj.options.length-1; i>=0; i--) {
  	obj.options[i] = null;
  }
	obj.options[0] = new Option("=== 載入中,請稍候 ===","");
			
	var	HttpMethod = "GET";
	var myURL = ajaxHome + "/LocHotel.aspx?type=hotel"
	+ "&area=" + areaCode + "&country=" + country + "&city=" + city + "&location=" + locCode;
	req = initXMLHTTPRequest();
	if (req) {
		req.onreadystatechange = onReadyState2;
		req.open(HttpMethod,myURL,true);
		req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		req.send("");
	}
}

function onReadyState2() {
	var ready = req.readyState;
	var data = null;
	var obj = null;
	if (ready == READY_STATE_COMPLETE) {
		data = req.responseText;
		fillHotel(data);
	} else {

	}
}

function fillHotel(data) {
  var opt;  
  var htl = data.split("|");
  for (j=0; j<htl.length; j++) {
  	opt = htl[j].split(";");
  	if (opt[0] != "") obj.options[j] = new Option(opt[0],opt[1]);
  }
  obj.options[obj.options.length] = new Option("::請選擇飯店名稱::","");
  if (gHtlIndex > -1) {
  	obj.selectedIndex = gHtlIndex;
  	gHtlIndex = -1;
  } else {
  	obj.selectedIndex = obj.options.length - 1;
	}
}

function initLocHotel() {
	var obj;
	
	obj = document.getElementById("sLocation");
	for (i=obj.options.length-1; i>=0; i--) {
  	obj.options[i] = null;
  }
  obj.options[0] = new Option("::請先選擇洲別::","");

	obj = document.getElementById("sHotel");
	for (i=obj.options.length-1; i>=0; i--) {
  	obj.options[i] = null;
  }
  obj.options[0] = new Option("::請先選擇洲別::","");
}

//-->
