﻿var Shop =function()
{
   this.getItemCount = function()
    {
          $.ajax({
            url:'/WebService/GetItemCount.ashx',
            dataType:'html',  
            data:{t: Math.random()},
            success:function(data){$("#CartItemsCount").html(data)}
            })
    }
    this.getTotalPrice = function()
    {
          $.ajax({
            url:'/WebService/GetTotalPrice.ashx',
            dataType:'html',  
            data:{t: Math.random()},
            success:function(data){$("#TotalPrice").html(data)}
            })
    }
    this.AddToCart = function(s_itemid){
          $.ajax({
            url:'/WebService/AddToCart.ashx',
            dataType:'html',  
            data:{itemid:s_itemid,t: Math.random()},
            success:function(data){
            alert(data);
            (new Shop()).getItemCount();
            (new Shop()).getTotalPrice();
            }
            })
    }
    this.AdFavorate = function(s_itemname,s_url,s_itemid){
     $.ajax({
            url:'/WebService/AddFavorite.ashx',
            dataType:'html',  
            data:{itemid:s_itemid,url:s_url,itemname:s_itemname,t: Math.random()},
            success:function(data){
            alert(data);
            }
            })
    }
    /* ========================= */ 
    this.Loginlite = function(){
        var username=$("#UserName").val();
        var password=$("#Password").val();
        if(username.length==0)
        {
            alert("请输入登陆名");
             $("#UserName").focus()
             $("#UserName").css({background:"red", border:"1px solid #ccc"});
             $("#UserName").blur(function(){ $(this).css({background:"#FFFFFF", border:"1px solid #ccc"})});
            return false;
        }
        if(password.length==0)
        {
            alert("请输入密码");
            $("#Password").css({background:"red", border:"1px solid #ccc"});
            $("#Password").focus();
            $("#Password").blur(function(){ $(this).css({background:"#FFFFFF", border:"1px solid #ccc"})});
            return false;
        }
         $.ajax({
                url:'/WebService/Login.ashx',
                dataType:'html',  
                data:{t: Math.random(),UserName:username,Password:password},
                success:function(data){
                    if(data=="failure")
                    {
                        alert("登陆失败!密码错误!");
                    }
                    if(data == "success")
                    {
                       (new Shop).LoginStatus(); 
                    }
                }
                })
    }
    this.LoginStatus = function()
    {
          $.ajax({
            url:'/WebService/LoginStatus.ashx',
            dataType:'html',  
            data:{t: Math.random()},
            success:function(data){
                $("#Member").html(data)}
            })
    }
    
    this.LoadAd = function(sAdid)
    {
         $.ajax({
            url:'/WebService/LoadAd.ashx',
            dataType:'html',  
            data:{Adid:sAdid,t: Math.random()},
            success:function(data){
                  $("#ad"+sAdid).html(data);
                }
            })
    }
}





