/**
 * Copyright (c) 2008, AimToG. All rights reserved.
 * Code licensed under the AimToG License
 * Version 1.0
 *
 * @author jacojang<jacojang@aimtog.co.kr>
 */

//-----------------------------------------------------------------------------
// Edit Here
//-----------------------------------------------------------------------------
var TS_SERVER_HOST		= "ts.netfunnel.com";	// Default TS host
var TS_SERVER_PORT		= 8000;					// Default TS port
var TS_QUERY_STR		= "ts.wseq";			// Default request query
var TS_MAX_TTL			= 30;					// Default max ttl (second) 5~30
var TS_CONN_TIMEOUT		= 3;					// Default connect timeout (second)
var TS_CONN_RETRY		= 1;					// Default connect retry count
var TS_INIT_LIMIT		= 20;					// Default init retry
var TS_NO_ACTION		= 600;					// Default noAction Timeout (second) 
var TS_COOKIE_ID		= "NetFunnel_ID";		// Default Cookie ID
var TS_COOKIE_TIME		= 0;					// Default Cookie Time (minute) 
var TS_COOKIE_DOMAIN	= "";					// Default Cookie Domain
var TS_BYPASS			= true;				// NetFunnel Routine Bypass [true|false]
var TS_POPUP_TOP		= false;					// Popup Top Position ( "false" is center )
var TS_POPUP_LEFT		= false;				// Popup Left Position ( "false" is center )
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// Global Define
//-----------------------------------------------------------------------------

/*
 * Request Type.
 */
var RTYPE_NONE				= 0000;		/**< 0000:Type ¾øÀ½				*/
var RTYPE_GET_TID			= 5001;		/**< 5001:Æ¼ÄÏID ¿äÃ»			*/
var RTYPE_CHK_ENTER			= 5002;		/**< 5002:ÁøÀÔ¿äÃ»				*/
var RTYPE_ALIVE_NOTICE		= 5003;		/**< 5003:Alive Notice 			*/
var RTYPE_SET_COMPLETE		= 5004;		/**< 5004:¿Ï·á ¿äÃ»				*/
var RTYPE_GET_TID_CHK_ENTER	= 5101;		/**< 5101:ID¿äÃ» + ÁøÀÔ¿äÃ»		*/
var RTYPE_INIT				= 5105;		/**< 5106:ÃÊ±âÈ­ ¿äÃ» 			*/
var RTYPE_STOP				= 5106;		/**< 5107:Á¤Áö ¿äÃ»				*/

/**
 * Return Codes constants
 */
var RET_NORMAL				= 200;		/**< 200:Á¤»ó					*/
var RET_CONTINUE			= 201;		/**< 201:°è¼Ó ÁøÇà				*/
var RET_E_SYSTEM			= 500;		/**< 500:½Ã½ºÅÛ ¿¡·¯ 			*/
var RET_E_SECURITY			= 501;		/**< 501:º¸¾È ¿¡·¯				*/
var RET_E_IO				= 502;		/**< 502:I/O ¿¡·¯				*/
var RET_E_CONN_TIMEOUT		= 503;		/**< 503:Á¢¼Ó ½Ã°£ ÃÊ°ú 		*/
var RET_E_ARUNNING			= 504;		/**< 504:ÀÌ¹Ì ½ÇÇàÁß			*/
var RET_E_NOINIT			= 505;		/**< 505:ÃÊ±âÈ­ µÇÁö ¾ÊÀ½		*/ 
var RET_E_INSERT			= 506;		/**< 506:ÀÔ·Â ½ÇÆÐ				*/
var RET_E_NOPERM			= 507;		/**< 507:±ÇÇÑÀÌ ¾øÀ½.			*/
var RET_E_KEY_EXPIRE		= 508;		/**< 508:Key À¯È¿½Ã°£ ÃÊ°ú		*/
var RET_E_PARAM				= 509;		/**< 505:¿Ã¹Ù¸£Áö ¾ÊÀº ÆÄ¶ó¸ÞÅÍ	*/ 
var RET_E_NOT_STARTED		= 510;		/**< 507:¼­ºñ½º°¡ ¾ÆÁ÷ ½ÃÀÛÀüÀÓ	*/ 
var RET_E_NO_ACTION			= 511;		/**< 508:»ç¿ëÀÚÀÇ ActionÀÌ ¾øÀ½ */ 

/**
 * Process Status Constants
 */
var PS_N_RUNNING			= 0;		/**< 0:½ÇÇàÁßÀÌÁö ¾ÊÀº »óÅÂ		*/
var PS_RUNNING				= 1;		/**< 1:½ÇÇàÁß »óÅÂ				*/
var PS_CONTINUE				= 2;		/**< 2:°è¼Ó ½ÇÇàÁß »óÅÂ			*/
var PS_TIMEOUT				= 3;		/**< 3:Á¢¼Ó Á¦ÇÑ½Ã°£ ÃÊ°ú 		*/
var PS_ERROR				= 99;		/**< 99:¿¡·¯ »óÅÂ				*/

/**
 * Busy Box Display Type
 */
var BUSY_BOX_TYPE			= 1;		/**< 0:Round Bar 1:ProgressBar	*/

/**
 * NetFunnel Name Space ÁöÁ¤
 */
var NetFunnel 		= new Object();

/**
 * Busy Box ´ë±âÀÎ¿ø ¹× ½Ã°£ ¹®±¸ Ç¥½Ã
 */
NetFunnel.showTimeLimit 	= 300;
NetFunnel.showCountLimit 	= 1000;

/**
 * Easy interface¸¦ À§ÇÑ Global °´Ã¼
 */
NetFunnel.gControl 	= null;


/**
 * Busy Alert Box 
 */
NetFunnel.BusyBoxObj = new Object();
NetFunnel.BusyBoxCnt = 0;
NetFunnel.BusyBox = function(oID,oConfig){
    this._cells = new Object();
    this._config = new Object();
    // target Object
    if(typeof oID == "string"){
        this._obj = document.getElementById(oID);
    }else{
        this._obj = oID;
    }

    this._id = NetFunnel.BusyBoxCnt;
    NetFunnel.BusyBoxObj[this._id] = this;
    NetFunnel.BusyBoxCnt++;

    // Config 
    this._config["width"]       = 300;
    this._config["height"]      = 5;
    this._config["count"]       = 20;
    this._config["interval"]    = 50;
    this._config["colors"]		= this._colors;
    this._config["bgcolor"]		= "#FFFFFF";
    if(typeof oConfig == "object"){
        for(var i in oConfig){
            this._config[i] = oConfig[i];
        }
    }
    if(this._config["count"] <= 0){
        this._config["count"]   = 20;
    }

    // Make Display
    this._oTable    = document.createElement("table");
    this._oTable.style.width = this._config["width"]+"px";
    this._oTable.cellPadding = 0;
    this._oTable.cellSpacing = 0;
    //this._oTable.style.border = "1px solid #CDCDCD";

    tTbody  = document.createElement("tbody");
    tRow    = document.createElement("tr");

    for(var i = 0 ; i < this._config["count"] ; i++){
        tCell = document.createElement("td");
        tCell.style.height  = this._config["height"]+"px";
        tCell.style.backgroundColor  = this._config["bgcolor"];
        tCell.id = this._id;
        this._cells[i] = tCell;
        tRow.appendChild(tCell);
    }
    tTbody.appendChild(tRow);
    this._oTable.appendChild(tTbody);
    this._obj.appendChild(this._oTable);

    this.show = function(){
        this._obj.style.visibility = "visible";
        this._timer = setInterval("NetFunnel.BusyBox._action("+this._id+")",this._config["interval"]);
        return;
    };

    this.hide = function(){
        this._obj.style.visibility = "hidden";
        if(this._timer){
            clearInterval(this._timer);
            this._timer = null;
        }
        return;
    };


    this._action = function(id){
        if(this != NetFunnel.BusyBoxObj[id]){
            return this._action.apply(NetFunnel.BusyBoxObj[id],arguments);
        }

		colors_len = this._config["colors"].length;
        if(this._direct == 0){
			j=0
			for(i=(colors_len-1) ; i >= 0 ; i--){
            	tVal = Math.abs(this._curr - i);
            	this._cells[tVal].style.backgroundColor = this._config["colors"][j++];
			}
            this._curr++;
            if(this._curr == this._config["count"]){
                this._direct = 1;
                this._curr = this._config["count"] - 1;
            }
        }else{
			j=0
			for(i=(colors_len-1) ; i >= 0 ; i--){
				if(i>0){
					tVal = ((this._curr+i)>=this._config["count"])?this._config["count"]*2 -1 - (this._curr + i):(this._curr + i);
					if(tVal > 0) this._cells[tVal].style.backgroundColor = this._config["colors"][j++];
				}else{
					this._cells[this._curr].style.backgroundColor = this._config["colors"][j++];
				}
			}
            this._curr--;
            if(this._curr < 0 ){
                this._direct = 0;
                this._curr = 1;
            }
        }
        return true;
    }
}

NetFunnel.ProgressBar = function(oID,oConfig){
    this._cells = new Object();
    this._config = new Object();
    // target Object
    if(typeof oID == "string"){
        this._obj = document.getElementById(oID);
    }else{
        this._obj = oID;
    }

    this._id = NetFunnel.BusyBoxCnt;
    NetFunnel.BusyBoxObj[this._id] = this;
    NetFunnel.BusyBoxCnt++;

    // Config 
    this._config["width"]       = 360;
    this._config["height"]      = 5;
    this._config["count"]       = 50;
    this._config["interval"]    = 50;
    this._config["colors"]		= this._colors;
    this._config["bgcolor"]		= "#FFFFFF";
    if(typeof oConfig == "object"){
        for(var i in oConfig){
            this._config[i] = oConfig[i];
        }
    }
    if(this._config["count"] <= 0){
        this._config["count"] = 50;
    }

    // Make Display
    this._oTable    = document.createElement("table");
    this._oTable.style.width = this._config["width"]+"px";
    
    tTbody  = document.createElement("tbody");
    tRow    = document.createElement("tr");

    for(var i = 0 ; i < this._config["count"] ; i++){
        tCell = document.createElement("td");
        tCell.style.height  = this._config["height"]+"px";
        tCell.style.backgroundColor  = this._config["bgcolor"];
        tCell.id = this._id;
        this._cells[i] = tCell;
        tRow.appendChild(tCell);
    }
    tTbody.appendChild(tRow);
    this._oTable.appendChild(tTbody);
    this._obj.appendChild(this._oTable);

    this.show = function(){
        this._obj.style.visibility = "visible";
        this._timer = setInterval("NetFunnel.ProgressBar._action("+this._id+")",this._config["interval"]);
        return;
    };

    this.hide = function(){
        this._obj.style.visibility = "hidden";
        if(this._timer){
            clearInterval(this._timer);
            this._timer = null;
        }
        return;
    };

		// ÃÖÃÊ »ý¼º½Ã ´ë±âÀÚ ¼ö
		var gWaitingCount = 0;
		// ÃÊ±â »ý¼º ±¸ºÐ ÇÃ·¡±×
		var wFlag = 0;

    this._action = function(id){
		// ´ë±âÀÚ ¼ö¸¦ ±¸ÇÑ´Ù.
		var waitingCount = NetFunnel.gLastData.nwait;

		if( wFlag == 0 ){
			// ÃÊ±â POPUP»ý¼º½Ã ´ë±âÀÚ¼ö¸¦ ±Û·Î¹ú º¯¼ö¿¡ ÀúÀå
			gWaitingCount = waitingCount;
			// ÃÊ±â POPUP »ý¼º ¿©ºÎ¸¦ ÆÇ´ÜÇÏ´Â ÇÃ·¡±×
			wFlag = 1;
		}

		if(this != NetFunnel.BusyBoxObj[id]){
			return this._action.apply(NetFunnel.BusyBoxObj[id],arguments);
		}

		colors_len = this._config["colors"].length;
		// Style Sheet¿¡¼­ td, th paddingÀ» Á¤ÀÇÇÒ °æ¿ì ÀÌ»ó µ¿ÀÛÇÏ´Â Çö»ó¿¡ ´ëÀÀ
        this._oTable.cellPadding = 0;
        this._oTable.cellSpacing = 0;		
        this._oTable.style.width = this._config["width"]+"px";

		// ÁøÇà »óÅÂ¹Ù¸¦ Ç¥ÇöÇÏ±â À§ÇÑ µ¥ÀÌÅÍ º¯È¯( ´ë±âÀÚ ¼ö ¹éºÐÀ² È¯»ê )
		currWaiting = 100 - Math.round((NetFunnel.gLastData.nwait / gWaitingCount)*100);
		

		// ÀÜ»ó Á¦°Å 
		for( i = 0; i < 50; i ++ )	{
			this._cells[i].style.backgroundColor = "#57A9E1";
		}

        rangeBar = currWaiting/2;
        
		// ÇöÀç ´ë±âÀÚ ¸¸Å­ ÁøÇà »óÅÂ¹ÙÀÇ »öÀ» Ã¤¿ò
		for( i = 0; i < rangeBar; i ++ ){
			this._cells[i].style.backgroundColor = this._config["colors"][0];
		}

		this._curr++;

		if(this._curr >= this._config["count"]) {
			this._direct = 100;
		}
		return true;
    }
    
}

NetFunnel.BusyBox.prototype._mmm    = 0;
NetFunnel.BusyBox.prototype._id     = 0;
NetFunnel.BusyBox.prototype._curr   = 0;
NetFunnel.BusyBox.prototype._direct = 0;
NetFunnel.BusyBox.prototype._obj    = null;
NetFunnel.BusyBox.prototype._cells  = null;
NetFunnel.BusyBox.prototype._timer  = null;
NetFunnel.BusyBox.prototype._oTable = null;
NetFunnel.BusyBox.prototype._config = null;
NetFunnel.BusyBox.prototype._colors = ['',"#FFFFFF","#DDDDDD","#BBBBBB","#999999","#777777","#444444"];


NetFunnel.BusyBox._action = function(id){
    NetFunnel.BusyBoxObj[id]._action(id);
}

NetFunnel.ProgressBar._action = function(id){
    NetFunnel.BusyBoxObj[id]._action(id);
}

/**
 * Cookie °ü¸®
 */
NetFunnel.Cookie = {
	set: function(key,value,minutes,domain) {
		var tStr=key+ "=" +escape(value);

		if(typeof minutes != "undefined"  && (minutes.constructor == Number) && minutes > 0 ) {
			var expire=new Date();
			expire.setMinutes(expire.getMinutes() + minutes);	
			tStr += ";expires="+expire.toGMTString();
		}
		if(typeof domain != "undefined"  && domain.constructor == String && domain != "" ) {
			tStr += ";domain="+domain;
		}else if(TS_COOKIE_DOMAIN != ""){
			tStr += ";domain="+TS_COOKIE_DOMAIN;
		}
		tStr +=";path=/;";
		document.cookie=tStr;
	},

	del: function(key) {
		NetFunnel.Cookie.set(key,"",-1);
	},

	get: function(key){
		if (document.cookie.length>0) {
			c_start=document.cookie.indexOf(key + "=");
			if (c_start!=-1)
			{ 
				c_start=c_start + key.length+1; 
				c_end=document.cookie.indexOf(";",c_start);
				if (c_end==-1) c_end=document.cookie.length;
				return unescape(document.cookie.substring(c_start,c_end));
			} 
		}
		return "";
	}
};

/**
 * Detect Browser
 */
NetFunnel.BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ string: navigator.userAgent, subString: "Chrome", identity: "Chrome" },
		{ string: navigator.userAgent, subString: "OmniWeb", versionSearch: "OmniWeb/", identity: "OmniWeb" },
		{ string: navigator.vendor, subString: "Apple", identity: "Safari" },
		{ prop: window.opera, identity: "Opera" },
		{ string: navigator.vendor, subString: "iCab", identity: "iCab" },
		{ string: navigator.vendor, subString: "KDE", identity: "Konqueror" },
		{ string: navigator.userAgent, subString: "Firefox", identity: "Firefox" },
		{ string: navigator.vendor, subString: "Camino", identity: "Camino" },
		// for newer Netscapes (6+)
		{ string: navigator.userAgent, subString: "Netscape", identity: "Netscape" },
		{ string: navigator.userAgent, subString: "MSIE", identity: "Explorer", versionSearch: "MSIE" },
		{ string: navigator.userAgent, subString: "Gecko", identity: "Mozilla", versionSearch: "rv" },
		// for older Netscapes (4-)
		{ string: navigator.userAgent, subString: "Mozilla", identity: "Netscape", versionSearch: "Mozilla" }
	],
	dataOS : [
		{ string: navigator.platform, subString: "Win", identity: "Windows" },
		{ string: navigator.platform, subString: "Mac", identity: "Mac" },
		{ string: navigator.platform, subString: "Linux", identity: "Linux" }
	]
};
NetFunnel.BrowserDetect.init();

/**
 * ÇöÀçÀÇ MouseÀÇ À§Ä¡¸¦ ¹Þ¾Æ¿Í¼­ ÀúÀå ÇÑ´Ù.
 *
 * @memberOf NetFunnel
 * @param {Object} e Event Object
 * @return {Boolean} ½ÇÇà ¼º°ø ¿©ºÎ
 */
NetFunnel.getMouseXY = function(e) {
	if ( NetFunnel.BrowserDetect.browser == "Explorer") {
		tempX = event.clientX + document.body.scrollLeft
		tempY = event.clientY + document.body.scrollTop
	}else{
		tempX = e.pageX
		tempY = e.pageY
	}

	// catch possible negative values in NS4
	if (tempX < 0){tempX = 0}
	if (tempY < 0){tempY = 0}  

	// show the position values in the form named Show
	// in the text fields named MouseX and MouseY
	NetFunnel.MouseX = tempX
	NetFunnel.MouseY = tempY

	return true
}
//if ( NetFunnel.BrowserDetect.browser != "Explorer") document.captureEvents(Event.MOUSEMOVE);
//document.onmousemove = NetFunnel.getMouseXY;


/**
 * Default Callback Function
 */
NetFunnel.gPop = null;
NetFunnel.gTimer = null;
NetFunnel.gLastData = null;
NetFunnel.countdown_stop = function()
{
	NetFunnel_sendStop();
	if(NetFunnel.gPop) { 
		NetFunnel.gPop.hide();
		NetFunnel.gPop.destroy();
		delete NetFunnel.gPop;
		NetFunnel.gPop = null;
	}
}
/*
NetFunnel.countdown = function()
{
    if(NetFunnel.gLastData && NetFunnel.gLastData.time_left >= 0){
        // ´ë±â Á¤º¸¸¦ Ãâ·ÂÇÑ´Ù.
		var tTime = document.getElementById("NetFunnel_Loading_Popup_TimeLeft");
        var tCount = document.getElementById("NetFunnel_Loading_Popup_Count");

		tCount.innerHTML=NetFunnel.gLastData.nwait;
		tTime.innerHTML=NetFunnel.gLastData.real_time_left;
    }

	if(NetFunnel.gLastData.time_left <=0 && NetFunnel.gTimer){
		clearInterval(NetFunnel.gTimer)
		if(NetFunnel.gPop) { 
			//NetFunnel.gPop.hide();
		}
		return;
	}
	NetFunnel.gLastData.time_left--;
	NetFunnel.gLastData.real_time_left--;
}
*/
NetFunnel.countdown = function()
{
    if(NetFunnel.gLastData && NetFunnel.gLastData.time_left >= 0){
        // ´ë±â Á¤º¸¸¦ Ãâ·ÂÇÑ´Ù.
		var tTime = document.getElementById("NetFunnel_Loading_Popup_TimeLeft");
        var tCount = document.getElementById("NetFunnel_Loading_Popup_Count");

		//tCount.innerHTML=NetFunnel.gLastData.nwait;
		//tTime.innerHTML=NetFunnel.gLastData.real_time_left;
		
		if(NetFunnel.gLastData.nwait > NetFunnel.showCountLimit || NetFunnel.gLastData.real_time_left > NetFunnel.showTimeLimit ){
//				tCount.innerHTML="´Ù¼öÀÇ&nbsp;";
				tCount.innerHTML="´Ù¼öÀÇ&nbsp;";

//				if(tTime.innerHTML == "....."){
				if(tTime.innerHTML.length >= 5){
					tTime.innerHTML= ".";
				}else{
					tTime.innerHTML+=".";
				}

			}else{
				tCount.innerHTML=String(NetFunnel.gLastData.nwait)+"¸íÀÇ&nbsp;";
				tTime.innerHTML="&nbsp;" + NetFunnel.gLastData.real_time_left+"sec";
			}
    }

	if(NetFunnel.gLastData.time_left <=0 && NetFunnel.gTimer){
		clearInterval(NetFunnel.gTimer)
		if(NetFunnel.gPop) { 
			//NetFunnel.gPop.hide();
		}
		return;
	}
	NetFunnel.gLastData.time_left--;
	NetFunnel.gLastData.real_time_left--;
}

NetFunnel.DefaultCallback = {
	"onSuccess": function(ev,ret){
		if(NetFunnel.gTimer){
			clearInterval(NetFunnel.gTimer);
		}
		if(NetFunnel.gPop){
			NetFunnel.gPop.hide();
			NetFunnel.gPop.destroy();
			delete NetFunnel.gPop;
			NetFunnel.gPop = null;
		}
		if(typeof ret.next == "string"){
			if(NetFunnel._oTargetFrame != null){
				NetFunnel._oTargetFrame.location.href=ret.next;
			}else{
				document.location.href=ret.next;
			}
		}else if(typeof ret.next == "function"){
			ret.next(ev,ret);
		}
	},
	"onContinued": function(ev,ret) {

		if(typeof ret.next == "string"){
			if(NetFunnel._oTargetFrame != null){
				NetFunnel._oTargetFrame.location.href=ret.next;
			}else{
				document.location.href=ret.next;
			}
			return;
		}else if(typeof ret.next == "function"){
			ret.next(ev,ret);
			return;
		}

		if(ret.rtype == RTYPE_CHK_ENTER || ret.rtype == RTYPE_GET_TID_CHK_ENTER){
			if(NetFunnel.gTimer){
				clearInterval(NetFunnel.gTimer);
			}

			if(NetFunnel.gPop){
				NetFunnel.gPop.destroy();
				delete NetFunnel.gPop;
				NetFunnel.gPop = null;
			}

			height=181;
			top_height=85;
			width=400;

			var lp = document.getElementById("NetFunnel_Loading_Popup");
			if(!lp){
				lp = document.createElement('div');
				lp.id = "NetFunnel_Loading_Popup";
				lp.style.border="3px solid #185887";
				lp.style.backgroundColor="#EDEDEE";
				lp.style.textAlign="center";

				lp_top = document.createElement('div');
				lp_top.id = "NetFunnel_Loading_Popup_Top";
				lp_top.style.backgroundColor="white";
				lp_top.style.height=top_height;
				lp_top.align="center";
				lp_top.style.paddingTop="3px";
				lp_top.style.paddingLeft="5px";
				lp_top.style.paddingRight="5px";
				lp.appendChild(lp_top);

				lp_bottom = document.createElement('div');
				lp_bottom.id = "NetFunnel_Loading_Popup_Bottom";
				lp_bottom.style.height=(height-top_height)
				lp_bottom.align="center";
				lp_bottom.style.paddingBottom="3px";
				lp_bottom.style.paddingLeft="5px";
				lp_bottom.style.paddingRight="5px";
				lp.appendChild(lp_bottom);

				lp_ct_top = document.createElement('div');
				lp_ct_top.id = "NetFunnel_Loading_Popup_CT_Top";
				lp_ct_top.style.textAlign="right";
				lp_ct_top.style.font="bold 8px Trebuchet MS,±¼¸²,Gulim,AppleGothic,sans-serif";
				lp_ct_top.innerHTML="<a href='http://www.aimtog.co.kr/net/net_01.asp' target=_blank style='text-decoration:none'><span style='color:#52cb4b'>Net</span><span style='color:337a99'>FUNNEL</span></a>";
				lp_top.appendChild(lp_ct_top);

				lp_ct_wait = document.createElement('div');
				lp_ct_wait.id = "NetFunnel_Loading_Popup_CT_Wait";
				lp_ct_wait.style.textAlign="center";
				lp_ct_wait.style.font="bold 14px ±¼¸²,Gulim,AppleGothic,sans-serif";
				lp_ct_wait.style.paddingTop="3px";
				lp_ct_wait.style.color="#185887";
				lp_ct_wait.innerHTML="Please Wait...";
				lp_top.appendChild(lp_ct_wait);

				lp_ct_sec = document.createElement('div');
				lp_ct_sec.id = "NetFunnel_Loading_Popup_CT_Sec";
				lp_ct_sec.style.textAlign="right";
				lp_ct_sec.style.font="bold 12px ±¼¸²,Gulim,AppleGothic,sans-serif";
				lp_ct_sec.style.color="#676767";
				lp_ct_sec.innerHTML="<span id='NetFunnel_Loading_Popup_TimeLeft'></span>";
				lp_ct_sec.style.width=width*9/10;
				lp_ct_sec.style.paddingBottom="2px";
				lp_top.appendChild(lp_ct_sec);

				lp_ct_busy_top = document.createElement('div');
				lp_ct_busy_top.id = "NetFunnel_Loading_Popup_CT_Busy";
				lp_ct_busy_top.style.textAlign="center";
				lp_ct_busy_top.style.font="bold 12px ±¼¸²,Gulim,AppleGothic,sans-serif";
				lp_ct_busy_top.style.width=width*9/10;
				lp_ct_busy_top.style.padding="2px";
				lp_ct_busy_top.style.backgroundColor="#57A9E1";
				lp_top.appendChild(lp_ct_busy_top);

				lp_ct_busy = document.createElement('div');
				lp_ct_busy.id = "NetFunnel_Loading_Popup_CT_Busy";
				lp_ct_busy.style.textAlign="center";
				lp_ct_busy.style.width=width*9/10;
				lp_ct_busy_top.appendChild(lp_ct_busy);

				switch (BUSY_BOX_TYPE)
				{
				case 1:
					busybox = new NetFunnel.ProgressBar(lp_ct_busy,{ width:(width*9/10), count:50, bgcolor:"", colors:[ "#FFFF99", ], interval:50 });
					break;
				default :
					busybox = new NetFunnel.BusyBox(lp_ct_busy,{ width:(width*9/10), count:30, bgcolor:"", colors:[ "", "#57A9E1", "#73bbed", "#8dc9f3", "#a7d5f6", "#c3e2f8", "#dceefb", "#f2f7fb", "#FFFFFF", ], interval:50 });
					break;
				}
				busybox.show();

				lp_ct_msg1 = document.createElement('div');
				lp_ct_msg1.id = "NetFunnel_Loading_Popup_CT_Msg1";
				lp_ct_msg1.style.textAlign="center";
				lp_ct_msg1.style.font="normal 12px ±¼¸²,Gulim,AppleGothic,sans-serif";
				lp_ct_msg1.style.color="#676767";
				lp_ct_msg1.style.paddingTop="7px";
				lp_ct_msg1.style.width=width*9/10;
				lp_ct_msg1.innerHTML="°í°´´Ô ¾Õ¿¡ <b><span id='NetFunnel_Loading_Popup_Count'></span></b>´ë±âÀÚ°¡ ÀÖ½À´Ï´Ù.";
				lp_top.appendChild(lp_ct_msg1);

				lp_ct_bar = document.createElement('div');
				lp_ct_bar.id = "NetFunnel_Loading_Popup_CT_Bar";
				lp_ct_bar.style.backgroundColor="#2B70A2";
				lp_ct_bar.style.height="1px";
				lp_ct_bar.innerHTML="&nbsp;";
				lp_ct_bar.style.fontSize=0;
				lp_ct_bar.style.lineHeight=0;
				lp_ct_bar.style.overflow="hidden";
				lp_bottom.appendChild(lp_ct_bar);

				lp_ct_msg2 = document.createElement('div');
				lp_ct_msg2.id = "NetFunnel_Loading_Popup_CT_Msg2";
				lp_ct_msg2.style.textAlign="center";
				lp_ct_msg2.style.font="normal 12px ±¼¸²,Gulim,AppleGothic,sans-serif";
				lp_ct_msg2.style.color="#5378A2";
				lp_ct_msg2.innerHTML="ÇöÀç Á¢¼Ó·®ÀÌ ¸¹¾Æ ´ë±â ÁßÀÌ¸ç, Àá½Ã¸¸ ±â´Ù¸®½Ã¸é";
				lp_ct_msg2.style.paddingTop="11px";
				lp_ct_msg2.style.width=width*9/10;
				lp_bottom.appendChild(lp_ct_msg2);

				lp_ct_msg3 = document.createElement('div');
				lp_ct_msg3.id = "NetFunnel_Loading_Popup_CT_Msg3";
				lp_ct_msg3.style.textAlign="center";
				lp_ct_msg3.style.font="normal 12px ±¼¸²,Gulim,AppleGothic,sans-serif";
				lp_ct_msg3.style.color="#5378A2";
				lp_ct_msg3.innerHTML="ÀÚµ¿À¸·Î ÇØ´çÆäÀÌÁö·Î ÀÌµ¿ÇÕ´Ï´Ù.";
				lp_ct_msg3.style.paddingTop="7px";
				lp_ct_msg3.style.paddingBottom="13px";
				lp_ct_msg3.style.width=width*9/10;
				lp_bottom.appendChild(lp_ct_msg3);

				lp_ct_msg4 = document.createElement('div');
				lp_ct_msg4.id = "NetFunnel_Loading_Popup_CT_Msg4";
				lp_ct_msg4.style.padding="5px";
				lp_ct_msg4.style.backgroundColor="#185887";
				lp_ct_msg4.style.textAlign="center";
				lp_ct_msg4.style.color="white";
				lp_ct_msg4.style.width=width*9/10;
				lp_ct_msg4.style.font="normal 12px ±¼¸²,Gulim,AppleGothic,sans-serif";
				lp_ct_msg4.innerHTML="¡Ø Reload ÇÏ½Ã¸é ´ë±â½Ã°£ÀÌ ´õ ±æ¾îÁý´Ï´Ù. <span onclick='NetFunnel.countdown_stop()' style='cursor:pointer'>[ÁßÁö]</span>";
				lp_ct_msg4.style.paddingTop="4px";
				lp_bottom.appendChild(lp_ct_msg4);

				var theBody = document.getElementsByTagName('BODY')[0];
				theBody.appendChild(lp);
			}

			NetFunnel.gPop = new NetFunnel.Popup("NetFunnel_Loading_Popup",width,height,TS_POPUP_TOP,TS_POPUP_LEFT);

			delete NetFunnel.gLastData;
			NetFunnel.gLastData = ret.data;
			NetFunnel.gLastData.time_left     = parseInt(ret.data.ttl);
			NetFunnel.gLastData.tps = parseInt(ret.data.tps);
			if(NetFunnel.gLastData.tps == 0) NetFunnel.gLastData.tps = 1;
			NetFunnel.gLastData.real_time_left     = Math.round(parseInt(ret.data.nwait)/NetFunnel.gLastData.tps);
			if(NetFunnel.gLastData.real_time_left < 3){
				NetFunnel.gLastData.real_time_left = 3;
			}

			var tTime = document.getElementById("NetFunnel_Loading_Popup_TimeLeft");
			var tCount = document.getElementById("NetFunnel_Loading_Popup_Count");

			if(NetFunnel.gLastData.nwait > NetFunnel.showCountLimit || NetFunnel.gLastData.real_time_left > NetFunnel.showTimeLimit ){
				tCount.innerHTML="´Ù¼öÀÇ&nbsp;";
//				if(tTime.innerHTML == "....."){
				if(tTime.innerHTML.length >= 5){
					tTime.innerHTML=".";
				}else{
					tTime.innerHTML+=".";
				}
			}else{
				tCount.innerHTML=String(NetFunnel.gLastData.nwait)+"¸íÀÇ&nbsp;";
				tTime.innerHTML="&nbsp;" + NetFunnel.gLastData.real_time_left+"sec";
			}

			NetFunnel.gTimer = setInterval("NetFunnel.countdown()",1000);
			NetFunnel.gPop.show();

		}
	},
	"onError":function(ev,ret) {
		if(typeof ret.next == "string"){
			if(NetFunnel._oTargetFrame != null){
				NetFunnel._oTargetFrame.location.href=ret.next;
			}else{
				document.location.href=ret.next;
			}
			return;
		}else if(typeof ret.next == "function"){
			ret.next(ev,ret);
			return;
		}
	}
};

/**
 * Event Class ÀÇ »ý¼ºÀÚ
 *
 * @classDescription	»õ·Î¿î EventÅ¬·¡½º¸¦ »ý¼ºÇÑ´Ù.
 * @return {Object}	»õ·Î»ý¼ºµÈ Event°´Ã¼ 
 * @constructor
 */
NetFunnel.Event = function()
{
	this.events = [];
	this.builtinEvts = [];
}

/**
 * ÇØ´ç Element¿¡ ´ëÇÑ ÁÖ¾îÁø ActionÀÇ ¹øÈ£¸¦ ¾ò¾î¿Â´Ù.
 *
 * @memberOf NetFunnel.Event
 * @param {Object} obj action ÀÌ ¿¬°áµÈ element
 * @param {String} evt ÀÌº¥Æ® ÀÌ¸§ 
 * @param {Function} action ÀÌº¥Æ®°¡ ¹ß»ýÇßÀ»¶§ ½ÇÇàµÈ action
 * @param {Object} binding The object to scope the action to.
 * @return {Number} Á¤¼ö°ª
 */
NetFunnel.Event.prototype.getActionIdx = function(obj,evt,action,binding)
{
	if(obj && evt)
	{

		var curel = this.events[obj][evt];
		if(curel)
		{
			var len = curel.length;
			for(var i = len-1;i >= 0;i--)
			{
				if(curel[i].action == action && curel[i].binding == binding)
				{
					return i;
				}
			}
		}
		else
		{
			return -1;
		}
	}
	return -1;
};

/**
 * Listener Ãß°¡
 *
 * @memberOf NetFunnel.Event
 * @param {Object} obj action ÀÌ ¿¬°áµÈ element
 * @param {String} evt ÀÌº¥Æ® ÀÌ¸§ 
 * @param {Function} action ÀÌº¥Æ®°¡ ¹ß»ýÇßÀ»¶§ ½ÇÇàµÈ action
 * @param {Object} binding The object to scope the action to.
 * @return {null} ¾øÀ½.
 */
NetFunnel.Event.prototype.addListener = function(obj,evt,action,binding)
{
	if(this.events[obj])
	{
		if(this.events[obj][evt])
		{
			if(this.getActionIdx(obj,evt,action,binding) == -1)
			{
				var curevt = this.events[obj][evt];
				curevt[curevt.length] = {action:action,binding:binding};
			}
		}
		else
		{
			this.events[obj][evt] = [];
			this.events[obj][evt][0] = {action:action,binding:binding};
		}
	}
	else
	{
		this.events[obj] = [];
		this.events[obj][evt] = [];
		this.events[obj][evt][0] = {action:action,binding:binding};
	}
};

/**
 * Listener Á¦°Å
 *
 * @memberOf NetFunnel.Event
 * @param {Object} obj action ÀÌ ¿¬°áµÈ element
 * @param {String} evt ÀÌº¥Æ® ÀÌ¸§ 
 * @param {Function} action ÀÌº¥Æ®°¡ ¹ß»ýÇßÀ»¶§ ½ÇÇàµÈ action
 * @param {Object} binding The object to scope the action to.
 * @return {null} ¾øÀ½
 */
NetFunnel.Event.prototype.removeListener = function(obj,evt,action,binding)
{
	if(this.events[obj])
	{
		if(this.events[obj][evt])
		{
			var idx = this.actionExists(obj,evt,action,binding);
			if(idx >= 0)
			{
				this.events[obj][evt].splice(idx,1);
			}
		}
	}
};

/**
 * ÀÌº¥Æ® ¹ß»ý
 *
 * @memberOf NetFunnel.Event
 * @param e [(event)] ³»Àå ÀÌº¥Æ®°´Ã¼ Àü´Þ
 * @param {Object} obj action ÀÌ ¿¬°áµÈ element
 * @param {String} evt ÀÌº¥Æ® ÀÌ¸§ 
 * @param {Object} args ÀÌº¥Æ®¿¡ Àü´ÞµÈ ÀÎÀÚ
 * @return {null} ¾øÀ½.
 */
NetFunnel.Event.prototype.fireEvent = function(e,obj,evt,args)
{
	if(!e){e = window.event;}

	if(obj && this.events)
	{
		var evtel = this.events[obj];
		if(evtel)
		{
			var curel = evtel[evt];
			if(curel)
			{
				for(var act = 0; curel.length > act; act ++)
				{
					var action = curel[act].action;
					if(curel[act].binding)
					{
						action = action.bind(curel[act].binding);
					}
					action(e,args);
				}
			}
		}
	}
};


NetFunnel.gPopup = new Array();
NetFunnel.PopupUtil = {
	getViewportHeight:function () {
		if (window.innerHeight!=window.undefined) return window.innerHeight;
		if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;                        
		if (document.body) return document.body.clientHeight                                                       
		return window.undefined;                                                                                    
	},
	 getViewportWidth:function() {                                                                                   
		var offset = 17;
		var width = null;
		if (window.innerWidth!=window.undefined) return window.innerWidth; 
		if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth;                         
		if (document.body) return document.body.clientWidth;                                                        
	},                                                                                                               
	getScrollTop:function() { 
		if (self.pageYOffset) {   
			return self.pageYOffset;                                                                                
		} else if (document.documentElement && document.documentElement.scrollTop){   
			return document.documentElement.scrollTop;                                                              
		} else if (document.body) {   
			return document.body.scrollTop;                                                                         
		}                                                                                                           
	},
	getScrollLeft:function() {
		if (self.pageXOffset) {   
			return self.pageXOffset;                                                                                
		} else if (document.documentElement && document.documentElement.scrollLeft){   
			return document.documentElement.scrollLeft;                                                             
		} else if (document.body) {   
			return document.body.scrollLeft;                                                                        
		}                                                                                                           
	},
	resizePopup:function(){
		for(var i = 0; NetFunnel.gPopup.length > i; i++){
			NetFunnel.gPopup[i]._centerPopWin();
		}
	}
}



/**
 * Modal Popup Window
 */
NetFunnel.Popup = function (id,width,height,top,left) {
	var theBody = document.getElementsByTagName('BODY')[0];
	var popmask = document.getElementById('mpopup_bg');
	var popiframe = document.getElementById('pop_iframe');
	
	if(!popmask){
		popmask = document.createElement('div');
		popmask.id = 'mpopup_bg';
		popmask.innerHTML="<table width='100%' height='100%'><tr><td>&nbsp;</td></tr></table>";

		popmask.style.position="absolute";
		popmask.style.zIndex="1200";
		popmask.style.top="0px";
		popmask.style.left="0px";
		popmask.style.width="100%";
		popmask.style.height="100%";
	
		theBody.appendChild(popmask);
	}
	
	if(!popiframe){
		//IE 6.0 Select Ã³¸®
		popiframe = document.createElement('iframe');
		popiframe.id = 'pop_iframe';
		popiframe.scrolling = "no";
		popiframe.frameborder="0";
		popiframe.border="0";
		popiframe.framespacing="0";
		popiframe.marginheight="0";
		popiframe.marginwidth="0";
		
		popiframe.style.filter="alpha(opacity=50)";
		popiframe.style.zIndex="1199";
		popiframe.style.top="0px";
		popiframe.style.left="0px";
		popiframe.style.width="100%";
		//popiframe.style.height="100%";
		theBody = document.getElementsByTagName('BODY')[0];
		popiframe.style.height=theBody.scrollHeight;
		popiframe.style.position="absolute";
		popiframe.style.border="0px solid #FFFFFF";
		
		theBody.appendChild(popiframe);
	} 
	
	var tObj = document.getElementById(id);
	tObj.style.position 	= "absolute";
	tObj.style.visibility 	= "hidden";
	tObj.style.display 		= "none";
	tObj.style.width 		= width;
	tObj.style.height 		= height;

	this._mCount++;	
	this._mMask = popmask;
	this._mPopIFrame = popiframe;
	this._mObj 	= tObj;

	this._mWidth 	= width;
	this._mHeight 	= height;
	this._mTop		= top;
	this._mLeft		= left;
	this.mid		= "mpopup_"+this._mCount;

	//addEvent(window, "resize", NetFunnel.PopupUtil.resizePopup);
    this.addListener(window,"resize",NetFunnel.PopupUtil.resizePopup); 
	NetFunnel.gPopup.push(this);
}

NetFunnel.Popup.prototype           = new NetFunnel.Event(); 
NetFunnel.Popup.prototype._mCount 	= 0;
NetFunnel.Popup.prototype._mid 		= "";
NetFunnel.Popup.prototype._mObj		= null;
NetFunnel.Popup.prototype._mMask	= null;
NetFunnel.Popup.prototype._mPopIFrame    = null;
NetFunnel.Popup.prototype._mWidth	= 0;
NetFunnel.Popup.prototype._mHeight	= 0;
NetFunnel.Popup.prototype._mIsShown	= false;

NetFunnel.Popup.prototype._setMaskSize = function() {
    var theBody = document.getElementsByTagName("BODY")[0];                                     
            
    var fullHeight = NetFunnel.PopupUtil.getViewportHeight();
    var fullWidth = NetFunnel.PopupUtil.getViewportWidth();                                                         
    
    // Determine what's bigger, scrollHeight or fullHeight / width                              
    if (fullHeight > theBody.scrollHeight) {                                                    
        popHeight = fullHeight;                                                                 
    } else {
        popHeight = theBody.scrollHeight;                                                       
    }                                                                                           
    
    if (fullWidth > theBody.scrollWidth) {                                                      
        popWidth = fullWidth;                                                                   
    } else {
        popWidth = theBody.scrollWidth;                                                         
    }                                                                                           
    
    this._mMask.style.height 	= popHeight + "px";         
    this._mMask.style.width 	= popWidth + "px";                                                   
}  

NetFunnel.Popup.prototype._centerPopWin = function () {
	if (this._mIsShown){
        var theBody = document.getElementsByTagName("BODY")[0];

        //theBody.style.overflow = "hidden";
        var scTop = parseInt(NetFunnel.PopupUtil.getScrollTop(),10);
        var scLeft = parseInt(theBody.scrollLeft,10);

				this._setMaskSize();

        var fullHeight = NetFunnel.PopupUtil.getViewportHeight();
        var fullWidth = NetFunnel.PopupUtil.getViewportWidth();

      if( typeof this._mTop == "number" ){
    	    	this._mObj.style.top = this._mTop + "px";
			}else{
      	  	this._mObj.style.top = (scTop + ((fullHeight - this._mHeight) / 2)) + "px";
			}

			if( typeof this._mLeft == "number" ){
        	this._mObj.style.left = this._mLeft + "px";
			}else{
				this._mObj.style.left =  (scLeft + ((fullWidth - this._mWidth) / 2)) + "px";
			}
    }
}


NetFunnel.Popup.prototype.show = function(){
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "auto";
	this._mObj.style.zIndex 	= "1202";	
	this._mObj.style.visibility = "visible";
	this._mObj.style.display 	= "block";
	this._mMask.style.visiblity	= "visible";
	this._mMask.style.display	= "block";
	this._mPopIFrame.style.visiblity = "visible";
	this._mPopIFrame.style.display   = "block";
	this._mIsShown = true;
	this._centerPopWin();
}

NetFunnel.Popup.prototype.hide = function(){
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "auto";
	this._mObj.style.visibility	= "hidden";
	this._mObj.style.display	= "none";
	this._mMask.style.visiblity	= "hidden";
	this._mMask.style.display	= "none";
	this._mPopIFrame.style.visiblity = "hidden";
	this._mPopIFrame.style.display   = "none";
	this._mIsShown = false;
}

NetFunnel.Popup.prototype.destroy = function(){
	// remove event handler;
	//removeEvent(window,"resize",NetFunnel.PopupUtil.resizePopup);
    //this.removeListener(window,"resize",NetFunnel.PopupUtil.resizePopup); 
	//removeEvent(window,"scroll",NetFunnel.PopupUtil.resizePopup);

	// global list ¿¡¼­ »èÁ¦
	var tsize = NetFunnel.gPopup.length;
	for(var i = 0 ; i < tsize ; i++){
		var tObj = NetFunnel.gPopup.pop();
		if(tObj.mid == this.mid){
			delete tObj;
			continue;
		}
		NetFunnel.gPopup.push(tObj);	
	}
}

/**
 * RetVal Class ÀÇ »ý¼ºÀÚ.
 *
 * @classDescription NetFunnel¿¡¼­ ¹Þ¾Æ¿Â °á°ú°ªÀ» ParsingÇØ ÁØ´Ù.
 * @param {String} °á°ú ¹®ÀÚ¿­
 */
NetFunnel.RetVal = function(str)
{
	this._mParam	= new Object();
	this._mRtype 	= parseInt(str.substr(0,4));
	this._mCode 	= parseInt(str.substr(5,3));
	this._mRetStr	= str.substr(9,str.length - 9);

	this._parse();
}

//-----------------------------------------------------------------------------
// NetFunnel.RetVal private variable 
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// NetFunnel.RetVal public variable 
//-----------------------------------------------------------------------------


//-----------------------------------------------------------------------------
// NetFunnel.RetVal private member function
//-----------------------------------------------------------------------------
/**
 * left trim
 *
 * @memberOf NetFunnel.RetVal
 * @param {String} str Input String
 * @return {String} processed String
 */
NetFunnel.RetVal.prototype._ltrim = function(str) { 
	for(var k = 0; k < str.length && this._isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
/**
 * right trim
 *
 * @memberOf NetFunnel.RetVal
 * @param {String} str Input String
 * @return {String} processed String
 */
NetFunnel.RetVal.prototype._rtrim = function(str) {
	for(var j=str.length-1; j>=0 && this._isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}

/**
 * String trim
 *   - ¹®ÀÚ¿­ ¾ÕµÚÀÇ °ø¹é Á¦°Å
 *
 * @memberOf NetFunnel.RetVal
 * @param {String} str Input String
 * @return {String} processed String
 */
NetFunnel.RetVal.prototype._trim = function(str) {
	return this._ltrim(this._rtrim(str));
}

/**
 * °ø¹é¹®ÀÚ ¿©ºÎ ÆÇ´Ù.
 *    - °ø¹é¹®ÀÚ = " \t\n\r\f"
 *
 * @memberOf NetFunnel.RetVal
 * @param {String} charToCheck Å×½ºÆ® char
 * @return {Boolean} °ø¹é¿©ºÎ
 */
NetFunnel.RetVal.prototype._isWhitespace = function(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

/**
 * ÀÔ·ÂµÈ °á°ú°ªÀ» ÆÄ½ÌÇØ¼­ »ç¿ëÇÏ±â Æí¸®ÇÑ ÇüÅÂ·Î ÀúÀå ÇÑ´Ù.
 *
 * @memberOf NetFunnel.RetVal
 * @return {null} ¾øÀ½
 */
NetFunnel.RetVal.prototype._parse = function()
{
	var titem = this._mRetStr.split('&');
	for(var i = 0; titem.length > i; i++){
		temp=titem[i].split('=');

		if(temp.length > 1){
			key=this._trim(temp[0]);
			value=this._trim(temp[1]);

			this._mParam[key] = value;
		}
	}
}

//-----------------------------------------------------------------------------
// NetFunnel.RetVal public member function
//-----------------------------------------------------------------------------
/**
 * Return Code Àü´Þ
 *
 * @memberOf NetFunnel.RetVal
 * @return {Number} Return Code °ª
 */
NetFunnel.RetVal.prototype.getRetCode = function(){
	return this._mCode;
}
NetFunnel.RetVal.prototype.setRetCode = function(inCode){
	return (this._mCode = inCode);
}
/**
 * ¿äÃ» Å¸ÀÔ (Request Type) Àü´Þ
 *
 * @memberOf NetFunnel.RetVal
 * @return {Number} Request Type °ª
 */
NetFunnel.RetVal.prototype.getReqType = function(){
	return this._mRtype;
}
NetFunnel.RetVal.prototype.setReqType = function(inType){
	return (this._mRtype = inType);
}
/**
 * °á°ú ¹®ÀÚ¿­ Àü´Þ
 *
 * @memberOf NetFunnel.RetVal
 * @return {String} »ý¼º½Ã ÀÔ·ÂµÇ¾ú´ø °á°ú ¹®ÀÚ¿­
 */
NetFunnel.RetVal.prototype.getRetStr = function(){
	return this._mRetStr;
}

/**
 * °á°ú°ª ¿äÃ»
 *
 * @memberOf NetFunnel.RetVal
 * @param {String} key Ã£À¸·Á´Â °ªÀÇ key ¹®ÀÚ¿­
 * @return {String} key¿¡ ÇØ´çÇÏ´Â value ¹®ÀÚ¿­
 */
NetFunnel.RetVal.prototype.getValue = function(key){
	try{
		return this._mParam[key];
	}catch(e){
		return null;
	}
}

/**
 * °á°ú°ª ¼³Á¤
 *
 * @memberOf NetFunnel.RetVal
 * @param {String} key ¼³Á¤ÇÏ·Á´Â °ªÀÇ key ¹®ÀÚ¿­
 * @param {String} value ¼³Á¤ÇÏ·Á´Â °ªÀÇ value ¹®ÀÚ¿­
 * @return {String} ÀÌÀü Value °ª
 */
NetFunnel.RetVal.prototype.setValue = function(key,value){
	oldValue = null
	try{
		
		if ( this.isKeyExist(key) ){
			oldValue = this.getValue(key);
		}

		this._mParam[key] = value;
		return oldValue;
	}catch(e){
		return null;
	}
}


/**
 * ¼ýÀÚÇü °á°ú°ª ¿äÃ»
 *
 * @memberOf NetFunnel.RetVal
 * @param {String} key Ã£À¸·Á´Â °ªÀÇ key ¹®ÀÚ¿­
 * @return {Number} key¿¡ ÇØ´çÇÏ´Â value ¼ýÀÚ
 */
NetFunnel.RetVal.prototype.getNumber = function(key){
	try{
		return parseInt(this._mParam[key]);
	}catch(e){
		return 0;
	}
}

/**
 * key Á¸Àç ¿©ºÎ È®ÀÎ
 *
 * @memberOf NetFunnel.RetVal
 * @param {String} key Ã£À¸·Á´Â °ªÀÇ key ¹®ÀÚ¿­
 * @return {Boolean} keyÀÇ Á¸Àç¿©ºÎ
 */
NetFunnel.RetVal.prototype.isKeyExist = function(key){
	try{
		if(this._mParam[key] != null){
			return true;
		}
	}catch(e){
	}
	return false;
}

/**
 * ÀüÃ¼ Parameter Object ¿äÃ»
 *
 * @memberOf NetFunnel.RetVal
 * @return {Object} parameterµéÀÇ ÀúÀåµÈ Object
 */
NetFunnel.RetVal.prototype.getParam = function(){
	return this._mParam;
}



/**
 * TsClient Contructor
 *
 */
NetFunnel.TsClient = function(oConfigs,oCallbacks)
{
	this.mConfig 					= new Object();
	this.mConfig["host"] 			= TS_SERVER_HOST;
	this.mConfig["port"]			= TS_SERVER_PORT;
	this.mConfig["query"]			= TS_QUERY_STR;
	this.mConfig["max_ttl"]			= TS_MAX_TTL;
	this.mConfig["conn_timeout"]	= TS_CONN_TIMEOUT;
	this.mConfig["conn_retry"]		= TS_CONN_RETRY;
	this.mConfig["no_action"]		= TS_NO_ACTION;
	this.mConfig["cookie_id"]		= TS_COOKIE_ID;
	this.mConfig["cookie_time"]		= TS_COOKIE_TIME;
	this.mConfig["cookie_domain"]	= TS_COOKIE_DOMAIN;
	this.mConfig["popup_top"]		= TS_POPUP_TOP;
	this.mConfig["popup_left"]		= TS_POPUP_LEFT;
	
    // Validate configs
    //if(oConfigs && (oConfigs.constructor == Object)) {
        for(var sConfig in oConfigs) {
            this.mConfig[sConfig] = oConfigs[sConfig];
        }
    //}
   	TS_POPUP_TOP	= this.mConfig["popup_top"];
 		TS_POPUP_LEFT	= this.mConfig["popup_left"];

	this.id			= NetFunnel.TsClient._Count;
	//this.id			= "netfunnel_obj_"+NetFunnel.TsClient._Count;
	NetFunnel.TsClient._Objects[this.id] = this;
	NetFunnel.TsClient._Count = NetFunnel.TsClient._Count + 1;

	// Add Event Listener
	if(oCallbacks["onSuccess"])		{ this.addListener(this,"onSuccess",oCallbacks["onSuccess"]); }
	if(oCallbacks["onContinued"])	{ this.addListener(this,"onContinued",oCallbacks["onContinued"]); }
	if(oCallbacks["onError"])		{ this.addListener(this,"onError",oCallbacks["onError"]); }


	this.counter[RTYPE_NONE]			= 0;
	this.counter[RTYPE_GET_TID]			= 0;
	this.counter[RTYPE_CHK_ENTER]		= 0;
	this.counter[RTYPE_ALIVE_NOTICE]	= 0;
	this.counter[RTYPE_SET_COMPLETE]	= 0;
	this.counter[RTYPE_INIT]			= 0;
	this.counter[RTYPE_STOP]			= 0;


	this.connTimeout = function connTimeout(id)
	{
		if(this != NetFunnel.TsClient._Objects[id]){
			return connTimeout.apply(NetFunnel.TsClient._Objects[id],arguments);
		}
		this._resetScript();

		if(this.counter[this._mReqType] < this.mConfig["conn_retry"]){
			this._mStatus = PS_TIMEOUT;
			this.counter[this._mReqType] += 1;
			switch(this._mReqType){
				case RTYPE_GET_TID: 
					this.getTicketID(this.user_id,this.user_tid,false);
					return;
					break;
				case RTYPE_CHK_ENTER: 
					this.chkEnter(this.key,false);
					return;
					break;
				case RTYPE_GET_TID_CHK_ENTER: 
					this.getTidChkEnter(this.user_id,this.user_tid,false);
					return;
					break;
				case RTYPE_ALIVE_NOTICE: 
					this.aliveNotice(this.key,"","",false);
					return;
					break;
				case RTYPE_SET_COMPLETE: 
					this.setComplete(this.key,"","",false);
					return;
					break;
				default:
			}
		}
		if(this._mReqType == RTYPE_CHK_ENTER || this._mReqType == RTYPE_GET_TID_CHK_ENTER ){
			NetFunnel.Cookie.set(this.mConfig["cookie_id"],"5002:200:key=connection_timeout",1,this.mConfig["cookie_domain"]);
		}
		this.fireEvent(null,this,'onError',{rtype:this._mReqType,code:RET_E_CONN_TIMEOUT,data:{msg:"Connection Timeout"},next:this.next.success});
		this._mStatus = PS_ERROR;

	};
}

NetFunnel.connTimeout = function(id)
{
	try{
		setTimeout("NetFunnel.connTimeoutProc("+id+")",5000);
	}catch(e){
	}
};

NetFunnel.connTimeoutProc = function(id)
{
	try{
		NetFunnel.TsClient._Objects[id].connTimeout(id);
	}catch(e){
	}
};


NetFunnel.chkEnter = function(id)
{
	try{
		tRetVal = null;
		tKey 	= NetFunnel.TsClient._Objects[id].key;

		if( typeof NetFunnel.TsClient._Objects[id].retval == "object" ){
			tRetVal = NetFunnel.TsClient._Objects[id].retval;
		}

		if(tRetVal != null && tRetVal.isKeyExist("key")){
			tKey = tRetVal.getValue("key");
		}
		
		NetFunnel.TsClient._Objects[id].chkEnter(tKey);
	}catch(e){
	}
};


NetFunnel.chkEnterCont = function(id)
{
	try{
		tRetVal = null;
		tKey 	= NetFunnel.TsClient._Objects[id].key;

		if( typeof NetFunnel.TsClient._Objects[id].retval == "object" ){
			tRetVal = NetFunnel.TsClient._Objects[id].retval;
		}

		if(tRetVal != null && tRetVal.isKeyExist("key")){
			tKey = tRetVal.getValue("key");
		}
		
		NetFunnel.TsClient._Objects[id].chkEnterCont(tKey);
	}catch(e){
	}
};

NetFunnel.aliveNotice = function(id)
{
	try{
		tRetVal = null;
		tKey 	= NetFunnel.TsClient._Objects[id].key;
		tIp 	= NetFunnel.TsClient._Objects[id].ip;
		tPort 	= NetFunnel.TsClient._Objects[id].port;


		if( typeof NetFunnel.TsClient._Objects[id].retval == "object" ){
			tRetVal = NetFunnel.TsClient._Objects[id].retval;
		}

		if(tRetVal && tRetVal.isKeyExist("key")){
			tKey = tRetVal.getValue("key");
		}
		if(tRetVal && tRetVal.isKeyExist("ip")){
			tIp = tRetVal.getValue("ip");
		}
		if(tRetVal && tRetVal.isKeyExist("port")){
			tPort = tRetVal.getValue("port");
		}

		NetFunnel.TsClient._Objects[id].aliveNotice(tKey,tIp,tPort,true);
	}catch(e){
	}
};


NetFunnel.aliveNoticeCont = function(id)
{
	try{
		tRetVal = null;
		tKey 	= NetFunnel.TsClient._Objects[id].key;
		tIp 	= NetFunnel.TsClient._Objects[id].ip;
		tPort 	= NetFunnel.TsClient._Objects[id].port;

		if( typeof NetFunnel.TsClient._Objects[id].retval == "object" ){
			tRetVal = NetFunnel.TsClient._Objects[id].retval;
		}

		if(tRetVal && tRetVal.isKeyExist("key")){
			tKey = tRetVal.getValue("key");
		}
		if(tRetVal && tRetVal.isKeyExist("ip")){
			tIp = tRetVal.getValue("ip");
		}
		if(tRetVal && tRetVal.isKeyExist("port")){
			tPort = tRetVal.getValue("port");
		}

		NetFunnel.TsClient._Objects[id].aliveNoticeCont(tKey,tIp,tPort,true);
	}catch(e){
	}
};

NetFunnel.setComplete = function(id)
{
	try{
		tRetVal = null;
		tKey 	= NetFunnel.TsClient._Objects[id].key;
		tIp 	= NetFunnel.TsClient._Objects[id].ip;
		tPort 	= NetFunnel.TsClient._Objects[id].port;

		if( typeof NetFunnel.TsClient._Objects[id].retval == "object" ){
			tRetVal = NetFunnel.TsClient._Objects[id].retval;
		}

		if(tRetVal && tRetVal.isKeyExist("key")){
			tKey = tRetVal.getValue("key");
		}
		if(tRetVal && tRetVal.isKeyExist("ip")){
			tIp = tRetVal.getValue("ip");
		}
		if(tRetVal && tRetVal.isKeyExist("port")){
			tPort = tRetVal.getValue("port");
		}

		NetFunnel.TsClient._Objects[id].setComplete(tKey,tIp,tPort,true);
	}catch(e){
	}
};




//-----------------------------------------------------------------------------
// NetFunnelTsClient private variable 
//-----------------------------------------------------------------------------
NetFunnel.TsClient._Count 				= 0;
NetFunnel.TsClient._Objects 			= new Object();

/**
 * NetFunnel.Event Class »ó¼Ó
 */
NetFunnel.TsClient.prototype			= new NetFunnel.Event();

/**
 * Init Done flag
 */
NetFunnel.TsClient.prototype._initDone 	= false;



//-----------------------------------------------------------------------------
// NetFunnelTsClient public variable 
//-----------------------------------------------------------------------------
/**
 * Object ID
 */
NetFunnel.TsClient.prototype.id 		= null;

/**
 * ¼³Á¤Á¤º¸ 
 */
NetFunnel.TsClient.prototype.mConfig	= null;

/**
 * TS ¼­¹ö Á¢¼ÓÀ» À§ÇÑ key
 */
NetFunnel.TsClient.prototype.key		= null;

/**
 * Script Object
 */
NetFunnel.TsClient.prototype.script		= null;

/**
 * Alarm Object
 */
NetFunnel.TsClient.prototype.alarm		= null;

/**
 * Alarm Object
 */
NetFunnel.TsClient.prototype._mReqType	= RTYPE_NONE;

/**
 * Previous Mouse Position
 */
NetFunnel.TsClient.prototype._mMousePos	= 0;

/**
 * Action ÀÌ ¾ø¾ú´ø ´©Àû ½Ã°£
 */
NetFunnel.TsClient.prototype._mNoActTime= 0;

/**
 * Process Status
 */
NetFunnel.TsClient.prototype._mStatus	= PS_N_RUNNING;


NetFunnel.TsClient.prototype.counter	= new Object();

/**
 * ¼º°ø¹× ½ÇÆÐ½Ã ÀÌµ¿ÇÒ °æ·Î
 */
NetFunnel.TsClient.prototype.next		= {success:"",error:""};

//-----------------------------------------------------------------------------
// NetFunnel.TsClient Private member function
//-----------------------------------------------------------------------------
/**
 * ÃÊ±âÈ­
 *   - °´Ã¼¸¦ »ý¼ºÇÑ ÈÄ¿¡ ÃÖÃÊ 1¹ø ²À ½ÇÇà½ÃÄÑ ÁÖ¾î¾ß ÇÑ´Ù.
 *   - ÃÊ±âÈ­ ¼º°ø¿©ºÎ´Â isInitDone() ÇÔ¼ö¸¦ ÅëÇØ¼­ È®ÀÎ È° ¼ö ÀÖ´Ù.
 *
 * @memberOf NetFunnel.TsClient
 * @return {null} ¾øÀ½.
 */
NetFunnel.TsClient.prototype.init = function(){
	this._nCount++;
	this._initDone = true;

};

/**
 * »ç¿ëÀÚÀÇ Action ÀÌ ÀÖ´ÂÁö ¿©ºÎ È®ÀÎ
 *   - ¸¶¿ì½ºÀÇ ¿òÁ÷À¸·Î È®ÀÎÇÑ´Ù.
 *
 * @memberOf NetFunnel.TsClient
 * @return {Boolean} Action¿©ºÎ.
 */
NetFunnel.TsClient.prototype._isNoAction = function(){
	if(this._mMousePos == NetFunnel.MouseX){
		return true;
	}
	this._mMousePos = NetFunnel.MouseX;
	return false;
};

/**
 * Connection Timeout À» Ã¼Å©ÇÏ±â À§ÇÑ Å¸ÀÌ¸Ó¸¦ Reset
 *
 * @memberOf NetFunnel.TsClient
 * @return {Null} ¾øÀ½
 */
NetFunnel.TsClient.prototype._resetAlarm = function(){
	if(this.alarm != null){
		clearTimeout(this.alarm);
	}
	this.alarm = null;
};

/**
 * Continued ÀÌº¥Æ®¿¡ ÀÇÇÑ Àç½Ãµµ¸¦ À§ÇÑ Å¸ÀÌ¸Ó¸¦ Reset
 *
 * @memberOf NetFunnel.TsClient
 * @return {Null} ¾øÀ½
 */
NetFunnel.TsClient.prototype._resetRetryTimer = function(){
	if(this.retryTimer != null){
		clearTimeout(this.retryTimer);
	}
	this.retryTimer = null;
};

/**
 * Script Object¸¦ ÃÊ±âÈ­ ÇÑ´Ù.
 *
 * @memberOf NetFunnel.TsClient
 * @return {Null} ¾øÀ½
 */
NetFunnel.TsClient.prototype._resetScript = function(){
	if(this.script){
		var head = document.getElementsByTagName("head").item(0);
		head.removeChild(this.script);
	}
	this.script = null;
};

/**
 * »ç¿ëÀÚÀÇ ¿äÃ»¿¡ ÀÇÇÑ °á°ú °ªÀ» Parsing ÇÏ°í ¾Ë¸Â´Â ÀÌº¥Æ®¸¦ »ç¿ëÀÚ¿¡°Ô 
 * µ¹·ÁÁØ´Ù.
 *
 * @memberOf NetFunnel.TsClient
 * @return {Null} ¾øÀ½
 */
NetFunnel.TsClient.prototype._showResult = function(){
	this._resetAlarm();
	this.retval = new NetFunnel.RetVal(this.result);
	
	// ¹Þ¾Æ¿Â °ªÀ» ÄíÅ°¿¡ ÀúÀå
	if(this.retval.getReqType() == RTYPE_GET_TID_CHK_ENTER){
		this.retval.setReqType(RTYPE_CHK_ENTER);	
	}

	NetFunnel.ttl = 0;
	this.counter[this._mReqType] = 0;
	switch(this.retval.getReqType()){
		case RTYPE_GET_TID: 
			this._showResultGetTicketID(this.retval);
			break;
		case RTYPE_CHK_ENTER: 
			this._showResultChkEnter(this.retval);
			break;
		case RTYPE_ALIVE_NOTICE: 
			this._showResultAliveNotice(this.retval);
			break;
		case RTYPE_SET_COMPLETE: 
			this._showResultSetComplete(this.retval);
			break;
		default:
			NetFunnel.Cookie.del(this.mConfig["cookie_id"]);
			this.fireEvent(null,this,'onError',
					{rtype:RTYPE_NONE,code:this.retval.getRetCode(),data:this.retval.getParam(),next:this.next.error});
			this._mStatus = PS_ERROR;
	}
};

NetFunnel.TsClient.prototype._showResultGetTicketID = function(retval){
	switch(retval.getRetCode()){
		case RET_NORMAL:
			// Success Event 
			NetFunnel.Cookie.set(this.mConfig["cookie_id"],this.result,this.mConfig["cookie_time"],this.mConfig["cookie_domain"]);
			this._mStatus = PS_N_RUNNING;
			this.fireEvent(null,this,'onSuccess',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.success});
			break;
		default:
			// Fail Event
			NetFunnel.Cookie.del(this.mConfig["cookie_id"]);
			this._mStatus = PS_ERROR;
			this.fireEvent(null,this,'onError',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.error});
			
	}
	return;
};

NetFunnel.TsClient.prototype._showResultChkEnter = function(retval){
	switch(retval.getRetCode()){
		case RET_NORMAL:
			// Success Event 
			NetFunnel.Cookie.set(this.mConfig["cookie_id"],this.result,this.mConfig["cookie_time"],this.mConfig["cookie_domain"]);
			this._mStatus = PS_N_RUNNING;
			this.fireEvent(null,this,'onSuccess',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.success});
			break;
		case RET_CONTINUE:
			// Continued Event 
			this._mStatus = PS_CONTINUE;

			// ReTry
			ttl = retval.getNumber('ttl');
			if(ttl > this.mConfig["max_ttl"]){
				ttl = this.mConfig["max_ttl"];
				retval.setValue('ttl',ttl);
			}

			this.fireEvent(null,this,'onContinued',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.continued});

			if(ttl > 0){
				if(this.retryTimer){
					clearTimeout(this.retryTimer);
				}
				NetFunnel.ttl = ttl;
				this.retryTimer = setTimeout("NetFunnel.chkEnterCont("+this.id+")",ttl*1000);	
			}

			break;
		default:
			// Fail Event
			NetFunnel.Cookie.del(this.mConfig["cookie_id"]);
			this._mStatus = PS_ERROR;
			this.fireEvent(null,this,'onError',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.error});
			
	}
	return;
};

NetFunnel.TsClient.prototype._showResultAliveNotice = function(retval){
	switch(retval.getRetCode()){
		case RET_NORMAL:
			// Success Event 
			this._mStatus = PS_N_RUNNING;
			this.fireEvent(null,this,'onSuccess',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.success});
			break;
		case RET_CONTINUE:
			// Continued Event 
			this._mStatus = PS_CONTINUE;
			if( this._mNoActTime > this.mConfig["no_action"]){
				this.fireEvent(null,this,'onError',
						{rtype:retval.getReqType(),code:RET_E_NO_ACTION,data:retval.getParam(),next:this.next.error});
				this._mNoActTime = 0;
				this._mStatus = PS_ERROR;
				break;
			}

			ttl = retval.getNumber('ttl');
			if(ttl > this.mConfig["max_ttl"]){
				ttl = this.mConfig["max_ttl"];
				retval.setValue('ttl',ttl);
			}

			this.fireEvent(null,this,'onContinued',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.continued});

			if(ttl > 0){
				if(this.retryTimer){
					clearTimeout(this.retryTimer);
				}
				if(this._isNoAction()){
					this._mNoActTime += ttl;
				}else{
					this._mNoActTime = 0;
				}
				this.retryTimer = setTimeout("NetFunnel.aliveNoticeCont("+this.id+")",ttl*1000);	
			}

			break;
		default:
			// Fail Event
			if(retval.getRetCode() == RET_E_KEY_EXPIRE){
				NetFunnel.Cookie.del(this.mConfig["cookie_id"]);
			}
			this._mStatus = PS_ERROR;
			this.fireEvent(null,this,'onError',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.error});
			
	}
	return;
};

NetFunnel.TsClient.prototype._showResultSetComplete = function(retval){
	NetFunnel.Cookie.del(this.mConfig["cookie_id"]);
	switch(retval.getRetCode()){
		case RET_NORMAL:
			// Success Event 
			this._mStatus = PS_N_RUNNING;
			this.fireEvent(null,this,'onSuccess',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.success});
			break;
		default:
			// Fail Event
			this._mStatus = PS_ERROR;
			this.fireEvent(null,this,'onError',
					{rtype:retval.getReqType(),code:retval.getRetCode(),data:retval.getParam(),next:this.next.error});
			
	}
	return;
};




/**
 * ½Å±Ô Á¢¼ÓÀ» À§ÇÑ Á¢¼ÓÁ¤º¸ ÃÊ±âÈ­
 *
 * @memberOf NetFunnelTsClient
 * @param {Number} rtype ¿äÃ» Å¸ÀÔ
 * @return {Boolean} ÃÊ±âÈ­ ¼º°ø¿©ºÎ
 */
NetFunnel.TsClient.prototype._connInit = function(rtype)
{
	this.result 		= null;
	this._mReqType		= rtype;
	this._resetAlarm();
	this._resetScript();
	this._resetRetryTimer();
	this.alarm = setTimeout("NetFunnel.connTimeout("+this.id+")",parseInt(this.mConfig["conn_timeout"])*1000);


	if(!this.mConfig["host"] || this.mConfig["host"] == ""){
		return false;
	}
	if(!this.mConfig["port"] || this.mConfig["port"] == ""){
		return false;
	}
	if(!this.mConfig["query"] || this.mConfig["query"] == ""){
		return false;
	}
	this._mStatus = PS_RUNNING;
	return true;
};

/**
 * TS ¼­¹ö·Î ¿äÃ» Àü¼Û
 *
 * @memberOf NetFunnelTsClient
 * @param {String} url ¿äÃ» URL
 * @return {Boolean} ¿äÃ» ¼º°ø¿©ºÎ
 */
NetFunnel.TsClient.prototype._sendRequest = function(url){
	// 1. Script °´Ã¼ »ý¼º
	this.script = document.createElement ("script");
	
	// 2. Script °´Ã¼¿¡ URL µî·Ï, Head¿¡ Script µî·Ï
	this.script.src = url;
	var head = document.getElementsByTagName("head").item(0);
	head.appendChild(this.script);

	return true;
}

/**
 * ¿¡·¯ Àü´Þ 
 *
 * @memberOf NetFunnelTsClient
 * @param {Number} eRType ¿äÃ» Å¸ÀÔ
 * @param {Number} eCode °á°ú°ª ÄÚµå
 * @return {null} ¾øÀ½.
 */
NetFunnel.TsClient.prototype._sendError = function(eRType,eCode)
{		
	var tMsg = "";
	switch(eCode){
		case RET_E_ARUNNING:
			tMsg = "Already running";
			break;
		case RET_E_NOINIT:
			tMsg = "Uninitialized object";
			break;
		case RET_E_SYSTEM:
		default:
			tMsg = "System error";
			
	}
	this.fireEvent(null,this,'onError',{rtype:eRType,code:eCode,data:{msg:tMsg},next:this.next.error});
}



//-----------------------------------------------------------------------------
// NetFunnel.TsClient public member function
//-----------------------------------------------------------------------------

/**
 * ¸í·É ¼º°ø½Ã ÀÌµ¿ÇÏ°ÔµÉ URL¸¦ ¼³Á¤ÇÑ´Ù.
 *   - DefaultCallback À» »ç¿ëÇÒ¶§¸¸ À¯È¿ÇÏ¸ç Callback ÇÔ¼ö¸¦ ÁöÁ¤Çß´Ù¸é
 *     »ç¿ëµÇÁö ¾Ê´Â´Ù.
 *
 * @memberOf NetFunnelTsClient
 * @param {String} success ¸í·É ¼º°ø½Ã ÀÌµ¿ÇÒ URL
 * @param {String} error ¸í·É ½ÇÆÐ½Ã ÀÌµ¿ÇÒ URL
 * @return {null} ¾øÀ½.
 */
NetFunnel.TsClient.prototype.setNext = function(next){
	if( typeof next == "object"){
		this.next 	= next;
	}else{
		this.next.success = undefined;
		this.next.continued = undefined;
		this.next.error = undefined;
	}
}

/**
 * ½ÇÇàÁßÀÎ ¸í·É ¸ØÃã Àü¼Û
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @memberOf NetFunnelTsClient
 * @return {null} ¾øÀ½.
 */
NetFunnel.TsClient.prototype.sendStop = function(first){
	if(TS_BYPASS == true) { this.fireEvent(null,this,'onSuccess',{rtype:this._mReqType,code:RET_NORMAL,data:{},next:this.next.success}); return true; }

	if(first == 'undefined'){ first = true; }
	if(first){ this.counter[RTYPE_STOP]=0; }

	this._resetAlarm();
	this._resetRetryTimer();
	this._resetScript();
	this.fireEvent(null,this,'onSuccess',{rtype:this._mReqType,code:RET_NORMAL,data:{},next:this.next.success});

	this._mStatus = PS_N_RUNNING;
	return true;
}


/**
 * TicketID ¿äÃ» ¸í·É Àü¼Û
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @memberOf NetFunnelTsClient
 * @param {String} user_id »ç¿ëÀÚID
 * @param {String} user_tid »ç¿ëÀÚTID (¼­ºñ½º¿¡ »ç¿ëµÇ´Â Ticket¿¡ ´ëÇÑ ½Äº°ÀÚ)
 * @return {null} ¾øÀ½.
 */
NetFunnel.TsClient.prototype.getTicketID = function(user_id,user_tid,first){
	if(TS_BYPASS == true) { this.fireEvent(null,this,'onSuccess',{rtype:this._mReqType,code:RET_NORMAL,data:{},next:this.next.success}); return true; }

	if(first == 'undefined'){ first = true; }
	if(first){ this.counter[RTYPE_GET_TID]=0; }

	// 0. ½ÇÇàÁßÀÎÁö ¿©ºÎ È®ÀÎ
	if ( this._mStatus == PS_RUNNING ) {
		this._sendError(RTYPE_GET_TID,RET_E_ARUNNING);
		return false;
	}

	// 1. ÃÊ±âÈ­
	if(!this._connInit(RTYPE_GET_TID)){
		this._sendError(RTYPE_GET_TID,RET_E_NOINIT);
		return false;
	}

	this.user_id = user_id;
	this.user_tid = user_tid;

	// 2. URL »ý¼º
	url = "http://"+this.mConfig["host"]+":"+this.mConfig["port"]+"/"+this.mConfig["query"]+"?opcode="+RTYPE_GET_TID+"&nfid="+this.id;
	url += "&js=yes";
	url += "&user_id="+user_id;
	url += "&user_tid="+user_tid;

	tdate = new Date();
	url += "&"+tdate.getTime();

	this._sendRequest(url);

	return true;
}


/**
 * ÁøÀÔ ¿äÃ» ¸í·É Àü¼Û
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onContinued(evt,oArg.rtype,oArg.code,oArg.data) : ´ë±â
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @memberOf NetFunnelTsClient
 * @param {String} key getTicketID¸¦ ÅëÇØ Àü´Þ¹ÞÀº ½Äº°ÀÚ
 * @return {null} ¾øÀ½.
 */
NetFunnel.TsClient.prototype.chkEnter = function(key,first){
	// 0. ½ÇÇàÁßÀÎÁö ¿©ºÎ È®ÀÎ
	if(TS_BYPASS == true) { this.fireEvent(null,this,'onSuccess',{rtype:this._mReqType,code:RET_NORMAL,data:{},next:this.next.success}); return true; }

	if ( this._mStatus == PS_RUNNING || this._mStatus == PS_CONTINUE) {
		this._sendError(RTYPE_CHK_ENTER,RET_E_ARUNNING);
		return false;
	}
	return this.chkEnterProc(key,first);
}

NetFunnel.TsClient.prototype.chkEnterCont = function(key,first){
	// 0. ½ÇÇàÁßÀÎÁö ¿©ºÎ È®ÀÎ
	if ( this._mStatus == PS_RUNNING ) {
		this._sendError(RTYPE_CHK_ENTER,RET_E_ARUNNING);
		return false;
	}
	return this.chkEnterProc(key,first);
}

NetFunnel.TsClient.prototype.chkEnterProc = function(key,first){
	if(first == 'undefined'){ first = true; }
	if(first){ this.counter[RTYPE_CHK_ENTER]=0; }

	// 1. ÃÊ±âÈ­
	if(!this._connInit(RTYPE_CHK_ENTER)){
		this._sendError(RTYPE_CHK_ENTER,RET_E_NOINIT);
		return false;
	}

	if(!key || key == ""){
		if(this.key){
			key = this.key;	
		}else{
			this._sendError(RTYPE_CHK_ENTER,RET_E_PARAM);
			return false;
		}
	}
	this.key = key;

	url = "http://"+this.mConfig["host"]+":"+this.mConfig["port"]+"/"+this.mConfig["query"]+"?opcode="+RTYPE_CHK_ENTER+"&key="+key+"&nfid="+this.id;
	if(NetFunnel.ttl > 0){
		url = url+"&ttl="+NetFunnel.ttl;
	}
	url += "&js=yes";
	tdate = new Date();
	url += "&"+tdate.getTime();

	this._sendRequest(url);

	return true;
}

/**
 * ID¹ß±Þ + ÁøÀÔ ¿äÃ» ¸í·É Àü¼Û
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onContinued(evt,oArg.rtype,oArg.code,oArg.data) : ´ë±â
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @memberOf NetFunnelTsClient
 * @param {String} user_id »ç¿ëÀÚID
 * @param {String} user_tid »ç¿ëÀÚTID (¼­ºñ½º¿¡ »ç¿ëµÇ´Â Ticket¿¡ ´ëÇÑ ½Äº°ÀÚ)
 * @return {null} ¾øÀ½.
 */
NetFunnel.TsClient.prototype.getTidChkEnter = function(user_id,user_tid,first){
	// 0. ½ÇÇàÁßÀÎÁö ¿©ºÎ È®ÀÎ
	if(TS_BYPASS == true) { this.fireEvent(null,this,'onSuccess',{rtype:this._mReqType,code:RET_NORMAL,data:{},next:this.next.success}); return true; }

	if ( this._mStatus == PS_RUNNING || this._mStatus == PS_CONTINUE) {
		this._sendError(RTYPE_CHK_ENTER,RET_E_ARUNNING);
		return false;
	}
	return this.getTidChkEnterProc(user_id,user_tid,first);
}

NetFunnel.TsClient.prototype.getTidChkEnterProc = function(user_id,user_tid,first){
	if(first == 'undefined'){ first = true; }
	if(first){ this.counter[RTYPE_GET_TID_CHK_ENTER]=0; }

	// 1. ÃÊ±âÈ­
	if(!this._connInit(RTYPE_GET_TID_CHK_ENTER)){
		this._sendError(RTYPE_GET_TID_CHK_ENTER,RET_E_NOINIT);
		return false;
	}

	this.user_id = user_id;
	this.user_tid = user_tid;

	url = "http://"+this.mConfig["host"]+":"+this.mConfig["port"]+"/"+this.mConfig["query"]+"?opcode="+RTYPE_GET_TID_CHK_ENTER+"&nfid="+this.id;
	if(NetFunnel.ttl > 0){
		url = url+"&ttl="+NetFunnel.ttl;
	}
	//alert(url);
	url += "&js=yes";
	tdate = new Date();
	url += "&"+tdate.getTime();
	url += "&user_id="+user_id;
	url += "&user_tid="+user_tid;

	this._sendRequest(url);

	return true;
}


/**
 * Alive Notice ¿äÃ» ¸í·É Àü¼Û
 *  - chkEnter ¸í·ÉÀ» ÅëÇØ¼­ ½Ã½ºÅÛ¿¡ ÁøÀÔ Çã°¡¸¦ ¹ÞÀºÈÄ¿¡´Â ÀÌ ¸í·ÉÀ» Àü¼ÛÇØ Áà¾ß¸¸ ÇöÀçÀÇ 
 *    client°¡ ÇÁ·Î¼¼½º¸¦ ÁøÇà ÇÏ´ÂÁö¸¦ TS ¼­¹ö¿¡¼­ ¾Ë ¼ö ÀÖ°Ô µÈ´Ù. ¹Ýº¹ ÁÖ±â´Â TS ¼­¹ö¿¡¼­ 
 *    ¾Ë·Á ÁÖ°Ô µÇ¸ç flash client¿¡¼­ ÀÚµ¿À¸·Î ÀçÀü¼ÛÇÏ°Ô µÈ´Ù.
 *
 *   - Event
 *     - onContinued(evt,oArg.rtype,oArg.code,oArg.data) : ´ë±â
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @memberOf NetFunnelTsClient
 * @param {String} key chkEnter¸¦ ÅëÇØ Àü´Þ¹ÞÀº ½Äº°ÀÚ
 * @param {String} ip TS¼­¹ö IP Á¤º¸
 * @param {Number} port TS¼­¹ö Port Á¤º¸
 * @return {null} ¾øÀ½.
 */
NetFunnel.TsClient.prototype.aliveNoticeProc = function(key,ip,port,first){
	if(first == 'undefined'){ first = true; }
	if(first){ this.counter[RTYPE_ALIVE_NOTICE]=0; }

	// 1. ÃÊ±âÈ­
	if(!this._connInit(RTYPE_ALIVE_NOTICE)){
		this._sendError(RTYPE_ALIVE_NOTICE,RET_E_NOINIT);
		return false;
	}

	if(!key || key == ""){
		if(this.key){
			key = this.key;	
		}else{
			this._sendError(RTYPE_ALIVE_NOTICE,RET_E_PARAM);
			return false;
		}
	}
	this.key 	= key;
	this.ip 	= ip;
	this.port 	= port;

	if(ip && ip!="" && port && port != ""){
		url = "http://"+ip+":"+port+"/"
	}else{
		url = "http://"+this.mConfig["host"]+":"+this.mConfig["port"]+"/"
	}
	url = url+this.mConfig["query"]+"?opcode="+RTYPE_ALIVE_NOTICE+"&key="+key+"&nfid="+this.id;
	url += "&js=yes";
	tdate = new Date();
	url += "&"+tdate.getTime();

	this._sendRequest(url);
	return true;

}

NetFunnel.TsClient.prototype.aliveNotice = function(key,ip,port,first){
	// 0. ½ÇÇàÁßÀÎÁö ¿©ºÎ È®ÀÎ
	if(TS_BYPASS == true) { this.fireEvent(null,this,'onSuccess',{rtype:this._mReqType,code:RET_NORMAL,data:{},next:this.next.success}); return true; }
	if ( this._mStatus == PS_RUNNING || this._mStatus == PS_CONTINUE ) {
		this._sendError(RTYPE_ALIVE_NOTICE,RET_E_ARUNNING);
		return false;
	}
	return this.aliveNoticeProc(key,ip.port,first);
}

NetFunnel.TsClient.prototype.aliveNoticeCont = function(key,ip,port,first){
	// 0. ½ÇÇàÁßÀÎÁö ¿©ºÎ È®ÀÎ
	if ( this._mStatus == PS_RUNNING ) {
		this._sendError(RTYPE_ALIVE_NOTICE,RET_E_ARUNNING);
		return false;
	}
	return this.aliveNoticeProc(key,ip,port,first);
}

/**
 * ¿Ï·á ¿äÃ» ¸í·É Àü¼Û
 *   - ¸ðµç ÇÁ·Î¼¼½º°¡ Á¾·á µÇ¾úÀ»¶§ È£Ãâ ÇÑ´Ù.
 *   - ¿Ï·á ÈÄ ÀÌ¸í·ÉÀ» È£ÃâÇÏÁö ¾ÊÀ¸¸é ½Ã½ºÅÛÀÇ °¡¿ë¼ºÀÌ ÀúÇÏµÇ¸ç, Á¤È®ÇÑ Åë°èÁ¤º¸¸¦ ¾òÀ» ¼ö ¾ø´Ù.
 *
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @memberOf NetFunnelTsClient
 * @param {String} key chkEnter¸¦ ÅëÇØ Àü´Þ¹ÞÀº ½Äº°ÀÚ
 * @param {String} ip TS¼­¹ö IP Á¤º¸
 * @param {Number} port TS¼­¹ö Port Á¤º¸
 * @return {null} ¾øÀ½.
 */
NetFunnel.TsClient.prototype.setComplete = function(key,ip,port,first){
	if(TS_BYPASS == true) { this.fireEvent(null,this,'onSuccess',{rtype:this._mReqType,code:RET_NORMAL,data:{},next:this.next.success}); return true; }

	if(first == 'undefined'){ first = true; }
	if(first){ this.counter[RTYPE_SET_COMPLETE]=0; }

	// 0. ½ÇÇàÁßÀÎÁö ¿©ºÎ È®ÀÎ
	if ( this._mStatus == PS_RUNNING ) {
		this._sendError(RTYPE_SET_COMPLETE,RET_E_ARUNNING);
		return false;
	}

	// 1. ÃÊ±âÈ­
	if(!this._connInit(RTYPE_SET_COMPLETE)){
		this._sendError(RTYPE_SET_COMPLETE,RET_E_NOINIT);
		return false;
	}

	if(!key || key == ""){
		if(this.key){
			key = this.key;	
		}else{
			this._sendError(RTYPE_SET_COMPLETE,RET_E_PARAM);
			return false;
		}
	}
	this.key 	= key;
	this.ip 	= ip;
	this.port 	= port;

	if(ip && ip!="" && port && port != ""){
		url = "http://"+ip+":"+port+"/"
	}else{
		url = "http://"+this.mConfig["host"]+":"+this.mConfig["port"]+"/"
	}
	url = url+this.mConfig["query"]+"?opcode="+RTYPE_SET_COMPLETE+"&key="+key+"&nfid="+this.id;
	url += "&js=yes";
	tdate = new Date();
	url += "&"+tdate.getTime();

	this._sendRequest(url);
	return true;
}

/**
 * NetFunnel ÄíÅ° Á¸Àç ¿©ºÎ
 *
 * @memberOf NetFunnelTsClient
 * @return {boolean} ÄíÅ°Á¸Àç ¿©ºÎ
 */
NetFunnel.TsClient.prototype.cookieExist = function()
{
	result = NetFunnel.Cookie.get(this.mConfig["cookie_id"]);
	if(result == ""){
		return false;
	}

	var retval = new NetFunnel.RetVal(result);
	key = retval.getValue("key");
	if(!key){ 
		NetFunnel.Cookie.del(this.mConfig["cookie_id"]);
		return false; 
	}
	return true;
}

/**
 * NetFunnel ±¸µ¿Áß ¿©ºÎ
 *
 * @memberOf NetFunnelTsClient
 * @return {boolean} ±¸µ¿Áß ¿©ºÎ
 */
NetFunnel.TsClient.prototype.isRunning = function()
{
	if ( this._mStatus == PS_RUNNING || this._mStatus == PS_CONTINUE ) {
		return true;
	}
	return false;
}



/**
 * NetFunnel Ts Utilities 
 * 	Static functions
 */
var NetFunnelTsUtil = {
	/**
	 * Event ¿¡ ÀÇÇØ Àü´ÞµÈ Data¸¦ Debug ¸Þ¼¼Áö ÇüÅÂÀÇ ¹®ÀÚ¿­·Î ¸¸µé¾îÁØ´Ù.
	 *
	 * @memberOf NetFunnelTsUtil
	 * @param {String} callback Callback Event ÀÌ¸§
	 * @param {Number} rtype Request Type
	 * @param {Number} code Return Code
	 * @param {Object} data Return Data
	 * @param {Boolean} is_html HTML ÇüÅÂ ¿©ºÎ
	 * @return {String} ÀÔ·Â°ª¿¡ ÀÇÇØ ÀÛ¼ºµÈ ¹®ÀÚ¿­
	 */
	makeDebugMsg:function(callback,rtype,code,data,is_html)
	{
		var nl="\n";
		var space="       ";
		if(is_html == true){
			nl="<br>";
			space="&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
		}

		switch(rtype){
			case RTYPE_GET_TID: rtype_s 			= "getTicketID"; 		break;
			case RTYPE_CHK_ENTER: rtype_s 			= "chkEnter"; 			break;
			case RTYPE_ALIVE_NOTICE: rtype_s 		= "aliveNotice"; 		break;
			case RTYPE_SET_COMPLETE: rtype_s 		= "setComplete"; 		break;
			case RTYPE_GET_TID_CHK_ENTER: rtype_s 	= "getTID+ChkEnter";	break;
			case RTYPE_INIT: rtype_s 				= "Init"; 				break;
			case RTYPE_STOP: rtype_s 				= "stop"; 				break;
			default: rtype_s 						= "Unknown"; 			break;
		}

		switch(code){
			case RET_NORMAL: code_s 			= "Normal"; 			break;
			case RET_CONTINUE: code_s 			= "Continue"; 			break;
			case RET_E_SYSTEM: code_s 			= "System Error"; 		break;
			case RET_E_SECURITY: code_s 		= "Security Error"; 	break;
			case RET_E_IO: code_s 				= "I/O Error"; 			break;
			case RET_E_CONN_TIMEOUT: code_s 	= "Connection Timeout"; break;
			case RET_E_ARUNNING: code_s 		= "Already Running"; 	break;
			case RET_E_NOINIT: code_s 			= "Init Error"; 		break;
			case RET_E_INSERT: code_s 			= "Insert Error"; 		break;
			case RET_E_NOPERM: code_s 			= "No Permission"; 		break;
			case RET_E_KEY_EXPIRE: code_s 		= "Key Expire"; 		break;
			case RET_E_PARAM: code_s 			= "Parameter Error"; 	break;
			case RET_E_NOT_STARTED: code_s 		= "No service time"; 	break;
			case RET_E_NO_ACTION: code_s 		= "No action Error"; 	break;
			default: code_s 					= "Unknown Error"; 		break;
		}

		var tStr = callback+" "+nl+nl+"  - type : "+rtype_s+" ("+rtype+")"+nl+" - Code : "+code_s+" ("+code+")"+nl+" - Params"+nl;
		for (var i in data)
		{
			tStr += space+i+" ---> "+data[i]+nl;
		}
		return tStr;
	},

	/**
	 * Event ¿¡ ÀÇÇØ Àü´ÞµÈ Data¸¦ ´ÙÀ½ url ·Î Àü´Þ
	 * 
	 * @memberOf NetFunnelTsUtil
	 * @param {String} url ÀÌµ¿ÇÒ URL
	 * @param {Object} data Return Data
	 * @return {null}
	 */
	goNextPage:function(url,data){
		var tUrl = url;
		for(var i in data){
			tUrl += "&"+i+"="+data[i];
		}
		document.location.href = tUrl;
	},

	/**
	 * µð¹ö±× ¸Þ¼¼Áö¸¦ Ãâ·ÂÇÑ´Ù. ( flash ¿¡ ÀÇÇØ È£Ãâ µÈ´Ù. )
	 *
	 * @memberOf NetFunnelTsUtil
	 * @param {String} msg Ãâ·ÂµÉ ¹®ÀÚ¿­
	 */
	alertDebugMsg:function(msg){
		alert(msg);
	}
}

var gtext="";
/**
 * ÃÊ±âÈ­ ¿äÃ» 
 *
 *  - CallBack
 *		* onSuccess   : ¼º°ø½Ã È£ÃâµÇ´Â ÇÔ¼ö 
 *		* onContinued : ttl ÀÌ Àü´ÞµÈ °æ¿ì È£ÃâµÇ´Â ÇÔ¼ö ( È£ÃâÈÄ¿¡ ttl ¸¸Å­ sleep ÇÑ´Ù. )
 *		* onError     : ¿¡·¯ ¹ß»ý½Ã È£ÃâµÇ´Â ÇÔ¼ö
 *
 *
 * @param {Object|String} oFlash Flash Object¿¡ ´ëÇÑ ÀÌ¸§ÀÌ³ª Object °´Ã¼
 * @param {Object} oConfigs ¼³Á¤Á¤º¸
 * @param {Object} oCallbacks ÀÌº¥Æ®¿¡ ´ëÇÑ Callback ÇÔ¼ö Á¤ÀÇ
 * @return {Boolean} °´Ã¼»ý¼º ¼º°ø ¿©ºÎ
 */
function NetFunnel_init(oFlash,oConfigs,oCallbacks){
	try{
		
	//if(oConfigs && (oConfigs.constructor == Object)) {
	if(typeof oConfigs == "object"){
		//alert("NetFunnel_init_frame");
	}
	
		if(NetFunnel.gControl){
			NetFunnel.gControl = null;
		}
		
		NetFunnel._oTargetFrame = null;
		if(typeof oFlash == "object" && oFlash != null){
			NetFunnel._oTargetFrame = oFlash;
		}

		if(typeof oCallbacks == "undefined"){
			oCallbacks = NetFunnel.DefaultCallback;
		}else{
			if(!oCallbacks["onSuccess"]) { oCallbacks["onSuccess"] = NetFunnel.DefaultCallback["onSuccess"]; }
			if(!oCallbacks["onContinued"]) { oCallbacks["onContinued"] = NetFunnel.DefaultCallback["onContinued"]; }
			if(!oCallbacks["onError"]) { oCallbacks["onError"] = NetFunnel.DefaultCallback["onError"]; }
		}

		NetFunnel.gControl = new NetFunnel.TsClient(oConfigs,oCallbacks);
		return true;
	}catch(err){
		NetFunnel.gControl = null;
		gtext = err;
		return false;
	}
}

/**
 * ½ÇÇàÁßÀÎ ¸í·É ¸ØÃã Àü¼Û
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @param {String|Function} next ¸í·É ¼º°ø½Ã ÀÌµ¿ÇÒ URL or ½ÇÇàÇÒ Function (Optional)
 * @return {boolean} ¼º°ø¿©ºÎ
 */
function NetFunnel_sendStop(next){
	try{
		if(!NetFunnel.gControl){ NetFunnel_init();  }
		NetFunnel.gControl.setNext(next);
		NetFunnel.gControl.sendStop();
		return true;
	}catch(err){
		return false;
	}
}

/**
 * TicketID ¿äÃ» ¸í·É Àü¼Û
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @param {String|Function} next ¸í·É ¼º°ø½Ã ÀÌµ¿ÇÒ URL or ½ÇÇàÇÒ Function (Optional)
 * @param {String} user_id »ç¿ëÀÚ ¾ÆÀÌµð 
 * @param {String} user_tid »ç¿ëÀÚ ticket ¾ÆÀÌµð 
 * @return {boolean} ¼º°ø¿©ºÎ
 */
function NetFunnel_getTicketID(next,user_id,user_tid){
	try{
		if(!NetFunnel.gControl){ NetFunnel_init();  }

		NetFunnel.gControl.setNext(next);
		NetFunnel.gControl.getTicketID(user_id,user_tid);
		return true;
	}catch(err){
		return false;
	}
}

/**
 * ÁøÀÔ ¿äÃ» ¸í·É Àü¼Û
 *   - chkEnter ¸í·ÉÀ» ÅëÇØ¼­ ½Ã½ºÅÛ¿¡ ÁøÀÔ Çã°¡¸¦ ¹ÞÀºÈÄ¿¡´Â ÀÌ ¸í·ÉÀ» Àü¼ÛÇØ Áà¾ß¸¸ ÇöÀçÀÇ 
 *     client°¡ ÇÁ·Î¼¼½º¸¦ ÁøÇà ÇÏ´ÂÁö¸¦ TS ¼­¹ö¿¡¼­ ¾Ë ¼ö ÀÖ°Ô µÈ´Ù. ¹Ýº¹ ÁÖ±â´Â TS ¼­¹ö¿¡¼­ 
 *     ¾Ë·Á ÁÖ°Ô µÇ¸ç flash client¿¡¼­ ÀÚµ¿À¸·Î ÀçÀü¼ÛÇÏ°Ô µÈ´Ù.
 *
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onContinued(evt,oArg.rtype,oArg.code,oArg.data) : ´ë±â
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @param {String|Function} next ¸í·É ¼º°ø½Ã ÀÌµ¿ÇÒ URL or ½ÇÇàÇÒ Function (Optional)
 * @param {Object} data Á¢¼Ó Data (Optional) 
 * @return {boolean} ¼º°ø¿©ºÎ
 */
function NetFunnel_chkEnter(next){
	try{
		if(!NetFunnel.gControl){ NetFunnel_init();  }

		if(typeof data != "undefined" && data.constructor == Object){
			key = data["key"];
			if(!key){ return false; }
		}else{
			// Cookie ¿¡¼­ °ªÀ» °¡Á®¿Â´Ù.
			result = NetFunnel.Cookie.get(NetFunnel.gControl.mConfig["cookie_id"]);
			if(result == ""){
				return false;
			}

			var retval = new NetFunnel.RetVal(result);
			var key = retval.getValue("key");
            if(!key){ 
                NetFunnel.Cookie.del(NetFunnel.gControl.mConfig["cookie_id"]);
                return false; 
            }
		}

		NetFunnel.gControl.setNext(next);
		NetFunnel.gControl.chkEnter(key);

		return true;
	}catch(err){
		return false;
	}
}

/**
 * ¹ß±Þ¿äÃ» + ÁøÀÔ ¿äÃ» ¸í·É Àü¼Û
 *   - Key ¹ß±Þ¿äÃ»°ú chkEnter ¿äÃ»À» µ¿½Ã¿¡ ¼öÇàÇÑ´Ù.
 *   - chkEnter ¸í·ÉÀ» ÅëÇØ¼­ ½Ã½ºÅÛ¿¡ ÁøÀÔ Çã°¡¸¦ ¹ÞÀºÈÄ¿¡´Â ÀÌ ¸í·ÉÀ» Àü¼ÛÇØ Áà¾ß¸¸ ÇöÀçÀÇ 
 *     client°¡ ÇÁ·Î¼¼½º¸¦ ÁøÇà ÇÏ´ÂÁö¸¦ TS ¼­¹ö¿¡¼­ ¾Ë ¼ö ÀÖ°Ô µÈ´Ù. ¹Ýº¹ ÁÖ±â´Â TS ¼­¹ö¿¡¼­ 
 *     ¾Ë·Á ÁÖ°Ô µÇ¸ç client¿¡¼­ ÀÚµ¿À¸·Î ÀçÀü¼ÛÇÏ°Ô µÈ´Ù.
 *
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onContinued(evt,oArg.rtype,oArg.code,oArg.data) : ´ë±â
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @param {String|Function} next ¸í·É ¼º°ø½Ã ÀÌµ¿ÇÒ URL or ½ÇÇàÇÒ Function (Optional)
 * @param {String} user_id »ç¿ëÀÚ ¾ÆÀÌµð 
 * @param {String} user_tid »ç¿ëÀÚ ticket ¾ÆÀÌµð 
 * @return {boolean} ¼º°ø¿©ºÎ
 */
function NetFunnel_getTidChkEnter(next,user_id,user_tid){
	try{
		if(!NetFunnel.gControl){ NetFunnel_init();  }
		NetFunnel.gControl.setNext(next);
		NetFunnel.gControl.getTidChkEnter(user_id,user_tid);
		return true;
	}catch(err){
		return false;
	}
}


/**
 * Alive Notice ¿äÃ» ¸í·É Àü¼Û
 *   - Event
 *     - onContinued(evt,oArg.rtype,oArg.code,oArg.data) : ´ë±â
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @param {String|Function} next ¸í·É ¼º°ø½Ã ÀÌµ¿ÇÒ URL or ½ÇÇàÇÒ Function (Optional)
 * @param {Object} data Á¢¼Ó Data (Optional) 
 * @return {boolean} ¼º°ø¿©ºÎ
 */
function NetFunnel_aliveNotice(next,data){
	try{
		if(!NetFunnel.gControl){ NetFunnel_init();  }


		if(typeof data != "undefined" && data.constructor == Object){
			key = data["key"];
			if(!key){ return false; }
			ip = data["ip"];
			port = data["port"];
		}else{
			// Cookie ¿¡¼­ °ªÀ» °¡Á®¿Â´Ù.
			result = NetFunnel.Cookie.get(NetFunnel.gControl.mConfig["cookie_id"]);
			if(result == ""){
				return false;
			}

			var retval = new NetFunnel.RetVal(result);
			key = retval.getValue("key");
            if(!key){ 
                NetFunnel.Cookie.del(NetFunnel.gControl.mConfig["cookie_id"]);
                return false; 
            }
			ip = retval.getValue("ip");
			port = retval.getValue("port");
		}

		NetFunnel.gControl.setNext(next);
		NetFunnel.gControl.aliveNotice(key,ip,port);
		return true;
	}catch(err){
		return false;
	}
}

/**
 * ¿Ï·á ¿äÃ» ¸í·É Àü¼Û
 *   - ¸ðµç ÇÁ·Î¼¼½º°¡ Á¾·á µÇ¾úÀ»¶§ È£Ãâ ÇÑ´Ù.
 *   - ¿Ï·á ÈÄ ÀÌ¸í·ÉÀ» È£ÃâÇÏÁö ¾ÊÀ¸¸é ½Ã½ºÅÛÀÇ °¡¿ë¼ºÀÌ ÀúÇÏµÇ¸ç, Á¤È®ÇÑ Åë°èÁ¤º¸¸¦ ¾òÀ» ¼ö ¾ø´Ù.
 *
 *   - Event
 *     - onSuccess(evt,oArg.rtype,oArg.code,oArg.data) : ¼º°ø½Ã
 *     - onError(evt,oArg.rtype,oArg.code,oArg.data) : ½ÇÆÐ½Ã
 *
 * @param {String|Function} next ¸í·É ¼º°ø½Ã ÀÌµ¿ÇÒ URL or ½ÇÇàÇÒ Function (Optional)
 * @param {Object} data Á¢¼Ó Data (Optional) 
 * @return {boolean} ¼º°ø¿©ºÎ
 */
function NetFunnel_setComplete(next,data){
	try{
		if(!NetFunnel.gControl){ NetFunnel_init();  }

		if(typeof data != "undefined" && data.constructor == Object){
			key = data["key"];
			if(!key){ return false; }
			ip = data["ip"];
			port = data["port"];
		}else{
			// Cookie ¿¡¼­ °ªÀ» °¡Á®¿Â´Ù.
			result = NetFunnel.Cookie.get(NetFunnel.gControl.mConfig["cookie_id"]);
			if(result == ""){
				return false;
			}

			var retval = new NetFunnel.RetVal(result);
			key = retval.getValue("key");
			if(!key){ 
				NetFunnel.Cookie.del(NetFunnel.gControl.mConfig["cookie_id"]);
				return false; 
			}
			ip = retval.getValue("ip");
			port = retval.getValue("port");
		}

		NetFunnel.gControl.setNext(next);
		NetFunnel.gControl.setComplete(key,ip,port);
		return true;
	}catch(err){
		return false;
	}
}

/**
 * NetFunnel ÄíÅ° Á¸Àç ¿©ºÎ
 *
 * @return {boolean} ÄíÅ°Á¸Àç ¿©ºÎ
 */
function NetFunnel_cookieExist(){
	if(!NetFunnel.gControl){ return false }
	return NetFunnel.gControl.cookieExist();
}

/**
 * NetFunnel ±¸µ¿Áß ¿©ºÎ
 *
 * @return {boolean} ±¸µ¿Áß ¿©ºÎ
 */
function NetFunnel_isRunning(){
	if(!NetFunnel.gControl){ return false; }
	return NetFunnel.gControl.isRunning();
}

/**
 * NetFunnel IFRAME »ç¿ë ´ë±âÃ¢ È£Ãâ
*/

function NetFunnel_init_frame(oExecFrame,oConfigs,oCallbacks){
	NetFunnel._oFrame = null;
	
	if(typeof oExecFrame != "object" || oExecFrame == null){
  	oExecFrame = this;
  }
  
	NetFunnel._oFrame = oExecFrame;
	return NetFunnel._oFrame.NetFunnel_init(this,oConfigs,oCallbacks);
}

function NetFunnel_getTidChkEnter_frame(next,user_id,user_tid){
	if(NetFunnel._oFrame == null) return false;
	NetFunnel._oFrame.NetFunnel_getTidChkEnter(next,user_id,user_tid);
}
