﻿// JScript 文件
//切换产品颜色
function ImgTextChangeProductColor(styleID, productCode, dataType) {

    $.getJSON("/Product/GetProductInfo.aspx?ProductCode=" + productCode + "&dataType=" + dataType,
	function(data) {
	    var productInfo = data;
	    productInfo.VPrice = productInfo.VPrice.replace(".00", "");
	    productInfo.Price = productInfo.Price.replace(".00", "");
	    productInfo.SPrice = productInfo.SPrice.replace(".00", "");
	    var productRefInfoUrl = productInfo.ProductInfoUrl;
	    var refValue = "ref=StyleList_" + styleID + "_" + productCode;
	    var item = $("#item_" + styleID);
	    item.find(".pic a").eq(0).attr("href", productRefInfoUrl).attr("ref",refValue);
	    
	    item.find(".pic a img").eq(0).attr("src", productInfo.PhotoPath.replace("lists", "lists170"));
	    item.find(".productName a").eq(0).attr("href", productInfo.ProductInfoUrl).html(productInfo.ProductName);
	    item.find(".price .sc").eq(0).html("售价￥" + productInfo.Price);
	    item.find(".price strong del").eq(0).html("￥" + productInfo.VPrice);
	    item.find(".productInfo .ProductName").eq(0).html(productInfo.ProductName);
	    item.find(".productInfo .prouctCode").eq(0).html(productInfo.ProductCode);
	    item.find(".productInfo .sprice").eq(0).html(productInfo.SPrice);
	    item.find(".productInfo .vprice").eq(0).html(productInfo.VPrice);
	    item.find(".productInfo .price").eq(0).html(productInfo.Price);
	    //	    item.find(".productInfo .commentsNumber").eq(0).html(GetStartStr(productInfo.Asoverall));
	    //	    item.find(".productInfo .comments").eq(0).html(productInfo.AssessCount);
	    item.find(".productInfo .pic").eq(0).html(productInfo.MidPhoto);

	    item.find(".productInfo .salesFlag").eq(0).html(productInfo.SalesFlag);
	    item.find("dl dd").each(function(i) {
	        if ($(this).attr("id") == "color_" + styleID + "_" + productCode) {
	            if (i % 5 == 4) {
	                $(this).attr("class", "currentColor2");
	                $(this).find("a").blur();
	            }
	            else {
	                $(this).attr("class", "currentColor");
	                $(this).find("a").blur();
	            }
	        }
	        else {
	            if (i % 5 == 4) {
	                $(this).attr("class", "otherColor2");
	            }
	            else {
	                $(this).attr("class", "otherColor");
	            }
	        }

	    });
	    item.find(".pic .teshui").remove();
	    item.find(".pic .qianggou").remove();
	    item.find(".pic .duanma").remove();
	    item.find(".pic .newview").remove();
	    item.find(".pic .qingcang").remove();

	    if (productInfo.SalesFlag == "1") {
	        item.find(".pic").eq(0).append("<div class=\"teshui\">" + productInfo.SPrice.replace(".00", "") + "</div> ");
	    }
	    else if (productInfo.SalesFlag == "2") {
	        item.find(".pic").eq(0).append("<div class=\"qianggou\">" + productInfo.SPrice.replace(".00", "") + "</div> ");
	    }
	    else if (productInfo.SalesFlag == "3") {
	        item.find(".pic").eq(0).append("<div class=\"qingcang\">" + productInfo.SPrice.replace(".00", "") + "</div> ");
	    }

	    if (productInfo.IsNew == "1")
	        item.find(".pic").eq(0).append("<div class=\"newview\"></div>");
	    if (productInfo.SPrice == productInfo.Price) {
	        if (productInfo.IsDuanma == "True") {
	            item.find(".pic").eq(0).append("<div class=\"duanma\"></div>");
	        }
	    }
	}); 
}

function ListChangeProductColor(styleID,productCode,dataType) {
    $.getJSON("/Product/GetProductInfo.aspx?ProductCode=" + productCode + "&dataType=" + dataType,
	function(data) {
	    var productInfo = data;
	    productInfo.VPrice = productInfo.VPrice.replace(".00", "");
	    productInfo.Price = productInfo.Price.replace(".00", "");
	    productInfo.SPrice = productInfo.SPrice.replace(".00", "");
	    var productRefInfoUrl = productInfo.ProductInfoUrl;
	    var refValue = "StyleList_" + styleID + "_" + productCode;
	    var item = $("#item_" + styleID);
	    item.find(".pic a").eq(0).attr("href", productRefInfoUrl).attr("ref", refValue);
	    item.find(".pic a img").eq(0).attr("src", productInfo.PhotoPath.replace("lists", "lists170"));
	    item.find(".aProductName").eq(0).attr("href", productInfo.ProductInfoUrl);
	    item.find(".aProductName strong").eq(0).html(productInfo.ProductName);

	    var strPrice = "";
	    if (dataType == 1)
	        productInfo.SalesFlag = 0;
	    switch (productInfo.SalesFlag) {
	        case "1":
	            strPrice = "特惠价：￥" + productInfo.SPrice;
	            break;
	        case "2":
	            strPrice = "抢购价：￥" + productInfo.SPrice;
	            break;
	        case "3":
	            strPrice = "清仓价：￥" + productInfo.SPrice;
	            break;
	        default:
	            strPrice = "售价：￥" + productInfo.Price;
	            break;

	    }
	    item.find(".fontyj del").eq(0).html("￥" + productInfo.VPrice);
	    item.find(".fonthj").eq(0).html(strPrice);
	    if (productInfo.SPrice != productInfo.Price && productInfo.SalesFlag != "0")
	        item.find(".fontsj").html("售价：￥" + productInfo.Price.replace(".00", ""));
	    else
	        item.find(".fontsj").html("");
	    item.find(".starImg").html(GetStartStr(productInfo.Asoverall));

	    item.find("#bCommentCount").html(productInfo.AssessCount);
	    var urlTJ = "/product/SendFriend.aspx?objUrl=" + productInfo.PhotoPath + "&objPrice=" + productInfo.Price + "&objName=" + escape(productInfo.ProductName) + "&objID=" + productCode + "&objVPrice=" + productInfo.VPrice + "&objSprice=" + productInfo.SPrice;
	    item.find("#aTJ").attr("href", urlTJ);
	    var urlZC = "/Usercenter/UserFavorite.aspx?AddCart=" + productCode;
	    item.find("#aZC").attr("href", urlTJ);

	    item.find(".productInfo .ProductName").eq(0).html(productInfo.ProductName);
	    item.find(".productInfo .prouctCode").eq(0).html(productInfo.ProductCode);
	    item.find(".productInfo .sprice").eq(0).html(productInfo.SPrice);
	    item.find(".productInfo .vprice").eq(0).html(productInfo.VPrice);
	    item.find(".productInfo .price").eq(0).html(productInfo.Price);
	    //	    item.find(".productInfo .commentsNumber").eq(0).html(GetStartStr(productInfo.Asoverall));
	    //	    item.find(".productInfo .comments").eq(0).html(productInfo.AssessCount);
	    item.find(".productInfo .pic").eq(0).html(productInfo.MidPhoto);

	    item.find(".productInfo .salesFlag").eq(0).html(productInfo.SalesFlag);
	    //item.find("#divProp").eq(0).html(productInfo.Prop);

	    item.find(".StyleColor dd").each(function() {
	        $(this).removeClass("currentColor");
	        $(this).removeClass("otherColor");
	        if ($(this).attr("id") == "color_" + styleID + "_" + productCode) {
	            $(this).attr("class", "currentColor");
	            $(this).find("a").blur();
	        }
	        else {
	            $(this).attr("class", "otherColor");
	        }
	    });

	    item.find(".pic .teshui").remove();
	    item.find(".pic .qianggou").remove();
	    item.find(".pic .duanma").remove();
	    item.find(".pic .newview").remove();
	    item.find(".pic .qingcang").remove();

	    if (productInfo.SalesFlag == "1") {
	        item.find(".pic").eq(0).append("<div class=\"teshui\">" + productInfo.SPrice.replace(".00", "") + "</div> ");
	    }
	    else if (productInfo.SalesFlag == "2") {
	        item.find(".pic").eq(0).append("<div class=\"qianggou\">" + productInfo.SPrice.replace(".00", "") + "</div> ");
	    }
	    else if (productInfo.SalesFlag == "3") {
	        item.find(".pic").eq(0).append("<div class=\"qingcang\">" + productInfo.SPrice.replace(".00", "") + "</div> ");
	    }

	    if (productInfo.IsNew == "1")
	        item.find(".pic").eq(0).append("<div class=\"newview\"></div>");

	    if (productInfo.SPrice == productInfo.Price) {
	        if (productInfo.IsDuanma == "True") {
	            item.find(".pic").eq(0).append("<div class=\"duanma\"></div>");
	        }
	    }
	    //document.write(item.html());
	}); 
}


function GetStartStr(amount)
{
	var str="";
	var num = parseInt(amount);
	var deci = amount - num;
	for (var i = 0; i < 5; i++)
	{
	   if (i < num)
	   {
		   str+="<img src=\"http://images.vancl.com/NewVancl/Common/s1.gif\"/>";
	   }
	   else if (deci < 0.25 && i == num)
	   {
		   str+="<img src=\"http://images.vancl.com/NewVancl/Common/s0.gif\"/>";
	   }
	   else if (deci >= 0.25 && deci <= 0.75 && i == num)
	   {
		   str+="<img src=\"http://images.vancl.com/NewVancl/Common/s05.gif\"/>";
	   }
	   else if (deci > 0.75 && i == num)
	   {
		   str+="<img src=\"http://images.vancl.com/NewVancl/Common/s1.gif\"/>";
	   }
	   else
	   {
		   str+="<img src=\"http://images.vancl.com/NewVancl/Common/s0.gif\"/>";
	   }
	}
	return str;
}
