﻿function addtoCart() {
    var qtystr = "";
    var pidstr = "";
    var qty = document.getElementsByName("qty");
    var pid = document.getElementsByName("pid");
    for (var i = 0; i < qty.length; i++) {
        if ($.trim(qty[i].value) != null && $.trim(qty[i].value) != "") {
            qtystr += $.trim(qty[i].value) + ",";
            pidstr += $.trim(pid[i].value) + ",";
            qty[i].value = "";
        }
    }
    if (qtystr != "") {
        var url = "/Cart/addToCart.asp?qty=" + qtystr + "&pid=" + pidstr;
        $.get(url, function(result) {
            if (!document.getElementById("dynmaic"))
                $(document.body).append("<div id=\"dynmaic\"></div>");
            $("#dynmaic").html(result);
            window["dialog"] = $("#dynmaic").dialog({
                title: "website dialog",
                close: function() {
                    $(this).dialog("destroy");
                }
            });
        });
    }
    else {
        alert("Please input quantity!")
    }
}
function checkout() {
    window.location = "/Cart/viewcart.asp";
}
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();
        }
    }
}


