// JScript 文件
var integral="0";
 var UserTool=
{
    success:false,
    UserToolcount:0,
    settime:"",
    createDiv:function()
    {
        var domWindow = document.createElement("div");
        domWindow.className = "fixed_div";
        domWindow.innerHTML="<div class=\"foot_2\"><div class=\"ft2\" id=\"login\"></div></div>"
        $(document.body).append(domWindow);
    },
    retable1:function(data,iso)
    {
        if(data=="0"||data=="邮箱或密码不正确！")
        {
            if(iso==1)
            {
                alert("邮箱或密码不正确")
                $("#alogin").blur();
            }
            else
            {
                var login="<dl>";
                login+="<dd>邮箱│昵称：<input type=\"text\" id=\"txtname\" style=\"width:120px;\" />  &nbsp;&nbsp;&nbsp;密码：<input type=\"password\" id=\"password\" style=\"width:120px;\" />  &nbsp;&nbsp;&nbsp;<a style='color:#fff;' href=\"javascript:UserTool.loginAjax()\" id=\"alogin\">登录</a>  &nbsp;&nbsp;&nbsp;<a style='color:#fff;' href=\"/Member/Register.aspx\">注册</a>&nbsp;&nbsp;&nbsp;<a style='color:#fff;' href=\"/Member/ForgetPassword.aspx\">忘记密码</a></dd></dl>";
                login+="<ul style=\"width:320px; padding-top:13px;\"><li><img style='vertical-align: middle;' src='/images/index/top_tu1.gif'/>&nbsp;&nbsp;<a style='color:#fff;' href='javascript:toOrder();'>订餐查询</a></li><li><img style='vertical-align: middle;' src='/images/index/top_tu2.gif'/>&nbsp;&nbsp;<a  onclick=\"this.style.behavior='url(#default#homepage)';this.setHomePage(document.location.href.substring(0,document.location.href.indexOf('/',7)) );return false;\" style='color:#fff;' href='javascript:void(0)'>设为首页</a></li><li><img style='vertical-align: middle;' src='/images/index/top_tu3.gif'/>&nbsp;&nbsp;<a style='color:#fff;' href='JavaScript:addfavorite();'>收藏本店</a></li></ul>";
                $("#login").html(login);
                $("#txtname").keyup(function(e){ if (e.keyCode == 13) $("#password").focus() });
                $("#password").keyup(function(e){ if (e.keyCode == 13) {UserTool.loginAjax();$("#password").blur()} }); 
                UserTool.success=false;
            }
            
        }
        else
        {
            if(iso==0)
            {
                 var login="<dl>";
                login+="<dd>欢迎您，"+data+"！ <a style='color:#fff;' href=\"javascript:UserTool.SignoutAjax()\">[退出]</a>   &nbsp;<a href='/Private/UserIntegral.aspx' style='color:#fff;'>我的积分("+integral+")</a>  &nbsp;</dd></dl>";
                login+="<ul style=\"width:320px; padding-top:13px;\"><li><img style='vertical-align: middle;' src='/images/index/top_tu1.gif'/>&nbsp;&nbsp;<a style='color:#fff;' href='javascript:toOrder();'>订餐查询</a></li><li><img style='vertical-align: middle;' src='/images/index/top_tu2.gif'/>&nbsp;&nbsp;<a style='color:#fff;' onclick=\"this.style.behavior='url(#default#homepage)';this.setHomePage(document.location.href.substring(0,document.location.href.indexOf('/',7)) );return false;\" href='javascript:void(0)'>设为首页</a></li><li><img style='vertical-align: middle;' src='/images/index/top_tu3.gif'/>&nbsp;&nbsp;<a style='color:#fff;' href='JavaScript:addfavorite();'>收藏本店</a></li></ul>";
                $("#login").html(login);
                UserTool.success=true;
            }
            else
            {
                location.reload();
            }
        }
    },
    loginAjax:function ()
    {
        var email=($("#txtname").length ==0?"":$("#txtname").val());
	    var password=($("#password").length ==0?"":$("#password").val());
        $.ajax({
	        type: "post",
	        url: "/Member/ajax/AjaxLogin.aspx?Email=" +email+ "&Password="+password,
	        cache:false,
	        success: function(data, textStatus){
 		
		        UserTool.retable1(data,1);
 			
	        },
	        error: function(data){
	        alert(data);
	        }
            });
      },
      CheckLogin:function ()
      {
        $.ajax({
	        type: "post",
	        url: "/Member/ajax/CheckLogin.aspx",
	        data:"" ,
	        cache:false,
	        success: function(data){
			if(data!="0"||data!="邮箱或密码不正确！")
        	{
			    $.ajax({
	            	type: "post",
	           	 url: "/Member/ajax/AllIntegral.aspx",
	           	 data:"" ,
	           	 cache:false,
	           	 success: function(data1){
				    integral=data1;
		        	UserTool.retable1(data,0);},
	             error: function(data1){alert(data1.responseText);}
                });
			}
			else
		        UserTool.retable1(data,0);
	        },
	        error: function(data){
	        alert(data);
	        }
            });
      },
      SignoutAjax:function()
      {
        $.ajax({
	        type: "post",
	        url: "/Member/ajax/LoginExit.aspx",
	        data:"" ,
	        cache:false,
	        success: function(data, textStatus){
		         //UserTool.retable1(data,0);
		        location.reload();
	        },
	        error: function(data){
	        alert(data);
	        }
            });
      }
}
  $(function(){
  UserTool.createDiv();
  UserTool.CheckLogin();
  $(".fixed_div").floatdiv({left:"0",top:"0"});
  
    });