$(document).ready(function(){
    //下拉按钮鼠标经过效果
    $(".new_dropdown").on("mouseover",".dropdown-toggle,.dropdown-menu",function(){
　　　　$(this).parent('.dropdown').addClass('open');
　　})
    .on("mouseout",".dropdown-toggle,.dropdown-menu",function(){
　　　　$(this).parent('.dropdown').removeClass('open');
　　});

    $("#btn-verify").click(function(){
        if($("#input-verify-uname").val()==''){
            alert('姓名不能为空');
            return false;
        }
        var url=$("form#form-verify").attr('action');
        var data=$("form#form-verify").serialize();
        $.post(url,data,function(result){
            if (result==1) {
                $("#verify-dialog").css("display","none");
                location.href=location.href;
            }else if(result==2){
                alert('疑似有重名,请填写完整、准确的姓名信息！');
            }else{
                alert('个人信息更新失败，请联系梁宇云！');
            }
        });
    });

    $("#person-set").click(function(){
        $("#verify-dialog").css("display","block");
    });
});

function submitForm(form) {
    var url=$("#" + form).attr('action');
    var data=$("#" + form).serialize();
    $.ajax({
      type: 'POST',
      url: url,
      data: data,
      success: successfun,
      error: errorfun,
      dataType: "json"
    });
    return false
}
function errorfun(responseText, statusText, xhr, form) {
   alert("Action unsuccessful. Try again later.")
}
function successfun(responseText, statusText, xhr, form) {
    for (var key in responseText) {
        if (responseText[key].name == "ok") {
            if ($("#auto_update_cache_checkbox").attr("checked")) {
                $.modaldialog.success(responseText[key].value + "n" + "\u9759\u6001\u9875\u9762\u66f4\u65b0\u4e2d...");
                updateCache($("#auto_update_cache_checkbox").val(), "")
            } else {
                $.modaldialog.success(responseText[key].value)
            }
        } else {
            if (responseText[key].name == "ok_go") {
                setTimeout(function () {
                    window.location.href = responseText[key].value
                }, 2000)
            } else {
                if (responseText[key].name == "no") {
                    $.modaldialog.error(responseText[key].value)
                } else {
                    if (responseText[key].name == "go") {
                        window.location.href = responseText[key].value
                    } else {
                        if (responseText[key].name == "ok_modal") {
                            $(".modal").modal("hide");
                            $.modaldialog.success(responseText[key].value)
                        } else {
                            if (responseText[key].name == "no_modal") {
                                $(".modal").modal("hide");
                                $.modaldialog.error(responseText[key].value)
                            } else {
                                var url = window.location.href;
                                window.location.href = url.replace(/#warning/g, "") + "#warning";
                                showTips(responseText[key].name, responseText[key].value);
                                $("button").button('reset');
                            }
                        }
                    }
                }
            }
        }
    }
    return true
}

function showTips(objName, title) {
    $("#" + objName).tooltip({
        title: title,
        placement: "top",
        trigger: "manual"
    });
    $("#" + objName).tooltip("show");
    setTimeout(function () {
        $("#" + objName).tooltip("hide")
    }, 3000)
}

function ajax_link($this) 
{
    var url=$this.attr('data-href');
    $.ajax({
        type: 'get',
        url: url,
        data: '',
        dataType: "json",
        success: function(responseText, statusText, xhr, form){
            if (responseText.status == "ok_go") {
                $("#msgbox").text('操作成功！');
                if (comment_url) {
                    window.location.href =comment_url;
                }else{
                    window.location.href = responseText.link;
                }
            }
      }
    });
    return false;
}
