﻿var flag=0;
var xmlHttp;
   String.prototype.trim= function()  
    {  
             // 用正则表达式将前后空格  
             // 用空字符串替代。  
             return this.replace(/(^\s*)|(\s*$)/g, "");  
    }
    function createXmlHttpRequest()
    {
        if(window.XMLHttpRequest)
        {
            xmlHttp=new XMLHttpRequest();
        
            if(xmlHttp.overrideMimeType)
                {
                    xmlHttp.overrideMimeType("text/xml");
                }
        }
        else if(window.ActiveXObject)
        {
            try
            {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");                   
            }
            catch(e)
            {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");                   
            }
        }
        if(!xmlHttp)
        {
            window.alert("你的浏览器不支持创建XMLhttpRequest对象");
        }
        return xmlHttp;
    }
function loginResult()
{
    if(xmlHttp.readyState==4)//服务器响应状态
    {
         //alert('status='+xmlHttp.status); 
        if(xmlHttp.status==200)//代码执行状态
        {
            //alert('revalu='+xmlHttp.responseText);
            if(xmlHttp.responseText=="true")
            { 
                flag=0;
                window.alert('登陆成功！');
            }
            else
            {
                window.alert("用户名或密码不正确，请重新输入！");
                document.getElementById("Header1_TextBox2").value="";
                flag=1;
            }
        }
//       else if (xmlHttp.status == 404)
//           alert("Request URL does not exist");
//       else if (xmlHttp.status == 500)
//           alert("服务器异常！");
//       else
//            alert("Exception");
    }
}

function login()
{
    
    var name=document.getElementById("Header1_TextBox1").value.trim();
    var pwd=document.getElementById("Header1_TextBox2").value.trim();
    //alert('name:'+name+'pwd='+pwd);
    if(name=="")
    {
        window.alert("用户名不能为空");        
        document.getElementById("Header1_TextBox1").focus();        
        return false;
    }
   if(pwd=="")
   {
        window.alert("密码不能为空");        
        document.getElementById("Header1_TextBox2").focus();        
        return false;
   }
   createXmlHttpRequest(); 
   var url="../shidongmanage/loginEvent.aspx?Name="+name+"&Pass="+pwd+"&Event=login";
   //alert('url='+url);
   xmlHttp.open("GET",url,true);
   xmlHttp.onreadystatechange=loginResult;
   xmlHttp.send(null);  
   if(flag==1)
      event.returnValue=false; 
}

