/*[CountryJudgmentObj]*/
function JLJS_CountryJudgmentObj(){
	this.currencyCD = "USD";
	
	if(JLJS02.site.region.isAU){ 
		this.currencyCD = "AUD";
	}else if(JLJS02.site.region.isHK){ 
		this.currencyCD = "HKD";
	}else if(JLJS02.site.region.isCN){
		this.countryCD = "CN";
	}else if(JLJS02.site.region.isKR){
		this.currencyCD = "KRW";
	}else if(JLJS02.site.region.isSG){
		this.currencyCD = "SGD";
	}else if(JLJS02.site.region.isNZ){
		this.currencyCD = "NZD";
	}else if(JLJS02.site.region.isTH){
		this.currencyCD = "THB";
	}else if(JLJS02.site.region.isUK){
		this.currencyCD = "GBP";
	}else if(JLJS02.site.region.isFR){
		this.currencyCD = "EUR";
	}else if(JLJS02.site.region.isDE){
		this.currencyCD = "EUR";
	}else if(JLJS02.site.region.isNL){
		this.currencyCD = "EUR";
	}else if(JLJS02.site.region.isES){
		this.currencyCD = "EUR";
	}else if(JLJS02.site.region.isIT){
		this.currencyCD = "EUR";
	}else if(JLJS02.site.region.isEG){
		this.currencyCD = "EUR";
	}else if(JLJS02.site.region.isAT){
		this.currencyCD = "EUR";
	}else if(JLJS02.site.region.isCH){
		this.currencyCD = "CHF";
	}else if(JLJS02.site.region.isRU){
		this.currencyCD = "EUR";
	}else if(JLJS02.site.region.isCA){
		this.currencyCD = "CAD";
	}
}

var JLJS_countryObj = new JLJS_CountryJudgmentObj();
/*[/CountryJudgmentObj]*/

/*[hotel_AreaNarrowDawn]*/
function JLJS_HotelModuleNarrowDown(){
	this.countries = {
		"JPN" : {
		"CD" : "JPN", "title" : "Japan",
		"list" : [ "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47" ],
		"defaultFlg" : 1
		}
	};
	this.cities = {
		"01" : { "CD" : "01", "title" : "Sapporo", "list" : [ "ALL", "AIR" ] },
		"02" : { "CD" : "02", "title" : "Aomori", "list" : [ "ALL", "AIR" ] },
		"03" : { "CD" : "03", "title" : "Morioka","list" : [ "ALL", "AIR" ] },
		"04" : { "CD" : "04", "title" : "Sendai","list" : [ "ALL", "AIR" ] },
		"05" : { "CD" : "05", "title" : "Akita", "list" : [ "ALL", "AIR" ] },
		"06" : { "CD" : "06", "title" : "Yamagata", "list" : [ "ALL", "AIR" ] },
		"07" : { "CD" : "07", "title" : "Fukushima", "list" : [ "ALL", "AIR" ] },
		"08" : { "CD" : "08", "title" : "Mito", "list" : [ "ALL", "AIR" ] },
		"09" : { "CD" : "09", "title" : "Utsunomiya", "list" : [ "ALL", "AIR" ] },
		"10" : { "CD" : "10", "title" : "Maebashi", "list" : [ "ALL", "AIR" ] },
		"11" : { "CD" : "11", "title" : "Saitama", "list" : [ "ALL", "AIR" ] },
		"12" : { "CD" : "12", "title" : "Chiba","list" : [ "ALL", "NRT" ] },
		"13" : {
			"CD" : "13", "title" : "Tokyo",
			"list" : [ "TYO", "HND", "AKA", "RPG", "ASA", "UEN", "GIZ", "IKE", "ODA", "SBY", "SNG", "SIN", "IDA", "SBA", "NHB" ],
			"defaultFlg" : 1
		},
		"14" : { "CD" : "14", "title" : "Yokohama","list" : [ "ALL", "AIR" ] },
		"15" : { "CD" : "15", "title" : "Niigata","list" : [ "ALL", "AIR" ] },
		"16" : { "CD" : "16", "title" : "Toyama","list" : [ "ALL", "AIR" ] },
		"17" : { "CD" : "17", "title" : "Kanazawa","list" : [ "ALL", "AIR" ] },
		"18" : { "CD" : "18", "title" : "Fukui","list" : [ "ALL", "AIR" ] },
		"19" : { "CD" : "19", "title" : "Kofu","list" : [ "ALL", "AIR" ] },
		"20" : { "CD" : "20", "title" : "Nagano","list" : [ "ALL", "AIR" ] },
		"21" : { "CD" : "21", "title" : "Gifu","list" : [ "ALL", "AIR" ] },
		"22" : { "CD" : "22", "title" : "Shizuoka","list" : [ "ALL", "AIR" ] },
		"23" : { "CD" : "23", "title" : "Nagoya","list" : [ "ALL", "AIR" ] },
		"24" : { "CD" : "24", "title" : "Tsu","list" : [ "ALL", "AIR" ] },
		"25" : { "CD" : "25", "title" : "Otsu","list" : [ "ALL", "AIR" ] },
		"26" : { "CD" : "26", "title" : "Kyoto","list" : [ "ALL", "AIR" ] },
		"27" : { "CD" : "27", "title" : "Osaka","list" : [ "ALL", "AIR" ] },
		"28" : { "CD" : "28", "title" : "Kobe","list" : [ "ALL", "AIR" ] },
		"29" : { "CD" : "29", "title" : "Nara","list" : [ "ALL", "AIR" ] },
		"30" : { "CD" : "30", "title" : "Wakayama","list" : [ "ALL", "AIR" ] },
		"31" : { "CD" : "31", "title" : "Tottori","list" : [ "ALL", "AIR" ] },
		"32" : { "CD" : "32", "title" : "Matsue","list" : [ "ALL", "AIR" ] },
		"33" : { "CD" : "33", "title" : "Okayama","list" : [ "ALL", "AIR" ] },
		"34" : { "CD" : "34", "title" : "Hiroshima","list" : [ "ALL", "AIR" ] },
		"35" : { "CD" : "35", "title" : "Yamaguchi","list" : [ "ALL", "AIR" ] },
		"36" : { "CD" : "36", "title" : "Tokushima","list" : [ "ALL", "AIR" ] },
		"37" : { "CD" : "37", "title" : "Takamatsu","list" : [ "ALL", "AIR" ] },
		"38" : { "CD" : "38", "title" : "Matsuyama","list" : [ "ALL", "AIR" ] },
		"39" : { "CD" : "39", "title" : "Kochi","list" : [ "ALL", "AIR" ] },
		"40" : { "CD" : "40", "title" : "Fukuoka","list" : [ "ALL", "AIR" ] },
		"41" : { "CD" : "41", "title" : "Saga","list" : [ "ALL", "AIR" ] },
		"42" : { "CD" : "42", "title" : "Nagasaki","list" : [ "ALL", "AIR" ] },
		"43" : { "CD" : "43", "title" : "Kumamoto","list" : [ "ALL", "AIR" ] },
		"44" : { "CD" : "44", "title" : "Oita","list" : [ "ALL", "AIR" ] },
		"45" : { "CD" : "45", "title" : "Miyazaki","list" : [ "ALL", "AIR" ] },
		"46" : { "CD" : "46", "title" : "Kagoshima","list" : [ "ALL", "AIR" ] },
		"47" : { "CD" : "47", "title" : "Naha","list" : [ "ALL", "AIR" ] }
	};
	this.areas = {
		"TYO" : { "CD" : "130", "title" : "-", "defaultFlg" : 1 },
		"HND" : { "CD" : "131", "title" : "Haneda Airport" },
		"AKA" : { "CD" : "132", "title" : "Akasaka" },
		"RPG" : { "CD" : "133", "title" : "Roppongi" },
		"ASA" : { "CD" : "134", "title" : "Asakusa" },
		"UEN" : { "CD" : "135", "title" : "Ueno" },
		"GIZ" : { "CD" : "136", "title" : "Ginza" },
		"IKE" : { "CD" : "137", "title" : "Ikebukuro" },
		"ODA" : { "CD" : "138", "title" : "Odaiba" },
		"SBY" : { "CD" : "139", "title" : "Shibuya" },
		"SNG" : { "CD" : "13a", "title" : "Shinagawa" },
		"SIN" : { "CD" : "13b", "title" : "Shinjuku" },
		"IDA" : { "CD" : "13c", "title" : "Iidabashi" },
		"SBA" : { "CD" : "13d", "title" : "Shiba" },
		"NHB" : { "CD" : "13e", "title" : "Nihonbashi" },
		"ALL" : { "CD" : "", "title" : "-" },
		"AIR" : { "CD" : "", "title" : "Airport" },
		"NRT" : { "CD" : "", "title" : "Narita Airport" }
	};
	this.countryOP = null;
	this.cityOP = null;
	this.areaOP = null;
}

JLJS_HotelModuleNarrowDown.prototype = {
	init : function( forms ){
		if(!forms){ return; }
		
		this.countryOP = forms["country"];
		this.cityOP = forms["city"];
		this.areaOP = forms["area"];
		this.setCountryOptions();
	},
	
	narrowDownCountry : function(){
		var countryVal = this.countryOP[this.countryOP.selectedIndex].value;
		this.cityOP.options.length = 0;
		
		for(var i=0; i<this.countries[countryVal]["list"].length; i++){
			var countryList = this.countries[countryVal]["list"][i];			
			var newOPT = this.setCityTextValue(countryVal, countryList);
			this.cityOP.appendChild(newOPT);	
		}
		
		this.narrowDownCity();		
	},
	
	narrowDownCity : function(){
		var cityVal = this.cityOP[this.cityOP.selectedIndex].value;
		this.areaOP.options.length = 0;
		
		for(var i=0; i<this.cities[cityVal]["list"].length; i++){
			var cityList = this.cities[cityVal]["list"][i];
			var newOPT = this.setAreaTextValue(cityVal, cityList);
			this.areaOP.appendChild(newOPT);
		}
	},
	
	setCountryOptions : function(){

		for(var i in this.countries){
			var newOPT = document.createElement( 'option' );
			newOPT.value = this.countries[i][ "CD" ];
			newOPT.innerHTML = this.countries[i][ "title" ];
			
			if(this.countries[i]["defaultFlg"]){
				newOPT.selected = true;
			}
			this.countryOP.appendChild(newOPT);	
		}
		
		this.setCityOptions();
	},
	
	setCityOptions : function(){
		var countryVal = this.countryOP[this.countryOP.selectedIndex].value;
		
		for(var j=0; j<this.countries[countryVal]["list"].length; j++){
			var countryList = this.countries[countryVal]["list"][j];
			var newOPT = this.setCityTextValue(countryVal, countryList);
			this.cityOP.appendChild(newOPT);
		}
		
		this.setAreaOptions();
	},
	
	setAreaOptions : function(){
		var cityVal = this.cityOP[this.cityOP.selectedIndex].value;
		
		for(var k=0; k<this.cities[cityVal]["list"].length; k++){
			var cityList = this.cities[cityVal]["list"][k];
			var newOPT = this.setAreaTextValue(cityVal, cityList);
			this.areaOP.appendChild(newOPT);
		}
	},
	
	setAreaTextValue : function(cityVal, cityList){
		var newOPT = document.createElement( 'option' );

		if(cityList == "ALL"){
			newOPT.value = cityVal +"0";
		}else if(cityList == "AIR"){
			newOPT.value =  cityVal + "1";
		}else if(cityList == "NRT"){
			newOPT.value =  cityVal + "1";
		}else{
			newOPT.value = this.areas[cityList][ "CD" ];
		}
		newOPT.innerHTML = this.areas[cityList][ "title" ];
		
		if(this.areas[cityList]["defaultFlg"]){
			newOPT.selected = true;
		}
		
		return newOPT;
	},
	
	setCityTextValue : function(countryVal, countryList){
		var newOPT = document.createElement( 'option' );
		newOPT.value = this.cities[countryList][ "CD" ];
		newOPT.innerHTML = this.cities[countryList][ "title" ];
		
		if(this.cities[countryList]["defaultFlg"]){
			newOPT.selected = true;
		}
		
		return newOPT;
	}
}

var JLJS_HMnarrowdown = new JLJS_HotelModuleNarrowDown();
/*[/hotel_AreaNarrowDawn]*/

/*[hotelModule_Currency]*/
function JLJS_HotelModuleCurrency(){
	this.priceList = {
		"USD" : [ 50, 100, 150, 200, 250, 300 ],
		"CAD" : [ 50, 100, 150, 200, 250, 300 ],
		"EUR" : [ 25, 50, 75, 100, 125, 150 ],
		"GBP" : [ 25, 50, 75, 100, 125, 150 ],
		"CHF" : [ 50, 100, 150, 200, 250, 300 ],
		"AUD" : [ 50, 100, 150, 200, 250, 300 ],
		"NZD" : [ 50, 100, 150, 200, 250, 300 ],
		"SGD" : [ 50, 100, 150, 200, 250, 300 ],
		"HKD" : [ 250, 500, 750, 1000, 1250, 1500 ],
		"THB" : [ 2500, 5000, 7500, 10000, 12500, 15000 ],
		"KRW" : [ 50000, 100000, 150000, 200000, 250000, 300000 ]};
	this.hotelform = null;
	this.currencyCD = JLJS_countryObj.currencyCD;
	this.moneyList = [];
}

JLJS_HotelModuleCurrency.prototype = {
	init : function( forms ){
		this.hotelform = forms;		
		this.moneyList = this.priceList[this.currencyCD];
		
		this.setFromOption();
		this.setToOption();
	},
	
	setFromOption : function(){
		var pFrom = this.hotelform["p_from"];
		pFrom.options.length = 0;
		
		var any = new Option("any", "");
		any.selected = true;
		pFrom.options[0] = any;
		for(var i=0; i < this.moneyList.length-1; i++){
			var text = this.currencyCD + " " + this.moneyList[i];
			pFrom.options[pFrom.options.length] = new Option(text, this.moneyList[i]);
		}
	},
	
	setToOption : function(){
		var pTo = this.hotelform["p_to"];
		pTo.options.length = 0;
		
		var opts = new Array();
		for(var i=0; i<this.moneyList.length; i++){
			var text = this.currencyCD + " " + this.moneyList[i];
			pTo.options[i] = new Option(text, this.moneyList[i]);
		}
		var any = new Option("any", "");
		pTo.options[pTo.options.length] = any;
		any.selected = true;
	}
}

var JLJS_HMcurrency = new JLJS_HotelModuleCurrency();
/*[/hotelModule_Currency]*/

function JLJS_HotelModule() {
	
	this.HOTEL_FORM = "hotelSearchForm";
	this.TOPMODULE_HOTELFROM = "topHotelSearchForm";
	this.HOTEL_HIDDENPARAM = "hotelHiddenParam";
	this.setupOnLoadFlag = true;
	this.hotelform = {};
	this.tophotelform = {};
	this.hiddenParamform = {};
	this.cityNode = {};
	this.currencyCD = null;
	this.depDateSelector;
}

JLJS_HotelModule.prototype = {
	setup : function() {
		this.hotelform = document.getElementById(this.HOTEL_FORM);
		
		this.init();
	},
	
	topModuleSetup : function(){
		this.hotelform = document.getElementById(this.TOPMODULE_HOTELFROM);
		
		this.init();
	},
	
	init : function(isCst){
		if(!this.hotelform) return;
		
		this.depDateSelector = new JLJS_DateSelector(this.hotelform["month"], this.hotelform["day"]);
		var dateInfo = {
			"initFlg" : true
		}
		this.hotelDateSpecify(dateInfo);
		
		var self = this;
		JLJS.addEvent( this.hotelform["month"], "change", function( e ){
			dateInfo.initFlg = false;
			self.hotelDateSpecify(dateInfo);
		});
		this.hotelCalendarSet(this.hotelform);
		JLJS_HMnarrowdown.init(this.hotelform);
		JLJS_HMcurrency.init(this.hotelform);
		this.hotelAreaNarrowDown(this.hotelform);
		
		this.hiddenParamform = document.getElementById(this.HOTEL_HIDDENPARAM);
	},
	
	submitActionForm : function() {
		var forms = this.hotelform;
		var paramString = "";
		var params = [ "month", "day", "period", "room_type", "rooms", "p_from", "p_to",  "start_rating", "area" , "call_lang", "currency_flg" ];
		
		if(this.hotelform["siteid1"] && this.hotelform["siteid2"] && this.hotelform["siteid3"]){
			var siteid1 = this.hotelform["siteid1"];
			var siteid2 = this.hotelform["siteid2"];
			var siteid3 = this.hotelform["siteid3"];
			
			if(siteid1.checked){
				params.push("siteid1");
			}
			if(siteid2.checked){
				params.push("siteid2");
			}
			if(siteid3.checked){
				params.push("siteid3");
			}
			
			if(!siteid1.checked && !siteid2.checked && !siteid3.checked){
				params.push("siteid1", "siteid2", "siteid3");
			}
		}
		
		for(var i=0; i<params.length; i++){
			var value = "";
			if(params[i] == "call_lang"){
				value = "en";
			}else if(params[i] == "currency_flg"){
				value = JLJS_countryObj.currencyCD;
			}else{
				value = this.hotelform[ params[i] ].value;
			}

			paramString = paramString + "\n<input type='hidden' name='" + params[i] + "' value='" + value + "'>"
		}
		
		this.hiddenParamform.innerHTML = paramString;

		this.hiddenParamform.submit();
	},
	
	hotelDateSpecify : function(dateInfo){
		if(!this.depDateSelector){ return; }
		
		if(dateInfo.initFlg) {
			this.depDateSelector.applyOffset('+7d');
		} else {
			this.depDateSelector.setDateBySelector();
		}
	},
	
	hotelCalendarSet : function( form ){
		var floatCalIcons = JLJS.getElementsByClassName("floatCalIcon", "a", form);
		for (var i=0;i<floatCalIcons.length;i++) {
			var floatCalIcon = floatCalIcons[i];
			
			if(JLJS_CalNav.used) {
				JLJS_CalNav.lang = JLJS02.site.lang.code;
				JLJS.addEvent(floatCalIcon,	"click",
					function(e) {
						var prm = {};
						var opt = {start:0, end:330, startNoReserveMonthDisplay:false, festivalDay:false, dayRange:'5', callBack:null, dayOfWeekFlag: true, isEN:JLJS02.site.lang.isEN};
						prm["board"] = {month: form["month"], day: form["day"]};
						JLJS_CalNav.calDisplay(
							{target: e.currentTarget,
							option: opt,
							frm : prm
							}
						)
					}
				);
			} else {
				JLJS.classAttr.add(floatCalIcon, "hidden");
			}
		}
	},
	
	hotelAreaNarrowDown : function( forms ){
		var countryNode = forms["country"];
		var cityNode = forms["city"];
		JLJS.addEvent( countryNode, "change", function(){ JLJS_HMnarrowdown.narrowDownCountry(); } );
		JLJS.addEvent( cityNode, "change", function(){ JLJS_HMnarrowdown.narrowDownCity(); } );
	}
};

var JLJS_HM = new JLJS_HotelModule();
var JLJS_CALGP = null;
