$(function () {
    $("#myPageAlert").hide();
    systemparameterDataBind();
});
//绑定对话类
function systemparameterDataBind()
{
    manageObj.gettalktype();
}
//绑定对话类型回调
function AsyncGetTalkTypeResult(jsonResult)
{
    if (jsonResult.success) {
        if (jsonResult.data.length > 0) {
           
            for (i in jsonResult.data) {
                if (jsonResult.data[i].key == "talktype") {
                    var item = $.parseJSON(jsonResult.data[i].valus);
                    $("#txtFansMax_JJ").val(item.fans_jj);

                    $("#txtFansMax_JH").val(item.fans_jh);

                    $("#txtFansMax_YB").val(item.fans_yb);

                }

                if (jsonResult.data[i].key == "ispassverifyuser") {
                    var isselected = jsonResult.data[i].valus == "1" ? true : false;
                    $("#checkVerify").prop("checked", isselected);
                }
                if (jsonResult.data[i].key == "mailsort") {
                    var lasrCall = jsonResult.data[i].valus == "1" ? true : false;
                    $("#lastcall").prop("checked", lasrCall);
                    $("#iaitial").prop("checked", !lasrCall);
                }
                if (jsonResult.data[i].key == "msgphoneencrypt") {
                    var isselPhone = jsonResult.data[i].valus == "1" ? true : false;
                    $("#phoneNumEncryption").prop("checked", isselPhone);
                }
                //if (jsonResult.data[i].key == "bisphonefriendtop") {
                //    var topFriend = jsonResult.data[i].valus =="1" ? true : false;
                //    $("#topFriend").prop("checked", topFriend);
                //}
            }
        } else {
            $("#txtFansMax_JJ").val(10);

            $("#txtFansMax_JH").val(5);

            $("#txtFansMax_YB").val(1);
            $("#checkVerify").prop("checked", false);
            $("#iaitial").prop("checked", false);
            $("#lastCall").prop("checked", true);
            $("#phoneNumEncryption").prop("checked", false);
            //$("#topFriend").prop("checked", false);
            //$("#txtFansMax_Cs").val(10);
            //ShowError("myPageAlert", "未查到有效数据，请添加！");
        }
    } else {
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
    }
    $(".loadingcover").hide();
    $(".loading").hide();
}
//提交
function TalkTypeSubmit()
{
    $(".loadingcover").show();
    $(".loading").show();
    if (CheckOut() != true)
    {
        return;
    }
    var item = {};
    var txtFansMax_JJ = $("#txtFansMax_JJ");
  
    var txtFansMax_JH = $("#txtFansMax_JH");
 
    var txtFansMax_YB = $("#txtFansMax_YB");

    //var txtFansMax_Cs = $("#txtFansMax_Cs");
  
  
    item.fans_jj = txtFansMax_JJ.val();
   
    item.fans_jh = txtFansMax_JH.val();
   
    item.fans_yb = txtFansMax_YB.val();
    //0为关闭 1为开启
    var straotoaddfriend = $("#checkVerify").is(":checked") ? "1" : "0";
    item.fans_cs = 10;
    var talktype = {}//对话
    talktype.key = "talktype";
    talktype.val = item;

    var ispassverifyuser = {}//开启好友验证
    ispassverifyuser.key = "ispassverifyuser";
    ispassverifyuser.val = straotoaddfriend;

    //1按最后通话时间排序 2按字母排序
    var addressBookSelsed = $("#lastcall").is(":checked") ? "1" : "2";
    var address = {};//通讯录排序
    address.key = "mailsort";
    address.val = addressBookSelsed;

    //开启电话号码加密  0为关闭 1为开启
    var phoneEncryption = $("#phoneNumEncryption").is(":checked") ? "1" : "0";
    var msgPhone = {};
    msgPhone.key = "msgphoneencrypt";
    msgPhone.val = phoneEncryption;

    ////开启好友置顶同步到手机端
    //var friendsSetTop = $("#topFriend").is(":checked") ? "1" : "0";
    //var friends = {};
    //friends.key = "bisphonefriendtop";
    //friends.val = friendsSetTop;

    var count = [];
    count.push(talktype);
    count.push(ispassverifyuser);
    count.push(address)
    count.push(msgPhone);
    //count.push(friends);

    var strParaJson = $.toJSON({
        para: count
    });
    manageObj.pararesetnew(strParaJson);
}
//回调
function AsyncParaResetNewResult(jsonResult)
{
    if (jsonResult.success) {
        ShowMsg("myPageAlert", "操作成功！");
    } else {
        ShowError("myPageAlert", "操作失败：" + jsonResult.error);
    }

    $(".loadingcover").hide();
    $(".loading").hide();
}

//非空验证/逻辑验证
function CheckOut()
{
    var txtFansMax_JJ = $("#txtFansMax_JJ");
    
    var txtFansMax_JH = $("#txtFansMax_JH");
  
    var txtFansMax_YB = $("#txtFansMax_YB");

    //var txtFansMax_Cs = $("#txtFansMax_Cs");
  
   
    //非空验证
    if ($.trim(txtFansMax_JJ.val()) == "") {
        ShowError("myPageAlert", "极佳粉丝消息数不能为空！");
        txtFansMax_JJ.focus();
        return false;
    }
 
    if ($.trim(txtFansMax_JH.val()) == "") {
        ShowError("myPageAlert", "粉丝较好消息数不能为空！");
        txtFansMax_JH.focus();
        return false;
    }
   
    if ($.trim(txtFansMax_YB.val()) == "") {
        ShowError("myPageAlert", "粉丝一般消息数不能为空！");
        txtFansMax_YB.focus();
        return false;
    }

    //if ($.trim(txtFansMax_Cs.val()) == "") {
    //	ShowError("myPageAlert", "错失对话时间不能为空");
    //	txtFansMax_Cs.focus();
    //	return false;
    //}
    //if ($.trim(txtFansMax_Cs.val()) < 10) {
    //	ShowError("myPageAlert", "错失对话最小为10分钟！");
    //	txtFansMax_Cs.focus();
    //	return false;
    //}
    if (txtFansMax_YB.val() <= 0)
    {
        ShowError("myPageAlert", "粉丝一般消息数必须大于0！");
        return false;
    }
   
    //逻辑验证
    if (Number(txtFansMax_JH.val()) >= Number(txtFansMax_JJ.val())) {
        ShowError("myPageAlert", "较好对话消息数不能大于等于极佳对话消息数！");
        txtFansMax_JH.focus();
        return false;
    }
    if (Number(txtFansMax_YB.val()) >= Number(txtFansMax_JH.val())) {
        ShowError("myPageAlert", "一般对话消息数不能大于等于较好对话消息数！");
        txtCusMax_YB.focus();
        return false;
    }
    //if (txtFansMax_JJ.val().substr(0, 1) == 0 || txtFansMax_JH.val().substr(0, 1) == 0 || txtFansMax_YB.val().substr(0, 1) == 0 || txtFansMax_Cs.val().substr(0,1) == 0) {
    //    ShowError("myPageAlert", "首位不能为0！");

    //    return false;
    //}
    return true;
}

//通讯录选择排序类型单击事件
function ContactListSelection(type) {
    if (type == 1) {
        //按最后通话时间排序
        $("#iaitial").prop("checked", false);
        $("#lastcall").prop("checked", true);
    } else {
        //按首字母排序
        $("#iaitial").prop("checked", true);
        $("#lastcall").prop("checked", false);
    }
}
    