﻿// JScript 文件
$(function(){
    try{
        //获取购物车内的产品数量
        $.ajax({
            url:"/Ajax.aspx?action=GetCartCount&ran="+Math.random,
            success:function(ms){
                $("#JK_MyCartCount").html(ms);
            }
        })
    }catch(error){}
    
    try{
        //获取文章的点击次数
        $.ajax({
            url:"/Ajax.aspx?action=GetArticleReadCount&ArticleId="+document.getElementById("ArticleId").value+"&ran="+Math.random,
            success:function(ms){
                $("#ArticleClickCount").html(ms);
            }
        })
    }catch(error){}
        
    try{
        //增加文章的阅读次数
        var ArticleId=document.getElementById("ArticleId");
        if(ArticleId!=null)
        {
            $.ajax({
                url:"/Ajax.aspx?action=AddArticleClickCount&ArticleId="+document.getElementById("ArticleId").value
            })
        }
    }catch(error){}
    
    try{
        //判断用户是否登陆
        $.ajax({
            url:"/Ajax.aspx?action=GetUserName",
            success:function(ms){
                if(ms!="")
                {
                    $("#LoginState").html(ms);
                }else
                {
                    $("#LoginState").html("请您<span class=\"red\"><a href=\"/Login.aspx\" title=\"会员登陆\">登陆</a></span>或者<span class=\"red\"><a href=\"/Register.aspx\" title=\"注册会员\">注册</a></span>");
                }
            }
        })
    }catch(error){}
})
function CutStr(str,n)
{
    var ilen = str.length;
    if(ilen*2 <= n) return str;
    n -= 3;
    var i = 0;
    while(i < ilen && n > 0)
    {
        if(escape(str.charAt(i)).length>4) n--;
        n--;
        i++;
    }
    if( n > 0) return str;
    return str.substring(0,i)+"...";
}
function PubProComment(ProductID,ComContent,UserName,Password)
{
    $.ajax({
        type: "GET",
        url: "/Ajax.aspx?action=PubProComment&ProductID="+ProductID+"&ComContent="+ComContent+"&UserName="+UserName+"&Password="+Password,
        success :function(ms){
            if(ms=="success"){
                alert("您的评论已发布。");
                window.location.reload();
            }
        },
        error:function(request, settings){
            if(request.responseText.indexOf("对不起！此产品的评论功能被关闭")!=-1)
            {
                alert("对不起！此产品的评论功能被关闭。");
            }else{
                alert("对不起！此产品的评论功能被关闭。");
            }
        }
    })
}

function collect(productid)
{
    window.open("/ProductFavourite.aspx?productid="+productid);
    
}

var flag=false; 
function DrawImage(ImgD){ 
var image=new Image(); 
image.src=ImgD.src; 
if(image.width>0 && image.height>0){ 
flag=true; 
if(image.width/image.height>= 250/250){ 
if(image.width>250){
ImgD.width=250; 
ImgD.height=(image.height*250)/image.width; 
}else{ 
ImgD.width=image.width;
ImgD.height=image.height; 
} 
/*ImgD.alt="bigpic" */
} 
else{ 
if(image.height>250){
ImgD.height=250; 
ImgD.width=(image.width*250)/image.height; 
}else{ 
ImgD.width=image.width;
ImgD.height=image.height; 
} 
/*ImgD.alt="bigpic" */ 
} 
}
}

