if (typeof(SIDEVIEW_JS) == 'undefined') // ÇÑ¹ø¸¸ ½ÇÇà
{
    if (typeof jb2_is_member == 'undefined')
        alert('jb2_is_member º¯¼ö°¡ ¼±¾ðµÇÁö ¾Ê¾Ò½À´Ï´Ù.');
    if (typeof jb2_path == 'undefined')
        alert('jb2_path º¯¼ö°¡ ¼±¾ðµÇÁö ¾Ê¾Ò½À´Ï´Ù.');

    var SIDEVIEW_JS = true;

    // È¸¿øÀÌ¸§ Å¬¸¯½Ã È¸¿øÁ¤º¸µîÀ» º¸¿©ÁÖ´Â ·¹ÀÌ¾î
    function insertHead(name, text, evt) 
    {
        var idx = this.heads.length;
        var row = new SideViewRow(-idx, name, text, evt);
        this.heads[idx] = row;
        return row;
    }

    function insertTail(name, evt) 
    {
        var idx = this.tails.length;
        var row = new SideViewRow(idx, name, evt);
        this.tails[idx] = row;
        return row;
    }

    function SideViewRow(idx, name, onclickEvent) 
    {
        this.idx = idx;
        this.name = name;
        this.onclickEvent = onclickEvent;
        this.renderRow = renderRow;
        
        this.isVisible = true;
        this.isDim = false;
    }

    function renderRow()
    {
        if (!this.isVisible)
            return "";

        (this.name == 'mail' || this.name == 'report' || this.name == 'allow1') ? clsName='pl5' : clsName='bd_dash';
        var str = "<li class='"+clsName+"' id='sideViewRow_"+this.name+"'><span>"+this.onclickEvent+"</span></li>";
        return str;
    }

    function showSideView(curObj, mb_no, name, note, email, homepage, blog)
    {
        var sideView = new SideView('nameContextMenu', curObj, mb_no, name, note, email, homepage, blog);
        sideView.showLayer();
    }

    function SideView(targetObj, curObj, mb_no, name, note, email, homepage, blog)
    {
        this.targetObj = targetObj;
        this.curObj = curObj;
        this.mb_no = mb_no;
        var name = name.replace(/¡¦/g,"");
        this.name = name;
        this.note = note;
        this.email = email;
        this.homepage = homepage;
        this.blog = blog;
        this.clsName = 'sideview';
        this.showLayer = showLayer;
        this.makeNameContextMenus = makeNameContextMenus;
        this.heads = new Array();
        this.insertHead = insertHead;
        this.tails = new Array();
        this.insertTail = insertTail;
        this.getRow = getRow;
        this.hideRow = hideRow;
        this.dimRow = dimRow;

		/* // ÇÁ·ÎÇÊ
        if (mb_id)
            this.insertTail("profile", "<a href=\"javascript:win_profile('"+mb_id+"');\">ÇÁ·ÎÇÊº¸±â</a>");
        */

        // ¸àÅä·Î±×
        if (mb_no)
            this.insertTail("mentolog", "<a href=\"javascript:win_mentolog("+mb_no+")\">¸àÅä·Î±×º¸±â</a>");

        // È¨ÆäÀÌÁö
        if (homepage)
            this.insertTail("homepage", "<a href=\"javascript:;\" onclick=\"window.open('"+homepage+"');\">¹Ì´ÏÈ¨ÇÇ</a>");
        // ºí·Î±×
        if (blog)
            this.insertTail("blog", "<a href=\"javascript:;\" onclick=\"window.open('"+blog+"');\">ºí·Î±×</a>");
        // ÂÊÁöº¸³»±â
        if (note)
            // ºÒ¿©¿ì ÀÚ¹Ù½ºÅ©¸³Æ®Ã¢ÀÌ ¶ß´Â ¿À·ù¸¦ ¼öÁ¤
            this.insertTail("note", "<a href=\"javascript:win_note("+mb_no+");\">ÂÊÁöº¸³»±â</a>");
        // ¸ÞÀÏº¸³»±â
        //if (email)
        //    this.insertTail("mail", "<a href=\"javascript:win_formmail('"+mb_id+"','"+name+"','"+email+"');\">¸ÞÀÏº¸³»±â</a>");

        /*
        // ÃÖ°í°ü¸®ÀÚÀÏ °æ¿ì
        if (jb2_is_admin == "super") {
            // È¸¿øÁ¤º¸º¯°æ
            if (mb_id)
                this.insertTail("modify", "<a href='"+jb2_path+"/" + jb2_admin + "/member_form.php?w=u&mb_id="+mb_id+"' target='_blank'>È¸¿øÁ¤º¸º¯°æ</a>");
            // Æ÷ÀÎÆ®³»¿ª
            if (mb_id)
                this.insertTail("point", "<a href='"+jb2_path+"/" + jb2_admin + "/point_list.php?sfl=mb_id&stx="+mb_id+"' target='_blank'>Æ÷ÀÎÆ®³»¿ª</a>");
        }
        */
    }

    function showLayer() 
    {
        clickAreaCheck = true;
        var oSideViewLayer = document.getElementById(this.targetObj);
        var oBody = document.body;
        var iTop = 0;
        var iLeft = 0;

        if (oSideViewLayer == null) {
            oSideViewLayer = document.createElement("DIV");
            oSideViewLayer.id = this.targetObj;
            oSideViewLayer.style.position = 'absolute';
            oBody.appendChild(oSideViewLayer);
        }
        oSideViewLayer.innerHTML = this.makeNameContextMenus();

        if (jb2_is_gecko) {
            iTop = getAbsoluteTop(this.curObj) + this.curObj.offsetHeight - 13;
        } else {
            if (getAbsoluteTop(this.curObj) + this.curObj.offsetHeight + oSideViewLayer.scrollHeight + 5 > oBody.scrollHeight)
                iTop = getAbsoluteTop(this.curObj) - oSideViewLayer.scrollHeight;
            else
                iTop = getAbsoluteTop(this.curObj) + this.curObj.offsetHeight - 15;
        }
        iLeft = getAbsoluteLeft(this.curObj) - this.curObj.offsetWidth;

        oSideViewLayer.style.top = iTop + 'px';
        oSideViewLayer.style.left = iLeft + 'px';

        divDisplay(this.targetObj, 'block');

        //selectBoxHidden(this.targetObj);
    }

    function getAbsoluteTop(oNode)
    {
        var oCurrentNode=oNode;
        var iTop=0; /*
        while(oCurrentNode.tagName!="BODY") {
            iTop+=oCurrentNode.offsetTop - oCurrentNode.scrollTop;
            oCurrentNode=oCurrentNode.offsetParent;
        } */

		if(oCurrentNode.offsetParent){
			do{
				if(oCurrentNode.tagName!="body")
					iTop += oCurrentNode.offsetTop - oCurrentNode.scrollTop;
			}
			while(oCurrentNode = oCurrentNode.offsetParent);
		}
        return iTop;
    }

    function getAbsoluteLeft(oNode)
    {
        var oCurrentNode=oNode;
        var iLeft=0;
        iLeft+=oCurrentNode.offsetWidth;/*
        while(oCurrentNode.tagName!="BODY") {
            iLeft+=oCurrentNode.offsetLeft;
            oCurrentNode=oCurrentNode.offsetParent;
        }*/

		if(oCurrentNode.offsetParent){
			do{
				if(oCurrentNode.tagName!="body")
					iLeft += oCurrentNode.offsetLeft;
			}
			while(oCurrentNode = oCurrentNode.offsetParent);
		}
        return iLeft;
   }


    function makeNameContextMenus() 
    {
        var str = "<ul id='"+this.clsName+"'>";
        
        var i=0;
        for (i=this.heads.length - 1; i >= 0; i--)
            str += this.heads[i].renderRow();
       
        var j=0;
        for (j=0; j < this.tails.length; j++)
            str += this.tails[j].renderRow();
        
        str += "</ul>";

        return str;
    }

    function getRow(name) 
    {
        var i = 0;
        var row = null;
        for (i=0; i<this.heads.length; ++i) 
        {
            row = this.heads[i];
            if (row.name == name) return row;
        }

        for (i=0; i<this.tails.length; ++i) 
        {
            row = this.tails[i];
            if (row.name == name) return row;
        }
        return row;
    }

    function hideRow(name) 
    {
        var row = this.getRow(name);
        if (row != null)
            row.isVisible = false;
    }

    function dimRow(name) 
    {
        var row = this.getRow(name);
        if (row != null)
            row.isDim = true;
    }

    // Internet Explorer¿¡¼­ ¼¿·ºÆ®¹Ú½º¿Í ·¹ÀÌ¾î°¡ °ãÄ¥½Ã ·¹ÀÌ¾î°¡ ¼¿·ºÆ® ¹Ú½º µÚ·Î ¼û´Â Çö»óÀ» ÇØ°áÇÏ´Â ÇÔ¼ö
    // ·¹ÀÌ¾î°¡ ¼¿·ºÆ® ¹Ú½º¸¦ Ä§¹üÇÏ¸é ¼¿·ºÆ® ¹Ú½º¸¦ hidden ½ÃÅ´
    // <div id=LayerID style="display:none; position:absolute;" onpropertychange="selectBoxHidden('LayerID')">
    function selectBoxHidden(layer_id) 
    {
        //var ly = eval(layer_id);
        var ly = document.getElementById(layer_id);

        // ·¹ÀÌ¾î ÁÂÇ¥
        var ly_left   = ly.offsetLeft;
        var ly_top    = ly.offsetTop;
        var ly_right  = ly.offsetLeft + ly.offsetWidth;
        var ly_bottom = ly.offsetTop + ly.offsetHeight;

        // ¼¿·ºÆ®¹Ú½ºÀÇ ÁÂÇ¥
        var el;

        for (i=0; i<document.forms.length; i++) {
            for (k=0; k<document.forms[i].length; k++) {
                el = document.forms[i].elements[k];
                if (el.type == "select-one") {
                    var el_left = el_top = 0;
                    var obj = el;
                    if (obj.offsetParent) {
                        while (obj.offsetParent) {
                            el_left += obj.offsetLeft;
                            el_top  += obj.offsetTop;
                            obj = obj.offsetParent;
                        }
                    }
                    el_left   += el.clientLeft;
                    el_top    += el.clientTop;
                    el_right  = el_left + el.clientWidth;
                    el_bottom = el_top + el.clientHeight;

                    // ÁÂÇ¥¸¦ µûÁ® ·¹ÀÌ¾î°¡ ¼¿·ºÆ® ¹Ú½º¸¦ Ä§¹üÇßÀ¸¸é ¼¿·ºÆ® ¹Ú½º¸¦ hidden ½ÃÅ´
                    if ( (el_left >= ly_left && el_top >= ly_top && el_left <= ly_right && el_top <= ly_bottom) || 
                         (el_right >= ly_left && el_right <= ly_right && el_top >= ly_top && el_top <= ly_bottom) ||
                         (el_left >= ly_left && el_bottom >= ly_top && el_right <= ly_right && el_bottom <= ly_bottom) ||
                         (el_left >= ly_left && el_left <= ly_right && el_bottom >= ly_top && el_bottom <= ly_bottom) ||
                         (el_top <= ly_bottom && el_left <= ly_left && el_right >= ly_right && el_bottom >= ly_top)
                        )
                        el.style.visibility = 'hidden';
                }
            }
        }
    }

    // °¨Ãß¾îÁø ¼¿·ºÆ® ¹Ú½º¸¦ ¸ðµÎ º¸ÀÌ°Ô ÇÔ
    function selectBoxVisible()
    {
        for (i=0; i<document.forms.length; i++)
        {
            for (k=0; k<document.forms[i].length; k++)
            {
                el = document.forms[i].elements[k];
                if (el.type == "select-one" && el.style.visibility == 'hidden')
                    el.style.visibility = 'visible';
            }
        }
    }


    function divDisplay(id, act)
    {
        selectBoxVisible();

        document.getElementById(id).style.display = act;
    }

    function hideSideView() 
    {
        if (document.getElementById("nameContextMenu"))
            divDisplay ("nameContextMenu", 'none');
    }

    var clickAreaCheck = false;
    document.onclick = function()
    {
        if (!clickAreaCheck) 
            hideSideView();
        else 
            clickAreaCheck = false;
    }

    /* °Ô½Ã¹° */
    function showSideView2(curObj, wr_id, url)
    {
        var sideView = new SideView2('nameContextMenu', curObj, wr_id, url);
        sideView.showLayer();
    }

    function SideView2(targetObj, curObj, wr_id, url)
    {
        this.targetObj = targetObj;
        this.curObj = curObj;
        this.clsName = 'frmNData';
        this.showLayer = showLayer;
        this.makeNameContextMenus = makeNameContextMenus;
        this.heads = new Array();
        this.insertHead = insertHead;
        this.tails = new Array();
        this.insertTail = insertTail;
        this.getRow = getRow;
        this.hideRow = hideRow;
        this.dimRow = dimRow;

        if (jb2_table) {
            // ÇÁ¸°Æ®
            this.insertTail("print", "<a href=\"javascript:;\" onclick=\"win_print("+wr_id+");\">ÇÁ¸°Æ® ÇÏ±â</a>");

            // ÅÙº¼Ã¥²ÈÀÌ ´ã±â
            if (jb2_is_member)
                this.insertTail("scrap", "<a href=\"javascript:win_scrap('"+jb2_table+"',"+wr_id+");\">ÅÙº¼Ã¥²ÈÀÌ ´ã±â</a>");

            // ½Å°íÇÏ±â
            this.insertTail("report", "<a href=\"javascript:;\" onclick=\"win_report(escape('"+url+"'));\">½Å°íÇÏ±â</a>");
        }
    }

    /* ±â´É¼³Á¤ */
    function showOptionSelect(curObj,hidObj,flag)
    {
        var sideView = new SideView3('nameContextMenu', curObj,hidObj,flag);
        sideView.showLayer();
    }

    function SideView3(targetObj,curObj,hidObj,flag)
    {
        this.targetObj = targetObj;
        this.curObj = curObj;
        this.clsName = 'frmOption';
        this.showLayer = showLayer;
        this.makeNameContextMenus = makeNameContextMenus;
        this.heads = new Array();
        this.insertHead = insertHead;
        this.tails = new Array();
        this.insertTail = insertTail;
        this.getRow = getRow;
        this.hideRow = hideRow;
        this.dimRow = dimRow;

        var msg = Array();
        if (flag)
             msg = ['Çã¿ë','ºñÇã¿ë'];
        else {
             msg = ['»ç¿ë','»ç¿ë ¾ÈÇÔ'];
             this.clsName = 'frmOption2';
        }

        if (jb2_table) {
            var clsName = '';
            for (var i = 0; i < msg.length; i++)
            {
                cName = (i < msg.length - 1) ? 'bg_dash' : 'bg_none';
                this.insertTail("allow"+i, "<span class=\""+cName+"\"onclick=\"setSelectOption('"+curObj.id+"','"+hidObj+"',"+flag+","+i+");\">"+msg[i]+"</span>");
            }
        }
    }

    function setSelectOption(obj,hobj,flag,val) {
        var msg = Array();
        msg = (flag) ? ['Çã¿ë','ºñÇã¿ë'] : ['»ç¿ë','»ç¿ë ¾ÈÇÔ'];

        if (val) {
            $(obj).className = 'deny';
            $(obj).update(msg[1]);
            $('write_'+hobj).value = 0;
        } else {
            $(obj).className = 'allow';
            $(obj).update(msg[0]);
            $('write_'+hobj).value = 1;
        }
    }
}

