var BrowserIsMSIE = 0;
var agent = navigator.userAgent;
if( agent.indexOf("MSIE") > 0 ) BrowserIsMSIE = 1;


// Get Object by ID
function getObject( objectId ) { 
	// checkW3C DOM, then MSIE 4, then NN 4. 
	if( document.getElementById && document.getElementById(objectId) ) {
		return document.getElementById(objectId); 
	} else if (document.all && document.all(objectId)) { 
		return document.all(objectId); 
	} else if (document.layers && document.layers[objectId]) { 
		return document.layers[objectId]; 
	} else {
		return false; 
	}
}

function moveTop() {
	window.scrollTo(0,0);
}

function resizeToBodyDlg(iWidth, iHeight) {
	window.dialogWidth = iWidth + "px";
	window.dialogHeight = iHeight + "px";

	window.dialogWidth = (iWidth * 2 - document.body.clientWidth) + "px";
	window.dialogHeight = (iHeight * 2 - document.body.clientHeight) + "px";
}

function trim (strSource) {
	re = /^[\s¡¡]+|[\s¡¡]+$/g;

	return strSource.replace(re, '');
}

function ltrim (strSource) {
	re = /^[\s¡¡]+/g;

	return strSource.replace(re, '');
}

function rtrim (strSource) {
	re = /[\s¡¡]+$/g;

	return strSource.replace(re, '');
}


// ¸Þ´º°ü·Ã
var strCurrMenu = "";
function MenuGo( strUrl, strID ) {
	strMenuName = "";
	if( strCurrMenu.length > 3 ) {
		strMenuName = getObject(strCurrMenu).innerHTML;
		strMenuName = strMenuName.replace("<B><U>", "");
		strMenuName = strMenuName.replace("</U></B>", "");
		strMenuName = strMenuName.replace("<b><u>", "");
		strMenuName = strMenuName.replace("</u></b>", "");
		getObject(strCurrMenu).innerHTML = strMenuName;
	}
	if( strID.length > 3 ) {
		getObject(strID).innerHTML = "<b><u>" + getObject(strID).innerHTML + "</u></b>";
		strCurrMenu = strID;
	}
	if( strUrl.length > 0 ) {
		if( strID=="mn_00" ) 
			document.location.href = strUrl;
		else {
			moveTop();
			getObject("ifMain").src = strUrl;
		}
	}
}


// ·Î±×ÀÎ&·Î±×¾Æ¿ô ÈÄ¿¡ ÀüÃ¼ ÆäÀÌÁö »õ·Î ÀÐ±â
function AfterLoginLogout() {
	var strMainSrc = getObject("ifMain").src;
	if( isCT == 'Y' ) 
		document.location.href = '/main.php?cartoon=Y&menu=' + escape(strMainSrc);
	else
		document.location.href = '/main.php?menu=' + escape(strMainSrc);
}


function pop_win_sbar(url, winname, width, height, left, top)	{
	if( left>=0 || top>=0 ) 
		window.open(url, winname, "left=" + left + ",top=" + top + ",scrollbars=yes,fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,width=" + width + ",height=" + height);
	else {
//		window.open(url, winname, "left =" + (screen.availWidth-width)/2 + ",top=" + (screen.availHeight-height)/2 + ",fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,width=" + width + ",height=" + height);
		var w_left = window.screenLeft;
		var w_width = parent.document.body.clientWidth;
		var w_top = window.screenTop;
		var w_height = parent.document.body.clientHeight;
		left = (w_width-width)/2+w_left/2;
		top = (w_height-height)/2+w_top/2;

		window.open(url, winname, "left =" + left + ",top=" + top + ",scrollbars=yes,fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,width=" + width + ",height=" + height);

	}
}

function pop_win(url, winname, width, height, left, top)	{
	if( left>=0 || top>=0 ) 
		window.open(url, winname, "left=" + left + ",top=" + top + ",fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,width=" + width + ",height=" + height);
	else {
//		window.open(url, winname, "left =" + (screen.availWidth-width)/2 + ",top=" + (screen.availHeight-height)/2 + ",fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,width=" + width + ",height=" + height);
		var w_left = window.screenLeft;
		var w_width = parent.document.body.clientWidth;
		var w_top = window.screenTop;
		var w_height = parent.document.body.clientHeight;
		left = (w_width-width)/2+w_left/2;
		top = (w_height-height)/2+w_top/2 - 100;

		window.open(url, winname, "left =" + left + ",top=" + top + ",fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,width=" + width + ",height=" + height);

	}
}

function pop_memo(url, winname, width, height, cnt) {
	if( cnt<=4 ) {
		pop_win(url, winname, width, height, -1, -1);
	} else {
		pop_win(url, winname, width, height, 200, 100);
	}
}

function isNumber(val)
{
	var charSet = "0123456789"
	var ReturnCount = 0
	for (var i=0;i<val.length;i++) {
		if (charSet.indexOf(val.substring(i, i+1)) < 0 )
			ReturnCount++;
	}
	
	return (ReturnCount == 0);
}


function ErrHandle( errno )	{
	var imgurl = getObject("img"+errno);
	imgurl.src = "/images/1by1.gif";
	imgurl.border = imgurl.width = imgurl.height = 0;
	if( errno == 1 )	{
		getObject("errmsg").style.display = "";
		getObject("pn2").style.display = "none";
	}
}

function setEditMode(sMode) {
	//getObject("editBox").editmode = sMode;
	put_editmode(sMode);
}

var durlCnt = 0;
function copy_clipboard(strContentURL)
{
    var doc = document.body.createTextRange();
    doc.moveToElementText(document.getElementById(strContentURL));
    doc.select();
    doc.execCommand('copy');
	getObject("durl").style.visibility="visible";
	copy_clipboard_hidden();
}

function copy_clipboard_hidden() {
	if( durlCnt < 2 ) {
		durlCnt++;
		chid = setTimeout("copy_clipboard_hidden()", 1000);
	} else {
		getObject("durl").style.visibility="hidden"; 
		clearTimeout( chid );
		durlCnt = 0;
	}
}

function ViewTravel( no, loc, pmemo ) {
	var width = 1024;
	var w_left = window.screenLeft;
	var w_width = parent.document.body.clientWidth;
	var w_top = window.screenTop;
	if ( w_top < 0 ) w_top = 0;
	var w_height = parent.document.body.clientHeight;
	if( w_width < width ) 
		left = w_left/2;
	else
		left = (w_width-width)/2+w_left/2;
	height = w_height + w_top/2;
	if( pmemo=='Y' )
		window.open('/travel/view.php?no='+no+'&loc='+loc+'#PMEMO', 'travel', "left =" + left + ",top=0,fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height);
	else
		window.open('/travel/view.php?no='+no+'&loc='+loc, 'travel', "left =" + left + ",top=0,fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=" + width + ",height=" + height);
}
