/*-----------------------------------------------------------------------------------------
* base
* ÀÛ¼ºÀÏ : 2006.01.15.
* ¼öÁ¤ÀÏ : 2006.07.08.
* ÀÛ¼ºÀÚ : À¯¿µÀç
-----------------------------------------------------------------------------------------*/

//var domain = String(document.domain).split(".");
//var _LOCATION_BASE_URL = "http://" + document.domain;

//-----------------------------------------------------------------------------------
// ±âÃÊ ¼±¾ð
function addEvent(target, en, func)
{
	if (window.addEventListener) 
	{
		if ((target == window) && (en.toLowerCase() == "load"))
			document.addEventListener("DOMContentLoaded", func, false);
		else	
	        target.addEventListener(en, func, false);
    } 
    else if (target.attachEvent) 
	{
		if ((target == window) && (en.toLowerCase() == "load"))
	    	document.attachEvent("onreadystatechange", function(e) { if (document.readyState == "complete") func(); });
		else
	        target.attachEvent("on"+en, func);
    } 
	else 
	{
        var __func = eval("target.on"+en);

        eval("target.on"+en) = function() 
		{
            func();
            __func();
        };
    }
};

function wopen(url, id, option, w, h, dir)
{
	if (typeof(dir) == "undefined")
		dir = "c";

	//scrollbars=no,status=no,resizable=no,location=no,

	if (typeof(w) != "undefined")
		option += ",width="+w;

	if (typeof(h) != "undefined")
		option += ",height="+h;
	
	switch(dir)
	{
		case "tl" :
			option += ",top=0";
			option += ",left=0";
			break;
		case "tr" :
			option += ",top=0";
			if (typeof(w) != "undefined")
				option += ",left="+(screen.width-w);
			break;
		case "c" :
			if ((typeof(w) != "undefined") && (typeof(h) != "undefined"))
			{
				option += ",top="+((screen.height-h)/2);
				option += ",left="+((screen.width-w)/2);
			}
			break;
		case "bl" :
			if (typeof(h) != "undefined")
				option += ",top="+(screen.height-h);
			option += ",left=0";
			break;
		case "br" :
			if (typeof(h) != "undefined")
				option += ",top="+(screen.height-h);
			if (typeof(w) != "undefined")
				option += ",left="+(screen.width-w);
			break;
	}

	var win = window.open(url, id, option);

	if (win != null)
		win.focus();
	else
		alert("ÆË¾÷À» Á¦ÇÑÇÏ¿© Ã¢À» ¿­ ¼ö ¾ø½À´Ï´Ù.\\n\\nÆË¾÷À» Çã¿ë ÇØ ÁÖ½Ê½Ã¿À.");
};

function resizeImage(i, max, hmax)
{
	if(!max) 
	{
		if (i.parentNode)
		{
			max = i.parentNode.offsetWidth;
			hmax = i.parentNode.offsetHeight;
		}

		if (max <= 0)
			max = 100;

		if (hmax <= 0)
			hmax = 100;
	}
	if (i.width > max) 
	{
		i.height = i.height*(max/i.width);
		i.width = max;
	}
	if (i.height > hmax) 
	{
		i.width = i.width*(hmax/i.height);
		i.height= hmax;
	}
/*
	if (i.width > i.height && i.width > max) 
	{
		i.height = i.height*(max/i.width);
		i.width = max;
	}
	else if (i.width <= i.height && i.height > hmax) 
	{
		i.width = i.width*(hmax/i.height);
		i.height= hmax;
	}
*/	
};

// »ç¿ëÀÚ ÆË¾÷ ¼³Á¤
var userPopup = function() {};
userPopup.prototype.open = function(event, uid)
{
	if (uid != "")
	{
		var win = window.open(_LOCATION_BASE_URL + "/user/index.php?uid=" + uid, "__USER_INFO", "scrollbars=no,status=no,resizable=no,location=no, width=400,height=500,top=" + (screen.height-500)/2 + ",left=" + (screen.width-400)/2);

		if (win != null)
			win.focus();
		else
			alert("ÆË¾÷À» Á¦ÇÑÇÏ¿© Ã¢À» ¿­ ¼ö ¾ø½À´Ï´Ù.\\n\\nÆË¾÷À» Çã¿ë ÇØ ÁÖ½Ê½Ã¿À.");
	}
};

var userPopupMenu = null;
function onloadUserPopup() { if (typeof(userPopup) != "undefined") { userPopupMenu = new userPopup(); } };
addEvent(window, "load", onloadUserPopup);

//-----------------------------------------------------------------------------------
//ÄíÅ° °ü·Ã ½ºÅ©¸³Æ®
// ·ÎÄÃ¿¡ »ý¼ºµÈ ÄíÅ° Áß ÀÌ¸§ÀÌ NameÀÎ ÄíÅ°ÀÇ °ªÀ» ¹ÝÈ¯ÇÑ´Ù.
function getCookie(Name) 
{
	var search = Name + "=";

	if (document.cookie.length > 0) 
	{
		offset = document.cookie.indexOf(search);

		if (offset != -1) 
		{
			offset += search.length;
			end = document.cookie.indexOf(";", offset);

			if (end == -1) 
				end = document.cookie.length;

			return unescape(document.cookie.substring(offset, end));
		}
		else 
			return false;
	}
	else 
		return false;
};

getRealOffsetTop = function(obj) 
{
	return obj?obj.offsetTop + getRealOffsetTop(obj.offsetParent):0;
};

getRealOffsetLeft = function(obj) 
{
	return obj?obj.offsetLeft + getRealOffsetLeft(obj.offsetParent):0;
};

function purge(d) 
{
	if (d == null)
		return false;

	var a = d.attributes, i, l, n; 
	if (a) 
	{ 
		l = a.length; 
		for (i = 0; i < l; i += 1) 
		{ 
			n = a[i].name; 
			if (typeof d[n] === 'function') 
				d[n] = null; 
		} 
	} 
	a = d.childNodes; 
	if (a) 
	{ 
		l = a.length; 
		for (i = 0; i < l; i += 1) 
			purge(d.childNodes[i]); 
	} 
}; 

function removeObject(obj)
{
	if (obj == null)
		return false;

	purge(obj);

	if (obj.removeNode)
		obj.removeNode(true);
	else
		obj.parentNode.removeChild(obj);
};

function mGET(arrayKey, arrayValue, Value) 
{ 
	count = arrayKey.length; 
	for(i=0;i<count;i++) 
	{ 
		if(arrayKey[i]==Value) 
		{ 
			return arrayValue[i]; 
			break; 
		} 
	} 
};

// flash ÄÚµå »ç¿ë (¼Ò½ºÆíÁý Å¬¸³ µî)
function mEmbed() 
{ 
	var key = new Array(); 
	var value = new Array(); 
	var contents; 
	var embed_type; 
	var error_check=0; 
	var i, j; 
	var count; 
	var data; 
	var temp; 

	if(mEmbed.arguments.length==1) 
	{ 
		contents = mEmbed.arguments[0]; 
	} 
	else 
	{ 
		for(i=0;i<mEmbed.arguments.length;i++) 
		{ 
			temp = mEmbed.arguments[i].replace(/\"|'/g,""); 
			data = temp.split('='); 
			key[i] = data[0]; 
			value[i] = data[1]; 
			count = data.length; 

			for(j=2;j<count;j++) 
				value[i] += '=' + data[j]; 
		} 

		contents=''; 
		srcdata = mGET(key,value,'src'); 

		if(/\.(swf)$/.test(srcdata)) 
		{ 
			embed_type = 1; 
		} 
		else if(/\.(mov|avi|wma|wmv)$/.test(srcdata)) 
		{ 
			embed_type = 2; 
		} 

		var classid = mGET(key,value,'classid'); 
		var codebase = mGET(key,value,'codebase'); 

		if(embed_type==1) 
		{ 
			classid = 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'; 
			codebase = 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.c-ab#version=6,0,29,0'; 
		} 
		else if(embed_type==2) 
		{ 
			classid = 'clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95'; 
			codebase = 'http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.c-ab#Version=6,4,5,715'; 
		} 

		if(classid && codebase) 
		{ 
			contents += '<object'; 
			if(classid) 
				contents += ' classid="' + classid + '"'; 

			if(codebase) 
			{ 
				contents += ' codebase="' + codebase + '"'; 
			} 

			count = key.length; 

			for(i=0;i<count;i++) 
			{ 
				if(value[i]!='') 
				{ 
					if(key[i]!='src') 
					{ 
						contents += ' ' + key[i] + '="' + value[i] + '"'; 
					} 
				} 
			} 
			contents += '>'; 

			for(i=0;i<count;i++) 
			{ 
				if(value[i]!='') 
				{ 
					if(embed_type==1 && key[i]=='src') 
						contents += '<param name="movie" value="' + value[i] + '" />'; 
					else 
						contents += '<param name="' + key[i] + '" value="' + value[i] + '" />'; 
				} 
			} 
		} 
		count = key.length; 
		contents += '<embed'; 
		for(i=0;i<count;i++) 
			if(value[i]!='') 
				contents += ' ' + key[i] + '="' + value[i] + '"'; 

		contents += '>'; 
		contents += '</embed>'; 

		if(classid && codebase) 
			contents += '</object>'; 
	}
	document.write(contents); 
};

function catchTab(e, item)
{
	if(navigator.userAgent.match("Gecko"))
		c=e.which;
	else
		c=e.keyCode;

	if(c==9)
	{
		replaceSelection(item,String.fromCharCode(9));
		setTimeout("document.getElementById('"+item.id+"').focus();",0); 
		return false;
	}
};

function replaceSelection (input, replaceString) 
{
	if (input.setSelectionRange) 
	{
		var selectionStart = input.selectionStart;
		var selectionEnd = input.selectionEnd;
		input.value = input.value.substring(0, selectionStart)+ replaceString + input.value.substring(selectionEnd);

		if (selectionStart != selectionEnd)
			setSelectionRange(input, selectionStart, selectionStart + replaceString.length);
		else
			setSelectionRange(input, selectionStart + replaceString.length, selectionStart + replaceString.length);
	}
	else if (document.selection) 
	{
		var range = document.selection.createRange();

		if (range.parentElement() == input) 
		{
			var isCollapsed = range.text == '';
			range.text = replaceString;

			if (!isCollapsed) 
			{
				range.moveStart('character', -replaceString.length);
				range.select();
			}
		}
	}
}; 

function setSelectionRange(input, selectionStart, selectionEnd) 
{
	if (input.setSelectionRange) 
	{
		input.focus();
		input.setSelectionRange(selectionStart, selectionEnd);
	}
	else if (input.createTextRange) 
	{
		var range = input.createTextRange();
		range.collapse(true);
		range.moveEnd('character', selectionEnd);
		range.moveStart('character', selectionStart);
		range.select();
	}
};

// ie6 css background-image ±ôºýÀÓ ¹®Á¦ Ã³¸®¸¦ À§ÇÔ
(function(){
 
/*Use Object Detection to detect IE6*/
var  m = document.uniqueID /*IE*/
&& document.compatMode  /*>=IE6*/
&& !window.XMLHttpRequest /*<=IE6*/
&& document.execCommand ;

try{ if(!!m){ m("BackgroundImageCache", false, true) /* = IE6 only */ } }catch(oh){};
})();

/*
function textToClipBoard(text)
{
	if (window.clipboardData) 
	{
		window.clipboardData.setData("Text", text); 
		return true;
	} 
	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 false; 

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

		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 = text;  
		str.data = copytext; 

		trans.setTransferData("text/unicode",str,copytext.length*2); 
		var clipid = Components.interfaces.nsIClipboard; 
		if (!clipid) 
			return false; 

		clip.setData(trans,null,clipid.kGlobalClipboard); 
		return true;
	} 

	return false; 
};

//-----------------------------------------------------------------------------------
// ¼±ÅÃ ¹®ÀÚ¿­ Å¬¸³ º¸µå·Î º¹»ç

function expandRangeToWord(range) 
{
	var startOfWord = /^\s\S+$/;
	var endOfWord = /^\S+\s$/;
	var whitespace = /^\s+$/;
	
	range.setStart(range.startContainer, range.startOffset - 1);
	while (whitespace.test(range.toString())) 
	{
		range.setEnd(range.endContainer, range.endOffset + 1);
		range.setStart(range.startContainer, range.startOffset + 1);
	}
	while (!startOfWord.test(range.toString())) 
	{
		range.setStart(range.startContainer, range.startOffset - 1);
	}
	range.setStart(range.startContainer, range.startOffset + 1);
	while (!endOfWord.test(range.toString())) 
	{
		range.setEnd(range.endContainer, range.endOffset + 1);
	}
	range.setEnd(range.endContainer, range.endOffset - 1);
	return range.toString();
};


function selectToClipboard(event) 
{
	if (document.body && document.body.createTextRange) 
	{
		event = window.event;

		var range = document.body.createTextRange();
		range.moveToPoint(event.clientX, event.clientY);
		range.expand('word');
		range.execCommand("copy");
		alert(range.text);
		
		return range.text;
	}
	else if (event.rangeParent && document.createRange) 
	{
		var range = document.createRange();
		range.setStart(event.rangeParent, event.rangeOffset);
		range.setEnd(event.rangeParent, event.rangeOffset);
		
		return expandRangeToWord(range);    
	}
	else 
	{
		return false;
	}
};

*/

function imageResize(obj, width, height)
{
	if ((width <=0) && (height <= 0))
	{
		obj.style.visibility = "visible";
		return false;
	}
	
	width = parseInt(width);
	height = parseInt(height);
	var i_width = (obj.style.pixelWidth > 0 )?(obj.style.pixelWidth):(obj.width);
	var i_height = (obj.style.pixelHeight > 0 )?(obj.style.pixelHeight):(obj.height);
	
	if ((width > 0) && (parseInt(i_width) > width))
	{
		i_height = i_height * (width / i_width);
		i_width = width;
	}

	if ((height > 0) && (parseInt(i_height) > height))
	{
		i_width = i_width * (width / i_width);
		i_height = height;
	}
	
	if (width > 0)
		obj.style.width = parseInt(i_width) + "px";
	
	if (height > 0)
		obj.style.height = parseInt(i_height) + "px";

	obj.style.visibility = "visible";
};

// ie5 ÀÌÇÏ ¹öÀüÀÇ ¹è¿­ °ü·Ã Ã³¸®°¡ ¼³Á¤¾ÈµÈ °Í¿¡ ´ëÇÑ Ã³¸®
// array¸¦ foreach ½ÃÅ³ °æ¿ì ¹®Á¦°¡ µÊ - °¢ prototypeÀÌ ÇÏ³ªÀÇ ¹è¿­·Î ÀÎ½Ä µÊ
// push¸¦ ¾È¾²°Å³ª ´ëÃ¼ Ã³¸®ÇÏ´Â °ÍÀÌ ÁÁÀ» °Í °°À½
if (!Array.prototype.pop) { 
	Array.prototype.pop = function() { 
		var last; 
		if (this.length) { 
			last = this[this.length - 1]; 
			this.length -= 1; 
		} 
		return last; 
	}; 
};

// Adds one or more elements to the end of an array and returns the new length of the array. 
if (!Array.prototype.push) { 
	Array.prototype.push = function() { 
		for (var i = 0; i < arguments.length; ++i) { 
			this[this.length] = arguments[i]; 
		} 
		return this.length; 
	}; 
};

// Removes the first element from an array and returns that element. 
if (!Array.prototype.shift) { 
	Array.prototype.shift = function() { 
		var first; 
		if (this.length) { 
			first = this[0]; 
			for (var i = 0; i < this.length - 1; ++i) { 
				this[i] = this[i + 1]; 
			} 
			this.length -= 1; 
		} 
		return first; 
	}; 
};

// Adds one or more elements to the front of an array and returns the new length of the array. 
if (!Array.prototype.unshift) { 
	Array.prototype.unshift = function() { 
		if (arguments.length) { 
			var i,  len = arguments.length; 
			for (i = this.length + len - 1; i >= len; --i) { 
				this[i] = this[i - len]; 
			} 
			for (i = 0; i < len; ++i) { 
				this[i] = arguments[i]; 
			} 
		} 
		return this.length; 
	}; 
};

// Adds and/or removes elements from an array. 
if (!Array.prototype.splice) { 
	Array.prototype.splice = function(index,  howMany) { 
		var elements = [],  removed = [],  i; 
		for (i = 2; i < arguments.length; ++i) { 
			elements.push(arguments[i]); 
		} 
		for (i = index; (i < index + howMany) && (i < this.length); ++i) { 
			removed.push(this[i]); 
		} 
		for (i = index + howMany; i < this.length; ++i) { 
			this[i - howMany] = this[i]; 
		} 
		this.length -= removed.length; 
		for (i = this.length + elements.length - 1; i >= index + elements.length; --i) { 
			this[i] = this[i - elements.length]; 
		} 
		for (i = 0; i < elements.length; ++i) { 
			this[index + i] = elements[i]; 
		} 
		return removed; 
	}; 
};

/* ie5 ÀÌÇÏ ¹öÀüÀÇ encodeURIComponent */
function utf8(wide) 
{
	var c, s;
	var enc = "";
	var i = 0;
	while(i<wide.length) 
	{
		c= wide.charCodeAt(i++);
		// handle UTF-16 surrogates
		if (c>=0xDC00 && c<0xE000) 
			continue;

		if (c>=0xD800 && c<0xDC00) 
		{
			if (i>=wide.length) continue;
			s= wide.charCodeAt(i++);
			if (s<0xDC00 || c>=0xDE00) continue;
			c= ((c-0xD800)<<10)+(s-0xDC00)+0x10000;
		}
		// output value
		if (c<0x80) enc += String.fromCharCode(c);
		else if (c<0x800) enc += String.fromCharCode(0xC0+(c>>6),0x80+(c&0x3F));
		else if (c<0x10000) enc += String.fromCharCode(0xE0+(c>>12),0x80+(c>>6&0x3F),0x80+(c&0x3F));
		else enc += String.fromCharCode(0xF0+(c>>18),0x80+(c>>12&0x3F),0x80+(c>>6&0x3F),0x80+(c&0x3F));
	}
	return enc;
};

var hexchars = "0123456789ABCDEF";

function toHex(n) 
{
	return hexchars.charAt(n>>4)+hexchars.charAt(n & 0xF);
};

var okURIchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-";

if (typeof(encodeURIComponent) != "function")
{
	eval("\
	function encodeURIComponent(s) \
	{\
		var s = utf8(s);\
		var c;\
		var enc = '';\
		for (var i= 0; i<s.length; i++) \
		{\
			if (okURIchars.indexOf(s.charAt(i))==-1)\
				enc += '%'+toHex(s.charCodeAt(i));\
			else\
				enc += s.charAt(i);\
		}\
		return enc;\
	}");
};
 
// <a href="#" onclick="return false;"> °¡ ÀÏºÎ ie¿¡¼­ ¿ÀÀÛµ¿ÇÏ´Â °ÍÀ» ¹æÁö <a href="#" onclick="return rFalse(event);">
function rFalse(event)
{
	if (typeof window.event != "undefined")
		event = window.event;

	if (event)
	{
		if (typeof event.preventDefault!= 'undefined')
			event.preventDefault(); // W3C 
		else
			event.returnValue = false; // IE 
	}
	// safey for handling DOM Level 0 
	return false;
};

function selectInnerText(obj) 
{ 
	if (window.getSelection) 
	{ 
		window.getSelection().selectAllChildren(obj); 
	} 
	else if (document.body.createTextRange) 
	{ 
		var r = document.body.createTextRange(); 
		r.moveToElementText(obj); 
		r.select(); 
	} 
};

function urlencode(q)
{ 
	return escape(q).replace('/\+/g', "%2B"); 
};

function print_r(theObj)
{
	var txt = "";

	if (theObj.constructor == Array || theObj.constructor == Object)
	{
		txt += "<ul>";
		for(var p in theObj)
		{
			if(theObj[p].constructor == Array || theObj[p].constructor == Object)
			{
				txt += "<li>["+p+"] => "+typeof(theObj)+"</li>";
				txt += "<ul>";
				txt += print_r(theObj[p]);
				txt += "</ul>";
			} 
			else 
			{
				txt += "<li>["+p+"] => "+theObj[p].cpname+"-"+theObj[p].id+"</li>";
			}
		}
		txt += "</ul>";
	}

	return txt;
};
