﻿
var dragable = false,_x = 0,_y = 0,pos;
var _offsetX = 0,_offsetY = 0,objRef = null;

document.onmousedown = function(e)
{
    e = window.event || e;
    var obj = e.target || e.srcElement;
    if(null == obj) return;
    dragable = false;
    while(obj)
    {
        if("TD" == obj.tagName) break;
        obj = obj.parentNode;
    }
    if(obj&&("_DIALOG_TITLE" == obj.id))
    {
        _x = e.clientX;
        _y = e.clientY;
        while(obj.id != "_DIALOG_BODY") obj = obj.parentNode;
        pos = GetAbsPos(obj);
        _offsetX = pos.Left
        _offsetY = pos.Top;
        dragable = true;
        objRef = obj;
    }
}
document.onmousemove = function(e)
{
    e = window.event || e;
    if(!dragable);
    if(null == objRef) return;
    if(e.button > 1) return (objRef = null);
    objRef.style.top = (_offsetY + e.clientY - _y) + 'px';
    objRef.style.left = (_offsetX + e.clientX - _x) + 'px';
}
document.onmouseup = function(e)
{
    dragable = false;
    objRef = null;
}

function HideShow(flag)
{
    if (null == document.all) return;
    var els = document.all;
    for (var i = 0, l = els.length; i < l; i++)
    {
        if (els[i].tagName.match(/^(SELECT)|(OBJECT)|(IFRAME)$/gi) == null) continue;
        try
        {
            els[i].style.visibility = flag ? "hidden" : "visible";
        }
        catch(e) {}
    }
}

function ShowLoginBox()
{
    var obj = GetE('_LDiv');
    if (null == obj) return;
    
    var shtml = '';
    
    if (null == GetE('_DIALOG_BODY'))
    {
        shtml += '<table width="406" id="_DIALOG_BODY" height="330" border="0" align="center" cellpadding="0" cellspacing="0" style="display:none;background-image:url(http://user.artxun.com/bg/box_bg.gif);background-repeat:no-repeat;position:absolute;z-index:999999;">';
        shtml += '<tr><td width="362" height="26" style="cursor:move;" id="_DIALOG_TITLE" ondragstart="return false;"><span style="font-weight:bold;font-size:14px;font-family:宋体;color:#000000;">&nbsp;博宝用户登陆</span></td><td width="32" align="center"><a href="javascript:;" onclick="CloseBox()" target="_self"><img src="http://user.artxun.com/bg/close.gif" alt="关闭" width="16" height="16" border="0" /></a>';
        shtml += '</td></tr><tr><td height="273" colspan="2" valign="top"><form id="_loginform" name="_loginform" method="post" action="http://user.artxun.com/servlet/Login?return=1" onsubmit="return DoUserLogin(this);"><table width="100%" border="0" align="center" cellpadding="4" cellspacing="0">';
        shtml += '<tr><td height="30" colspan="2" align="center"><span style="font-weight:bold;font-size:14px;font-family:宋体;color:#000000;">博宝注册用户登陆</span></td></tr><tr><td width="123" height="26" style="font-weight:bold;font-size:12px;font-family:宋体;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;用户名：</td><td width="261"><input name="username" style="width:160px;" type="text" id="username" /></td></tr>';
        shtml += '<tr><td height="26" style="font-weight:bold;font-size:12px;font-family:宋体;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;码：</td><td><input name="password" type="password" id="password" style="width:160px;" /></td></tr><tr><td height="26" colspan="2" align="left" style="font-weight:bold;font-size:12px;font-family:宋体;color:#000000;">&nbsp;&nbsp;&nbsp;<input type="checkbox" name="rememberme" value="1" id="rememberme" />';
        shtml += '记住我的登录状态</td></tr><tr><td>&nbsp;</td><td height="26"><input type="submit" name="Submit" value="&nbsp;登&nbsp;陆&nbsp;" />&nbsp;<a href="http://user.artxun.com/forgetpassword.jsp" target="_blank">忘记密码？</a></td></tr>';
        shtml += '<tr><td colspan="2" height="20"><hr width="85%" /></td></tr><tr height="26"><td colspan="2" style="font-weight:bold;font-size:12px;font-family:宋体;color:#000000;">&nbsp;&nbsp;&nbsp;&nbsp;没有博宝帐号？</td></tr>';
        shtml += '<tr><td colspan="2" align="center" height="30"><input type="button" name="" value="马上注册博宝帐号!" onclick="location.href=\'http://user.artxun.com/register.jsp\'" /><br /><br /><div id="_tip" align="center" style="font-weight:bold;color:#ff0000;font-size:9pt;"></div></td></tr></table></form></td></tr></table>';
        obj.innerHTML = shtml;
    }
    
    HideShow(true);
    
    with (GetE('_MDiv').style)
    {
        position = 'absolute';
        zIndex = 999998;
        backgroundColor = '#efefef';
        filter = 'alpha(opacity=50)';
	opacity = '0.5';
        width = document.body.scrollWidth + 'px';
        height = document.body.scrollHeight + 'px';
        top = '0px';
        left = '0px';
        display = '';
    }
    
    obj = GetE('_DIALOG_BODY');
    with (obj.style)
    {
        top = ((document.body.scrollTop == 0 ? document.documentElement.scrollTop : document.body.scrollTop) + (document.documentElement.clientHeight / 2) - (330 / 2)) + 'px';
        left = ((document.body.scrollLeft == 0 ? document.documentElement.scrollLeft : document.body.scrollLeft) + (document.documentElement.clientWidth / 2) - (406 / 2)) + 'px';
        display = '';
    }
}

function CloseBox()
{
    HideShow(false);
    var obj = GetE('_DIALOG_BODY');
    if (obj) obj.style.display = 'none';
    if(GetE('_MDiv')) GetE('_MDiv').style.display = 'none';
}
