﻿function addtoCart() {
    var qtystr = [];
    var pidstr = [];
    var ii = 0;

    $(":input[name='qty']").each(function(i, n) {
        if (!isNaN(parseInt(n.value))) {
            qtystr[ii] = n.value;
            pidstr[ii++] = $(n).parent().find(":hidden[name='pid']").val();
            n.value = "";
        }
    });
    if (qtystr.length > 0 && (qtystr.length == pidstr.length)) {
        var url = "/Website/ShopCar/addToCar.aspx";
        $.post(url, { ProductId: pidstr, Count: qtystr }, function(result) {
            result = $(result);
            window.CloseDialog = function() {
                result.dialog("destroy");
            }
            result.dialog({
                width: 500
                , modal: true
                , close: CloseDialog
            });
        });
    }
    else {
        alert("Please input quantity!")
    }
}
function checkout() {
    window.location = "/Website/ShopCar/ShopCar.aspx";
}
function checkinput(v) {
    if (v.value.length != 0) {
        var filter = /^\s*[0-9]{0,5}\s*$/;
        if (!filter.test(v.value) || v.value == "0" || v.value.charAt(0) == "0") {
            alert("Input Error!");
            v.focus();
            v.select();
        }
    }
}


