// JavaScript Document
function Fid(id){
return document.getElementById(id);}
function hiddenLoginWnd(){
var e=Fid('login_container');
e.style.display="none";}
function getv(imgcode)
	{
	    
		
		imgcode.src="code.aspx?"+Math.random();
				
	}
function mask_form()
{
	
	
	var newMask  = document.createElement("div");

  	newMask.id = "mask";

 	 newMask.style.width = document.body.scrollWidth + "px";
 	 newMask.style.height = (document.body.scrollHeight > document.body.clientHeight)?document.body.scrollHeight:document.body.clientHeight + "px";
 	 newMask.style.filter = "alpha(opacity=30)";
 	 newMask.style.opacity = "0.30";
  	 newMask.className ="mask";
	 document.body.appendChild(newMask);
}
function closewin()
{
	if(Fid('mask'))
	{
		var e=Fid('mask');
		document.body.removeChild(e);
	}
	if(Fid('login_container'))
	{
		var e=Fid('login_container');
		document.body.removeChild(e);
	}
	
}
function form_login()
	{
	    
	    if(form_checkform())
	    form_updateTotal();
	}
	function form_checkform()
	{

        
	    var struserid=document.getElementById('form_userid').value;
    
        struserid = String(struserid).replace(/(^\s*)|(\s*$)/g,"");
        
        var struserwd=document.getElementById('form_userpwd').value;
    
        struserwd = String(struserwd).replace(/(^\s*)|(\s*$)/g,"");
        
        var strcode=document.getElementById('form_codeid').value;
    
        strcode = String(strcode).replace(/(^\s*)|(\s*$)/g,"");
        
        if(struserid=='')
        {
            alert('请正确填写用户名!');
            return false;
        }
        if(struserwd=='')
        {
            alert('请正确填写密码!');
            return false;
        }
        if(strcode=='')
        {
            alert('请正确填写图片验证码!');
            return false;
        }
        return true;
       
	}
	 var xmlHttp;
        function form_updateTotal()
        {
            
                if(window.ActiveXObject)
                {
                    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                }
                else if(window.XMLHttpRequest)
                {
                    xmlHttp=new XMLHttpRequest();
                }
           
            
            url="checkuser.aspx?uid="+document.getElementById('form_userid').value+"&pwd="+document.getElementById('form_userpwd').value+"&code="+document.getElementById('form_codeid').value+"&id="+'form'+'&type=0';
            xmlHttp.open("GET",url,true);
            xmlHttp.onreadystatechange=form_doUpdate;
            xmlHttp.send();
           
            
            
        }
        function form_doUpdate()
        {
               
            
            if(xmlHttp.readyState==4)
            {
                document.getElementById('ul_loginfo').style.display = '';
                document.getElementById('ul_loading').style.display = 'none';
                var e=document.getElementById('lbltishi');
                switch(xmlHttp.responseText)
                {
                    case '1':
                        e.innerHTML='<img src="images/cha.gif"/>验证码错误!';
                        getv(document.getElementById('img_code')); 
                        break;
                    case '2':
                        e.innerHTML='<img src="images/cha.gif"/>用户名或密码错误!';
                        getv(document.getElementById('img_code'));  
                        break;
                    case '3':
                        e.innerHTML='<img src="images/cha.gif"/>登陆错误!';
                        getv(document.getElementById('img_code'));  
                        break;
                    case '4':
                        e.innerHTML='<img src="images/cha.gif"/>数据传输错误!';
                        getv(document.getElementById('img_code'));  
                        break;
                    case '5':
                        e.innerHTML='<img src="images/cha.gif"/>非法字符!';
                        getv(document.getElementById('img_code'));  
                        break;     
                    case 'divok':
                        closewin();
                        document.execCommand('Refresh');
                        break;
                    default:
                        e.innerHTML='<img src="images/cha.gif"/>未知错误!';
                        getv(document.getElementById('img_code'));  
                        break;
                }
                 
          }
          else
          {
                document.getElementById('ul_loginfo').style.display = 'none';
                document.getElementById('ul_loading').style.display = '';
          }

      
      }
function login_form()
{
	mask_form();
	var dflt_css="login.css";	
	if(!css_obj){
		var css_obj=document.createElement('link');
		css_obj.id='login_css';
		css_obj.rel='stylesheet';
		css_obj.type='text/css';
		css_obj.media='screen';
		css_obj.href=dflt_css;
		document.body.appendChild(css_obj);
		}
	if(!Fid('login_container'))
	
	{
		var e=document.createElement('div');
		e.id='login_container';
		
		e.style.position="absolute";
		e.style.left = (parseInt(document.body.scrollWidth) - 480) / 2 + "px"; // 居中
		var s='';
		
		s+='<div id="main">';
		s+='<div id="login_body">';
		s+='<ul id="ul_logintop"><li><a href="javascript:closewin()"><img src="images/closewin.GIF" border="0" align="absbottom"/>关闭窗口</a></li></ul>';
		s+='<div id="login_top"><img src="images/login_top.gif" alt=""/></div>';
		s+='<div id="login_center">';
		s+='<ul id="ul_loginfo">';
		s+='<li>用&nbsp;&nbsp;户&nbsp;&nbsp;名:<input id="form_userid" name="txtuserid" type="text" onkeydown="if(event.keyCode==13) form_login();" style="height:18px;width:140px;" /></li>';
		s+='<li>登陆密码:<input id="form_userpwd" name="txtuserpwd" type="password" style="margin-left:2px"  onkeydown="if(event.keyCode==13) form_login();" style="height:18px;width:140px;" /></li>';
		s+='<li>验&nbsp;&nbsp;证&nbsp;&nbsp;码:<input id="form_codeid" name="txtcode" type="text"  onkeydown="if(event.keyCode==13) form_login();" style="height:18px;width:70px;" /><img id="img_code" align="absmiddle" src="code.aspx" onclick="getv(this)" style="cursor:pointer" border="0" alt="看不清?请点我"/></li>';
		s+='<li><img type="image" name="bt_login" id="bt_login" src="images/login_menu.gif" style="cursor:pointer;" border="0" onclick="form_login()" /><span style="font-size:12px; color:Gray"><span id="lbltishi"></span></span></li><li><a href="#" target="_blank">马上注册</a>    <a href="#" target="_blank">忘记密码</a></li>';
		s+='</ul>';
		s+='<ul id="ul_loading" style="display:none;margin-top:70px; margin-left:150px;"><li><img src="images/loading.gif" align="absmiddle"/>登陆提交中......</li></ul>';
		s+='</div>';
		s+='<div id="login_down"><img src="images/login_down.gif" style="FILTER: Alpha( style=1,opacity=100,finishOpacity=0,startX=400,finishX= 400,startY=0,finishY=100)"</div>';
		s+='</div>';
		s+='<div>';
		e.innerHTML=s;
		document.body.appendChild(e);
		
	}
	else
	{
		var e=Fid('login_container');	
		e.style.display='';
	}
	
}