var menuOn = false;
var overMenu = false;
var menuInfo = {
	MenuWidth: MenuWidth = 101,
	MenuHeight: MenuHeight = 0,
	FontSize: FontSize = "9pt",
	FontColor: FontColor = "black",
	BgColor: BgColor = "#FFFFFF",
	FontColorBar: FontColor = "#000000",
	BgColorBar: BgColor = "#D8D8D8",
	FontColorOver: FontColor = "#336702",
	BgColorOver: BgColor = "#FFFFFF",
	BorderColor: BorderColor = "#000000",
	MenuItem: MenuItem = [
//		[ "myhompy", "<b>È¨ÇÇ º¸±â</b>", true, "main_menu_ico00.gif" ],
//		[ "", "", true ],
		[ "sendmemo", "ÂÊÁö º¸³»±â", true, "icon_note01.gif" ]
//		[ "talk", "Ã¤ÆÃÇÏ±â", true, "main_menu_ico01.gif" ],
//		[ "sendsms", "¹®ÀÚ º¸³»±â", true, "main_menu_ico03.gif" ],
//		[ "sendmail", "¸ÞÀÏ º¸³»±â", true, "main_menu_ico04.gif" ],
//		[ "telephone", "ÀüÈ­ °É±â", true, "ico_telephone.gif" ],
//		[ "", "", true ],
//		[ "addbuddy", "Ä£±¸ Ãß°¡", true, "main_menu_ico05.gif" ],
//		[ "block", "¼ö½ÅÂ÷´Ü", true, "main_menu_ico06.gif" ]
	]
};

var miniInfo = {
	MenuWidth: MenuWidth = 101,
	MenuHeight: MenuHeight = 0,
	FontSize: FontSize = "9pt",
	FontColor: FontColor = "black",
	BgColor: BgColor = "#FFFFFF",
	FontColorBar: FontColor = "#000000",
	BgColorBar: BgColor = "#D8D8D8",
	FontColorOver: FontColor = "#336702",
	BgColorOver: BgColor = "#FFFFFF",
	BorderColor: BorderColor = "#000000",
	MenuItem: MenuItem = [
		[ "myhompy", "<b>È¨ÇÇ º¸±â</b>", true, "main_menu_ico00.gif" ],
		[ "sendmemo", "ÂÊÁö º¸³»±â", true, "main_menu_ico02.gif" ],
		[ "addbuddy", "Ä£±¸ Ãß°¡", true, "main_menu_ico05.gif" ]
	]
};

var userInfo = {
	UserId: UserId = "",
	NickNm: NickNm = "",
	ToUserId: ToUserId = "",
	ToNickNm: ToNickNm = ""
};

makeMenu();

function makeMenu() {
	var sHTML;

	sHTML = "<div id=\"userMenu\" style=\"position:absolute;width:"+menuInfo.MenuWidth+"px;color:"+menuInfo.FontColor+";border:none;z-index:9999;visibility:hidden\" onMouseOver=\"menuOver(this)\" onMouseOut=\"menuOut(this)\"></div>"

	document.write(sHTML);
}

function showMenuEx(sUserId, sNickNm, sToUserId, sToNickNm, sMenuType, bLogin, strOrgUrl) {
	var oMenuInfo;

	if (sMenuType == "M") {
		oMenuInfo = miniInfo;
	} else {
		oMenuInfo = menuInfo;
	}

	overMenu = true;
	if (menuOn)
		return;
		
	var oMenu = document.all.userMenu;
	var sHTML;
	var left;
	var top;
	var oParentPositionedElement;

	userInfo.UserId = sUserId;
	userInfo.NickNm = sNickNm;
	userInfo.ToUserId = sToUserId;
	userInfo.ToNickNm = sToNickNm;

	oMenuInfo.MenuHeight = 23;

	sHTML = "<div style=\"position:relative;height:4px\"><img src=\"" + g_imgsvr + "/usermenu/popmenu_top.gif\"/></div>";
	//		"<div style=\"position:relative;height:18px;font-size:"+oMenuInfo.FontSize+";font-weight:bold;color:"+oMenuInfo.FontColorBar+";background-color:"+oMenuInfo.BgColorBar+";padding:3px;border-left:solid 1 " + oMenuInfo.BorderColor + "; border-right:solid 1 " + oMenuInfo.BorderColor + "\">&nbsp;"+userInfo.ToUserId+"</div>" +
	//		"<div style=\"position:relative;height:1px;background-color:"+oMenuInfo.BorderColor+";\"><img src=\""+g_imgsvr+"/1by1.gif\" border=\"0\"></div>";

	for (var i = 0; i < oMenuInfo.MenuItem.length; i++) {
		if (oMenuInfo.MenuItem[i][0] == "") {
				oMenuInfo.MenuHeight += 1;
				sHTML += "<div style=\"position:relative;background-image:url('" + g_imgsvr + "/usermenu/popmenu_dot.gif'); background-color:"+oMenuInfo.BgColor+";border-left:solid 1 " + oMenuInfo.BorderColor + "; border-right:solid 1 " + oMenuInfo.BorderColor + "\"><img src=\""+g_imgsvr+"/1by1.gif\" border=\"0\"/></div>";
		}
		else {
			if (i == 0 || oMenuInfo.MenuItem[i-1][0] == "") {
				oMenuInfo.MenuHeight += 3;
				sHTML += "<div style=\"position:relative;height:3px;background-color:"+oMenuInfo.BgColor+";border-left:solid 1 " + oMenuInfo.BorderColor + "; border-right:solid 1 " + oMenuInfo.BorderColor + "\"><img src=\""+g_imgsvr+"/1by1.gif\" border=\"0\"></div>";
			}

			oMenuInfo.MenuHeight += 18;
			sHTML += "<div style=\"position:relative;font-size:"+oMenuInfo.FontSize+";font-weight:normal;padding:2px;background-color:"+oMenuInfo.BgColor+";border-left:solid 1 " + oMenuInfo.BorderColor + "; border-right:solid 1 " + oMenuInfo.BorderColor + "\"";
			if (oMenuInfo.MenuItem[i][2] == true || userInfo.UserId != "Guest")
				sHTML += " onmouseover=\"this.style.backgroundColor = '" + oMenuInfo.BgColorOver + "'\" onmouseout=\"this.style.backgroundColor = '" + oMenuInfo.BgColor + "'\"";
			if (bLogin == 'False')
				sHTML += ">&nbsp;<img src=\"" + g_imgsvr + "/fileguri/memo/" + oMenuInfo.MenuItem[i][3] + "\" align=\"absmiddle\"/>&nbsp;<a href=\"javascript:DoLogin()\""
			else
				sHTML += ">&nbsp;<img src=\"" + g_imgsvr + "/fileguri/memo/" + oMenuInfo.MenuItem[i][3] + "\" align=\"absmiddle\"/>&nbsp;<a href=\"javascript:menuAction('" + oMenuInfo.MenuItem[i][0] + "')\""
	
			
			
			
			if (oMenuInfo.MenuItem[i][2] == true || userInfo.UserId != "Guest")
				sHTML += " onMouseOver=\"itemOver(this)\" onMouseOut=\"itemOut(this)\"";
			sHTML += ">" + oMenuInfo.MenuItem[i][1] + "</a></div>"
			if (i < oMenuInfo.MenuItem.length-1 && oMenuInfo.MenuItem[i+1][0] == "") {
				oMenuInfo.MenuHeight += 3;
				sHTML += "<div style=\"position:relative;height:3px;background-color:"+oMenuInfo.BgColor+";border-left:solid 1 " + oMenuInfo.BorderColor + "; border-right:solid 1 " + oMenuInfo.BorderColor + "\"><img src=\""+g_imgsvr+"/1by1.gif\" border=\"0\"></div>";
			}
		}
	}
	sHTML += "<div style=\"position:relative;height:4px\"><img src=\"" + g_imgsvr + "/usermenu/popmenu_bottom.gif\"/></div>";

	oMenu.innerHTML = sHTML;

	for (var i=oMenu.parentElement;i!=null;i=i.parentElement) if (i.style.position != "") oParentPositionedElement = i
	if (oParentPositionedElement == null) oParentPositionedElement = document.body

	var rightedge=document.body.clientWidth-event.clientX
	var bottomedge=document.body.clientHeight-event.clientY
	if (rightedge<oMenu.offsetWidth)
		oMenu.style.left=document.body.scrollLeft+event.clientX-oMenu.offsetWidth
	else
		oMenu.style.left=document.body.scrollLeft+event.clientX
	if (bottomedge<oMenu.offsetHeight)
		oMenu.style.top=document.body.scrollTop+event.clientY-oMenu.offsetHeight
	else
		oMenu.style.top=document.body.scrollTop+event.clientY
	oMenu.style.display=""		

	oMenu.style.visibility = "visible";

	if (document.onmousedown != null) {
		document.onmousedown();
	}
	document.onmousedown = pageClick;
}

function showMiniMenu(sUserId, sNickNm, sToUserId, sToNickNm) {
	showMenuEx(sUserId, sNickNm, sToUserId, sToNickNm, "M");
}

function showMenu(sUserId, sNickNm, sToUserId, sToNickNm, bLogin, strOrgUrl) {
	showMenuEx(sUserId, sNickNm, sToUserId, sToNickNm, "S", bLogin, strOrgUrl);
}

function hideMenu() {
	if (menuOn == true && overMenu == false) {
		menuOn = false;
		document.all.userMenu.style.visibility = "hidden";
		document.onmousedown = null;
	}
}

function delayedHideMenu()
{
	overMenu = false;
	setTimeout("hideMenu()", 1000);
}

function menuOver() {
	menuOn = true;
	overMenu = true;
}

function menuOut() {
	if (event.srcElement.contains(event.toElement))	return;
	overMenu = false;
	delayedHideMenu();
}

function itemOver(objItem) {
	itemOn = true;
	overMenu = true;
	objItem.style.color = menuInfo.FontColorOver;
	objItem.style.textDecoration = "underline";
}

function itemOut(objItem) {
	objItem.style.color = menuInfo.FontColor;
	objItem.style.textDecoration = "none";
}

function pageClick() {
	if (menuOn == true && overMenu == false) {
		hideMenu();
	}
}

function menuAction(strAction) {
	overMenu = false;
	hideMenu();

	switch (strAction) {
	case "userinfo":
		window.open(g_memosvr + "/MoUserDetail.asp?fromid="+userInfo.UserId+"&toid="+userInfo.ToUserId+"&fromnm="+fcEscape(userInfo.NickNm)+"&toname="+fcEscape(userInfo.ToNickNm), "_blank", "fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=550");
		break;
	case "addbuddy":
		if (userInfo.UserId.toLowerCase() == "guest")
		{
			alert("¸ÕÀú ·Î±×ÀÎÇÏ¼¼¿ä.");
			return;
		}
		if (userInfo.UserId == userInfo.ToUserId)
		{
			alert("ÀÚ½ÅÀ» Ä£±¸·Î Ãß°¡ÇÒ ¼ö ¾ø½À´Ï´Ù.");
			return;
		}
		window.open(g_hompysvr + "/hm/Manage/Buddy/AddBuddyForm.asp?id=" + userInfo.UserId + "&buddyid=" + userInfo.ToUserId + "&dontreload=Y", "AddBuddyWin", "fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=490,height=280");
		break;
	case "sendmemo":
//		window.open(g_memosvr + "/MoUserInfo.asp?fromid="+userInfo.UserId+"&toid="+userInfo.ToUserId+"&fromnm="+fcEscape(userInfo.NickNm)+"&toname="+fcEscape(userInfo.ToNickNm), "_blank", "fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=300");
		window.open(g_fgsvr + "/memo/FgMemoSendForm.asp?fromid="+userInfo.UserId+"&toid="+userInfo.ToUserId+"&fromnm="+fcEscape(userInfo.NickNm)+"&toname="+fcEscape(userInfo.ToNickNm), "_blank", "fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=458,height=595");
		break;
	case "sendsms":
		Mobile_PopEmotUp(userInfo.NickNm, '', '', '');
//			window.open(g_mobilesvr + "/message/mmsg.asp");
		break;
	case "sendmail":
		window.open(g_mailsvr + "/MessageCenter/Email/McSendMailForm.asp?toid="+userInfo.ToUserId);
		break;
	case "talk":
		var today = new Date();
		window.open(g_playsvr + "/chat/PeCtCreateIMChat.asp?chatIDType=U&touserid="+userInfo.ToUserId+"&tonickname="+fcEscape(userInfo.ToNickNm),
					"FcChatDateWindow_"+today.getTime(),
					"fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=630,height=500");
		break;
	case "invite":
		window.open(g_memosvr + "/MoSelectInviteChatRoom.asp?fromid="+userInfo.UserId+"&fromname="+fcEscape(userInfo.NickNm)+"&toid="+userInfo.ToUserId, "SelectInviteChatRoomWindow","fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=340,height=240");
		break;
	case "sendgift":
		window.open(g_pimssvr + "/myfreechal/pims/gift/digital/SelectItemCatPopUp.asp?OrgSelVal1=||"+userInfo.ToUserId, "SendGiftWindow","fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=606,height=340");
		break;
	case "block":
		window.open(g_memosvr + "/MoBlock.asp?userid="+userInfo.UserId+"&blackid="+userInfo.ToUserId, "BlockWindow","fullscreen=no,titlebar=no,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=240,height=240");
		break;
	case "telephone":
		window.open(g_msgrsvr + "/Dialpad/DialpadCall.asp?phonenum=","pop","toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=500,height=280");
	}
}

