﻿$(document).ready(function()
{
    loadMyCar();
    LoadUserInfo();
    //LoadLatestReview();
    //$("h1").hide("fast");
    //$(".news").hide("fast");
    SetStyle();
    SetUsage();
    SetPrice();
    $("#update").html("<img width=1 height=1 src='/gh/hdlUpdate.ashx' />");
});


function SetStyle()
{
    $("#pstitle").click(function()
    {
        $("#psstyle").toggle();
    });
}

function SetUsage()
{
    $("#usagelisttitle").click(function()
    {
        $("#usagelist").toggle();
    });
}

function SetPrice()
{
    $("#pricetitle").click(function()
    {
        $("#pricelist").toggle();
    });
}


//加载我的购物车 CarItems
function loadMyCar()
{
    var timestamp = (new Date()).valueOf(); 
    $.getJSON("/gh/hdlMyCar.ashx?tm="+timestamp,function(data){
        if(data!="")
        {           
            $("#CarItems").html("");
            $.each(data, function(i,o)
            {
                $("<div class='CarProductItem'>").html("<a href='/sc/mycar.aspx'><img width=25px height=25px src="+o.prsPImg+" /></a>").appendTo("#CarItems");
              })
            $("#CatItemCount").html("("+data.length+")");
       }
    }); 
}

//加载用户资料 txtUserName,txtEmail,SignInArea
function LoadUserInfo()
{
    $("#SignInArea").html("您还没有登录，请先<a href='/ac/signin.aspx?url="+document.URL+"'><strong>登录</strong></a> 或 <a href='/ac/signup.aspx'><strong>注册</strong></a>");
    var timestamp = (new Date()).valueOf(); 
    $.getJSON("/gh/hdluser.ashx?tm="+timestamp,function(data){
        if(data.UserName!="")
        {
            $("#SignInArea").html("Hi, "+data.UserName+" <b><a href='/ac/myprofile.aspx'>我的档案</a></b> <b><a href='/ac/exit.aspx'>退出</a></b>");
            $("input[id='txtUserName']").attr("value",data.UserName);
            $("input[id='txtEmail']").attr("value",data.Email); 

        }
    }); 
}

//加载最新产品评论 - div = LatestReview
function LoadLatestReview()
{
    var timestamp = (new Date()).valueOf();
    $.getJSON("/gh/hdlLatestReview.ashx?tm="+timestamp,function(data){
        $("#LatestReview").html("");
            $.each(data, function(i,o){
                if (o.prsICO=="")
                {
                    $("<div class='divLatestReview'>").html("<img alt='"+o.prsName+"' src='/gh/hdlico.ashx?w=30&h=30&tm="+i+"' /><div class='lrContent'><a href='"+o.prsURL+"'>"+o.prsContent+"</a></div>").appendTo("#LatestReview");
                }
                else
                {
                    $("<div class='divLatestReview'>").html("<img alt="+o.prsName+" src="+o.prsICO+" /><div class='lrContent'><a href='"+o.prsURL+"'>"+o.prsContent+"</a></div>").appendTo("#LatestReview");
                }
           
        });
    });
}
