// GET 변수를 JS 변수로 가져오기
var $_qry_str
$_qry_str = location.search.substring(1);
if($_qry_str!="")
{
	var $__GET = new Object();
	var $k = 0;
	var $_GET = new Object();
	do
	{
		if($_qry_str.split("=")[1])
		{
			$__GET[$_qry_str.split("=")[0].replace(/&/, "")] = $_qry_str.split("=")[1].split(/&|$/)[0];
			$_qry_str = $_qry_str.split($_qry_str.split("=")[1].split(/&|$/)[0])[1];
		}
		$k ++;
	}
	while($k < (location.search.split("=").length - 1))
	{ for(key in $__GET) { $_GET[key] = $__GET[key]; } }
}

// mousein 이벤트 확인 함수
function checkMouseEnter(element, evt)
{
	if (element.contains && evt.fromElement)
	{
		return !element.contains(evt.fromElement);
	}
	else if (evt.relatedTarget)
	{
		return !containsDOM(element, evt.relatedTarget);
	}
}

// mouseout 이벤트 확인 함수
function checkMouseLeave(element, evt)
{
	if (element.contains && evt.toElement)
	{
		return !element.contains(evt.toElement);
	}
	else if (evt.relatedTarget)
	{
		return !containsDOM(element, evt.relatedTarget);
	}
}

// profileList 링크 이동 함수
function sendToProfile(pno, gno)
{
	if(pno!="")
	{
		if(pno=="new")
		{
			location.href = window.location.pathname + "?mode=createProfile";
		}
		else
		{
			location.href = window.location.pathname + "?mode=viewProfile&pno=" + pno + "&gno=" + gno;
		}
	}
}

// ADMIN 셋팅 저장 함수
function adminSet(mode, rno, sel, cmd, ob)
{
	sel.action="adminSetup.php?mode=" + mode + "&rno=" + rno + "&cmd=" + cmd +"&QNO=" + ob + "&set=1";
	sel.submit();
}

//클립보드로 내용 복사
function setClipBoard(meintext)
{
	
	if (window.clipboardData)
	{
		window.clipboardData.setData("Text", meintext);
	}
	else if (window.netscape) 
	{ 
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;

		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;

		trans.addDataFlavor('text/unicode');

		var str = new Object();
		var len = new Object();

		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);

		var copytext=meintext;

		str.data=copytext;

		trans.setTransferData("text/unicode",str,copytext.length*2);

		var clipid=Components.interfaces.nsIClipboard;

		if (!clip) return false;

		clip.setData(trans,null,clipid.kGlobalClipboard);

	}
	window.alert('클립보드에 저장되었습니다. \nCtrl + V 하시면 붙여넣기가 됩니다.');
	return false;
}

// 쿠키 생성 함수
function setCookie( name, value, expires, path, domain, secure ) 
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct 
	expires time, the current script below will set 
	it for x number of days, to make it for hours, 
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = 
		name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// 쿠키 가져오는 함수
// with this test document.cookie.indexOf( name + "=" );
function getCookie(check_name)
{
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}

		a_temp_cookie = null;
		cookie_name = '';
	}

	if ( !b_cookie_found )
	{
		return null;
	}
}

// this deletes the cookie when called
function delCookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

//// a(array)를 제외한 모든 interval 초기화 함수
function clearAllIntervalsExcept(a)
{
	var x = {};
	for ( var i in a )
	{ x [ '_' + a [ i ] ] = 1; };

	// create new interval
	var id = setInterval ( this, 'blank', 0 );

	while ( id != 0 )
	{
		// count through all intervals and clear them one by one
		// except those defined in the array
		if ( !x [ '_' + id ] ) clearInterval ( id );
		id--;
	}
}

//공백 제거 trim() 함수
String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

// 엔터 눌렀을때 폼 넘어가는 것 방지하는 함수
// 사용 방법: onkeypress="disableEnterKey(event)"
function disableEnterKey(e)
{
	var key;      
	if(window.event)
	{
		key = window.event.keyCode; //IE
	}
	else
	{
		key = e.which; //firefox
	}

	return (key != 13);
}

function displayMessage(msg)
{
	$('messageBox').style.display = "block";
	$('messageBox').appendChild(document.createTextNode(msg));
	location.href="#alert";
}