    var rsaPulickKey = null;
    var publicKeyModulus  = null;
    var publicKeyExponent = null;
    var rsa = null;
    var komeEncryptResult = false;
    
    var formElementArray = null;
    
    var executeEncCnt = 0;
    
    var callBackFunction = null;
    
    var exceptField = new Array();
    
    var messageToLong = false;    
    
    function komeDoEncForm(f,callBack){
        
        if(strsymkey == null || strsymkey == ''){
            getKey();   
        }
        
        if(f == null){
            alert('¾ÏÈ£È­ÇÒ FormÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.');
            return;   
        }
        
        var elemSize = f.elements.length;
        
        formElementArray = new Array(elemSize);
        
        for(var i=0; i<f.elements.length; i++){
            formElementArray[i] = f.elements[i]; 
        }
        
        var divideCnt = 10;
         
        var cnt = Math.round(elemSize/divideCnt)+1;
        
        callBackFunction = callBack;
         
        
        for(var i=0; i<cnt; i++){
            
            var startIdx = i*divideCnt;
            var endIdx = (i+1)*divideCnt;
            
            if(endIdx>elemSize) endIdx = elemSize;
             
            if(i == 0){
                komeDoEncFormTimer(startIdx,endIdx);
            }else{ 
                window.setTimeout("komeDoEncFormTimer('"+startIdx+"','"+endIdx+"');",50);
            }
        }
         
          
    }
     
    
    function komeDoEncFormTimer(startIdx,endIdx){
         
        startIdx = eval(startIdx);
        endIdx = eval(endIdx);
         
        for(var i=startIdx; i<endIdx; i++){
            
            executeEncCnt++;
             
            var typeName = formElementArray[i].type;
            var typeValue = formElementArray[i].value;
            var typeObj = formElementArray[i];
            
            
            // ¸ÖÆ¼ÆÄÆ® Æû
            if(typeObj.name == 'filePath'){
                continue;
            }
            
            // °³ÀÎÀÎÁõÅ°
            //if(typeObj.name == 'kome_certificate'){
            //    continue;
            //}
            
            //var isPass = false;
            //
            //for(var k=0; k<exceptField.length; k++){
            //    if(exceptField[k] == typeObj.name) isPass = true;
            //}
            
            //if(isPass) continue;
            
            // kome AES key °ªÀÎ°æ¿ì
            if(typeObj.name == 'komeEnc'){
                 
                if(strsymkey == null) continue;
                
                typeObj.value = komeDoRSAEncText(strsymkey);
                continue;
            }
            
            
            if(typeValue == null || typeValue == "") continue;
            
            typeName = typeName.toLowerCase();
            
            
            if(typeName == "hidden"){
                komeDoEnc(typeObj);
            }if(typeName == "text" || typeName == "txt" || typeName == "password" || typeName == "textarea"){
                komeDoEnc(typeObj);
            }if(typeName.indexOf("select") == 0){
                 
                
                for(var a=0; a<typeObj.options.length; a++){
                     
                    if(typeObj.options[a].selected == true){
                        typeObj.options[a].value = komeDoEncText(typeObj.options[a].value);
                    }
                }
                
            }else if(typeName == "checkbox"){
                 
                
                if(typeObj.checked == true){
                    typeObj.value = komeDoEncText(typeObj.value);
                }
            }else if(typeName == "radio"){
                
                if(typeObj.checked == true){
                    typeObj.value = komeDoEncText(typeObj.value);
                }
            } 
            
            
            
            
        }
        
        if(executeEncCnt == formElementArray.length){ 
            executeEncCnt = 0;
            if(callBackFunction != null){ 
                var tempFunc = callBackFunction;
                callBackFunction = null;
                tempFunc();
            }
        }
    }

    function komeDoEnc(obj){


        if(obj == null) {
            alert("¾ÏÈ£È­ÇÒ ´ë»óÀÌ Á¸ÀçÇÏÁö ¾Ê½À´Ï´Ù.");
            komeEncryptResult = false;
            return;
        }

        obj.value = komeDoEncText(obj.value);
    }
    
    
    
    
    
    function komeDoEncText(txt){
        
        var ret = txt;
        
        if(txt == null || txt == '') return txt;
        
        var errorCnt = 0;
 
        try{
 
            ret = doAESEncode(txt);

            komeEncryptResult = true;

        }catch(ex){
            
            alert(ex);
            komeEncryptResult = false;
            alert('¾ÏÈ£È­ ÀÛ¾÷Áß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.');
            return txt;
        }
        
        return ret;

    }
    
    
    
    function komeDoRSAEncText(txt){
        
        var ret = txt;
        
        if(txt == null || txt == '') return txt;
        
        var errorCnt = 0;

        /*** RSA ¾ÏÈ£È­ ***/
        try{

            // RSA °ø°³Å°¸¦ ¾ò¾î¿Â´Ù.
            if(rsaPulickKey == null || rsaPulickKey == ''){
                
                rsaPulickKey = getRSAPublickKey();
                 
                publicKeyModulus  =rsaPulickKey.substring(0,rsaPulickKey.indexOf("|"));
                publicKeyExponent =rsaPulickKey.substring(rsaPulickKey.indexOf("|")+1);
                rsa = new RSAKey();
                rsa.setPublic(publicKeyModulus, publicKeyExponent);   
                
                if(rsaPulickKey.length <10){
                    alert('¾ÏÈ£È­ Å°°ª »ý¼ºÀ» ½ÇÆÐÇÏ¿´½À´Ï´Ù.');
                    return;
                }
            }
 
            ret = rsa.encrypt(txt);

            komeEncryptResult = true;

        }catch(ex){
            komeEncryptResult = false;
            alert('¾ÏÈ£È­ ÀÛ¾÷Áß ¿À·ù°¡ ¹ß»ýÇÏ¿´½À´Ï´Ù.');
            return txt;
        }
        
        return ret;

    }
    
    
    				


    // RSA °ø°³Å° ¾ò¾î¿Â´Ù.
	function getRSAPublickKey(){

		var httpRequest = null;

		if ( window.ActiveXObject ) {	//IEÀÏ °æ¿ì
			try{
				httpRequest = new ActiveXObject("Msxml2.XMLHTTP");		//ÃÖ½Å¹öÀü ¸ÕÀú ¾ò¾îº»´Ù.
			}catch(e){
				try{
					httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
				}catch(ee){}
			}
		} else if ( window.XMLHttpRequest ){	//IE ÀÌ¿Ü¿¡ XMLHttpRequest¸¦ Áö¿øÇÏ´Â ºê¶ó¿ìÀúÀÏ °æ¿ì
			httpRequest = new XMLHttpRequest();
		}

		if(httpRequest == null){
		    alert('½Ã½ºÅÛ¿¡¼­ Áö¿øÇÏÁö ¾Ê´Â ºê¶ó¿ìÁ®ÀÔ´Ï´Ù.');
		    return;
		}

		httpRequest.open("POST" , "/jsp/common/rsaPublicKeyMake.jsp" , false);
		httpRequest.send();

		return httpRequest.responseText;
	}
    	
    	
    	
    function encodeURL(str){
    
        var s0, i, s, u;
        s0 = "";                // encoded str
    
        for (i = 0; i < str.length; i++){   // scan the source
            s = str.charAt(i);
            u = str.charCodeAt(i);          // get unicode of the char
            if (s == " "){s0 += "+";}       // SP should be converted to "+"
    
            else {
                if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                    s0 = s0 + s;            // don't escape
                }else {                  // escape
    
                    if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                        s = "0"+u.toString(16);
                        s0 += "%"+ s.substr(s.length-2);
                    }else if (u > 0x1fffff){     // quaternary byte format (extended)
    
                        s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                        s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                        s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                        s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                        
                    }else if (u > 0x7ff){        // triple byte format
                        s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                        s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                        s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                    }else {                      // double byte format
    
                        s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                        s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                    }
                }
            }
        }
        return s0;
    }
        
         
     
    
    function decodeURL(str){
    
        var s0, i, j, s, ss, u, n, f;
        s0 = "";                // decoded str
    
        for (i = 0; i < str.length; i++){   // scan the source str
            s = str.charAt(i);
            if (s == "+"){s0 += " ";}       // "+" should be changed to SP
            
            else {
    
                if (s != "%"){s0 += s;}     // add an unescaped char
                else{               // escape sequence decoding
                    u = 0;          // unicode of the character
                    f = 1;          // escape flag, zero means end of this sequence
                    while (true) {
    
                        ss = "";        // local str to parse as int
                        
                        for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
    
                            sss = str.charAt(++i);
                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
                                ss += sss;      // if hex, add the hex character
                            } else {--i; break;}    // not a hex char., exit the loop
    
                        }
    
                        n = parseInt(ss, 16);           // parse the hex str as byte
    
                        if (n <= 0x7f){u = n; f = 1;}   // single byte format
                        if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                        if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                        if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                        if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
                        if (f <= 1){break;}         // end of the utf byte sequence
                        if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
                        else {break;}                   // abnormal, format error
                    }
    
                    s0 += String.fromCharCode(u);           // add the escaped character
                }
            }
        }
        return s0;
    }
