﻿function addfavorites(proid) {
   var xmlhttpe = createXMLHttpRequeste();
    xmlhttpe.onreadystatechange = function() {
        if (xmlhttpe.readyState == 4) {
            //判断是否请求成功
            if (xmlhttpe.status == 200) {
                if (xmlhttpe.responseText == "0") {

                    $("f-" + proid).innerHTML = "<a href='javascript:void();' class='listact'>已收藏</a>";
                    $("f-" + proid).className = "star-on";

                }
                else if (xmlhttpe.responseText == "1") {
                alert("请先登录！");
                }
                else {
                    alert(xmlhttpe.responseText);
                }
            }

            else {
                alert("发生内部错误！");
            }
        }
    }
    xmlhttpe.open("GET", "/Theme/Default/js/product.aspx?etype=favoritesadd&proid=" + encodeURIComponent(proid) + "&rd=" + Math.random(), true); //传递数据的方法同样有GET和POST两种,但是当方法为POST时下面的一句话就必须写
    xmlhttpe.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttpe.send(null);
}


function addcart() {
    var hiproid = $("hiproid");
    var hiprosdk = $("hiprosdk");
    
    var goodsnum = $("goodsnum");
    var dropColor = $("dropColor");
    var dropSize = $("dropSize");
    var procolor ="";
    var prosize = "";
    if (dropColor != null)
    { procolor = dropColor.value }
    if (dropSize != null)
    { prosize = dropSize.value }
  var  xmlhttpe = createXMLHttpRequeste();
  xmlhttpe.open("GET", "/Theme/Default/js/product.aspx?etype=addcart&productsdk=" + encodeURIComponent(hiprosdk.value) + "&productid=" + encodeURIComponent(hiproid.value) + "&procolor=" + encodeURIComponent(procolor) + "&prosize=" + encodeURIComponent(prosize) + "&productnum=" + encodeURIComponent(goodsnum.value) + "&rd=" + Math.random(), false); //传递数据的方法同样有GET和POST两种,但是当方法为POST时下面的一句话就必须写
    xmlhttpe.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttpe.send(null);
    if (xmlhttpe.readyState == 4) {
        //判断是否请求成功
        if (xmlhttpe.status == 200) {
            if (xmlhttpe.responseText == "0") {

                location.href = $("hiurl").value+'shoppingcart.html';

            }
            else if (xmlhttpe.responseText == "1") {
                alert("你选择的商品不存在");
            }
            else {
                alert(xmlhttpe.responseText);
            }
        }

        else {
            alert("发生内部错误！");
        }
    }
}


function loadpro() {
    var hiproid = $("hiproid");
    var dropColor = $("dropColor");
    var dropSize = $("dropSize");
    var procolor = "";
    var prosize = "";
    if (dropColor != null)
    { procolor = dropColor.value }
    if (dropSize != null)
    { prosize = dropSize.value }

    if (procolor == "0") {
        return;
    }
    if (prosize == "0") {
        return;
    }

   var xmlhttpe = createXMLHttpRequeste();

   xmlhttpe.open("GET", "/Theme/Default/js/product.aspx?etype=loadpro&productid=" + encodeURIComponent(hiproid.value) + "&procolor=" + encodeURIComponent(procolor) + "&prosize=" + encodeURIComponent(prosize) + "&rd=" + Math.random(), false); //传递数据的方法同样有GET和POST两种,但是当方法为POST时下面的一句话就必须写
    xmlhttpe.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
    xmlhttpe.send(null);
    if (xmlhttpe.readyState == 4) {
        //判断是否请求成功
        if (xmlhttpe.status == 200) {
            if (xmlhttpe.responseText != "") {
                $("prosdk").innerHTML = xmlhttpe.responseText;
            } 
        }

        else {
            alert("发生内部错误！");
        }
    }
}


function delcart(proid, prosdk) {
    var hiproid = $("hiproid");
    var hiprosdk = $("hiprosdk");
    var hitype = $("hitype");
    var hinum = $("hinum");
    hitype.value = "del";
    hiproid.value = proid;
    hiprosdk.value = prosdk;
    document.getElementById("form1").submit();
}

function updatecart(proid, prosdk) {
    var hiproid = $("hiproid");
    var hiprosdk = $("hiprosdk");
    var hitype = $("hitype");
    var hinum = $("hinum");
    hitype.value = "update";
    hiproid.value = proid;
    hinum.value = $("num-" + proid + "-" + prosdk).value;
    hiprosdk.value = prosdk;
    document.getElementById("form1").submit();
}
