//
// INIplugn-128 Java Script
// 1. update 2002/01/29 wakano@initech.com
//  - ½ÅÇÑÀºÇà È£È¯ ¸Þ¼Òµå ±â´É Ãß°¡.
//		EncryptInput(form)     => EncForm
//		EncryptInput2(form, r) => EncFormVerify
//		À§ ¸Þ¼Òµå »ç¿ë½Ã ³»ºÎÀûÀ¸·Î ShinHan_plugin º¯¼ö¸¦ »ç¿ëÇÏ¿© Ã³¸®µÊ
//	-. INIpluginData¾øÀÌ EcnForm.. »ç¿ë½Ã ¿¡·¯Ã³¸®
//
// 2. update 2002/03/13 wakano@initech.com
//  - ¿¡ÇÃ¸´ÀÌ³ª ÇÃ·¹½¬ °°Àº°ÍÀº elementsÀÇ °ªÀÌ "" ÀÏ°æ¿ì°¡ ÀÖÀ½
//		if(element.name=="") continue;
//
// 3. update 2002/11/30 wakano@initech.com
//  - GatherValeu¿¡¼­ element.typeÀÌ "select"ÀÏ°æ¿ì ¾ÏÈ£È­µÈ ¿øº»ÀÌ »èÁ¦µÇÁö ¾Ê´Â ¹ö±×¼öÁ¤
//
// 4. update 2002/06/11 brson@initech.com
//  -. GatherValue, EncLink, EncLocation ¼öÁ¤
//		:AddServerTimeÀÌ trueÀÏ¶§ TimeURL¿¡¼­ server½Ã°£ ¾ò¾î¼­ µ¥ÀÌÅ¸·Î Ãß°¡ÇÔ.
//
// 5. update 2004/07/29 wakano@initech.com
//	-. iframe»ç¿ë½Ã ÇÁ·¹ÀÓ¸í(secureframe)°ú Àü¿ªº¯¼ö¸íÀÌ Ãæµ¹·Î ÀÎÇÏ¿© secureframeÀ» Ã£Áö ¸øÇÏ´Â ¹ö±×¼öÁ¤
//	   (Àü¿ªº¯¼ö·Î ¼±¾ðµÈ secureframe¸¦ __secureframe__·Î º¯°æ)
//
// 6. update 2005/09/07 smgrl@initech.com
//      -. GatherValue ¹ö±× ¼öÁ¤, ±×¿Ü ÁÖ¼®µé Á¤¸®  
//
// 7. ÀüÀÚ¼¼±Ý°è»ê¼­ ¹ß±Þ/Àç¹ß±Þ/°»½Å ¿ë ÇÔ¼ö Ãß°¡ (2010/01/15)
// 

var TimeURL = "http://" + window.location.host + "/initech/plugin/tools/Time.jsp";       // ¾àÇÑ Replay-Attack ¹æÁö(JSP)
//var TimeURL = "http://" + window.location.host + "/initech/plugin/tools/Time.asp";       // ¾àÇÑ Replay-Attack ¹æÁö(ASP)
//var TimeURL = "http://" + window.location.host + "/initech/plugin/tools/Random.jsp";   // °­ÇÑ Replay-Attack ¹æÁö(JSP ¸¸ ÀÖÀ½)  

var E2ERandomURL = "http://"+ window.location.host + "/initech/plugin/tools/E2E_Random.jsp";
// var E2ERandomURL = "http://172.16.201.110/initech/plugin/tools/E2E_Random.jsp";

var LogoURL = 'http://' + window.location.host + '/initech/plugin/site/img/kdb_ci.jpg';


/*
// ±Ý°á¿ø TEST CAIP
var YessignCAIP = "203.233.91.231";     // 2048 Å×½ºÆ® ÀÎÁõ¼­ °ü·Ã
var YessignCMPPort = "4512";
// ÀüÀÚÀÎÁõ TEST CAIP
var CrossCertCAIP = "211.180.234.201";  // 2048 Å×½ºÆ® ÀÎÁõ¼­ °ü·Ã
var CrossCMPPort = "4512";  
*/

// ±Ý°á¿ø REAL CAIP
var YessignCAIP = "203.233.91.71";
var YessignCMPPort = 4512;
// ÀüÀÚÀÎÁõ REAL CAIP
var CrossCertCAIP = "211.192.169.90";
var CrossCMPPort = "4512";

var cipher = "SEED-CBC";
var InitechPackage = "INITECH";
var YessignPackage = "YESSIGN";
var CrossCertPackage = "CROSSCERT";

var STORAGE2 = "HDD|FDD|USB|SCARD|PHONE";
//var STORAGE2 = "USB|SCARD|FDD|PHONE";

var EnableMsg = true;
var secureframename="secureframe";
var __secureframe__=null;
var framecount = 0;
var maxframecount = 10;
var ShinHan_plugin = false;
//var ShinHan_plugin = true;
var AddServerTime=false;

var secureframe_errmsg = "¾ÏÈ£È­¸ðµâÀÌ Á¤»óÀûÀ¸·Î ·ÎµùµÇÁö ¾Ê¾Ò½À´Ï´Ù.\n\n";
secureframe_errmsg += "Áñ°ÜÃ£±â¿¡¼­ »ê¾÷ÀºÇà »èÁ¦ ÈÄ ´Ù½Ã Ãß°¡ÇÏ¿© »ç¿ëÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.\n\n";
secureframe_errmsg += "µ¿ÀÏÇÑ ¹®Á¦°¡ °è¼Ó ¹ß»ýÇÒ °æ¿ì ÄÝ¼¾ÅÍ(1588-1500)·Î ¹®ÀÇ ¹Ù¶ø´Ï´Ù.";

//var secureframe_errmsg = "¾ÏÈ£È­ÇÁ·¹ÀÓ(secureframe)À» Ã£À»¼ö ¾ø½À´Ï´Ù.";

//20070803 ÆË¾÷ ¹× ¸ð´ÞÃ¢°ü·Ã ¼öÁ¤  
function FindSecureFrame(inframe)
{
	if(__secureframe__!=null) return __secureframe__;
	if (framecount++ > maxframecount) return null;
	if ((typeof inframe == "undefined") || (inframe == null))
	{
		return null;
	}
	else if ((typeof inframe.secureframe != "undefined")  && (inframe.secureframe != null))
	{
		framecount = 0;
		return inframe.secureframe
	} 
	else if (inframe.parent.frames.length > 0) 
	{
		
		if(inframe != inframe.parent)
		{
			return FindSecureFrame(inframe.parent);
		}
	}
    	return null;
}
//20070803 ÆË¾÷ ¹× ¸ð´ÞÃ¢°ü·Ã ¼öÁ¤  
function FrameCheck()
{
	if (typeof document.INIplugin != "undefined") 
	{
		__secureframe__ = self;
	} 
	else 
	{
		framecount = 0;		
		__secureframe__ = FindSecureFrame(parent);
		
		//ÆË¾÷,¸ð´Þ ÆË¾÷Ã¢ÀÎ °æ¿ì Ãß°¡  
		//¸ð´ÞÃ¢À» »ý¼º½Ã window°³Ã¼¸¦ Arguments·Î Àü´ÞÇßÀ»°æ¿ì »ç¿ë°¡´É  
		if (__secureframe__ == null) {
			var open_frame = null;
			open_frame = top.opener;

			//opener°¡ ¾øÀ»°æ¿ì ¸ð´ÞÃ¢À¸·Î ÆÇ´Ü ¸ð´ÞÃ¢À¸·Î ³Ñ°Ü¹ÞÀº À©µµ¿ì °³Ã¼¸¦ open_frameÀ¸·Î ¼³Á¤  
			if ((typeof open_frame) == "undefined" && (typeof window.dialogArguments)!="undefined")
			{
				if (typeof(window.dialogArguments.parent_frame) == "object") {
					open_frame = window.dialogArguments.parent_frame;			// param °´Ã¼¾È¿¡ self °¡ ÀúÀåÇÑ °æ¿ì
				} else {
					open_frame = window.dialogArguments;						// param ÀÌ selfÀÎ °æ¿ì 
				}
				
				//alert(typeof(open_frame));
//				open_frame = document.self;
			}
			//ÃÖ»óÀ§ opener±îÁö Ã£¾Æ°£´Ù.  
			while((typeof open_frame) != "undefined")
			{
				 if((typeof open_frame.document) == "unknown"){break;}//opener°¡ Á¸ÀçÇÏ´ÂÁö ¿©ºÎ Ã¼Å©  
				framecount = 0;
				 __secureframe__ = FindSecureFrame(open_frame);
				 
				if (__secureframe__ != null){
					break;
				}else{							
					var t_open_frame = open_frame;
					open_frame = open_frame.top.opener;

					if ((typeof open_frame) == "undefined" && (typeof t_open_frame.window.dialogArguments)!="undefined")//opener°¡ ¾øÀ»°æ¿ì ¸ð´ÞÀ¸·Î ÆÇ´Ü  
					{
						open_frame = t_open_frame.window.dialogArguments;
					}
				}
			}
		}
	}
}


function ModuleInstallCheck()
{
	FrameCheck();
	if (__secureframe__==null) return;

	if(navigator.appName == "Netscape")
	{
		return __secureframe__.document.INIplugin;
	}

	else
	{
//alert("=>"+__secureframe__.INIplugin);
		//alert(__secureframe__.INIplugin +"||"+typeof(__secureframe__.INIplugin)+"||"+ __secureframe__.INIplugin.object);
		if(__secureframe__.INIplugin==null || typeof(__secureframe__.INIplugin) == "undefined" || __secureframe__.INIplugin.object==null) return null;
		else return __secureframe__.INIplugin;
	}
}

/*function ModuleInstallCheck()
{
	FrameCheck();
	if (__secureframe__==null) return;
	if(navigator.appName == "Netscape") {
		return __secureframe__.document.INIplugin;
	} else {
		// IE8 ¼öÁ¤
		var ua = window.navigator.userAgent;

		if(ua.indexOf('Trident/4.0') >= 0){ // IE 8.0 ÀÎ °æ¿ì. 

			if(opener!=null){				
				if ( "undefined" == typeof( opener.ModuleInstallCheck ) ) {
					if(__secureframe__.INIplugin==null || typeof(__secureframe__.INIplugin) == "undefined" || __secureframe__.INIplugin.object==null) {
						return null;
					} else {
						return __secureframe__.INIplugin;
					}
				} else {
					// »çÀÌÆ® µµ¸ÞÀÎÀ» ÁöÁ¤ÇÑ´Ù.
					window.document.domain = "kdb.co.kr"; 
					return opener.ModuleInstallCheck();
					//alert("http://10.1.8.117:7031");
					//self.opener.location='http://10.1.8.117:7031'; 
					//return self.ModuleInstallCheck();
				}
			} else {
				if(__secureframe__.INIplugin==null || typeof(__secureframe__.INIplugin) == "undefined" || __secureframe__.INIplugin.object==null) return null;
				else return __secureframe__.INIplugin;	
			}
		} else {
			if (__secureframe__.INIplugin==null || typeof(__secureframe__.INIplugin) == "undefined" || __secureframe__.INIplugin.object==null) {
				return null;
			} else {
				return __secureframe__.INIplugin;
			}
		}
	}
}*/


function GatherValue(form, start, bErase)
{
	var strResult = "";
	var name = "";
	var value = "";
	var sel=0;

	// INIplugin-128 Install Check
	obj = ModuleInstallCheck();
	if (obj == null) return "";
	
	len = form.elements.length;
	for(i=start; i<len; i++) 
	{
		element = form.elements[i];

		//add to wakano 2002/03/13
		if(element.name=="") continue;
		if(element.name=="INIpluginData") continue;
		//add to smgrl 2004/06/22
		if(element.name=="filedata") continue;

		if ((ShinHan_plugin) && (element.name=="input")) // with for Shinhan Bank 
			continue;
		if (!((form.elements[i].type != "button") && (form.elements[i].type != "reset") && (form.elements[i].type != "submit"))) 
			continue;

		if ( ((element.type == "radio") || (element.type == "checkbox")) && (element.checked!=true) ) 
			continue;
		// File Field´Â SKIPÇÑ´Ù.  
     	//KDB¿ëÀ¸·Î ¼öÁ¤ÇÔ 	if(form.elements[i].name.indexOf('file_', 0) >= 0) {
		/*if(form.elements[i].name.indexOf('file_', 0) >= 0) {
			continue;
        	}*/

		if (element.type == "select-one") {
			sel = element.selectedIndex;
			if(sel<0) continue;
      //2007.04.19 ¼öÁ¤ select box ±¸Çö½Ã value °ªÀÌ ""ÀÎ°æ¿ì ¼­¹ö¿¡´Â text°ªÀÌ value·Î ³Ñ¾î°¡´Â Çö»ó ¼öÁ¤  
      value = element.options[sel].value;
			/*if (element.options[sel].value != ''){	
				value = element.options[sel].value;
			} else {
				//value = element.options[sel].text;
                                value = '';
			}*/
			if(bErase) element.selectedIndex = -1;
		} else{
			value = element.value;
			if(bErase && !((element.type == "radio") || (element.type == "checkbox"))) element.value = "";
		}
		
		//add to smgrl 2004/06/29
		if(element.type == "select-multiple") {
			var j;
			
			for(j=0;j<element.options.length;j++){
				if(element.options[j].selected==true){
					if(strResult!="") strResult += "&";
					if(element.id=="")
						strResult += element.name;
					else
						strResult += element.id;
					strResult += "=";
					strResult += obj.URLEncode(element.options[j].value);
					if(bErase) element.options[j].select=false;
				}
			}
			if(bErase) element.selectedIndex = -1;
			continue;
		}

		// modify wakano 2001/08/21
		if ((element.type == "checkbox") && (bErase)) element.checked = false;

		if (strResult!="") strResult += "&";

		// modify brson 2002/06/11 check element.name
		/*
		if(element.name!=""){
			if(element.id=="")
				strResult += element.name;
			else
				strResult += element.id;
			strResult += "=";
			strResult += obj.URLEncode(value);
		}
		*/
		// 2007.05.03 ¼öÁ¤ element.name default (id°¡ ¾Æ´Ï¶ó nameÀ» ½á¾ß¸¸ HTML ±Ô°Ý¿¡ ¸ÂÀ½)  
    strResult += element.name;
    strResult += "=";
    strResult += obj.URLEncode(value);

	}

	//modify brson 2002/06/11 
	//dt¿¡ server time Ãß°¡  
	var ver="4,2,0,0";
	if(AddServerTime && EnableFunction(ver)) {
		if(strResult!=""){
				strResult = "__INIts__=" + obj.GetServerTime(TimeURL) + "&" + strResult;
		}
		else{
				strResult = "__INIts__=" + obj.GetServerTime(TimeURL);
		}
	}

	return strResult;
}

function GatherFileValue(form, start, bErase)
{
	var strResult = "";
	var name = "";
	var value = "";
	var sel=0;

	// INIplugin-128 Install Check
	obj = ModuleInstallCheck();
	if (obj == null) return "";
	
	len = form.elements.length;
	for(i=start; i<len; i++) 
	{
		element = form.elements[i];

		//add to wakano 2002/03/13
		if(element.name=="") continue;
		if(element.name=="INIpluginData") continue;
		if(element.name=="filedata") continue;

		if ((ShinHan_plugin) && (element.name=="input")) // with for Shinhan Bank 
			continue;
		if (!((form.elements[i].type != "button") && (form.elements[i].type != "reset") && (form.elements[i].type != "submit"))) 
			continue;

		if ( ((element.type == "radio") || (element.type == "checkbox")) && (element.checked!=true) ) 
			continue;
		// File Field
        	/*if(form.elements[i].name.indexOf('file_', 0)>=0)
		{
	       		 if(strResult!="")
			{
 	        		strResult += "&";
            		}
            		strResult+= form.elements[i].name;
            		strResult += "=";
            		strResult += obj.URLEncode(form.elements[i].value);
			if(bErase) form.elements[i].value = "";
 		}*/
	}
	return strResult;
}

// make for Shinhan Bank
function EncryptInput(form)
{	
	ShinHan_plugin = true;
	return EncForm(form);
}

function EncryptInput2(form, r)
{
	ShinHan_plugin = true;
	return EncFormVerify(form);
}

function EncForm(form) 
{
	var INIdata = "";
	var eletemp = "";
	var filetemp = "";

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}

	filetemp = GatherFileValue(form, 0, true);
	if (filetemp !=  "")
	{
		if ((form.filedata.value = obj.MakeFileData(10, cipher, filetemp)) == "") return false; 
	}

	eletemp = GatherValue(form, 0, true);
	
	// 2011.01.27 °íµµÈ­ °ü·Ã Ãß°¡
	if ((INIdata = obj.MakeINIpluginData(10, cipher, eletemp, TimeURL))=="") return false;
	//if ((INIdata = obj.MakeINIpluginData(0, cipher, eletemp, ""))=="") return false;

	//add bye wakano 2001/01/29
	if (typeof form.INIpluginData == "undefined") 
	{
		if (ShinHan_plugin) // with for Shinhan Bank 
		{
			form.input.value = INIdata;
			form.input.name = "INIpluginData"; // for Shinhan Bank
		} else {
			alert("INIpluginData(form.name)°¡ ÇÊ¿äÇÕ´Ï´Ù.");
			return false;
		}
	} else {
		form.INIpluginData.value = INIdata;
	}

	//alert("¾ÏÈ£È­µÈ µ¥ÀÌÅ¸ : [" + INIdata + "]");
	return true;
}

function EncForm2(form1, form2) 
{
	var INIdata = "";
	var eletemp = "";
	var filetemp = "";
	
	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}

	filetemp = GatherFileValue(form1, 0, false);

	if (filetemp !=  "") 
	{
		if ((form2.filedata.value = obj.MakeFileData(10, cipher, filetemp)) == "") return false; 
	}

	eletemp = GatherValue(form1, 0, false);
	
	// 2011.01.27 °íµµÈ­ °ü·Ã Ãß°¡
	if ((INIdata = obj.MakeINIpluginData(10, cipher, eletemp, TimeURL))=="") return false;
	//if ((INIdata = obj.MakeINIpluginData(0, cipher, eletemp, ""))=="") return false;

	//add bye wakano 2001/01/29	
	if (typeof form2.INIpluginData == "undefined") 
	{
		if (ShinHan_plugin) // with for Shinhan Bank 
		{
			form2.input.value = INIdata;
			form2.input.name = "INIpluginData"; // for Shinhan Bank
		} else {
			alert("INIpluginData(form.name)°¡ ÇÊ¿äÇÕ´Ï´Ù.");
			return false;
		}
	} else {
		form2.INIpluginData.value = INIdata;
	}

   	return true;
}



function Idecrypt(data)
{
	var decdata = "";
	var obj = ModuleInstallCheck();

	if (obj == null) return "";
	
	//alert("º¹È£È­ÇÏ±âÀü µ¥ÀÌÅ¸ : [" + data + "]");

	if (navigator.appName == 'Netscape') 
		decdata = unescape(obj.Decrypt(cipher, data));
	else
		decdata = obj.Decrypt(cipher, data);

	//alert("º¹È£È­µÈ µ¥ÀÌÅ¸ : [" + decdata + "]");

	return decdata;
}

function Idecrypt2(data)
{
	obj = ModuleInstallCheck();
	if (obj == null) return "";
	
	if (navigator.appName == 'Netscape') 
		return unescape(obj.Decrypt2(cipher, data));
	else
		return obj.Decrypt2(cipher, data);
}

//¾ÐÃà+¾ÏÈ£È­ µÈ ³»¿ëÀ» º¹È£È­ ÇÏ¿© ¸®ÅÏÇÔ.(by Seon Jong Kim.)
function IdecryptWithGunzip(data)
{
	var decdata = "";
	obj = ModuleInstallCheck();
	if (obj == null) return "";

	var ver = "5, 1, 6, 1";
	if(!EnableFunction(ver)) {
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â º» ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg) alert(msg);
		return false;
	}
	
	if (navigator.appName == 'Netscape') 
		decdata = unescape(obj.DecryptWithGunzip(cipher, data));
	else
		decdata = obj.DecryptWithGunzip(cipher, data);

	return decdata;
}

function EncFormVerify(form) 
{
	var INIdata = "";
	var eletemp = "";
	var filetemp = "";
	var Random = TimeURL; 

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}

	filetemp = GatherFileValue(form, 0, true);
	if (filetemp !=  "") 
	{
		if ((form.filedata.value = obj.MakeFileData(11, cipher, filetemp)) == "") return false; 
	}
	
	eletemp = GatherValue(form, 0, true);
	// 2011.01.27 °íµµÈ­ °ü·Ã Ãß°¡
	if ((INIdata = obj.MakeINIpluginData(11, cipher, eletemp, Random))=="") return false;
	//if ((INIdata = obj.MakeINIpluginData(1, cipher, eletemp, Random))=="") return false;

	//add bye wakano 2001/01/29
	if (typeof form.INIpluginData == "undefined") 
	{
		if (ShinHan_plugin) // with for Shinhan Bank 
		{
			form.input.value = INIdata;
			form.input.name = "INIpluginData"; // for Shinhan Bank
		} else {
			alert("INIpluginData(form.name)°¡ ÇÊ¿äÇÕ´Ï´Ù.");
			return false;
		}
	} else {
		form.INIpluginData.value = INIdata;
	}
    
   	return true;
}

function EncFormVerify2(form1, form2)
{
	var INIdata = "";
	var eletemp = "";
	var filetemp = "";
	var Random = TimeURL;

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}
		
	filetemp = GatherFileValue(form1, 0, false);
	if (filetemp !=  "") 
	{
		if ((form2.filedata.value = obj.MakeFileData(11, cipher, filetemp)) == "") return false; 
	}
	
	eletemp = GatherValue(form1, 0, false);
	// 2011.01.27 °íµµÈ­ °ü·Ã Ãß°¡
	if ((INIdata = obj.MakeINIpluginData(11, cipher, eletemp, Random))=="") return false;
	//if ((INIdata = obj.MakeINIpluginData(1, cipher, eletemp, Random))=="") return false;
	//add bye wakano 2001/01/29

	if (typeof form2.INIpluginData == "undefined") 
	{
		if (ShinHan_plugin) // with for Shinhan Bank 
		{
			form2.input.value = INIdata;
			form2.input.name = "INIpluginData"; // for Shinhan Bank
		} else {
			alert("INIpluginData(form.name)°¡ ÇÊ¿äÇÕ´Ï´Ù.");
			return false;
		}
	} else {
		form2.INIpluginData.value = INIdata;
	}
	//alert(form2.INIpluginData.value);
   	return true;
}

/* ASP Time Check ¿ë ÇÔ¼ö ÀÓ½Ã¿ëÀÔ´Ï´Ù. */
function imsi_FormVerify(form1, form2)
{
	var INIdata = "";
	var eletemp = "";
	var filetemp = "";
	var TimeURL = "http://" + window.location.host + "/initech/plugin/tools/Time.asp";
	var Random = TimeURL;

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}
	
	filetemp = GatherFileValue(form1, 0, false);
	if (filetemp !=  "") 
	{
		if ((form2.filedata.value = obj.MakeFileData(11, cipher, filetemp)) == "") return false; 
	}

	eletemp = GatherValue(form1, 0, false);
	// °íµµÈ­ °ü·Ã 20110129 lkh
	if((form2.INIpluginData.value = obj.MakeINIpluginData(10, cipher, eletemp, Random))=="") return false;
	if ((INIdata = obj.MakeINIpluginData(10, cipher, eletemp, Random))=="") return false;

	//add bye wakano 2001/01/29
	if (typeof form2.INIpluginData == "undefined") 
	{
		if (ShinHan_plugin) // with for Shinhan Bank 
		{
			form2.input.value = INIdata;
			form2.input.name = "INIpluginData"; // for Shinhan Bank
		} else {
			alert("INIpluginData(form.name)°¡ ÇÊ¿äÇÕ´Ï´Ù.");
			return false;
		}
	} else {
		form2.INIpluginData.value = INIdata;
	}
	
   	return true;
}

function EncLinkVerify(url, encData, target)
{
	var queryString = "INIpluginData=";
	var INIdata;
	var Random = TimeURL;

	obj = ModuleInstallCheck();
	
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}
	// °íµµÈ­ °ü·Ã 20110129
	if((INIdata = obj.MakeINIpluginData(11, cipher, encData, Random))=="") return;
	queryString += obj.URLEncode(INIdata);

	if(url.indexOf('?', 0) < 0) url += "?";
	if((url.charAt(url.length-1)!='?') && (url.charAt(url.length-1)!='&')) url += "&";
	
	url += queryString;
	window.open(url, target);
}

function InsertUserCert(cert)
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;

	return obj.InsertUserCert(InitechPackage, "", cert);
}

function InsertUserCert2(cert, storage)
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;

	return obj.InsertUserCert(InitechPackage, storage, cert);
}

function CertRequest(form)
{
	var dn="";
	var temp=""
	len = form.elements.length;

	form.req.value="";

	obj = ModuleInstallCheck();
	if (obj == null) return false;
	
	for (i = 0; i < len; i++) 
	{
		var name = form.elements[i].name.toUpperCase();
		var temp = form.elements[i].value;
		if(name == "C")	dn = dn + "C=" + obj.URLEncode(temp) + "&";
		if(name == "L")	dn = dn + "L=" + obj.URLEncode(temp) + "&";
		if(name == "O")	dn = dn + "O=" + obj.URLEncode(temp) + "&";
		if(name == "OU") dn = dn + "OU=" + obj.URLEncode(temp) + "&";
		if(name == "CN") dn = dn + "CN=" + obj.URLEncode(temp) + "&";
		if(name == "EMAIL")
		{
			if(temp=="") temp = " ";

			dn = dn + "EMAIL=" + obj.URLEncode(temp) + "&";
		}
	}
	
	//req = obj.CertRequest(InitechPackage, "", dn, form.challenge.value); 
	
	// 2011.02.24 °íµµÈ­ °ü·Ã 
	req = obj.CertRequest(InitechPackage, "HDD|FDD|USB", dn, form.challenge.value);

    if(req=="fail_iKeyUse")  {
	    alert("iKey USB ÀúÀåÀåÄ¡´Â »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.");
    	return false;
	} else if (req=="fail_GetUSBSerial") {
	    alert("USBÀúÀåÀåÄ¡¸¦ ÀÎ½ÄÇÒ¼ö ¾ø½À´Ï´Ù.");
	    return false;
	}
	// 2011.02.24 °íµµÈ­ °ü·Ã Ãß°¡ ³¡

	if(req!="true") return false;
	form.req.value = req;
	
	return true;		
}


function CertRequest2(form)
{
 	var dn="";
	var temp=""
	len = form.elements.length;

	form.req.value="";

	obj = ModuleInstallCheck();
	if (obj == null) return false;
	
	for (i = 0; i < len; i++) 
	{
		var name = form.elements[i].name.toUpperCase();
		var temp = form.elements[i].value;
		if(name == "C")	dn = dn + "C=" + obj.URLEncode(temp) + "&";
		if(name == "L")	dn = dn + "L=" + obj.URLEncode(temp) + "&";
		if(name == "O")	dn = dn + "O=" + obj.URLEncode(temp) + "&";
		if(name == "OU") dn = dn + "OU=" + obj.URLEncode(temp) + "&";
		if(name == "CN") dn = dn + "CN=" + obj.URLEncode(temp) + "&";
		if(name == "EMAIL")
		{
			if(temp=="") temp = " ";

			dn = dn + "EMAIL=" + obj.URLEncode(temp) + "&";
		}
	}
	
	//req = obj.CertRequest2(InitechPackage, "", dn, form.challenge.value); 

	// 2011.02.24 °íµµÈ­ °ü·Ã 
	req = obj.CertRequest2(InitechPackage, "HDD|FDD|USB", dn, form.challenge.value);

    if(req=="fail_iKeyUse")  {
	    alert("iKey USB ÀúÀåÀåÄ¡´Â »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.");
    	return false;
	} else if (req=="fail_GetUSBSerial") {
	    alert("USBÀúÀåÀåÄ¡¸¦ ÀÎ½ÄÇÒ¼ö ¾ø½À´Ï´Ù.");
	    return false;
	}
	// 2011.02.24 °íµµÈ­ °ü·Ã Ãß°¡ ³¡
	
	if(req!="true") return false;
	form.req.value = req;
	
	return true;		
}

function IssueCertificate(szRef, szCode)
{
    
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	
	var Arg = "";
	var challenge = "1111";
	
	Arg += "REF=";
	Arg += obj.URLEncode(szRef);
	Arg += "&CODE=";
	Arg += obj.URLEncode(szCode);
	Arg += "&CAIP=";
	Arg += obj.URLEncode(YessignCAIP);
	Arg += "&CAPORT=";
	Arg += obj.URLEncode(YessignCMPPort);
	
	obj.CertRequest(YessignPackage, "", Arg, challenge);
	
}

function UpdateCertificate()
{
    
	obj = ModuleInstallCheck();
	if (obj == null) return false;

	var Arg = "";
	var challenge = "1111";
	
	Arg += "CAIP=";
	Arg += obj.URLEncode(YessignCAIP);
	Arg += "&CAPORT=";
	Arg += obj.URLEncode(YessignCMPPort);
	
	//obj.CertUpdate(YessignPackage, "", Arg);
	if(obj.CertUpdate2(YessignPackage, "", Arg)=="")	return false; //Ä³½¬µÈÀÎÁõ¼­»ç¿ë½Ã  
	return true;
}

function InsertCACert(cert)
{
	// INIplugin-128 Install Check
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	
	obj.InsertCACert(InitechPackage, cert);
	
	return true;
}

//add bye wakano 2001/01/29 with for Shinhan Bank 
function EncryptedCertRequest(form1)
{
        ShinHan_plugin = true;
    	if(CertRequest(form1)){
        	return EncForm(form1);
    	}
    	return false;
}

function EncCertReq(form1)
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	
	if(CertRequest(form1)) return EncForm(form1);

	return false;
	
}

function EncCertReq2(form1, form2)
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	
	if(!CertRequest(form1))
		return false;

	return EncForm2(form1, form2);
}

function LoadCACert(CACert)
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	
	obj.LoadCACert(CACert);
	
	return true;
}

function DeleteUserCert(DelCert)
{
	obj = ModuleInstallCheck();
	if (obj == null) return;
	
	if (obj.DeleteUserCert(InitechPackage, "", DelCert)) 
	{
		//alert("ÇØ´ç ÀÎÁõ¼­ »èÁ¦ÇÏ¿´½À´Ï´Ù.");
	}
	else
	{
		//alert("ÇöÀç »ç¿ëÇÏ½Ã´Â ÄÄÇ»ÅÍ¿¡ ÇØ´ç ÀÎÁõ¼­°¡ ¾ø¾î¼­ »èÁ¦ÇÏÁö ¸øÇÏ¿´½À´Ï´Ù.");
	}
	
	return;		
}

function RevokeCertificate(serial)
{
    obj = ModuleInstallCheck();
    if (obj == null) return false;
    //alert(serial);
	if(obj.DeleteUserCert(YessignPackage, "", serial))
	{
		//alert("ÇØ´ç ÀÎÁõ¼­ »èÁ¦ÇÏ¿´½À´Ï´Ù.");
		return true;
	}
	else
	{
		//alert("ÇöÀç »ç¿ëÇÏ½Ã´Â ÄÄÇ»ÅÍ¿¡ ÇØ´ç ÀÎÁõ¼­°¡ ¾ø¾î¼­ »èÁ¦ÇÏÁö ¸øÇÏ¿´½À´Ï´Ù.");
		return false;
	}

    return  true;
}

function SelFile(field)
{
    obj = ModuleInstallCheck();
    if (obj == null) return false;

    field.value = obj.SelectFile();
}

function InstallModule(InstallModuleURL)
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	if(InstallModuleURL=="") return true;
	obj.InstallModule(InstallModuleURL);
	return true;
}

function FilterUserCert(storage, issuerAndSerial)
{
    obj = ModuleInstallCheck();
    if (obj == null) return -1;
	return obj.FilterUserCert(storage, issuerAndSerial);
}

function URLEncode(data)
{
    obj = ModuleInstallCheck();
    if (obj == null) return "";
	return obj.URLEncode(data);
}

function GetStorageSerial(storage, pin)
{
    obj = ModuleInstallCheck();
    if (obj == null) return "";
	return obj.GetStorageSerial(storage, pin);
}

function IsCheckCard(storage)
{
	obj = ModuleInstallCheck();
    if (obj == null) return false;
	return obj.IsCheckCard(storage);
}

function VerifyPin(storage, pin)
{
    //alert("VerifyPIN :: "+ storage+":"+pin)
	obj = ModuleInstallCheck();
    if (obj == null) return false;
	//alert("VerifyPIN result :: "+obj.VerifyPIN(storage, pin));
	return obj.VerifyPIN(storage, pin);
}

function ChangePIN(storage, oldpin, newpin)
{
    obj = ModuleInstallCheck();
    if (obj == null) return false;
	return obj.ChangePIN(storage, oldpin, newpin);
}

//add to brson :  ÆÄÀÏ¾ÏÈ£È­ V4.0.2.4
///////////////////////////////////////////////////
///////////// ÆÄÀÏ¾ÐÈ£È­ API  /////////////////////
///////////////////////////////////////////////////

function EncFile(url, form) 
{
	var eletemp = "";
	var filetemp = "";

	obj = ModuleInstallCheck();
	if (obj == null) return false;

	filetemp = GatherFileValue(form, 0, true);
	if (filetemp !=  "")
	{
		if ((form.INIfileData.value = obj.UploadEncryptFile(url, 10, cipher, filetemp, TimeURL)) == ""){
			alert("File Upload Fail");
			return false; 
		}
		//alert("INIfileData = " + form.INIfileData.value);
	}

	eletemp = GatherValue(form, 0, true);
	// °íµµÈ­ °ü·Ã 20110129
	if ((form.INIpluginData.value = obj.MakeINIpluginData(10, cipher, eletemp, TimeURL))=="") return false;

   	return true;
}

function EncFile2(url, form, form2) 
{
	var eletemp = "";
	var filetemp = "";

	obj = ModuleInstallCheck();
	if (obj == null) return false;

	filetemp = GatherFileValue(form, 0, false);
	if (filetemp !=  "")
	{
		//alert("fileValue = " + filetemp);
		if ((form.INIfileData.value = obj.UploadEncryptFile(url, 10, cipher, filetemp, TimeURL)) == ""){
			alert("File Upload Fail");
			return false; 
		}
		//alert("INIfileData = " + form.INIfileData.value);
	}

	eletemp = GatherValue(form, 0, false);
	// °íµµÈ­ °ü·Ã 20110129
	if ((form2.INIpluginData.value = obj.MakeINIpluginData(10, cipher, eletemp, TimeURL))=="") return false;

   	return true;
}

function EncDown(url, args) 
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	return obj.DownloadEncryptFile(url, 10, cipher, args, TimeURL);
}

function EncDownVerify(url, args) 
{

	obj = ModuleInstallCheck();
	if (obj == null) return false;
	return obj.DownloadEncryptFile(url, 11, cipher, args, TimeURL);
}

///////////////////////////////////////////////////
///////////// ÃÊ±â°ª ¼¼ÆÃ API  /////////////////////
///////////////////////////////////////////////////

function LoadCert(Cert)
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	return obj.LoadCert(Cert);
}

function InitCache()
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	
	obj.InitCache();
	
	return true;
}

function SetCacheTime(gap)
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	
	obj.SetCacheTime(gap);
	
	return true;
}

function ReSession()
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	obj.ReSession();
	return true;
}

function SetLogoPath()
{
    obj = ModuleInstallCheck();
    if (obj == null) return false;
    return obj.SetLogoPath(LogoURL);
}

function EnableCheckCRL(check)
{
    obj = ModuleInstallCheck();
    if (obj == null) return false;
    obj.EnableCheckCRL(check);
}

function SetVerifyNegoTime(time1, time2)
{
    obj = ModuleInstallCheck();
    if (obj == null) return false;
    obj.SetVerifyNegoTime(time1, time2);
}

function DisableInvalidCert(check)
{
	obj = ModuleInstallCheck();
	if (obj == null) return false;
	obj.DisableInvalidCert(check);
}

function SetTVBanking(bTV)
{
	var ver = "4, 1, 3, 0";
	if(EnableFunction(ver)) {
		obj = ModuleInstallCheck();
		if (obj == null) return false;
		obj.SetTVBanking(bTV);
	} else {
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â Áö¿øÇÏÁö ¾Ê´Â±â´ÉÀÔ´Ï´Ù."
	    msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg) alert(msg);
		return false;
	}
	return true;
}

///////////////////////////////////////////////////
///////////// ±âÅ¸             /////////////////////
///////////////////////////////////////////////////

function GetVersion()
{
	var ver = "4,0,0,0"
    obj = ModuleInstallCheck();
    if (obj == null) return ver;
	return new String(obj.GetVersion());
}

function EnableFunction(inputVersion)
{
	var thisArray = GetVersion().split(',');
    var inputArray = inputVersion.split(',');

	for (i=0; i<4; i++)
	{
		if (parseInt(thisArray[i], 10) > parseInt(inputArray[i], 10))
			return true;
		else if (parseInt(thisArray[i], 10) < parseInt(inputArray[i], 10))
			return false;
	}
	return true;
}

function ManageCert()
{
	obj = ModuleInstallCheck();
	if (obj == null) return; 

	FilterCert(STORAGE2, "")
	//obj.ExtendMethod( "certcopytotarget" , "SCARD&000000&resetpwd" ) ;
	obj.ManageCert();
}

function INIAbout()
{
	obj = ModuleInstallCheck();
	if (obj == null) return;
	obj.About();
}

function GetClientUID()
{
	var ver = "4, 5, 0, 0";
	if(EnableFunction(ver)) {
		obj = ModuleInstallCheck();
		if (obj == null) return;
	    return obj.GetClientUID();
	} else {
		var msg;
		//msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â Áö¿øÇÏÁö ¾Ê´Â±â´ÉÀÔ´Ï´Ù."
	    //msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
	    msg = "\n .. °ø»çÁßÀÔ´Ï´Ù... "
		if (EnableMsg) alert(msg);
	}
	return;
}


///////////////////////////////////////////////////
/////////////¼¼±Ý°è»ê¼­ API ½ÃÀÛ/////////////////////
///////////////////////////////////////////////////

function MakeTaxData(inform, outform)
{
	var gValue = "";
    var ret  = "";
    
	len = inform.elements.length;
    outform.INIpluginTax.value="";

    // INIplugin-128 Install Check
    INIpluginObject = ModuleInstallCheck();
    if (INIpluginObject == null) return false;

    for (i = 0; i < len; i++) {
    	var name = inform.elements[i].name;
        var value = INIpluginObject.URLEncode(inform.elements[i].value);
        gValue = gValue + name + "=" + value + "&";
    }

    ret = INIpluginObject.MakeTaxData(gValue);
    if(ret == "" || ret == "CERT_NOT_FOUND") return false;
    outform.INIpluginTax.value = ret;

    return true;
}

function EncMakeTaxData(inform, outform)
{
	if(MakeTaxData(inform, outform)) {
		//alert(outform.INIpluginTax.value);
		return EncForm(outform);
	}
	return false;
}

function SaveTaxData(taxData)
{
        // INIplugin-128 Install Check
        INIpluginObject = ModuleInstallCheck();
        if (INIpluginObject == null) return false;
        if(INIpluginObject.SaveTaxData(taxData)) {
                return true;
        } else {
                return false;
        }
}

function SaveTaxData2Clt(pfile, taxData)
{
        // INIplugin-128 Install Check
        INIpluginObject = ModuleInstallCheck();
        if (INIpluginObject == null) return false;
        if(INIpluginObject.SaveTaxData2Clt(pfile, taxData)) {
                return true;
        } else {
                return false;
        }
}

function ManageTax()
{
	INIpluginObject = ModuleInstallCheck();
        if (INIpluginObject == null) return false;
        if(INIpluginObject.manageTax()) {
                return true;
        } else {
                return false;
        }
}


///////////////////////////////////////////////////
///////////// ÀüÀÚ¼­¸í API ½ÃÀÛ/////////////////////
///////////////////////////////////////////////////

function IniSign(form, data, inputtitle, inputdata)
{
	var ver = "4, 1, 9, 0";
	if(EnableFunction(ver)) {
		INIpluginObject = ModuleInstallCheck();
		if (INIpluginObject == null) return false;
		
		form.PKCS7SignedData.value = INIpluginObject.IniSign("sha1", data, TimeURL, inputtitle, inputdata);
		if(form.PKCS7SignedData.value=="") return false;
		//alert(PKCS7SignedData);
		return true;
	} else {
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â ÀüÀÚ¼­¸í ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg) alert(msg);
		return false;
	}
}

function IniSign2(form, data)
{
	var ver = "4, 1, 9, 0";
	if(EnableFunction(ver)) {
		INIpluginObject = ModuleInstallCheck();
		if (INIpluginObject == null) return false;

		form.PKCS7SignedData.value = INIpluginObject.IniSign2("sha1", data, TimeURL);
		if(form.PKCS7SignedData.value=="") return false;
		return true;

	} else {
		//alert("this");
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â ÀüÀÚ¼­¸í ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		//msg = "\n .. °ø»çÁßÀÔ´Ï´Ù... "
		if (EnableMsg) alert(msg);
		return false;
	}
}

/*function AddSignValue(data, name, value)
{
	if(data!="") data += "¢¯";
	data += URLEncode(name);
	data += "=";
	data += URLEncode(value);
	return data;
}*/

function AddSignValue(data, name, value)
{
	if(data!="") data += "¢¯";
	data += name;
	data += "=";
	data += URLEncode(value);
	return data;
}


/*function EncLocation(indata)
{
	var	INIdata;
	var s = indata.indexOf('?');
	var url = indata.substring(0, s) + "?INIpluginData=";
	var encData = indata.substring(s+1);

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}
	//modify brson 2002/06/11 
	//dt¿¡ server time Ãß°¡  
	var ver="4,2,0,0";
	if(AddServerTime && EnableFunction(ver)) {
		if(encData!=""){
				encData = "__INIts__=" + obj.GetServerTime(TimeURL) + "&" + encData;
		}
		else{
				encData = "__INIts__=" + obj.GetServerTime(TimeURL);
		}
	}

	if( (INIdata = obj.MakeINIpluginData("0", cipher, encData, "")) == "" )
		return;
	url += obj.URLEncode(INIdata);

	return url;
}*/

//20090521-------------------¼öÁ¤-----------------------------
function EncLocation(indata)
{
	var	INIdata;
	var s = indata.indexOf('?');
	var url;
	var encData;
	
	if (s<0){
		//alert("no parameter");
		url= indata+"?INIpluginData=";
		encData = "dummy";
	}else{
		url = indata.substring(0, s) + "?INIpluginData=";
		encData = indata.substring(s+1);
	}
//alert("EncLocation :: "+url+" && " + encData);
	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}
	//modify brson 2002/06/11 
	//dt¿¡ server time Ãß°¡  
	var ver="4,2,0,0";
	if(AddServerTime && EnableFunction(ver)) {
		if(encData!=""){
				encData = "__INIts__=" + obj.GetServerTime(TimeURL) + "&" + encData;
		}
		else{
				encData = "__INIts__=" + obj.GetServerTime(TimeURL);
		}
	}
// °íµµÈ­ °ü·Ã 20110129
	if( (INIdata = obj.MakeINIpluginData("10", cipher, encData, TimeURL)) == "" )
		return;
	url += obj.URLEncode(INIdata);

	//alert(url);

	return url;
}




function PKCS7SignedData(form, data, view)
{
	var ver = "4, 1, 14, 0";
	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}
	if(EnableFunction(ver)) {
		form.PKCS7SignedData.value = obj.PKCS7SignData("sha1", data, TimeURL, view);
		if(form.PKCS7SignedData.value=="") return false;
		return true;
	} else {
		//alert("this");
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â ÀüÀÚ¼­¸í ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg)	alert(msg);
		return false;
	}
}

function SignFile(filename)
{
	var obj = ModuleInstallCheck();
	if (obj == null) return "";
	
	return obj.SignFile(filename);
}

//ÀÌÁß¾ÏÈ£È­  
function EncryptTo(cert, data)
{
	var ver = "4, 3, 1, 0";
	if(EnableFunction(ver)) {
		obj = ModuleInstallCheck();
		if (obj == null) "";
		return obj.MakeINIpluginData2(cert, 0, cipher, data, TimeURL);
	} else {
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â ÀÌÁß¾ÏÈ£È­ ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg) alert(msg);
		return "";
	}
	return "";
}

function AddValue(data, name, value)
{
	if(data!="") data += "&";
	data += URLEncode(name);
	data += "=";
	data += URLEncode(value);
	return data;
}

function SetProperty(name, value)
{
	var obj = ModuleInstallCheck();
	if (obj == null) return "";
	return obj.SetProperty(name, value);
}

function makeSK(BSCert, form)
{
	
	var ver = "4, 5, 2, 11";
	if(!EnableFunction(ver)) {
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â ÀÌÁß¾ÏÈ£È­ ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg) alert(msg);
		return false;
	}

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}
	if (typeof form.INIencSK == "undefined") {
		alert("INIecnSK(form.name)°¡ ÇÊ¿äÇÕ´Ï´Ù.");
		return false;
	}
	
	form.INIencSK.value = obj.MakeSessionKeyInfo(BSCert, "SEED-CBC");
	return true;
}

// sk¸¦ ÀÌ¿ëÇÏ¿© Æ¯Á¤formÀÇ value°ªÀ» ¾ÏÈ£È­ÇÏ¿© ±âÁ¸ value¸¦ ±³Ã¼ÇÔ
function EncryptToSK(name, form)
{
	var ver = "4, 5, 2, 11";
	if(!EnableFunction(ver)) {
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â ÀÌÁß¾ÏÈ£È­ ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg) alert(msg);
		return false;
	}

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}
	for(var i=0; i<form.elements.length; i++) 
	{
		var element = form.elements[i];
		if (element.name == name) {
			element.value = obj.EncryptWithSKInfo2(form.INIencSK.value, element.value);
			return true;
		}
	}
	alert("ÀÌÁß¾ÏÈ£È­ÇÒ form.name(" + name + ")À» Ã£À»¼ö°¡ ¾ø½À´Ï´Ù.");
	return false;
}



function IsCachedCert()
{
	var obj = ModuleInstallCheck();
	if (obj == null) return false;
	return obj.IsCachedCert();
}

function GetCachedCert(name)
{
	var obj = ModuleInstallCheck();
	if (obj == null) return "";
	return obj.GetCachedCert(name);
}

function CheckCRL(cert)
{
	var obj = ModuleInstallCheck();
	if (obj == null) return false;
	return obj.CheckCRL(cert);
}

function ViewCert(cert)
{
	var obj = ModuleInstallCheck();
	if (obj == null) return;
	obj.ViewCert(cert);
}

//¼±Á¾ Ãß°¡... °øÀ¯ °ªÀ» ³ÖÀ» ¼ö ÀÖÀ½  
function setSharedAttribute(name, value){
	obj = ModuleInstallCheck();
	if (obj == null) return false;

	var ver = "5, 1, 5, 23";
	if(!EnableFunction(ver)) {
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â º» ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg) alert(msg);
		return false;
	}
	
	obj.setSharedAttribute(name, value);
	return true;
}

function getSharedAttribute(name){
	obj = ModuleInstallCheck();
	if (obj == null) return null;

	var ver = "5, 1, 5, 23";
	if(!EnableFunction(ver)) {
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â º» ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg) alert(msg);
		return false;
	}
	
	return obj.getSharedAttribute(name);
}

/*
 * Ä³½¬µÈ ÀÎÁõ¼­ÀÇ serial °ªÀ» ¸®ÅÏÇÑ´Ù.
 * add by juno at 2004/11/11 - ½ÅÇÑÀºÇà Å¬¶óÀÌ¾ðÆ®¿¡¼­ ÀÎÁõ¼­ È®ÀÎÇÏ±â
 * GetCachedData("serial") - ÇöÀç Ä³½¬µÈ ÀÎÁõ¼­ÀÇ SerialNumber¸¦ ¸®ÅÏÇÑ´Ù.
 * GetCachedData("subjectcn") - ÇöÀç Ä³½¬µÈ ÀÎÁõ¼­ÀÇ SubjectCN¸¦ ¸®ÅÏÇÑ´Ù.
 * GetCachedData("subjectdn") - ÇöÀç Ä³½¬µÈ ÀÎÁõ¼­ÀÇ SubjectDNÀ» ¸®ÅÏÇÑ´Ù.
 * GetCachedData("issuerdn") - ÇöÀç Ä³½¬µÈ ÀÎÁõ¼­ÀÇ IssuerDNÀ» ¸®ÅÏÇÑ´Ù.
 */
function GetCachedData(key)
{
	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}

	if(key == "serial") {
	    return obj.GetCachedData(key);
	}
        else if(key == "subjectcn") {
	    return obj.GetCachedData(key);
	}
	else if(key == "subjectdn") {
	    return obj.GetCachedData(key);
	}
	else if(key == "issuerdn") {
	    return obj.GetCachedData(key);
	}
	else {
	    alert("Àû´çÇÑ key°¡ ¾Æ´Õ´Ï´Ù. [serial, subjectdn, subjectcn, issuerdn]");
	    return false;
	}
}

//ÆÄÀÏ °æ·Î¸¦ ÀÔ·Â¹Þ¾Æ ÇØ½¬°ª ¸®ÅÏÇØÁÜ.  
function FileHash(filepath)
{
	//SetProperty("FileHash", filepath);

	//alert("filepath : " + filepath);
	if (obj == null){ 
		alert("obj load fail");
	}
	else
	{
		return obj.ExtendMethod("FileHash", filepath);
	}
}

function FilterCert(storage, issuerAndSerial)
{
    obj = ModuleInstallCheck();
    if (obj == null) return -1;
	
	return obj.FilterCert(storage, issuerAndSerial);
}

function EncryptFile(sk,file1,file2){
	
	//alert("file1["+file1+"]");
	//alert("file2["+file2+"]");
	
	obj = ModuleInstallCheck();
 	if (obj == null) return null;
 	b64key = obj.Base64(0, sk+'INISAFE NETWORK.');
 	ret = obj.EncryptFile("SEED-CBC", b64key, file1, file2);
 	//alert(ret);
  	return ret;

}
//ÀÎÁõ¼­ Ã¢ Ä³½¬±â´É ¹× Ä¸¼Çº¯°æ ÇÔ¼ö(2007.04.30)
/* 
	ForceCertQuest("ShowOnlySelectedOne");   
    - ¸¶Áö¸· Á¦ÃâµÈ ÀÎÁõ¼­¸¸ Ãâ·Â ÇÔ
    ForceCertQuest("CertReplace,MsgForChangeCert"); 
    - ¸ðµç ÀÎÁõ¼­¸¦ Ãâ·ÂÇÑ ÈÄ, ¸¶Áö¸· Á¦ÃâµÈ ÀÎÁõ¼­¿Í ´Ù¸¥ ÀÎÁõ¼­¸¦ ¼±ÅÃÇßÀ» ¶§, »ç¿ëÀÚ¿¡°Ô °æ°í ¸Þ¼¼Áö¸¦ Ãâ·ÂÈÄ »õ·Î ¼±ÅÃÇÑ ÀÎÁõ¼­·Î Àû¿ëÇÔ
    ForceCertQuest("MsgForChangeCert"); 
    - ¸ðµç ÀÎÁõ¼­¸¦ Ãâ·ÂÇÑ ÈÄ, ¸¶Áö¸· Á¦ÃâµÈ ÀÎÁõ¼­¿Í ´Ù¸¥ ÀÎÁõ¼­¸¦ ¼±ÅÃÇßÀ» ¶§, »ç¿ëÀÚ¿¡°Ô °æ°í ¸Þ¼¼Áö¸¦ Ãâ·ÂÈÄ ÀÌÀü ÀÎÁõ¼­·Î Àû¿ëÇÔ
    ForceCertQuest("CertReplace,");
    - ¸ðµç ÀÎÁõ¼­¸¦ Ãâ·ÂÇÑ ÈÄ, ¸¶Áö¸· Á¦ÃâµÈ ÀÎÁõ¼­¿Í ´Ù¸¥ ÀÎÁõ¼­¸¦ ¼±ÅÃÇßÀ» ¶§, ¸Þ¼¼Áö ¾øÀÌ »õ·Î ¼±ÅÃÇÑ ÀÎÁõ¼­·Î Àû¿ëÇÔ
    ForceCertQuest(""); 
    - ¸ðµç ÀÎÁõ¼­¸¦ Ãâ·ÂÇÑ ÈÄ, ¸¶Áö¸· Á¦ÃâµÈ ÀÎÁõ¼­¿Í ´Ù¸¥ ÀÎÁõ¼­¸¦ ¼±ÅÃÇßÀ» ¶§, ¸Þ¼¼Áö ¾øÀÌ ÀÌÀü ÀÎÁõ¼­·Î Àû¿ëÇÔ
*/
function ForceCertQuest(caption)
{
  obj = ModuleInstallCheck();
  if (obj == null) return null;

  return obj.ExtendMethod("ForceCertQuest", caption); 
  //return obj.ExtendMethod("InitCache", "on");
 }

//INISafeWebSSO.exe·ÎºÎÅÍ ÇØ´ç auth_ref¸¦ Å°·Î ÀúÀåµÈ °ªÀ» ÀÐ¾î¿Í
//»õ·Î¿î INISafeWebClient¿¡ ¼ÂÆÃÇÑ´Ù.   
function SetCachedData(auth_ref)    
{
	obj = ModuleInstallCheck();
	if (obj == null) return "";

	return obj.SetCachedData(auth_ref);
}

//INISafeWebSSO.exe¿¡ ÀúÀåµÈ °ªÀ» ¸ðµÎ Áö¿î´Ù.    
function ClearCachedData()   
{
	obj = ModuleInstallCheck();
	if (obj == null) return "";
	return obj.ClearCachedData();
}

//INISafeWebSSO.exe¸¦ ÁßÁö½ÃÅ²´Ù.   
function EndCacheProcess()
{
	obj = ModuleInstallCheck();
	if (obj == null) return "";
	return obj.EndCacheProcess();
}

//INISafeWebSSO.exe¸¦ ½ÇÇàÇÏ°í formÀÇ auth_ref¸¦ Å°·Î ÇÏ¿©
//ÀÎÁõ¼­ Á¤º¸¸¦ ÀúÀåÇÑ´Ù.   
function CacheEncFormVerify(form) 
{
	var INIdata = "";
	var eletemp = "";
	var filetemp = "";
	var Random = TimeURL; 

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}

	filetemp = GatherFileValue(form, 0, true);
	if (filetemp !=  "") 
	{
		if ((form.filedata.value = obj.MakeFileData(11, cipher, filetemp)) == "") return false; 
	}

	eletemp = GatherValue(form, 0, true);
	
	if ((INIdata = obj.CacheINIpluginData(1, cipher, eletemp, Random))=="") return false;

	//add bye wakano 2001/01/29
	if (typeof form.INIpluginData == "undefined") 
	{
		if (ShinHan_plugin) // with for Shinhan Bank 
		{
			form.input.value = INIdata;
			form.input.name = "INIpluginData"; // for Shinhan Bank
		} else {
			alert("INIpluginData(form.name)°¡ ÇÊ¿äÇÕ´Ï´Ù.");
			return false;
		}
	} else {
		form.INIpluginData.value = INIdata;
	}

   	return true;
}

function ExtendMethod(param1, param2)
{
	obj = ModuleInstallCheck();
    if (obj == null) {
		alert("SecureFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return -1;
	}

	return obj.ExtendMethod(param1, param2);
}



















/********************************************************************************************************************************
 ********************************************************************************************************************************
 ONLY KDB(2009.09.30) - etc function
 ********************************************************************************************************************************
 ********************************************************************************************************************************/

var g_szCAName, g_szRef, g_szCode, g_manyusb, g_mediaName;
var g_private, g_firstMedia;

/* °³ÀÎ ÀÎÁõ¼­ */
function IssueCertificate2(szCAName, szRef, szCode)
{
    //alert("IssueCertificate2");
	g_private = true;
	g_szRef = szRef;
	g_szCode = szCode;
	g_szCAName = szCAName;
	// »ê¾÷ÀºÇà Àü¿ë UI Àû¿ë Flag	1:°³ÀÎ 2:±â¾÷ 0:¹ü¿ë(»êÀºÀÌ¿Ü)
	SetProperty("certmanui_setkdbusedproperty" , "1" );
	STORAGE2 = "HDD|FDD|SCARD|PHONE";
	if (GetPluginDev() == "SCARD") {
		//alert("°³ÀÎ»ç¿ëÀÚ´Â ½º¸¶Æ®Ä«µå¸¦ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.");
		//return false;
		g_manyusb = 1;
		g_mediaName = "SCARD";
		g_CopyProcess = "ISSUE";
		// SCARD derivation key get
		if (_goIframe(false) == false) {
			alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
			return false;
		} else {
		    //alert("IssueCertificate2 SCARD _goIframe(false) == true");
			t_id = setInterval("_wait_Value(\"ISSUE\", false)", 100);
			return true;
		}
	} else if (GetPluginDev() == "USB") {
		alert("°³ÀÎ»ç¿ëÀÚ´Â USB Key¸¦ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.");
		return false;
	} else {
		g_mediaName = "";
		return IssueCertificate2_KDB_proce(szCAName, szRef, szCode, 1);
	}
}

/* ±â¾÷ ÀÎÁõ¼­ */
function IssueCertificate2_KDB(szCAName, szRef, szCode, manyusb)
{
	//2011.02.24 °íµµÈ­ °ü·Ã Internet Security Å°¿¡ ÀÎÁõ¼­¸¦ ¹ß±Þ Â÷´ÜÇÏ´Â ±â´É Ãß°¡ 
    //SetProperty("iKeyNoUseOfCertRequest","true");
    //2011.02.24 Ãß°¡ ³¡. 
    
    // »ê¾÷ÀºÇà Àü¿ë UI Àû¿ë Flag	1:°³ÀÎ 2:±â¾÷ 0:¹ü¿ë(»êÀºÀÌ¿Ü)
	SetProperty("certmanui_setkdbusedproperty" , "2" );
	
	g_private = false;//false : ±â¾÷, true : °³ÀÎ
	g_CopyProcess = "ISSUE";
	g_szCAName = szCAName;
	// 090823 ÁÖ¼® :: STORAGE2 = "USB|SCARD";
	if (GetPluginDev() == "USB") {
		g_mediaName = "USB Key";
		g_firstMedia = "USB";
		alert("ÀÎÁõ¼­¸¦ ¼³Ä¡ÇÕ´Ï´Ù.\n[°ü¸®ÀÚ]ÀÇ USB Key¸¦ »ðÀÔÇÏ½Å ÈÄ È®ÀÎÀ» ´©¸£½Ê½Ã¿À");
		return IssueCertificate2_KDB_proce(szCAName, szRef, szCode, manyusb);
		//alert();
	} else if (GetPluginDev() == "SCARD") {
		g_szRef = szRef;
		g_szCode = szCode;
		g_manyusb = manyusb;
		g_mediaName = "½º¸¶Æ®Ä«µå";
		g_firstMedia = "SCARD";
		// SCARD derivation key ±¸ÇÏ±â
		if (_goIframe(false) == false) {
			alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
			return false;
		} else {
		    
			t_id = setInterval("_wait_Value(\"ISSUE\", false)", 100);
			return true;
		}
	} else {
		//alert("±â¾÷»ç¿ëÀÚ´Â USB Key¿Í ½º¸¶Æ®Ä«µå¸¸ »ç¿ë°¡´ÉÇÕ´Ï´Ù.");
		//return false;
		return IssueCertificate2_KDB_proce(szCAName, szRef, szCode, manyusb);
	}
}

/* ÀüÀÚ ¼¼±Ý°è»ê¼­ ¿ë */
function IssueCertificate2_ESERO(szCAName, szRef, szCode)
{

	var Arg = "";
	var challenge = "1111";

	Arg += "REF=";
	Arg += URLEncode(szRef);
	Arg += "&CODE=";
	Arg += URLEncode(szCode);

	// »ê¾÷ÀºÇà Àü¿ë UI Àû¿ë Flag	1:°³ÀÎ 2:±â¾÷ 0:¹ü¿ë(»êÀºÀÌ¿Ü)
	SetProperty("certmanui_setkdbusedproperty" , "2" );
	STORAGE2 = "HDD|FDD|PHONE";

	if (szCAName == "01" ) { // ±Ý°á¿ø
		Arg += "&CAIP=";
		Arg += URLEncode(YessignCAIP);
		Arg += "&CAPORT=";
		Arg += URLEncode(YessignCMPPort);
		
		if(obj.CertRequest(YessignPackage, STORAGE2, Arg, challenge)!="true") {
			var msg = "°øÀÎÀÎÁõ¼­ ¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
				msg += "¾Æ·¡ÀÇ ÂüÁ¶¹øÈ£¿Í ÀÎ°¡ÄÚµå¸¦ ÂüÁ¶ÇÏ½Ã¿© ±Ý°á¿ø¿¡¼­ ¹ß±Þ ¹ÞÀ¸½Ã±â ¹Ù¶ø´Ï´Ù.\n\n"
				msg += "ÂüÁ¶¹øÈ£ : " + szRef;
				msg += "\tÀÎ°¡ÄÚµå : " + szCode;
			//alert(msg);
			return false;
		}		
	} else if (szCAName == "03" ) { //ÀüÀÚÀÎÁõ
		Arg += "&CAIP=";
		Arg += URLEncode(CrossCertCAIP);
		Arg += "&CAPORT=";
		Arg += URLEncode(CrossCMPPort);
		//INITECH Ãß°¡ 090807------------------------------
		SetProperty( "isplugindevinit" , "TRUE" );
		if(obj.CertRequest(CrossCertPackage, STORAGE2, Arg, challenge)!="true") {

			var msg = "°øÀÎÀÎÁõ¼­ ¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
				msg += "¾Æ·¡ÀÇ ÂüÁ¶¹øÈ£¿Í ÀÎ°¡ÄÚµå¸¦ ÂüÁ¶ÇÏ½Ã¿© ÀüÀÚÀÎÁõ¿¡¼­ ¹ß±Þ ¹ÞÀ¸½Ã±â ¹Ù¶ø´Ï´Ù.\n\n"
				msg += "ÂüÁ¶¹øÈ£ : " + szRef;
				msg += "\tÀÎ°¡ÄÚµå : " + szCode;
			//alert(msg);
			return false;
		}
	} else {
		alert(szCAName + " Àº(´Â) Á¤ÀÇµÇÁö ¾ÊÀº CA±â°üÀÔ´Ï´Ù.");
		return false;
	}

	return true;
}


function IssueCertificate2_KDB_proce(szCAName, szRef, szCode, manyusb)
{
    //alert("IssueCertificate2_KDB_proce START");
 
	//alert("ÀÎÁõ¼­¸¦ USB/SCARD ¿Ü ´Ù¸¥ ¸ÅÃ¼¿¡ ÀúÀåÇÏ½Ã°Ú½À´Ï±î?");
	obj = ModuleInstallCheck();
	if (obj == null) return false;

	var Arg = "";
	var challenge = "1111";
	var device_type = GetPluginDev();

	Arg += "REF=";
	Arg += obj.URLEncode(szRef);
	Arg += "&CODE=";
	Arg += obj.URLEncode(szCode);

	if (g_private == false && (device_type == "SCARD" || device_type == "USB")) {
		if (PinInit() != "true") {
			alert("ÀúÀå ¸ÅÃ¼ ÃÊ±âÈ­¿¡ ½ÇÆÐÇß½À´Ï´Ù.");
			return false;
		}
		//alert("KEY ÃÊ±âÈ­ ¼º°ø");
	}
	if (g_private == true && (/*device_type == "SCARD" || */device_type == "USB")) {
		//alert("°³ÀÎ»ç¿ëÀÚ´Â USB Key³ª ½º¸¶Æ®Ä«µå¸¦ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.");
		alert("°³ÀÎ»ç¿ëÀÚ´Â USB Key¸¦ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.");
		return false;
	}
	//alert(STORAGE2);
	if (szCAName == "01" ) { // ±Ý°á¿ø
		Arg += "&CAIP=";
		Arg += URLEncode(YessignCAIP);
		Arg += "&CAPORT=";
		Arg += URLEncode(YessignCMPPort);
		//INITECH Ãß°¡ 090807------------------------------
		SetProperty( "isplugindevinit" , "TRUE" );
		
		// ±âÁ¸ ¼Ò½º
		/*
		if(obj.CertRequest(YessignPackage, STORAGE2, Arg, challenge)!="true") {
			var msg = "°øÀÎÀÎÁõ¼­ ¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
				msg += "¾Æ·¡ÀÇ ÂüÁ¶¹øÈ£¿Í ÀÎ°¡ÄÚµå¸¦ ÂüÁ¶ÇÏ½Ã¿© ±Ý°á¿ø¿¡¼­ ¹ß±Þ ¹ÞÀ¸½Ã±â ¹Ù¶ø´Ï´Ù.\n\n"
				msg += "ÂüÁ¶¹øÈ£ : " + szRef;
				msg += "\tÀÎ°¡ÄÚµå : " + szCode;
			//alert(msg);
			if (device_type == "SCARD")
				if (typeof(NEXTACTION) == "function") {
					NEXTACTION(false);
				}
			return false;
		}
		*/
		
		//2011.02.24 °íµµÈ­ °ü·Ã ±â¾÷ ¹ðÅ· UI ¼³Á¤ 
        if (g_private == false) {
		    // ±â¾÷ »ç¿ëÀÚ ¹Ý¿µ
		    var ret;
        	ret = obj.CertRequest(YessignPackage, "HDD|FDD|USB", Arg, challenge);
        	
        	if (ret !="true") {
                if(ret=="fail_iKeyUse")  {
            	    alert("iKey USB ÀúÀåÀåÄ¡´Â »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.");
                	return false;
            	} else if (ret=="fail_GetUSBSerial") {
            	    alert("USBÀúÀåÀåÄ¡¸¦ ÀÎ½ÄÇÒ¼ö ¾ø½À´Ï´Ù.");
            	    return false;
            	} else {
            	    var msg = "°øÀÎÀÎÁõ¼­ ¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
    				msg += "¾Æ·¡ÀÇ ÂüÁ¶¹øÈ£¿Í ÀÎ°¡ÄÚµå¸¦ ÂüÁ¶ÇÏ½Ã¿© ±Ý°á¿ø¿¡¼­ ¹ß±Þ ¹ÞÀ¸½Ã±â ¹Ù¶ø´Ï´Ù.\n\n"
    				msg += "ÂüÁ¶¹øÈ£ : " + szRef;
    				msg += "\tÀÎ°¡ÄÚµå : " + szCode;
        			//alert(msg);
        			if (device_type == "SCARD")
        				if (typeof(NEXTACTION) == "function") {
        					NEXTACTION(false);
        				}
        			return false;
            	}
        	}
		} else {
		    // °³ÀÎ »ç¿ëÀÚ ¹Ý¿µ
		    if(obj.CertRequest(YessignPackage, STORAGE2, Arg, challenge)!="true") {
    			var msg = "°øÀÎÀÎÁõ¼­ ¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
    				msg += "¾Æ·¡ÀÇ ÂüÁ¶¹øÈ£¿Í ÀÎ°¡ÄÚµå¸¦ ÂüÁ¶ÇÏ½Ã¿© ±Ý°á¿ø¿¡¼­ ¹ß±Þ ¹ÞÀ¸½Ã±â ¹Ù¶ø´Ï´Ù.\n\n"
    				msg += "ÂüÁ¶¹øÈ£ : " + szRef;
    				msg += "\tÀÎ°¡ÄÚµå : " + szCode;
    			//alert(msg);
    			if (device_type == "SCARD")
    				if (typeof(NEXTACTION) == "function") {
    					NEXTACTION(false);
    				}
    			return false;
    		}				
		}
		//2011.02.24 Ãß°¡ ³¡. 
		
	} else if (szCAName == "03" ) { //ÀüÀÚÀÎÁõ
		Arg += "&CAIP=";
		Arg += URLEncode(CrossCertCAIP);
		Arg += "&CAPORT=";
		Arg += URLEncode(CrossCMPPort);
		//INITECH Ãß°¡ 090807------------------------------
		SetProperty( "isplugindevinit" , "TRUE" );
		/*		
		if(obj.CertRequest(CrossCertPackage, STORAGE2, Arg, challenge)!="true") {

			var msg = "°øÀÎÀÎÁõ¼­ ¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
				msg += "¾Æ·¡ÀÇ ÂüÁ¶¹øÈ£¿Í ÀÎ°¡ÄÚµå¸¦ ÂüÁ¶ÇÏ½Ã¿© ÀüÀÚÀÎÁõ¿¡¼­ ¹ß±Þ ¹ÞÀ¸½Ã±â ¹Ù¶ø´Ï´Ù.\n\n"
				msg += "ÂüÁ¶¹øÈ£ : " + szRef;
				msg += "\tÀÎ°¡ÄÚµå : " + szCode;
			//alert(msg);
			if (device_type == "SCARD")
				if (typeof(NEXTACTION) == "function") {
					NEXTACTION(false);
				}
			return false;
		}
		*/
		//2011.02.24 °íµµÈ­ °ü·Ã ±â¾÷ ¹ðÅ· UI ¼³Á¤ 
        if (g_private == false) {
		    // ±â¾÷ »ç¿ëÀÚ ¹Ý¿µ
		    var ret;
        	ret = obj.CertRequest(CrossCertPackage, "HDD|FDD|USB", Arg, challenge);
        	        	
        	if (ret !="true") {
                if(ret=="fail_iKeyUse")  {
            	    alert("iKey USB ÀúÀåÀåÄ¡´Â »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.");
                	return false;
            	} else if (ret=="fail_GetUSBSerial") {
            	    alert("USBÀúÀåÀåÄ¡¸¦ ÀÎ½ÄÇÒ¼ö ¾ø½À´Ï´Ù.");
            	    return false;
            	} else {
            	    var msg = "°øÀÎÀÎÁõ¼­ ¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
    				msg += "¾Æ·¡ÀÇ ÂüÁ¶¹øÈ£¿Í ÀÎ°¡ÄÚµå¸¦ ÂüÁ¶ÇÏ½Ã¿© ±Ý°á¿ø¿¡¼­ ¹ß±Þ ¹ÞÀ¸½Ã±â ¹Ù¶ø´Ï´Ù.\n\n"
    				msg += "ÂüÁ¶¹øÈ£ : " + szRef;
    				msg += "\tÀÎ°¡ÄÚµå : " + szCode;
        			//alert(msg);
        			if (device_type == "SCARD")
        				if (typeof(NEXTACTION) == "function") {
        					NEXTACTION(false);
        				}
        			return false;
            	}
        	}
		} else {
		    // °³ÀÎ »ç¿ëÀÚ ¹Ý¿µ
    		if(obj.CertRequest(CrossCertPackage, STORAGE2, Arg, challenge)!="true") {
			var msg = "°øÀÎÀÎÁõ¼­ ¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
				msg += "¾Æ·¡ÀÇ ÂüÁ¶¹øÈ£¿Í ÀÎ°¡ÄÚµå¸¦ ÂüÁ¶ÇÏ½Ã¿© ÀüÀÚÀÎÁõ¿¡¼­ ¹ß±Þ ¹ÞÀ¸½Ã±â ¹Ù¶ø´Ï´Ù.\n\n"
				msg += "ÂüÁ¶¹øÈ£ : " + szRef;
				msg += "\tÀÎ°¡ÄÚµå : " + szCode;
			//alert(msg);
			if (device_type == "SCARD")
				if (typeof(NEXTACTION) == "function") {
					NEXTACTION(false);
				}
			    return false;
		    }
		}
		//2011.02.24 Ãß°¡ ³¡. 
		
		
	} /*else if (szCAName == "SIGNKOREA" ) { //Áõ±ÇÀü»ê
		Arg += "&CAIP=";
		Arg += obj.URLEncode(SignKoreaCAIP);
		Arg += "&CAPORT=";
		Arg += obj.URLEncode(SignKoreaCMPPort);

		obj.CertRequest(SignKoreaPackage, STORAGE2, Arg, challenge);
	}*/ else {
		alert(szCAName + " Àº(´Â) Á¤ÀÇµÇÁö ¾ÊÀº CA±â°üÀÔ´Ï´Ù.");
		return false;
	}

	if (g_private == true) {		// °³ÀÎ »ç¿ëÀÚ
		//alert("ÀÎÁõ¼­ ¼³Ä¡¸¦ ¿Ï·áÇÏ¿´½À´Ï´Ù.");	
		if (device_type == "SCARD") {
		    
		    //TEST
		    //alert("PinInitUI() CALL");
		    
		    //TEST
		    /*
			if (PinInitUI()=="true")
				ret = true;
			else 
				ret = false;
			*/
			
			ret = true;
			
			//TEST
			//alert("PinInitUI() AFTER ret : "+ ret);
			
			
			if (typeof(NEXTACTION) == "function") {
				NEXTACTION(ret);
				return ret;
			}
		}
		return true;
	} else if (g_private == false) {		// ±â¾÷ »ç¿ëÀÚ
		if (PinInitUI()=="true"){		// ÀÓ½Ã SCARD & USB PIN ¹øÈ£ º¯°æ
			alert("[°ü¸®ÀÚ]ÀÇ "+g_mediaName+"¿¡ ÀÎÁõ¼­ ¼³Ä¡¸¦ ¿Ï·áÇÏ¿´½À´Ï´Ù.");
		} else{
			alert("[°ü¸®ÀÚ]ÀÇ "+g_mediaName+"ÀÇ Keyºñ¹Ð¹øÈ£ ¼³Á¤¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.");
			return false;
		}
	}
	
	if (manyusb > 1 && g_private==false) {
		//090823ÁÖ¼® :: copycert("USB|SCARD", manyusb, false);	
		//alert("º¹¼öº¹»ç STORAGE2 : " + g_firstMedia);
		copycert(g_firstMedia, manyusb, false);	
	} else if (manyusb == 1 && g_private==false) {
		display_alert_message();
		if (device_type == "SCARD")
			if (typeof(NEXTACTION) == "function") {
				NEXTACTION(true);
				return true;
			}
	} 
	//alert("true ¸®ÅÏÀü");


	return true;
}

/* °³ÀÎ ÀÎÁõ¼­ */
function UpdateCertificate2(szCAName)
{
	g_private = true;
	g_szCAName = szCAName;
	if (GetPluginDev() == "SCARD") {		
		//alert("°³ÀÎ»ç¿ëÀÚ´Â ½º¸¶Æ®Ä«µå¸¦ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.");
		//return false;
		g_manyusb = 1;
		g_mediaName = "½º¸¶Æ®Ä«µå";
		g_CopyProcess = "UPDATE";
		if (_goIframe(false) == false) {
			alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
			return false;
		} else {
			t_id = setInterval("_wait_Value(\"UPDATE\", false)", 100);
			return true;
		}
	} else if (GetPluginDev() == "USB") {
		alert("°³ÀÎ»ç¿ëÀÚ´Â USB Key¸¦ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.");
		return false;
	} else {
		g_mediaName = "";
		return UpdateCertificate2_KDB_proce(szCAName, 1);
	}
}

/* ±â¾÷ ÀÎÁõ¼­ */
function UpdateCertificate2_KDB(szCAName, manyusb)
{
    //2011.02.24 °íµµÈ­ °ü·Ã Internet Security Å°¿¡ ÀÎÁõ¼­¸¦ ¹ß±Þ Â÷´ÜÇÏ´Â ±â´É Ãß°¡ 
    //SetProperty("iKeyNoUseOfCertRequest","true");
    //2011.02.24 Ãß°¡ ³¡.
    
	g_CopyProcess = "UPDATE";
	g_szCAName = szCAName;
	g_private = false;
	if (GetPluginDev() == "USB") {
		g_mediaName = "USB Key";
		g_firstMedia = "USB";
		alert("ÀÎÁõ¼­¸¦ ¼³Ä¡ÇÕ´Ï´Ù.\n[°ü¸®ÀÚ]ÀÇ USB Key¸¦ »ðÀÔÇÏ½Å ÈÄ È®ÀÎÀ» ´©¸£½Ê½Ã¿À");
		return UpdateCertificate2_KDB_proce(szCAName, manyusb);
	} else if (GetPluginDev() == "SCARD") {
		g_manyusb = manyusb;
		g_mediaName = "½º¸¶Æ®Ä«µå";
		g_firstMedia = "SCARD";
		if (_goIframe(false) == false) {
			alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
			return false;
		} else {
			t_id = setInterval("_wait_Value(\"UPDATE\", false)", 100);
			return true;
		}
	} else {
		alert("±â¾÷»ç¿ëÀÚ´Â USB Key¿Í ½º¸¶Æ®Ä«µå¸¸ »ç¿ë°¡´ÉÇÕ´Ï´Ù.");
		return false;
	}
}

/* ÀüÀÚ¼¼±Ý°è»ê¼­¿ë */
function UpdateCertificate2_ESERO(szCAName)
{

	var Arg = "";
	var challenge = "1111";
	
	// »ê¾÷ÀºÇà Àü¿ë UI Àû¿ë Flag	1:°³ÀÎ 2:±â¾÷ 0:¹ü¿ë(»êÀºÀÌ¿Ü)
	SetProperty("certmanui_setkdbusedproperty" , "2" );
	SetProperty("IssueSkipOKAlertUI" , "yes" );
	SetProperty("skip_savecertsuggest" , "TRUE" );

	STORAGE2 = "HDD|FDD|PHONE";
	
	if (szCAName == "01" ) { // ±Ý°á¿ø
		Arg += "CAIP=";
		Arg += URLEncode(YessignCAIP);
		Arg += "&CAPORT=";
		Arg += URLEncode(YessignCMPPort);
		//090807
		SetProperty( "updatecertresetpsw" , "TRUE");
		SetProperty( "isplugindevinit" , "TRUE" );	
		if (obj.CertUpdate(YessignPackage, STORAGE2, Arg) == "") {
			var msg = "°øÀÎÀÎÁõ¼­ Àç¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
			//alert(msg);
			return false;
		}
	} else if (szCAName == "03" ) { //ÀüÀÚÀÎÁõ
		Arg += "&CAIP=";
		Arg += URLEncode(CrossCertCAIP);
		Arg += "&CAPORT=";
		Arg += URLEncode(CrossCMPPort);
		//090807
		SetProperty( "updatecertresetpsw" , "TRUE");
		SetProperty( "isplugindevinit" , "TRUE" );	
		if (obj.CertUpdate(CrossCertPackage, STORAGE2, Arg) == "") {
			var msg = "°øÀÎÀÎÁõ¼­ Àç¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
			//alert(msg);
			return false;
		}
	} else {
		alert(szCAName + " Àº(´Â) Á¤ÀÇµÇÁö ¾ÊÀº CA±â°üÀÔ´Ï´Ù.");
		return false;
	}
	return true;
}

function UpdateCertificate2_KDB_proce(szCAName, manyusb)
{
 
	obj = ModuleInstallCheck();
	if (obj == null) return false;

	var Arg = "";
	var challenge = "1111";
	var device_type = GetPluginDev();
	//090816c
	SetProperty( "IssueSkipOKAlertUI" , "yes" );
	SetProperty( "skip_savecertsuggest" , "TRUE" );
	if (g_private == false && (device_type == "SCARD" || device_type == "USB")) {
		if (PinInit() != "true") {
			alert("ÀúÀå ¸ÅÃ¼ ÃÊ±âÈ­¿¡ ½ÇÆÐÇß½À´Ï´Ù.");
			return false;
		}
	}
	if (g_private == true && (/*device_type == "SCARD" ||*/ device_type == "USB")) {
		//alert("°³ÀÎ»ç¿ëÀÚ´Â USB Key³ª ½º¸¶Æ®Ä«µå¸¦ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.");
		alert("°³ÀÎ»ç¿ëÀÚ´Â USB Key¸¦ Áö¿øÇÏÁö ¾Ê½À´Ï´Ù.");
		return false;
	}
	if (szCAName == "01" ) { // ±Ý°á¿ø
		Arg += "CAIP=";
		Arg += obj.URLEncode(YessignCAIP);
		Arg += "&CAPORT=";
		Arg += obj.URLEncode(YessignCMPPort);
		//090807
		SetProperty( "updatecertresetpsw" , "TRUE");
		SetProperty( "isplugindevinit" , "TRUE" );	
		/*		
    		if (obj.CertUpdate(YessignPackage, STORAGE2, Arg) == "") {
    			var msg = "°øÀÎÀÎÁõ¼­ Àç¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
    			//alert(msg);
    			return false;
    		}
		*/
		//2011.02.24 °íµµÈ­ °ü·Ã ±â¾÷ ¹ðÅ· UI ¼³Á¤ 
        if (g_private == false) {
		    // ±â¾÷ »ç¿ëÀÚ ¹Ý¿µ
		    var ret;
        	ret = obj.CertUpdate(YessignPackage, "HDD|FDD|USB", Arg);
        	        	
        	if (ret !="true") {
                if(ret=="fail_iKeyUse")  {
            	    alert("iKey USB ÀúÀåÀåÄ¡´Â »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.");
                	return false;
            	} else if (ret=="fail_GetUSBSerial") {
            	    alert("USBÀúÀåÀåÄ¡¸¦ ÀÎ½ÄÇÒ¼ö ¾ø½À´Ï´Ù.");
            	    return false;
            	} else {
            	    var msg = "°øÀÎÀÎÁõ¼­ Àç¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
        			//alert(msg);
        			return false;
            	}
        	}
		} else {
		    // °³ÀÎ »ç¿ëÀÚ ¹Ý¿µ
    		if (obj.CertUpdate(YessignPackage, STORAGE2, Arg) == "") {
    			var msg = "°øÀÎÀÎÁõ¼­ Àç¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
    			//alert(msg);
    			return false;
    		}
		}
		//2011.02.24 Ãß°¡ ³¡.
		
	} else if (szCAName == "03" ) { //ÀüÀÚÀÎÁõ
		Arg += "&CAIP=";
		Arg += obj.URLEncode(CrossCertCAIP);
		Arg += "&CAPORT=";
		Arg += obj.URLEncode(CrossCMPPort);
		//090807
		SetProperty( "updatecertresetpsw" , "TRUE");
		SetProperty( "isplugindevinit" , "TRUE" );	
		/*
		if (obj.CertUpdate(CrossCertPackage, STORAGE2, Arg) == "") {
			var msg = "°øÀÎÀÎÁõ¼­ Àç¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
			//alert(msg);
			return false;
		}
		*/

		//2011.02.24 °íµµÈ­ °ü·Ã ±â¾÷ ¹ðÅ· UI ¼³Á¤ 
        if (g_private == false) {
		    // ±â¾÷ »ç¿ëÀÚ ¹Ý¿µ
		    var ret;
        	ret = obj.CertUpdate(CrossCertPackage, "HDD|FDD|USB", Arg);
        	        	
        	if (ret !="true") {
                if(ret=="fail_iKeyUse")  {
            	    alert("iKey USB ÀúÀåÀåÄ¡´Â »ç¿ëÇÒ ¼ö ¾ø½À´Ï´Ù.");
                	return false;
            	} else if (ret=="fail_GetUSBSerial") {
            	    alert("USBÀúÀåÀåÄ¡¸¦ ÀÎ½ÄÇÒ¼ö ¾ø½À´Ï´Ù.");
            	    return false;
            	} else {
            	    var msg = "°øÀÎÀÎÁõ¼­ Àç¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
        			//alert(msg);
        			return false;
            	}
        	}
		} else {
		    // °³ÀÎ »ç¿ëÀÚ ¹Ý¿µ
    		if (obj.CertUpdate(CrossCertPackage, STORAGE2, Arg) == "") {
    			var msg = "°øÀÎÀÎÁõ¼­ Àç¹ß±Þ½Ã ¿À·ù°¡ ¹ß»ýÇÏ¿© ÀÎÁõ¼­ ¹ß±Þ¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.\n"
    			//alert(msg);
    			return false;
    		}
		}
		//2011.02.24 Ãß°¡ ³¡.		
		
	}/* else if (szCAName == "SIGNKOREA" ) { //Áõ±ÇÀü»ê
		Arg += "&CAIP=";
		Arg += obj.URLEncode(SignKoreaCAIP);
		Arg += "&CAPORT=";
		Arg += obj.URLEncode(SignKoreaCMPPort);

		obj.CertUpdate(SignKoreaPackage, "", Arg);
	} */else {
		alert(szCAName + " Àº(´Â) Á¤ÀÇµÇÁö ¾ÊÀº CA±â°üÀÔ´Ï´Ù.");
		return false;
	}

	if (g_private == true) {		// °³ÀÎ »ç¿ëÀÚ
		//alert("ÀÎÁõ¼­ ¼³Ä¡¸¦ ¿Ï·áÇÏ¿´½À´Ï´Ù.");
		if (device_type == "SCARD")
			if (typeof(NEXTACTION) == "function") {
				NEXTACTION(true);
				return true;
			}
		return true;
	} else if (g_private == false) {		// ±â¾÷ »ç¿ëÀÚ
		if (PinInitUI()=="true"){		// ÀÓ½Ã SCARD & USB PIN ¹øÈ£ º¯°æ
			alert("[°ü¸®ÀÚ]ÀÇ "+g_mediaName+"¿¡ ÀÎÁõ¼­ ¼³Ä¡¸¦ ¿Ï·áÇÏ¿´½À´Ï´Ù.");
		} else{
			alert("[°ü¸®ÀÚ]ÀÇ "+g_mediaName+"ÀÇ Keyºñ¹Ð¹øÈ£ ¼³Á¤¿¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù.");
			return false;
		}
	}
	
	if (manyusb > 1 && g_private==false) {
		//090823 ÁÖ¼® :: copycert("USB|SCARD", manyusb, false);	
		copycert(g_firstMedia, manyusb, false);	
	} else if (manyusb == 1 && g_private==false) {
		display_alert_message();
		if (device_type == "SCARD")
			if (typeof(NEXTACTION) == "function") {
				NEXTACTION(true);
				return true;
			}
	}

	return true;
}

function RevokeCertificate2(szCAName, serial)
{
    //alert("RevokeCertificate2");
    //alert("szCAName :   "+szCAName);
    //alert("serial   :   "+serial);
    
    obj = ModuleInstallCheck();
    if (obj == null) return false;

	if (szCAName == "01" ) { // ±Ý°á¿ø
		rc = obj.DeleteUserCert(YessignPackage, "", serial);
	} else if (szCAName == "03" ) { //ÀüÀÚÀÎÁõ
		rc = obj.DeleteUserCert(CrossCertPackage, "", serial);
	} /*else if (szCAName == "SIGNKOREA" ) { //Áõ±ÇÀü»ê
		rc = obj.DeleteUserCert(SignKoreaPackage, "", serial);
	} */else {
		//alert("Á¤ÀÇµÇÁö ¾ÊÀº CA±â°üÀÔ´Ï´Ù.");
		return false;
	}
	
	if( rc )
	{
		//alert("ÇØ´ç ÀÎÁõ¼­¸¦ »èÁ¦ÇÏ¿´½À´Ï´Ù.");
		return true;
	}
	else
	{
		//alert("ÇöÀç »ç¿ëÁßÀÎ ÄÄÇ»ÅÍ¿¡ ÇØ´ç ÀÎÁõ¼­°¡ ¾ø¾î¼­ »èÁ¦ÇÏÁö ¸øÇß½À´Ï´Ù.");
		return false;
	}
}


function MultiPKCS7SignedData(form, data, view, index)
{
	var ver = "4, 1, 14, 0";
	var pkcs7Str = "";

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}
	if(EnableFunction(ver)) {
		/*
		eval("document."+form.name+".PKCS7SignedData"+index).value = obj.PKCS7SignData("sha1", data, TimeURL, view);  
		return true;
		*/
		pkcs7Str = obj.PKCS7SignData("sha1", data, TimeURL, view);

		if (pkcs7Str==""){
			return false;
		}else{
			eval("document."+form.name+".PKCS7SignedData"+index).value = pkcs7Str;
			return true;
		}
		
	} else {
		var msg;
		msg = "ÇöÀç ¼³Ä¡µÈ ¹öÀü V " + GetVersion() + " ¿¡¼­´Â ÀüÀÚ¼­¸í ±â´ÉÀ» Áö¿øÇÏÁö ¾Ê½À´Ï´Ù."
		msg += "\n\nV " + ver + " ÀÌ»óÀ¸·Î ¾÷±×·¹ÀÌµå ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù."
		if (EnableMsg) alert(msg);
			return false;
	}
} 

//20090730 ÆË¾÷ ¹× ¸ð´ÞÃ¢°ü·Ã ¼öÁ¤/Active-X ¸ðµâ  
function FrameCheck_ActiveX()
{
	if (typeof document.KDBDevObj != "undefined") 
	{
		__secureframe__ = self;
	} 
	else 
	{
		framecount = 0;		
		__secureframe__ = FindSecureFrame(parent);
		
		//ÆË¾÷,¸ð´Þ ÆË¾÷Ã¢ÀÎ °æ¿ì Ãß°¡  
		//¸ð´ÞÃ¢À» »ý¼º½Ã window°³Ã¼¸¦ Arguments·Î Àü´ÞÇßÀ»°æ¿ì »ç¿ë°¡´É  
		if (__secureframe__ == null) {
			var open_frame = null;
			open_frame = top.opener;

			//opener°¡ ¾øÀ»°æ¿ì ¸ð´ÞÃ¢À¸·Î ÆÇ´Ü ¸ð´ÞÃ¢À¸·Î ³Ñ°Ü¹ÞÀº À©µµ¿ì °³Ã¼¸¦ open_frameÀ¸·Î ¼³Á¤  
			if ((typeof open_frame) == "undefined" && (typeof window.dialogArguments)!="undefined")
			{
				open_frame = window.dialogArguments;
			}
			//ÃÖ»óÀ§ opener±îÁö Ã£¾Æ°£´Ù.  
			while((typeof open_frame) != "undefined")
			{
				 if((typeof open_frame.document) == "unknown"){break;}//opener°¡ Á¸ÀçÇÏ´ÂÁö ¿©ºÎ Ã¼Å©  
				framecount = 0;
				 __secureframe__ = FindSecureFrame(open_frame);
				 
				if (__secureframe__ != null){
					break;
				}else{							
					var t_open_frame = open_frame;
					open_frame = open_frame.top.opener;

					if ((typeof open_frame) == "undefined" && (typeof t_open_frame.window.dialogArguments)!="undefined")//opener°¡ ¾øÀ»°æ¿ì ¸ð´ÞÀ¸·Î ÆÇ´Ü  
					{
						open_frame = t_open_frame.window.dialogArguments;
					}
				}
			}
		}
	}
}





/********************************************************************************************************************************
 ********************************************************************************************************************************
 ONLY KDB(2009.09.30) - // 20090730 Active-X ¸ðµâ
 ********************************************************************************************************************************
 ********************************************************************************************************************************/
function EncLink(url, encData, target, style)
{
	//document.domain = "kdb.co.kr";
	var queryString = "INIpluginData=";
	var INIdata;

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert(secureframe_errmsg);
		return false;
	}

	//modify brson 2002/06/11 
	//dt¿¡ server time Ãß°¡
	var ver="4,2,0,0";
	if(AddServerTime && EnableFunction(ver)) {
		if(encData!=""){
				encData = "__INIts__=" + obj.GetServerTime(TimeURL) + "&" + encData;
		}
		else{
				encData = "__INIts__=" + obj.GetServerTime(TimeURL);
		}
	}
	// °íµµÈ­ °ü·Ã 20110129
	if ((INIdata = obj.MakeINIpluginData("10", cipher, encData, TimeURL))=="") return;
	queryString += obj.URLEncode(INIdata);
	if(url.indexOf('?', 0) < 0) url += "?";
	if((url.charAt(url.length-1)!='?') && (url.charAt(url.length-1)!='&')) url += "&";
	url += queryString;
	
	//alert("url==>"+url); 
	
	//ÆË¾÷Ã¢ÀÌ Ç×»ó °¡¿îµ¥¿¡ È­¸é °¡¿îµ¥¿¡ ¶ßµµ·Ï ¼öÁ¤ WebCash
	var sVal = style.split(",");
	var tmpWidth = "";
	var tmpHeight = "";
	var tmpStr = "";
       
	for(i = 0 ; i < sVal.length ; i++) {
		tmpStr = ib_trim(sVal[i]).toLowerCase();

		if(tmpStr.indexOf("width=") >= 0) {
			tmpWidth = tmpStr.substring(tmpStr.indexOf("=")+1);
		}
		if(tmpStr.indexOf("height=") >= 0) {
			tmpHeight = tmpStr.substring(tmpStr.indexOf("=")+1);
		}
	}
	if(tmpWidth != "" && tmpHeight != "") {
		var nLeft  = screen.width/2 - tmpWidth/2 ;
		var nTop   = screen.height/2 - tmpHeight/2 ;
		style = "left=" + nLeft + ",top=" +  nTop + "," + style;
	}
	
	var kdbNa = window.open(url, target, style);
	return kdbNa;
	//window.showModalDialog(url, target, style); 
 
}

/* WebCash Ãß°¡ */
function ib_trim(str){
    return str.replace(/(^\s*)|(\s*$)/g,"");
}

 
 function ModuleInstallCheck_ActiveX()
{
	FrameCheck_ActiveX();
	if (__secureframe__==null) return;
	if(navigator.appName == "Netscape")
	{
		return __secureframe__.document.KDBDevObj;
	}
	else
	{
		if(__secureframe__.KDBDevObj==null || typeof(__secureframe__.KDBDevObj) == "undefined" || __secureframe__.KDBDevObj.object==null) { return null;}
		else { return __secureframe__.KDBDevObj; }
	}
}


















/* --------------------------------------------------------- */			
// °³ ¹ß  ¾÷ Ã¼ : Initech Co., Ltd.
// ÃÖÃÊÀÛ¼ºÀÏÀÚ : 2009. 07. 14
// ÃÖÁ¾º¯°æÀÏÀÚ : 2009. 07. 14(Oh Soon Keun)
/* --------------------------------------------------------- */			


var g_alert_flag = false;										// for debug
var g_CurDev = "";												// ÇöÀç ²ÈÇôÀÖ´Â ¸ÅÃ¼¸¦ °¡Á®¿Â´Ù.
var g_dfkey = "";												// smartcard derivation key

var g_cur_count;
var g_total_count;
var g_repasswd_flag;
var g_beforeCsn = "";
var t_id;
var t_count=0;
var g_before_serial;

function install_error()
{
	var errmsg = "»ç¿ëÀÚ ¿äÃ» ¶Ç´Â ¿À·ù¿¡ ÀÇÇØ ¸ðµâÀÌ ¼³Ä¡(¶Ç´Â ¾÷µ¥ÀÌÆ®)µÇÁö ¾Ê¾Ò½À´Ï´Ù.\r\n\r\n -. ¸ðµâ ¼³Ä¡°¡ ¾ÈµÉ °æ¿ì ¼³Ä¡È­¸é¿¡ ¾È³»¸¦ ÂüÁ¶ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.\r\n -. À©µµ¿ìÁî XP ¼­ºñ½º ÆÑ2 »ç¿ëÀÚ´Â »ó´Ü¿¡ ¼³Ä¡ ÅÇÀ» Å¬¸¯ÇÏ½Ê½Ã¿À.\r\n -. ±ÇÇÑÀÌ Á¦ÇÑµÈ »ç¿ëÀÚÀÇ °æ¿ì ¹Ýµå½Ã °ü¸®ÀÚ(Administrator) °èÁ¤À¸·Î ¼³Ä¡ÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.";
	document.body.onload = "";
	alert(errmsg);
}

function InstallModule_ActiveX()
{

	var KDBDevObj = ModuleInstallCheck_ActiveX();

	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return false;
	} else {
		return true;
		//alert("OK");
	}

	if(typeof(KDBDevObj) == "undefined")
	{
		//alert("undefined");
		return false;
	}	
	if(KDBDevObj == null)
	{
		return false;
		//alert("no object");
	}
}	
		
function SetDFValue(dfv)
{
	g_dfkey = dfv;
}

function GetDFValue()
{
	if (g_alert_flag) alert("GetDFValue() => " + g_CurDev + ", " + g_dfkey);
	if (g_CurDev != "SCARD") {
		return "";
	}
	return g_dfkey;
}

function GetPluginDev()
{
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	g_CurDev = KDBDevObj.GetPluginDev();
	if (g_alert_flag) alert("GetPluginDev() => " + g_CurDev);

	if (g_CurDev != "USB" && g_CurDev != "SCARD") {
		g_CurDev = "unknown";
	}
	if (g_CurDev != "SCARD") {
		SetDFValue("");
	}

	return g_CurDev;
}

//ÇÉ°ªÀÌ ÃÊ±âÇÉÀÎÁö ¾Ë¾Æ¿Â´Ù
//¸¶°Å "11111111"
//ÀÎÅÍ³Ý½ÃÅ¥¸®Æ¼ "12345678"
//½º¸¶Æ®Ä«µå "000000"
function IsInitPin()
{
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	var ret = KDBDevObj.IsInitPin( g_CurDev );	
	if (g_alert_flag) alert("IsInitPin() => " + ret);
	return ret;

}
	
//ÃÊ±âÇÉ °ªÀ¸·Î º¯°æÇÔ ( ³»ºÎ³»¿ëÀº Áö¿ìÁö ¾Ê´Â´Ù / ¸¸ÀÏ LockÀÌ µÇ¾îÀÖ´Â °æ¿ì ³»ºÎ ³»¿ëµµ Áö¿î´Ù )
function PinInitUI()
{
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

    //TEST
    //alert("PinInitUI : "+ g_CurDev + ", "+ GetDFValue() );
	var ret = KDBDevObj.PinInitUI(g_CurDev, GetDFValue() );
	//alert("KDBDevObj.PinInitUI(g_CurDev, GetDFValue() ) ret="+ret);
	
	return ret;
}

function PinInit()
{
    //TEST
    //alert("PinInit : "+ g_CurDev + ", "+ GetDFValue() );
    
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}
	var ret = KDBDevObj.PinInit( g_CurDev , "", GetDFValue() );

	if (g_alert_flag) alert("PinInit() => " + ret);
	return ret;
}

//ÇÉ°ªÀ» º¯°æÇÔ
function ChangePinUI()
{
    //TEST
    //alert("PinInit : "+ g_CurDev + ", "+ GetDFValue() );
    
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	var ret = KDBDevObj.ChangePinUI( g_CurDev );
	return ret ;
}

function ChangePin(strOldPin, strNewPin)
{
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	var ret = KDBDevObj.ChangePin( g_CurDev , strOldPin , strNewPin );
	if (g_alert_flag) alert(ret + " - " + strOldPin + "->" + strNewPin );
	return ret;
}

function PinVerifyUI()
{
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	var ret = KDBDevObj.PinVerifyUI( g_CurDev );
	return ret ;
}

function PinVerify(strPin)
{
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	var ret = KDBDevObj.PinVerify( g_CurDev , strPin );
	if (g_alert_flag) alert(ret + " - " + strPin);

	return ret ;
		

}

function GetSerial()
{
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	var ret = KDBDevObj.GetSerial( g_CurDev );
	if (g_alert_flag) alert(ret);
	return ret;
}



function checkIFrame()
{
	if (document.iframe==null || typeof(document.iframe) == "undefined") {
		return false;
	}
	return true;
}

function check_inipin()//·Î±×ÀÎ ½Ã ¸ÅÃ¼ÀÇ PIN¹øÈ£°¡ ÃÊ±âPINÀÎÁö È®ÀÎÇØÁÖ°í ¾Æ´Ï¸é ¼³Á¤ UI
{

	if (InstallModule_ActiveX() == false) {
		setTimeout("check_inipin()", 100);
	} else {
		GetPluginDev();
		if (g_CurDev == "USB") {
			if (IsInitPin() == "true") 
			return PinInitUI();
		} else if (g_CurDev == "SCARD") {
			if (IsInitPin() == "true") {
				PinInitUI_SCARD();
			}
		}
		
	}
}

function PinInit_SCARD()
{
	if (_goIframe(false) == false) {
		return null;
	}
	
	t_id = setInterval("_wait_Value(\"INIT\", false)", 100);
}

function PinInitUI_SCARD() {
	if (_goIframe(false) == false) {
		return null;
	}
	
	t_id = setInterval("_wait_Value(\"INIT_UI\", false)", 100);
}

function GetCardSerial()	// TEMP
{
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	var ret = KDBDevObj.GetExternalSerial( g_CurDev );
	if (g_alert_flag) alert(ret);
	return ret;
}

// 20090813 mediaÀÇ ¾ÏÈ£È­µÈ PIN °ªÀ» °¡Á®¿Â´Ù.
function GetPin(media)
{
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	var ret = KDBDevObj.GetPin(media);
	if (g_alert_flag) alert(ret);
	return ret;	
}


// ½º¸¶Æ® Ä«µå derivation key¸¦ ¾ò±âÀ§ÇØ Àü¹® Àü¼Û
function _goIframe(copy_flag)
{
	if (checkIFrame() == false) {
		alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return false;
	}
	while(GetPluginDev() != "SCARD") {
		if (confirm("½º¸¶Æ®Ä«µå¸¦ »ðÀÔÇÏ¼¼¿ä.\n°è¼Ó ÁøÇàÇÕ´Ï±î?")) {
			continue;
		} else {
			return false;
		}
	}

	var csn = GetCardSerial();
	SetDFValue("");

	if (true) {
		for(var i=0; i<=10; i++) {
			if(csn == g_beforeCsn) {
				alert("½º¸¶Æ®Ä«µå¸¦ ¹Ù²ÙÁö ¾Ê¾Ò½À´Ï´Ù.\n\n´Ù¸¥ ½º¸¶Æ®Ä«µå¸¦ »ðÀÔÇÏ°í È®ÀÎÀ» ´©¸£½Ê½Ã¿À.");
				csn = GetCardSerial();
			} else {
				break;
			}
		}
	}

	var attach = "";
	attach += "/jsp/cer/cer5/Cer510A01K_01.jsp?";
	attach += "hi_keyDerivationData=";
	attach += "&hi_keyVersion=99"
	attach += "&hi_keyIndex=99";
	attach += "&hi_terminalRandom=";
	attach += "&hi_cardRandom=";
	attach += "&hi_cardCryptogram=";
	attach += "&hi_csn="+csn;
    
    //TEST
    //alert(attach);
	// IFrame À» ÀÌ¿ëÇØ¼­ Scard Derivation Key¸¦ ¾ò±â À§ÇÑ Àü¹® Àü¼Û
	document.iframe.location.href = EncLocation(attach);

	g_beforeCsn = csn;
}

function saveDFvalue(dftemp)
{
	SetDFValue(dftemp);
}

/*
	½º¸¶Æ® Ä«µåÀÇ derivation key¸¦ ¾òÀ» ¶§±îÁö ´ë±âÇÔ.
*/
function _wait_Value(type, repwd_flag)
{
	var ret;
	
	if (t_count > 10 * 30) {	
		clearInterval(t_id);
		return;
	} else if (GetDFValue() != "") {
		clearInterval(t_id);
		t_count = 0;
		switch (type) {
			case "INIT":				// PIN Init
				ret = PinInit();
				if (typeof(NEXTACTION) == "function") {
					NEXTACTION(ret);
				}
				break;
			case "INIT_UI":				// PIN Init UI
				ret = PinInitUI();
				if (typeof(NEXTACTION) == "function") {
					NEXTACTION(ret);
				}
				break;
			case "COPY":				// copy scard
				ret = copycert_scard("COPY");		// copy process
				break;
			case "COPY_OTHER":				// copy scard
				//alert("copyCert_other_scard(\"COPY\");");
				ret = copyCert_other_scard("COPY");		// copy process
				break;
			case "ISSUE":				// copy scard
				//PinInit();
				IssueCertificate2_KDB_proce(g_szCAName, g_szRef, g_szCode, g_manyusb);
				break;
			case "UPDATE":				// update scard
				//PinInit();
				UpdateCertificate2_KDB_proce(g_szCAName, g_manyusb);
				break;
			default:
				break;

		}
		SetDFValue("");
		//issueCertICCard(strRef,strAuth,strIdn,strUseusb,strManyusb);
		return;
	} else {
        t_count++;
	}
}

/*	function SelectMedia(media)
	{
		var KDBDevObj = ModuleInstallCheck_ActiveX();
		if (KDBDevObj == null) {
			//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
			return null;
		}
		var ret = KDBDevObj.SelectMedia(media);

		return ret;
	}*/


/*
	function copycert(from, count, repwd_flag)
	Parameters
		from : º¹»çÇÒ ÀÎÁõ¼­¸¦ ÀÐ¾î ¿Ã ÀúÀå ¸ÅÃ¼
		count : ÀÎÁõ¼­ º¹»ç È½¼ö
		repwd_flag : ÀÎÁõ¼­ º¹»ç ½Ã ÀÎÁõ¼­ ¾ÏÈ£ Àç¼³Á¤ ¿©ºÎ,					
					 trueÀÎ °æ¿ì º¹»ç °úÁ¤ ¹«ÇÑ ¹Ýº¹ (count¿¡ ¿µÇâ¹ÞÁö ¾ÊÀ½)	
					 true : ÀÎÁõ¼­ º¹»ç½Ã »ç¿ë
					 false : ÀÎÁõ¼­ ¹ß±Þ/Àç¹ß±Þ/°»½Å ½Ã »ç¿ë
*/

function copycert(from, count, repwd_flag) 
{
	if (GetPluginDev() == "USB" && (from == "USB" || from == "USB|SCARD")) {
		if (repwd_flag) {
		//	nMedia => 1: SCARD, 2: USB, 3: HDD
			if (loadCertFromMedia(2) != "success")
				return false;
		} 
		return copycert_usb(count, repwd_flag);
	} else if (GetPluginDev() == "SCARD" && (from == "SCARD" || from == "USB|SCARD")) {
		g_cur_count = 0;
		g_total_count = count;
		g_repasswd_flag = repwd_flag;
		if (repwd_flag) {
			if (loadCertFromMedia(1) != "success")
				return false;
		} else {
			obj = ModuleInstallCheck();
			if (obj == null) {
				alert("¾ÏÈ£È­ ÇÁ·¹ÀÓ(secureframe)À» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
				return false;
			}
		}	
		if (GetPluginDev() != "SCARD") {
			alert("½º¸¶Æ®Ä«µå°¡ »ðÀÔµÇÁö ¾Ê¾Ò½À´Ï´Ù.");
			return false;
		} else {
			g_beforeCsn = GetCardSerial();
			g_before_serial = GetSerial();
		}
		g_cur_count = 2;
		copycert_scard("READY");	// check smart card, and ready to scard
	} else {
		alert("¸ÅÃ¼°¡ ÁØºñµÇÁö ¾Ê¾Ò½À´Ï´Ù.");
		if (typeof(NEXTACTION) == "function") {
			NEXTACTION(false);
		}
		return false;
	}
}

function copycert_usb(count, repwd_flag) 
{
	var obj, ret;	
	g_total_count = count;
	
	obj = ModuleInstallCheck();
	if (obj == null) {
		alert("¾ÏÈ£È­ ÇÁ·¹ÀÓ(secureframe)À» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return false;
	}

	GetPluginDev();
	g_before_serial = GetSerial();
	if (repwd_flag) {
		g_CopyProcess = "LOGIN";
		if (copyCert2(2) == "success") {
			return true;
		} 
	} else {
		g_cur_count = 2;		// ÀÌ¹Ì °ü¸®ÀÚ ÀÎÁõ¼­¸¦ ÀúÀåÇßÀ¸¹Ç·Î, 2ÀåÂ° º¹»ç¸¦ ½ÃÀÛÇÑ´Ù.
		while(g_total_count >= g_cur_count) {
			strMsg = "[ÀÌ¿ëÀÚ "+g_cur_count+"/"+g_total_count+"]ÀÇ ÀÎÁõ¼­¸¦ ¼³Ä¡ÇÕ´Ï´Ù.\n";
			strMsg += "¼³Ä¡ÇÒ ÀÌ¿ëÀÚ USB Key·Î ¹Ù²Ù¾î ÁÖ½Ê½Ã¿À\n";
			strMsg += "°è¼Ó ÁøÇàÇÕ´Ï±î?";
			if (!confirm(strMsg)) 
				break;
			
			if (copyCert(2) == "success") {
				g_cur_count++;
			} 
		}
			
		display_alert_message();
	
		return true;
	}
	return false;
}

function copycert_scard(copy_process)
{
	//g_cur_count, g_total_count, g_repasswd_flag
	var obj;
	var copy_flag = "yes";
	var to = null;
	
	obj = ModuleInstallCheck();
	if (obj == null) {
		alert("¾ÏÈ£È­ ÇÁ·¹ÀÓ(secureframe)À» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return false;
	}
	if (copy_process == "READY") {			// ½º¸¶Æ® Ä«µå º¹»ç ÁØºñ, Ä«µå»ðÀÔ¿©ºÎ Ã¼Å©, derivation key Àü¹® Àü¼Û
		if (!g_repasswd_flag) {
			while (g_total_count >= g_cur_count) {
				strMsg = "[ÀÌ¿ëÀÚ "+g_cur_count+"/"+g_total_count+"]ÀÇ ÀÎÁõ¼­¸¦ ¼³Ä¡ÇÕ´Ï´Ù.\n";
				strMsg += "¼³Ä¡ÇÒ ÀÌ¿ëÀÚ ½º¸¶Æ®Ä«µå·Î ¹Ù²Ù¾î ÁÖ½Ê½Ã¿À\n";
				strMsg += "°è¼Ó ÁøÇàÇÕ´Ï±î?";
				if (!confirm(strMsg)) {
					// ¹ß±Þ º¹»ç Áß ÁßÁöÇÑ °æ¿ì
					display_alert_message();
					if (typeof(NEXTACTION) == "function") {
						NEXTACTION(true);
						return true;
					}	
				}
				if (GetPluginDev() != "SCARD") {
					alert("½º¸¶Æ®Ä«µå°¡ »ðÀÔµÇÁö ¾Ê¾Ò½À´Ï´Ù.");
					continue;
				}
				if(g_before_serial == GetSerial()) {	// serial °ªÀ¸·Î ¸ÅÃ¼ ±³Ã¼ ¿©ºÎ Ã¼Å©
					alert("ÀúÀå¸ÅÃ¼°¡ ±³Ã¼µÇÁö ¾Ê¾Ò½À´Ï´Ù.");
					continue;
				}
				break;
			}			
		} else {
			if (!confirm("ÀÎÁõ¼­¸¦ º¹»çÇÕ´Ï´Ù\nÀÌ¿ëÀÚÀÇ ½º¸¶Æ®Ä«µå°¡ »ðÀÔµÇ¾ú½À´Ï±î?")) {
				alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
				NEXTACTION(check_copy_count());
				return "cancel";
			} else {
				while ("SCARD" != GetPluginDev()) {
					if (!confirm("ÀÌ¿ëÀÚÀÇ ½º¸¶Æ®Ä«µå¸¦ »ðÀÔÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.")) {
						alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
						if (typeof(NEXTACTION) == "function") {
							NEXTACTION(check_copy_count());
							return "cancel";
						}							
					}
				}
			}
		}
			
		if (_goIframe(false) == false) {
			alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
			if (typeof(NEXTACTION) == "function") {
				NEXTACTION(check_copy_count());
				return "cancel";
			}	
			//return true;
		} else {
			t_id = setInterval("_wait_Value(\"COPY\", "+g_repasswd_flag+")", 100);
			return true;
		}
	} else if (copy_process == "COPY") {		// ½ÇÁ¦ º¹»ç ÁøÇà
		if (PinInit() == "false") {
			alert("ÀúÀå¸ÅÃ¼ PIN ¹øÈ£ ÃÊ±âÈ­¿¡ ½ÇÆÐÇß½À´Ï´Ù.");
			copy_flag = "no";
		}				

		if (copy_flag == "yes") {
			//ExtendMethodÀÇ certcopytotargetÀ» È£ÃâÇÏ¿© Å¸ÄÏ¿¡ ·ÎµùµÈ ÀÎÁõ¼­ º¹»ç
			//to => MEDIA_TYPE|DEFAULT_KEY|resetpwd (option)
			to = "SCARD&000000";
			if (g_repasswd_flag)
				to += "&resetpwd";			// ÀÎÁõ¼­ ÆÐ½º¿öµå Àç¼³Á¤
			SetProperty("certmanui_setkdbusedproperty", "2" );
			copy_flag = obj.ExtendMethod( "certcopytotarget" , to ) ;
		}
		if (copy_flag == "yes") {		
			g_before_serial = GetSerial(); // º¹»ç¸¦ ¼º°øÇÑ °æ¿ì ÇöÀç serialÀ» ÀúÀå
			g_cur_count++;
			if (g_repasswd_flag)
				alert("ÀÎÁõ¼­ º¹»ç¸¦ ¿Ï·áÇß½À´Ï´Ù.");
			else {
				return copycert_scard("READY");  // ´ÙÀ½ º¹»ç¸¦À§ÇØ ÁØºñ ´Ü°è·Î
			}
		} else if(copy_flag =="no") {
			alert("ÀÎÁõ¼­ º¹»ç¸¦ ½ÇÆÐÇß½À´Ï´Ù." || copy_flag =="user_password_incorrect");
		} else if(copy_flag =="user_canceled") {
			alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
		}		
	
		if (g_total_count >= g_cur_count) {
			if (confirm("ÀÎÁõ¼­ º¹»ç¸¦ Ãß°¡·Î ÁøÇàÇÏ½Ã°Ú½À´Ï±î?")) {
				copycert_scard("READY");
				return true;		
			}
		}
		// ´ÙÁß º¹»ç ÁßÁö
		display_alert_message();
		if (typeof(NEXTACTION) == "function") {
			NEXTACTION(check_copy_count());
			return false;
		}		
	}
}

function display_alert_message()
{
	SelectCopyCert();
	if (g_CopyProcess == "ISSUE") {
		// root verify
		//alert("ÃÖ»óÀ§ ±â°ü(KISA) ÀÎÁõ¼­ ÇØ½¬°ª : "+ExtendMethod("getrootcerthash",""));
		alert("Á¤»óÀûÀ¸·Î ¹ß±Þ(Àç¹ß±Þ) µÇ¾ú½À´Ï´Ù.");
	} else if (g_CopyProcess == "UPDATE") {
		// expire date
		/*if (g_szCAName == "01")
			strMsg = "±ÝÀ¶°áÁ¦¿ø °øÀÎÀÎÁõ¼­ °»½ÅÀÌ ¿Ï·áµÇ¾ú½À´Ï´Ù.\n\n";
		else if (g_szCAName == "03")
			strMsg = "ÇÑ±¹ÀüÀÚÀÎÁõ °øÀÎÀÎÁõ¼­ °»½ÅÀÌ ¿Ï·áµÇ¾ú½À´Ï´Ù.\n\n";*/
			strMsg = "°øÀÎÀÎÁõ¼­ °»½ÅÀÌ ¿Ï·áµÇ¾ú½À´Ï´Ù.\n";
			strMsg += "ÀÎÁõ¼­ À¯È¿±â°£Àº ";
			strMsg += ExtendMethod("get_issueupdatecertdata","notafter");
			strMsg += "±îÁö ÀÔ´Ï´Ù.";
			alert(strMsg);
	}
}

function check_copy_count()
{
	if (g_cur_count > 2) {
		return true;
	} else {
		return false;
	}
}

var g_CopyProcess;
var g_iniplugindata;
/*
	ÇØ´ç ¸ÅÃ¼¿¡¼­ ÀÎÁõ¼­¸¦ ÀÐ¾î¿Ã ¶§ »ç¿ë
*/
//	nMedia => 1: SCARD, 2: USB, 3: HDD 4: ¸ðµç¸ÅÃ¼
function loadCertFromMedia(nMedia)
{
	var mediaType;
	if (typeof(nMedia) == "number")
		switch (nMedia) {
			case 1:
				mediaType = "SCARD";
				break;
			case 2:
				mediaType = "USB";
				break;
			case 3:
				mediaType = "HDD";
				break;
			case 4://090807Ãß°¡
				mediaType = "HDD|FDD|SCARD|PHONE";
				break;
			case 5:
				mediaType = "HDD|FDD";
				break;
			default :
				return "fail";
		}
	else if (typeof(nMedia) == "string") {
		mediaType = nMedia;
	}
	
	obj = ModuleInstallCheck();
	if (obj == null) {
		alert("¾ÏÈ£È­ ÇÁ·¹ÀÓ(secureframe)À» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return "fail";
	}

	InitCache();	
	
	// ÀÐ¾î¿Ã ¿øº» ÀÎÁõ¼­°¡ Á¸ÀçÇÏ´Â ½ºÅä¸®ÁöÀÇ ÇÊÅÍ¸µÀ» °Ç´Ù.
	SetProperty('certmanui_SearchStorageFilterOnDevice' , 'TRUE');
	obj.FilterCert(mediaType, ""); 
	
	// ÀÎÁõ¼­¸¦ ·ÎµùÇÏ±â À§ÇØ¼­ MakeINIpluginData¸¦ È£ÃâÇÑ´Ù. ¹Ýµå½Ã Vf=1·Î
	// °íµµÈ­ °ü·Ã 20110129
	g_iniplugindata = obj.MakeINIpluginData(11, "SEED-CBC", "Copy", TimeURL); 
	
	if (g_iniplugindata == "") {
		alert("º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
		return "cancel";
	} else {
		g_CopyProcess = "MANAGE";
		g_before_serial = "";
		return "success";
	}
}

function GetINIpluginDataFromCert()
{
	return g_iniplugindata;
}

function resetInPinNum()
{
	if (GetPluginDev() == "SCARD") {
		if (PinInit() == "true") {
			return "success";
		}
	}
	return "fail";
}

/*
	±â¾÷ÀÎÁõ¼­ º¹¼ö ¹ß±Þ½Ã »ç¿ë
	nMedia : ¸ÅÃ¼ Á¾·ù
	Á¤ÇØÁø È½¼ö¸¸ Å­ º¹»ç.
	g_cur_count, g_total_count
*/
// nMedia => 1: SCARD, 2: USB
function copyCert(nMedia)
{
	var type, typeStr, to;
	if (nMedia == 1) {
		type = "SCARD";
		typeStr = "½º¸¶Æ®Ä«µå";
		//S 090808 - modify
		if (checkIFrame() == false) {
			alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
			return "fail";
		}
		//E 090808 - modify
	} else if (nMedia == 2) {
		type = "USB"
		typeStr = "USB Key";
	} else {
		alert("Áö¿øÇÏÁö ¾Ê´Â ¹Ìµð¾î Å¸ÀÔÀÔ´Ï´Ù.");
		return "fail";
	}
	/* S 090808 - modify
	if (checkIFrame() == false) {
		alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return "fail";
	}
	E 090808 - modify*/
	if (ModuleInstallCheck() == null) {
		alert("¾ÏÈ£È­ ÇÁ·¹ÀÓ(secureframe)À» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return "fail";
	}

	if (!confirm("ÀÎÁõ¼­¸¦ ¼³Ä¡ÇÕ´Ï´Ù\nÀÌ¿ëÀÚÀÇ "+typeStr+"°¡ »ðÀÔµÇ¾ú½À´Ï±î?")) {
		alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
		return "cancel";
	} else {
		while (type != GetPluginDev()) {
			if (!confirm("ÀÌ¿ëÀÚÀÇ "+typeStr+"¸¦ »ðÀÔÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.")) {
				alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
				return "cancel";
			}
		}
	}
	
	while (g_before_serial == GetSerial()) {
		alert(typeStr + "¸¦ ¹Ù²ÙÁö ¾Ê¾Ò½À´Ï´Ù.\n´Ù¸¥ " + typeStr + "¸¦ »ðÀÔÇÏ°í È®ÀÎÀ» ´©¸£½Ê½Ã¿À.");
		do {
			if (!confirm("ÀÌ¿ëÀÚÀÇ "+typeStr+"¸¦ »ðÀÔÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.")) {
				alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
				return "fail";
			}
		} while (type != GetPluginDev());
	}
	if (PinInit() == "false") {
		alert("ÀúÀå¸ÅÃ¼ÀÇ PIN ÃÊ±âÈ­¸¦ ½ÇÆÐÇß½À´Ï´Ù.");
		return "fail";
	}

	if (type == "USB") {
		if (PinVerify("12345678") == "true") {
			default_PIN = "12345678";
		} else {
			default_PIN = "11111111";
		}			
	} else if (type == "SCARD") {
		default_PIN = "000000";
	}
	to = type+"&"+default_PIN;
	//to += "&resetpwd";			// ÀÎÁõ¼­ ÆÐ½º¿öµå Àç¼³Á¤
	SetProperty("certmanui_setkdbusedproperty", "2" );
	copy_flag = obj.ExtendMethod( "certcopytotarget" , to ) ;
	
	if (copy_flag == "yes") {
		g_before_serial = GetSerial(); // º¹»ç¸¦ ¼º°øÇÑ °æ¿ì ÇöÀç serialÀ» ÀúÀå
		ret = "success";
	} else if(copy_flag =="no") {
		alert("ÀÎÁõ¼­ º¹»ç¿¡ ½ÇÆÐÇß½À´Ï´Ù.");
		ret = "fail";
	} else if(copy_flag =="user_canceled" || copy_flag =="user_password_incorrect") {
		alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù." );
		ret = "cancel";
	/** 2011.11.30 ³ì»öÅ° °íµµÈ­ ÀÎÁõ¼­ º¹»ç ¹æÁö */
	} else if(copy_flag == "2048_notsupport") {
		alert("ÇØ´ç USBÅ°´Â °íµµÈ­µÈ ÀÎÁõ¼­ ÀúÀåÀÌ ºÒ°¡´ÉÇÕ´Ï´Ù.");
		ret = "fail";
	}

	return ret;
}

/*
	°ü¸®ÀÚ ÀÎÁõ¼­ º¹»ç½Ã »ç¿ë.
	nMedia : ¸ÅÃ¼ Á¾·ù
	È½¼ö¿¡ »ó°ü¾øÀÌ °è¼Ó º¹»çÇÔ
*/
function copyCert2(nMedia)
{
	var type, typeStr, to, count=0, default_PIN;
	if (nMedia == 1) {
		type = "SCARD";
		typeStr = "½º¸¶Æ®Ä«µå";
		if (checkIFrame() == false) {
			alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
			return "fail";
		}
	} else if (nMedia == 2) {
		type = "USB"
		typeStr = "USB Key";
	} else {
		alert("Áö¿øÇÏÁö ¾Ê´Â ¹Ìµð¾î Å¸ÀÔÀÔ´Ï´Ù.");
		return "fail";
	}
	
	if (ModuleInstallCheck() == null) {
		alert("¾ÏÈ£È­ ÇÁ·¹ÀÓ(secureframe)À» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return "fail";
	}

	if (!confirm("ÀÎÁõ¼­¸¦ º¹»çÇÕ´Ï´Ù\nÀÌ¿ëÀÚÀÇ "+typeStr+"°¡ »ðÀÔµÇ¾ú½À´Ï±î?")) {
		alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
		return "cancel";
	} else {
		while (type != GetPluginDev()) {
			if (!confirm("ÀÌ¿ëÀÚÀÇ "+typeStr+"¸¦ »ðÀÔÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.")) {
				alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
				return "cancel";
			}
		}
	}

	if (g_CopyProcess == "MANAGE") {
		if (PinInit() == "false") {
			alert("ÀúÀå¸ÅÃ¼ÀÇ PIN ÃÊ±âÈ­¸¦ ½ÇÆÐÇß½À´Ï´Ù.");
			return "fail";
		}
		if (type == "USB") {
			if (PinVerify("12345678") == "true") {
				default_PIN = "12345678";
			} else {
				default_PIN = "11111111";
			}			
		} else if (type == "SCARD") {
			default_PIN = "000000";
		}
		to = type+"&"+default_PIN;
		to += "&resetpwd";			// ÀÎÁõ¼­ ÆÐ½º¿öµå Àç¼³Á¤
		//alert(to);
		SetProperty("certmanui_setkdbusedproperty", "2" );
		copy_flag = obj.ExtendMethod( "certcopytotarget" , to ) ;
		PinInitUI();
		
	} else {
		while (g_before_serial == GetSerial()) {
			alert(typeStr + "¸¦ ¹Ù²ÙÁö ¾Ê¾Ò½À´Ï´Ù.\n´Ù¸¥ " + typeStr + "¸¦ »ðÀÔÇÏ°í È®ÀÎÀ» ´©¸£½Ê½Ã¿À.");
			do {
				if (!confirm("ÀÌ¿ëÀÚÀÇ "+typeStr+"¸¦ »ðÀÔÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.")) {
					alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
					return "fail";
				}
			} while (type != GetPluginDev());
		}
		if (PinInit() == "false") {
			alert("ÀúÀå¸ÅÃ¼ÀÇ PIN ÃÊ±âÈ­¸¦ ½ÇÆÐÇß½À´Ï´Ù.");
			return "fail";
		}
		if (type == "USB") {
			if (PinVerify("12345678") == "true") {
				default_PIN = "12345678";
			} else {
				default_PIN = "11111111";
			}			
		} else if (type == "SCARD") {
			default_PIN = "000000";
		}
		to += type+"&"+default_PIN;
		to += "&resetpwd";			// ÀÎÁõ¼­ ÆÐ½º¿öµå Àç¼³Á¤
		copy_flag = obj.ExtendMethod( "certcopytotarget" , to ) ;
	}

	if (copy_flag == "yes") {
		alert("ÀÎÁõ¼­ º¹»ç¸¦ ¿Ï·áÇß½À´Ï´Ù.");
		g_before_serial = GetSerial(); // º¹»ç¸¦ ¼º°øÇÑ °æ¿ì ÇöÀç serialÀ» ÀúÀå
		ret = "success";
		count++;
	} else if(copy_flag =="no") {
		alert("ÀÎÁõ¼­ º¹»ç¿¡ ½ÇÆÐÇß½À´Ï´Ù.");
		ret = "fail";
	} else if(copy_flag =="user_canceled" || copy_flag =="user_password_incorrect") {
		alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù." );
		ret = "cancel";
	}
	/** 2011.11.30 ³ì»öÅ° °íµµÈ­ ÀÎÁõ¼­ º¹»ç ¹æÁö */
	else if(copy_flag == "2048_notsupport") {
		alert("ÇØ´ç USBÅ°´Â °íµµÈ­µÈ ÀÎÁõ¼­ ÀúÀåÀÌ ºÒ°¡´ÉÇÕ´Ï´Ù.");
		ret = "fail";
	}

	if (g_CopyProcess == "LOGIN") {
		if (confirm("ÀÎÁõ¼­ º¹»ç¸¦ Ãß°¡·Î ÁøÇàÇÏ½Ã°Ú½À´Ï±î?")) {
			ret = copyCert2(nMedia);
		}
	} else if (g_CopyProcess == "OTHER") {
		if (confirm("ÀÎÁõ¼­ º¹»ç¸¦ Ãß°¡·Î ÁøÇàÇÏ½Ã°Ú½À´Ï±î?")) {
			return "success";
		} else {
			return "cancel";
		}
	}

	g_CopyProcess = "LOGIN";
	if (count > 0) {
		return "success";
	} else {
		return ret;
	}	
}

//090810 Ãß°¡
//090829 ¼öÁ¤ scard Áö¿ø
/*
	Å¸Çà ÀÎÁõ¼­ µî·Ï½Ã »ç¿ë
	type  : ¸ÅÃ¼ Á¾·ù
	count : º¹»çÇÒ È½¼ö
*/
function copyCert_other(type, count){
	var ret, obj;
	g_total_count = count;
	g_cur_count = 1;
	if (type == "USB") {
		ret = copyCert_other_usb(type, count);
	} else if (type == "SCARD") {
		//alert("copyCert_other_scard(\"READY\");");
		copyCert_other_scard("READY");
		ret = "continue";
	}

	return ret;
}

function copyCert_other_usb(type, count){
	var obj, ret;

	obj = ModuleInstallCheck();
	if (obj == null) {
		alert("¾ÏÈ£È­ ÇÁ·¹ÀÓ(secureframe)À» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return false;
	}
	
	GetPluginDev();
	if (PinInit() == "false") {
		alert("ÀúÀå¸ÅÃ¼ÀÇ PIN ÃÊ±âÈ­¸¦ ½ÇÆÐÇß½À´Ï´Ù.");
		return "fail";
	}
	if (type == "USB") {
		if (PinVerify("12345678") == "true") {
			default_PIN = "12345678";
		} else {
			default_PIN = "11111111";
		}			
	}	
	SetProperty("certmanui_setkdbusedproperty", "2" );
	ret = obj.ExtendMethod("certcopytotarget","USB&"+default_PIN);
	if(ret=="yes"){
		if(!PinInitUI()){
			alert("ÀúÀå¸ÅÃ¼°¡ Àá±Ý»óÅÂÀÌ°Å³ª PIN¹øÈ£ ¼³Á¤ ¿À·ùÀÔ´Ï´Ù.");
			return false;
		}

		alert("[°ü¸®ÀÚ]ÀÇ USB Key¿¡ ÀÎÁõ¼­ ¼³Ä¡¸¦ ¿Ï·áÇÏ¿´½À´Ï´Ù.");

		
		g_before_serial = GetSerial();
		g_cur_count = 2;		// ÀÌ¹Ì °ü¸®ÀÚ ÀÎÁõ¼­¸¦ ÀúÀåÇßÀ¸¹Ç·Î, 2ÀåÂ° º¹»ç¸¦ ½ÃÀÛÇÑ´Ù.

		while(g_total_count >= g_cur_count) {
			strMsg = "[ÀÌ¿ëÀÚ "+g_cur_count+"/"+g_total_count+"]ÀÇ ÀÎÁõ¼­¸¦ ¼³Ä¡ÇÕ´Ï´Ù.\n";
			strMsg += "¼³Ä¡ÇÒ ÀÌ¿ëÀÚ USB Key·Î ¹Ù²Ù¾î ÁÖ½Ê½Ã¿À\n";
			strMsg += "°è¼Ó ÁøÇàÇÕ´Ï±î?";
			if (!confirm(strMsg)) 
				break;

			while (g_before_serial == GetSerial()) {
				alert(type + "¸¦ ¹Ù²ÙÁö ¾Ê¾Ò½À´Ï´Ù.\n´Ù¸¥ " + type + "¸¦ »ðÀÔÇÏ°í È®ÀÎÀ» ´©¸£½Ê½Ã¿À.");
				do {
					if (!confirm("ÀÌ¿ëÀÚÀÇ "+type+"¸¦ »ðÀÔÇÏ½Ã±â ¹Ù¶ø´Ï´Ù.")) {
						alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
						return "fail";
					}
				} while (type != GetPluginDev());
			}
			
			if (PinInit() == "false") {
				alert("ÀúÀå¸ÅÃ¼ÀÇ PIN ÃÊ±âÈ­¸¦ ½ÇÆÐÇß½À´Ï´Ù.");
				return "fail";
			}
			if (type == "USB") {
				if (PinVerify("12345678") == "true") {
					default_PIN = "12345678";
				} else {
					default_PIN = "11111111";
				}			
			} else if (type == "SCARD") {
				default_PIN = "000000";
			}	

			SetProperty("certmanui_setkdbusedproperty", "2" );
			ret = obj.ExtendMethod("certcopytotarget",type+"&"+default_PIN);
			
			if (ret == "yes") {
				g_cur_count++;
			} 
			/** 2011.11.30 ³ì»öÅ° °íµµÈ­ ÀÎÁõ¼­ º¹»ç ¹æÁö */
        	else if(ret == "2048_notsupport") {
        		alert("ÇØ´ç USBÅ°´Â °íµµÈ­µÈ ÀÎÁõ¼­ ÀúÀåÀÌ ºÒ°¡´ÉÇÕ´Ï´Ù.");
        	}
		}

		return true;
	}
	/** 2011.11.30 ³ì»öÅ° °íµµÈ­ ÀÎÁõ¼­ º¹»ç ¹æÁö */
	else if(ret == "2048_notsupport") {
		alert("ÇØ´ç USBÅ°´Â °íµµÈ­µÈ ÀÎÁõ¼­ ÀúÀåÀÌ ºÒ°¡´ÉÇÕ´Ï´Ù.");
		return false;
	}
	else {
		alert("[°ü¸®ÀÚ]ÀÇ USB Key¿¡ ÀÎÁõ¼­ ¼³Ä¡ÇÏÁö ¸øÇß½À´Ï´Ù.");
		return false;
	}
}

function copyCert_other_scard(copy_process){
	//g_cur_count, g_total_count, g_repasswd_flag
	var obj;
	var copy_flag = "yes";
	var to = null;
	
	obj = ModuleInstallCheck();
	if (obj == null) {
		alert("¾ÏÈ£È­ ÇÁ·¹ÀÓ(secureframe)À» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return false;
	}
	if (copy_process == "READY") {			// ½º¸¶Æ® Ä«µå º¹»ç ÁØºñ, Ä«µå»ðÀÔ¿©ºÎ Ã¼Å©, derivation key Àü¹® Àü¼Û
		if (g_cur_count > 1) {
			while (g_total_count >= g_cur_count) {
				strMsg = "[ÀÌ¿ëÀÚ "+g_cur_count+"/"+g_total_count+"]ÀÇ ÀÎÁõ¼­¸¦ ¼³Ä¡ÇÕ´Ï´Ù.\n";
				strMsg += "¼³Ä¡ÇÒ ÀÌ¿ëÀÚ ½º¸¶Æ®Ä«µå·Î ¹Ù²Ù¾î ÁÖ½Ê½Ã¿À\n";
				strMsg += "°è¼Ó ÁøÇàÇÕ´Ï±î?";
				if (!confirm(strMsg)) {
					// ¹ß±Þ º¹»ç Áß ÁßÁöÇÑ °æ¿ì
	//				display_alert_message();
					if (typeof(NEXTACTION) == "function") {
						NEXTACTION(true);
						return true;
					}	
				}
				if (GetPluginDev() != "SCARD") {
					alert("½º¸¶Æ®Ä«µå°¡ »ðÀÔµÇÁö ¾Ê¾Ò½À´Ï´Ù.");
					continue;
				}
				if(g_before_serial == GetSerial()) {	// serial °ªÀ¸·Î ¸ÅÃ¼ ±³Ã¼ ¿©ºÎ Ã¼Å©
					alert("ÀúÀå¸ÅÃ¼°¡ ±³Ã¼µÇÁö ¾Ê¾Ò½À´Ï´Ù.");
					continue;
				}
				break;
			}
		}
		//alert("_goIframe(false)");
		if (_goIframe(false) == false) {
			alert("IFrameÀ» Ã£À» ¼ö ¾ø½À´Ï´Ù.");
			if (typeof(NEXTACTION) == "function") {
				NEXTACTION(true);
				return "cancel";
			}	
			//return true;
		} else {
			//alert("setInterval(\"_wait_Value(\\\"COPY_OTHER\\\", \"+g_repasswd_flag+\")\", 100);");
			t_id = setInterval("_wait_Value(\"COPY_OTHER\", "+g_repasswd_flag+")", 100);
			return true;
		}
	} else if (copy_process == "COPY") {		// ½ÇÁ¦ º¹»ç ÁøÇà
		//alert("PinInit()");
		if (PinInit() == "false") {
			alert("ÀúÀå¸ÅÃ¼ÀÇ PIN ÃÊ±âÈ­¸¦ ½ÇÆÐÇß½À´Ï´Ù.");
			if (typeof(NEXTACTION) == "function") {
				NEXTACTION(true);
				return "cancel";
			}	
			return "fail";
		}
		//alert("obj.ExtendMethod");
		SetProperty("certmanui_setkdbusedproperty", "2" );
		copy_flag = obj.ExtendMethod("certcopytotarget","SCARD&000000");
		
		if (g_cur_count == 1) {
			if(copy_flag=="yes"){
				//alert("PinInitUI");
				if(!PinInitUI()){
					alert("ÀúÀå¸ÅÃ¼°¡ Àá±Ý»óÅÂÀÌ°Å³ª PIN¹øÈ£ ¼³Á¤ ¿À·ùÀÔ´Ï´Ù.");
					if (typeof(NEXTACTION) == "function") {
						NEXTACTION(false);
						return false;
					}
				}
				g_cur_count++;
				alert("[°ü¸®ÀÚ]ÀÇ USB Key¿¡ ÀÎÁõ¼­ ¼³Ä¡¸¦ ¿Ï·áÇÏ¿´½À´Ï´Ù.");
				if (g_total_count == 1) {
					//display_alert_message();
					if (typeof(NEXTACTION) == "function") {
						NEXTACTION(true);
						return true;
					}	
				}
			} else{
				alert("[°ü¸®ÀÚ]ÀÇ USB Key¿¡ ÀÎÁõ¼­ ¼³Ä¡ÇÏÁö ¸øÇß½À´Ï´Ù.");
				if (typeof(NEXTACTION) == "function") {
					NEXTACTION(false);
					return false;
				}
			}
		} else {
			if (copy_flag == "yes") {		
				g_before_serial = GetSerial(); // º¹»ç¸¦ ¼º°øÇÑ °æ¿ì ÇöÀç serialÀ» ÀúÀå
				g_cur_count++;
				alert("ÀÎÁõ¼­ º¹»ç¸¦ ¿Ï·áÇß½À´Ï´Ù.");
			} else if(copy_flag =="no") {
				alert("ÀÎÁõ¼­ º¹»ç¸¦ ½ÇÆÐÇß½À´Ï´Ù." || copy_flag =="user_password_incorrect");
			} else if(copy_flag =="user_canceled") {
				alert("ÀÎÁõ¼­ º¹»ç°¡ Ãë¼ÒµÇ¾ú½À´Ï´Ù.");
			}		
		}
	
		if (g_total_count >= g_cur_count) {
			if (confirm("ÀÎÁõ¼­ º¹»ç¸¦ Ãß°¡·Î ÁøÇàÇÏ½Ã°Ú½À´Ï±î?")) {
				copyCert_other_scard("READY");
				return true;		
			}
		}
		// ´ÙÁß º¹»ç ÁßÁö
	//	display_alert_message();
		if (typeof(NEXTACTION) == "function") {
			NEXTACTION(check_copy_count());
			return false;
		}		
	}
}

function SelectCopyCert()
{
	if (g_szCAName == "03" && g_private == false) {
		if (confirm("´Ù¸¥ ¸ÅÃ¼¿¡µµ ÀúÀåÇÏ½Ã°Ú½À´Ï±î?")) {
			copy_flag = ExtendMethod( "certcopytotarget" , "HDD|FDD&12345678" ) ;
			if ( copy_flag == "yes" )
				alert( "ÀÎÁõ¼­°¡ ¼º°øÀûÀ¸·Î º¹»çµÇ¾ú½À´Ï´Ù." );
			else if ( copy_flag == "no" )
				alert( "ÀÎÁõ¼­ º¹»ç°¡ ½ÇÆÐÇÏ¿´½À´Ï´Ù." );
			else if ( copy_flag == "user_canceled" )
				alert( "ÀÎÁõ¼­ ºñ¹Ð¹øÈ£ ¼³Á¤À» Ãë¼ÒÇÏ¼Å¼­ ÀÎÁõ¼­ º¹»ç°¡ Ãë¼Ò µÇ¾ú½À´Ï´Ù." );
		}
	}
}

/*function testtest(str){
	var KDBDevObj = ModuleInstallCheck_ActiveX();
	if (KDBDevObj == null) {
		//alert("KDB Device ActiveX¸¦ Ã£À» ¼ö ¾ø½À´Ï´Ù.");
		return null;
	}

	var ret = KDBDevObj.SelectMedia(str);
	
	return ret; 
}*/

