function IEver()
{
    var ua = window.navigator.userAgent
    var msie = ua.indexOf ("MSIE ")

    if ( msie > 0 )
        return parseFloat(ua.substring(msie+5,ua.indexOf(";", msie)))
    else
        return 0
}

if (IEver()>=6) ie6 = true;
else ie6 = false;


function askClearMessage()
{
	return window.confirm ("¸Þ½ÃÁöµéÀ» ÀÐÀ½ »óÅÂ·Î Ã¼Å©ÇÏ½Ã°Ú½À´Ï±î?");
}

function userLogin()
{
	var url = gURL_root + "/login.php";
	var loginWin = window.open(url,"miniwiniLoginWnd","width=300,height=170");
}


function userJoin()
{
	window.alert("[°¡ÀÔ ÈÄ ÀÎÁõµÇ±â±îÁö ÇÏ·ç Á¤µµ°¡ ¼Ò¿äµË´Ï´Ù]\n\n°¡ÀÔ ÈÄ ¹Ù·Î ·Î±×ÀÎµÇÁö ¾Ê´Â´Ù°í ´Ù½Ã °¡ÀÔÇÏÁö ¸¶¼¼¿ä :)\n\n* ÀÌ¸§/´Ð³×ÀÓ/ÀÌ¸ÞÀÏ/È¨ÆäÀÌÁö ÁÖ¼Ò µîÀÇ Á¤º¸ÀÇ ½Å·Úµµ¿¡ µû¶ó ÀÎÁõµÇÁö ¾ÊÀ» ¼öµµ ÀÖ½À´Ï´Ù.");
	var url = gURL_root + "/join.php";
	var loginWin = window.open(url,"join","width=450,height=350");
}


function openMessageBox()
{
	window.open(gURL_message + '/messageBox.php','mwMessagebox','width=750,height=550')
}

function validateMIcon()
{
	try
	{
		event.srcElement.nextSibling.style.display="";
		event.srcElement.style.display = "none";
	}
	catch(e){}
}


function mwUserMenu(e)
{
	if (!e) e = window.event;
	var srcEl = e.srcElement?e.srcElement:e.target;

	while (srcEl.tagName != "A")
		srcEl = srcEl.parentNode;

	var eType = e.type;
	var sMemberId = srcEl.getAttribute("sMemberId");


	if (eType == "contextmenu")
	{
		mwMessageSend(sMemberId);
	}
	else if (eType == "click")
	{
		mwWhois(sMemberId);
	}
	return;
}


function mwWhois(sMemberId)
{
	var url = gURL_member + "/whois.php?who="+sMemberId;
	var sWinName = "mwWhoisWin_"+sMemberId;

	if (!isMoz)
	{
		var x = (screen.availWidth - 500)/2;
		var y = (screen.availHeight - 550)/2;
		var msgWin = window.open(url,"_blank","width=500,height=350,top="+y+",left="+x);
	}
	else
		var msgWin = window.open(url,"_blank","width=500,height=350");

	return;
}

function mwMessageSend(sMemberId)
{
	var rnd = Math.random();
	var url = gURL_message + "/message.php?to="+sMemberId+"&rnd="+rnd;

	var regex = /[-._]/gi;
	sMemberId = sMemberId.replace(regex,"");

	var sWinName = "mwmessageWin_"+sMemberId;

	if (!isMoz)
	{
		document.location.href='javascript:';
		var x = (screen.availWidth - 500)/2;
		var y = (screen.availHeight - 550)/2;
		var msgWin = window.open(url,sWinName,"width=500,height=550,top="+y+",left="+x);
	}
	else
		var msgWin = window.open(url,sWinName,"width=500,height=550");

	return;

}

function show(obj)
{
	obj.style.display = "";
}


function toggle(obj)
{
	if (obj.style.display == 'none')
		obj.style.display = '';
	else
		obj.style.display = 'none';
}
function hide(obj)
{
	obj.style.display = "none";
}


function fx(nNewPadding,el)
{
	while (el.tagName!="TD")
		el = el.parentNode;
	var nPadding = parseInt(el.getAttribute("nPadding"));
	el.style.paddingTop=nPadding+nNewPadding;
}

function defx(el)
{
	while (el.tagName!="TD")
		el = el.parentNode;
	var nPadding = parseInt(el.getAttribute("nPadding"));
	el.style.paddingTop = nPadding;

	ref = el.getAttribute("ref");
	if (ref)
	{
		var ref = document.getElementById(ref);

		while (ref.tagName!="TD")
			ref = ref.parentNode;

		var nPadding = parseInt(ref.getAttribute("nPadding"));
		ref.style.paddingTop = nPadding;
	}
}


function trim(str)
{
	newstr = str.replace (/(^\s*)|(\s*$)/g, "");
	return newstr;
}


function mwTabActivate(sRng,obj)
{
	var sClass;
	var o2 = obj;

	while (o2.tagName!="TD")
		o2 = o2.parentNode;

	while (obj.tagName!="DIV")
		obj = obj.parentNode;

	var bEng = obj.getAttribute("isEng");

	if (bEng == "false")
		sClass = "mk";
	else
		sClass = "mw";

	var cnt = 0;
	rng = document.getElementById(sRng);
	alltabs = rng.getElementsByTagName("TD");
	len = alltabs.length;

	for (i=0 ; i < len ; i++)
	{
		el = alltabs[i];

		if (el.className.indexOf(sClass + "Tab_active")>-1)
		{
			org_className = el.className.substring(12);
			el.className = sClass + "Tab_inactive" + org_className;
			cnt++;
		}
	}


	o2.parentNode.childNodes[0].className = sClass + "Tab_active_left";
	o2.parentNode.childNodes[1].className = sClass + "Tab_active";
	o2.parentNode.childNodes[2].className = sClass + "Tab_active_right";
}



function setOpinionFlag(obj)
{
	var oForm = document.getElementById(g_sCommentFormName);
	oForm.opinionFlag.value = obj.value;
}

function setLock(obj)
{
	if (obj.checked)
	{
		document.add_Comment.isLocked.value = 1;
		eval(g_sVisualEditor).innerHTML = eval(g_sVisualEditor).innerHTML + "<br><br><span class=locked>Thread closed</span>";
	}
	else
		document.add_Comment.isLocked.value = 0;
}

function commonReComment(nIndex,s2,s3)
{
	var obj = document.getElementById("recommentContainer_"+nIndex);
	var oForm = document.getElementById(g_sCommentFormName);

	for (i=0;i<g_nTotalComments;i++)
	{
		var el = document.getElementById("recommentContainer_"+i);
		hide(el);
		if (nIndex!=i)
			el.innerHTML = "";
	}



	if (g_bTextarea)
	{
		var el = document.getElementById("iViewTextareaContainer");
		if (obj.innerHTML == "")
		{
			el.innerHTML = "";


			obj.style.display = "";
			obj.innerHTML = htmlTextareaForm;

			var el = document.getElementById("iView_textarea");
			el.focus();
			oForm.c_org.value = s2;
			oForm.depth.value = s3;
		}
		else
		{
			obj.style.display = "none";
			obj.innerHTML = "";

			el.innerHTML = htmlCommentForm_footer;

			var el = document.getElementById("iView_textarea");
			el.focus();

			oForm.c_org.value = "";
			oForm.depth.value = "";
		}
	}
	else
	{
		var sHTML = htmlCommentForm_header + htmlCommentForm_iView + htmlCommentForm_footer;
		if (obj.innerHTML == "")
		{
			var el = document.getElementById("iViewContainer");
			el.innerHTML = "";

			var el = document.getElementById("masterContainerForComment");
			el.innerHTML = "";

			var el = document.getElementById("masterContainerForComment2");
			el.innerHTML = "";

			obj.style.display = "";
			obj.innerHTML = sHTML;

			var el = document.getElementById("iView");
			el.focus();
			oForm.c_org.value = s2;
			oForm.depth.value = s3;

			var el = document.getElementById("divOpinionSelector");
			hide(el);
		}
		else
		{
			obj.style.display = "none";
			obj.innerHTML = "";

			var el = document.getElementById("masterContainerForComment");
			el.innerHTML = htmlCommentForm_header;

			var el = document.getElementById("iViewContainer");
			el.innerHTML = htmlCommentForm_iView;

			var el = document.getElementById("masterContainerForComment2");
			el.innerHTML = htmlCommentForm_footer;

			var el = document.getElementById("iView");
			el.focus();

			oForm.c_org.value = "";
			oForm.depth.value = "";

			var el = document.getElementById("divOpinionSelector");
			show(el);
		}
	}
}




function editComment(sCode,sTbl,nId,nOrg)
{
	window.open(gURL_common+"/editComment.php?projCode="+sCode+"&tbl="+sTbl+"&commentId="+nId+"&topicId="+nOrg,"mwEditWnd","width=500,height=300");
}


function showHelp(sHelpIdx)
{
	var rnd = Math.random();
	var sUri = gURL_virtual + "/help/?helpIdx="+sHelpIdx;
	window.open(sUri,"mwHelpWnd","width=550,height=500,scrollbars=yes");
}


function setCookie(name,value,expiredays)
{
	var todayDate = new Date();
	todayDate.setDate(todayDate.getDate() + expiredays);
	document.cookie = name + "=" + escape(value) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}


function getCookie(name)
{
	var nameOfCookie = name + "=";
	var x = 0;
	while (x <= document.cookie.length)
	{
		var y = (x+nameOfCookie.length);
		if (document.cookie.substring( x, y ) == nameOfCookie)
		{
			if ((endOfCookie=document.cookie.indexOf(";",y)) == -1)
			{
				endOfCookie = document.cookie.length;
			}
			return unescape(document.cookie.substring(y,endOfCookie));
		}

		x = document.cookie.indexOf(" ",x) + 1;
		if (x == 0)
		{
			break;
		}
	}
	return "";
}


function rand(from,to)
{
	while (true)
	{
		n = parseInt(Math.random() * 100);
		if (n >= from && n <= to)
			return n;
	}
}


function in_array(needle,arr)
{
	for (i = 0 ; i < arr.length ; i++)
		if (needle == arr[i]) return true;
	return false;
}


function shuffle(arr)
{
	var aNum = new Array();
	var ret = new Array();
	while (arr.length != aNum.length)
	{
		n = rand(0, arr.length -1);
		if (!in_array (n, aNum))
		{
			ret[ret.length] = arr[n];
			aNum[aNum.length] = n;
		}
	}
	g_shuffle = aNum;
	return ret;
}


function musicboxRemotePlay(sAction)
{
	try
	{
		top.frames[0].playerControl(sAction);
	}
	catch(e){}
}


function playMultimediaFile(obj)
{
	try
	{
		el = obj.previousSibling;
		while (el.tagName!="A")
			el = el.previousSibling;
		var sURL = el.href;
		var sID = el.href;

		if (document.getElementById(sID)==null)
		{
			var sHTML = "<EMBED id='"+sID+"' autostart=true src='"+sURL+"'><br>";
			el.insertAdjacentHTML('beforeBegin',sHTML);
		}
	}
	catch(e){}
}


function generateMedia(sID,sURL)
{
	try
	{
		if (document.getElementById(sID)==null)
		{
			var el = event.srcElement;
			while(el.tagName!="DIV")
				el = el.parentElement;
			sHTML = "<EMBED id='"+sID+"' autostart='true' SRC='"+sURL+"'>";
			el.insertAdjacentHTML('afterEnd',sHTML);
		}
	}
	catch(e){}
}




function visualTag(sTag,obj)
{
	obj.focus();
	var rng = obj.document.selection.createRange();

	switch(sTag)
	{
		case "bold":
			document.execCommand("Bold",false,null);
			obj.focus();
			break;

		case "italic":
			document.execCommand("Italic",false,null);
			obj.focus();
			break;

		case "underline":
			document.execCommand("Underline",false,null);
			obj.focus();
			break;

		case "strike":
			document.execCommand("StrikeThrough",false,null);
			obj.focus();
			break;

		case "insertImage":
			var rnd = Math.random();
			window.showModalDialog(gURL_common+"/dialogInsertImage.php?rnd="+rnd,obj,"status:no;dialogWidth:460px;dialogHeight:444px");
			break;

		case "color":
			var sColor = getColorFromColorDlg();
			document.execCommand("ForeColor",false,sColor);
			obj.focus();
			break;

		case "bgcolor":
			var sColor = getColorFromColorDlg();
			document.execCommand("BackColor",false,sColor);
			obj.focus();
			break;

		case "hilite":
			document.execCommand("BackColor",false,"FFFF00");
			document.execCommand("ForeColor",false,"000000");
			break;

		case "sup":
			document.execCommand("Superscript",false,null);
			obj.focus();
			break;

		case "createLink":
			var rnd = Math.random();
			window.showModalDialog(gURL_common+"/dialogCreateLink.php?rnd="+rnd,obj,"status:no;dialogWidth:540px;dialogHeight:568px");
			break;

		case "insertEmoticons":
			var rnd = Math.random();
			window.showModalDialog(gURL_common+"/dialogInsertEmoticons.php?rnd="+rnd,obj,"status:no;dialogWidth:500px;dialogHeight:600px");
			break;
	}
}


function getColorFromColorDlg()
{
	if (ie6)
	{
		sInitColor = null;
		var sColor = dlgHelper.ChooseColorDlg(sInitColor);

		sColor = sColor.toString(16);

		if (sColor.length < 6)
		{
			var sTempString = "000000".substring(0,6-sColor.length);
			sColor = sTempString.concat(sColor);
		}
		return sColor;
	}
}


function showTexticonList(sObj)
{
	var rnd = Math.random();
	url = gURL_common + "/texticons.php?obj="+sObj+"&rnd="+rnd;
	window.showModalDialog(url,window,"dialogWidth:600px;dialogHeight:500px;status:no");
}


function showTexticons(sObj)
{
	var rnd = Math.random();
	url = gURL_common + "/texticonList.php?obj="+sObj+"&rnd="+rnd;
	window.showModalDialog(url,window,"dialogWidth:600px;dialogHeight:500px;status:no");
}

function insertEmoticon(sEmoticon,obj)
{
	obj.focus();
	obj.document.execCommand('InsertImage', false, sEmoticon);
}


function addToFavorite(favTitle,url)
{
	if ((navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4))
	{
		window.external.AddFavorite(url, unescape(favTitle));
	}
}

function copyURL(s)
{
	var doc = document.body.createTextRange();
	var s = document.getElementById(s);
	doc.moveToElementText(s);
	doc.select();
	doc.execCommand('copy');
	alert('URLÀÌ Å¬¸³º¸µå¿¡ ÀúÀåµÇ¾ú½À´Ï´Ù.');
}

function copyText(sId)
{
	bResult = window.clipboardData.setData("Text",document.getElementById(sId).innerText);
	if (bResult)
		alert('Å¬¸³º¸µå¿¡ ÀúÀåµÇ¾ú½À´Ï´Ù.');
}


function setSearchOption(nScale,obj)
{
	var el = document.getElementById("DivSearchForm");

	var a = el.getElementsByTagName("IMG");
	var len = a.length;


	for (i=0;i<len;i++)
		a[i].src = gURL_img+"/commonUI/checkbox/cCheckbox.png";


	obj.src = gURL_img+"/commonUI/checkbox/cCheckbox_on.png";

	document.searchForm.scale.value = nScale;
}



function toggleSearchOparator()
{
	var el = document.getElementById("img_op");

	if (document.searchForm.op.value == "and")
	{
		el.src = gURL_img+"/commonUI/button/buttonSearch_or.png";
		document.searchForm.op.value = "or";
	}
	else
	{
		el.src = gURL_img+"/commonUI/button/buttonSearch_and.png";
		document.searchForm.op.value = "and";
	}
}

function searchTopic()
{
	if (document.searchForm.keyword.value == "")
	{
		alert("°Ë»ö¾î¸¦ ÀÔ·ÂÇÏ¼¼¿ä");
		return;
	}
	searchForm.submit();
}

function showTopicRelated(s)
{
	hide(document.getElementById("DivMasterContainer_trackback"));
	hide(document.getElementById("DivMasterContainer_comment"));
	show(document.getElementById("DivMasterContainer_"+s));

	return;
}



function showTrackback(sTr)
{
	var o = document.getElementById(sTr);
	if (o.style.display != "none")
		hide(o);
	else
		show(o);
}





var g_sVisualEditor = "";
var g_bVisualEditor = true;
var g_bTextarea	= false;


function activateVisualEditor()
{
	try
	{
		document.getElementById(g_sVisualEditor).contentEditable = true;
	}
	catch(e){initAltEditor()}
}

function initVisualEditor(sId)
{
	g_sVisualEditor = sId;
	activateVisualEditor();
}

function toggleVisualEditorMode()
{
	if (g_bVisualEditor)
	{
		setVisualEditorMode(false);
	}
	else
	{
		setVisualEditorMode(true);
	}
	g_bVisualEditor = !g_bVisualEditor;
}

function setVisualEditorMode(bVisual)
{
	var o1 = document.getElementById(g_sVisualEditor);
	var o2 = document.getElementById(g_sVisualEditor+"_code");
	var oForm = document.getElementById(g_sCommentFormName);


	if (bVisual)
	{
		o1.innerHTML = o2.value;
		show(o1);
		show(divToolbarsVisualTags);
		hide(o2);
		o1.focus();
		oForm.isTextarea.value = '';
	}
	else
	{
		o2.value = o1.innerHTML;
		hide(o1);
		hide(divToolbarsVisualTags);
		show(o2);
		o2.focus();
		oForm.isTextarea.value = '1';
	}
}


function initAltEditor()
{
	g_bTextarea = true;
	var oForm = document.getElementById(g_sCommentFormName);
	oForm.isTextarea.value = 1;

	var o1 = document.getElementById(g_sVisualEditor);
	var o2 = document.getElementById(g_sVisualEditor+"_code");
	var o3 = document.getElementById("DivVisualEditorToolbar");
	var o4 = document.getElementById(g_sVisualEditor+"_textarea");

	hide(o1);
	hide(o2);
	hide(o3);
	show(o4);
}



function confirmCommonPost()
{
	var o1 = document.getElementById(g_sVisualEditor);
	var o2 = document.getElementById(g_sVisualEditor+"_code");
	var o3 = document.getElementById(g_sVisualEditor+"_textarea");
	var oButton = document.getElementById("submitButton");


	var oForm = document.getElementById(g_sCommentFormName);
	var sHTML;

	if (g_bTextarea)
	{
		oForm.isTextarea.value = 1;
		oForm.contents.value = o3.value;
		oButton.disabled = true;

		if (!trim(oForm.subject.value))
		{
			alert("Á¦¸ñÀÌ ¾ø½À´Ï´Ù.");
			oButton.disabled = false;
			o3.focus();
			return;
		}
		else if (!trim(o3.value))
		{
			alert("³»¿ëÀÌ ¾ø½À´Ï´Ù.");
			oButton.disabled = false;
			o3.focus();
			return;
		}
		else
		{
			oForm.submit();
		}
	}
	else
	{
		if (g_bVisualEditor)
		{
			sHTML = o1.innerHTML;
		}
		else
		{
			sHTML = o2.value;
		}

		DivCommentPostChecker.innerText = sHTML;
		oForm.contents.value = sHTML;

		oButton.disabled = true;

		if (trim(DivCommentPostChecker.innerText) == "")
		{
			alert("³»¿ëÀÌ ¾ø°Å³ª ±×¸²¸¸ ÀÖ½À´Ï´Ù.");
			oButton.disabled = false;
			return false;
		}

		else if (trim(oForm.contents.value) == "")
		{
			alert("³»¿ëÀÌ ¾ø½À´Ï´Ù.");
			oButton.disabled = false;
			return false;
		}
		else
		{
			oForm.submit();
		}
	}
}


function confirmCommonCommentPost()
{
	var o1 = document.getElementById(g_sVisualEditor);
	var o2 = document.getElementById(g_sVisualEditor+"_code");
	var o3 = document.getElementById(g_sVisualEditor+"_textarea");
	var oButton = document.getElementById("commentButton");

	var oForm = document.getElementById(g_sCommentFormName);
	var sHTML;

	if (g_bTextarea)
	{
		oForm.isTextarea.value = 1;
		oForm.comment.value = o3.value;
		oButton.disabled = true;

		if (!trim(o3.value))
		{
			alert("³»¿ëÀÌ ¾ø½À´Ï´Ù.");
			oButton.disabled = false;
			o3.focus();
			return;
		}
		else
		{
			oForm.submit();
		}
	}
	else
	{
		if (g_bVisualEditor)
		{
			sHTML = o1.innerHTML;
		}
		else
		{
			sHTML = o2.value;
		}

		oButton.disabled = true;

		DivCommentPostChecker.innerText = sHTML;
		oForm.comment.value = sHTML;

		if (trim(DivCommentPostChecker.innerText) == "")
		{
			alert("³»¿ëÀÌ ¾ø°Å³ª ±×¸²¸¸ ÀÖ½À´Ï´Ù.");
			oButton.disabled = false;
			return false;
		}

		else if (trim(oForm.comment.value) == "")
		{
			alert("³»¿ëÀÌ ¾ø½À´Ï´Ù.");
			oButton.disabled = false;
			return false;
		}
		else
		{
			oForm.submit();
		}
	}
}



function captureEnterKey()
{
    if (event.keyCode == 13)
	{
        if (event.shiftKey == false)
		{
            var sel = document.selection.createRange();
            sel.pasteHTML('<br>');
            event.cancelBubble = true;
            event.returnValue = false;
            sel.select();

            return false;
        }
        else
		{
            return event.keyCode = 13;
		}
    }
}



function printMiniwini()
{
	var oMain		= document.getElementById("DivMiniwini");
	var oContainer	= document.getElementById("DivPrint");
	var oScreen		= document.getElementById("DivScreen");

	oContainer.innerHTML = oMain.innerHTML;
	document.body.style.background = "white url()";
	hide(oScreen);
	show(oContainer);

	window.print();
}


function resizeMiniwini(sHow)
{
	var oRoof1	= document.getElementById("DivRoof");
	var oRoof2	= document.getElementById("DivRoof2");
	var oLeft	= document.getElementById("DivRoofRight");

	var nWidth1 = parseInt(oRoof1.style.width);
	var nWidth2 = parseInt(oRoof2.style.width);



	switch (sHow)
	{
		case "+":
			var nNewWidth1 = nWidth1 + 30;
			var nNewWidth2 = nWidth2 + 30;
			oLeft.style.left = parseInt(oLeft.style.left) + 30;
			break;
		case "default":
			var nNewWidth1 = 721;
			var nNewWidth2 = 726;
			oLeft.style.left = 853;
			break;
		case "-":
			var nNewWidth1 = nWidth1 - 30;
			var nNewWidth2 = nWidth2 - 30;
			oLeft.style.left = parseInt(oLeft.style.left) - 30;
			break;
	}

	oRoof1.style.width = nNewWidth1;
	oRoof2.style.width = nNewWidth2;

	setCookie("nMiniwiniRoofWidth",nNewWidth1,365);
}

function shakeWindow()
{
	var x = 10;
	for (i=0;i,i<20;i++)
	{
		window.moveBy(0,x)
		window.moveBy(x,0)
		window.moveBy(0,-x)
		window.moveBy(-x,0)
	}
}

function hiliteKeyword()
{
}

