//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



/*================================================================================================*/
// ksgate ¿¡¼­ »ç¿ëÇÏ´ø escape_url, encodeURL, decodeURL, alertMsg, DataSet À¯Áö
/*================================================================================================*/
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;
	var e2e_mark    = "xk";

	function add( key, value )
	{
		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;
	}
	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 eput( key, value, idx )
	{
		key = e2e_mark + '' + key;
		this.put(key, value, idx);
	}
	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 eget(key, idx)
	{
		key = e2e_mark + '' + key;
		this.get(key, idx);
	}
	function xget ( key, idx )
	{
		return this.get ( key, idx );
//			var val = this.get ( key, idx );
//			if ( val != '' )
//			{
//				val = BlockDec(val);
//			}
//			return val.toString().replace(/(^\s*)|(\s*$)/g, "");
	}
	function del(key, idx)
	{
		var arry = this.mp[key];
		if(!arry) return;
		arry.splice( idx, 1 );
	}
	function delRow(idx)
	{
		for ( var i=0 ; i < this.keyArry.length ; i++ )
		{
			var key	= this.keyArry[i];
			var arry = this.mp[key];
			if(!arry) continue;
			arry.splice( idx, 1 );
		}
	}
	function getCount(key)
	{
		var arry = this.mp[key];
		if ( !arry )	return 0;
		return arry.length;
	}
	function getParam(urlEncoding)
	{


		if(urlEncoding == null || urlEncoding == undefined ||  urlEncoding == true)
		{
			urlEncoding = true;
		}
		else
		{
			urlEncoding = false;
		}

		var str = '';
		var pCnt = 0;

		if(urlEncoding)
		{
			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++;
				}
			}
		}
		else
		{
			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 + '=' + 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();
//			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] == '' ) ? '' : BlockDec(this.mp[key][j]) );
//				}
//				str += ']\n';
//			}
//			return str;

	}
	function toXML()
	{
		var cnt = this.count();
		var buff = "<dataset><result>";

		for ( var i=0 ; i <cnt ; i++ )
		{
			buff += "<data-block>";

			for ( var j=0 ; j < this.keyArry.length ; j++ )
			{
				var key	= this.keyArry[j];
				var arr	= this.mp[key];

				buff += "<" + key + ">"

				var tmp = arr[i];
				if(tmp == null || tmp == undefined) tmp = "";

				buff += tmp;
				buff += "</" + key + ">"
			}

			buff += "</data-block>";
		}

		buff += "</result></dataset>";
		return buff;
	}
	function count()
	{
		var max = 0;
		for ( var i=0 ; i < this.keyArry.length ; i++ )
		{
			var key	= this.keyArry[i];
			var len	= this.mp[key].length;

			if(max < len) max = len;
		}

		return max;
	}
	function getArray(key)
	{
		return this.mp[key];
	}
	function clear()
	{
		this.mp=new Object();
		this.keyArry=new Array();
	}

	this.add		= add;
	this.put		= put;
	this.eput		= eput;
	this.putIdx		= putIdx;
	this.get		= get;
	this.eget		= eget;
	this.del		= del;
	this.delRow		= delRow;
	this.xget		= xget;
	this.getCount	= getCount;
	this.getParam	= getParam;
	this.toString	= toString;
	this.toxString	= toxString;
	this.clear		= clear;
	this.getArray	= getArray;
	this.toXML	= toXML;
	this.count	= count;


}//DataSet











/*================================================================================================*/
//XMLHttp, XMLDom °´Ã¼ »ý¼º ¹× Dom °ü·Ã Util
/*================================================================================================*/

//XMLHttp »ý¼º.
function createXMLHttp( )
{

	var xmlHttp = null;

	// ie
	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();
	}

	return xmlHttp;

}// createXMLHttp


/*================================================================================================*/

//XMLDom »ý¼º.
function createXMLDom( )
{

	var xmlDom = null;

	// ie
	if( window.ActiveXObject )
	{

		try
		{
			xmlDom = new ActiveXObject( "Msxml2.DOMDocument.6.0" );
			xmlDom.resolveExternals = true;
		}
		catch( e1 )
		{
			try{ xmlDom = new ActiveXObject( "Msxml2.DOMDocument.4.0" ); }
			catch( e2 )
			{
				try{ xmlDom = new ActiveXObject( "Microsoft.XMLDOM" ); }
				catch( e3 )
				{
				}
			}
		}
	}else if (document.implementation && document.implementation.createDocument) { 
		xmlDoc=document.implementation.createDocument("","",null);
	} else {
		alert('Your browser cannot handle this script');
	}

	return xmlDom;

}// createXMLDom


/*================================================================================================*/

function xmlDoc(xml)
{


	this.xgetXmlDoc = xgetXmlDoc;
	this.xecureDecode = xecureDecode;
	this.newXml = newXml;
	this.xml = this.newXml(xml,false);


	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]);
		}

	}


	function xgetXmlDoc()
	{
		var doc = this.xml.documentElement;
		this.xecureDecode(doc);
		return this.xml;
	}


	function newXml(xslFile, async)
	{
		var xsl = createXMLDom();
		xsl.async = async;
		xsl.load(xslFile);

		return xsl;
	}


}//xmlDoc


/*================================================================================================*/


//string Çü½ÄÀÇ xml À» ÀÌ¿ëÇØ¼­ xml dom À» »ý¼ºÇÑ´Ù.
function loadTextXML(xmlStr, async)
{
	if(async == undefined || async == null || async == "") async = false;
	var doc = createXMLDom();
	doc.async = async;
	doc.loadXML(xmlStr);

	return doc;
}//loadTextXML



//xsl ÆÄÀÏ ·ÎµåÇÑ °´Ã¼ ¸®ÅÏ
function xslLoad(xslFile, async)
{
	var xsl = createXMLDom();
	xsl.async = async;
	xsl.load(xslFile);

	return xsl;
}//xslLoad



function newDom(root)
{
	var dom = createXMLDom();
	var newEmt = dom.createElement(root);
	dom.appendChild(newEmt);
	return dom;

}//newDom




//º°µµÀÇ xml class ¸¦ »ç¿ëÇÏÁö ¾Ê°í xslt ¸¦ È­¸é¿¡ ³ëÃâ ½ÃÅ°±â À§ÇÑ ÇÔ¼ö
function applyXslt(target, xmlDom, xslt)
{
	var obj = document.all[target];

	if(xmlDom == undefined || xmlDom == null || xmlDom == "")
	{
		var xmlDom = createXMLDom();
		obj.innerHTML = xmlDom.transformNode(xslLoad(xslt,false));
	}
	else
	{
		obj.innerHTML = xmlDom.transformNode(xslLoad(xslt,false));
	}

}//applyXslt




/*================================================================================================*/
//Direct XML Interaction,
/*================================================================================================*/

// Normal Direct XML Interaction
function InteractionXML()
{


	function processTr(url, params, func)
	{
		var xmlHttp = createXMLHttp();


		if(func == null || func == undefined) xmlHttp.open ( "POST", url , false );
		else xmlHttp.open ( "POST", url , true );

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

		if(func == null || func == undefined)
		{
			return xmlHttp.responseXML;
		}
		else
		{
			xmlHttp.onreadystatechange = function()
			{
				if ( xmlHttp.readyState == 4 )
				{
					var	doc	= xmlHttp.responseXML;
					eval ( func + '(doc)' );
					return;
				}
			}
		}

	}//processTr



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

		var	xmlhttp;
		var	url = "http://" + window.location.host + "/ksgate/run/"+tr+".xml?"+Math.random();

		try
		{
			var rtn = processTr ( url, param, func);

			if(func == null || func == undefined)
			{
				return rtn;
			}


		}
		catch ( e )
		{
			errMsg = 'Åë½ÅÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù. [MSXML]\n\n°í°´Áö¿ø¼¾Å¸·Î ¿¬¶ô ¹Ù¶ø´Ï´Ù.(1544-8282)\n\n* TR: ' + tr;
			window.setTimeout( "alertMsg();", 500);
		}

		window.status='communication complete.';

	}//execute



	function isLogin()
	{
		var tmp = this.execute('hts/login/isLogin', new DataSet() );
		var output = new DomDataSet(tmp);

		if(output.get("isLogin") == "true") return true;
		else return false;
	}




	function iDefense()
	{
		var tmp = this.execute('hts/login/iDefense', new DataSet() );
		var output = new DomDataSet(tmp);

		if(output.get("firewallflag") == "Y") return true;
		else return false;
	}




	this.execute = execute;
	this.isLogin = isLogin;
	this.iDefense = iDefense;

}//InteractionXML





/*================================================================================================*/

// Xecure Direct XML Interaction
function XInteractionXML()
{
	// ¾ÏÈ£È­ Client »ý¼º
	loadXecureWebClient();

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




	function processTr(url, params, func)
	{
		var xmlHttp = createXMLHttp();


		if(func == null || func == undefined) xmlHttp.open ( "POST", url , false );
		else xmlHttp.open ( "POST", url , true );

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



		if(func == null || func == undefined)
		{
			var	orgXml		= xmlHttp.responseXML;
			var enc_text	= orgXml.documentElement.text;
			var plain_text  = BlockDec(enc_text);
			var doc = createXMLDom();
				doc.async = false;
				doc.loadXML(plain_text);

			return doc;

		}
		else
		{
			xmlHttp.onreadystatechange = function()
			{
				if ( xmlHttp.readyState == 4 )
				{

					var	orgXml		= xmlHttp.responseXML;
					if(( orgXml.documentElement) == null) return;
					var enc_text	= orgXml.documentElement.text;
					var plain_text  = BlockDec(enc_text);
					var doc = createXMLDom();
						doc.async = false;
						doc.loadXML(plain_text);
					eval ( func + '(doc)' );
					return;
				}
			}
		}

	}//processTr




	function execute(tr, input, func)
	{
		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	= sign( pText );

		if( sText != '' )
		{
			param += '&orgdata=' +  escape_url( encodeURL( '' + pText) ) + '&signdata=' + escape_url( encodeURL( '' + sText) );
		}
		var cipher	= document.getElementById('XecureWeb').BlockEnc( xgate_addr, urlPath, XecureEscape(param), "GET" );

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


		try
		{
			var doc = processTr(url, ppm, func);

			if(func == undefined || func == null)
			{
				document.body.style.cursor = '';
				return doc;
			}

		}
		catch ( e )
		{
			errMsg = 'Åë½ÅÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù. [MSXML]\n\n°í°´Áö¿ø¼¾Å¸·Î ¿¬¶ô ¹Ù¶ø´Ï´Ù.(1544-8282)\n\n* TR: ' + tr;
//				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 null;

	}//execute



	function login( input )
	{
			document.body.style.cursor = 'wait';
			var urlPath = "http://" + window.location.host + "/ksgate/login/hts/login/LOGIN.xml";
			var	param	= input.getParam();

			var cipher	= document.getElementById('XecureWeb').BlockEnc ( xgate_addr, urlPath, XecureEscape(param), "GET" );

			var	xmlhttp;
			var	url		= urlPath;
			var params	= "q=" + escape_url(cipher) + "&" + Math.random()

			try
			{
				var doc = processTr(url, params);
				document.body.style.cursor = '';
				return doc;
			}
			catch ( e )
			{
				errMsg = 'Åë½ÅÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù. [MSXML]\n\n°í°´Áö¿ø¼¾Å¸·Î ¿¬¶ô ¹Ù¶ø´Ï´Ù.(1544-8282)\n\n* TR: login';
				window.setTimeout( "alertMsg();", 500);
			}
			window.status='communication complete.';
			document.body.style.cursor = '';
			return null;

	}//login


	function sign(data)
	{
		var signdata = '';
		if ( typeof(userDN) != 'undefined' && userDN != '' && typeof(document.getElementById('CertManX')) != 'undefined' )
		{

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

			if(document.getElementById('CertManX').SetServiceMode('ÇÑÈ­Áõ±Ç', userDN) == false)
			{
				alert('[KX1]'+document.getElementById('CertManX').GetLastErrorMsg());
			}
			
			// DN¿¡ ÇØ´çÇÏ´Â ÀÎÁõ¼­¸¸ ¼±ÅÃÃ¢¿¡ Ç¥½Ã, ¼¼¼Ç°ü¸®ÀÚ¿¡¼­ ¼±ÅÃÇÑ ÀÎÁõ¼­ Á¤º¸À¯Áö
			if(document.getElementById('CertManX').SetMatchedContextExt(userDN, '' , '', 0) == '')
			{
				alert('[KX2]'+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;
	}//sign



	function isLogin()
	{
		var tmp = this.execute('hts/login/isLogin', new DataSet() );
		var output = new DomDataSet(tmp);

		if(output.get("isLogin") == "true") return true;
		else return false;

	}//isLogin



	function iDefense()
	{
		var tmp = this.execute('hts/login/iDefense', new DataSet() );
		var output = new DomDataSet(tmp);

		if(output.get("firewallflag") == "Y") return true;
		else return false;
	}



	this.execute = execute;
	this.isLogin = isLogin;
	this.iDefense = iDefense;
	this.login = login;

}//XInteractionXML








/*================================================================================================*/

// E2E XML Interaction
function E2EInteractionXML()
{


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

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



	function processTr(url, params, func)
	{
		var xmlHttp = createXMLHttp();


		if(func == null || func == undefined) xmlHttp.open ( "POST", url , false );
		else xmlHttp.open ( "POST", url , true );

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



		if(func == null || func == undefined)
		{
			var	orgXml		= xmlHttp.responseXML;
			var enc_text	= orgXml.documentElement.text;
			var plain_text  = BlockDec(enc_text);
			var doc = createXMLDom();
				doc.async = false;
				doc.loadXML(plain_text);

			return doc;

		}
		else
		{
			xmlHttp.onreadystatechange = function()
			{
				if ( xmlHttp.readyState == 4 )
				{

					var	orgXml		= xmlHttp.responseXML;
					var enc_text	= orgXml.documentElement.text;
					var plain_text  = BlockDec(enc_text);
					var doc = createXMLDom();
						doc.async = false;
						doc.loadXML(plain_text);
					eval ( func + '(doc)' );
					return;
				}
			}
		}

	}//processTr




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

		var	param	= input.getParam(false);

		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	= document.getElementById('XecureWeb').BlockEnc( xgate_addr, urlPath, XecureEscape(param), "GET" );

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



		try
		{
			var doc = processTr(url, ppm, func);

			if(func == undefined || func == null)
			{
				document.body.style.cursor = '';
				return doc;
			}

		}
		catch ( e )
		{
			errMsg = 'Åë½ÅÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù. [MSXML]\n\n°í°´Áö¿ø¼¾Å¸·Î ¿¬¶ô ¹Ù¶ø´Ï´Ù.(1544-8282)\n\n* TR: ' + tr;
//				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 null;

	}//execute



	function login( input )
	{
			document.body.style.cursor = 'wait';
			var urlPath = "http://" + window.location.host + "/ksgate/login/hts/login/LOGIN.xml";
			var	param	= input.getParam();

			var cipher	= document.getElementById('XecureWeb').BlockEnc ( xgate_addr, urlPath, XecureEscape(param), "GET" );

			var	xmlhttp;
			var	url		= urlPath;
			var params	= "q=" + escape_url(cipher) + "&" + Math.random()

			try
			{
				var doc = processTr(url, params);
				document.body.style.cursor = '';
				return doc;
			}
			catch ( e )
			{
				errMsg = 'Åë½ÅÁß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù. [MSXML]\n\n°í°´Áö¿ø¼¾Å¸·Î ¿¬¶ô ¹Ù¶ø´Ï´Ù.(1544-8282)\n\n* TR: login';
				window.setTimeout( "alertMsg();", 500);
			}
			window.status='communication complete.';
			document.body.style.cursor = '';
			return null;

	}//login


	function sign(data)
	{
		var signdata = '';
		if( typeof(userDN) != 'undefined' && userDN != '' && typeof(document.getElementById('CertManX')) != 'undefined' )
		{
			if(document.getElementById('CertManX').SetServiceMode('ÇÑÈ­Áõ±Ç', userDN) == false)
			{
				alert(document.getElementById('CertManX').GetLastErrorMsg());
			}
			
			// DN¿¡ ÇØ´çÇÏ´Â ÀÎÁõ¼­¸¸ ¼±ÅÃÃ¢¿¡ Ç¥½Ã, ¼¼¼Ç°ü¸®ÀÚ¿¡¼­ ¼±ÅÃÇÑ ÀÎÁõ¼­ Á¤º¸À¯Áö
			if(document.getElementById('CertManX').SetMatchedContextExt(userDN, '' , '', 0) == '')
			{
				alert(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;
	}//sign



	function isLogin()
	{
		var tmp = this.execute('hts/login/isLogin', new DataSet() );
		var output = new DomDataSet(tmp);

		if(output.get("isLogin") == "true") return true;
		else return false;

	}//isLogin



	function iDefense()
	{
		var tmp = this.execute('hts/login/iDefense', new DataSet() );
		var output = new DomDataSet(tmp);

		if(output.get("firewallflag") == "Y") return true;
		else return false;
	}



	this.execute = execute;
	this.isLogin = isLogin;
	this.iDefense = iDefense;
	this.login = login;

}//E2EInteractionXML








/*================================================================================================*/
// DomDataSet : ±âÁ¸ Object DataSet°ú ÇÔ¼ö¸í µ¿ÀÏÇÏ°Ô À¯Áö
/*================================================================================================*/



//xml dom È°¿ëÀ» À§ÇÑ dataset class
function DomDataSet(xmlDom)
{

	this.xmlDom = xmlDom;
	this.root = xmlDom.documentElement;




	//idx ¹øÂ° keyElementÀÇ text ¸®ÅÏ
	function get(key, idx)
	{
		var dList = this.xmlDom.getElementsByTagName(key);

		if(!dList) return '';
		if(idx == null ) idx = 0;
		var val;

		try
		{
			val = dList[idx].firstChild.nodeValue;
			//val = dList.item(idx).text;
			
		}
		catch (e)
		{
			return '';
		}

		return val.toString().replace(/(^\s*)|(\s*$)/g, "");
	}



	//idx ¹øÂ° keyElement ¸®ÅÏ
	function getEmt(key, idx)
	{
		var dList = this.xmlDom.getElementsByTagName(key);

		if(!dList) return '';
		if(idx == null ) idx = 0;

		return dList.item(idx);
	}



	//keyElement Ä«¿îÆ® ¸®ÅÏ
	function getCount(key)
	{
		var dList = this.xmlDom.getElementsByTagName(key);
		if(!dList) return 0;
		return dList.length;
	}



	//keyElement Ãß°¡
	function put(key, content)
	{
		var newEmt = this.xmlDom.createElement(key);
		var textnode = this.xmlDom.createTextNode(content);
		newEmt.appendChild(textnode);
		this.root.appendChild(newEmt);
	}



	//keyElement °´Ã¼ »ý¼ºÈÄ ¸®ÅÏ
	function getNewEmt(key, content)
	{
		var newEmt = this.xmlDom.createElement(key);
		var textnode = this.xmlDom.createTextNode(content);
		newEmt.appendChild(textnode);

		return newEmt;
	}



	//oldEmt¸¦ newEmt·á ±³Ã¼
	function replace(newEmt, oldEmt)
	{
		this.root.replaceChild(newEmt, oldEmt);
	}




	//keyElement °¡ ÀÖÀ¸¸é replace ¾øÀ¸¸é put
	function merge(key, content)
	{
		if(this.getCount(key) > 0) this.replace(this.getNewEmt(key, content), this.getEmt(key));
		else this.put(key, content);
	}



	//dom xml ¸®ÅÏ
	function getDom()
	{
		return this.xmlDom;
	}



	//xml È­¸é Ãâ·Â
	function debug()
	{
		alert(this.xmlDom.xml);
	}



	//xslt Çü½Ä¿¡ ¸Â°Ô transform
	function transform(target, xslt)
	{
		if (typeof(document.all[target]) == 'undefined') return;
		document.all[target].innerHTML = this.xmlDom.transformNode(xslLoad(xslt,false));
	}


	function domMerge(addDom)
	{
		var dom = addDom.documentElement;
		var domChild = dom.childNodes;
		var cnt = domChild.length;

		for(var i=0 ; i<cnt ; ++i)
		{
			var xml = createXMLDom();
			xml.loadXML(domChild.item(i).xml);
			this.root.appendChild(xml.documentElement);
		}
	}




	function domMerge2(addDom)
	{
		var dom = addDom.documentElement;
		var result = dom.childNodes;

		if(result.item(0).nodeName == "result")
		{
			var domChild = result.item(0).childNodes;
			var cnt = domChild.length;

			for(var i=0 ; i<cnt ; ++i)
			{
				var xml = createXMLDom();
				xml.loadXML(domChild.item(i).xml);
				this.root.childNodes.item(0).appendChild(xml.documentElement);
			}
		}
	}



	function domMergeWrap(addDom)
	{
		this.root.appendChild(addDom.documentElement);
	}

	//¹«Á¶°Ç 0¹øÂ°ÀÇ ¿¤¸®¸ÕÆ®¸¦ »ý¼ºÇÑ´Ù.
	//ex) zput("targetfg","false");
	function zput(key,value){
		var dList = this.xmlDom.getElementsByTagName(key);

		if (!dList || dList.length == 0 ) {

			var newEmt = this.xmlDom.createElement(key);
			var textnode = this.xmlDom.createTextNode(value);
			newEmt.appendChild(textnode);
			this.root.appendChild(newEmt);
		}else{
			//alert(dList.length);
			dList.item(0).text = value;
		}
	}


	this.get				= get;
	this.getEmt			= getEmt;
	this.getCount		= getCount;
	this.put				= put;
	this.getNewEmt	= getNewEmt;
	this.replace		= replace;
	this.merge			= merge;
	this.getDom		= getDom;
	this.transform		= transform;
	this.debug		    = debug;
	this.domMerge		= domMerge;
	this.domMergeWrap		= domMergeWrap;
	this.zput		= zput;

}//class DomDataset




/*================================================================================================*/
// ÆäÀÌÁö ÀÎÀÚ°ªÀ» »ç¿ëÇÏ±â ÆíÇÏ°Ô arguSearch ¿¡ ³Ö´Â´Ù.
/*================================================================================================*/

	var arguSearch = 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	= arguSearch.getCount(v_name);
				arguSearch.put ( v_name, v_value , v_nameCnt );
			}
		}
	}
	catch ( EEE )
	{
		alert('[XML]'+EEE.description);
	}

