
var retStr = "";
var username="";
var returnlogin="";
var xmlhttpname=false;
var xmlhttplogin=false;

 retStr += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
retStr +='<tr>'
retStr +='<td width="13%" align="center" class="ff14b"><span class="ffwhite">用户名:</span></td>';
retStr +='<td width="17%">';
retStr +='<input name="yonghuming" type="text" id="txtName" size="10" style="background-color: #FFFFFF; border-color: #bbc5cd; border-style: solid; border-width: 1px"/></td>';
retStr +='<td width="12%" align="center" class="ff14b"><span class="ffwhite">密 码:</span>';
retStr +='</td>';
retStr +='<td width="20%">';
retStr +='<input name="mima" type="password" id="txtPwd" size="10" style="background-color: #FFFFFF; border-color: #bbc5cd; border-style: solid; border-width: 1px"/></td>';
retStr +='<td width="19%"><input type="image"  name="denglu" onclick="login()" id="denglu" src="/images/hnjshome_18.jpg"/></td>';
retStr +='<td width="19%">';
retStr +='<a href="/register" target="_blank" style="color:#FFFFFF;"> 免费注册 </a></td></tr></table>'
document.write("<div id='mydiv'>");
document.write(retStr);
 document.write('</div>');
 
 function login()
{
  var txtname = document.getElementById('txtName');
    var txtpwd = document.getElementById('txtPwd');
    if(txtname.value==""){alert('用户名不能为空');return false;}
    if(txtpwd.value ==""){alert('密码不能为空');return false;}
    getlogin(txtname.value,txtpwd.value);
    if(returnlogin == "1")
    {
   getCookie('name');
    }
    else
    {
    alert('用户名或者密码不对!');
    document.getElementById('txtName').focus();
   }
}

//删除指定的cookie
function delck(ckname)
{
  window.location.href="/logout.aspx";
}
function getCookie(name)
{
var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
if(arr=document.cookie.match(reg))
{ 
    var first,last,result,bb;
    first = arr[2].indexOf('login_nickname');
   last = arr[2].substring(first,arr[2].length);
   result = last.indexOf('=');
   bb = last.substring((result +1),last.length);
   getname(bb);
    var strVal = '';
    strVal +='<table width="100%" border="0" cellspacing="0" cellpadding="0">';
    strVal +='<tr><td width="70%" align="center" class="ff14b"><span class="ffwhite">'+username+',欢迎您回来 &nbsp;</span><a href="/user/home.aspx" class="ffwhite"> >>会员中心</a><a style="cursor:hand;" onclick="delck(\'name\')"> >>退出</a></td>';
    strVal +='</tr></table>';
    document.getElementById('mydiv').innerHTML= strVal;

}
else 
    {
     document.getElementById('mydiv').innerHTML= retStr;
    }
}

 function getname(infoid){
       
         if(window.XMLHttpRequest){
          xmlhttpname=new XMLHttpRequest();
          
         }else if(window.ActiveXObject){
           xmlhttpname=new ActiveXObject("Microsoft.XMLHttp");
            
        }
        var url="/readbook/lookaction.aspx?id="+infoid+"&type=2";
       xmlhttpname.onreadystatechange=callbackname;
        xmlhttpname.open("get",url,false);
        xmlhttpname.send();
         
     }
     
     function getlogin(txtname,txtpwd){
      if(window.XMLHttpRequest){
          xmlhttplogin=new XMLHttpRequest();
          
         }else if(window.ActiveXObject){
           xmlhttplogin=new ActiveXObject("Microsoft.XMLHttp");
            
        }
       
        var url="/readbook/lookaction.aspx?name="+txtname+"&pwd="+txtpwd+"&type=3";
       xmlhttplogin.onreadystatechange=callbacklogin;
        xmlhttplogin.open("get",url,false);
        xmlhttplogin.send();
        }
        
      function callbackname(){
        if(xmlhttpname.readystate==4)
        {
         var now=  username = xmlhttpname.responseText;
          xmlhttpname = window.setTimeout(getname,5544445645555000);
        }
        }
         function callbacklogin(){
        if(xmlhttplogin.readystate==4)
        {
          var now= returnlogin = xmlhttplogin.responseText;
           xmlhttplogin = window.setTimeout(getlogin,5555444215555000);
        }
     }
getCookie('name');