var menuOn = false;
var overMenu = false;
var noViewMenu = false;
var menuInfo = {
	MenuWidth: MenuWidth = 100,
	MenuHeight: MenuHeight = 0,
	FontSize: FontSize = "9pt",
	FontColor: FontColor = "black",
	BgColor: BgColor = "#e6e6e6",
	FontColorBar: FontColor = "#ffffff",
	BgColorBar: BgColor = "#BB8A0B",
	FontColorOver: FontColor = "white",
	BgColorOver: BgColor = "blue",   //mouseover color
	BorderColor: BorderColor = "#A7A7A7",
	MenuItem: MenuItem = []
};
var actionStr = [];

makeMenu();


function makeMenu() {
	var sHTML;
	sHTML = "<div id=\"popupMenu\" style=\"position:absolute;width:"+menuInfo.MenuWidth+"px;height:"+menuInfo.MenuHeight+"px;color:"+menuInfo.FontColor+";background-color:"+menuInfo.BgColor+";border:1 solid "+menuInfo.BorderColor+";z-index:2;visibility:hidden\" onMouseOver=\"menuOver(this)\" onMouseOut=\"menuOut(this)\"></div>"
	document.writeln(sHTML);
}

function PopupMenu(menuIf, instr) {
  if (noViewMenu) return;
	var oMenu = document.all.popupMenu;
	var sHTML;
	var left;
	var top;

	var tmparr = instr.split(',');
	actionStr = tmparr;
	switch (menuIf)
	{
		case 'basic1':
			menuInfo.MenuItem = menuInfo_basic;
			break;
		case 'out':
			menuInfo.MenuItem = menuInfo_out;
			break;
		case 'old':
			menuInfo.MenuItem = menuInfo_old;
			break;
	}

	if (menuInfo.MenuItem.length > 4)
    oMenu.style.height = (menuInfo.MenuItem.length-4) * 18;
  else
    oMenu.style.height = (menuInfo.MenuItem.length-(menuInfo.MenuItem.length/2)) * 18;

  sHTML = '';
	for (var i = 0; i < menuInfo.MenuItem.length; i++) {
		if (menuInfo.MenuItem[i][0] == "") {
				menuInfo.MenuHeight += 1;
				sHTML += "<div style=\"position:relative;background-color:"+menuInfo.BgColor+";\"><table align=center cellspacing=0 cellpadding=0 border=\"0\" width=90%><tr><td height=1 bgcolor=#B5B2B5></td></tr><tr><td height=1 bgcolor=#ffffff></td></tr><tr><td height=2></td></tr></table></div>";
		} else {
				sHTML += "<div align=\"center\" style=\"font-size:"+menuInfo.FontSize+";font-family:±¼¸²;cursor:hand;font-weight:normal;padding:3px;\" onMouseOver=\"itemOver(this)\" onMouseOut=\"itemOut(this)\" onClick=\"menuAction('"+menuInfo.MenuItem[i][0]+"')\">"+menuInfo.MenuItem[i][1]+"</div>"
		}
	}

	oMenu.innerHTML = sHTML;

	left = event.x + document.body.scrollLeft + 20;
	if (left < 10) {
		left = 10;
	}
	else if (left + menuInfo.MenuWidth + 10 > document.body.scrollLeft + document.body.clientWidth) {
		left = document.body.clientWidth + document.body.scrollLeft - menuInfo.MenuWidth - 10;
	}

	top = event.y + document.body.scrollTop ;
	if (top < 10) {
		top = 10;
	}
	else if (top + menuInfo.MenuHeight > document.body.scrollTop + document.body.clientHeight) {
		top = document.body.clientHeight + document.body.scrollTop - menuInfo.MenuHeight - 10;
	}

	oMenu.style.left = left;
	oMenu.style.top = top;

	oMenu.style.visibility = "visible";
	document.onmousemove = function(){
		var popLeft = document.getElementById("popupMenu").style.left;
		popLeft = parseInt(popLeft.toString().replace("px",""));
		var tem_left = popLeft - event.clientX ;
		if(tem_left > 100 || tem_left < -100 ){
			pageClick();
		}
	}
	//document.onmousedown = pageClick;
}

function hideMenu() {
	menuOn = false;
	document.all.popupMenu.style.visibility = "hidden";
}

function menuOver() {
	menuOn = true;
	overMenu = true;
}

function menuOut() {
	if (event.srcElement.contains(event.toElement))	return;
	overMenu = false;
}

function itemOver(objItem) {
	objItem.style.color = menuInfo.FontColorOver;
	objItem.style.background = menuInfo.BgColorOver;
}

function itemOut(objItem) {
	objItem.style.color = menuInfo.FontColor;
	objItem.style.background = menuInfo.BgColor;
}

function pageClick() {
//	if (menuOn == true && overMenu == false) {
	if (overMenu == false) {
		hideMenu();
	}
}

function menuAction(strAction) {
	hideMenu();
	execByMenu(strAction,actionStr);
}

/*¸Þ´ºÆíÁý*/
var menuInfo_basic = [
		[ "1", "ÇÁ·ÎÇÊº¸±â" ],
		[ "", "", true ],
		[ "2", "¹®ÀÚ º¸³»±â" ],
		[ "3", "¸ÞÀÏ º¸³»±â" ],
		[ "4", "ÆÑ½º º¸³»±â" ],
		[ "7", "ÂÊÁöº¸³»±â" ]
	];
var menuInfo_out = [
		[ "5", "ÇÁ·ÎÇÊº¸±â" ],
		[ "", "", true ],
		[ "5", "¹®ÀÚ º¸³»±â" ],
		[ "5", "¸ÞÀÏ º¸³»±â" ],
		[ "5", "ÆÑ½º º¸³»±â" ],
		[ "5", "ÂÊÁöº¸³»±â" ]
]
var menuInfo_old = [
		[ "6", "ÇÁ·ÎÇÊº¸±â" ],
		[ "", "", true ],
		[ "6", "¹®ÀÚ º¸³»±â" ],
		[ "6", "¸ÞÀÏ º¸³»±â" ],
		[ "6", "ÆÑ½º º¸³»±â" ],
		[ "5", "ÂÊÁöº¸³»±â" ]
]
function execByMenu(execdiv,execstr)
{
  var tmparr;
  switch (execdiv)
  {
    /** ±âº» ¸Þ´º **/
    case '1':
      Go1(execstr[0],execstr[1]);
      break;
    case '2':
      Go2(execstr[0],execstr[1]);
      break;
	case '3':
	  Go3(execstr[0],execstr[1]);
	  break;
	case '4':
	  Go4(execstr[0],execstr[1]);
	  break;
	case '5':
	  Go5();
	  break;
 	case '6':
	  Go6();
	 case '7':
	  Go7(execstr[0],execstr[1]);
	  break;
 }
}
function Go1(idx,onoff) {
//	if(onoff == "on") {
//		var url = "./member_personal_on.php?iMemIdx=" + idx;
//	}else if(onoff == "off") {
//		var url = "./member_personal.php?iCMemIdx=" + idx;
//	}
//	location.href= url;
//	return;
	var w = 780;
	var h = 580;
	var x = ( screen.width - w ) / 2 - 10;
	var y = ( screen.height - h ) / 2 - 10;

	if(onoff == "on") {
		var url = "../member_info.htm?iMemIdx=" + idx;
	}else if(onoff == "off") {
		var url = "../member_info.htm?iCMemIdx=" + idx;
	}
	var exp = "width=" + w + ", height=" + h + ", top=" + y + ",left=" + x + ", status=no, resizable=yes, toolbar=no, scrollbars=no ";
	var popup = window.open( url, "_profile", exp);
	popup.focus();
	return;
}


function Go2(idx,onoff) {
	var url = "./addService.php?action=index.php&uid=" + idx + "&onoff=" + onoff + "&type=handp";
	location.href= url;
	return;
}

function Go3(idx,onoff) {
	var url = "./addService.php?action=email_index.php&uid=" + idx + "&onoff=" + onoff + "&type=email";
	location.href= url;
	return;
}
function Go7(idx,onoff) {

	var url = '/okmemo/index.html?receiveridx='+idx
	var w=650;
	var h=500;
	var x = ( screen.width - w ) / 2 - 10;
	var y = ( screen.height - h ) / 2 - 10;
	var exp = "width=" + w + ", height=" + h + ", top=" + y + ",left=" + x + ", resizable=yes,scrollbars=yes ";
	var popup = window.open( url, "wndMemo", exp);
	popup.focus();
	return;
}
function Go4(idx,onoff) {
	var url = "./addService.php?action=fax_index.php&uid=" + idx + "&onoff=" + onoff + "&type=fax";
	location.href= url;
	return;
}

function Go5() {
	alert('·Î±×ÀÎÇÏ¼¼¿ä.');
	return;
}
function Go6() {
	alert('2008³â 1¿ù 1ÀÏ ÀÌÈÄ °Ô½ÃÀÚ¿¡°Ô¸¸ »ç¿ë°¡´ÉÇÕ´Ï´Ù.');
	return;
}
