﻿function CreateList(arr) {
    var obj = document.createElement("select");
    for (var n in arr) {
        $(obj).append("<option value=\"" + arr[n].fee + "\">" + arr[n].name + "</option>");
    }
    obj.options.selectedIndex = 0;
    obj.onchange = function () {
        DataChange();
    }    
    return obj;
}

function DataChange() {
    var tab1 = $("#tr1 td");
    var sp = $(tab1[2]).find("span");
    var sel = $(tab1[2]).find("select");
    var idx = sel[0].options.selectedIndex;
    var f1 = arr1[idx].fee;
    sp.html(FormatPrice(f1));
    $(tab1[8]).html(arr1[idx].remark)

    sp = $(tab1[4]).find("span");
    sel = $(tab1[4]).find("select");
    idx = sel[0].options.selectedIndex;
    var f2 = arrFee1[idx].fee;
    sp.html(FormatPrice(f2));

    var t = FormatPrice(f2 + f1 + stock);
    $(tab1[5]).html(t);
    $(tab1[6]).html(arrFee1[idx].time)
}

function FormatPrice(v) {
    v = Math.ceil(100 * v) / 100;
    var t = v + "";
    var arr = t.split(".");    
    if (arr.length == 1) t=t + ".00";
    else if (arr[1].length == 1) t=t + "0";    
    return t;
}

function orderNow() {
    window.top.location.replace("/User/Login.aspx");
}


var fromList = [{ n: "中国", v: "CN", m: 2 },
{ n: "美国仓库", v: "US", m: 1, ct: "San Francisco" },
{ n: "英国仓库", v: "UK", m: 1, ct: "Portsmouth" },
{ n: "澳洲仓库", v: "AU", m: 1, ct: "Sydney"}];

function Validate() {
    if (!$("#weight").val()) {
        alert("请填写包裹重量.");
        return false;
    }
    if (!$("#length").val() || !$("#width").val() || !$("#height").val()) {
        alert("请填写包裹包装规格.");
        return false;
    }
    return true;
}

function BindFrom(val) {
    $("#from option").remove();
    $.each(fromList, function (index, item) {
        if (item.m == val) {
            $("#from").append("<option value='" + item.v + "'>" + item.n + "</option>");
        }
    });
    setTimeout(function () {
        $("#from option")[0].selected = true;
    }, 10);     
}

function FindItem(v) {
    var res = false;
    $.each(fromList, function (index, item) {
        if (item.v == v) {
            res = item;
            return false;
        }
    });
    return res;
}
