//XInteraction »ç¿ë½Ã XecureWeb Client ·ÎµùÀ» À§ÇØ
function loadXecureWebClient()
{
	if( document.getElementById('XecureWeb') == null || document.getElementById('XecureWeb') == undefined)
	{

		var	v_agent = navigator.userAgent.toString().toLowerCase();
		var v_appName = navigator.appName;
        var v_OBJ = "";
		var x_codebase = "";
		var x_classid = "";


		if( v_appName == 'Netscape')
		{
		}
		else
		{
			x_codebase = "http://download.softforum.co.kr/Published/XecureWeb/v7.2.4.1/xw_install.cab#Version=7,2,4,1";
			x_classid = "CLSID:7E9FDB80-5316-11D4-B02C-00C04F0CD404";
		}


		try
		{
			//ie9 ´ëÀÀÀ» À§ÇÑ º¯°æ
			var v_pOBJ = document.createElement('INPUT');
				v_pOBJ.setAttribute("TYPE", "hidden");
				v_pOBJ.setAttribute("ID", "p");
				v_pOBJ.setAttribute("NAME", "p");

			var v_fOBJ = document.createElement('FORM');
				v_fOBJ.setAttribute("ID", "xecure");
				v_fOBJ.setAttribute("NAME", "xecure");
				v_fOBJ.appendChild(v_pOBJ);

			var v_scrOBJ = document.createElement('SCRIPT');
				v_scrOBJ.setAttribute("LANGUAGE", "javascript");
				v_scrOBJ.setAttribute("SRC", "/XecureObject/xecureweb.js");

			var x_OBJ = document.createElement('OBJECT');
			    x_OBJ.setAttribute("ID", "XecureWeb");
			    x_OBJ.setAttribute("NAME", "XecureWeb");
				x_OBJ.setAttribute("CODEBASE", x_codebase);
				x_OBJ.setAttribute("CLASSID" , x_classid);
				x_OBJ.setAttribute("WIDTH" ,"0");
				x_OBJ.setAttribute("HEIGHT" ,"0");

			var x_PARAM = document.createElement("PARAM");
			    x_PARAM.setAttribute("NAME", "lang");
			    x_PARAM.setAttribute("VALUE", "korean");
				x_OBJ.appendChild(x_PARAM);

				v_OBJ = document.createElement('div');
				v_OBJ.style.display = 'none';
				v_OBJ.appendChild(x_OBJ);
				v_OBJ.appendChild(v_fOBJ);
				v_OBJ.appendChild(v_scrOBJ);

			document.write(v_OBJ.outerHTML);

		}
		catch( PE )
		{
			document.write(v_OBJ.outerHTML);
		}
	
	
	}//if


}//loadXecureWebClient


//XInteraction »ç¿ë½Ã °øÀÎÀÎÁõ¼­ Client ·ÎµùÀ» À§ÇØ
function loadCertManX()
{

	if( document.getElementById('CertManX') == null || document.getElementById('CertManX') == undefined)
	{

		var	v_agent = navigator.userAgent.toString().toLowerCase();
		var v_appName = navigator.appName;
        var v_OBJ = "";
		var x_codebase = "";
		var x_classid = "";

		if( v_appName == 'Netscape')
		{
		}
		else
		{
			x_codebase = "/center/download/down/sign/SKCommAX.cab#version=9,8,0,2";
			x_classid = "CLSID:EC5D5118-9FDE-4A3E-84F3-C2B711740E70";
		}


		try
		{
			//ie9 ´ëÀÀÀ» À§ÇÑ º¯°æ
			var x_OBJ = document.createElement('OBJECT');
			    x_OBJ.setAttribute("ID", "CertManX");
			    x_OBJ.setAttribute("NAME", "CertManX");
				x_OBJ.setAttribute("CODEBASE", x_codebase);
				x_OBJ.setAttribute("CLASSID" , x_classid);

				v_OBJ = document.createElement('div');
				v_OBJ.style.display = 'none';
				v_OBJ.appendChild(x_OBJ);

			document.write(v_OBJ.outerHTML);

		}
		catch( PE )
		{
			document.write(v_OBJ.outerHTML);
		}
	
	
	}//if

}//loadCertManX




	var errMsg;
	function escape_url(url)
	{
		var i;
		var ch;
		var out = '';
		var url_string = '';

		url_string = String(url);

		for (i = 0; i < url_string.length; i++) {
			ch = url_string.charAt(i);
			if (ch == ' ')		out += '%20';
			else if (ch == '%')	out += '%25';
			else if (ch == '&')	out += '%26';
			else if (ch == '+')	out += '%2B';
			else if (ch == '=')	out += '%3D';
			else if (ch == '?') out += '%3F';
			else				out += ch;
		}
		return out;
	}
	/*  Function Equivalent to java.net.URLEncoder.encode(String, "UTF-8")
		Copyright (C) 2002, Cresc Corp.
		Version: 1.0
	*/
	function encodeURL(str)
	{
		var s0, i, s, u;
		s0 = "";                // encoded str

		// scan the source
		for (i = 0; i < str.length; i++)
		{
			s = str.charAt(i);
			u = str.charCodeAt(i);          // get unicode of the char
			if ( s == " " )
			{
				s0 += "+";	// SP should be converted to "+"
			} else
			{
				if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a)))
				{
					// check for escape
					s0 = s0 + s;            // don't escape
				} else
				{
					// escape
					if ((u >= 0x0) && (u <= 0x7f))
					{	// single byte format
						s = "0"+u.toString(16);
						s0 += "%"+ s.substr(s.length-2);
					} else if (u > 0x1fffff)
					{	// quaternary byte format (extended)
						s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
						s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
						s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
						s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
					} else if (u > 0x7ff)
					{	// triple byte format
						s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
						s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
						s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
					} else
					{	// double byte format
						s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
						s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
					}
				}
			}
		}
		return s0;
	}
	/*  Function Equivalent to java.net.URLDecoder.decode(String, "UTF-8")
		Copyright (C) 2002, Cresc Corp.
		Version: 1.0
	*/
	function decodeURL(str)
	{
		var s0, i, j, s, ss, u, n, f;
		s0 = "";                // decoded str
		for (i = 0; i < str.length; i++)
		{
			// scan the source str
			s = str.charAt(i);
			if (s == "+")
			{
				s0 += " ";		// "+" should be changed to SP
			} else
			{
				if (s != "%")
				{
					s0 += s;     // add an unescaped char
				} else
				{
					// escape sequence decoding
					u = 0;          // unicode of the character
					f = 1;          // escape flag, zero means end of this sequence
					while (true)
					{
						ss = "";        // local str to parse as int
						for (j = 0; j < 2; j++ )
						{
							// get two maximum hex characters for parse
							sss = str.charAt(++i);
							if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F")))
							{
								ss += sss;      // if hex, add the hex character
							} else
							{
								--i; break;    // not a hex char., exit the loop
							}
						}
						n = parseInt(ss, 16);           // parse the hex str as byte
						if (n <= 0x7f){u = n; f = 1;}   // single byte format
						if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
						if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
						if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
						if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
						if (f <= 1){break;}         // end of the utf byte sequence
						if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
						else {break;}                   // abnormal, format error
					}
					s0 += String.fromCharCode(u);           // add the escaped character
				}
			}
		}
		return s0;
	}

	function alertMsg()
	{
		alert(errMsg);
	}

	var _v_XecureOBJ = new Object();
	var _v_XecureVAR = new Object();
	function fn_loadXecureVAR()
	{
		var url			= "http://" + location.host + '/common/include/XecureVAR.js';
		var jsSource	= "";
		var xmlHttp = null;
		if ( window.ActiveXObject )
		{
			try	{ xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.6.0");
			} catch(e1)
			{
				try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
				} catch(e2)
				{
					try	{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
					} catch(e3)
					{
					}
				}
			}
		}
		if( xmlHttp )
		{
			xmlHttp.open('get', url, false);
			xmlHttp.send(null);
			jsSource	= xmlHttp.responseText;
			eval ( jsSource );
		}
	}
/*================================================================================================*/
	function DataSet()
	{
		this.mp			= new Object();
		this.keyArry	= new Array();
		var	index		= -1;
		function put ( key, value, idx )
		{
			if ( idx == null )	idx = 0;
			var arry = this.mp[key];
			if ( !arry )
			{
				arry								= new Array();
				this.mp[key]						= arry;
				this.keyArry[this.keyArry.length]	= key;
			}

			this.mp[key][this.mp[key].length] = value;
//			this.mp[key][idx] = value;
		}

		function putIdx ( key, value, idx )
		{
			if ( idx == null )	idx = 0;
			var arry = this.mp[key];
			if ( !arry )
			{
				arry								= new Array();
				this.mp[key]						= arry;
				this.keyArry[this.keyArry.length]	= key;
			}

			this.mp[key][idx] = value;
		}

		function get(key, idx)
		{
			var arry = this.mp[key];
			if(!arry) return '';
			if(idx == null ) idx = 0;
			var val = arry[idx];

			if ( !val )	val='';

			return val.toString().replace(/(^\s*)|(\s*$)/g, "");
		}
		function xget ( key, idx )
		{
			return this.get ( key, idx );
		}
		function getCount(key)
		{
			var arry = this.mp[key];
			if ( !arry )	return 0;
			return arry.length;
		}
		function getParam()
		{
			var str = '';
			var pCnt = 0;
			for ( var i=0 ; i < this.keyArry.length ; i++ )
			{
				var key	= this.keyArry[i];
				var arr	= this.mp[key];
				for ( var j=0 ; j < arr.length ; j++ )
				{
					str += ( ( pCnt != 0 ) ? '&' : '') + key + '=' + escape_url( encodeURL( '' + this.mp[key][j]) );
					pCnt++;
				}
			}
			return str;
		}
		function toString()
		{
			var str = '';
			for ( var i=0 ; i < this.keyArry.length ; i++ )
			{
				var key	= this.keyArry[i];
				var arr	= this.mp[key];
				str += key + ' = ' + this.mp[key].length + '[';
				for ( var j=0 ; j < arr.length ; j++ )
				{
					str += ( ( j != 0 ) ? ',' : '') + this.mp[key][j];
				}
				str += ']\n';
			}
			return str;
		}
		function toxString()
		{
			return this.toString();
		}
		function getArray(key)
		{
			return this.mp[key];
		}
		function clear()
		{
			this.mp=new Object();
			this.keyArry=new Array();
		}

		this.put		= put;
		this.putIdx		= putIdx;
		this.get		= get;
		this.xget		= xget;
		this.getCount	= getCount;
		this.getParam	= getParam;
		this.toString	= toString;
		this.toxString	= toxString;
		this.clear		= clear;
		this.getArray	= getArray;
	}
/*================================================================================================*/
/*================================================================================================*/
	function Interaction()
	{
		this.nn_trSize = 0;
		function processTr ( url, params , output, func )
		{
			var xmlHttp = null;
			if ( window.ActiveXObject )
			{
				try	{ xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.6.0");
				} catch(e1)
				{
					try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
					} catch(e2)
					{
						try	{ xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
						} catch(e3)
						{
						}
					}
				}
			}else {
				// opera, safari
				xmlHttp = new XMLHttpRequest();
			}
			
			if ( func == null )
			{
				xmlHttp.open ( "POST", url , false );
			} else
			{
				xmlHttp.open ( "POST", url , true );
			}
			this.nn_trSize++;
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.send(params);

			if ( func == null )
			{
				this.nn_trSize--;
				var	doc			= xmlHttp.responseXML;
				var	nodeList	= doc.getElementsByTagName("result");

				if(nodeList.length != 0)
				{

					var	chNdLst		= nodeList.item(0).childNodes;
					var	idx			= 0;

					for ( var i=0 ; i < chNdLst.length ; i++ )
					{
						var nd	= chNdLst.item(i);
						if ( nd.nodeType != nd.TEXT_NODE )
						{
							var cchNdLst=chNdLst.item(i).childNodes;
							for ( y=0 ; y < cchNdLst.length ; y++ )
							{
								var n=cchNdLst.item(y);
								try
								{
									output.put(n.nodeName, n.firstChild.nodeValue, idx);
								} catch (e)
								{
									output.put(n.nodeName, '', idx);
								}
							}
							idx++;
						}
					}

				}//if(nodeList.length != 0)

			} else
			{
				xmlHttp.onreadystatechange = function()
				{
					if ( xmlHttp.readyState == 4 )
					{
						var	doc			= xmlHttp.responseXML;
						var	nodeList	= doc.getElementsByTagName("result");

						if(nodeList.length != 0)
						{

							var	chNdLst		= nodeList.item(0).childNodes;
							var	idx			= 0;

							for ( var i=0 ; i < chNdLst.length ; i++ )
							{
								var nd	= chNdLst.item(i);
								if ( nd.nodeType != nd.TEXT_NODE )
								{
									var cchNdLst=chNdLst.item(i).childNodes;
									for ( var y=0 ; y < cchNdLst.length ; y++ )
									{
										var n=cchNdLst.item(y);
										try
										{
											output.put(n.nodeName, n.firstChild.nodeValue, idx);
										} catch (e)
										{
											output.put(n.nodeName, '', idx);
										}
									}
									idx++;
								}
							}
							this.nn_trSize--;
							eval ( func + '(output)' );
						}

					}//if(nodeList.length != 0)
				}
			}
		}

		function execute ( tr, input, output, func )
		{
			var	param	= input.getParam();

			if ( output == null )
				var output = new DataSet();

			var	xmlhttp;
			var	url		= "http://" + window.location.host + "/gksgate/run/"+tr+".xml?"+Math.random();
			try
			{
				this.processTr ( url, param, output, func );
				return output;
			} catch ( e )
			{
				errMsg = 'Åë½ÅÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù. [MSXML]\n\n°í°´Áö¿ø¼¾Å¸·Î ¿¬¶ô ¹Ù¶ø´Ï´Ù.(1544-8282)\n\n* TR:'+tr;


//				errMsg = e.message+' Interaction execute error.'+'\n* TR:'+tr;
//				if ( xmlhttp!=null )
//					errMsg = errMsg+"\n\n* HTTP RESPONSE\n"+xmlhttp.ResponseText;
				window.setTimeout( "alertMsg();", 500);
			}
			window.status='communication complete.';
			return output;
		}
		function isLogin()
		{
			var input   = new DataSet();
			var output  = new DataSet();
				output  = this.execute('hts/login/isLogin', input, output );
			return output.get('isLogin') == 'true';
		}

	    function executeZ(tr, input) {
	        var params = input.getParam();
	        var xmlHttp = null;

	        var url = "http://" + window.location.host + "/gksgate/run/" + tr
	                + ".xml?" + Math.random();
	        try {
	            if (window.ActiveXObject) {
	                try {
	                    xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.6.0");
	                } catch (e1) {
	                    try {
	                        xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
	                    } catch (e2) {
	                        try {
	                            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	                        } catch (e3) {
	                        }
	                    }
	                }
	            }else {
	        		// opera, safari
	        		xmlHttp = new XMLHttpRequest();
	        	}

	            xmlHttp.open("POST", url, false);
	            this.nn_trSize++;
	            xmlHttp.setRequestHeader('Content-Type',
	                    'application/x-www-form-urlencoded; charset=UTF-8');
	            xmlHttp.setRequestHeader("Content-length", params.length);
	            xmlHttp.send(params);
	            doc = xmlHttp.responseXML;
	        } catch (e) {
				errMsg = '½Ã½ºÅÛ Á¡°ËÁßÀÔ´Ï´Ù.\nÀá½Ã ÈÄ¿¡ ÀÌ¿ëÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.\n* TR:'+tr;
				window.setTimeout( "alertMsg();", 500);
	        }
	        window.status = 'communication complete.';
	        return doc;
	    }

		this.processTr = processTr;
		this.execute = execute;
		this.isLogin = isLogin;
		this.executeZ = executeZ;
	}
/*================================================================================================*/

/*================================================================================================*/
	function XInteraction()
	{


		// ¾ÏÈ£È­ Client »ý¼º
		loadXecureWebClient();

		// ÀüÀÚ¼­¸í Client »ý¼º
		loadCertManX();


		function processTr ( url, params , output )
		{
			var xmlHttp = null;
			if ( typeof(window.XMLHttpRequest) != 'undefined' )
			{
				xmlHttp = new window.XMLHttpRequest();
			} else
			{
				xmlHttp = new window.ActiveXObject('Microsoft.XMLHTTP');
			}

			xmlHttp.open ( "POST", url , false );
			xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.send(params);

			var	doc			= xmlHttp.responseXML;
			var enc_text	= doc.documentElement.text;
			var plain_text  = BlockDec(enc_text);
			var xdoc = new ActiveXObject("Microsoft.XMLDOM");
				xdoc.async = false;
				xdoc.loadXML(plain_text);
			var	nodeList		= xdoc.getElementsByTagName("result");

			if(nodeList.length != 0)
			{
				var	chNdLst		= nodeList.item(0).childNodes;
				var	idx			= 0;

				for ( i=0 ; i < chNdLst.length ; i++ )
				{
					var nd	= chNdLst.item(i);
					if ( nd.nodeType != nd.TEXT_NODE )
					{
						var cchNdLst = chNdLst.item(i).childNodes;
						for ( y=0 ; y < cchNdLst.length ; y++ )
						{
							var n	= cchNdLst.item(y);
							try
							{
								output.put(n.nodeName, n.firstChild.nodeValue, idx);
							} catch (e)
							{
								output.put(n.nodeName, '', idx);
							}
						}
						idx++;
					}
				}

			}//if(nodeList.length != 0)
		}

		function execute ( tr, input, output )
		{
			document.body.style.cursor = 'wait';
			var urlPath = "http://" + window.location.host + "/ksgate/xrun/"+tr+".xml";

			var	param	= input.getParam();

			var	pText	= param.replace ( /&/g, "#" ).replace(/=/g, "" ).replace(/ /g, "");
			if ( pText.length < 150 )
			{
				var pLen = 150 - pText.length;
				for ( idx=0 ; idx < pLen ; idx++)	pText += ' ';
			} else
			{
				pText = pText.substring(0,150);
			}
			var sText	= this.sign ( pText );

			if ( sText != '' )
			{
				param += '&orgdata=' +  escape_url( encodeURL( '' + pText) ) + '&signdata=' + escape_url( encodeURL( '' + sText) );
			}

			
			var cipher;
			try{
				cipher	= document.getElementById('XecureWeb').BlockEnc ( xgate_addr, urlPath, XecureEscape(param), "GET" );
			}catch(e){
				alert( 'º¸¾ÈÇÁ·Î±×·¥ ¼³Ä¡ ÈÄ ·Î±×ÀÎ ÇØÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.\n(»ó´ÜÀÇ ¾Ë¸²Ç¥½ÃÁÙÀ» Å¬¸¯, ¶Ç´Â ´Ù¿î·Îµå È­¸é¿¡¼­ XecureWeb ÇÁ·Î±×·¥À» ¼³Ä¡ÇØÁÖ¼¼¿ä)');
				return new DataSet();
			}

			if ( output == null )
				var output = new DataSet();

			var	xmlhttp;
			var	url		= urlPath + '?' + Math.random();
			var ppm		= 'q=' + escape_url(cipher);


			try
			{
				this.processTr(url, ppm, output);
			} catch ( e )
			{
				errMsg = 'Åë½ÅÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù. [MSXML]\n\n°í°´Áö¿ø¼¾Å¸·Î ¿¬¶ô ¹Ù¶ø´Ï´Ù.(1544-8282)\n\n* TR:'+tr;
//				errMsg = e.message+' Interaction execute error.'+'\n* TR:'+tr;
//				if ( xmlhttp!=null )
//					errMsg = errMsg+"\n\n* HTTP RESPONSE\n"+xmlhttp.ResponseText;
				window.setTimeout( "alertMsg();", 500);
			}
			window.status='communication complete.';

			document.body.style.cursor = '';

			return output;
		}

		function login ( input , output )
		{
			document.body.style.cursor = 'wait';
			var urlPath = "http://" + window.location.host + "/ksgate/login/hts/login/LOGIN.xml";
			var	param	= input.getParam();
			
			var cipher;
			try{
				cipher	= document.getElementById('XecureWeb').BlockEnc ( xgate_addr, urlPath, XecureEscape(param), "GET" );
			}catch(e){
				alert( 'º¸¾ÈÇÁ·Î±×·¥ ¼³Ä¡ ÈÄ ·Î±×ÀÎ ÇØÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.\n(»ó´ÜÀÇ ¾Ë¸²Ç¥½ÃÁÙÀ» Å¬¸¯, ¶Ç´Â ´Ù¿î·Îµå È­¸é¿¡¼­ XecureWeb ÇÁ·Î±×·¥À» ¼³Ä¡ÇØÁÖ¼¼¿ä)');
				return new DataSet();
			}
						
			if ( output == null )
				var output = new DataSet();

			var	xmlhttp;
			var	url		= urlPath;
			var params	= "q=" + escape_url(cipher) + "&" + Math.random()
			try
			{
				this.processTr( url, params, output );
			} catch ( e )
			{
				errMsg = 'Åë½ÅÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù. [MSXML]\n\n°í°´Áö¿ø¼¾Å¸·Î ¿¬¶ô ¹Ù¶ø´Ï´Ù.(1544-8282)\n\n* TR: login';
//				errMsg = e.message+' Interaction execute error.'+'\n* TR: login';
//				if ( xmlhttp!=null )
//					errMsg = errMsg+"\n\n* HTTP RESPONSE\n"+xmlhttp.ResponseText;
				window.setTimeout( "alertMsg();", 500);
			}
			window.status='communication complete.';

			document.body.style.cursor = '';

			return output;
		}
		function sign ( data )
		{
			var signdata = '';
			if ( typeof(userDN) != 'undefined' && userDN != '' && typeof(document.getElementById('CertManX')) != 'undefined' )
			{
				//Å°º¸µåº¸¾È°ú ¿¬µ¿ÇÏ±â(°øÀÎÀÎÁõºñ¹Ð¹øÈ£ ÀÔ·ÂÇÏ´Â°÷¿¡ ÀÚµ¿À¸·Î Å°º¸µåº¸¾ÈÀÌ Àû¿ëµÊ) Å°º¸µåº¸¾È ¾÷Ã¼ ¹Ù²î¸é ¼öÁ¤ÇÏ¿©¾ß ÇÔ.
				if(document.getElementById('CertManX').SetKeySaferMode(1) == false)
				{
					//alert('Å°º¸µåº¸¾ÈÀû¿ë Fail_ksgate');
				}

				if(document.getElementById('CertManX').SetServiceMode('ÇÑÈ­Áõ±Ç', userDN) == false) 
				{
					alert('[KG1]'+document.getElementById('CertManX').GetLastErrorMsg());
				}

				// DN¿¡ ÇØ´çÇÏ´Â ÀÎÁõ¼­¸¸ ¼±ÅÃÃ¢¿¡ Ç¥½Ã, ¼¼¼Ç°ü¸®ÀÚ¿¡¼­ ¼±ÅÃÇÑ ÀÎÁõ¼­ Á¤º¸À¯Áö
				if(document.getElementById('CertManX').SetMatchedContextExt(userDN, '' , '', 0) == '')
				{
					alert('[KG2]'+document.getElementById('CertManX').GetLastErrorMsg());
				}
				document.getElementById('CertManX').SetWrongPasswordLimit(1);
				signdata = document.getElementById('CertManX').SignData_ne_B64('', data, 0);
				var tmp_signdata = '';
				var ch;
				var slen = signdata.length;
				for ( _i=0 ; _i < slen ; _i++ )
				{
					ch = signdata.charCodeAt(_i);
					if (ch != 13 && ch != 10) tmp_signdata += signdata.charAt(_i);
				}
				signdata = tmp_signdata;
			}
			return signdata;
		}
		function isLogin()
		{
			var input   = new DataSet();
			var output  = new DataSet();
				output  = this.execute('hts/login/isLogin', input, output );
			return output.xget('isLogin') == 'true';
		}

	    /**
	     *
	     * @param tr
	     * @param input
	     * @return
	     *
	     */
	    function executeZ(tr, input) {
	        var xmlHttp = null;
	        var doc = null;
	        var urlPath = "http://" + window.location.host + "/ksgate/xrun/" + tr
	                + ".xml";

	        var param = input.getParam();
	        var pText = param.replace(/&/g, "#").replace(/=/g, "")
	                .replace(/ /g, "");
	        if (pText.length < 150) {
	            var pLen = 150 - pText.length;
	            for (idx = 0; idx < pLen; idx++)
	                pText += ' ';
	        } else {
	            pText = pText.substring(0, 150);
	        }
	        var sText = sign(pText);

	        if (sText != '') {
	            param += '&orgdata=' + escape_url(encodeURL('' + pText))
	                    + '&signdata=' + escape_url(encodeURL('' + sText));
	        }
	        
	        var cipher;
			try{
				cipher	= document.getElementById('XecureWeb').BlockEnc(xgate_addr, urlPath,
		                XecureEscape(param), "GET");
			}catch(e){
				alert( 'º¸¾ÈÇÁ·Î±×·¥ ¼³Ä¡ ÈÄ ·Î±×ÀÎ ÇØÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.\n(»ó´ÜÀÇ ¾Ë¸²Ç¥½ÃÁÙÀ» Å¬¸¯, ¶Ç´Â ´Ù¿î·Îµå È­¸é¿¡¼­ XecureWeb ÇÁ·Î±×·¥À» ¼³Ä¡ÇØÁÖ¼¼¿ä)');
				return new DataSet();
			}
	        
	        var url = urlPath + '?' + Math.random();
	        var ppm = 'q=' + escape_url(cipher);

	        try {

	            if (typeof (window.XMLHttpRequest) != 'undefined') {
	                xmlHttp = new window.XMLHttpRequest();
	            } else {
	                xmlHttp = new window.ActiveXObject('Microsoft.XMLHTTP');
	            }

	            if (xmlHttp) {
	                xmlHttp.open("POST", url, false);
	                xmlHttp.setRequestHeader('Content-Type',
	                        'application/x-www-form-urlencoded; charset=UTF-8');
	                xmlHttp.setRequestHeader("Content-length", ppm.length);
	                xmlHttp.send(ppm);
	                doc = xmlHttp.responseXML;
	                this.xecureDecode(doc.documentElement);
	            }

	        } catch (e) {
				errMsg = '½Ã½ºÅÛ Á¡°ËÁßÀÔ´Ï´Ù.\nÀá½Ã ÈÄ¿¡ ÀÌ¿ëÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.\n* TR:'+tr;
				window.setTimeout( "alertMsg();", 500);
	        }
	        window.status = 'communication complete.';
	        return doc;
	    }

	    var decodeTmp = "";
	    function xecureDecode(doc) {
	        var tmp = doc.childNodes;
	        for ( var i = 0; i < tmp.length; i++) {
	            if (tmp[i].nodeType != "1")
	                tmp[i].text = BlockDec(tmp[i].text);
	            else
	                this.xecureDecode(tmp[i]);
	            decodeTmp = decodeTmp + "|" + tmp[i].text;
	        }
	    }// xecureDecode


		function executeSTR(tr, input) {
	        var xmlHttp = null;
	        var doc = null;
	        var urlPath = "http://" + window.location.host + "/ksgate/xrun/" + tr
	                + ".xml";

	        var param = input.getParam();
	        var pText = param.replace(/&/g, "#").replace(/=/g, "")
	                .replace(/ /g, "");
	        if (pText.length < 150) {
	            var pLen = 150 - pText.length;
	            for (idx = 0; idx < pLen; idx++)
	                pText += ' ';
	        } else {
	            pText = pText.substring(0, 150);
	        }
	        var sText = sign(pText);

	        if (sText != '') {
	            param += '&orgdata=' + escape_url(encodeURL('' + pText))
	                    + '&signdata=' + escape_url(encodeURL('' + sText));
	        }
	        
	        var cipher;
			try{
				cipher	= document.getElementById('XecureWeb').BlockEnc(xgate_addr, urlPath,
		                XecureEscape(param), "GET");
			}catch(e){
				alert( 'º¸¾ÈÇÁ·Î±×·¥ ¼³Ä¡ ÈÄ ·Î±×ÀÎ ÇØÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.\n(»ó´ÜÀÇ ¾Ë¸²Ç¥½ÃÁÙÀ» Å¬¸¯, ¶Ç´Â ´Ù¿î·Îµå È­¸é¿¡¼­ XecureWeb ÇÁ·Î±×·¥À» ¼³Ä¡ÇØÁÖ¼¼¿ä)');
				return new DataSet();
			}
	        
	        var url = urlPath + '?' + Math.random();
	        var ppm = 'q=' + escape_url(cipher);

	        try {

	            if (typeof (window.XMLHttpRequest) != 'undefined') {
	                xmlHttp = new window.XMLHttpRequest();
	            } else {
	                xmlHttp = new window.ActiveXObject('Microsoft.XMLHTTP');
	            }

	            if (xmlHttp) {
	                xmlHttp.open("POST", url, false);
	                xmlHttp.setRequestHeader('Content-Type',
	                        'application/x-www-form-urlencoded; charset=UTF-8');
	                xmlHttp.setRequestHeader("Content-length", ppm.length);
	                xmlHttp.send(ppm);
	                recv_xml = xmlHttp.responseXML;
	                
					var enc_text	= recv_xml.documentElement.text;
					var doc  = BlockDec(enc_text);

					//return(plain_text);
					//this.xecureDecode(doc.documentElement);
	            }

	        } catch (e) {
				errMsg = '½Ã½ºÅÛ Á¡°ËÁßÀÔ´Ï´Ù.\nÀá½Ã ÈÄ¿¡ ÀÌ¿ëÇØ ÁÖ½Ã±â ¹Ù¶ø´Ï´Ù.\n* TR:'+tr;
				window.setTimeout( "alertMsg();", 500);
	        }
	        window.status = 'communication complete.';
	        return doc;
	    }

		this.XInteraction	= XInteraction;
		this.processTr		= processTr;
		this.execute		= execute;
		this.login			= login;
		this.sign			= sign;
		this.isLogin		= isLogin;
	    this.executeZ		= executeZ;
		this.executeSTR		= executeSTR;
	    this.xecureDecode = xecureDecode;
	}
/*================================================================================================*/

	var queryString = new DataSet();

	try
	{
		var qstr = location.search.substring(1);
		if ( qstr.length > 0 )
		{
			var variables = qstr.split('&');
			for (var i=0 ; i < variables.length ; i++ )
			{
				var v_name		= variables[i].substring ( 0, variables[i].indexOf('=') ).replace(/(^\s*)|(\s*$)/g, "");
				var v_value		= variables[i].substring ( variables[i].indexOf('=')+1 ).replace(/(^\s*)|(\s*$)/g, "");
				var v_nameCnt	= queryString.getCount(v_name);
				queryString.put ( v_name, v_value , v_nameCnt );
			}
		}
	} catch ( EEE )
	{
		alert('[TEXT]'+EEE.description);
	}

