$(function () {
    //添加项
    $("#rewriteItemAddBtn").click(function () {
        var obj = $(this);
        var showHtml = "";
        showHtml += "<p>";
        showHtml += "<label class=\"name\">自定义Url" + obj.attr("rel") + ":</label>";
        showHtml += "<input class=\"input200 f_left\" value=\"\" name=\"key_group\" type=\"text\" /> ";
        showHtml += "<label style=\"width:60px;\" class=\"name\">匹配Url:</label>";
        showHtml += "<input class=\"input200 f_left m_right8\" value=\"\" name=\"value_group\" type=\"text\" />";
        showHtml += "<label class=\"name\"><a href=\"#\" rel=\"del\" class=\"R\">[移除]</a></label>";
        showHtml += "<span style=\"display:block;height:6px;border-bottom:1px solid #A7DDE7;\" class=\"clear-0\"></span>";
        showHtml += "</p>";

        $("#itemBox").before(showHtml);
        return false;
    })

    //移除
    $("a[rel='del']").live('click', function () {
        var obj = $(this);
        if (confirm("确定删除此项吗？")) {
            obj.next("hr").remove();
            obj.parent().parent("p").remove();
            showRewriteHide();
        }
        return false;
    })

    //重新组合
    function showRewriteHide() {
        var showValue = "";
        $("#itemBox p").each(function () {
            var obj = $(this);
            showValue += obj.find("input[name='key_group']").val() + "#" + obj.find("input[name='value_group']").val() + ",";
        })
        $("#postData_hide").val(showValue);
    }

    //提交判断
    $("form").submit(function () {
        var retValue = true;

        $("#itemBox p input").each(function () {
            if ($(this).val() == "") {
                retValue = false;
                return false;
            }
        })

        //判断空
        if (!retValue) {
            $("input:submit").attr("disabled", false);
            $("input:submit").next("span").attr("class", "point ico-error R");
            $("input:submit").next("span").text("还有空的项未填写");
            setInterval(delSubmitBtnMsg, 3000);
            return false;
        }
        showRewriteHide();

        $("input:submit").attr("disabled", true);
        $("input:submit").next("span").attr("class", "Q");
        $("input:submit").next("span").html("<img src=\"Images/Loading.gif\" align=\"middle\" /> 正在保存…");
    });
})