var DYNIFS = {
		// Storage for known IFrames.
		iframes: {},
		// Here we save any previously installed onresize handler.
		oldresize: null,
		// Flag that tell us if we have already installed our onresize handler.
		ready: false,
		// The document dimensions last time onresize was executed.
		dim: [-1,-1],
		// Timer ID used to defer the actual resize action.
		timerID: 0,
		// Obtain the dimensions (width,height) of the given document.
		getDim: function(d) {
			var w=200, h=200, scr_h, off_h;
			if( d.height ) { return [d.width,d.height]; }
			with( d.body ) {
				if( scrollHeight ) { h=scr_h=scrollHeight; w=scrollWidth; }
				if( offsetHeight ) { h=off_h=offsetHeight; w=offsetWidth; }
				if( scr_h && off_h ) h=Math.max(scr_h, off_h);
			}
			return [w,h];
		},
		// This is our window.onresize handler.
		onresize: function() {
			// Invoke any previously installed onresize handler.
			if( typeof this.oldresize == 'function' ) { this.oldresize(); }
			// Check if the document dimensions really changed.
			var dim = this.getDim(document);
			if( this.dim[0] == dim[0] && this.dim[1] == dim[1] ) return;
			// Defer the resize action to prevent endless loop in quirksmode.
			if( this.timerID ) return;
			this.timerID = setTimeout('DYNIFS.deferred_resize();', 10);
		},
		// This is where the actual IFrame resize is invoked.
		deferred_resize: function() {
			// Walk the list of known IFrames to see if they need to be resized.
			for( var id in this.iframes ) this.resize(id);
			// Store resulting document dimensions.
			this.dim = this.getDim(document);
			// Clear the timer flag.
			this.timerID = 0;
		},
		// This is invoked when the IFrame is loaded or when the main window is resized.
		resize: function(id) {
			// Browser compatibility check.
			if( !window.frames || !window.frames[id] || !document.getElementById || !document.body )
				return;
			// Get references to the IFrame window and layer.
			var iframe = window.frames[id];
			var div = document.getElementById(id);
			if( !div ) return;
			// Save the IFrame id for later use in our onresize handler.
			if( !this.iframes[id] ) {
				this.iframes[id] = true;
			}
			// Should we inject our onresize event handler?
			if( !this.ready ) {
				this.ready = true;
				this.oldresize = window.onresize;
				window.onresize = new Function('DYNIFS.onresize();');
			}
			// This appears to be necessary in MSIE to compute the height
			// when the IFrame'd document is in quirksmode.
			// OTOH, it doesn't seem to break anything in standards mode, so...
			if( document.all ) div.style.height = '0px';
			// Resize the IFrame container.
			var dim = this.getDim(iframe.document);
			div.style.height = (dim[1]+30) + 'px';
		}
	};

function checkComment(obj,obj2){
	if(getByteLen(obj.value) > 1000){
		alert('덧글은 1000byte 이하로 작성해주세요.');
		obj.value = strCut(obj.value, 1000);
		return;
	}
	obj2.value = getByteLen(obj.value);
}

function checkTextLength(obj){
	if(getByteLen(obj.value) > 200){
		alert('200Byte 이하로 입력해주세요.');
		obj.value = strCut(obj.value, 200);
		return;
	}
}

//바이트 구하기
function getByteLen(str){
       return(str.length+(escape(str)+"%u").match(/%u/g).length-1);
}


//글자수 잘라내기
function strCut(message, maximum){
	var inc = 0;
	var nbytes = 0;
	var msg = "";
	var msglen = message.length;
	
	for (i=0; i<msglen; i++) {
		var ch = message.charAt(i);
		
		if (escape(ch).length > 4) {
			inc = 2;
		}
		else if (ch == '\n') {
			if (message.charAt(i-1) != '\r') {
				inc = 1;
			}
		}
		else if (ch == '<' || ch == '>') {
			inc = 4;
		}
		else {
			inc = 1;
		}
		
		if ((nbytes + inc) > maximum) {
			break;
		}
		nbytes += inc;
		msg += ch;
	}
	
	return msg;
}

// 게시판 파일 리스트 팝업 
function filePopup(bbsSeq,seq) {
	window.open('filePopup.fs?bbsSeq='+bbsSeq+'&seq='+seq,'','width=387px,height=249px,scrollbars=yes');
}

//입력사항체크
function chkText(field,text,msg){
	text = text.replace("　", "");
	text = text.replace(/\s*/, "");
	if (text==""){
		var caption = field.parentNode.parentNode.firstChild.innerText;
		if (!field.getAttribute("label")) field.setAttribute("label",(caption)?caption:field.name);
		if (!msg) msg = "[" + field.getAttribute("label") + "] 필수입력사항";
		//if (msg) msg2 += "\n\n" + msg;
		alert(msg);
		if (field.tagName!="SELECT") field.value = ""; 
		if (field.type!="hidden" && field.style.display!="none") field.focus();
		return false;
	}
	return true;
}


//주민등록번호 체크
function chkResno(getValue, checkMode){
	var resno = getValue;
			
	birthYear = (resno.charAt(6) <= '2') ? '19' : '20';
	birthYear += resno.substr(0, 2);
	birthMonth = resno.substr(2, 2) - 1;
	birthDate = resno.substr(4, 2);
	birth = new Date(birthYear, birthMonth, birthDate);

	if ( birth.getYear()%100 != resno.substr(0, 2) || birth.getMonth() != birthMonth || birth.getDate() != birthDate) {
		alert('잘못된 주민등록번호입니다.');
		return false;
	}
	
	if(checkMode == "2"){
		fmt = /^\d{6}[1234]\d{6}$/;
		if (!fmt.test(resno)) {
			alert('잘못된 주민등록번호입니다.'); return false;
		}	
	
		buf = new Array(13);
		for (i = 0; i < 13; i++) buf[i] = parseInt(resno.charAt(i));
	
		multipliers = [2,3,4,5,6,7,8,9,2,3,4,5];
		for (i = 0, sum = 0; i < 12; i++) sum += (buf[i] *= multipliers[i]);
	
		if ((11 - (sum % 11)) % 10 != buf[12]) {
			alert('잘못된 주민등록번호입니다.');
			return false;
		}
	}
	
	return true;
}

//숫자 체크
function checkNumber( obj ) {

	var regExpr2 = /^[0-9]+$/;	
	if ( obj.value.length > 0 && !regExpr2.test( obj.value ) ) {
		alert( "숫자만 입력가능합니다" );
		obj.value = '';
		obj.focus();
		return false;
    }
	
	return true;
}

//숫자 체크
function checkNumberToZero( obj ) {

	var regExpr2 = /^[0-9]+$/;	
	if ( obj.value.length > 0 && !regExpr2.test( obj.value ) ) {
		alert( "숫자만 입력가능합니다" );
		obj.value = '0';
		obj.focus();
		return false;
    }
	
	return true;
}

/**
 * 공백제거
 * @param str
 * @return
 */
function trim (str) {    
	str = str.replace(/^\s+/, '');     
	for (var i = str.length - 1; i > 0; i--) {         
		if (/\S/.test(str.charAt(i))) {            
			str = str.substring(0, i + 1);            
			break;        
		}     
	}    
	return str; 
}

/**
 * 한글 체크
 * @param obj
 * @return
 */
function korCheck(obj) {
	var chkStr = trim(obj.value);
	for(i=0; i<chkStr.length; i++ ){
		var a = chkStr.charCodeAt(i);
		if(a > 128) {
			alert("한글을 입력 할 수 없습니다.");
			obj.value = "";
			obj.focus();
			break;
		}
	}
	return true;
}

/**라디오버튼 체크확인*/
function chkRadio(msg) {
	var obj = document.getElementsByTagName("input");
	var radios = new Array();
	var idx = 0;
	for(var i=0; i<obj.length; i++){
		if(obj[i].type == 'radio')
			radios[idx++] = obj[i];
	}
	var cnt=0;

	for(i=0; i<radios.length;i++)	{
		if(radios[i].checked==true){
			cnt++;
		}
	}

	if(cnt==0){
		alert(msg);
		return false;
	}
	return true;
}
function right(e) { 
	if (navigator.appName == 'Netscape' && (e.which == 3 || e.which == 2)) 
		return false; 
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button == 2 || event.button == 3)) { 
		alert("오른쪽 마우스 버튼을 사용할수 없습니다");
		return false; 
	} 
	return true; 
} 
//document.onmousedown=right; 
