/*
 * javascript ±âº» ÇÔ¼ö
 * @filename  : lib.js
 * @version   : v 0.2 2006.01.18
 * @author    : jang eun sung
 */
 
/*
lib_initFrame()			¡æ iframe Å©±â ÀÚµ¿ Á¶Àý

lib_imgVisibility			¡æ img °¡½Ä¼º Ã¼Å©ÇÏ¿© ¹Ý´ë·Î ¼³Á¤ÇØÁÜ

lib_isProcess()			¡æ isProcess is true/false check


lib_telKuk_onKey(obj, obj2)		¡æ ÀüÈ­¹øÈ£ ±¹¹ø ¾ÕÀÚ¸® È®ÀÎ ÇÔ¼ö
lib_telNo_onKey(obj, obj2)		¡æ ÀüÈ­¹øÈ£ µÞÀÚ¸® È®ÀÎ ÇÔ¼ö


lib_Jumin_chk(strInput)		¡æ ÁÖ¹Î¹øÈ£ È®ÀÎ
lib_Saun_chk(strCorpNum)		¡æ »ç¾÷ÀÚ¹øÈ£ È®ÀÎ


lib_NumberHanComma(obj1,obj2)		¡æ ÄÞ¸¶ Ãß°¡ ¹× ÀÔ·Â ¼ýÀÚÀÇ ÇÑ±ÛÈ­
lib_CommaDel(str)			¡æ ÄÞ¸¶ »èÁ¦
lib_CommaAdd(strValue)		¡æ ÄÞ¸¶ Ãß°¡





lib_check_nonchar(strInput)		¡æ Æ¯¼ö¹®ÀÚ È®ÀÎ
lib_check_num(strInput)		¡æ ¼ýÀÚ È®ÀÎ
lib_check_alpha(strInput)		¡æ ¿µ¹®ÀÚ È®ÀÎ
lib_check_alphaNumber(strInput)	¡æ ¿µ¼ýÀÚ È®ÀÎ

lib_check_space(strInput)		¡æ °ø¹é È®ÀÎ
lib_check_korean(strInput)		¡æ ÇÑ±Û Æ÷ÇÔ È®ÀÎ

lib_is_length(strInput)		¡æ ¹®ÀÚ¿­ ±æÀÌ ¹ÝÈ¯
lib_is_byte(strInput)		¡æ ¹®ÀÚ¿­ byte ¹ÝÈ¯

lib_HTMLDecode(strInput)		¡æ Tag¸¦ HTML Æ¯¼ö ¹®ÀÚ·Î º¯È¯

lib_trim(strInput)			¡æ ÁÂ¿ì °ø¹éÁ¦°Å

lib_layerhideshow(obj)			¡æ ÇØ´ç °´Ã¼°¡ º¸¿©Áö°í ÀÖÀ¸¸é °¨Ãá´Ù.(layer)
lib_makeCursorHand(obj)			¡æ Mouse ¼Õ¸ð¾çÀ¸·Î º¯°æ
lib_onmousebgcolor(obj,bgcolors)	¡æ onMouseOver="lib_onmousebgcolor(this,'#FFF0F5');"
				¡æ onMouseOut="lib_onmousebgcolor(this,'');"


lib_location(urlstr)			¡æ location.href
lib_locationReplace(urlstr)			¡æ urlstr ÁÖ¼ÒÀÇ ÆäÀÌÁö·Î ÀÌµ¿ÈÄ Çö ÆäÀÌÁö·Î history.back();ÀÌ ¾ÈµÊ					

lib_newWindowOpen(loadurl,windowname,widthsize,heightsize,toolbar_yn,resizalbe_yn,scrollbars_yn,menubar_yn,toppx,leftpx)
¡æ lib_newWindowOpen("ÁÖ¼Ò","Ã¢ÀÌ¸§","widthÅ©±â","heightÅ©±â","Åø¹Ùyes/no","Å©±âÁ¶Àýyes/no","½ºÅ©·Ñ¹Ùyes/no","¸Þ´º¹Ùyes/no",""ÀÌ¸é Math.floor( (screen.availWidth-(w+12))/2 ),""ÀÌ¸é Math.floor( (screen.availHeight-(h+30))/2 ))


lib_keyP(e,obj)			¡æ enter key onKeyPress ¹ß»ý½Ã obj·Î focus ÀÌµ¿
lib_keyF(e,funObj) 			¡æ enter key onKeyPress ¹ß»ý½Ã funobj È£Ãâ
lib_focus(obj)			¡æ obj focus
lib_readOnly(obj)			¡æ obj readOnly / bgcolor º¯°æ
*/

/*
	<style='ime-mode:active'> : ÇÑ±Û ÀÚµ¿ÀÔ·Â 
	<style='ime-mode:inactive'> : ¿µ¹® ÀÚµ¿ÀÔ·Â 
	document.ÆûÀÌ¸§.ÄÁÆ®·Ñ¸í.disabled = true
	document.all.sbtn.style.visibility = "hidden";
	formObj.encoding="multipart/form-data";
*/
	
//######################## iframe ÀÚµ¿ Å©±â Á¶Àý Js ########################
	function lib_initFrame()
	{
		try{
			self.resizeTo(document.body.scrollWidth , document.body.scrollHeight);
		}catch(err){}
	}
//######################## //iframe ÀÚµ¿ Å©±â Á¶Àý Js ########################

	function lib_imgVisibility(imgObj)
	{
		if(imgObj.style.visibility == ""){
			imgObj.style.visibility = "hidden";
		}else{
			imgObj.style.visibility = "";
		}
	}
//######################## Áßº¹ ½ÇÇà ¹æÁö Js ########################
	var isProcess = false;
	function lib_isProcess()
	{
		if(isProcess == true){
			alert("Ã³¸®ÁßÀÔ´Ï´Ù. Àá½Ã¸¸ ±â´Ù·Á ÁÖ½Ê½Ã¿À.");
			return true;
		}else{
			return false;
		}
	}
//######################## //Áßº¹ ½ÇÇà ¹æÁö Js ########################

//######################## ¼ýÀÚ ÄÚ¸¶ Ã³¸® JS ########################
		function lib_NumberHanComma(obj1,obj2)
		{
			var obj1Tmp;
			var obj2Tmp;
		
			obj1Tmp = lib_CommaDel(obj1.value);
		
			if(!lib_check_num(obj1Tmp)){
				alert("¼ýÀÚ¸¸ ÀÔ·ÂÀÌ °¡´ÉÇÕ´Ï´Ù.");
				obj1Tmp = String(obj1Tmp).substring(0,String(obj1Tmp).length - 1);
				obj1.value = lib_CommaAdd(obj1Tmp);
				return false;
			}
		
			if (obj1Tmp == 0) obj2Tmp =  '¿µ';
			
			var phonemic = ['','ÀÏ','ÀÌ','»ï','»ç','¿À','À°','Ä¥','ÆÈ','±¸'];
			var unit = ['','','½Ê','¹é','Ãµ','¸¸','½Ê¸¸','¹é¸¸','Ãµ¸¸','¾ï','½Ê¾ï','¹é¾ï','Ãµ¾ï','Á¶','½ÊÁ¶','¹éÁ¶'];
        		
			var ret = '';
			var part = new Array();
		
			for (var x=0; x<String(obj1Tmp).length; x++) part[x] = String(obj1Tmp).substring(x,x+1);
			for (var i=0, cnt = String(obj1Tmp).length; cnt > 0; --cnt,++i){
				p = phonemic[part[i]];
				p+= (p) ? (cnt>4 && phonemic[part[i+1]]) ? unit[cnt].substring(0,1) : unit[cnt] : '';
				ret+= p;
			}
			
			obj2Tmp = ret;
			obj1Tmp = lib_CommaAdd(obj1Tmp);
		
			obj1.value = obj1Tmp;
			obj2.value = obj2Tmp;
		}
        		
		function lib_CommaDel(str)
		{
 			re = /^$|,/g;	// "$" and "," ÀÔ·Â Á¦°Å
 			return str.replace(re, "");
		}
        		
		function lib_CommaAdd(strValue)
		{
 			var objRegExp = new RegExp('(-?[0-9]+)([0-9]{3})'); 
   			while(objRegExp.test(strValue)){
   				strValue = strValue.replace(objRegExp, '$1,$2');
   			} 
 			return strValue;
		}
//######################## //¼ýÀÚ ÄÚ¸¶ Ã³¸® JS ########################


//######################## ÁÖ¹Î/»ç¾÷ÀÚ¹øÈ£ È®ÀÎ JS ########################

			function lib_Jumin_chk(strInput)
			{
				IDtot = 0;
				IDAdd="234567892345";

				if(!lib_check_num(strInput) || lib_is_length(strInput) != 13){
					return false;
				}
			
				
				for(i=0;i<12;i++){
					IDtot=IDtot+parseInt(strInput.substring(i,i+1))*parseInt(IDAdd.substring(i,i+1));
				}
				IDtot=11-(IDtot%11);
			
				if(IDtot==10){
					IDtot=0;
				}else if(IDtot==11){
					IDtot=1;
				}
				
				if(parseInt(strInput.substring(12,13))==IDtot){
					return false;
				}else{
					return true;
				}
			}
			

			function lib_Saun_chk(strCorpNum)
			{
				var num=strCorpNum;
				
				var w_c,w_e,w_f,w_tot;
				
				w_c    = num.charAt(8) * 5;
				w_e    = parseInt((w_c/10),10);
				w_f    = w_c % 10;
				
				w_tot  = num.charAt(0) * 1;
				w_tot += num.charAt(1) * 3;
				w_tot += num.charAt(2) * 7;
				w_tot += num.charAt(3) * 1;
				w_tot += num.charAt(4) * 3;
				w_tot += num.charAt(5) * 7;
				w_tot += num.charAt(6) * 1;
				w_tot += num.charAt(7) * 3;
				w_tot += num.charAt(9) * 1;
				w_tot += (w_e+w_f)		 
				
				if (!(w_tot % 10))  return true;
			}
			
//######################## //ÁÖ¹Î/»ç¾÷ÀÚ¹øÈ£ È®ÀÎ JS ########################


//######################## ÀüÈ­¹øÈ£ ÀÔ·Â È®ÀÎ JS ########################
			function lib_telKuk_onKey(obj, obj2)
			{
				var strValue	= obj.value;
			
				if( strValue.substring(0,1) == "0" ){
					alert("¸Ç¾ÕÀÚ¸®¿¡ '0'ÀÌ ¿Ã ¼ö°¡ ¾ø½À´Ï´Ù.");
					return false;
				}
			
				if(!lib_check_num(strValue)){
					alert("¼ýÀÚ¸¸ ÀÔ·ÂÀÌ °¡´ÉÇÕ´Ï´Ù.");
					return false;
				}
			
				if ( strValue.length == 3 ){
					obj2.focus();
					obj2.select();
				}
			}
			function lib_telNo_onKey(obj, obj2)
			{
				var strValue	= obj2.value;
				var tmpStr;
			
				if(!lib_check_num(strValue)){
					alert("¼ýÀÚ¸¸ ÀÔ·ÂÀÌ °¡´ÉÇÕ´Ï´Ù.");
					return false;
				}
			
				if(obj.value.length !=4 ){
					if ( strValue.length == 5 ){
						tmpStr = strValue.substring(0,1);
			    	    		obj.value = obj.value.substring(0,3) + tmpStr;
						obj2.value = obj2.value.substring(1,5);
					}
				}else{		
					if(strValue.length ==5 ){
						obj2.value = strValue.substring(0,4);
					}
				}
			}
//######################## //ÀüÈ­¹øÈ£ ÀÔ·Â È®ÀÎ JS ########################


//######################## ±âº» Js ########################
	
	function lib_check_num(strInput)
	{
		/*
		var isPW = /^[0-9]/;

		if(isPW.test(strInput) ){
       			return true;
		}else{
			return false;
		}
		*/
		
		for(var i=0;i<strInput.length;i++){
			var codenum=strInput.charCodeAt(i);
			
			if(codenum > 58 || codenum < 47){
				return false;
			}
		}
		
		return true;
	}
	
	function lib_check_alpha(strInput)
	{
		var isPW = /^[a-zA-Z]/;
		
		if(isPW.test(strInput) ){
       			return true;
		}else{
			return false;
		}
	}
	
	function lib_check_alphaNumber(strInput)
	{
		var isPW = /^[a-zA-Z0-9]/;
		
		if(isPW.test(strInput) ){
       			return true;
		}else{
			return false;
		}
	}
	
	
	
	
	function lib_check_space(strInput)
	{
     		if(strInput.search(/\s/) != -1){
     			return true;
     		}else{
         			return false;
     		}
	}
	
	function lib_check_korean(strInput)
	{
		var result=false;
		for(var i=0;i<strInput.length;i++){
			var codenum=strInput.charCodeAt(i);
			if(codenum > 128){
				result=true;
			}
		}
		return result;
	}
	
	
	
	
	
	function lib_is_length(strInput)
	{
		var varLen = 0;
		var agr = navigator.userAgent;

		for (i=0; i<strInput.length; i++){
			ch = strInput.charAt(i);
			if ((ch == "\n") || ((ch >= "¤¿") && (ch <= "È÷")) || ((ch >="¤¡") && (ch <="¤¾")))
				varLen += 2;
			else
				varLen += 1;
		}
		return (varLen);
	}
	
	function lib_is_byte(strInput)
	{	    	
		var Obj_String;			//**	°Ë»ç ÇÒ ÀÔ·ÂÆûÀÇ ±ÛÀÚ
		var Obj_Count_Byte    =0;		//**	°Ë»ç ÇÒ ±ÛÀÚÀÇ Byte ¼ö
		var Obj_String_Length =0;		//**	°Ë»ç ±ÛÀÚÀÇ ±æÀÌ
		var tmpString;			//**	±ÛÀÚÀÇ ÀÓ½ÃÀúÀå
		var i;
			
		Obj_String		= new String(strInput);
		Obj_String_Length	= Obj_String.length;
				
		for(i=0;i<Obj_String_Length;i++){
			tmpString 	= Obj_String.charAt(i);
					
			if(escape(tmpString).length > 4){
				Obj_Count_Byte	+=2;
			}else if (tmpString != '\r'){
				Obj_Count_Byte	++;
			}
		}
				
		return Obj_Count_Byte;
	}
	
	
	
	
	
	function lib_HTMLDecode(strInput)
	{
		var strRetVal = "";

		strRetVal = strInput.replace(/&gt;/gi, ">");
		strRetVal = strRetVal.replace(/&lt;/gi, "<");
		strRetVal = strRetVal.replace(/&quot;/gi, "\"");
		strRetVal = strRetVal.replace(/&amp;/gi, "&");

		return strRetVal;
	}
	
	
	
	
	function lib_trim(strInput)
	{
		while (strInput.charAt(0) == " "){
			strInput = strInput.substr(1);
		}
		
		while (strInput.charAt(strInput.length-1) == " "){ 
			strInput = strInput.substr(0, strInput.length-1);
		}
		
		return strInput;
	}
	
	
	
	
	
	function lib_makeCursorHand(obj)
	{
		obj.style.cursor = "hand";
	}
	
	function lib_layerhideshow(obj)
	{
		if(obj.style.display == "none"){
			obj.style.display = "";
		}else{
			obj.style.display = "none";
		}
	}
	
	function lib_onmousebgcolor(obj,bgcolors)
	{
		obj.style.backgroundColor = bgcolors;
	}
	
	
	
	
	
	function lib_location(urlstr)
	{
		if(lib_trim(urlstr) != ""){
			location.href = urlstr ;
		}else{
			alert("Àß¸øµÈ ÀÌµ¿ ÁÖ¼ÒÀÔ´Ï´Ù.\n\n´Ù½Ã È®ÀÎÇØ ÁÖ½Ê½Ã¿À.");
		}
		
	}
	
	function lib_locationReplace(urlstr)
	{
		if(lib_trim(urlstr) != ""){
			location.replace(urlstr)
		}else{
			alert("Àß¸øµÈ ÀÌµ¿ ÁÖ¼ÒÀÔ´Ï´Ù.\n\n´Ù½Ã È®ÀÎÇØ ÁÖ½Ê½Ã¿À.");
		}
	}
	
	function lib_newWindowOpen(loadurl,windowname,widthsize,heightsize,toolbar_yn,resizalbe_yn,scrollbars_yn,menubar_yn,toppx,leftpx)
	{
		var windowoption;
		var openwindows;
		windowoption = "width=" + widthsize;
		windowoption = windowoption + ",height=" + heightsize;
		windowoption = windowoption + ",toolbar=" + toolbar_yn;
		windowoption = windowoption + ",resizable="+ resizalbe_yn;
		windowoption = windowoption + ",scrollbars=" + scrollbars_yn;
		windowoption = windowoption + ",menubar=" + menubar_yn;
		
		
		if(toppx == ""){
			windowoption = windowoption + ",top=" + Math.floor( (screen.availWidth-(widthsize * 2))/2 );
		}else{
			windowoption = windowoption + ",top=" + toppx;
		}
		
		if(toppx == ""){
			windowoption = windowoption + ",left=" + Math.floor( (screen.availHeight+(heightsize - (heightsize * 0.8)))/2 );
		}else{
			windowoption = windowoption + ",left=" + leftpx;
		}
		
		//alert(windowoption);
		openwindows = window.open(loadurl,windowname,windowoption);
		openwindows.focus();
	}
	
	
	
	
	
	function lib_keyP(e,obj)
	{
		var keycode = e.keyCode;
		if (keycode == 13){
			lib_focus(obj)		
		}
	}

	function lib_keyF(e,funObj)
	{
		var keycode = e.keyCode;
		if (keycode == 13){
			eval(funObj);
		}
	}

	function lib_focus(obj)
	{
		obj.focus();
	}
			
	function lib_readOnly(obj)
	{
		obj.style.backgroundColor = "#C0C0C0";
		obj.readOnly = true;
	}
	
	
	
	
	
	
	function lib_check_nonchar(strInput)
	{
		
		var isPW = /[$\\@\\\#%\^\&\*\(\)\[\]\+\-\_\{\}\`\~\=\|\/\!\;\:\'\"\,\<\.\>\?]/;
		if(strInput.search(isPW) != -1)
		{
			return true;
		}else{
			return false;
		}
	}
//######################## //±âº» Js ########################



