function Calculate(Weight, Zone) {
    // 单价列表，包括基本价格
    var PriceList = [
                    [17.9, 3.5, 3.5, 3.5, 3.6, 7.2],
                    [19.3, 4.3, 4.3, 4.2, 4.4, 8.8],
                    [20.5, 6.2, 5.9, 5.9, 5.9, 11.80],
                    [20.5, 6.2, 5.9, 5.9, 5.9, 11.80],
                    [27.7, 8.6, 8.2, 7.8, 7.4, 14.60],
                    [31.3, 9.3, 8.6, 7.9, 8.9, 15.9],
                    [25.7, 7.1, 6.4, 5.7, 6.5, 11.9],
                    ];
    // Weight 在每一段中的“数量”
    var WeightPart1 = 0,
        WeightPart2 = 0,
        WeightPart3 = 0,
        WeightPart4 = 0,
        WeightPart5 = 0;
    // Zone 必须在 1 到 6 之间
    if ((Zone < 1) || (Zone > 7)) throw new Error("Zone must be 1 - 7");
    Zone = Zone - 1;
    // 按规则对 Weight 进行舍入操作
    if (Weight < 30) {
        // 注释掉第 15 和第 22 行，可以让 25.5 作为 26 处理，否则仍然作为 25.5
        if (Math.round(Weight) - Weight != 0.5) {
            if (Math.round(Weight) < Weight) {
                Weight = Math.round(Weight) + 0.5;
            }
            else {
                Weight = Math.round(Weight);
            }
        }
    }
    else if (Weight > 30) {
        if (Math.round(Weight) < Weight) {
            Weight = Math.round(Weight) + 1;
        }
        else {
            Weight = Math.round(Weight);
        }
    }
    // 将 Weight 拆分成几个部分，计算每个部分的“数量”
	if (Weight < 1) {
	        Weight = 1;
    }	
    if (Weight <= 5) {
        WeightPart1 = Weight * 2;
    }
    else {
        WeightPart1 = 10;
        if (Weight <= 10) {
            WeightPart2 = (Weight - 5) * 2;
        }
        else {
            WeightPart2 = 10;
            if (Weight <= 20) {
                WeightPart3 = (Weight - 10) * 2;
            }
            else {
                WeightPart3 = 20;
                if (Weight <= 30) {
                    WeightPart4 = (Weight - 20) * 2;
                }
                else {
                    WeightPart4 = 20;
                    WeightPart5 = (Weight - 30);
                }
            }
        }
    }

	
    // 套用公式计算结果
    var Result = PriceList[Zone][0] + (PriceList[Zone][1] * WeightPart1) +
        (PriceList[Zone][2] * WeightPart2) + (PriceList[Zone][3] * WeightPart3) +
        (PriceList[Zone][4] * WeightPart4) + (PriceList[Zone][5] * WeightPart5);
    // 大于 $29 时的折扣
    // 返回值始终带有两位小数(两个 return 语句只能并且必须选用一个，另一个必须被注释或者删掉)
    return Result.toFixed(2);
    // 不管返回值的小数问题
    //return Result;
}

function CalIt() {
    var oWeight;
    var oZone;
    var oRate;
    oWeight = document.getElementById("Weight");
    oZone = document.getElementById("Zone");
    oRate = document.getElementById("Rate");
    if (isNaN(oWeight.value)) {
        // 若在 Weight 文本框里输入的不是数字则提示
        oRate.value = "Please input a number";
    }
    else {
        oRate.value = Calculate(oWeight.value, oZone.value);
         //alert(oNoDisc.checked);
    }
}

