var menuGo = 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=\"menuStop(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;
	}

	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.documentElement.scrollLeft + 20;
	if (left < 10) {
		left = 10;
	}
	else if (left + menuInfo.MenuWidth + 10 > document.documentElement.scrollLeft + document.documentElement.clientWidth) {
		left = document.documentElement.clientWidth + document.documentElement.scrollLeft - menuInfo.MenuWidth - 10;
	}

	top = event.y + document.documentElement.scrollTop ;
	if (top < 10) {
		top = 10;
	}
	else if (top + menuInfo.MenuHeight > document.documentElement.scrollTop + document.documentElement.clientHeight) {
		top = document.documentElement.clientHeight + document.documentElement.scrollTop - menuInfo.MenuHeight - 10;
	}

	oMenu.style.left = left;
	oMenu.style.top = top;

	oMenu.style.visibility = "visible";
	document.onmousedown = pageClick;
}

function hideMenu() {
	menuGo = false;
	document.all.popupMenu.style.visibility = "hidden";
}

function menuOver() {
	menuGo = true;
	overMenu = true;
}

function menuStop() {
	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 (menuGo == true && overMenu == false) {
		hideMenu();
	}
}

function menuAction(strAction) {
	hideMenu();
	execByMenu(strAction,actionStr);
}

/*¸Þ´ºÆíÁý*/
var menuInfo_basic = [
		[ "1", "ÇÁ·ÎÇÊº¸±â" ],
		[ "", "", true ],
		[ "2", "¹®ÀÚ º¸³»±â" ],
		[ "3", "¸ÞÀÏ º¸³»±â" ],
		[ "4", "ÆÑ½º º¸³»±â" ]
	];
var menuInfo_out = [	
		[ "5", "ÇÁ·ÎÇÊº¸±â" ],
		[ "", "", true ],
		[ "5", "¹®ÀÚ º¸³»±â" ],
		[ "5", "¸ÞÀÏ º¸³»±â" ],
		[ "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;
  }
}	

function Go1(idx,onoff) {
	var w = 420;
	var h = 600;
	var x = ( screen.width - w ) / 2 - 10;
	var y = ( screen.height - h ) / 2 - 10;
	
	if(onoff == "on") {
		var url = "./member_personal_on.php?iMemIdx=" + idx;
	}else if(onoff == "off") {
		var url = "./member_personal.php?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&uid=" + idx + "&onoff=" + onoff + "&type=handp";
	location.href= url;
	return;
}

function Go3(idx,onoff) {
	var url = "./addService.php?action=email_index&uid=" + idx + "&onoff=" + onoff + "&type=email";
	location.href= url;
	return;
}

function Go4(idx,onoff) {
	var url = "./addService.php?action=fax_index&uid=" + idx + "&onoff=" + onoff + "&type=fax";
	location.href= url;
	return;
}

function Go5() {
	alert('·Î±×ÀÎÇÏ¼¼¿ä.');
	return;
}
