﻿$(function () {
    $(".form_valid .input_form,.form_valid select,.form_valid textarea").css({
        "border": "1px solid #d9d9d9",
        "border-top": "1px solid #c0c0c0",
        "font-family": "Arial, 宋体",
        "font-size": "12px",
        "color": "#444444"
    });
    $(".input_line").css({
        "border": "0",
        "border-bottom": "1px solid #444444",
        "font-family": "Arial, 宋体",
        "font-size": "12px",
        "color": "#444444"
    });
    
    $(".form_valid .input_form,.form_valid select,.form_valid textarea").mousemove(function () {
        hover($(this));
    });
    $(".form_valid .input_form,.form_valid select,.form_valid textarea").mouseout(function () {
        no_hover($(this));
    });
    $(".form_valid .input_form,.form_valid select,.form_valid textarea").focus(function () {
        hover($(this));
    });
    $(".form_valid .input_form,.form_valid select,.form_valid textarea").blur(function () {
        no_hover($(this));
    });
})
function hover(obj) {
    obj.css({ border: '1px solid #309fd6' });
}
function no_hover(obj) {
    obj.css({ "border": "1px solid #d9d9d9", "border-top": "1px solid #c0c0c0" });
}

function _sub(obj) {
    var form = obj;
    if (!form)
        return;
    FormAjaxSubmit({
        form: form,
        callback: function (r) {
            var d = r.data;
            if (d) {
                $(".bh").html(d.bh);
                $(".pw").html(d.pw);
                $(".form_valid").hide();
                $(".succe_msg").show();
                return;
            }
            if (r.succMsg) {
                alert(r.succMsg);
                history.go(0);
                //window.close();
                
            }
        }
    });
}

function _ywcxSub(obj) {
    var form = obj;
    if (!form)
        return;
    var bh = $("#bh").val();
    var pw = $("#pw").val();
    FormAjaxSubmit({
        form: form,
        callback: function (r) {
            var d = r.data;
            if (d) {
                $(".bh").html(d.bh);
                $(".pw").html(d.pw);
                $(".form_valid").hide();
                $(".succe_msg").show();
                return;
            }
            if (r.succMsg) {
                alert(r.succMsg);
                history.go(-1);
            }
        }
    });
}

function yyddSub(obj) {
    var form = obj;
    if (!form)
        return;
    FormAjaxSubmit({
        form: form,
        callback: function (r) {
            if (r.succMsg) {
                $(".tab_order").hide();
                $(".succe_msg").show();
            }
        }
    });
}

function transSub(obj) {
    var form = obj;
    if (!form)
        return;
    FormAjaxSubmit({
        form: form,
        callback: function (r) {
            var d = r.data;
            if (d) {
                $(".bh").html(d.bh);
                $(".pw").html(d.pw);
                $(".form_valid").hide();
                $(".succe_msg").show();
                return;
            }
            history.go(0);
        }
    });
}

function FormAjaxSubmit(Config) {
    var form = Config.form;
    form.ajaxSubmit({
        success: function (data) {
            var json = eval('(' + data + ')');
            if (json.success) {
                if (Config.callback)
                    Config.callback(json);
                return;
            } else {
                if (json.stateMsg) {
                    $(".valid_span").show(); //.show();
                    $(".valid_err").hide();
                    var item;
                    $.each(json.stateMsg, function (i) {
                        item = json.stateMsg[i];
                        if (item.msg != "") {
                            $("#v_" + item.id).hide();
                            $("#err_" + item.id).show();
                            $("#err_" + item.id).html(item.msg);
                        }
                    })
                }
                if (json.errMsg)
                    alert(json.errMsg);
            }
        },
        error: function (response, error) {
            alert(response.responseText);
        }
    });


//function FormSubmit(Config) {
//    $.ajax({
//        type: "post",
//        url: Config.url,
//        data: Config.params,
//        datatype: "json",
//        contentType: "application/json; charset=utf-8",
//        success: function (data) {
//            var json = eval('(' + data + ')');
//            if (json.success) {
//                if (Config.callback)
//                    Config.callback(json);
//                return;
//            } else {
//                if (json.stateMsg) {
//                    $(".valid_span").show(); //.show();
//                    $(".valid_err").hide();
//                    var item;
//                    $.each(json.stateMsg, function (i) {
//                        item = json.stateMsg[i];
//                        if (item.msg != "") {
//                            $("#v_" + item.id).hide();
//                            $("#err_" + item.id).show();
//                            $("#err_" + item.id).html(item.msg);
//                        }
//                    })

//                }
//            }
//        },
//        error: function (XMLHttpRequest, textStatus, errorThrown) {
//            alert(errorThrown);
//        }
//    });
//}



//    $.ajax({
//        type: "post",
//        url: Config.url,
//        data: Config.params,
//        datatype: "json",
//        contentType: "application/json; charset=utf-8",
//        success: function (data) {
//            var json = eval('(' + data + ')');
//            if (json.success) {
//                if (Config.callback)
//                    Config.callback(json);
//                return;
//            } else {
//                if (json.stateMsg) {
//                    $(".valid_span").show(); //.show();
//                    $(".valid_err").hide();
//                    var item;
//                    $.each(json.stateMsg, function (i) {
//                        item = json.stateMsg[i];
//                        if (item.msg != "") {
//                            $("#v_" + item.id).hide();
//                            $("#err_" + item.id).show();
//                            $("#err_" + item.id).html(item.msg);
//                        }
//                    })

//                }
//            }
//        },
//        error: function (XMLHttpRequest, textStatus, errorThrown) {
//            alert(errorThrown);
//        }
//    });
}

//type:get/post
// url, data, dataType, Start, End, Success, Error
function doRequest(Config) {
    $.ajax({
   		    type: Config.type,
   		    url: Config.url,
   		    data: Config.data,
   		    dataType: Config.dataType,
   		    beforeSend: Config.Start,
   		    error: function (response, error) {
   		        if (error == "error") {
   		            if (response.responseText) {
   		                //window.alert(response.responseText);
   		            }
   		        }
   		        if (Config.Error) {
   		            Config.Error(response, error);
   		        }
   		    },
   		    success: Config.Success,
   		    complete: Config.End
   		});
}
