﻿// JScript 文件
var domain1="/Response_Ajax/";
   document.writeln(" <div style=\"float:left;\"><div id=\"pull\" style=\" visibility:hidden; left: 156px; top:268px; width:260px;border:0;\" ></div></div>");
    document.writeln(" <input type=\"hidden\" id=\"hid_answer\"/>");
    document.writeln(" <input type=\"hidden\" id=\"hid_f_username\"/>");
var userName = ""
var str = "";
var password = "";
var verCode = "";
  //------------------------------------弹出框
  //显示类型隐藏层
  function   ShowHideLogin(obj1,obj2,state){ 
      var   spell=obj1.innerHTML;  
      var   btn=obj1;  
      var   obj=document.getElementById(obj2);  
      var   h=btn.offsetHeight;  
      var   w=btn.offsetWidth;  
      var   x=btn.offsetLeft;  
      var   y=btn.offsetTop;  
       
      while(btn=btn.offsetParent){y+=btn.offsetTop;x+=btn.offsetLeft;}  
       
      var   hh=obj.offsetHeight;  
      var   ww=obj.offsetWidth;  
      var   xx=obj.offsetLeft;//style.left;  
      var   yy=obj.offsetTop;//style.top;  
      var   obj2state=state.toLowerCase();  
      var   showx,showy,showstate;  
       
      if(obj2state=="show"   ||   obj2state=="hide"   ||   obj2state=="hidden")
      {  
        if(obj2state=="show")
        {
            showstate="visible";
        }
        else
        {
            showstate="hidden";
        }  
        
      }  
      else{ 
      
      showstate="hidden"; 
      }  
      showx=x;
      showy=y+h;  
      obj.style.left=showx+"px";  
      obj.style.top=showy+"px";  
      obj.style.visibility=showstate;
      InitLogin();
  }
  
  function InitLogin()
  {
     str = "";
     str = str +" <div style=\" width:260px; border:1px solid #ddd;border-top:none;  font-size: 12px;line-height: 2em;color: #222;  padding-bottom:5px;\">";
	 str = str +" <a href=\"javascript:HiddenLogin();\"><img  style=\"float:right; margin:6px 5px 0 0;\" src=\"/Image/Public/Pull_Login/no.gif\" border=\"0\" width=\"15\" height=\"15\" /></a>";
	 str = str +" <h2 style=\"background-image: url(/Image/Public/Pull_Login/tb.gif);background-repeat: repeat-x;";
	 str = str +" text-align:left; line-height:28px;font-size:14px;color:#fff;font-weight: bold;margin:0px;padding: 0 0 0 10px;\">请输入登陆信息</h2>"
	 str = str +"<table width=\"0\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" style=\"margin-top:5px;\"><tr height=\"20\"><td width=\"68\" align=\"right\">用户名：</td>";
	 str = str +"<td width=\"187\" align=\"left\"><input id=\"user_name\"  style=\"height:18px;\"  type=\"text\" onkeydown=\"if (event.keyCode == 13){SubmitLogin();}\" /></td></tr><tr height=\"20\"><td align=\"right\">密 码：</td>";
	 str = str +"<td align=\"left\"><input  style=\"height:18px;\" id=\"password\" type=\"password\" onkeydown=\"if (event.keyCode == 13){SubmitLogin();}\" /></td></tr><tr height=\"25\"><td align=\"right\">验证码：</td>";
	 str = str +"<td align=\"left\"><input  style=\"height:18px;\" id=\"ver_code\" type=\"text\" size=\"10\" onkeydown=\"if (event.keyCode == 13){SubmitLogin();}\" /> <img id=\"CodeImg\" onclick=\"this.src='/Page/Public/CheckCode.aspx?tmp='+Math.random();return false;\" src=\"/Page/Public/CheckCode.aspx\" alt=\"验证码\" />";
     str = str +" <a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"document.getElementById('CodeImg').src='/Page/Public/CheckCode.aspx?tmp='+Math.random();return false;\" class=\"chakan\">换个</a></td>";                 
	 str = str +"</tr></table><div style=\"text-align:center\"> <a target=\"_blank\" href=\"/Page/Public/FindPassWord.aspx\">忘记密码？</a>";
	 str = str +"</div><div style=\"width:176px;margin:0 auto;\">";
	 str = str +"<div style=\"height:25px;width:70px;padding-left:10px; background-image: url(/Image/Public/Pull_Login/an_1.gif); float:left; text-align:center;\">";
	 str = str +"<a href=\"javascript:SubmitLogin();\" id=\"login_submit\" style=\"color:#333; text-decoration: none;\" > 登 录</a></div>";
	 str = str +"<div style=\"height:25px;width:80px; background-image: url(/Image/Public/Pull_Login/an_2.gif); float:right; text-align:center;\">";
	 str = str +"<a href=\"#\" style=\"color:#333; text-decoration: none;\" >帮 助</a></div></div><div style=\"clear:both;\"></div>";
	 str = str +"<h4 style=\"background-image: url(/Image/Public/Pull_Login/zc.gif);width:164px;height:33px;line-height:33px;font-size:13px;";
	 str = str +"margin: 8px auto 0 auto ; text-align:center;\"><a href=\"/Page/Member/regist.aspx\"  style=\"font-weight: bold;color: #FFFFFF;	text-decoration: none;\">立即注册</a></h4>";
	 str = str +"<div style=\"clear:both;\"></div></div>";

      document.getElementById('pull').innerHTML = str;
      document.getElementById("user_name").focus();
  }
  
  
 //弹出层显示/隐藏
    function HiddenLogin()
    {
     document.getElementById('pull').style.visibility = "hidden"; 
    }
    
//------------------------------------弹出框结束
   //登陆
   function SubmitLogin()
    {
        if(!CheckLogin()) //验证要提交的数据
        {
           return;
        }
        userName = document.getElementById("user_name").value.replace(/^\s+|\s+$/g,"");
        password = document.getElementById("password").value.replace(/^\s+|\s+$/g,"");
        verCode = document.getElementById("ver_code").value.replace(/^\s+|\s+$/g,"");
        var op = "Login";
        var url = domain1+'Public/Program.aspx';
        var pars ='userName='+ userName+'&verCode='+ verCode+'&password='+ password+'&op=' + op;
        var myAjax = new Ajax.Request(
                url,
                {method: 'get', parameters: pars, onSuccess: SubmitLoginSuccess}
                );
        document.getElementById('pull').innerHTML = "<img src=\"/Image/Public/loading4.gif\" style=\"margin-left:30px\"/>";
    } 
    
     function SubmitLoginSuccess(originalRequest)
      {
       var Result= originalRequest.responseText;
        if(Result == "0")
        {
//           if(window.location.href.indexOf("Home_Page") == -1);
//             {
//                window.open("/page/price/NewAddPrice.aspx");
//             }
           HiddenLogin();window.location.reload(true);return;
        }
        else
        {
            if(Result == "1")
            {alert("您好，密码不对！");}
            if(Result == "2")
            {alert("您好，验证码不对！");}
            document.getElementById('pull').innerHTML = str;
            document.getElementById("user_name").value = userName;
            document.getElementById("ver_code").value = verCode;
            document.getElementById("password").value = password;
        }
      }
    
  
      //验证
    function CheckLogin()
    {
        if(document.getElementById("user_name").value.length<=0)
        {
               alert("您好，用户名不能为空！");
                return false;
        }
        
        if(document.getElementById("password").value.length<=0)
        {
               alert("您好，密码不能为空！");
                return false;
        }
        
        if(document.getElementById("ver_code").value.length<=0)
        {
               alert("您好，验证码不能为空！");
                return false;
        }
    
          return true;
    }
    
    

    
    
    
      
