﻿document.domain = "yi9.com";

//读取评论相关信息
function getCommentSummary(pid) {
    $.getJSON("http://yi92010.yi9.com/product/review.aspx?action=loadSummary&callback=?&productID=" + pid,
      function(summartResult) {
          var summary = summartResult.Summary;
          $("#totalCommentsNum").text(summary.PctTotal);
          $("#comments_all_number").text(summary.PctTotal + " ");

          $("#lblPctPos").css("width", summary.PctPositive + "%");
          $("#txtPctPosition").text(summary.PctPositive + "%");

          $("#lblPctNeutral").css("width", summary.PctNeutral + "%");
          $("#txtPctNeutral").text(summary.PctNeutral + "%");

          $("#lblPctNegative").css("width", summary.PctNegative + "%");
          $("#txtPctNegative").text(summary.PctNegative + "%");

          $("#comments_bar_loading").remove();
          $("#comments_bar").css("display", "inline");
          $(".comments_bg_p01_div02").css("display", "inline");
      })
}

function getComments(pid, mType) {
    $.getJSON("http://yi92010.yi9.com/product/review.aspx?action=reviewList&callback=?&productID=" + pid + "&mType=" + mType,
      function(commentsResult) {
          $("#comments_body" + mType).html("");
          var comments = commentsResult.ReviewList;
          if (comments.length > 0) {
              $(comments).each(function() {
                  var comment = "<table width='100%' border='0' cellspacing='0' cellpadding='0' class='comment_table'>";
                  comment += "<thead>";
                  comment += "<tr>";
                  comment += "<th width='12%'>用户名</th>";
                  comment += "<th width='88%'>";
                  comment += "<div class='left'>评论</div>";
                  comment += "<div class='right'>" + this.mDate + "</div>";
                  comment += "</th>";
                  comment += "</tr>";
                  comment += "</thead>";
                  comment += "<tbody>";
                  comment += "<tr>";
                  comment += "<td class='td02'>";
                  comment += "<p class='p01'>" + this.NickName; +"</p>";
                  comment += "<p class='p02'></p>";
                  comment += "</td>";
                  comment += "<td class='td01'>";
                  comment += "<span>" + this.tTitle + "</span>";
                  comment += "<div>";

                  for (var i = 0; i < this.pMark; i++)
                      comment += "<img src=\"http://www.yi9.com/images/star02.gif\" />";
                  for (var i = 0; i < 5 - this.pMark; i++)
                      comment += "<img src=\"http://www.yi9.com/images/star01.gif\" />";

                  comment += "</div>";
                  comment += "<p class='clear'>" + this.tContent;
                  comment += "</td>";
                  comment += "</tr>";
                  comment += "</tbody>";
                  comment += "</table>";

                  $("#comments_body" + mType).append(comment);
                  $("#comments_list_loading" + mType).remove();
                  $("#comments_body" + mType).css("display", "inline");
              });
          } else {
              $("#comments_list_loading" + mType).remove();
              $("#comments_body" + mType).css("display", "inline");
          }
      })
}

function getInquiries(pid) {
    var i = 0;
    $.getJSON("http://yi92010.yi9.com/product/inquiries.aspx?action=InquiriesList&callback=?&productID=" + pid,
      function(inquiriesResult) {
          $("#inquiriesBody").html("");
          var inquiries = inquiriesResult.InquiriesList;
          if (inquiries.length > 0) {
              $(inquiries).each(function() {
                  var inquiry = "";

                  inquiry += "<li class=\"clear\">";
                  inquiry += "<div class=\"buy_div02_line\">";
                  inquiry += "<div class=\"buy_div02_line_left\">";
                  inquiry += "用户名: " + this.NickName + "</div>";
                  inquiry += "<div class=\"buy_div02_line_right\">";
                  inquiry += this.mDate + "</div>";
                  inquiry += "</div>";
                  inquiry += "<div class=\"buy_div02_bg\">";
                  inquiry += "<p class=\"clear\">";
                  inquiry += "<span class=\"p01\">咨询内容：</span><span class=\"p02\">" + this.tContent + "</span>";
                  inquiry += "</p>";
                  inquiry += "<p class=\"clear font01\">";
                  inquiry += "<span class=\"p03\">易酒回复：</span><span class=\"p02\">" + this.rContent + "</span>";
                  inquiry += "</p>";
                  inquiry += "</div>";
                  inquiry += "</li>";

                  $("#inquiriesBody").append(inquiry);
                  $("#inquiriesBody_loading").remove();
                  $("#inquiriesBody").css("display", "block");
                  i++;
              });
          } else {
              $("#inquiriesBody_loading").remove();
              $("#inquiriesBody").css("display", "inline");
          }
          $("#inquiries_total_number").text(i);
      })
}
function selectOneLayer_ajax(Oneli, One, Num, mType, pid) {
    getComments(pid, mType);
    for (i = 1; i < 5; i++) {
        if (i == Num) {
            document.getElementById(Oneli + i).className = "intabcurrent"; document.getElementById(One + i).style.display = "block";
        }
        else {
            document.getElementById(Oneli + i).className = ""; document.getElementById(One + i).style.display = "none";
        }
    }
}
function formLoad(productID) {
    var options = {
        zoomWidth: 400,
        zoomHeight: 300,
        showEffect: 'show',
        hideEffect: 'fadeout',
        fadeoutSpeed: 'slow',
        title: false,
        xOffset: 40
    }
    $(".jqzoom").jqzoom(options);
    getCommentSummary(productID);
    getComments(productID, 1);
    getInquiries(productID);
    getProductUnite(productID);
}
var groupprice = 0;

function getProductUnite(pid) {

    groupprice = 0;
    var id = 0;
    var productUnite = "";
    var productTable = "";
    var buygroupline = "";

    $.getJSON("http://yi92010.yi9.com/product/productUnite.aspx?action=getProductUnite&callback=?&ProductID=" + pid,
     function(json) {
         for (var i = 0; i < json.length; i++) {

             id++;

             if (i == 0) { getProductByID(pid); }
             groupprice += Math.round(json[i].MemberPrice);
             productUnite += "<li class='winzh_kj_lidiv03'><img src='http://www.yi9.com/images/img_177.gif' /></li>";
             productUnite += "<li><div class='winzh_kj_lidiv01'><a target='_blank'  href='"+json[i].FilePath+"'><img src='http://www.yi9.com/yi9ErpImages/"+json[i].ImgBig4+"' width='74' height='79' /></a></div><div class='winzh_kj_lidiv02'><input  id=chb" + json[i].ProductID + " value=" + json[i].MemberPrice + " name='chickbuy' onclick='javascript:void(0);checkclick(" + pid + ",this);'  checked='checked' name='' type='checkbox' value='' /><a target='_blank' href='"+json[i].FilePath+"'><span>" + json[i].ChineseName + "</span></a></div></li>";
             buygroupline += json[i].ProductID + ",";
         }
         if (id != 0) {
             $("#P_Unite").show();
             $("#buyline").attr("href", "javascript:buy('" + pid + "," + buygroupline.substring(0, buygroupline.length - 1) + "','1,1,1,1')");
             $("#productUnite").append(productUnite);
             $("#pprice").text("￥" + Math.round(groupprice + primaryprice));

         }
     })
}


var primaryprice = 0;
var price = 0;

function getProductByID(pid) {

    $.getJSON("http://yi92010.yi9.com/product/productUnite.aspx?action=getProductByID&callback=?&PID=" + pid,
     function(json) {

         $("#productChineseName").html(json.ChineseName);
         $("#imgone").attr("src", "http://www.yi9.com/yi9ErpImages/"+json.ImgBig4);
         $("#line").attr("href", json.FilePath);
         primaryprice = json.MemberPrice;

         $("#pprice").text("￥" + Math.round(groupprice + primaryprice));
     })

}


function checkclick(pid, src) {

    var j = 0;
    var gprice = 0;
    var buygroupline = "";
    var checkid = "";
    var checknames = document.getElementsByName('chickbuy');
    var groupnum="";
    checkid = checknames[0].id;
    for (var i = 0; i < checknames.length; i++) {
        if (checknames[i].checked == true) {
            j++;
            gprice += Math.round(checknames[i].value);
            buygroupline += checknames[i].id.substring(3) + ",";

        }
        
    }

    $("#pprice").text("￥" + Math.round(gprice + primaryprice));

   switch(j)
   {
   case 1:groupnum="1,1";
   break;
   case 2:groupnum="1,1,1";
   break
   case 3:groupnum="1,1,1,1";
   break;
   }  
   
     $("#buyline").attr("href", "javascript:buy('" + pid + "," + buygroupline.substring(0, buygroupline.length - 1) + "','"+groupnum+"')");

    if (j == 0) {
        $("#" + src.id).attr("checked", true);
      $("#buyline").attr("href", "javascript:buy('" + pid + "," + checkid.substring(3) + "','1,1')");
        alert("请确认选中至少一款");
        j = 1;
    }
    $("#count").html(j);
}


function kaixin() {
    var u = 'http://www.kaixin001.com/repaste/share.php?rtitle=' + encodeURIComponent("易酒") + '&rurl=' +
encodeURIComponent(location.href) + '&rcontent=' + encodeURIComponent("易酒");
    if (!window.open(u, 'kaixin')) {
        location.href = u;
    }
}
function xiaonei() {
    var u = 'http://share.xiaonei.com/share/buttonshare.do?link=' + encodeURIComponent(location.href) + '& title=' + encodeURIComponent("易酒");
    if (!window.open(u, 'xiaonei')) {
        location.href = u;
    }
}
function douban() {
    var u = 'http://www.douban.com/recommend/?url=' + encodeURIComponent(location.href) + '& title=' + encodeURIComponent("易酒");
    if (!window.open(u, 'douban')) {
        location.href = u;
    }
}
function facebook() {
    var u = 'http://www.facebook.com/share.php?u=' + encodeURIComponent(location.href) + '& title=' + encodeURIComponent("易酒");
    if (!window.open(u, 'facebook')) {
        location.href = u;
    }
}
function twitter() {

    var u = 'http://twitter.com/home?status=' + encodeURIComponent("易酒");
    if (!window.open(u, 'twitter')) {
        location.href = u;
    }
}
