﻿/// <reference path="jquery-1.4.1.js" />
/// <reference path="jquery-1.4.1-vsdoc.js" />
// JScript 文件

function Warn(msg) {
    $.messager.alert('失败信息', msg, 'warning');
}
function Confirm(msg) {
    $.messager.confirm('确定删除吗', msg, function(r) {
        if (r) {
            return true;
        }
        else {
            return false;
        }
    });
}
function BindDate() {
    $(".is_date").click(function() {
        WdatePicker({ isShowClear: false, readOnly: true, firstDayOfWeek: 1, dateFmt: 'yyyy-MM-dd HH:mm:ss' });
    });

}
function BindDateNoTime() {
    $(".is_date").click(function() {
        WdatePicker({ isShowClear: false, readOnly: true, firstDayOfWeek: 1, dateFmt: 'yyyy-MM-dd' });
    });

}
$(function() {
    //保存按钮
    $(".btn_save").click(function() {
        $.ajax({
            type: "POST",
            dataType: "xml",
            url: $(this).attr("rel"),
            data: $(".addForm").serialize(),
            success: function(msg) {
                var json = $(msg).find("string").text();
                json = JSON.parse(json);
                $("#feedMsg").html(json.Msg);
                $("#feedMsg").fadeOut(200);
                location.href = json.ReUrl;
            }
        });
    });

    //更新按钮
    $(".btn_update").click(function() {
        $.ajax({
            type: "POST",
            dataType: "xml",
            url: $(this).attr("rel"),
            data: $(".edit_form").serialize(),
            success: function(msg) {
                var json = $(msg).find("string").text();
                json = JSON.parse(json);
                $("#feedMsg").html(json.Msg);
                $("#feedMsg").fadeOut(200);
                location.href = json.ReUrl;
            }
        });

    });

    //返回按钮
    $(".btn_back").click(function() {
        location.href = $(this).attr("rel");
    });

    //新增按钮
    $(".add_btn").click(function() {
        location.href = $(this).attr("rel");
    });

    //编辑按钮
    $(".edit_btn").click(function() {
        var checkedNums = $(".form_checkbox:checked").length;

        if (checkedNums == 0) {
            $.messager.alert('警告', '你选择至少一个项目操作！', 'warning');

        }
        else {
            if (checkedNums > 1) {
                $.messager.alert('警告', '你选择的项目多于一个，请选择一个进行编辑！', 'warning');
            }
            else {
                location.href = $(this).attr("rel") + "?editId=" + $(".form_checkbox:checked").val();
            }
        }
    });

    //编辑按钮
    $(".check_btn").click(function() {
        var checkedNums = $(".form_checkbox:checked").length;

        if (checkedNums == 0) {
            $.messager.alert('警告', '你选择至少一个项目操作！', 'warning');
            return false;
        }
        else {
            if (checkedNums > 1) {
                $.messager.alert('警告', '你选择的项目多于一个，请选择一个进行编辑！', 'warning');
                return false;
            }

        }
    });

    //删除按钮
    $(".del_btn").click(function() {
        var checkedNums = $(".form_checkbox:checked").length;
        if (checkedNums == 0) {
            $.messager.alert('警告', '你选择至少一个项目操作！', 'warning');
            return false;
        }

        //        else {
        //            var fields = $(".form_checkbox:checked").not($(".selectAll")[0]).serializeArray();
        //            var ret = "";
        //            $.each(fields, function(i, field) {
        //                ret += field.value;
        //                ret += ","
        //            });
        //            ret = ret.substring(0, ret.length - 1)
        //            $.ajax({
        //                type: "POST",
        //                dataType: "xml",
        //                url: $(this).attr("rel"),
        //                data: { delId: ret },
        //                success: function(msg) {
        //                    var json = $(msg).find("string").text();
        //                    json = JSON.parse(json);
        //                    $("#feedMsg").html(json.Msg);
        //                    $("#feedMsg").fadeOut(200);
        //                    location.href = json.ReUrl;
        //                }
        //            });
        //        }
    });

    //全选按钮
    $(".selectAll").click(function() {
        if ($(this).attr("checked") == true) {
            $(this).attr("checked", true);
            $(".form_checkbox").attr("checked", true);
        }
        else {
            $(this).attr("checked", false);
            $(".form_checkbox").attr("checked", false);
        }
    });

    //鼠标放上行之后换颜色
    $("tr.tips_row0").hover(function() {
        $(this).removeClass("tips_row0");
        $(this).addClass("hover");    //鼠标经过添加hover样式
    },
        function() {
            $(this).removeClass("hover");
            $(this).addClass("tips_row0");    //鼠标离开移除hover样式
        }
    );

    $("tr.tips_row1").hover(function() {
        $(this).removeClass("tips_row1");
        $(this).addClass("hover");    //鼠标经过添加hover样式
    },
        function() {
            $(this).removeClass("hover");
            $(this).addClass("tips_row1");  //鼠标离开移除hover样式
        }
    );

    //退出系统
    $(".btnLoginOut").click(function() {
        $.ajax({
            type: "POST",
            dataType: "text",
            url: $(this).attr("rel"),
            success: function(msg) {
                location.href = "#";
                Warn(msg);
                location.reload()
            }
        });
    });


});


function Open(url) {
    window.open(url, 'newwindow', 'height=700,width=650,top=1,left=120,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=auto,status=no')
}

function Open2(url) {
    window.open(url, 'newwindow', 'height=500,width=350,top=60,left=120,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,location=no,status=no')
}

function OpenWin(url, h, w, top, left) {
    window.open(url, "newwindow", "height=" + h + ", width=" + w + ", top=" + top + ", left=" + left + ", toolbar=no, menubar=no, scrollbars=yes, location=no, status=no");
}
   



