﻿function LoginStatus(type,id)
{
     $.ajax({
            url:'/WebService/LoginStatus.ashx',
            dataType:'html',  
            data:{t: Math.random(),tp:type},
            success:function(data){$("#"+id).html(data)}
            })
}
function IndexLoginSubmit()
{
    var username=$("#UserName").val();
    var password=$("#Password").val();
    if(username.length==0)
    {
        alert("请输入登陆名");
         $("#UserName").focus()
         $("#UserName").css({background:"#FF0", 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:"#FF0", border:"1px solid #ccc"});
        $("#Password").focus();
        $("#Password").blur(function(){ $(this).css({background:"#FFFFFF", border:"1px solid #ccc"})});
        return false;
    }
     $.ajax({
            url:'/WebService/LoginStatus.ashx',
            dataType:'html',  
            data:{t: Math.random(),UserName:username,Password:password},
            success:function(data){
                if(data=="failure")
                {
                    alert("登陆失败!密码错误!");
                }
                if(data == "success")
                {
                   LoginStatus("v","LoginStatus");
                   LoginStatus("h","toplogin"); 
                }
            }
            })
}
function IndexCategorySwap()
{
    $ImgTab1=$("#ImgTab1");
    $ImgTab2=$("#ImgTab2");
    
    $ImgTab1.hover(
    function(){
        $ImgTab1.attr("src","/images/sub_1.jpg");
        $ImgTab2.attr("src","/images/sub_2.jpg");
        $("#c1").show();
        $("#c2").hide();
        },
    function(){}
    )
     $ImgTab2.hover(
    function(){
        $ImgTab2.attr("src","/images/sub_22.jpg");
        $ImgTab1.attr("src","/images/sub_11.jpg");
        $("#c2").show();
        $("#c1").hide();
        },
    function(){}
    )
}

function AddFavorite(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);
            }
            })
}
function AddCart(s_itemid)
{
      $.ajax({
            url:'/WebService/AddToCart.ashx',
            dataType:'html',  
            data:{itemid:s_itemid,t: Math.random()},
            success:function(data){
            alert(data);
            LoadCartItemCount();
            }
            })
}
function LoadAd(sAdid)
{
   
    $.ajax({
    url:'/WebService/LoadAd.ashx',
    dataType:'html',  
    data:{Adid:sAdid,t: Math.random()},
    success:function(data){
          $("#ad"+sAdid).html(data);
        }
    })

}
function LoadCartItemCount()
{
     $.ajax({
    url:'/WebService/GetItemCount.ashx',
    dataType:'html',  
    data:{t: Math.random()},
    success:function(data){
          $("#cartitemcount").html(data);
        }
    })
}
$(document).ready(
    function(){
        LoginStatus("v","LoginStatus");//栽入首页的登陆框
        LoginStatus("h","toplogin"); 
        IndexCategorySwap();//首页栏目切换
        LoadCartItemCount();
    }
);