function JLJS_RecommendAreaControl() {
	
	this.COOKIE_SESSION_AIRPORT = "sessionAirport";
	this.COOKIE_AUTO_SEL_AIRPORT = "autoSelAirport";
	this.COOKIE_AREA_AIRPORT = "areaAirport";
	this.RT_IDs = "RTA-4533-082a3bc31419";
	this.RT_IDh = "RTA-4533-082afc770dd1";
	this.COOKIE_DOMAIN = ".jal.co.jp";
	this.AUTO_SEL_AIRPORT = "autoSelAirport";
	this.RECOMMEND_AIRPORT = "rt_recommendAirport";
	this.MAX_TIMER_COUNT = 5;
	this.NONE = "none";

	this.rtId = "";
	if (location.host.match(/^[0-9\.:]+$/)){
		this.rtId = this.RT_IDs;
	}else{
		this.rtId = this.RT_IDh;
	}
	this.recommendId = "";
	this.execRtFlag = true;
	this.airport = "";
	this.afterExec = function (){};
	this.sessionAirport = {};
	this.timer;
	this.timerCount = 1;
	this.env = {};
	this.env.isIE50 = ( JLJS.env.isIE && navigator.appVersion.toLowerCase().match( /msie 5\.0/ )) ? true : false;
	this.env.isIE55 = ( JLJS.env.isIE && navigator.appVersion.toLowerCase().match( /msie 5\.5/ )) ? true : false;	
	this.form = {};
	
	this.airportDelList = ["FKS"];
	this.airportChangeHash = {"CTS":"SPK"};
}

JLJS_RecommendAreaControl.prototype = {
	init : function() {
		
		this.recommendId = "'" + arguments[0] + "'";
		for (var i=1;i<arguments.length;i++) {
			this.recommendId += ",'" + arguments[i] + "'";
		}		
		
		if (this.execRtFlag && !(this.env.isIE50 || this.env.isIE55)){
			this.execRtoaster();
		}else{
			this.getAirport();
			if (!this.airport && !(this.env.isIE50 || this.env.isIE55)){
				this.execRtoaster();
			}
		}
	},
	
	execRtoaster : function(){
		
		Rtoaster.init(this.rtId);
		eval("Rtoaster.recommendNow(" + this.recommendId + ")");
	},
	
	getAirport : function(){
		this.sessionAirport = JLJS_CookieMgr.getMulti(this.COOKIE_SESSION_AIRPORT);
		
		var areaAirport = JLJS_CookieMgr.get(this.COOKIE_AREA_AIRPORT);
		areaAirport = this.delAirportCookie(areaAirport);
		if (areaAirport){
			this.airport = areaAirport;
			
			var cookieOption = {domain : this.COOKIE_DOMAIN};
			var date = new Date();
			date.setFullYear(date.getFullYear() + 1);
			var expires = date.toGMTString();
			cookieOption.expires = expires;
			if(window.location.host.match(/^[0-9\.:]+$/)) {
				delete cookieOption.domain;
			}
			for (var i in this.airportChangeHash) {
				if (this.airport == i) {
					this.airport = this.airportChangeHash[i];
					break;
				}
			}
			JLJS_CookieMgr.set(this.COOKIE_AREA_AIRPORT, this.airport, cookieOption);
			return;
		}

		if (this.sessionAirport){
			var autoSelAirport = this.sessionAirport[this.COOKIE_AUTO_SEL_AIRPORT];
			if (autoSelAirport) {
				this.airport = autoSelAirport;
				return;
			}
		}
	},
	load : function(){
		
		if (this.airport) {
			this.afterExec(this.airport);
		}else{
			this.getAirport();
			if (this.airport) {
				this.afterExec(this.airport);
			}else{
				this.form = document.getElementById(this.RECOMMEND_AIRPORT);
				if (!this.callback()) {
					this.timer = setInterval(function(){JLJS_recAreaCtrl.callback()} ,200);	
				}		
			}

		}
	},
	callback : function(){
		var airport = "";
		var autoSelElment = this.form[this.AUTO_SEL_AIRPORT];
		if (autoSelElment){
			airport = "" + autoSelElment.value;
		}

		if (this.timerCount > this.MAX_TIMER_COUNT) {
			clearInterval(this.timer);
			this.afterExec(this.airport);
		}else if (airport) {
			if (airport != this.NONE){
				this.airport = airport;
				var cookieOption = {domain : this.COOKIE_DOMAIN};
				if(window.location.host.match(/^[0-9\.:]+$/)) {
					delete cookieOption.domain;
				}
				JLJS_CookieMgr.addMulti(this.COOKIE_SESSION_AIRPORT, this.COOKIE_AUTO_SEL_AIRPORT, this.airport, cookieOption);
			}
			clearInterval(this.timer);
			this.afterExec(this.airport);
			return true;
		}else{
			this.timerCount++;
		}
		return false;
	},
	delAirportCookie : function(airport) {
		if (airport) {
			var date = new Date();
			date.setFullYear(date.getFullYear() - 10);
			var expires = date.toGMTString();
			var cookieOption = {domain : this.COOKIE_DOMAIN, "expires":expires};
			if(window.location.host.match(/^[0-9\.:]+$/)) {
				delete cookieOption.domain;
			}
			for (var i=0;i<this.airportDelList.length;i++) {
				if (airport == this.airportDelList[i]) {
					JLJS_CookieMgr.set(this.COOKIE_AREA_AIRPORT, "", cookieOption);
					airport = "";
					break;
				}
			}
		}
		return airport;
	}
	
}

var JLJS_recAreaCtrl = new JLJS_RecommendAreaControl();


