﻿function $(elem){
    	return document.getElementById(elem);
	}
	function Login(isbackDiv){
		if($('floatDiv')==null){
			var floatDiv = document.createElement('div');
			floatDiv.id = "floatDiv"; 
			floatDiv.style.position = "absolute";
			floatDiv.style.width = 300 + "px";
			floatDiv.style.height = 200 + "px";
			floatDiv.style.left = (document.documentElement.clientWidth/2 + document.documentElement.scrollLeft - 150) +"px";
			floatDiv.style.top = (document.documentElement.clientHeight/3 + document.documentElement.scrollTop) +"px";
			floatDiv.style.zIndex  = 1001;
			//登录界面代码,http://www.pc123.org原创制作
			var loginText = "<div id=\"headDiv\" onmousedown=\"moveDiv(event,'floatDiv');\"><h3>用户登录</h3><span><a href=\"javascript:void(null)\" onclick=\"CloseFloatDiv('floatDiv')\"><img src=\"../img/close.gif\" alt=\"关闭窗口\" border=\"0\" /></a></span></div>";
			loginText += "<div id=\"bodyDiv\">";
			loginText += "";
			loginText += "<input type=\"hidden\" name=\"fmdo\" value=\"login\" />";
			loginText += "<input type=\"hidden\" name=\"dopost\" value=\"login\" />";
			loginText += "<input type=\"hidden\" name=\"gourl\" value=\"\" />";
			loginText += "<ul><li>用户名：<input id=\"userid\" name=\"userid\" class=\"tbx\" type=\"text\" maxlength=\"20\"  onkeydown=\"uidKeydown(event)\"/></li>";
			loginText += "<li>密&nbsp;&nbsp;码：<input id=\"pwd\" name=\"pwd\" class=\"tbx\" type=\"password\" maxlength=\"20\" onkeydown=\"pwdKeydown(event)\"/></li>";
			loginText += "<li>验证码：<input id=\"vdcode\" name=\"vdcode\" class=\"code\" type=\"text\" size=\"4\" maxlength=\"4\" onkeydown=\"vcodeKeydown(event);javascript:return keyboard_num(this, 4, event);\" style=\"ime-mode:disabled;\"/>&nbsp;";
			loginText += "<img src=\"VCode.aspx?r='+Math.random();\" onclick=\"src='VCode.aspx?r='+Math.random();\" style=\"cursor:pointer\" alt=\"看不清验证码？点击图片刷新\" />";
			loginText += "</li></ul>";
			loginText += "<input id=\"btnSubmit\" type=\"button\" name=\"btnLogin\" class=\"submit\" value=\"\" onclick=\"if(CheckLogin()){CallServer(sval())}\" />&nbsp;";
			loginText += "<a href=\"Reg.aspx\">注册新用户</a>|<a href=\"Login.aspx\">标准登录</a>";
			loginText += "";
			loginText += "</div>";		
			floatDiv.innerHTML = loginText;
			document.body.appendChild(floatDiv);
			$("userid").focus();
		}
		else{
			$('floatDiv').style.display = "block";
		}
		if($('backDiv')==null && isbackDiv ==true){
			var backDiv = document.createElement('div');
			backDiv.id = "backDiv";
			backDiv.style.backgroundColor = "Black";
			backDiv.style.filter = "alpha(opacity=70)";
			backDiv.style.MozOpacity = "0.70";
			backDiv.style.position = "absolute";
			backDiv.style.left = "0px";
			backDiv.style.top = "0px";
			backDiv.style.width = Math.max(document.body.scrollWidth, document.documentElement.clientWidth) +"px";
			backDiv.style.height = Math.max(document.body.scrollHeight, document.documentElement.clientHeight)+"px";
			document.body.appendChild(backDiv);
			$('backDiv').style.zIndex = 1000;
		}
		else if(isbackDiv ==true){
			$('backDiv').style.display = "block";
		}		
	}
	function moveDiv(event, elem)
	{
		$('floatDiv').style.filter = "alpha(opacity=50)";
		var oObj = $(elem);	
		oObj.onmousemove = mousemove;
		oObj.onmouseup = mouseup;
		oObj.setCapture ? oObj.setCapture() : function(){};
		oEvent = window.event ? window.event : event;
		var dragData = {x : oEvent.clientX, y : oEvent.clientY};
		var backData = {x : parseInt(oObj.style.top), y : parseInt(oObj.style.left)};
		function mousemove()
		{
			var oEvent = window.event ? window.event : event;
			var iLeft = oEvent.clientX - dragData["x"] + parseInt(oObj.style.left);
			var iTop = oEvent.clientY - dragData["y"] + parseInt(oObj.style.top);
			oObj.style.left = iLeft;
			oObj.style.top = iTop;
			dragData = {x: oEvent.clientX, y: oEvent.clientY};
		}
		function mouseup()
		{
			var oEvent = window.event ? window.event : event;
			oObj.onmousemove = null;
			oObj.onmouseup = null;
			$('floatDiv').style.filter = "";
			if(oEvent.clientX < 1 || oEvent.clientY < 1)
			{
				oObj.style.left = backData.y;
				oObj.style.top = backData.x;
			}
				oObj.releaseCapture ? oObj.releaseCapture() : function(){};
		}
	}
	function CloseFloatDiv(){
		$('floatDiv').style.display = "none";
		if($('backDiv')){
			$('backDiv').style.display = "none";
		}
	}
	
	function CheckLogin()
	{
    
    
 var usnm = $("userid").value;
        var uspwd = $("pwd").value;
         var ckcode = $("vdcode").value;
        if(usnm=="")
            { 
                alert("请输入用户名");
                $("userid").focus();
                  return false;
            }
        else if(uspwd=="")
            {
                alert("请输入密码");
                $("pwd").focus();
                
          return false;
            }
             else if(ckcode=="")
            {
                alert("请验证码");
                $("vdcode").focus();
                
               return false;
            }
            return true;
	}
	function vcodeKeydown(e)
{
   var ev = e || window.event;
   ev.keyCode==13 && $('btnSubmit').click(); 
}
function uidKeydown(e)
{
   var ev = e || window.event;
   ev.keyCode==13 && $("pwd").focus(); 
}
function pwdKeydown(e)
{
   var ev = e || window.event;
   ev.keyCode==13 && $("vdcode").focus(); 
}
function sval()
{
    id=$("userid").value;
     pd=$("pwd").value;
   vc=$("vdcode").value;
   arg=id+";"+pd+";"+vc;
   return arg
}
