var tb_pathToImage = "/img/manager/icon/loadingAnimation.gif";
var Conditionpopup = {
	options : {},
	datas : [],
	windowpopup : null,
	timeout: 1000, /* ms */
	aryObjKjDelay: [],
	
	/**
	 * opt = {
	 * 		ci: id of company 
	 * }
	 */
	
	showPopup : function (id) {		
		if(id==1) {
		  $('ChoiceStation').style.display = 'none';
		  $('ChoiceCity').style.display = 'inline';
		  
		}
		else if(id==2) {
		  $('ChoiceStation').style.display = 'inline';
		  $('ChoiceCity').style.display = 'none';
		  
		}
		Conditionpopup.windowpopup.showPopup();
	},
	
	closePopup : function (id) {
		Conditionpopup.windowpopup.closePopup();
	},
	
	init : function () {
		Event.observe($('inputRealname'), 'keyup', Conditionpopup.searchRealname.bind(this));
		Conditionpopup.windowpopup = new WindowPopup();
		Conditionpopup.windowpopup.setOptions(
			{
				idWindow: 'TB_window'
			}
		);
		Conditionpopup.windowpopup.initPopup();
	},
	
	searchRealname : function () {
		var o = new KjDelay(Conditionpopup.breakEventKeyup, 0, null);
	},
	
	breakEventKeyup : function () {
		for( var len = Conditionpopup.aryObjKjDelay.length, i = len - 1; i >= 0; i-- ){
			if(Conditionpopup.aryObjKjDelay[i] != null) {
				if(Conditionpopup.aryObjKjDelay[i].isFinished()) {
					Conditionpopup.aryObjKjDelay[i] = null;
					delete Conditionpopup.aryObjKjDelay[i];
				} else {
					Conditionpopup.aryObjKjDelay[i].clear();
				}
			}
		}
		
		Conditionpopup.aryObjKjDelay[Conditionpopup.aryObjKjDelay.length] = new KjDelay(Conditionpopup.callAjaxRequestBySearch, Conditionpopup.timeout, null);
	},
	
	callAjaxRequestBySearch: function () {
		var text = $('inputRealname').value;
	    
	}
	
}


KjDelay = function (f, m, o) {
	this.f = f;
	this.m = m;
	this.resoure = null;
	this.o = o;
	this.delay();
	this._isClear= false;
	this._isFinished= false;
}

KjDelay.prototype = {
	clear : function () {
		this._isClear = true;
		if(this.resoure) clearInterval(this.resoure);
		this.resoure = null;
	},
	
	isFinished: function () {
		return this._isFinished;
	},
	
	delay : function () {
		this._isClear = false;
		var me = this;
		this.resoure = setInterval(function() { me.end(me); }, this.m);
	},

	end : function (me) {
		if(me.resoure) clearInterval(me.resoure);
		me.resoure = null;
		if (me.f && !me._isClear) {
			me.f(me.o);
		}
		me._isClear= false;
		this._isFinished= true;
	}
}
