// 빈값 검사 (메세지 출력 / 공백을 제외하고 빈값이면 true 아니면 false)
function chkBlank_msg(box, msg) {
	var valid = box.value.replace(/\s/gi,"");
	if (valid=="") {
		if (!msg) msg = "빈 값입니다. 값을 입력하세요.";
		alert(msg); box.focus();
		return true;
	}
	return false;
}

// 팝업창 띄우기
var _pop //create global variable without assigning a value so that its value is null
function popen(url,name,w,h,scroll,pos,res) { // (경로,이름,가로,세로,스크롤유무,위치,리사이즈)

	if (!scroll) scroll = 1;
	if (!pos) pos = "center";
	if (!res) res = 0;

	switch (pos) {
		case 'center' :
			LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
			TopPosition = (screen.height) ? (screen.height - h - 100) / 2 : 100;
			break;
		case "random" :
			LeftPosition = (screen.width) ? Math.floor(Math.random() * (screen.width - w)) : 100;
			TopPosition = (screen.height) ? Math.floor(Math.random() * ((screen.height - h) - 75)) : 100;
			break;
		default :
			LeftPosition=0;
			TopPosition=0;
			break;
	}

	var settings = 'width=' + w + ', height=' + h + ', top=' + TopPosition + ', left=' + LeftPosition + ', scrollbars=' + scroll;
	settings += ', location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=' + res;

	if(_pop!=null && !_pop.closed) {
		_pop.close();
	}

	pop = window.open(url, name, settings);
	pop.focus();
}


// 컨펌메세지 출력 후 이동
function conf_url(msg,murl) {
	if(confirm(msg)) window.location = murl;
}


// 리스트 함수
var marked_row = new Array;

function tableRowsInit()
{
	var rows = document.getElementsByTagName('tr');

	for ( var i = 0; i < rows.length; i++ )
	{
		if ( 'odd' != rows[i].className.substr(0,3) && 'even' != rows[i].className.substr(0,4) ) {
			continue;
		}
		if ( navigator.appName == 'Microsoft Internet Explorer' && (navigator.userAgent.indexOf('MSIE 6') != -1 || navigator.appVersion.indexOf("MSIE 7.0")>=0) ) {
			// but only for IE, other browsers are handled by :hover in css
			rows[i].onmouseover = function() {
				this.className += ' hover';
			}
			rows[i].onmouseout = function() {
				this.className = this.className.replace( ' hover', '' );
			}
		}

		// ... and to mark the row on click ...
		rows[i].onmousedown = function() {
			var unique_id;
			var checkbox;

			checkbox = this.getElementsByTagName( 'input' )[0];
			if ( checkbox && checkbox.type == 'checkbox' ) {
				 unique_id = checkbox.name + checkbox.value;
			} else if ( this.id.length > 0 ) {
				 unique_id = this.id;
			} else {
				 return;
			}

			if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
				 marked_row[unique_id] = true;
			} else {
				 marked_row[unique_id] = false;
			}

			if ( marked_row[unique_id] ) {
				 this.className += ' marked';
			} else {
				 this.className = this.className.replace(' marked', '');
			}

			if ( checkbox && checkbox.disabled == false ) {
				 checkbox.checked = marked_row[unique_id];
			}
		}

		// .. and checkbox clicks
		var checkbox = rows[i].getElementsByTagName('input')[0];
		if ( checkbox ) {
			checkbox.onclick = function() {
				 // opera does not recognize return false;
				 this.checked = ! this.checked;
			}
		}
	}
}


// tagName으로 Parent Object 얻기 - 2007-08-25 By Hss
function findParentObjByTagName(o, tag)
{
	tag = tag.toUpperCase();
	if (typeof(o) != "object") return null;
	if (o.parentNode == null) return null;
	if (o.parentNode.tagName == "undefined") return null;
	return (o.parentNode.tagName == tag) ? o.parentNode : findParentObjByTagName(o.parentNode, tag);
}

// 게시물 전체선택
function CheckAll(o, tag)
{
	var flag = o.checked;
	var obj = findParentObjByTagName(o, tag);
	if (typeof(obj)=="object")
	{
		if (flag) {
			markAllRows(obj);
		} else {
			unMarkAllRows(obj);
		}
	}
}

/** from phpMyAdmin
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function markAllRows( obj ) {
	var rows = obj.getElementsByTagName('tr');
	var unique_id;
	var checkbox;
	for ( var i = 1; i < rows.length; i++ )
	{
		checkbox = rows[i].getElementsByTagName( 'input' )[0];
		if ( checkbox && checkbox.type == 'checkbox' )
		{
			unique_id = checkbox.name + checkbox.value;
			if ( checkbox.disabled == false )
			{
				checkbox.checked = true;
				if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] )
				{
					rows[i].className += ' marked';
					marked_row[unique_id] = true;
				}
			}
		}
	}
}

/** from phpMyAdmin
 * marks all rows and selects its first checkbox inside the given element
 * the given element is usaly a table or a div containing the table or tables
 *
 * @param    container    DOM element
 */
function unMarkAllRows( obj ) {
	var rows = obj.getElementsByTagName('tr');
	var unique_id;
	var checkbox;
	for ( var i = 1; i < rows.length; i++ )
	{
		checkbox = rows[i].getElementsByTagName( 'input' )[0];
		if ( checkbox && checkbox.type == 'checkbox' )
		{
			unique_id = checkbox.name + checkbox.value;
			checkbox.checked = false;
			rows[i].className = rows[i].className.replace(' marked', '');
			marked_row[unique_id] = false;
		}
	}
}