﻿/********************************************************
 filename : mcpValidator.js
 author : rian-susukang
 create : 2006.10.31     
   
 
*********************************************************/
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/gi, "");
}
// ID Key Code Filter
	function inputIdFilter(obj)
	{
		if (event.keyCode == 13)
			return;
		if (((event.keyCode<48 || event.keyCode>57) && (event.keyCode<97 || event.keyCode>122) && (event.keyCode<65 || event.keyCode>90))) {
			 obj.focus();
			 event.returnValue=false;
		}
	}
	
	function inputContentFilter(obj)
	{
	    //var specialChars="#$%^&*()_+-={}[];':\",.<>/?";
	    var specialChars="'\"<>";
	    var keycode=String.fromCharCode(event.keyCode);
		
        if (specialChars.indexOf(keycode) != -1) {
			obj.focus();
			event.returnValue=false;
			alert('허용되지 않은 특수문자입니다.');
	    }
	}
	
	function inputAddressFilter(obj)
	{		
	    var specialChars="~`!@#$%^&*()_+={}[];':\",<>/?";
	    var keycode=String.fromCharCode(event.keyCode);
		
        if (specialChars.indexOf(keycode) != -1) {
			obj.focus();
			event.returnValue=false;
			alert('허용되지 않은 특수문자입니다.');
	    }
	}
	
	function inputMailFilter(obj)
	{		
	    var specialChars="~`!#$%^&*()+={}[];':\",<>/?";
	    var keycode=String.fromCharCode(event.keyCode);
		
        if (specialChars.indexOf(keycode) != -1) {
			obj.focus();
			event.returnValue=false;
			alert('허용되지 않은 특수문자입니다.');
	    }
	}
	
	function checkEmail(email) { 
	    var regExp = /[a-z0-9]{1,}@[a-z0-9-]{2,}.[a-z0-9]{2,}/i; 
	    
	    if(regExp.test(email))
	    	return true; 
	    else 
	    	return false; 
	}

	// Key Code Finder
	function keyCodeFinder()
	{
	   var ls_html = "";
	   var lo_win;
	
	   ls_html = ls_html + "<html>\n";
	   ls_html = ls_html + "<head>\n";
	   ls_html = ls_html + "<title>Press Any Key</title>\n";
	   ls_html = ls_html + "</head>\n";
	   ls_html = ls_html + "<body onkeydown=\"alert('The keyCode is ' + window.event.keyCode)\" style=\"font-family: verdana; font-size: 12px; background-color: buttonface; border: 0; color: buttontext; text-align: center;\" scroll=\"no\">\n";
	   ls_html = ls_html + "Press Any Key\n";
	   ls_html = ls_html + "</body>\n";
	   ls_html = ls_html + "<script>\n";
	   ls_html = ls_html + "window.resizeTo(200,100);\n";
	   ls_html = ls_html + "<\/script>\n";
	   ls_html = ls_html + "</html>\n";
	
	   lo_win = window.open("","win_keycode","width=200,height=100");
	
	   lo_win.document.write(ls_html);
	}

	// Disable Key Filter
	function delBackSpaceDisable(){
		var li_del_key = 46;       // delete?? KeyCode ?
		var li_backspace_key = 8;  // backspace?? KeyCode ?
   		if(event.keyCode==li_del_key || event.keyCode==li_backspace_key){
			event.returnValue = false;
		}
	}
	
// onkeypress Input Field Filter

	// Input Field Filter[sidInputFilter]
	function sidInputFilter(obj){
		 var sid = obj.value;
		 
		if(event.keyCode ==13) event.returnValue=false;
		
		if((event.keyCode<48) || (event.keyCode>57)) {
			 obj.focus();
			 event.returnValue=false;
		 }
		 if(sid.length==6) obj.value = obj.value+'-';	 
	}
	
	// Input Field Filter[numberInputFilterWithMinus]
	function numberInputFilterWithMinus(obj){
		if(event.keyCode ==13) return; 
		if((event.keyCode!=45)&&((event.keyCode<48) || (event.keyCode>57))) {
			 obj.focus();
			 event.returnValue=false;
		}
	}
	
	// Input Field Filter[numberInputFilter]
	function numberInputFilter(obj){
		if ((event.keyCode<48) || (event.keyCode>57)) {
			 obj.focus();
			 event.returnValue=false;
		}
	}
	
	// Input Field Filter[koreanWordInputFilter]
	function koreanWordInputFilter(obj){
		 if((event.keyCode < 12592) || (event.keyCode > 12687)){
			 obj.focus();
			 event.returnValue = false;
		 }
	}
	
	// Input Field Filter[koreanWordInputFilter]
	function koreanNumberInputFilter(obj){
		 if( ((event.keyCode < 12592) || (event.keyCode > 12687)) && ((event.keyCode<48) || (event.keyCode>57)) ) {
		 	obj.focus();
			event.returnValue = false;
		 }
	}
		
	//Input Field Filter[without ETC character filter]
	function withoutEtcChar(){

		if( event.keyCode=="34" ||  // " 
			event.keyCode=="94" 	// ^
			) event.returnValue = false;
    }

//Trim

	function minusTrim(str){
		return str.replace(/(-)/,"");
	}

 	//onblur Field Validator[HandPhone ]
	function handPhone(obj) {
		objs = obj.split( '-' );

		if( objs.length == 1 || objs.length == 3 )
		{
			if( objs.length == 3 )
				obj = objs[ 0 ] + '' + objs[ 1 ] + '' + objs[ 2 ];

			var reg = new RegExp("[0-9]");
			for(var i = 0 ; i < obj.length ; i++) {
				if(!reg.test(obj.charAt(i))) {
					return false;
				}
			}
		}
		else
		{
			return false;
		}

		return true;
	}
	
	// emwp Pwd Check
	function isGoodPwd(obj){
		var chkPwd = /^[a-z0-9_]{3,20}/;
		
		if(chkPwd.test(obj.value)){
			return false;
		}else{
			return true;
		}
	}
	
	function contents_filter(contents) {
		var reg1 = /((\d{6})([\-|\s]))+([1|2]\d{6})/   
		var reg2 = /((\(?([0]\d{1,2})\)?)([\-|\s]))*((\d{3,4})([\-|\s]))+(\d{4})/
		var reg3 = /((\d{6}))+([1|2|3|4|9|0]\d{6})/
		//var reg3 = /\d{6}(\-|)[1-4]\d{6}$/
		//var reg4 = /20/[0-9]/
		
		//alert("reg1="+contents.match(reg1));
		//alert("reg2="+contents.match(reg2));
		//alert("reg3="+contents.match(reg3));
		//alert("reg4="+contents.match(reg4));
		var str_reg = ""+contents.match(reg3);
		var arr_reg = str_reg.split(",");

		var reg_t = arr_reg[0];
		
		//alert("reg_t="+reg_t); 
		//alert("주민번호체크="+checkSIDCheckEmwp(reg_t));
	
	    //alert("contents.match(reg3)="+contents.match(reg3));
		if (contents.match(reg1)||contents.match(reg2)||(contents.match(reg3) && checkSIDCheckEmwp(reg_t))) {
		//if(contents.match(reg1)||contents.match(reg2)||contents.match(reg3)){
			//alert("주민번호 있어요.");
			return false;
		}		
		//alert("주민번호 없음!!!!!!!!!!!!!!!!!!!!!!!!!!!!!.");
		return true;
	}		
    
  	function OnCopy () {
            if (window.clipboardData) {
                window.clipboardData.setData ("Text", "개인정보보호법에 의해 민원글 복사를 차단합니다.");
            }
            return false;   // cancels the default copy operation
        }
        
	function copy_clipboard(obj) {
		if (!document.all) return;
        var index = obj;
        if (index.value=='') { 
        	document.body.focus(); 
        	return; 
        }
        
        index.select();
        var clip = index.createTextRange();
        clip.execCommand('copy');
    }
    
	//------------------------------------------------------------------------------
	// 함수명 : check_byte
	// 설명   : 글자수 제한
	//------------------------------------------------------------------------------
	function check_byte(_obj, _maxlength) {
		var ls_str = _obj.value; 
		var li_str_len = ls_str.length; 
		var li_max = _maxlength; 
		var i = 0; 
		var li_byte = 0; 
		var li_len = 0; 
		var ls_one_char = ""; 
		var ls_str2 = ""; 
		
		for(i=0; i<li_str_len; i++) {
			ls_one_char = ls_str.charAt(i); 
			if (escape(ls_one_char).length > 4) {
				li_byte += 2; 
			} else  { 
				li_byte++;
			} 
			
			if(li_byte <= li_max) { 
				li_len = i + 1; 
			} 
		} 
		
		if(li_byte > li_max) {
			alert( li_max + " 글자이내로 입력해주세요."); 
			ls_str2 = ls_str.substr(0, li_len); 
			_obj.value = ls_str2;
		} 
	}
	
	/**
	* 입력된 인자 숫자 인지 검사 한다.
	*/
	function isNumberEmwp(obj) {
		var reg = new RegExp("[0-9]");
		for(var i = 0 ; i < obj.length ; i++) {
			if(!reg.test(obj.charAt(i))) {
				return false;
			}
		}
		return true;
	}
	
	/**
	*   주민번호의 년월일(yymmdd)형식을 체크
	*/
	function isDateSSNEmwp( value, bit )
	{
	    var year = value.substring(0,2);
	    var month = value.substring(2,4);
	    var day   = value.substring(4,6);
	    
	    if ( checkMonthEmwp( month ) && checkDaySSNEmwp( year, month, day, bit ) )
	        return true;
	    else
	       return false;
	       
	}
	
	/**
	* 주민번호 체크 - 예외있슴, checksid 추천
	*/
	function checkSIDCheckEmwp(juminNum) {
		var s_SID;  // 주민등록번호
		var s_Mask; // 주민등록번호 검사를 위한 Mask 값
		var a;      // Loop Index 변수
		//alert(1);
		s_SID = juminNum;
		//s_SID = s_SID.replaceAll("-","");
		//s_SID = s_SID.replaceAll("_","");
		//s_SID = s_SID.replaceAll(" ","");

		s_Mask = "234567892345";
		//alert(2);
		if (s_SID.length != 13) { return false; }
		//alert(3);
		if(!isNumberEmwp(s_SID)) { return false; }
		//alert(4);
		if ( !isDateSSNEmwp( s_SID.substring(0,6), s_SID.substring(6,7) ) ) { return false; }
		//alert(5);
		var tot = 0;
		for( a = 0; a < 12; a++ ) { 
			tot += parseInt(s_SID.substring(a,a+1), 10) * parseInt(s_Mask.substring(a,a+1), 10); 
		}

		var result = 11 - (tot % 11);
		result = result % 10;
		var last = s_SID.substring(12);
		//alert(3);
		if ( result != parseInt(last,10) ) { return false; }
		return true;
			
	}
	
	/**
	*  입력된 월을 확인
	*/
	function checkMonthEmwp( value )
	{
	    if ( parseInt( value, 10 ) <= 0  || parseInt( value, 10 ) > 12  )
	        return false;
	    else
	        return true;
	}
	
	/**
	*  년월일의 형식을 확인
	*/
	function checkDaySSNEmwp( yy, mm, value, bit )
	{
	    var yyyy = null;
	    var monthDD = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	    var im = parseInt(mm, 10) - 1;
	    
	    if ( bit == "1" || bit == "2" ) 
	        yyyy = parseInt( "19" + yy, 10 );
	    else 
	        yyyy = parseInt( "20" + yy, 10 );
	        
	    if( ( (yyyy % 4 == 0) && (yyyy % 100 != 0)) || (yyyy % 400 == 0) )
	        monthDD[1] = 29;
	    
	    if( parseInt( value, 10 ) <= 0 || parseInt( value, 10 ) > monthDD[im] )
	        return false;
	    else
	        return true;
	}
	

