var NS4;
var IE4;
var mouse_top;
var mouse_left;
var scroll_top;
var scroll_left;
var event_id = "none";
var status_over = false;
var parent_menu_name = "menu_parent1";

var child_menu_array = ["menu_child1"];

var submenu_left_indent = 85;
var column_height = 18;
var submenu_top_indent = 0;
var mainmenu_top_indent = 0;
var menuover_bgcolor = "white";
var menuover_fgcolor = "blue";
var default_menuover_bgcolor = "white";
var default_menuover_fgcolor = "black";
var loginCheck;
var MemoID;

NS4 = (document.layers);
IE4 = (document.all);
isWin = (navigator.appVersion.indexOf("Win") != -1)

if (NS4) {
    document.captureEvents(Event.CLICK)
    document.onclick = MouseDown;
} else if (IE4) {
    document.onclick = MouseDown;
}

function startIt() {
}

function menuOver(ar_obj, MemoID) {
    status_over = true;
    changeColor(ar_obj);
    hideChild(event_id);
    viewSubMenu(event, ar_obj, MemoID);

}

function SubmenuOver(ar_obj) {
    status_over = true;
    changeColor(ar_obj);
}

function MouseDown(e) {
	event_target = event.srcElement;
    //event_target = event_target.toString();

    //event_menucheck = event_target.indexOf("javascript:MemoPopUp(");
    //event_filecheck = event_target.indexOf("javascript:filePopUp(");

    //if (!event_menucheck) parent_menu_name = "menu_parent";
    if (event_target.id == 'menuPopup') parent_menu_name = "menu_parent";
    if (event_target.id == 'filePopup') parent_menu_name = "file_parent";

    if (!status_over) {
        hideAll("menu_parent");
        hideAll("file_parent");
    }

    if (event_target.id == 'menuPopup') {
        if(loginCheck==true){
            viewMenu(event,  parent_menu_name);
        }
    } else if (event_target.id == 'filePopup') {
        viewMenu(event,  parent_menu_name);
    } else {
        if (!status_over) {
            hideAll("menu_parent");
            hideAll("file_parent");
        }
        return;
    }
}

function hideChild(MemoID) {
    if (event_id == "none") return;
    var menu_len = child_menu_array.length;
    for (i=0; i<menu_len; i++) eval(child_menu_array[i] + ".style.display = \"none\"");
}

function hideAll(menu_name) {
    eval(menu_name + ".style.display = \"none\"");
    if (event_id == "none") return;
    var menu_len = child_menu_array.length;
    for (i=0; i<menu_len; i++) eval(child_menu_array[i] + ".style.display = \"none\"");
}

function viewMenu(e, MemoID) {
    if (MemoID == "none") return;
    menuLocBod = window.document.body;
    xPos = menuLocBod.scrollLeft + event.clientX;
    yPos = event.clientY + menuLocBod.scrollTop;
    screen_height = window.document.body.offsetHeight;
    screen_width = window.document.body.offsetWidth;
    mouse_top = e.y;
    mouse_left = e.x;
    eval("mainmenu_top_indent = " + parent_menu_name + ".children[0].children[0].children.length");
    mainmenu_top_indent = mainmenu_top_indent * column_height;
    if (screen_height > mouse_top + mainmenu_top_indent)
        yPos = event.clientY + menuLocBod.scrollTop;
    else
        yPos = (event.clientY + menuLocBod.scrollTop) - mainmenu_top_indent;

    if (mouse_top - mainmenu_top_indent < 0)
        yPos = event.clientY + menuLocBod.scrollTop;


    eval(MemoID + ".style.pixelTop =" + yPos);
    eval(MemoID + ".style.pixelLeft =" + xPos);
    eval(MemoID + ".style.display = \"\"");
}

function viewSubMenu(e, ar_obj, MemoID) {
    if (MemoID == "none") return;
    event_id = MemoID;
    parent_top = menu_parent.style.pixelTop;
    parent_left = menu_parent.style.pixelLeft;
    child_top = ar_obj.style.pixelTop;
    child_left = ar_obj.style.pixelLeft;
    screen_height = window.document.body.offsetHeight;
    screen_width = window.document.body.offsetWidth;
    mouse_top = e.y;
    mouse_left = e.x;
    menuLocBod = window.document.body;
    xPos = menuLocBod.scrollLeft + parent_left + submenu_left_indent;
    eval("submenu_top_indent = " + MemoID + ".children[0].children[0].children.length");
    submenu_top_indent = submenu_top_indent * column_height;
    if (screen_height > mouse_top + submenu_top_indent)
        yPos = event.clientY + menuLocBod.scrollTop;
    else
        yPos = (event.clientY + menuLocBod.scrollTop) - submenu_top_indent;

    if (mouse_top - submenu_top_indent < 0)
        yPos = event.clientY + menuLocBod.scrollTop;

    eval(MemoID + ".style.pixelTop =" + yPos);
    eval(MemoID + ".style.pixelLeft =" + xPos);
    eval(MemoID + ".style.display = \"\"");
}

function menuOut(ar_obj) {
    status_over = false;
    changeColor(ar_obj);
}

function changeColor(ar_obj) {
    if (ar_obj.children[0].style.color == menuover_fgcolor) {
        ar_obj.children[0].style.color = default_menuover_fgcolor;
        ar_obj.children[0].style.backgroundColor = default_menuover_bgcolor;
    } else {
        ar_obj.children[0].style.backgroundColor = menuover_bgcolor;
        ar_obj.children[0].style.color = menuover_fgcolor;
    }
}

function MemoPopUp(RecvID,islogin) {
    user_id   = RecvID;
    loginCheck = islogin;
}

function MouseOnOverItem(key) {
    switch(key) {
        // 프로필 보기
        case "ShowProfile":
             ShowProfile(user_id,loginCheck);
             break;
        // 쪽지 보내기창
        case "MemoSendPop":
            ShowSendMemo(user_id,loginCheck);
            break;
        // 웹메일 보내기
        case "MailSendPop":
            ShowSendMail(user_id, loginCheck);
            break;
        default:break;
    }
    return;
}
// 프로필 보기
function ShowProfile(user_id,loginCheck)
{
    if (loginCheck)
    {
        //alert(parameter1+' '+parameter2);
        window.open('/devmain/mento/manager/profile/profile_detail.jsp?puser_id=' + user_id, '','width=540,height=450,resizable=no,scrollbars=yes');
    }
    else
    {
        alert("로그인 후 이용해 주세요.");
    }
}
// 쪽지 보내기
function ShowSendMemo(user_id,loginCheck)
{
    if (loginCheck)
    {
        window.open('/devmain/note/send/note_send_form.jsp?dataSeq=' + user_id, '','width=540,height=400,resizable=no,scrollbars=no');
    }
    else
    {
        alert("로그인 후 이용해 주세요.");
    }
}
// 웹메일 발송
function ShowSendMail(user_id,loginCheck)
{
    if (loginCheck)
    {
        window.open('/devmain/email/mail.jsp?dataSeq=' + user_id, '','width=540,height=430,resizable=no,scrollbars=no');
    }
    else
    {
        alert("로그인 후 이용해 주세요.");
    }
}

