var isIE6 = $.browser.msie && $.browser.version < 7;

var stockTimeout = null;
function stockIn() {
    if (stockTimeout != null) {
        window.clearTimeout(stockTimeout);
    }
    $(".addressWindows").show();
    $(".cityAdd").addClass("cityAddHover");

}

function stockOut() {
    stockTimeout = window.setTimeout(function() {
        $(".addressWindows").hide();
        $(".cityAdd").removeClass("cityAddHover");
    }, 50);
}

function checkStocking() {
    var closeCode = getCloseCode();
    if (closeCode != null) {
        var addr = $(".addressWindows a:contains('" + $.trim($("span.goodsAdd").text()) + "')");
        if (addr.length == 0) {
            return;
        }
        var housecode = addr.attr("name").replace("hs-", "");
        var url = [];
        url.push("/styles/stocking.mvc");
        url.push("?clothescode=" + closeCode);
        url.push("&housecode=" + housecode);
        $.get(url.join(""), function(data) {
            if (data == "True") {
                $("#stockinfo").text("最近库房有货");
            } else {
                $("#stockinfo").text("最近库房缺货, 预计从其他库房发出");
            }
        });
    }
    stockOut();
}





//获取CloseCode
function getCloseCode() {
    if ($(".selSize #onlickSelSize").length == 0) {
        return null;
    }
    return $(".selSize #onlickSelSize").attr("name")
}




function ChooseThisSize($this, SKU, maxNum) {
    if (maxNum < 10) {
        $("#comeon").fadeIn();
    } else {
        $("#comeon").fadeOut();
    }
    $(".selSize li").removeAttr("id");
    $($this).attr("id", "onlickSelSize");
    maxNum = parseInt(maxNum);
    $("#selectedSize").text("" + $.trim($($this).text()));//	规格：.attr("title")
    $(".selSizeArea h3 strong").text($.trim($($this).text()));

    var span = $("#selectedAmount option").length - maxNum;
    if (span > 0) {
        //减少option
        $("#selectedAmount option").eq(maxNum - 1).nextAll().remove();
    } else if (span < 0) {
        //增加option
        span = Math.abs(span);
        var array = new Array(span);
        $.map(array, function(n, i) {
            var val = parseInt($("#selectedAmount option:last-child").val()) + 1;
            $("#selectedAmount").append("<option value=\"" + val + "\">" + val + "</option>");
        });
    }
    checkStocking();
    $(".cityAdd").unbind();
    $(".cityAdd").hover(stockIn, stockOut);
    $(".addressWindows").hover(stockIn, stockOut);
}



function ChooseThisSize1($this, SKU, maxNum) {
    if (maxNum < 10) {
        $("#comeon").fadeIn();
    } else {
        $("#comeon").fadeOut();
    }
    $(".selColor li").removeAttr("id");
    $($this).attr("id", "onlickSelSize");
    maxNum = parseInt(maxNum);
    $("#selectedColor").text("颜色：" + $.trim($($this).text()));

    var span = $("#selectedAmount option").length - maxNum;
    if (span > 0) {
        //减少option
        $("#selectedAmount option").eq(maxNum - 1).nextAll().remove();
    } else if (span < 0) {
        //增加option
        span = Math.abs(span);
        var array = new Array(span);
        $.map(array, function(n, i) {
            var val = parseInt($("#selectedAmount option:last-child").val()) + 1;
            $("#selectedAmount").append("<option value=\"" + val + "\">" + val + "</option>");
        });
    }
    checkStocking();
    $(".cityAdd").unbind();
    $(".cityAdd").hover(stockIn, stockOut);
    $(".addressWindows").hover(stockIn, stockOut);
}

