﻿<!--
/*

=======================================================
◈String prototype Define
=======================================================
 1. IsId		: 아이디 허용 문자열 체크
 2. IsTel		: 전화번호 허용 문자열 체크
 3. IsMoney	: 머니 허용 문자열 체크
 4. IsAlpha		: 알파벳 허용 문자열 체크
 5. IsNumber	: 숫자 허용 문자열 체크
 6. IsJumin		: 주민등록번호 유효성 체크
 7. IsEmail		: 이메일 유효성 체크
 8. IsDate		: 일자 유효성 체크
 9. StrLen		: 문자열 Byte 계산
 10.LTrim		: 좌측 공백제거
 11.RTrim		: 우측 공백제거
 12.Trim		: 좌우측 공백제거
 13.TrimAll		: 모든 공백제거
=======================================================
◈ function Define
1. _cmdfocus	: 객체에 포커스 주기
2. GetRadioValue	: Radio객체의 값 얻기
3. Go_Next	: 객체가 고정길이(MaxLength) 인 경우  다음 값으로 포커스 이동(2byte문자는 제외함.)
4. Go_Next2	: 객체가 요구한 길이를 넘어가는 경우 다음 값으로 포커스 이동
5. DateDiff		: 둘 날짜간의 차이 계산(주의 날짜 형식이 틀린 경우 엉뚱한 값을 리턴할수 있음)
6. checkform	: 각종 형식의 값을 체크한다.
7. IsVaild_Phone : 핸드폰 값들의 유효성 검사.
=======================================================
*/
	String.prototype.IsNumeric = function() {
		this = this.value.LTrim().RTrim();
		var num= this
		if (num.length  == 0) return false;
		return ((isNaN(num * 1))?false:true);
	}


	String.prototype.IsId = function() {
		if (this.search(/[^A-Za-z0-9]/) == -1)
			return true;
		else
			return false;
	}

	String.prototype.IsTel = function() {
		if (this.search(/[^0-9_-]/) == -1)
			return true;
		else
			return false;
	}

	String.prototype.IsMoney = function() {
		if (this.search(/[^0-9_,]/) == -1)
			return true;
		else
			return false;
	}

	String.prototype.IsAlpha = function() {
		if (this.search(/[^A-Za-z]/) == -1)
			return true;
		else
			return false;
	}

	String.prototype.IsNumber = function() {
		if (this.search(/[^0-9]/) == -1)
			return true;
		else
			return false;
	}

	String.prototype.IsJumin = function() {
		var jumin= this
		if (jumin.length  != 13)
			return false;
		tval=jumin.charAt(0)*2 + jumin.charAt(1)*3 + jumin.charAt(2)*4
		+ jumin.charAt(3)*5 + jumin.charAt(4)*6 + jumin.charAt(5)*7
		+ jumin.charAt(6)*8+ jumin.charAt(7)*9 + jumin.charAt(8)*2
		+ jumin.charAt(9)*3 + jumin.charAt(10)*4 + jumin.charAt(11)*5;

		tval2=11- (tval % 11);
		tval2=tval2 % 10;

		if (jumin.charAt(12)==tval2 &&  (jumin.charAt(6)=="1" ||jumin.charAt(6)=="2")) {
			return true;
		}
		else{
			return false ;
		}
	}

	String.prototype.IsEmail = function() {
		var re=new RegExp("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$","gi");
		var matchArray=this.match(re);
		if (matchArray) return true;
		else return false;
//		if (this.search(/(.+)@.+\..+/) == -1)
//			return false;
//		else if(this.search("[ ]") == -1)
//			return false;
//		else {
//			for(var i=0; i < this.length;i++)
//				if (this.charCodeAt(i) > 256)
//					return false;
//			return true;
//		}
	}

	String.prototype.IsDate = function() {
		if (this.search(/\d{4}\.\d{2}\.\d{2}/) == -1)
			return false;
		else {
			return true;
		}
	}

	String.prototype.StrLen = function() {
		var temp;
		var set = 0;
		var mycount = 0;

		for( k = 0 ; k < this.length ; k++ ){
			temp = this.charAt(k);

			if( escape(temp).length > 4 ) {
				mycount += 2
			}
			else mycount++;
		}

		return mycount;
	}

	String.prototype.LTrim = function() {
		var i, j = 0;
		var objstr

		for ( i = 0; i < this.length ; i++){
			if (this.charAt(i) == ' ' ){
				j = j + 1;
			}
			else{
				break;
			}
		}
		return this.substr(j, this.length - j+1)
	}

	String.prototype.RTrim = function() {
		var i, j = 0;

		for ( i = this.length - 1; i >= 0 ; i--){
			if (this.charAt(i) == ' ' ){
				j = j + 1
			}
			else{
				break;
			}
		}
		return 	this.substr(0, this.length - j);
	}
	String.prototype.Trim = function() {
		return this.replace(/\s/g, "");
	}

	function _cmdfocus(formobj){
		formobj.select();
		formobj.focus();
	}

// 전화번호 체크
function IsVaild_Phone(pPhoneName,optTF, pNumber1, pNumber2, pNumber3 ){
	pNumber2.value = pNumber2.value.Trim();
	pNumber3.value = pNumber3.value.Trim();
	strpNumber1      = pNumber1.options[pNumber1.selectedIndex].value;
	if (strpNumber1 != "" || pNumber2.value != "" ||  pNumber3.value != "" || optTF ==true) {
		if (strpNumber1 == "") {
			//alert (pPhoneName + "을 선택하세요.");
			alert ("Select the "+pPhoneName +".");
			pNumber1.focus();
			_cmdfocus(pNumber1);
			return false;
		}

		// 전화번호 validation checking
		if (pNumber2.value == "" ) {
			//alert (pPhoneName + "를 넣으세요.");
			alert("Enter the "+ pPhoneName +".");
			_cmdfocus(pNumber2);
			return false;
		} else if (!(pNumber2.value.IsNumber())) {
			//alert (pPhoneName + "는 숫자만 입력 가능 합니다.")
			alert ("Numeric characters are only allowed for input of the " + pPhoneName + ".");
			_cmdfocus(pNumber2);
			return false;
		} else if (pNumber2.value.length<2) {
			//alert (pPhoneName + "가 잘못되었습니다.")
			alert ("You have entered wrong " + pPhoneName + ".");
			_cmdfocus(pNumber2);
			return false;
		}

		if (pNumber3.value == "" ) {
			//alert (pPhoneName + "를 넣으세요.");
			alert("Enter the "+ pPhoneName +".");
			_cmdfocus(pNumber3);
			return false;
		} else if (!(pNumber3.value.IsNumber())) {
			//alert (pPhoneName + "는 숫자만 입력 가능 합니다.");
			alert ("Numeric characters are only allowed for input of the " + pPhoneName + ".");
			_cmdfocus(pNumber3);
			return false;
		} else if (pNumber3.value.length!=4) {
			//alert (pPhoneName + "가 잘못되었습니다.");
			alert ("You have entered wrong " + pPhoneName + ".");
			_cmdfocus(pNumber3);
			return false;
		}

	}
	return true;
}
// 전화번호 체크 (구내번호 포함)
function IsVaild_Phone2(pPhoneName,optTF, pNumber1, pNumber2, pNumber3, pNumber4 ){
	pNumber4.value = pNumber4.value.Trim();
	var bIsVaild=IsVaild_Phone(pPhoneName,optTF, pNumber1, pNumber2, pNumber3);
	if (pNumber4.value != "") {
		if (bIsVaild==true ){
	 		if (!(pNumber4.value.IsNumber())) {
				//alert (pPhoneName + "의 구내번호는 숫자만 입력 가능 합니다.");
				alert ("Numeric characters are only allowed for input of the extension number");
				_cmdfocus(pNumber4);
				return false;
			}
		}
	}
	return bIsVaild;
}

function GetRadioValue(opt) {
	var leng = ((isNaN(opt.length*1))?1:opt.length*1);

	if (leng == 1)
	{
			if (opt.checked)
			{
				return opt.value;
			}
	}
	else {
		var n = opt.length;
		for (i=0; i<n; i++) {
			if (opt[i].checked) {
				return opt[i].value;
			}
		}
	}
	return "";
}

	function Go_Next(curField, nextField) {
		if (curField.value.length >= curField.maxLength) {
			nextField.focus();
		}
	}

	function Go_Next2(curField, nextField, curLength){
		if (curField.value.length >= curLength){
			nextField.focus();
		}
	}

	//입력형식:"YYYY/MM/DD"(다른 형식은 에러입니다.)
	function DateDiff(FromDate, ToDate){
		var D1,D2,Diff;						//변수를 선언합니다.
		var MinMilli = 1000 * 60;			//변수를 초기화합니다.
		var HrMilli = MinMilli * 60;
		var DyMilli = HrMilli * 24;
		D1 = Date.parse(FromDate);			//구문 분석합니다.
		D2 = Date.parse(ToDate);			//구문 분석합니다.
		Diff = Math.round(Math.abs((D2-D1) / DyMilli))
		if (Diff>-1) {
			Diff= Diff + 1;
		} else {
			Diff= Diff - 1;
		}
		return(Diff);						//결과를 반환합니다.
	}

	function checkform(formField, checkName, message, maxlength, minlength) {

	//각 필드별 입력값 체크
	//주민등록시 반드시 값으로 넘긴다.
	//필수입력 check
	//글자수 check
	//field 유효성 check

	formValue = formField.value.LTrim().RTrim();

		if(checkName != 'jumin'){
			if (formField == null ) {
				return false;
			}

			if (formValue == '' && minlength > 0){
				//alert(message + " 필수입력 항목입니다.");
				alert(message + ' is mandatory item for input.');
				_cmdfocus(formField);
				return false;
			}

			if (formValue.StrLen() < minlength) {
				//alert(message + " 최소" + minlength + "자이상 입력하세요.");
				alert("The resident "+ message +" shall be longer than "+minlength+" digits.");
				_cmdfocus(formField);
				return false;
			}

			if (maxlength != -1)
			{
				if (formValue.StrLen() > maxlength) {
					//alert(message + " 최대" + maxlength + "자까지 입력 가능합니다.");
					alert("Enter the resident "+message+" up to "+maxlength+" digits.");
					_cmdfocus(formField);
					return false;
				}
			}
		}

		switch(checkName) {
			case "" :
				return true;
			case "alpha" :
				formField.value	 = 	formValue;
				if (formValue.IsAlpha()) {
					return true;
				} else {
					//alert(message + " 영문자만 입력 가능 합니다.");
					alert("English letters shall only be entered in the box of the " + message + ".");
					_cmdfocus(formField);
					return false;
				}
				break;
			case "number" :
				formField.value	 = 	formValue;
				if (formValue.IsNumber()) {
					return true;
				} else {
					//alert(message + " 숫자만 입력 가능 합니다.");
					alert("Numeric characters are only allowed for input of the " + message + ".");
					_cmdfocus(formField);
					return false;
				}
				break;
			case "id" :
				formField.value	 = 	formValue;
				if (formValue.IsId()) {
					return true;
				} else {
					//alert(message + " 영문자와 숫자만 입력 가능 합니다.");
					alert("English letters and numeric characters are only allowed for " + message + ".");
					_cmdfocus(formField);
					return false;
				}
				break;
			case "tel" :
				formField.value	 = 	formValue;
				if (formValue.IsTel()) {
					return true;
				} else {
					//alert(message + " 숫자와 - 만 입력 가능합니다.");
					alert("Numeric characters and - are only for "+ message + ".");
					_cmdfocus(formField);
					return false;
				}
				break;
			case "email" :
				formField.value	 = 	formValue;
				if (formValue.IsEmail()) {
					return true;
				} else {
					//alert(message + " 이메일 형식이 틀립니다. 다시 입력해 주세요(형식: account@localhost.com");
					alert("You have entered wrong e-mail format. Please enter right format (format: account@localhost.com).");
					_cmdfocus(formField);
					return false;
				}
				break;
			case "date" :
				if (formValue.IsDate()) {
					return true;
				} else {
					//alert(message + " 날짜 형식이 틀립니다. 다시 입력해 주세요(형식: 1999.09.09)");
					alert("You have entered wrong date format. Please enter right format (format: 1999.09.09).");
					_cmdfocus(formField);
					return false;
				}
				break;
			case "jumin" :
				if(formValue.StrLen() != 13){
					alert("Please correct resident registration number.");
					return false
				}

				if (formValue.IsJumin()) {
					return true;
				} else {
					alert("Please correct resident registration number.");
					return false;
				}
				break;
		}
	}

function chkdate(cmbYear, cmbMonth, cmbDay){
	var selectmonth = cmbMonth.selectedIndex;
	var monthday, i;
	selectmonth = selectmonth + 1;

	// 평년일때 날자처리
	if (selectmonth == 1) monthday = 31;
	if (selectmonth == 3) monthday = 31;
	if (selectmonth == 4) monthday = 30;
	if (selectmonth == 5) monthday = 31;
	if (selectmonth == 6) monthday = 30;
	if (selectmonth == 7) monthday = 31;
	if (selectmonth == 8) monthday = 31;
	if (selectmonth == 9) monthday = 30;
	if (selectmonth == 10) monthday = 31;
	if (selectmonth == 11) monthday = 30;
	if (selectmonth == 12) monthday = 31;
	if (selectmonth == 13) monthday = 30;

	// 윤년처리
	if(selectmonth == 2) {
		var y = cmbYear.value;
		//윤년
		if ((y % 4) == 0) {
			//평년
			if ((y % 100) == 0) {
				//윤년
				if ((y % 400) == 0) {
					monthday = 29;
				}
				//평년
				else {
					monthday = 28;
				}
			}
			//윤년
			else {
				monthday = 29;
			}
		}
		//평년
		else {
			monthday = 28;
		}
	}
	cmbDay.length = monthday;
	for(i=0 ; i < monthday ;i++) {
		if (i < 9) {
			var option = new Option(i+1,'0'+(i+1));
			}
		else {
			var option = new Option(i+1, i+1);
			}
		cmbDay.options[i] = option;
	}
	return true;
}





/*◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆*/
/*
Input값 형식
	url		:   연결할 페이지
	Width		:   브라우저의 너비					숫자만 입력하세요(500=>○, '500'=>Ｘ,"500"=>Ｘ)
	Height		:   브라우저의 높이					숫자만 입력하세요(500=>○, '500'=>Ｘ,"500"=>Ｘ)
	Center		:   브라우저의 가운데 여부			true or false
	Toolbar		:   브라우저의 툴바 표시여부		yes or no
	Resizable	:   브라우저의 사이즈 조정 가능여부 yes or no
	Scrollbars	:   브라우저의 스크롤바 표시여부	yes or no
	Left		:   브라우저의 왼쪽 위치			숫자만 입력하세요(10=>○, '10'=>Ｘ,"10"=>Ｘ)
	Top			:   브라우저의 윗쪽 위치			숫자만 입력하세요(10=>○, '10'=>Ｘ,"10"=>Ｘ)
*/
//openWin:PopUp창을 띄우는 함수로 툴바,사이즈변화,스크롤바 없는 창입니다.)
function openWin(url,Width,Height,Center) {
	if (Center==true){
	  	window.open(url, "", "toolbar=no,resizable=no,scrollbars=no,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
	}
	else {
		window.open(url, "", "toolbar=no,resizable=no,scrollbars=no,width=" + Width + ",height=" + Height + ",left=0,top=0");
	}
}
//openWin_All:PopUp창을 띄우는 함수로 툴바,사이즈변화,스크롤바 포함하는 창입니다.)
function openWin_All(url,Width,Height,Center) {
	if (Center==true){
	  	window.open(url, "", "toolbar=yes,resizable=yes,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
	}
	else {
		window.open(url, "", "toolbar=yes,resizable=yes,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=0,top=0");
	}
}
//openWin_Toolbar:PopUp창을 띄우는 함수로 툴바만 창입니다.)
function openWin_Toolbar(url,Width,Height,Center) {
	if (Center==true){
	  	window.open(url, "", "toolbar=yes,resizable=no,scrollbars=no,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
	}
	else {
		window.open(url, "", "toolbar=yes,resizable=no,scrollbars=no,width=" + Width + ",height=" + Height + ",left=0,top=0");
	}
}
//openWin_Resizable:PopUp창을 띄우는 함수로 사이즈를 변경가능한 창입니다.)
function openWin_Resizable(url,Width,Height,Center) {
	if (Center==true){
	  	window.open(url, "", "toolbar=no,resizable=yes,scrollbars=no,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
	}
	else {
		window.open(url, "", "toolbar=no,resizable=yes,scrollbars=no,width=" + Width + ",height=" + Height + ",left=0,top=0");
	}
}
//openWin_Scrollbars:PopUp창을 띄우는 함수로 스크롤바가 있는 창입니다.)
function openWin_Scrollbars(url,Width,Height,Center) {
	if (Center==true){
	  	window.open(url, "", "toolbar=no,resizable=no,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
	}
	else {
		window.open(url, "", "toolbar=no,resizable=no,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=0,top=0");
	}
}
//openWin_Scrollbars:PopUp창을 띄우는 함수로 스크롤바가 있는 창입니다.)
function openWin_R_S(url,Width,Height,Center) {
	if (Center==true){
	  	window.open(url, "", "toolbar=no,resizable=yes,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=" + (window.screen.width/2-Width) + ",top=" + (window.screen.height/2-Height));
	}
	else {
		window.open(url, "", "toolbar=no,resizable=yes,scrollbars=yes,width=" + Width + ",height=" + Height + ",left=0,top=0");
	}
}
//openWin_Scrollbars:PopUp창을 띄우는 함수로 툴바,사이즈변화,스크롤바등을 모든 값을 정의하는 창입니다.)
function openWin_definition(url,Center,Toolbar,Resizable,Scrollbars,Width,Height,Left,Top) {
 	window.open(url, "", "toolbar=" + Toolbar+ ",resizable=" + Resizable + ",scrollbars=" + Scrollbars + ",width=" + Width + ",height=" + Height + ",left=" + Left + ",top=" + Top);
}



function ShowObject(ME_COMMENT) {
	document.write(ME_COMMENT.text);
	ME_COMMENT.id = "";
}

//-->

