﻿// JScript 파일

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.16
// Description  : 숫자만 입력가능하게
// arguments[0] : 허용문자
// ============================================================			
function onlyNumber()
{
	var ex = arguments[0]?arguments[0]:"";
	var exCode = 0;
	if(ex != "")
	{
		exCode = ex.charCodeAt(0);
	}
	
	if((event.keyCode<48)||(event.keyCode>57)) {
	    if ( event.keyCode == 13 || event.keyCode == exCode ) {
			event.returnValue=true;
		}
		else{
	        event.returnValue=false;
	    }
	    return;
	}
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : 숫자와 - 만 입력가능하게
// arguments[0] : 허용문자
// ============================================================		
function onlyNumAndMinus()
{			

	if(event.keyCode != 45){
		if((event.keyCode<48)||(event.keyCode>57)) {
			if ( event.keyCode!=13 ) {
				event.returnValue=false;
			}
			return;
		}
	}
}

// ============================================================
// 문자열의 앞뒤 space를 제거한다.
// ============================================================ 
String.prototype.trim = function trim(){
	var value = this;
	if (value == null) value =  "";
	value = value.replace(/^\s+/,  ""); // remove leading  white spaces
	value = value.replace(/\s+$/g, ""); // remove trailing while spaces
	return value;
}

//-----------------------------------------------------------------------------
// 문자의 좌 공백 제거
// @return : String
//-----------------------------------------------------------------------------
String.prototype.ltrim = function() {
	return this.replace(/(^\s*)/, "");
};

//-----------------------------------------------------------------------------
// 문자의 좌 공백 제거
// @return : String
//-----------------------------------------------------------------------------
    String.prototype.ltrim = function() {
	    return this.replace(/(^\s*)/, "");
    };

//-----------------------------------------------------------------------------
// 문자의 우 공백 제거
// @return : String
//-----------------------------------------------------------------------------
    String.prototype.rtrim = function() {
	    return this.replace(/(\s*$)/, "");  
    };

//-----------------------------------------------------------------------------
// 왼쪽자리수 채우기
// arguments[0] : 전체자리수
// arguments[1] : 채울 문자(default "0")
// @return : String
//-----------------------------------------------------------------------------
    String.prototype.lpad = function() {
	    if(this != null && this != ""){
		    var cnt    = arguments[0];
		    var padStr = arguments[1] ? arguments[1] : "0";
		    var digit = "";
		    if (this.length < cnt) {
			    for(var i = 0; i < cnt - this.length; i++) {
				    digit += padStr;
			    }
		    }
		    return digit + this;
	    }
	    else {
		    return this;
	    }
    };
//-----------------------------------------------------------------------------
// 오른쪽자리수 채우기
// arguments[0] : 전체자리수
// arguments[1] : 채울 문자(default "0")
// @return : String
//-----------------------------------------------------------------------------
    String.prototype.rpad = function() {
	    if(this != null && this != ""){
		    var cnt    = arguments[0];
		    var padStr = arguments[1] ? arguments[1] : "0";
		    var digit = "";
		    if (this.length < cnt) {
			    for(var i = 0; i < cnt - this.length; i++) {
				    digit += padStr;
			    }
		    }
		    return this + digit;
	    }
	    else {
		    return this;
	    }
    };

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.19
// Description  : 이메일 체크 함수
// ============================================================		
function checkEmail(email) {
		
	var invalidChars = "\"|&;<>!*\'\\"   ;
	for (var i = 0; i < invalidChars.length; i++) {
		if (email.indexOf(invalidChars.charAt ) != -1) {
		alert("잘못된 이메일 주소입니다.");
		return false;
		}
	}
	if (email.indexOf("@")==-1){
		alert("잘못된 이메일 주소입니다. '@'가 없습니다..");
		return false;
	}
	if (email.indexOf(" ") != -1){
		alert("잘못된 이메일 주소입니다.");
		return false;
	}
	if (window.RegExp) {
		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
		var reg1 = new RegExp (reg1str);
		var reg2 = new RegExp (reg2str);
		
		if (reg1.test(email) || !reg2.test(email)) {
		alert("잘못된 이메일 주소입니다.");
		return false;
		}
	}
	return true;
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.19
// Description  : 공통 팝업 띄우기
// ============================================================		
function OpenWindow(pUrl, pTitle, pWidth, pHeight)
{
	var left = (screen.width - pWidth) / 2 ;
	var top	= (screen.height - pHeight) / 2 ;
	var sFeatures = 'left=' + left + ', top=' + top + ', width=' + pWidth + ', height=' + pHeight + ',status=yes,toolbar=no,menubar=no,location=no' ;
	window.open(pUrl, pTitle, sFeatures);
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : ID 비번 체크
// ============================================================		
function loginChk()
{
	if(document.getElementById("UserId").value =="")
	{
		alert("아이디를 입력하세요");
		document.getElementById("UserId").focus();
		return;
	}
	if(document.getElementById("UserPwd").value =="")
	{
		alert("비밀번호를 입력하세요");
		document.getElementById("UserPwd").focus();
		return;
	}
	 document.frm.method ="post";
	 document.frm.action ="./admin_login.asp";
	 document.frm.submit();
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : ID 비번 체크
// ============================================================		
function IntraChk()
{
	if(document.getElementById("UserId").value =="")
	{
		alert("아이디를 입력하세요");
		document.getElementById("UserId").focus();
		return;
	}
	if(document.getElementById("UserPwd").value =="")
	{
		alert("비밀번호를 입력하세요");
		document.getElementById("UserPwd").focus();
		return;
	}
	 document.frm.method ="post";
	 document.frm.action ="./Intra_login.asp";
	 document.frm.submit();
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : 로그인 엔터키 적용
// ============================================================	
function onIntEnter()	{

    if(event.keyCode == 13){

      IntraChk();

    }

}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : 페이지 이동
// ============================================================		
function redirect(request_url){
    location.href = request_url;
}	

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : 로그인 엔터키 적용
// ============================================================	
function onEnter()	{

    if(event.keyCode == 13){

      loginChk();

    }

}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.12.31
// Description  : 로그아웃
// ============================================================	
function IntLogout(){

    if(!confirm("로그아웃 하시겠습니까?")) return false;
    document.frm.action = "./logout.asp";
    document.frm.method = "post";
    document.frm.submit();

}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : 로그아웃
// ============================================================	
function Logout(){

    if(!confirm("로그아웃 하시겠습니까?")) return false;

    parent.location.reload(); 
    document.frm.action = "./logout.asp";
    document.frm.method = "post";
    document.frm.submit();

}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : Re submit
// ============================================================	
function ReSubmit(url){
    
    document.frm.action = url;
    document.frm.method = "post";
    document.frm.submit();

}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : 입력한 글자수를 제한
// ============================================================	
function LimitLength(txaName,txaMaxLength)
{
   var boolReturn = true;
   var txaValue     = txaName.value;    // 이벤트가 일어난 컨트롤의 value 값
   var txaFullLength = txaValue.length; // 전체길이

   // 변수초기화
   var limitLength   = txaMaxLength; // 제한할 글자수 크기
   var i             = 0;   // for문에 사용
   var TotalByte     = 0;   // 한글일경우는 2 그밗에는 1을 더함
   var CurrentLength = 0;   // substring하기 위해서 사용
   var OneChar       = "";  // 한글자씩 검사한다
   var txaValue2     = "";  // 글자수를 초과하면 제한할수 글자전까지만 보여준다.

   for(i=0; i< txaFullLength; i++)
   {
      // 한글자추출
      OneChar = txaValue.charAt(i);

      // 한글이면 2를 더한다.
      if (escape(OneChar).length > 4)
      {
         //TotalByte += 2;
         TotalByte += 1;    //컬럼형식이 nvarchar 이므로 한글1글자도 1자리로 처리한다
      }
      // 그밖의 경우는 1을 더한다.
      else
      {
         TotalByte++;
      }

      // 전체 크기가 limitLength를 넘지않으면
      if(TotalByte <= limitLength)
      {
         CurrentLength = i + 1;
      }
   }
   
   // 전체길이를 초과하면
   if(TotalByte > limitLength)
   {
      boolReturn = false;

      alert( limitLength + "글자를 초과 입력할수 없습니다. \n\n초과된 내용은 자동으로 삭제 됩니다 !      ");
      txaValue2 = txaValue.substr(0, CurrentLength);
      txaName.value = txaValue2;
      
   }
   txaName.focus();  
   
   return boolReturn; 
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.11.23
// Description  : 파일용량 체크
// ============================================================	
function getFileSize(path,obj)
{
    var maxSize = 10000000; //4M

    
    var Version = isIE6();
    
    /*
    if(Version == false){// MSIE 7인 경우　
 
        var fso = new ActiveXObject("Scripting.FileSystemObject"); 
      　
        var f = fso.GetFile(path);
     
　      var fileSize = f.size;
　     
　      f = null; 　
　      fso = null;
　     
    }else{ 　　// MSIE 7 이하인 경우　　
        var img = new Image(); 　
　      img.dynsrc = path; 　
　      fileSize = img.fileSize; 
    }
    if(filesize > maxSize) {
       alert("파일용량이 초과되었습니다.\n10MB 이하만 첨부가능 합니다.");
       obj.select();
	   // document.execCommand('Delete'); 
    }
    */
    
}


// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.12.01
// Description  : 라디오 버튼 값 가져오기
// ============================================================	

function getRadioButtonValue( radioField ) {     
  for (var i =0; i<radioField.length; i++) {         
      if( radioField[i].checked == true ) {             
        return radioField[i].value;         
      }     
  } 
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.12.01
// Description  : 인터넷 버전이 6인지 체크
// ============================================================	
function isIE6() {
	return (navigator.appVersion.indexOf("MSIE 6.0") != -1) ? true : false;
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.12.01
// Description  : 인터넷 버전이 6인지 체크
// ============================================================	
//-----------------------------------------------------------------------------
// 문자열내의 _findValue를 모두 _replaceValue로 바꾸어 준다
// ex : str.replaceAll('xx','bb');
// @return : String
//-----------------------------------------------------------------------------
String.prototype.replaceAll = function(_findValue, _replaceValue) {
	return this.replace(new RegExp(_findValue,"g"), _replaceValue);
};

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.12.31
// Description  : 체크박스 라디오 버튼 테두리 없애기
// ============================================================	
function RemoveOutline()
 {

  for(i=0;i<document.getElementsByTagName("input").length;i++)
  {
     objinput = document.getElementsByTagName("input");
     if(objinput[i].type == "radio" || objinput[i].type == "checkbox")
     {    
     objinput[i].style.border = 0;
     }
  }
 }
 RemoveOutline();
 
// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.12.31
// Description  : 공통 팝업 띄우기
// ============================================================		
function OpenWindow(pUrl, pTitle, pWidth, pHeight)
{
	var left = (screen.width - pWidth) / 2 ;
	var top	= (screen.height - pHeight) / 2 ;
	var sFeatures = 'left=' + left + ', top=' + top + ', width=' + pWidth + ', height=' + pHeight + ',status=yes,toolbar=no,menubar=no,location=no' ;
	window.open(pUrl, pTitle, sFeatures);
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.12.31
// Description  : 날짜유효성 체크
// ============================================================		
function chkValidDate(ctrl) {
	var ymd = ctrl.value;
	var ymd = ymd.replace(/-/g,'');
	if(ctrl.value != ""){
		if(!isValidDate(ymd)) {
			alert('유효한 날짜가 아닙니다.');
			ctrl.value = "";
			ctrl.focus();  
			return;
		}
	}
	fmt_ymd(ctrl);
	return;
}

function isValidDate(s) {
	var s;
	var valchk;
	s = s.replace(/-/gi,"")
	valchk = s.substr(0,4);
	if(valchk <1900  || valchk > 2100){	return false;}
	if (s.length == 8) {
		var pt = /^\d{4}\d{2}\d{2}/;      
		if (!pt.test(s)) return false;
	} 
	else if(s.length == 6) {
		var pt = /^\d{4}\d{2}/;
		if (!pt.test(s)) return false;
		s = s + "01";
	} 
	else if(s.length == 4) {
		var pt = /^\d{4}/;
		if (!pt.test(s)) return false;
		s = s + "0101";
	} 
	else {
		return false;
	}

	var y = parseInt(s.substr(0,4), 10);
	var m = parseInt(s.substr(4,2), 10) -1;
	var d = parseInt(s.substr(6,2), 10);
	var dt = new Date(y, m, d);

	if (dt.getFullYear() == y && dt.getMonth() == m && dt.getDate() == d) {
		return true;
	}
	else {
		return false;
	}
}

// ============================================================ 
// 작성자       : 김현우
// 작성일       : 2009.12.31
// Description  : 날짜에 ' - ' 붙이기
// ============================================================		
function fmt_ymd(input) {
	val = input.value.replaceAll('-','');
	if (val.length == 8)    
		input.value = val.substring(0,4) + '-' + val.substring(4,6) + '-' + val.substring(6,8);
}














