// JavaScript Document

function GetResult(str)
{
	var req = false;
	if (window.XMLHttpRequest) {// if Mozilla, Safari etc
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // if IE
		try {
			req = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				req = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
			}
		}
	} else {
		return false;
	}


	req.onreadystatechange = function() {
		if (req.readyState == 4 && req.status == 200) {
			BuildSel(unescape(req.responseText),document.booking_form.hoteltype);
		}
	}
	try {
		req.open("GET","xmlhttp.php?sel="+str,true);
		req.send(null);
	} catch (e) {
	}

}

function BuildSel(str,sel)
{
    //?.
    document.booking_form.checkhotel.value = str;
    document.booking_form.hoteltype.options.length=0;
    var arrstr = new Array();
    arrstr = str.split(":");
    //?μSelect.
    for(var i=0;i<arrstr.length;i++)
    {
        option_arr = arrstr[i].split(",");
        sel.options[sel.options.length]=new Option(option_arr[1],option_arr[0])
		if (i == 0) {
			UpdateBooking(option_arr[0]);
		}
    }
}

function hotel_submit(lang)
{
	var temp_hotel = document.booking_form.hoteltype.value;
	if (document.booking_form.hoteltype.value > 0)
    {
		document.location = "gotohotel.php?hotel_id=" + temp_hotel;
		//document.booking_form.action = "home.php";
        //document.booking_form.submit();
    }
    else
    {
        alert(messages['select_hotel']);
    }
}

function checkin()
{
    if (document.booking_form.hoteltype.value <= 0)
    {
        alert(messages['select_hotel']);
		return;
    }
    if (document.booking_form.checkInDate.value == "mm/dd/yyyy" || document.booking_form.checkOutDate.value == "mm/dd/yyyy")
    {
        alert(messages['select_checkout_date']);
        return;
    }
    
    strarr = document.booking_form.checkhotel.value.split(":");
    for (i = 0; i < strarr.length; i++)
    {
		tmpstrarr = strarr[i].split(",");
        if (document.booking_form.hoteltype.value == tmpstrarr[0])
        {
            hotelid = tmpstrarr[2];
        }
    }
    
    inday = document.booking_form.checkInDate.value;
    inday_arr = inday.split("/");
    inday = inday_arr[2] + "/" + inday_arr[0] + "/" + inday_arr[1];
    outday = document.booking_form.checkOutDate.value;
    outday_arr = outday.split("/");
    outday = outday_arr[2] + "/" + outday_arr[0] + "/" + outday_arr[1];
	
	switch (document.booking_form.hoteltype.value)
	{
		case "12":
			u = "https://www.chinahotel.com.cn/ctshk/index.php?set=13&hotel_id=1&roomcount=" + document.booking_form.select1.value + "&inputday=" + inday + "&inputday2=" + outday;
			break;
			
		case "10":
			u = "https://www.chinahotel.com.cn/ctshk/index.php?set=13&hotel_id=2&roomcount=" + document.booking_form.select1.value + "&inputday=" + inday + "&inputday2=" + outday;
			break;
			
		case "9":
			u = "https://www.chinahotel.com.cn/ctshk/index.php?set=13&hotel_id=3&roomcount=" + document.booking_form.select1.value + "&inputday=" + inday + "&inputday2=" + outday;
			break;
			
		case "3":
			u = "https://www.chinahotel.com.cn/ctshk/index.php?set=13&hotel_id=4&roomcount=" + document.booking_form.select1.value + "&inputday=" + inday + "&inputday2=" + outday;
			break;
			
		default:
			u = "https://www.chinahotel.com.cn/ctshotelhk/index.php?set=13&hotel_id=" + hotelid + "&roomcount=" + document.booking_form.select1.value + "&inputday=" + inday + "&inputday2=" + outday;
			break;
	}
	
    window.open(u);
}

function UpdateBooking(hotel_id) {
	if (reservation_ids[hotel_id] != null) {
//		document.getElementById("new_booking").style.display = "";
//		document.getElementById("booking").style.display = "none";
		document.booking_form.HotelID.value = reservation_ids[hotel_id];
		document.booking_form.res_type.value = "booking_engine";
	} else {
//		document.getElementById("new_booking").style.display = "none";
//		document.getElementById("booking").style.display = "";
		document.booking_form.HotelID.value = hotel_id;
		document.booking_form.res_type.value = "email_form";
	}
}
				var bookings = null;
				function openWindow(url,name,width,height,resizable,scrollbars,statusbar,menubar,toolbar)
				{
					var win = eval(name);
					var optionString = "";
					if (width) optionString += "width=" + width + ",";
					if (height) optionString += "height=" + height + ",";
					if (resizable) optionString += "resizable=" + resizable + ",";
					if (scrollbars) optionString += "scrollbars=" + scrollbars + ",";
					if (statusbar) optionString += "statusbar=" + statusbar + ",";
					if (menubar) optionString += "menubar=" + menubar + ",";
					if (toolbar) optionString += "toolbar=" + toolbar + ",";
					win = window.open(url,name,optionString);
					win.focus();
				}

				function submitBooking(form) {
					if (form.HotelID.value != "" && form.HotelID.value != "0") {
						if (form.res_type.value == 'booking_engine') {
							form.DateIn.value=form.MM1.value + "/" + form.DD1.value + "/" + form.YY1.value;
						//	var url = "https://reservations.ihotelier.com/istay.cfm";
							var url = "https://booking.ihotelier.com/istay/istay.jsp";
							url += "?HotelID=" + form.HotelID.value;
							url += "&LanguageID=" + form.LanguageID.value;
							url += "&DateIn=" + form.DateIn.value;
							url += "&Length=" + form.Length.value;
							url += "&Rooms=" + form.Rooms.value;
							url += "&Adults=" + form.Adults.value;
							url += "&Children=" + form.Children.value;
							openWindow(url,"bookings",1010,710);
						} else {
							form.DateIn.value=form.MM1.value + "/" + form.DD1.value + "/" + form.YY1.value;
							var url = "reservation.php";
							url += "?HotelID=" + form.HotelID.value;
							url += "&LanguageID=" + form.LanguageID.value;
							url += "&MM1=" + form.MM1.value;
							url += "&DD1=" + form.DD1.value;
							url += "&YY1=" + form.YY1.value;
							url += "&DateIn=" + form.DateIn.value;
							url += "&Length=" + form.Length.value;
							url += "&Rooms=" + form.Rooms.value;
							url += "&Adults=" + form.Adults.value;
							url += "&Children=" + form.Children.value;
							window.location.href=url;
//							openWindow(url,"bookings",800,600);
						}
					} else {
				        alert(messages['no_reservation_service']);
					}
				}

