﻿function delProductItemFromCart(id) {
    var form = document.getElementById("item_" + id);
    var url = "/handle/deletecart.ashx?index=" + id;

    form.action = url;
    form.method = "POST";
    form.submit();
}
function set_price(str, quantity) {
    if (quantity != "0" && quantity != "") {
        priceObj = document.getElementById('price');
        arr = str.split(",");
        str = str.indexOf(",") == -1 ? str : arr[0] + arr[1];
        priceStr = parseInt(str) * parseInt(quantity);
        priceObj.innerHTML = "<strong>" + priceStr + "</strong>";
    }
}

function on_set_sale(pdtId) {
    var productId = '', quantity = '', urlStr = '';
    quantity = document.getElementById('quantity').value;
    productId = pdtId;
    var standard = document.getElementById('size').value;
    urlStr = "/handle/AddCart.ashx?productid=" + productId + "&quantity=" + quantity + "&standard=" + standard;
    window.location.href = urlStr;
}
function search() {
    var w = document.getElementById("txtSearch").value;
    if (w.length == 0) {
        alert("the keyword cannot be empty!");
        return;
    }
    document.getElementById("frmSearch").submit();
}

function login() {
    var email = encodeURIComponent($("#email").val());
    var password = encodeURIComponent($('#password').val());
    var returnUrl = encodeURIComponent($('#returnurl').val());
    $.ajax({
        type: "post",
        url: "/handle/Login.ashx",
        data: "email=" + email + "&password=" + password,
        success: function(msg) {
            if (msg != "0") {
                $("#regmsg").html("ok!login.....");
                if (returnUrl.length > 0)
                    window.location = returnUrl;
                else
                    window.location = "/myorders.html";
            }
            else {
                $("#regmsg").html("account or password error!");
            }
        },
        error: function(msg) {
            alert(msg);
        }
    });
}
