/**
 * 공통 스크립트 정의
 * 
 */
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
 
 /* =================================  팝업관련 Lib Start================================== */
/**
 * 팝업창띄우기
 * @param {uri} 팝업창띄울 URL정보
 * @param {winname} 팝업창 이름
 * @param {w} width
 * @param {h} height
 * @param {s} scroll여부 (0-no:noscroll, 1-yes:scroll)
 * @param {r} resize여부 (0-no:noresize, 1-yes:resize)
 * @author 김동완
 */
function winPopup(uri,winname,w,h,s,r){
	var newwin = window.open('about:blank',winname,'width='+w+',height='+h+',top=0,left=0,status=yes,scrollbars='+s+',resizable='+r);
	if (newwin == null){
		alert("팝업 차단기능 혹은 팝업차단 프로그램이 동작중입니다. 팝업 차단 기능을 해제한 후 다시 시도하세요.");
	}else{
		newwin = window.open(uri,winname,'width='+w+',height='+h+',top=0,left=0,status=no,scrollbars='+s+',resizable='+r);
		return newwin;
		newwin.focus();
	}
}



/**
 * 모달 팝업창띄우기 (IE전용)
 * @param {uri} 팝업창띄울 URL정보
 * @param {name} 팝업창 이름
 * @param {width} width
 * @param {height} height
 * @author 김동완
 */
function modalPopup(url, name, width, height) {
	if  (window.showModalDialog) {
		window.showModalDialog(url, name,  'dialogWidth:'+width+'px;dialogHeight:'+height+'px; status:no; resizable:no; help:no; center:yes; scroll:no');
	} else {
		var win = window.open(url, name,  'height='+height+',width='+width+',toolbar=no,directories=no,status=no,linemenubar=no,scrollbars=no,resizable=no,modal=yes,dependent=yes');
	}
}

/**
 * 반환값이 있는 모달 팝업 호출
 * <ul>
 * <li>argProperty[0] : 팝업창 width</li>
 * <li>argProperty[1] : 팝업창 height</li>
 * <li>argProperty[2] : 스크롤여부 no/auto/yes</li>
 * <li>argParam[0] : 호출할 주소 </li>
 * <li>argParam[1] : 팝업창 title </li>
 * </ul>
 * @param {array} argParam 부모창에서 모달창에 보낼 배열값
 * @param {array} argProperty 모달창 옵션값
 */
function returnModalPopup(argParam,argProperty){
	 var sURL   = argParam[0];
	 var sPos   = "dialogWidth:"+argProperty[0]+"px;dialogHeight:"+argProperty[1]+"px;resizable:0;scroll:"+argProperty[2]+";status:0;help:0;center:1;dialogHide:1;";
	 var retVal = window.showModalDialog(sURL,argParam,sPos);
	 return retVal;
}



/**
 * 팝업창으로 alert창 띄우기 (IE전용)
 * @param {msg} alert메세지
 * @author 김동완
 */
function popAlert(msg) {
	var foxHeight = 60;
	var ieHeight = 60;
	var ie7Height = 80;
	var widthStr = 350;
	var heightStr = 180;

    if(isIE){
        if(isIE6) {
            heightStr = heightStr+ieHeight;
        }else if(isIE7){
            heightStr = heightStr+ie7Height;
        }
    }else {
        heightStr = heightStr+foxHeight;
    }

	var errArray = [];
	errArray["alertMessage"] = msg;
	if(window.showModalDialog && document.all){
		window.showModalDialog("popAlert.jsp", errArray, "dialogWidth:"+widthStr+"px; dialogHeight:"+heightStr+"px; status:no; resizable:no; help:no; center:yes; scroll:no");
	}else {
		msg = msg.replaceAll("<br/>","\n").replaceAll("<br />","\n");
		var removeTagTxt = msg.stripTags();
		alert(removeTagTxt);
	}
}


/**
 * 팝업창으로 confirm 띄우기 (IE전용)
 * @param {msg} alert메세지
 * @param {titleImg} 타이틀이미지
 * @return {true/false}
 * @author 김동완
 */
function popConfirm(msg,titleImg) {
	var errArray = [];
	errArray["confirmMessage"] = msg;
	errArray["titleImage"] = titleImg;
	if(window.showModalDialog && document.all){
	    // dialogHeight 조정 : 150->180px 2008.10.18 by kyyoon
		var rtnVal = window.showModalDialog("popConfirm.jsp", errArray, "dialogWidth:410px; dialogHeight:180px; status:no; resizable:no; help:no; center:yes; scroll:no");
		return rtnVal;
	}else {
		var removeTagTxt = msg.stripTags();
		if(!confirm(removeTagTxt)){
			return false;
		}else {
			return true;
		}
	}

}
/**
 * onkeydown = checkEnter(event)
 * @param {event} onkeydown 이벤트
 * @retrn {boolean} true/false
 */
function checkEnter(evt){
	var tObj = (evt.srcElement) ? evt.srcElement : evt.target;
	var evCode = ( window.netscape ) ? evt.which : evt.keyCode ;
    if(evt.ctrlKey ==true) {
        return false;
    }
    if(evCode == 13){
        return true;
    }else {
        return false;
    }
}

function zoom(param){
	if(navigator.userAgent.toLowerCase().indexOf("msie")!=-1){
	
		if(document.body.style.zoom==null || document.body.style.zoom=="") zoomState=100;
		
		if(param=="in") zoomState += 10;
		else zoomState -= 10;
		
		if(zoomState > 140) zoomState=140;
		if(zoomState < 60) zoomState=60;
		
		document.body.style.zoom = zoomState+"%";
		
	}else{
		alert("이 브라우저에서는 지원하지 않습니다.");
	}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function menuMouseOver(idx){
	try{
		for(i=1 ; i<=5 ; i++){
			objImage = document.getElementById("necImage"+i);
			objLayer = document.getElementById("submenu"+i);
			if(i == idx){
				objImage.src = objImage.src.replace(i+".gif", i+"_over.gif");
				objLayer.style.display = "";
			}else{
				objImage.src = objImage.src.replace(i+"_over.gif", i+".gif");
				objLayer.style.display = "none";
			}
		}
	}catch(err){
		
	}
} 

function subMenuMouseOver(idx, subIdx){  
	objImage = document.getElementById("necSubImage"+idx+""+subIdx);
	objImage.src = objImage.src.replace("nec"+idx+"0"+subIdx+".", "nec"+idx+"0"+subIdx+"_on.");
}  

function subMenuMouseOut(idx, subIdx){ 
	objImage = document.getElementById("necSubImage"+idx+""+subIdx);
	objImage.src = objImage.src.replace("nec"+idx+"0"+subIdx+"_on.", "nec"+idx+"0"+subIdx+".");
}

/* =================================  객체 위치 관련 Lib Start============================== */
/**
 * tag 객체의 위치값 및 너비/높이값을 반환한다.
 * @param {objId} DOM객체 : document.getElementById()
 * @return {ret} left,top,width,height 를 반환한다.
 * @author 김동완
 * @since 2008.06.25 FF3 패치
 */
function getBounds(objId){
	var ret = new Object();
	var tag = document.getElementById(objId);

	if(tag !=null && tag != undefined ){
		if(tag.getBoundingClientRect){ //IE, FF3
			var rect = tag.getBoundingClientRect();
			ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft);
			ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop);
			ret.width = rect.right - rect.left;
			ret.height = rect.bottom - rect.top +1; // +1 = Moz와 맞춤
		} else  if (document.getBoxObjectFor) { // gecko 엔진 기반 FF3제외
			var box = document.getBoxObjectFor(tag);
			ret.left = box.x;
			ret.top = box.y;
			ret.width = box.width;
			ret.height = box.height;
		}else {
			ret.left = tag.offsetLeft;
			ret.top = tag.offsetTop;
			ret.width = tag.offsetWidth;
			ret.height = tag.offsetHeight  + 3;  // +1 = Moz와 맞춤
			var parent = tag.offsetParent;
			if (parent != tag) {
				while (parent) {
					ret.left += parent.offsetLeft;
					ret.top += parent.offsetTop;
					parent = parent.offsetParent;
				}
			}
			// 오페라와 사파리의 'absolute' postion의 경우 body의 offsetTop을 잘못 계산 보정
			var ua = navigator.userAgent.toLowerCase();
			if (ua.indexOf('opera') != -1 || ( ua.indexOf('safari') != -1 && getStyle(tag, 'position') == 'absolute' )) {
				ret.top -= document.body.offsetTop;
			}

		}
		return ret;
	}
}

/* =================================  자동Iframe 생성 Lib Start================================== */
/**
 * 자동으로 iframe생성 (IE6 버그 패치)
 * @param {string} iframe위에 올릴 객체아이디
 * @return {object} 생성된 iframe객체
 */
function createIframe(idx){
    var showObj = document.getElementById(idx);
    var showObjPos = getBounds(idx);
    var iFrame = document.createElement("IFRAME");
    iFrame.setAttribute("src", "blankSlip.jsp");
    iFrame.setAttribute("id", "_IFRAME_"+idx);
    iFrame.setAttribute("marginwidth", "0");
    iFrame.setAttribute("marginheight", "0");
    iFrame.setAttribute("frameborder", "0");
    iFrame.setAttribute("allowtransparency", "true");
    if(isIE6) iFrame.setAttribute("allowtransparency", "yes");

    iFrame.style.border = 0;
    iFrame.style.borderWidth = 0;
    iFrame.style.backgroundColor='transparent';
    iFrame.style.position= showObj.style.position;
    iFrame.style.left =showObjPos.left;
    iFrame.style.top =showObjPos.top;
    iFrame.style.width =showObjPos.width -3;
    iFrame.style.height =showObjPos.height;
    iFrame.style.zIndex = 150;
    document.body.appendChild(iFrame);
    return iFrame;
}

/**
 * 생성된 객체 없애기 (IE6 버그 패치)
 * @param {string} iframe위에 올릴 객체아이디
 */
function destroyIframe(idx){
    var iFrameIdx = "_IFRAME_"+idx;
    var iFrameObj = document.getElementById(iFrameIdx);
    if(iFrameObj !=undefined && iFrameObj !=null){
        document.body.removeChild(iFrameObj);
    }
}


/* =================================  문자열 관련 Lib Start================================== */
/**
 * 문자열의 공백을 제거한다.
 * @param {objVal} 문자열
 * @return {String} 공백을 제거한 문자열을 반환한다.
 * @author 김동완
 */
function trim(objVal){
    return objVal.replace(new RegExp("(^\\s*)|(\\s*$)", "g"), "");
}

/**
 * 숫자만 입력하기 FF에서는 한글도 입력되므로 onkeyup에서 validation check를 해야 함
 * 사용법 : onkeypress = "IsNumber(event)"; style="ime-mode:disabled";
 * @param {event} evt 이벤트
 * @return {boolean} event.returnValue;
 * @author 김동완
 * @since 2008.07.10 코드값(0-FF에서 ESC값,8,9,46,144,110,190) 추가 및 imeModeCheck
 */
function IsNumber(evt){
	var tObj = (evt.srcElement) ? evt.srcElement : evt.target;
	if(tObj.style.imeMode =="" || tObj.style.imeMode !="disabled") tObj.style.imeMode = "disabled" ;
	var evCode = ( window.netscape ) ? evt.which : evt.keyCode ;
	var sChar = String.fromCharCode( evCode);
	if(evCode == 8) tObj.select();
	if( sChar.match( /[^0-9]/gi ) ||
		!(evCode == 0 || evCode==9 || evCode==13
			|| evCode==144 || evCode==110
			|| evCode==190 ||( evCode>=48 && evCode<=57 )) ){
		if ( window.netscape ){
			evt.preventDefault() ;
		} else {
			event.keyCode = 0;
			event.returnValue=false;
		}
	}
}

/**
 * 숫자인지 아닌지 체크하여 값을 반환
 * @param {string} s 문자열
 * @return {boolean}
 */
function isNumeric(s){
     var isNum = /\d/;
     if( !isNum.test(s) ) { return false; }
     else { return true; }
}


/**
 * 반복된 문자열(숫자) 체크
 * @param {string} str 문자열
 * @return {boolean} true/false
 */
function isValidIterateNumber(str){
    var temp = "";
    var temp2 = str.substring(0,1);
    var con=1;

    for(i = 1; i < str.length; i++){
        temp = str.substring(i,i+1);
        if(temp2 == temp){
            if(isNumeric(temp)){
                con++;
                if(con>=3){
                    return false;
                    break;
                }
            }
        }else{
            con = 1;
        }
        if(isNumeric(temp)){
            temp2 = temp;
        }
    }
    if(con>=3){
        return false;
    }else{
        return true;
    }
}

/**
 * 이메일 정합성 체크
 * @param {string} e_mail
 * @return {boolean} 잘못된 이메일(true) or 정상적인 이메일(false)
 */
function isErrorEmailRet(e_mail) {
    var state = 0;

    var beforeChar = "";
    var currentChar = "";

    if(e_mail == "") {
        alert("E_mail을 입력하여 주십시요");
        return true;
    }

    if(isErrorDomainRet(getEmailDomain(e_mail))) {
        alert("이메일 주소가 잘못되었습니다. 확인하시기 바랍니다.");
        return true;
    }

    for(var i=0; i<e_mail.length; i++) {
        currentChar = e_mail.charAt(i);
        if(state == 0) {
            if(currentChar == "." || currentChar == "@" || currentChar == " ") {
            	alert("이메일 주소가 잘못되었습니다. 확인하시기 바랍니다.");
            	return true;
            } else {
            	state = 1;
            }
            continue;
        }

        if(state == 1) {
            if(currentChar == " ") {
            	alert("이메일 주소가 잘못되었습니다. 확인하시기 바랍니다.");
            	return true;
            } else if(currentChar == "@") {
            	state = 2;
            }
            continue;
        }

        if(state == 2) {
            if(currentChar == "." || currentChar == "@" || currentChar == " ") {
            	alert("받는 사람/보내는 사람 이메일 주소가 잘못되었습니다. 확인하시기 바랍니다.");
            	return true;
            } else {
            	state = 3;
            }
            continue;
        }

        if(state == 3) {
            if(currentChar == " " || currentChar == "@") {
            	alert("이메일 주소가 잘못되었습니다. 확인하시기 바랍니다.");
            	return true;
            }

            if(beforeChar == "." && currentChar == ".") {
            	alert("이메일 주소가 잘못되었습니다. 확인하시기 바랍니다.");
            	return true;
            } else {
            	beforeChar = currentChar;
            }
            continue;
        }
    }

    if(state != 3) {
        alert("domain이 완전하지 않습니다11.\n\n 다시 입력하여 주십시요");
        return true;
    } else if(state == 3 && currentChar == " ") {
        alert("domain이 완전하지 않습니다22.\n\n 다시 입력하여 주십시요");
        return true;
    } else if(state == 3 && currentChar == ".") {
        alert("domain이 완전하지 않습니다33.\n\n 다시 입력하여 주십시요");
        return true;
    }
    return false;
}

/**
 * 정확한 도메인 정보인지 체크
 * @param {string} 도메인문자열
 * @return {boolean} 잘못된 도메인(true) or 정상적인 도메인(false)
 */
function isErrorDomainRet(domain) {

	if(domain.charAt(0) == "."
		|| domain.charAt(0) == "-"
		|| domain.charAt(domain.length-1) == "."
		|| domain.indexOf(".") == -1)
		return true;

	for(var i=0; i<domain.length; i++) {
		var ch = domain.charAt(i);

		if((ch >= "0" && ch <= "9") || (ch >= "a" && ch <="z")
			|| (ch >= "A" && ch <= "Z") || (ch == ".") || (ch == "-")) {

		} else {
			return true;
		}
	}

	return false;
}

/**
 * 이메일 부분에서 도메인부분만 가져오기
 * @param {string} 이메일 문자열
 */
function getEmailDomain(e_mail) {
    var index = e_mail.indexOf("@");
    if(index == -1) return e_mail;
    return e_mail.substring(index+1, e_mail.length);
}


/**
 * 특수문자 아예 안먹게처리 :<br/>
 * 사용법 : <textarea onKeyPress="noSpecialChar(event)"></textarea>
 * @param {event} 이벤트
 */
function noSpecialChar(evt){
    var evCode = ( window.netscape ) ? evt.which : evt.keyCode ;
	var sChar = String.fromCharCode( evCode );

	if( sChar.match(/[^가-힣a-z0-9s]/gi)){
		if ( window.netscape ){
			evt.preventDefault() ;
		} else {
			event.cancelBubble = true;
			event.returnValue=false;
		}
	}
}

/**
 * 특수문자(.,-%~?*@#() 제외) 아예 안먹게처리 :<br/>
 * 사용법 : <textarea onKeyPress="noSpecialChar(event)"></textarea>
 * @param {event} 이벤트
 */
function noMemoSpecialChar(evt){
    var evCode = ( window.netscape ) ? evt.which : evt.keyCode ;
	var sChar = String.fromCharCode( evCode );

	if( !(sChar.match(/[^.,~?!*@#()가-힣a-z0-9s\-\%]/gi) ==null || sChar.match(/[^.,~?!*@#()가-힣a-z0-9s\-\%]/gi) ==" " || evCode==13) ){
		if ( window.netscape ){
			evt.preventDefault() ;
		} else {
			event.cancelBubble = true;
			event.returnValue=false;
		}
	}
}

/**
 * 문자열에서 숫자만 표기
 */
String.prototype.num = function() {return this.replace(/[^0-9]/g, "");}

/**
 * 숫자인지 아닌지 여부를 출력
 * @param {str} 텍스트
 * @return {true/false}
 */
function isInt(str) {
	var num = str.num();

	if (num.length == str.length) {
		return true; // 숫자로만 이루어져 있음
	} else {
		return false; // 숫자로만 이루어져 있지 않음
	}
}

/**
 * 모든 HTML테그 없애기
 * @param {allowed_tags} 허용할 태그
 */
String.prototype.stripAllTags = function () {
   var str = this;
   var pos1 = str.indexOf('<');

   if (pos1 == -1) return str;
   else {
       var pos2 = str.indexOf('>', pos1);
       if (pos2 == -1) return str;
       return (str.substr(0, pos1) + str.substr(pos2+1)).stripAllTags();
   }
}

/**
 * 정수형으로 변환
 */
String.prototype.int = function() {
	if(!isNaN(this))
		return parseInt(this);
	else
		return null;
}


/**
 * HTML테그 없애기
 * @param {allowed_tags} 허용할 태그
 */
String.prototype.stripTags = function(allowed_tags){
	var key = '';
	var tag = '';
	var matches = allowed_array = [];
	var allowed_keys = {};
	var bindThis = this;

	if (allowed_tags) {
		allowed_tags  = allowed_tags.replace(/[\<\> ]+/g, '');;
		allowed_array = allowed_tags.split(',');

		for (key in allowed_array) {
			tag = allowed_array[key];
			allowed_keys['<' + tag + '>']   = true;
			allowed_keys['<' + tag + ' />'] = true;
			allowed_keys['</' + tag + '>']  = true;
		}
	}
	matches = bindThis.match(/(<\/?[^>]+>)/gi);

	for (key in matches) {
		tag = matches[key].toString();
		if (!allowed_keys[tag]) {
			bindThis =  bindThis.replace(/<\S[^><]*>/g, '');
		}
	}

	return bindThis;

}

/**
 * 글자 바이트 가져오기
 * @param {s} 문자열
 * @return {len} 글자수
 */
function getByteLength(s){
	var len = 0;
	if (s == null) return 0;

	for(var i = 0; i < s.length; i++){
		var c = escape(s.charAt(i));
		if (c.length == 1) len++;
		else if (c.indexOf("%u") != -1) len += 2;
		else if (c.indexOf("%") != -1) len += c.length / 3;
	}
	return len;
}


/**
 * 댓글시 바이트 비교 400바이트 이상글자 못쓰게 막기<br>
 * 사용법 :<br/>
 * onkeydown="return textLimitByByte(this,400,document.getElementById('cmtStrNum'));" onkeyup="return textLimitByByte(this,400,document.getElementById('cmtStrNum'));"<br/>
 * onkeydown="return textLimitByByte(this,400);" onkeyup="return textLimitByByte(this,400);"
 * @param {field} 댓글인풋박스 객체
 * @param {maxlimit} 최대 글자수
 * @param {countfield} 바이트표시될 객체 (생략가능)
 */
function textLimitByByte(field,maxlimit,countfield){
	if(getByteLength(field.value)>maxlimit){
		alert("최대 " + maxlimit + "byte("+parseInt(maxlimit/2)+"자)를 넘길 수 없습니다.\n초과된 내용은 자동으로 삭제 됩니다.");
		// 2009-11-24 choyj_nec field.value = field.value.cut(maxlimit);
		field.value = field.value.substr(0, maxlimit);
	}
	if(countfield !=null ){
        countfield.innerHTML = getByteLength(field.value);
	}
}

/**
 * 주민번호 입력할 때 자동으로 다음 input 으로 이동한다.<br />
 * 사용법 onkeyup="moveNextField('juminno1','juminno2',6);"
 * @param {string} id_from 주민번호첫번째 필드 아이디
 * @param {string} id_to 주민번호 두번째 필드아이디
 * @param {int} maxSize 자릿수
 */
var next_go = true;
var cur_val = null;
function moveNextField(id_from,id_to,maxSize) {
	var cur = document.getElementById(id_from).value;
	curSize = cur.length;
	numFlag = isNumeric(cur);

	if ( !numFlag && curSize >= 1 && cur != '00' &&  cur != '000') {
		alert('숫자를 넣어주세요');
		document.getElementById(id_from).value='';
		document.getElementById(id_from).focus();
		return false;
	}
	if (curSize == maxSize) {
		if(next_go || cur_val != cur)
		{
			cur_val = cur;
			next_go = false;
			document.getElementById(id_to).focus();
		}
		return true;
	}
	next_go = true;
}

/**
 * 소수점이하 문자열을 포함하여 금액을 표시한다.
 * @param {string} num 문자열
 * @return {string} 문자열
 */
function formatCurrency(num){
	var sFirst = num.toString();  //변환전 문자열
	var sSecond = sFirst;    //변환후 문자열
	var sDot = "";      //소수점이하의 문자열
	var sTot ="";      //전체문자열

	if (sFirst.indexOf(".", 0) > 0) {
		sSecond = sFirst.substr(0, sFirst.indexOf(".", 0));
		sDot = sFirst.substring(sFirst.indexOf(".", 0), sFirst.length);
	}

	var len = sSecond.length;

	if (sSecond > 1) {
		while(len > 3) {
			len -= 3;
			sTot = ","+ sSecond.substr(len,3) + sTot;
		}
		return sSecond.substr(0,len) + sTot + sDot;
	} else {
		return sFirst;
	}
} 

/**
 * 금액마다 콤마를 찍어준다.
 * <code>onkeypress = addComma(this);</code>
 * @author 김동완
 */
function addComma(fname) {
	var value1 = delCommaRet(fname.value);
	var value2 = value1.length;
	var sVal = "";
	var j = 0;
	for (var i=value2; i>=0; i--) {
		var tmp = value1.charAt(i);
		if (tmp != ",") {
			if (j%3 == 0 && j != 0) {
				sVal = tmp + "," + sVal;
				j++;
			}else {
				sVal = tmp + sVal;
				j++;
			}
		}
	}
	fname.value = sVal;
}

/**
 * 컴마지운후 값 리턴.
 * @author 김동완
 */
function delCommaRet(fname) {
	var value1 = fname;
	var value2 = fname.length;
	var sVal = "";
	var j = 0;
	for (var i=value2; i>=0; i--) {
		var tmp = value1.charAt(i);
		if (tmp != ",") {
			sVal = tmp + sVal;
		}
	}
	return sVal;
}

/**
 * 금액 입력시 한글로 보여주기 
 * @fname this
 * @divId 금액을 표시할 divId. Null일 경우 한글금액을 반환 
 */
function changeHan(fname, divId)
{  
	hanA = new Array("","일","이","삼","사","오","육","칠","팔","구","십");
	danA = new Array("","십","백","천","","십","백","천","","십","백","천");
	num = delCommaRet(fname.value).split(',').join('');
	result = "";
		
	for(i=0 ; i < num.length ; i++) 
	{
		str = "";
		han = hanA[num.charAt(num.length-(i+1))];
		if(han != "") str = han+danA[i];
		if(i == 4) str += "만";
		if(i == 8) str += "억";
		result = str + result;
	}
	
	if(num.length > 0)
	{
		result = result + "원";
	} 
	
	if(divId != null && divId != ''){
		document.getElementById(divId).innerHTML = result;
	} else {
		return result;
	}
}

