// JavaScript Document
function fah(){
$('findAHotel').src = "../images/menu/menu_over_08.gif";
$('form').style.visibility = "visible";
}
function fah_off(){
$('findAHotel').src = "../images/menu/menu_08.gif";
$('form').style.visibility = "hidden";
}
function event_planner_on(){
$('eventPlanner').src = "../images/menu/menu_over_14.gif";
$('event_planner').style.visibility = "visible";
}
function event_planner_off(){
$('eventPlanner').src = "../images/menu/menu_14.gif";
$('event_planner').style.visibility = "hidden";
}
function event_lang_on(){
$('lang').src = "../../eng/images/buttons/menu/menu_over_06.png";
$('event_lang').style.visibility = "visible";
}
function event_lang_off(){
$('lang').src = "../../eng/images/buttons/menu/menu_06.png";
$('event_lang').style.visibility = "hidden";
}

function checkFields_book( ){
var hotelid = document.fm_booking.hotelid.value;
var datein = document.fm_booking.liveInDate.value;
var length = document.fm_booking.length.selectedIndex+1;
var rooms = document.fm_booking.rooms.value; //selectedIndex+1;
var adults = document.fm_booking.adults.selectedIndex;
var child = document.fm_booking.children.selectedIndex;
var date = datein.split("/");


//===================
var month=date[0];
var in_month=date[0];
var in_date=date[1];
var in_year=date[2];
//==================

if (month == 1){
	month = "JAN";	
}
if (month == 2){
	month = "FEB";	
}
if (month == 3){
	month = "MAR";	
}
if (month == 4){
	month = "APR";	
}
if (month == 5){
	month = "MAY";	
}
if (month == 6){
	month = "JUN";	
}
if (month == 7){
	month = "JUL";	
}
if (month == 8){
	month = "AUG";	
}
if (month == 9){
	month = "SEP";	
}
if (month == 10){
	month = "OCT";	
}
if (month == 11){
	month = "NOV";	
}
if (month == 12){
	month = "DEC";	
}

var date_input = new Date(month + " " + date[1]+", "+date[2]);
date_input.setDate(date_input.getDate() + length);

var out_date = date_input.getDate();
var out_month = date_input.getMonth()+1;
var out_month1 = date_input.getMonth()+1;
var out_year = date_input.getFullYear();

if (out_month == 1){
	out_month = "JAN";	
}
if (out_month == 2){
	out_month = "FEB";	
}
if (out_month == 3){
	out_month = "MAR";	
}
if (out_month == 4){
	out_month = "APR";	
}
if (out_month == 5){
	out_month = "MAY";	
}
if (out_month == 6){
	out_month = "JUN";	
}
if (out_month == 7){
	out_month = "JUL";	
}
if (out_month == 8){
	out_month = "AUG";	
}
if (out_month == 9){
	out_month = "SEP";	
}
if (out_month == 10){
	out_month = "OCT";	
}
if (out_month == 11){
	out_month = "NOV";	
}
if (out_month == 12){
	out_month = "DEC";	
}

if (document.fm_booking.hotelid.value=="0"){
	alert("請選擇酒店");
	document.fm_booking.hotelid.focus();
	return false ;
}

else if (document.fm_booking.liveInDate.value==""){
	alert("請選擇日期");
	document.fm_booking.liveInDate.focus();
	return false ;
}

if (hotelid == "mayfairshanghai"){


if(adults>3){
		adults=3;
	}
	
	if(adults<1){
		adults=1;
	}
	
	if(child>2){
		child=2;
	}
	
	
	guests = adults + child;
	if(guests>3){
		while(child>0 && guests>3 && adults>0){
			child--;
			guests = adults + child;
			if(guests>3){
				adults--;
			}
			guests = adults + child;
			if(guests<4){
				break;
			}
		}
		
	}

	guests = adults + child;
	window.open("https://www.yourreservation.net/ibe/HASHAMAY/main.html?language=CN&calArrivalDateField="+in_date+"-"+in_month+"-"+in_year+"&calDepartureDateField="+out_date+"-"+out_month1+"-"+out_year+"&occupancy="+guests+"&prsNumChildren="+child+"&prsRoomCount=1&prsRoomAge=0&prsRoomAge=0");
	//window.open("https://www.trustinternational.com/mBooker/srs2/4Z?LANGUAGE=zh_CN&i=mayfairshanghai&property=TXL-WW-HASHAMAY&in_day="+date[1]+"&in_month="+month+"-"+date[2]+"&out_day="+out_date+"&out_month="+out_month+"-"+out_year+"&guests="+guests);
} else if (hotelid == "23209" || hotelid == "23210" || hotelid =="25494" ){
	window.open("https://reservations.synxis.com/xbe/rez.aspx?Hotel="+hotelid+"&Chain=6158&arrive="+datein+"&depart="+out_month1+"/"+out_date+"/"+out_year+"&Adult="+adults+"&Child="+child+"&Room="+rooms+"&Lang=11&shell=sc");
} else if (hotelid == "70497" || hotelid == "70486" || hotelid == "70952"){
	window.open("https://booking.ihotelier.com/istay/istay.jsp?Hotelid="+hotelid+"&Datein="+datein+"&Length="+length+"&Rooms="+rooms+"&Adults="+adults+"&Children="+child+"&Languageid=5");
} else if (hotelid == "25321"){
	window.open("https://reservations.synxis.com/XBE/rez.aspx?Chain=6158&Hotel="+hotelid+"&arrive="+datein+"&depart="+out_month1+"/"+out_date+"/"+out_year+"&Adult="+adults+"&Child="+child+"&Room="+rooms+"&LANG=11");
} else if (hotelid == "27493"){
	window.open("https://reservations.synxis.com/XBE/rez.aspx?Chain=6158&Hotel="+hotelid+"&arrive="+datein+"&depart="+out_month1+"/"+out_date+"/"+out_year+"&Adult="+adults+"&Child="+child+"&Room="+rooms+"&shell=customSC&locale=zh-CN");
}else {
window.open("https://reservations.ihotelier.com/istay.cfm?hotelid="+hotelid+"&datein="+datein+"&length="+length+"&rooms="+rooms+"&adults="+adults+"&children="+child+"&languageid=5&x=6&y=6");
}

return false;
}