<!--
//==================================================================================================
//■Program Name	: 공통 자바스크립트 함수 모음
//■File	 Name	: /Class/Comm_Js.js
//■Description		: 공통 자바스크립트 함수 모음
//■Etc				: 
//==================================================================================================
//※History
//==================================================================================================
//Number		Date				Author		Version			Description
//==================================================================================================
//	1			2005-06-08			정미상		1.0
//==================================================================================================

//--------------------------------------------------------------------------------------------------
// Form체크를 위한 함수
//--------------------------------------------------------------------------------------------------
	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() {
		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 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 + " 필수입력 항목입니다.");
				_cmdfocus(formField);
				return false;
			}

			if (formValue.StrLen() < minlength) {
				alert(message + " 최소" + minlength + "자이상 입력하세요.");
				_cmdfocus(formField);
				return false;
			}

			if (formValue.StrLen() > maxlength) {
				alert(message + " 최대" + maxlength + "자(한글" + maxlength/2 + " 자)까지 입력 가능합니다.");
				_cmdfocus(formField);
				return false;
			}
		}		

		switch(checkName) {
			case "" :
				return true;
			case "alpha" :
				if (formValue.IsAlpha()) {
					return true;
				} else {
					alert(message + " 영문자만 입력 가능 합니다.");
					_cmdfocus(formField);
					return false;
				}
				break;
			case "number" :

				if (formValue.IsNumber()) {
					return true;
				} else {
					alert(message + " 숫자만 입력 가능 합니다.");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "id" :
				if (formValue.IsId()) {
					return true;
				} else {
					alert(message + " 영문자와 숫자만 입력 가능 합니다.");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "tel" :
				if (formValue.IsTel()) {
					return true;
				} else {
					alert(message + " 숫자와 - 만 입력 가능합니다.");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "email" :
				if (formValue.IsEmail()) {
					return true;
				} else {
					alert(message + " 이메일 형식이 틀립니다. 다시 입력해 주세요(형식: account@localhost.com");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "date" :
				if (formValue.IsDate()) {
					return true;
				} else {
					alert(message + " 날짜 형식이 틀립니다. 다시 입력해 주세요(형식: 1999.09.09)");
					_cmdfocus(formField);		
					return false;
				}
				break;
			case "jumin" :
				if(formValue.StrLen() != 13){
					alert("주민등록번호를 정확히 입력해주세요");
					return false
				}

				if (formValue.IsJumin()) {
					return true;
				} else {
					alert("주민등록번호를 정확히 입력해주세요");
					return false;
				}
				break;
		}
	}

//--------------------------------------------------------------------------------------------------
// Form focus
//--------------------------------------------------------------------------------------------------
	function _cmdfocus(formobj){
		formobj.select();
		formobj.focus();
	}

//--------------------------------------------------------------------------------------------------
// Next Form 필드
//--------------------------------------------------------------------------------------------------
	function Go_Next(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 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;
	}	
//--------------------------------------------------------------------------------------------------
// 라디오 박스 체크
//--------------------------------------------------------------------------------------------------
	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 GetCheckValue(opt) {		
		var leng = ((isNaN(opt.length*1))?1:opt.length*1);
		var chkcnt = 0;
		if (leng == 1)
		{
				if (opt.checked)
				{
					chkcnt = 1;
				}
		}
		else {
			var n = opt.length;			
			for (i=0; i<n; i++) {
				if (opt[i].checked) {					
					chkcnt = chkcnt + 1;
				}
			}
		}
		return chkcnt;
	}


//--------------------------------------------------------------------------------------------------
// 마퀴를 멈추게 하는 부분
//--------------------------------------------------------------------------------------------------
function MStop(chk)	
{  
	Toggle = 0;  
	switch(chk) {
    	case 1:
    	ex_marquee.stop(); // ID부분.stop();

    	break;
    	case 2:
    	mq_topic.stop();
    	break;
	}    
}
//--------------------------------------------------------------------------------------------------
// 이미 멈춰진 마퀴를 다시 움직이게 하는 소스
//--------------------------------------------------------------------------------------------------
function MStart(chk)	
{  
	Toggle = 1;  
	switch(chk) {
 	case 1:
    	ex_marquee.start(); // ID부분.start();
    	break;
    	case 2:
    	mq_topic.start();
    	break;
	}    
}
//--------------------------------------------------------------------------------------------------
// 마퀴를 좌우로 움직이는 스크립트
//--------------------------------------------------------------------------------------------------
function MStart2(chk)	
{  
	Toggle = 1;  

	switch(chk) {
 	case 1:
    	//ex_marquee.direction.value="left";
		ex_marquee.start(); // ID부분.start();
		ex_marquee.direction="left";

		
    	break;
    case 2:
		ex_marquee.start(); // ID부분.start();
		ex_marquee.direction="right";
		break;
	}    
}

function na_call(str)
{
eval(str);
}

//플래쉬 메뉴 MS에서 바뀌는 것 처리	2006년 4월 12일 부로 바뀜

function ShowObject(ME_COMMENT) {
	document.write(ME_COMMENT.text);
	ME_COMMENT.id = "";
}

//웹북팝업
function webbook()
{
	window.open("/comGlobal/webbook/m3500_new/view.htm","","scrollbars=no,width=806,height=711,left=150,top=10");
}

//-->

//웹진팝업
function webzine()
{
	window.open("http://pr.ceragem.net/2008_Photo_Contest/index.html","","scrollbars=no,width=962,height=690,left=10,top=10");
}

//-->
