// 입력값 공백 체크 함수
function isEmpty( data ){
	for ( var i = 0 ; i < data.length ; i++ ){
		if ( data.substring( i, i+1 ) != " " ) {
			return false;
		}
	}
	return true;
}
//메뉴 Show,Hide
function showhide(what){
	if (what.style.display=='none'){
		what.style.display='';
	}
	else{
		what.style.display='none';
	}
}

//전광판 보기
function PopupSignboard(uid){
	var url = uid;
	window.open(url,'','width=730 height=400 resizable=1 scrollbars=1');
}

//원본 이미지 보기
function ViewOriginImg(img_url){
	var url = "/app/realsize_img.php?url="+img_url;
	window.open(url,'','width=5 height=5 resizable=1 scrollbars=1');
}

function goSelectUrl(form) {
	if(form.url.selectedIndex != -1)
	self.window.open(form.url.options[form.url.selectedIndex].value, target="_self");
}


// wrapper for alert function
function Alert(msg) {
	if (window.showModalDialog) {
		window.showModalDialog('/skin/popup_alert.html', msg, 'dialogHeight:154px;dialogWidth:406px;center:yes;help:no;resizable:no;status:no');
	} else {
		alert(msg);
	}
}

// wrapper for confirm function
function Confirm(msg) {
	if (window.showModalDialog) {
		return window.showModalDialog('/skin/popup_confirm.html', msg, 'dialogHeight:154px;dialogWidth:406px;center:yes;help:no;resizable:no;status:no');
	} else {
		return confirm(msg);
	}
}

// get ajax root element
function getAjaxRoot(req) {
	try { var root = req.responseXML.documentElement; }
	catch(e) {
		alert(req.responseText);
		return null;
	}

	if (/Gecko/.test(navigator.userAgent)) {
		Element.cleanWhitespace(root);
	}

	if (root.getAttribute('result') != 'true') {
		try {
			Alert(root.getElementsByTagName('message')[0].childNodes[0].nodeValue);
		} catch(e) {
			alert(req.responseText);
		}
		return null;
	}

	return root;
}

// tree menu
var Tree = {
	toggle : function(obj) {
		var sub = obj.nextSibling;

		while (sub.nodeType != 1) sub = sub.nextSibling;

		if (sub.style.display == 'block') {
			if (/_open/.test(obj.className)) obj.className = obj.className.replace(/_open/, '_close');
			sub.style.display = 'none';
		} else {
			if (/_close/.test(obj.className)) obj.className = obj.className.replace(/_close/, '_open');
			sub.style.display = 'block';
		}
	}
}

// popup window
function modelessWindow(url, name, width, height)
{
	if (window.showModelessDialog) {
		window.showModelessDialog(url, window, 'dialogWidth:'+width+'px;dialogHeight:'+(height+35)+'px;center:yes;resizable:no');
	} else {
		var t = Math.floor((screen.height - 30 - height) / 2);
		var l = Math.floor((screen.width - width) / 2);
		var win = window.open(url, name, 'height='+height+',width='+width+',top='+t+',left='+l+',toolbar=no,directories=no,status=no,linemenubar=no,scrollbars=no,resizable=no,modal=yes,dependent=yes');
		try { win.focus() } catch(e) { Alert('팝업창을 허용해주세요.'); }
	}
}

// embed media
function mediashow(type,link,width,height) {
	if (width) width = ' width="'+width+'"';
	else width = '';
		
	if (height) height = ' height="'+height+'"';
	else height = '';

	switch (type) {
		case 'flash':
			str = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" '+width+height+'"><param name="movie" value="'+link+'" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="'+link+'" quality="high" wmode="transparent"  pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" '+width+height+'"></embed></object>';
			break;
		default:
			str = '<embed src="'+link+'" '+width+height+'"></embed>';
			break;
	}

	document.write(str);
}

// auto link
function autolink(str) {
	//var reg = new RegExp('\[(([a-z0-9.]+){2,4}\/?(.*))\|(.+)\]|((www\.|http:\/\/)[ "-~])', 'gi');
	var reg = /(http:\/\/[\x22-\x7E]+)/gmi;

	str = str.replace(reg, '<a href="$1" target="_blank">$1</a>');

	return str;
}

// popupNick
var popupNick = {
	menuObj : null,
	items : [],
	init : function() {
		if (this.menuObj != null) return true;

		this.menuObj = document.createElement('DIV');
		Element.setStyle(this.menuObj, {
			border   : '1px solid #CCCCCC',
			padding  : '1px',
			position : 'absolute',
			display  : 'none',
			backgroundColor : 'white'
		});

		document.body.appendChild(this.menuObj);

		// append items
		for(var i=0; i < this.items.length; i++) {
			this.menuObj.appendChild(this.items[i]);
		}
    },
	show : function(obj,id) {
		this.init();
		var pos = Position.cumulativeOffset(obj);
		var old_top = parseInt(this.menuObj.style.top);

		this.menuObj.style.top  = (pos[1]+obj.offsetHeight)+'px';
		this.menuObj.style.left = pos[0]+'px';

		if (old_top == pos[1]+obj.offsetHeight) $(this.menuObj).toggle();
		else $(this.menuObj).show();
		popupNick.id = id;
	},
	hide : function() {
		this.init();
		$(this.menuObj).hide();
	},
	addItem : function(caption, func) {
		var item = document.createElement('DIV');
		item.appendChild(document.createTextNode(caption));
		item.onclick = function() { func(popupNick.id); popupNick.hide(); };
		item.onmouseover = function() { this.style.backgroundColor = '#EDEDED'; }
		item.onmouseout = function() { this.style.backgroundColor = ''; }
		Element.setStyle(item, {
			fontSize : '8pt',
			fontFamily : '돋움',
			cursor  : 'pointer',
			padding : '1px 5px'
		});

		this.items.push(item);
	},
	removeItem : function(idx) {
	}
}