﻿
function setErrorInfo(info, isno, showDiv, waitHideDiv) {
    if (!isno) window.location.href = "#";
    configAlert(info, (showDiv != undefined ? showDiv : "#ErrorInfo,.ErrorInfo"), (waitHideDiv != undefined ? waitHideDiv : "#ConfigInfo,.ConfigInfo"), isno);
}
function configAlert(s, div, hodHideDiv, isno) {
    $(div).html("<div class=\"info\">" + s + "</div>");
    clearTimeout($(div).attr("ShowSetTimeout"));
    if (!isno) window.location.href = "#";
    configShow(div, function() {
        if (hodHideDiv) {
            $(hodHideDiv).attr("hideDiv", div);
        }
        else {
            var hideDiv = $(div).attr("hideDiv");
            $(hodHideDiv).attr("hideDiv", "");
            if (hideDiv) {
                configHide(hideDiv);
            }
            $(div).attr("ShowSetTimeout", setTimeout("configHide('" + div + "')", 5000));
        }
    });
}
//操作隐藏显示区
function displayDetailed(objectID, DetaileID, showMessage, hideMessage) {
    if ($("#" + objectID).val() == showMessage) {
        $("#" + objectID).val(hideMessage);
        $("#" + DetaileID).show();
    } else {
        $("#" + objectID).val(showMessage);
        $("#" + DetaileID).hide();
    }

}
//显示或隐藏层ID
function ShowORHideDIV(showid, isno) {
    if (isno) {
        $("#" + showid).show();
    } else {
        $("#" + showid).hide();
    }
    //$("#" + showid).toggle();
}


//共用操作模块
function operateItem(id, url, alertString, successString, errorString, successFunction, agrs, showID) {
    if (confirm(alertString)) {
        Loading(undefined);
        var sendData = { id: id };
        $.post(url, sendData, function(data) {
            EndLoading(showID);
            if (data == "true") {
                configAlert(successString, "#ConfigInfo,.ConfigInfo");
                if (successFunction) {
                    if (typeof (successFunction) == "function")
                        successFunction.apply(this, agrs ? agrs : []);
                    else {
                        for (var i = 0; i < successFunction.length; i++) {
                            successFunction[i].apply(this, agrs ? agrs[i] : []);
                        }
                    }
                }
            }
            else {
                configAlert(errorString ? errorString : data, "#ErrorInfo,.ErrorInfo");
            }
        });
    }
    else {
        return;
    }
}

//全选或取消全选
function checkBoxSelectAll(id, name) {
    if ($("#" + id).attr("checked") == true) { // 全选        
        $("input[name='" + name + "']").each(function() {
            $(this).attr("checked", true);
        });
    } else { // 取消全选
        $("input[name='" + name + "']").each(function() {
            $(this).attr("checked", false);
        });

    }

}
//图片比例显示
function DrawImage(ImgD, w, h) {
    var image = new Image();
    var iwidth = w; //定义允许图片宽度
    var iheight = h; //定义允许图片高度
    image.src = ImgD.src;
    LoadDrawImage(image, ImgD, iwidth, iheight);
}
function LoadDrawImage(image, ImgD, iwidth, iheight) {
    var iw, ih;
    iw = parseInt(image.width);
    ih = parseInt(image.height);
    if (iw == 0 && ih == 0) {
        setTimeout(function() { LoadDrawImage(image, ImgD, iwidth, iheight); }, 100);
        alert(ImgD.src);
        return false;
    }
    if (iw / ih >= iwidth / iheight) {
        if (iw > iwidth) {
            ImgD.style.width = iwidth + "px";
            ImgD.style.height = ((ih * iwidth) / iw) + "px";
        }
        else {
            ImgD.style.width = iw + "px";
            ImgD.style.height = ih + "px";
        }
        ImgD.alt = iw + "×" + ih;
    }
    else {
        if (ih > iheight) {
            ImgD.style.height = iheight + "px";
            ImgD.style.width = ((iw * iheight) / ih) + "px";
        }
        else {
            ImgD.style.width = iw + "px";
            ImgD.style.height = ih + "px";
        }
        ImgD.alt = iw + "×" + ih;
    }
}

//滑门点击
function liClick(a, isno) {
    $(".tags li").removeClass("selectTag");
    //$(".tags li").attr("name", "");
    if (isno) {
        $("#" + a).addClass("selectTag");
    } else {
        $(a).parent().addClass("selectTag");
    }
    //$(a).parent().attr("name", "selectTag");
}
//复制
function copyToClipboard(objID) {
    var txt = $("#" + objID).val();
    if (window.clipboardData) {
        window.clipboardData.setData("Text", txt);
    }
    else if (window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        } catch (e) {
            alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
        }
        var clip = Components.classes['@mozilla.org/widget/clipboard;1']
                 .createInstance(Components.interfaces.nsIClipboard);
        if (!clip) return;
        var trans = Components.classes['@mozilla.org/widget/transferable;1']
                  .createInstance(Components.interfaces.nsITransferable);
        if (!trans) return;
        trans.addDataFlavor('text/unicode');
        var str = new Object();
        var len = new Object();
        var str = Components.classes["@mozilla.org/supports-string;1"]
                .createInstance(Components.interfaces.nsISupportsString);
        var copytext = txt;
        str.data = copytext;
        trans.setTransferData("text/unicode", str, copytext.length * 2);
        var clipid = Components.interfaces.nsIClipboard;
        if (!clip) return false;
        clip.setData(trans, null, clipid.kGlobalClipboard);
    }
    alert("密钥已复制到剪切板中...");
    return false;

}
//通过TEXT得到对应拼音
function set_pinying(objectID, showID) {
    var pys = $("#" + objectID).val().split('');
    var pinyinma = "";
    for (var i = 0; i < pys.length; i++) {
        pinyinma += pinyin.go(pys[i]).substring(0, 1);
    };
    $("#" + showID).html(pinyinma);
}
//将某区域的HTML导出到EXCEL
function exportExcel(showID) {
    var tDom = document.createElement("DIV");
    tDom.innerHTML = $(showID).html();
    traversalDom(tDom, function(dom) {
        if (dom && dom.style && dom.style.display == "none") {
            dom.parentNode.removeChild(dom);
        }
    });

    var html = tDom.innerHTML;
    while (html.match(/<div[^>]*?>([\s\S]*?)<\/div>/ig)) {
        html = html.replace(/<div[^>]*?>([\s\S]*?)<\/div>/ig, "$1");
    }
    while (html.match(/<a[^>]*?>([\s\S]*?)<\/a>/ig)) {
        html = html.replace(/<a[^>]*?>([\s\S]*?)<\/a>/ig, "$1");
    }
    while (html.match(/<img[^>]*?\/>/ig)) {
        html = html.replace(/<img[^>]*?\/>/ig, "$1");
    }

    var form = document.createElement("form");
    form.style.cssText = "display:none;";
    form.action = "/Tools/ExportExcel";
    form.method = "post";
    form.target = "_blank";
    var htmlStr = document.createElement("input");
    htmlStr.name = "htmlStr";
    htmlStr.value = html;
    form.appendChild(htmlStr);
    document.body.appendChild(form);
    form.submit();
}

//*************************************************************************************************************************************************************
//地图标开始
//标注接口
function setMap(point, zoom, divId) {
    $("#WYDTLon").val(point.getLongitude());
    $("#WYDTLat").val(point.getLatitude());
    $("#WYDTZoom").val(zoom);
    hideObjById('show51MapMain'); //换一个ID是这边要改
    showObjById('DivAlreadyMarker');
    hideObjById('DivNotMarker');
}

//根据城市名标注默认显现地图
function setDefaultMapViewByCityName(cityName, zoom) {
    setDefaultMapViewByCityName(cityName, zoom);
    showDivCenter('show51MapMain', 'LETMarker');
    if (cityName != undefined && zoom != undefined && cityName != "" && zoom != "") {
        ezmarker.setDefaultView(cityName, zoom); //当第一次标记时用这个，根据IP判断显示的图片  
    }
}

//根据点标注默认显现地图有默认城市的
function setDefaultMapViewByPoint(lon, lat, zoom) {
    setDefaultMapViewByPoint(lon, lat, zoom);
    showDivCenter('show51MapMain', 'LETMarker');
    if (lon != undefined && lat != undefined && zoom != undefined && lon != "" && lat != "" && zoom != "" && lon != "0" && lat != "0" && zoom != "0") {
        ezmarker.setDefaultView(new LTPoint(lon, lat), zoom); //当第一次标记时用这个，根据IP判断显示的图片   
    }
}

//标注设默认显示位置图标
function setMapValue(lon, lat, zoom) {
    showDivCenter('show51MapMain', 'LETMarker');
    if (lon != undefined && lat != undefined && zoom != undefined && lon != "" && lat != "" && zoom != "" && lon != "0" && lat != "0" && zoom != "0") {
        ezmarker.setValue(new LTPoint(lon, lat), zoom); //这个方法会使setDefaultView无效
    }
}

function setEZMarker(lon, lat, zoom) {
    setMapValue($(lon).val(), $(lat).val(), $(zoom).val());
}


function showObjByEZMark(lon, lat, zoom, Obj, hideObj) {
    if ($(lon).val() == "" || $(lat).val() == "" || $(zoom).val() == "" || $(lon).val() == "0" || $(lat).val() == "0" || $(zoom).val() == "0") {
        hideObjById(Obj);  //这个方法会使setDefaultView无效
        showObjById(hideObj);
    }
    else {
        showObjById(Obj);
        hideObjById(hideObj);
    }
}



//清除标注 统一调用
function clear51MapDim() {
    $("#WYDTLon").val("");
    $("#WYDTLat").val("");
    $("#WYDTZoom").val("");
    $("#WYDTTitle").val("");
    $("#WYDTContent").val("");
    hideObjById('DivAlreadyMarker');
    showObjById('DivNotMarker');
    //configAlert("清除成功!请保存", "#ConfigInfo,.ConfigInfo");
}

//地图标注结束
//*************************************************************************************************************************************************************

//显示用户中心的应用
var showManageDivID = "manageAjaxShowMain";
function menuLink(url, isOpenWin) {
    
    /*
    $.post(url, "", function(data) {
        EndLoading();
        $("#" + showManageDivID).html(data);
    });
    */
    if (isOpenWin) window.open(url);
    else {
        Loading("载入中...");
        location.href = url;
    }
    $("#DivCreateProperty").html("");
    $("#DivPropertyPublish").show();
}

$(document).ready(function() {
    //配合Loading要固定
    $(window).resize(function() {
        updateLoadingPosition();
    });
    $(document).scroll(function() {
        updateLoadingPosition();
    });
});

//更新Loading的位置
function updateLoadingPosition() {
    $(".fixedRightDown").css({ "z-index": "9000", left: ((winDimensions().winWidth - $(".fixedRightDown").attr("offsetWidth")) / 2 + getScrollTop().left) + "px", top: ((winDimensions().winHeight - $(".fixedRightDown").attr("offsetHeight")) / 2 + getScrollTop().top) + "px" });
    $("#DivWrap").css({ "width": getPageSize().width + "px", "height": getPageSize().height + "px", "position": "absolute", "top": "0", "left": "0", "z-index": "8999" });
    setTimeout(function() { updateLoadingPosition(); }, 500);
}

//Loading
function Loading(showInfo, loadID) {
    loadID = (loadID != undefined ? loadID : "#Loading");
    var l = $(loadID);
    l.html("<div class=\"LoadingImg\"><img src=\"../../Content/images/loading/loading_process.gif\" /></div><div class=\"LoadingFont\">" + (showInfo ? showInfo : "载入中。。。</div>"));
    l.show();
    var load = $("#DivWrap")[0];
    if (!load) {
        load = document.createElement("Div");
        load.id = "DivWrap";
        document.body.appendChild(load);
        $(load).html('<iframe src="javascript:{void(0)}" style="width:100%;height:100%;border:none;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;" frameborder="0"></iframe>');
    }
    $(load).show();
    updateLoadingPosition();
}
//EndLoading
function EndLoading(loadID) {
    loadID = (loadID != undefined ? loadID : "#Loading");
    var l = $(loadID);
    l.hide();
    var load = $("#DivWrap")[0];
    if (!load) {
        load = document.createElement("Div");
        load.id = "DivWrap";
        $(load).css({ "filter": "alpha(opacity=0)", "-moz-opacity": "0", "opacity": "0", "background": "#000", "width": $(window).width(), "height": $(document.body).height(), "position": "absolute", "top": "0", "left": "0", "z-index": "1" });
        document.body.appendChild(load);
    }
    $(load).hide();
}

//隐藏列表
function hideList() {
    $("#List").hide();
}
//显示列表
function showList() {
    $("#List").show();
    $("#List div").show();
}
//隐藏详细资料
function hideDivAjax() {
    $("#DivAjax").hide();
}
//显示详细资料
function showDivAjax() {
    $("#DivAjax").show();
}
//显示搜索框
function showSearchList() {
    $("#ListSearch").show();
}
//隐藏搜索框
function hideSearchList() {
    $("#ListSearch").hide();
}

//*****************************************************************************************
//资源操作
//显示编辑窗口
function showResourcesEdit(id, parentID, name, cnName, dir, sort) {
    $("#DivEditResources").show();
    $("#edit_id").val(id);
    $("#edit_parentID").val(parentID);
    $("#edit_name").val(name);
    $("#edit_cnName").val(cnName);
    $("#edit_dir").val(dir);
    $("#edit_sort").val(sort);
}




//*****************************************************************************************
//用户操作

//修改用户信息
function editUser(reBack) {
    Loading("正在修改用户信息...");
    var url = "/MembershipAdministration/EditUser";
    if (reBack) url = "/User/EditUser";
    var sendData = { id: thisUserId, Email: $("#DetailUserInfo_Email").val()
    };
    if ($("#DetailUserInfo_Password").val()) {
        sendData.Password = $("#DetailUserInfo_Password").val();
        sendData.Password2 = $("#DetailUserInfo_Password2").val();
        if ($("#DetailUserInfo_Password").val()) {
            sendData.OldPassword = $("#DetailUserInfo_OldPassword").val();
        }
    }
    if ($("#DetailUserInfo_IsApproved").attr("checked") != undefined) {
        sendData.IsApproved = $("#DetailUserInfo_IsApproved").attr("checked") ? "true" : "false";
    }
    if ($("#DetailUserInfo_IsLockedOut").attr("checked") != undefined) {
        sendData.IsLockedOut = $("#DetailUserInfo_IsLockedOut").attr("checked") ? "false" : "true";
    }
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("<p>用户修改成功!</p>", "#ConfigInfo");
            if (!reBack) {

            }
            else eval(reBack);
        }
        else {
            setErrorInfo(data);
        }
    });
}

//修改用户详细信息
function editUserInfo(reBack, uid, manage) {
    var url = "/MembershipAdministration/EditUserInfo";
    if (reBack) url = "/User/EditUserInfo";
    if (manage) url = "/MembershipAdministration/EditUserInfo";
    if (uid) thisUserId = uid; ;
    var sendData = { id: thisUserId
                    , Province: $("#EditUserInfo_ProvinceId").val()
                    , City: $("#EditUserInfo_CityId").val()
                    , Town: $("#EditUserInfo_TownId").val()
                    , UserNo: $("#EditUserInfo_UserNo").val()
                    , NickName: $("#EditUserInfo_NickName").val()
                    , TrueName: $("#EditUserInfo_TrueName").val()
                    , Sex: ($("#EditUserInfo_Sex").attr("checked") ? "1" : "2")
                    , BirthDay: $("#EditUserInfo_BirthDay").val()
                    , EnablePhoto: $("#EditUserInfo_EnablePhoto").attr("checked")
                    , PhotoLocation: $("#EditUserInfo_PhotoLocation").val()
                    , EnableSign: $("#EditUserInfo_EnableSign").attr("checked")
                    , Signature: $("#EditUserInfo_Signature").val()
                    , Blog: $("#EditUserInfo_Blog").val()
                    , Interest: $("#EditUserInfo_Interest").val()
                    , QQ: $("#EditUserInfo_QQ").val()
                    , TelPhone: $("#EditUserInfo_TelPhone").val()
                    , MobilePhone: $("#EditUserInfo_MobilePhone").val()
                    , Fax: $("#EditUserInfo_Fax").val()
                    , IdCard: $("#EditUserInfo_IdCard").val()
                    , Address: $("#EditUserInfo_Address").val()
                    , PostCode: $("#EditUserInfo_PostCode").val()
                    , Account: $("#EditUserInfo_Account").val()
                    , PersonalProfile: $("#PersonalProfile").val()
                    , Honor: $("#Honor").val()
                    , OnlineStoreTitle: $("#OnlineStoreTitle").val()
    };
    Loading("修改用户详细信息...");
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("<p>用户修改成功!</p>", "#ConfigInfo");
            try {
                if (reBack != undefined) eval(reBack);
            } catch (e) { alert(e.message) }
        }
        else {
            setErrorInfo(data);
        }
    });
}

//创建用户
function createUser() {

    if ($("#CreateUser_UserName").val() == "") {
        setErrorInfo("请输入用户名", false, "#ErrorInfo", "#ConfigInfo");
    }
    else if ($("#CreateUser_Password").val() == "") {
        setErrorInfo("请输入密码", false, "#ErrorInfo", "#ConfigInfo");
    }
    else if ($("#CreateUser_Password2").val() == "") {
        setErrorInfo("请输入密码确认", false, "#ErrorInfo", "#ConfigInfo");
    }
    else if ($("#CreateUser_TrueName").val() == "") {
        setErrorInfo("请输入真实姓名", false, "#ErrorInfo", "#ConfigInfo");
    }
    else if ($("#CreateUser_Email").val() == "") {
        setErrorInfo("请输入邮箱地址", false, "#ErrorInfo", "#ConfigInfo");
    }
    //    else if ($("#CreateUser_PwdQuestion").val() == "") {
    //        setErrorInfo("请输入密码提示问题", false, "#ErrorInfo", "#ConfigInfo");
    //    }
    //    else if ($("#CreateUser_IsApproved").val() == "") {
    //        setErrorInfo("请输入密码提示问题的答案", false, "#ErrorInfo", "#ConfigInfo");
    //    }    
    else {
        //$("#CreateUser_Button").attr("disabled", "true");
        $("#CreateUser_Button").val("创建中...");
        var sendData = { UserName: $("#CreateUser_UserName").val()
                    , Password: $("#CreateUser_Password").val()
                    , Password2: $("#CreateUser_Password2").val()
                    , Email: $("#CreateUser_Email").val()
            //                    , PwdQuestion: $("#CreateUser_PwdQuestion").val()
            //                    , PwdAnswer: $("#CreateUser_PwdAnswer").val()
            //                    , IsApproved: $("#CreateUser_IsApproved").attr("checked")


            //                    , formCreateUser_DeptId: $("#formCreateUser_DeptId").val()
            //                    , formCreateUser_PositionId: $("#formCreateUser_PositionId").val()

            //                    , Country: $("#CreateUser_Country").val()
            //                    , Province: $("#PersonAreaSelect1").val()
            //                    , City: $("#PersonAreaSelect2").val()
            //                    , UserNo: $("#CreateUser_UserNo").val()
            //                    , NickName: $("#CreateUser_NickName").val()
                    , TrueName: $("#CreateUser_TrueName").val()
            //                    , Sex: ($("#CreateUser_Sex").attr("checked") ? "1" : "2")
            //                    , BirthDay: $("#CreateUser_BirthDay").val()
            //                    , EnablePhoto: $("#CreateUser_EnablePhoto").attr("checked")
            //                    , PhotoLocation: $("#CreateUser_PhotoLocation").val()
            //                    , EnableSign: $("#CreateUser_EnableSign").attr("checked")
            //                    , Signature: $("#CreateUser_Signature").val()
            //                    , Blog: $("#CreateUser_Blog").val()
            //                    , Interest: $("#CreateUser_Interest").val()
            //                    , QQ: $("#CreateUser_QQ").val()
            //                    , TelPhone: $("#CreateUser_TelPhone").val()
            //                    , MobilePhone: $("#CreateUser_MobilePhone").val()
            //                    , Fax: $("#CreateUser_Fax").val()
            //                    , IdCard: $("#CreateUser_IdCard").val()
            //                    , Address: $("#CreateUser_Address").val()
            //                    , PostCode: $("#CreateUser_PostCode").val()
            //                    , Account: $("#CreateUser_Account").val()
        };
        Loading("创建中...");
        $.post("/MembershipAdministration/CreateUser", sendData, function(data) {
            EndLoading();
            if (data.toString().substr(0, 4) == "true") {
                //$("#CreateUser_UserId").val(data.toString().substr(5, data.toString().length - 5));
                configAlert("<p>用户创建成功!请去您的邮箱激活您的账号！</p>", "#ConfigInfo");
                setTimeout("window.location.href = '/Account/Logon';", 1000);

            }
            else {
                setErrorInfo(data, true, "#ErrorInfo", "#ConfigInfo");
                //$("#CreateUser_Button").attr("disabled", "");
                $("#CreateUser_Button").val("创建");

            }
        });
    }
}
//创建设为初始化
function userCreateClear() {
    $("#CreateUserDiv :text").val("");
}
//取消创建
function cancleCreateUser() {
    userCreateClear();
    //$("#CreateUserDiv").hide();
    displayDetailed('displayDetailedUserButton', 'displayDetailedUser', '显示详细信息', '隐藏详细信息');
    $("#ErrorInfo").html("");
}

//列表
function userList(url) {
    Loading();
    $("#user_pageIndex").val(thisUsersPageIndex);
    $("#userListForm").submit();
    
//    var Name = $("#Name").val(); //日期类别  
//    var sendData = {
//        name: Name
//    };
//    $.post(url, sendData, function(data) {
//        EndLoading();
//        $("#" + showManageDivID).html(data);
//    }
//    );
}


//用户操作结束
//************************************************************************************************************************************


//************************************************************************************************************************************
//房源操作
function CreateProperty() {
    alert($("#SpanCreatePropertyDecoration input[name=CreatePropertyDecoration]:checked").val());

}

//房源操作结束
//************************************************************************************************************************************
//标签开始

function ListTag(pageIndex, pageSize) {
    var url = "/Tag/List", sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize,
        referenceId: $("#Ref").val()
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#List").html(data);
    });
}

//显示添加标签的HTML
function showCreateTag() {
    $("#btnShowCreateTag").hide();
    ShowORHideDIV('DivCreateTag', true);
}

//function recommendTag(tagId) {
//    var url = "/Tag/List", sendData = {
//        pageIndex: pageIndex,
//        pageSize: pageSize
//    }
//    Loading();
//    $.post(url, sendData, function(data) {
//        EndLoading();
//        $("#List").html(data);
//    });
//}
//首页推荐标签列表
function ListRecommendTag(pageIndex, pageSize) {
    var url = "/RecommendTag/List", sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize,
        referenceId: $("#Ref").val()
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#recommendTagList").html(data);
    });
}

//推荐首页标签
function RecommendTag(tagId) {
    var url = "/RecommendTag/Create", sendData = {
        tagId: tagId
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("推荐成功", "#ConfigInfo");
            ListRecommendTag(0, 10);
        } else {
            setErrorInfo(data);
        }
    });
}

function updateRecommendTagSort(id) {
    var url = "/RecommendTag/UpdateSort", sendData = {
        id: id,
        sort: $("#sort" + id).val()
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("修改成功", "#ConfigInfo");
            ListRecommendTag(0, 10);
        } else {
            setErrorInfo(data);
        }
    });
}
//标签结束
//************************************************************************************************************************************
//楼盘字典操作

//楼盘字典集合
function ListEstate(pageIndex, pageSize) {
    var url = "/Estate/List", sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#List").html(data);
    });
}

//显示添加楼盘的HTML
function showCreateEstate() {
    $("#btnShowCreateEstate").hide();
    ShowORHideDIV('DivCreateEstate', true);
    if ($("#CreateEstatePanel").length < 1) {
        Loading();
        $.get("/Estate/Create", {}, function(data) {
            EndLoading();
            $("#DivCreateEstate").html(data);
        });
    }
}


//楼盘字典集合
function detailsEstate(id) {
    var url = "/Estate/Details", sendData = {
        id: id
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#EstateShow").html(data);
        showNiWindow('EstateShow', '', '查看详细');
        onLoad();
        showLoadedBackFunc();
    });
}
//修改楼盘字典
function editEstate(id, backEval) {
    if (/[<>]+/.test($("#EditEstateName").val())) {
        setErrorInfo("字典名称中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditAddress2").val())) {
        setErrorInfo("详细地址中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditMgtCompany").val())) {
        setErrorInfo("物业公司中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditMgtTel").val())) {
        setErrorInfo("物业电话中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditMgtPrice").val())) {
        setErrorInfo("物业管理费中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditPrice").val())) {
        setErrorInfo("售均价中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditRemark").val())) {
        setErrorInfo("备注中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditEnvironment").val())) {
        setErrorInfo("周边环境中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditTransportation").val())) {
        setErrorInfo("交通设施中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditEducation").val())) {
        setErrorInfo("学校教育中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditBusiness").val())) {
        setErrorInfo("商业贸易中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditEntertainment").val())) {
        setErrorInfo("休闲娱乐中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else {
        //set_pinying('EditEstateName', 'EditSpell');
        var EditSchoolNames = [];
        $.each($('input[name=SchoolNames]'), function(i, n) { EditSchoolNames.push(n.value); });
        var url = "/Estate/Edit", sendData = {
            id: id,
            EstateName: $("#EditEstateName").val(),
            Spell: $("#EditSpell").html(),
            formPropertyUsage: $("#EditPropertyUsage").val(),
            formPropertyType: $("#EditPropertyType").val(),

            Address2: $("#EditAddress2").val(),
            formCompleteYearMonth: $("#EditCompleteYearMonth").val(),
            MgtCompany: $("#EditMgtCompany").val(),
            MgtTel: $("#EditMgtTel").val(),
            formMgtPrice: $("#EditMgtPrice").val(),
            formPrice: $("#EditPrice").val(),
            ProvinceId: $("#EditProvinceId").val(),
            CityId: $("#EditCityId").val(),
            TownId: $("#EditTownId").val(),
            AreaId: $("#EditAreaId").val(),
            SchoolNames: EditSchoolNames,
            Remark: $("#EditRemark").val(),
            Environment: $("#EditEnvironment").val(),
            Transportation: $("#EditTransportation").val(),
            Education: $("#EditEducation").val(),
            Business: $("#EditBusiness").val(),
            Entertainment: $("#EditEntertainment").val(),
            formWYDTLon: $("#WYDTLon").val(),
            formWYDTLat: $("#WYDTLat").val(),
            formWYDTZoom: $("#WYDTZoom").val(),
            WYDTTitle: $("#WYDTTitle").val(),
            WYDTContent: $("#WYDTContent").val()
        };
        Loading("修改中...");
        $.post(url, sendData, function(data) {
            EndLoading();
            try {
                if (backEval != undefined) eval(backEval);
            } catch (e) { alert(e.message) }
            if (data == "true") {
                configAlert("修改成功", "#ConfigInfo");
                closeNiWindow('EstateShow', '');
                ListEstate(0, 10);
            } else {
                setErrorInfo(data);
            }
        });
    }
}
//楼盘字典操作结束
//************************************************************************************************************************************


//************************************************************************************************************************************
//区域操作

//区域集合
function detailsArea(id) {
    var url = "/Area/Details", sendData = {
        id: id
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#AreaShow").html(data);
        showNiWindow('AreaShow', '', '查看详细');
        onLoad();
    });
}

//区域集合
function ListArea(pageIndex, pageSize) {
    var url = "/Area/List", sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#List").html(data);
    });
}

//添加区域
function createArea() {
    if (/[<>]+/.test($("#CreateAreaName").val())) {
        setErrorInfo("区域名中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else {
        var url = "/Area/Create", sendData = {
            formTownId: $("#AreaTownId").val(),
            AreaName: $("#CreateAreaName").val(),
            Sort: $("#CreateSort").val(),
            WYDTCode: $("#CreateWYDTCode").val(),
            formWYDTLon: $("#CreateWYDTLon").val(),
            formWYDTLat: $("#CreateWYDTLat").val(),
            formWYDTZoom: $("#CreateWYDTZoom").val(),
            WYDTTitle: $("#CreateWYDTTitle").val(),
            WYDTContent: $("#CreateWYDTContent").val(),
            WYDTImage: $("#CreateWYDTImage").val(),
            formWYDTImgWide: $("#CreateWYDTImgWide").val(),
            formWYDTImgHigh: $("#CreateWYDTImgHigh").val(),
            formWYDTImgTopLeftHorizontal: $("#CreateWYDTImgTopLeftHorizontal").val(),
            formWYDTImgTopLeftVertical: $("#CreateWYDTImgTopLeftVertical").val(),
            ImgIds: $("#CreateImgIds").val()
        };
        Loading("创建中...");
        $.post(url, sendData, function(data) {
            EndLoading();
            if (data == "true") {
                configAlert("创建成功", "#ConfigInfo");
                ListArea(0, 10);
            } else {
                setErrorInfo(data);
            }
        });
    }
}
//修改区域
function editArea(id, backEval) {
    if (/[<>]+/.test($("#EditAreaName").val())) {
        setErrorInfo("区域名中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else {
        var url = "/Area/Edit", sendData = {
            id: id,
            formTownId: $("#EditAreaTownId").val(),
            AreaName: $("#EditAreaName").val(),
            Sort: $("#EditSort").val(),
            WYDTCode: $("#EditWYDTCode").val(),
            formWYDTLon: $("#WYDTLon").val(),
            formWYDTLat: $("#WYDTLat").val(),
            formWYDTZoom: $("#WYDTZoom").val(),
            WYDTTitle: $("#WYDTTitle").val(),
            WYDTContent: $("#WYDTContent").val(),
            WYDTImage: $("#EditWYDTImage").val(),
            formWYDTImgWide: $("#EditWYDTImgWide").val(),
            formWYDTImgHigh: $("#EditWYDTImgHigh").val(),
            formWYDTImgTopLeftHorizontal: $("#EditWYDTImgTopLeftHorizontal").val(),
            formWYDTImgTopLeftVertical: $("#EditWYDTImgTopLeftVertical").val(),
            ImgIds: $("#EditImgIds").val()
        };
        Loading("修改中...");
        $.post(url, sendData, function(data) {
            EndLoading();
            try {
                if (backEval != undefined) eval(backEval);
            } catch (e) { alert(e.message) }
            if (data == "true") {
                configAlert("修改成功", "#ConfigInfo");
                closeNiWindow('AreaShow', '');
                ListArea(0, 10);
            } else {
                setErrorInfo(data);
            }
        });
    }
}
//************************************************************************************************************************************
//小学操作

//小学集合
function detailsSchool(id) {
    var url = "/School/Details", sendData = {
        id: id
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#SchoolShow").html(data);
        showNiWindow('SchoolShow', '', '查看详细');
        onLoad();
    });
}

//楼盘小学集合
function ListSchool(pageIndex, pageSize) {
    var url = "/School/List", sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#List").html(data);
    });
}

//添加小学
function createSchool() {
    if (/[<>]+/.test($("#CreateSchoolName").val())) {
        setErrorInfo("学校名字中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#CreateSchoolDescribe").val())) {
        setErrorInfo(" 学校描述中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else {
        var url = "/School/Create", sendData = {
            SchoolDescribe: $("#CreateSchoolDescribe").val(),
            SchoolName: $("#CreateSchoolName").val(),
            AreaId: $("#CreateSchoolAreaId").val()
        };
        Loading("创建中...");
        $.post(url, sendData, function(data) {
            EndLoading();
            if (data == "true") {
                configAlert("创建成功", "#ConfigInfo");
                ListSchool(0, 10);
            } else {
                setErrorInfo(data);
            }
        });
    }
}
//修改小学
function editSchool(id, backEval) {
    if (/[<>]+/.test($("#EditSchoolName").val())) {
        setErrorInfo("学校名字中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else if (/[<>]+/.test($("#EditSchoolDescribe").val())) {
        setErrorInfo(" 学校描述中不能包含'<'或'>'字符", false, "#ErrorInfo", "#ConfigInfo");
    } else {
        var url = "/School/Edit", sendData = {
            id: id,
            SchoolDescribe: $("#EditSchoolDescribe").val(),
            SchoolName: $("#EditSchoolName").val(),
            AreaId: $("#EditSchoolAreaId").val(),
            formWYDTLon: $("#WYDTLon").val(),
            formWYDTLat: $("#WYDTLat").val(),
            formWYDTZoom: $("#WYDTZoom").val(),
            WYDTTitle: $("#WYDTTitle").val(),
            WYDTContent: $("#WYDTContent").val()
        };
        Loading("修改中...");
        $.post(url, sendData, function(data) {
            EndLoading();
            try {
                if (backEval != undefined) eval(backEval);
            } catch (e) { alert(e.message) }
            if (data == "true") {
                configAlert("修改成功", "#ConfigInfo");
                closeNiWindow('SchoolShow', '');
                ListSchool(0, 10);
            } else {
                setErrorInfo(data);
            }
        });
    }
}
//小学操作结束
//************************************************************************************************************************************

//区域操作结束
//************************************************************************************************************************************


//************************************************************************************************************************************
//根据类别组获取类别下拉菜单,必须包含文件:"/Scripts/TFWSNS/Reference.js"
/*
@id:类别组ID
@showObjID:显示的ID(不带#号)
@sID:下拉菜单的ID
@sName:下拉菜单的Name
@value:下拉菜单默认选中值
@attr:下拉菜单的其他属性,如"onchage='alert(1)'"
@appValue:添加首项的Value:如有值,appText也需要传入
@appText:添加首项的Text:如有值,appValue也需要传入
例子:
<span id="spanTest1"></span>
<span id="spanTest2"></span>
<script>
getReferenceById('e2df4e1e-848c-4fe0-bacc-66766a108acf', 'spanTest1', 'test1', 'test11','','onchange="alert(1)"','','请选择');//加首项

getReferenceById('e2df4e1e-848c-4fe0-bacc-66766a108acf', 'spanTest2', 'test2', 'test22', '', 'onchange="alert(1)"'); //不加首项
</script>
*/
function getReferenceById(id, showObjID, sID, sName, value, attr, appValue, appText) {
    var list;
    try {
        eval("list=refGroupList;");
    } catch (e) { alert("未找到数据!" + e.message); return false; }
    var showObj = document.getElementById(showObjID);
    if (showObj) {
        var str = new Array(), proV;
        proV = id.toLocaleLowerCase();
        str.push("<select id=\"" + sID + "\" name=\"" + sName + "\" " + attr + ">");
        if (appValue != undefined && appValue != null) {
            str.push("<option value=\"" + appValue + "\">" + appText + "</option>");
        }
        if (list[proV] != null && list[proV] != undefined) {
            for (var i = 0; i < list[proV].length; i += 2) {
                str.push("<option" + (list[proV][i] === value ? " selected=\"true\"" : "") + " value=\"" + list[proV][i] + "\">" + list[proV][i + 1] + "</option>");
            }
        }
        str.push("</select>");
        showObj.innerHTML = str.join("");
    }
}
/*
参数参考上面方法
例子
<span id="span1"></span>
<span id="span2"></span>
<script>
getCheckBoxReferenceById('e2df4e1e-848c-4fe0-bacc-66766a108acf', 'span1', 'test33', '', '', '请选择'); //加首项
getCheckBoxReferenceById('e2df4e1e-848c-4fe0-bacc-66766a108acf', 'span2', 'test44', ''); //不加首项
</script>
*/
function geRadioReferenceById(id, showObjID, sName, value, appValue, appText) {
    var list;
    try {
        eval("list=refGroupList;");
    } catch (e) { alert("未找到数据!"); return false; }

    var str = new Array(), proV;
    proV = id.toLocaleLowerCase();
    if (appValue != undefined && appValue != null) {
        str.push("<label><input type=\"radio\" name=\"" + sName + "\" value=\"" + appValue + "\"" + (appValue === value ? " checked=\"true\"" : "") + ">" + appText + "</label>");
    }
    if (list[proV] != null && list[proV] != undefined) {
        for (var i = 0; i < list[proV].length; i += 2) {
            str.push("<label><input type=\"radio\" name=\"" + sName + "\" value=\"" + list[proV][i] + "\"" + (list[proV][i] === value ? " checked=\"true\"" : "") + ">" + list[proV][i + 1] + "</label>");
        }
    }
    document.getElementById(showObjID).innerHTML = str.join("");
}
function getCheckBoxReferenceById(id, showObjID, sName, value, appValue, appText) {
    var list;
    try {
        eval("list=refGroupList;");
    } catch (e) { alert("未找到数据!"); return false; }

    var str = new Array(), proV, values = new Array(), isselect = false;
    values = value.split(',');
    proV = id.toLocaleLowerCase();
    if (appText != undefined && appText != null) {
        str.push("<label><input type=\"checkbox\" name=\"" + sName + "\" value=\"" + appText + "\"" + (appText === value ? " checked=\"true\"" : "") + ">" + appText + "</label>");
    }
    if (list[proV] != null && list[proV] != undefined) {
        for (var i = 0; i < list[proV].length; i += 2) {
            for (var j = 0; j < values.length; j++) {
                if (list[proV][i + 1] === values[j]) {
                    isselect = true;
                }
            }
            str.push("<label><input type=\"checkbox\" name=\"" + sName + "\" value=\"" + list[proV][i + 1] + "\"" + (isselect ? " checked=\"true\"" : "") + ">" + list[proV][i + 1] + "</label>");
            isselect = false;
        }
    }
    document.getElementById(showObjID).innerHTML = str.join("");
}
//获取类别下拉菜单结束
//************************************************************************************************************************************
//网点展示开始
//创建网点FormAJAX化
function deptShowCreateScript() {
    $('#FormCreateDeptShow').ajaxForm({
        beforeSubmit: function(formData, jqForm, options) {
            Loading("创建中...", "DivCreateDeptShow");
        },
        success: function(data, statusText) {
            EndLoading("DivCreateDeptShow");
            if (statusText == "success") {
                if (data == "true") {
                    configAlert("<p>创建成功!</p>", ".ConfigInfo");
                    deptShowList();
                }
                else {
                    setErrorInfo(data, true, ".ErrorInfo", ".ConfigInfo");
                }
            }
            else { alert('请求失败!'); }
        }
    });
}

//编辑网点FormAJAX化
function deptShowEditScript() {
    $('#FormEditDeptShow').ajaxForm({
        beforeSubmit: function(formData, jqForm, options) {
            Loading("更新中...", "DIVEditDeptShow");
        },
        success: function(data, statusText) {
            EndLoading("DIVEditDeptShow");
            if (statusText == "success") {
                if (data == "true") {
                    configAlert("<p>更新成功!</p>", "#ConfigInfo");
                    deptShowList();
                }
                else {
                    setErrorInfo(data, true, "#ErrorInfo", "#ConfigInfo");
                }
            }
            else { alert('请求失败!'); }
        }
    });
} 

//显示列表
function deptShowList() {
    //hideDivAjax();
    Loading();
    var url = "/DeptShow/List"; ///List
    var sendData = { id: $("#DeptShowDeptId").val() };
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#DeptDeptShowList").html(data);
    }
    );
}

//查看详细
function detailsDeptShow(id) {
    Loading();
    var url = "/DeptShow/Details"; ///List
    var sendData = { id: id };
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#DeptShowDetail").html(data);
    }
    );
}


//网点展示结束
//****************************************************************************************************************************************
//网点
//管理
function viewDept() {
    hideDivAjax();
    Loading();
    var url = "/Depts/ViewDept"; ///List
    var id = $("#selectDept").val();
    var sendData = { id: id };
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#DivList").html(data);
    }
    );
}

//结束管理

//列表
function deptsList() {
    hideDivAjax();
    Loading();
    var url = "/Depts/Index"; ///List
    var sendData = {};
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#" + showManageDivID).html(data);
    }
    );
}

//设置父网点网点下拉列表
function deptssetParentDept(id) {
    $("#ParentId").val(id);
}

//显示单项记录
function deptsDetail(id) {
    Loading();
    var url = "/Depts/Details";
    var sendData = { id: id };
    $.post(url, sendData, function(data) {
        $("#DivAjax").html(data);
        showNiWindow('DivAjax', '', '查看网点');        
        onLoad();
        //$("#DivAjax").show();
        EndLoading();
    }
    );
}
//同意用户加入网点
function applyUserJoinDept(id) {
    Loading();
    var url = "/Depts/applyUserJoinDept";
    var sendData = { requestId: id };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("操作成功", "#ConfigInfo");
            requestList();
        } else {
            setErrorInfo(data);
        }
    }
    );
}
//拒绝用户加入网点
function refuseUserJoinDept(id) {
    Loading();
    var url = "/Depts/refuseUserJoinDept";
    var sendData = { requestId: id };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("操作成功", "#ConfigInfo");
            requestList();
        } else {
            setErrorInfo(data);
        }
    }
    );
}
//同意用户加盟网点
function applyDeptJoinDept(id) {
    Loading();
    var url = "/Depts/applyDeptJoinDept";
    var sendData = { requestId: id };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("操作成功", "#ConfigInfo");
            requestList();
        } else {
            setErrorInfo(data);
        }
    }
    );
}
//拒绝用户加盟网点
function refuseDeptJoinDept(id) {
    Loading();
    var url = "/Depts/refuseDeptJoinDept";
    var sendData = { requestId: id };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("操作成功", "#ConfigInfo");
            requestList();
        } else {
            setErrorInfo(data);
        }
    }
    );
}
//同意绑定房友账号
function applyBindingID(id, fyid) {
    Loading();
    var url = "/SendPropertyService/applyBindingID";
    var sendData = { requestId: id, FYID: fyid };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("操作成功", "#ConfigInfo");
            requestList();
        } else {
            setErrorInfo(data);
        }
    }
    );
}
//拒绝绑定房友账号
function refuseBindingID(id) {
    Loading();
    var url = "/SendPropertyService/refuseBindingID";
    var sendData = { requestId: id };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("操作成功", "#ConfigInfo");
            requestList();
        } else {
            setErrorInfo(data);
        }
    }
    );
}

/**
//修改
function deptsEdit(id) {
var DeptName = $("#DeptName").val();
var ParentId = $("#ParentId").val();
var Province = $("#AreaProvince").val();
var City = $("#AreaCITY").val();
var Description = $("#Description").val();
var Sort = $("#Sort").val();
var CommDefaultPersent = $("#CommDefaultPersent").val();
var IsCommCalculate = $("#IsCommCalculate").attr("checked");
var TtargetComm = $("#TtargetComm").val();
var formDataBaseCon = $("#formDataBaseCon").val();
var url = "/Depts/Edit";
Loading("编辑中...");
var sendData = { id: id, DeptName: DeptName, ParentId: ParentId, Description: Description, Sort: Sort, Province: Province, City: City
, CommDefaultPersent: CommDefaultPersent, IsCommCalculate: IsCommCalculate, TtargetComm: TtargetComm, formDataBaseCon: formDataBaseCon
}; //
$.post(url, sendData, function(data) {
EndLoading();
if (data == "true") {
createSetNull();
configAlert("修改成功", "#ConfigInfo");
deptsList();
}
else {
setErrorInfo(data);
}
});
}**/

//人员设置
function deptsPersonSet(id, pageIndex, pageSize) {
    //createSetNull();
    Loading();
    //    if (id == null) {
    //        id = $("#AParentId").val();
    //    }
    //    else {
    //        $("#AParentId").val(id);
    //    }
    var url = "/Depts/PersonSet";
    var sendData = { id: id, pageIndex: pageIndex, pageSize: pageSize };
    $.post(url, sendData, function(data) {
        $("#DivAjax").html(data);
        showNiWindow('DivAjax', '', '查看人员');
        //$("#DivAjax").show();
        EndLoading();
    });
}

//转交网点所有人
function DeptChangePersonIndex(id) {
    //createSetNull();
    Loading();
    //    if (id == null) {
    //        id = $("#AParentId").val();
    //    }
    //    else {
    //        $("#AParentId").val(id);
    //    }
    var url = "/Depts/DeptChangePersonIndex";
    var sendData = { id: id };
    $.post(url, sendData, function(data) {
        $("#DivAjax").html(data);
        showNiWindow('DivAjax', '', '转交网点所有人');
        //$("#DivAjax").show();
        EndLoading();
    });
}

//转交网点所有人
function DeptChangePerson(id) {
    if (confirm('确定要转交给他吗？')) {
        Loading();
        var url = "/Depts/DeptChangePerson";
        var uId = $("#selectDeptChangePersonIndex").val();
        var sendData = { id: id, uId: uId };
        $.post(url, sendData, function(data) {
            EndLoading();
            if (data == "true") {
                //createSetNull();
                configAlert("转交成功", "#ConfigInfo");
                closeNiWindow('DivAjax', ''); //获取网点下的人员列表
            }
            else {
                setErrorInfo(data);
            }
        });
    }
}
//var ExceptUser = new Array();
//function selectExceptUserSet(value, text) {
//    var i = ExceptUser.length;
//    ExceptUser[i] = new Array();
//    ExceptUser[i]["text"] = text;
//    ExceptUser[i]["value"] = value;
//}
////筛选人员
//function searchExceptUser() {
//    var name = $("#SeachUserName").val(); 
//    for (var i = 0; i < ExceptUser.length; i++) {
//        if (ExceptUser[i]["text"].contain(name)) {
//            alert(1111);
//        }
//    }
//}
//添加人员
function addPersonToDept() {
    Loading();
    var formPositionId = $("#PositionId").val();
    var formUserId = $("#ExceptUser").val();
    var deptId = $("#AParentId").val();
    var url = "/Depts/addPersonToDept";
    var sendData = { id: deptId, formPositionId: formPositionId, formUserId: formUserId };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            createSetNull();
            configAlert("添加成功", "#ConfigInfo");
            deptsPersonSet(deptId); //获取网点下的人员列表
        }
        else {
            setErrorInfo(data);
        }
    });
}

//移除人员
function removeUserFromDept(udpIds, deptId) {
    if (confirm('确定要移除他并且把他所有的房源转给网点所有人吗？')) {
        Loading();
        var url = "/Depts/delUserFromDept";
        var sendData = { udpIds: udpIds };
        $.post(url, sendData, function(data) {
            EndLoading();
            if (data == "true") {
                //createSetNull();
                configAlert("移除成功", "#ConfigInfo");
                deptsPersonSet(deptId); //获取网点下的人员列表
            }
            else {
                setErrorInfo(data);
            }
        });
    }
}

//移除人员
function removeUserSelfFromDept(udpIds, deptId) {
    if (confirm('确定要退出这个网点并且把您的房源转给本网点的所有人吗？')) {
        Loading();
        var url = "/Depts/delUserSelfFromDept";
        var sendData = { udpIds: udpIds };
        $.post(url, sendData, function(data) {
            EndLoading();
            if (data == "true") {
                //createSetNull();
                configAlert("移除成功", "#ConfigInfo");
                deptsPersonSet(deptId); //获取网点下的人员列表
            }
            else {
                setErrorInfo(data);
            }
        });
    }
}

//查看用户详细
function displayUser(userID, reback) {
    Loading("载入中...");
    thisUserId = userID;
    $("#userDisplay").html("<img src=\"../../Content/images/loading/loading_process.gif\" />正在打开用户信息...");
    showNiWindow("userDisplay", "", "用户详细");
    $.post("/MembershipAdministration/Details/" + userID, {}, function(data) {
        EndLoading();
        $("#userDisplay").html(data);
        showNiWindow("userDisplay", "", "用户详细");
        if (reback) eval(reback);
    });
}
function createKey(type) {
    Loading();
    var url = "/User/CreateKey";
    var sendData = {};
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#keyButton").val(type + "|" + data);
    });
}
//网点结束
//****************************************************************************************************************************************
//通知
//获取新的通知数量
function getNoticeCount() {
    //Loading();
    $("#SpanNoticeCount").html("<img src=\"../../Content/images/loading/loadingRed.gif\" />");
    var url = "/Notice/Count";
    var sendData = {};
    $.post(url, sendData, function(data) {
        //EndLoading();
        if (data != "0") $("#SpanNoticeCount").html('(' + data + ')');
        else $("#SpanNoticeCount").html('');
    }
    );
}
//更新用户新通知列表为旧的
function updateNoticeNewOld() {
    Loading();
    var url = "/Notice/updateNoticeToOld";
    var sendData = {};
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            $("#SpanNoticeCount").html('');
        }
    }
    );
}
//滑门通知点击
function clickNoticeTab() {
    if ($("#DivNoticeList").html() == undefined || $("#DivNoticeList").html() == '') {
        noticeList();
    }
}

//通知列表
function noticeList(pageIndex, pageSize, reback) {
    Loading();
    var url = "/Notice/List";
    var sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize
    };
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#DivNoticeList").html(data);
        if (reback) eval(reback);
    }
    );
}
//处理通知
function operateNotice() {
    showObjById('DivRequestList');
    hideObjById('DivNoticeList');
    //liClick('#requestA');
    $('#requestA').click();
}
//通知结束
//****************************************************************************************************************************************
//请求开始

//滑门请求点击
function clickRequestTab() {
    if ($("#DivRequestList").html() == undefined || $("#DivRequestList").html() == '') {
        requestList();
    }
}

//请求列表
function requestList() {
    Loading();
    var url = "/Request/List";
    var sendData = {};
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#DivRequestList").html(data);
        //if (reback) eval(reback);
    });
}
//请求结束
//****************************************************************************************************************************************
//房源操作

//生成房源//be2125b0-6ab9-457c-87fb-4f0297fda521骊特中国
function generateProperty(id, type) {
    var url = "/property/test", sendData = {
        id: id,
        type: type
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("生成成功", "#ConfigInfo");
        } else {
            setErrorInfo(data);
        }
    });
}


var uploadDivCount = 1, uploadImgMaxCount = 1;
var uploadDivCountNum = 0;
function initUploadDiv(i) {
    for (var j = uploadImgMaxCount - i + 2; j <= uploadImgMaxCount; j++) {
        $("#appUploadImgDIV").append('<div id="appUploadImgDIV_' + j + '"><input type="file" name="picture_' + j + '" id="picture' + j + '" /><a href="javascript:{removeUploadDiv(' + j + ');void(0);}">移除</a></div>');
    }
}
//设置编辑器的高度
function SetWinHeight(obj) {
    var win = obj;
    if (document.getElementById) {
        if (win && !window.opera) {
            if (win.contentDocument && win.contentDocument.body.offsetHeight)
                win.style.height = win.contentDocument.body.offsetHeight + "px";
            else if (win.Document && win.Document.body.scrollHeight)
                win.style.height = win.Document.body.scrollHeight + "px";
        }
    }
}
function appUploadDiv(fileOnchange) {
    if (!fileOnchange) fileOnchange = "";
    if (uploadDivCount < uploadImgMaxCount) {
        uploadDivCount++;
        uploadDivCountNum++;
        $("#appUploadImgDIV").append('<div id="appUploadImgDIV_' + uploadDivCountNum + '"><span id="appUploadImgDIVImg_' + uploadDivCountNum + '"></span><input onchange="' + fileOnchange + '" type="file" name="picture_' + uploadDivCountNum + '" id="picture_' + uploadDivCountNum + '" />'
        + '<a href="javascript:void(0)" onclick="showUploadImageEditor($(\'#picture_' + uploadDivCountNum + '\')[0])">用工具处理本图片</a> <label>是否做封面<input type="radio" value="' + uploadDivCountNum + '" name="smallImgIndex" /></label> <a href="javascript:{removeUploadDiv(' + uploadDivCountNum + ');void(0);}">移除</a></div>');
        if (uploadDivCount >= uploadImgMaxCount) $("#appUploadImgLinkBtn").hide();
    }
}
function showUploadImg(obj, toSpanId) {
    $("#" + toSpanId).html($("<img></img>").attr("src", getUploadValue(obj)));
}
function removeUploadDiv(i) {
    $("#appUploadImgDIV_" + i).remove();
    uploadDivCount--;
    if (uploadDivCount < uploadImgMaxCount) $("#appUploadImgLinkBtn").attr("disabled", "").show();
}
function setUpLoadList(id) {
    var url = "/Property/UpLoadList";
    var sendData = { id: id };
    $("#UpLoadListDiv").html("<img src=\"../../Content/images/loading/loading.gif\" />");
    $.post(url, sendData, function(data) {
        $("#UpLoadListDiv").html(data);
    });
}

function judgeUploadImageEditor(fileInput) {
    var src = getUploadValue(fileInput), fileName = fileInput.value;
    if (fileName.match(/\.jpg$/ig) == null
            && fileName.match(/\.jpeg$/ig) == null
            && fileName.match(/\.png$/ig) == null
            && fileName.match(/\.gif$/ig) == null) {
        alert("上传的图片格式不正确!");
        var fInput = $(fileInput), replaceFileInput = $("<input type='file' id='" + fInput.attr("id") + "' name='" + fInput.attr("name") + "' />").change(fInput.attr("onchange"));
        fInput.replaceWith(replaceFileInput);
        return false;
    }
}
var showUploadImageEditorWidth = 600, showUploadImageEditorHeight = 600, cutWidth, cutHeight,thisFileInput;
function showUploadImageEditor(fileInput) {
    if (navigator.userAgent.indexOf('Firefox') < 0) {
        alert("对不起,本功能暂时只支持火狐浏览器,请更换使用!");
        return;
    }
    var src="";
    try {
        src = (fileInput.tagName == "IMG" ? fileInput.src : getUploadValue(fileInput));
    } catch (e) { }
    if (src != "") {
        thisFileInput = fileInput;
        var cutV = $(fileInput).attr("cutValue");
        var loadImg_scale = null, loadImg_cutLeft = null, loadImg_cutTop = null;
        if (cutV) {
            var carVArr = cutV.split('+');
            loadImg_scale = carVArr[0];
            loadImg_cutLeft = carVArr[1];
            loadImg_cutTop = carVArr[2];
        }
        showNiWindow("showUploadImageEditor_IfrContent", "", "编辑图片");
        
        uploadImageEditor.init('uploadImgEditDiv', cutWidth + 'px', cutHeight + 'px', 1);
        uploadImageEditor.loadImage(src, 1, loadImg_scale, loadImg_cutLeft, loadImg_cutTop);
    }
    else {
        alert("请先选择图片!");
    }
}
function addUploadImgCut(cutVal) {
    var fileInput = thisFileInput;
    $(fileInput).attr("cutValue", cutVal);
    updateUploadImgCut();
};
function updateUploadImgCut() {
    var imageCutInp = $("#uploadImgCut");
    var cutVArr = [];
    $("input:file").each(function(i, n) {
        var cutV = $(n).attr("cutValue");
        if (cutV) cutVArr.push($(n).attr("name") + "|" + cutV);
    });
    $("img[name='editUploadImg']").each(function(i, n) {
        var cutV = $(n).attr("cutValue");
        if (cutV) cutVArr.push($(n).attr("imgID") + "|" + cutV);
    });

    imageCutInp.val(cutVArr.join(","));
}


var nEditor;
//创建房源连接
function CreatePropertyIndex(type) {
    var url = "", sendData = "";
    if (type == "Sell") {
        url = "/Property/CreatePropertySellIndex";
        sendData = {};
    }
    if (type == "Rent") {
        url = "/Property/CreatePropertyRentIndex"; sendData = {};

    }
    if (type == "Wanted") {
        url = "/Property/CreatePropertyWantedIndex"; sendData = {};
    }

    if (type == "Buy") {
        url = "/Property/CreatePropertyBuyIndex"; sendData = {};
    }
    if (type == "ListIndex") {
        url = "/Property/ListIndex"; sendData = {};
    }
    if (type == "List") {
        url = "/Property/List"; sendData = {};
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#CreatePropertyType").val(type);
        $("#DivCreateProperty").html("");
        $("#manageAjaxShowMain").html("");
        $("#DivCreateProperty").html(data);
        //        nEditor = new jtbcEditor('Remark');
        //        nEditor.tToolbarSets['default'] = ['separator', 'Bold', 'Italic', 'Underline', 'RemoveFormat', 'separator', 'Link', 'Unlink', 'Image', 'Smiley', 'separator', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'separator', 'TextColor', 'BGColor'];
        //        nEditor.tInit('nEditor', '/Scripts/jtbceditor/');
    });
}
//全局房源类型
var GlobalPublishState = "2c7f773f-c833-48f1-8ed3-049d16304f7c"; //默认是出售
//房源集合
function CreatePropertyList(type, pageIndex, pageSize) {
    if (type != -1) {
        GlobalPublishState = type;
    }
    var state = $("#PublishState").val();
    var source = $("#PropertyT").val();
    var formEstateName = $("#formSearchEstateName").val();
    var formAreaId = $("#formSearchAreaId").val();
    var formUserName = $("#formSearchUserName").val();
    var formPropertyNo = $("#formSearchPropertyNo").val();
    var formCountF = $("#formSearchCountF").val();
    var formSquare = $("#formSearchSquare").val();
    var formPrice = $("#formSearchPrice").val();
    var formRentPrice = $("#formSearchRentPrice").val();
    var formModDateMinDay = $("#formSearchModDateMinDay").val();    
    var url = "/Property/SearchPropertyList";
    var sendData = { Trade: GlobalPublishState,
                    formEstateName: formEstateName,
                    formAreaId: formAreaId,
                    formUserName: formUserName,
                    formPropertyNo:formPropertyNo,
                    formCountF:formCountF,
                    formSquare:formSquare,
                    formPrice: formPrice,
                    formRentPrice:formRentPrice,
                    formModDateMinDay:formModDateMinDay,
                    state: state, did: Property_DepartId, pageIndex: pageIndex, pageSize: pageSize, isNoMing: source, isNoGeRen: true };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#Details").html("");
        $("#ErrorInfo").html("");
        $("#PropertyList").html(data);
        ShowORHideDIV("PropertyList", true);
    });
}
//获得房源
function getPropertyDetails(id, cctvTypeID) {
    var url = "", sendData = {};
    var type = (cctvTypeID ? cctvTypeID : GlobalPublishState);
    if (type == "2c7f773f-c833-48f1-8ed3-049d16304f7c") {
        url = "/Property/DetailsPropertySellIndex";
        sendData = { id: id };
    }
    else if (type == "f270dec1-98f8-4c7b-a52b-235d1cca59ce") {
        url = "/Property/DetailsPropertyRentIndex";
        sendData = { id: id };
    }
    else if (type == "8b4e0422-dcd6-4135-8dfd-16de50e65072") {
        url = "/Property/DetailsPropertyWantedIndex"; sendData = { id: id };
    }
    else if (type == "2b9d3c88-6b71-4fb4-a9b7-96d35201fdaa") {
        url = "/Property/DetailsPropertyBuyIndex"; sendData = { id: id };
    }
    else { alert('参数错误!'); return false; }

    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        ShowORHideDIV("PropertyList", false);
        //$("#PropertyList").html("");
        $("#Details").html(data);
        //        nEditor = new jtbcEditor('Remark');
        //        nEditor.tInit('nEditor', '/Scripts/jtbceditor/');
        //        $("#Remark-div")[0].style.cssText = "width:500px;height:95px;";
        //        $("#Remark-iframe")[0].style.cssText = "width:500px;height:70px;";
        //        nEditor.tToolbarSets['default'] = ['separator', 'Bold', 'Italic', 'Underline', 'RemoveFormat', 'separator', 'Link', 'Unlink', 'Image', 'Smiley', 'separator', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'separator', 'TextColor', 'BGColor'];

    });
}
//修改发布状态
function updatePublishState(id, state, backEval) {
    var url = "/Property/UpdatePublishState";
    var ids = "";
    if (id == null || id == "") {
        var idsArr = new Array();
        $.each($("input[name='CheckboxIds']"), function(i, n) {
            if (n.checked) {
                idsArr.push(n.value);
            }
        });
        if (idsArr == null || idsArr == "") {
            return;
        }
        ids = idsArr.join(",");
    } else {
        ids = id;
    }
    var sendData = { ids: ids, state: state };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        try {
            if (backEval != undefined) eval(backEval);
        } catch (e) { alert(e.message) }
        if (data.length >= 4 && data.substr(0, 4) == "true") {
            configAlert("修改成功", "#ConfigInfo");
            CreatePropertyList(GlobalPublishState, 0, 15);
            if (data.length > 5) {
                //如果传回的信息是这样的格式true|...,那么要执行|后面的JS代码
                var tempEvalJs = data.substr(5);
                if (tempEvalJs) eval(tempEvalJs);
            }
        } else {
            setErrorInfo(data, false, "#ErrorInfo", "#ConfigInfo");
        }
    });
}
//选择删除
function deletePropertyPhoto(id, pid) {
    if (confirm("确定删除选择的房源图片?")) {
        var url = "/Property/DeleteUpLoadPhoto";
        var sendData = { id: id, pid: pid };
        Loading();
        $.post(url, sendData, function(data) {
        EndLoading();
            if (data.length >= 4 && data.substr(0, 4) == "true") {
                configAlert("删除成功", "#ConfigInfo");
                setUpLoadList(id);
                if (data.length > 5) {
                    //如果传回的信息是这样的格式true|...,那么要执行|后面的JS代码
                    var tempEvalJs = data.substr(5);
                    if (tempEvalJs) eval(tempEvalJs);
                }
            } else {
                setErrorInfo(data, false, "#ErrorInfo", "#ConfigInfo");
            }
        });
    } else {
        return;
    }
}
//选择删除
function flagTrashedAllProperty() {
    if (confirm("确定删除选择的房源?")) {
        var url = "/Property/FlagTrashedAll";
        var idsArr = new Array();
        $.each($("input[name='CheckboxIds']"), function(i, n) {
            if (n.checked) {
                idsArr.push(n.value);
            }
        });
        if (idsArr == null || idsArr == "") {
            return;
        }
        var ids = idsArr.join(",");
        var sendData = { ids: ids };
        Loading();
        $.post(url, sendData, function(data) {
            EndLoading();
            if (data == "true") {
                configAlert("删除成功", "#ConfigInfo");
                CreatePropertyList(GlobalPublishState, 0, 15);
            } else {
                setErrorInfo(data, false, "#ErrorInfo", "#ConfigInfo");
            }
        });
    } else {
        return;
    }
}


//查找房源
function SearchPropertyList(pageIndex, pageSize) {
    var url = "/Property/SearchPropertyList"
    var sendData = { pageIndex: pageIndex
                    , pageSize: pageSize
                    , TopcarriageStateId: $("#TopcarriageStateId").val()
                    , formBeginDate: $("#formStartDate").val()
                    , formEndDate: $("#formEndDate").val()
                    , formPropertyNo: $("#formPropertyNo").val()
                    , formUserName: $("#formUserName").val()
                    , formEstateName: $("#formEstateName").val()
                    , formAreaId: $("#formAreaId").val()
                    , state: $("#formstate").val()

    };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#PropertyList").html(data);
    });

}
//全局房源网点ID
var Property_DepartId = "00000000-0000-0000-0000-000000000000";
var Property_DepartName = "";
var Property_DepartRname = "";
var Property_Type = "个人房源";
var Property_Operate = false; //更新房源
var Property_Operate2 = false; //发布房源
var ttccee = false;
//设置房源网点ID
function setPropertyDepartId(did, dname, rname, isno,isnoF) {
    Property_Operate = isno;
    Property_Operate2 = isnoF;
    Property_DepartRname = "(" + rname + ")";
    Property_DepartId = did;
    Property_DepartName = dname;
    Property_Type = "中介房源";
    $("#DivPropertyPublish").hide();
}
//重置房源网点ID
function removePropertyDepartId() {
    Property_DepartId = "00000000-0000-0000-0000-000000000000";
    Property_DepartName = "";
    Property_DepartRname = "";
    Property_Type = "个人房源";
    Property_Operate = false;
    $("#DivPropertyPublish").show();
}




//房源结束
//****************************************************************************************************************************************
//********************************************
//推房操作
var recommend_Etype = 1;
//启用复选
function ActivateCheck(isno) {
    $("input[name='CheckboxIds']").attr("disabled", isno);
}
//选择推房
function ApplyRecommendProperty(id) {
    var url = "/RecommendProperty/ApplyRecommendProperty";
    var SImgId = '';
    $.each($("input[name='PropertyThumbnail" + id + "']"), function(i, n) {
        if (n.checked) {
            SImgId = n.value;
        }
    });
    alert(1);
    var sendData = { ids: id
                    , modId: $("#searchRefId").val()
                    , days: $("#searchCycleTime").val()
                    , SImgId: SImgId
                    , selectEType: recommend_Etype
    };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("提交成功", "#ConfigInfo");
            ShowORHideDIV('DivCreateRecommend', false);
            SearchRecommendPropertyList(0, 10);
        } else {
            setErrorInfo(data, false, "#ErrorInfo", "#ConfigInfo");
        }
    });

}
//得到推房类别和周期下拉
function RecommendSelect(pageIndex, pageSize) {
    var url = "/RecommendProperty/RecommendSelect"
    var sendData = { pageRefId: $("#SformPageRefId").val(),selectEType:recommend_Etype
    };
    Loading("加载中...");
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#DivRecommendSelect").html(data);
    });

}
//编辑首推房源
function EditRecommendProperty(id) {
    var url = "/RecommendProperty/Edit";
    var SImgId = '';
    $.each($("input[name='RecommendPropertyThumbnail" + id + "']"), function(i, n) {
        if (n.checked) {
            SImgId = n.value;
        }
    });
    if (SImgId == '') {
        setErrorInfo("请选择缩略图!", false, "#ErrorInfo", "#ConfigInfo");
        return;
    }
    var sendData = {
        id: id
        , Sort: $("#EditSort" + id).val()
        , SImgId: SImgId
    };
    Loading();
    $.post(url, sendData, function(data) {
    EndLoading();
    $(".ErrorInfo").html("");
        if (data == "true") {
            configAlert("编辑成功", "#ConfigInfo");
            SearchRecommendPropertyList(0, 10);
        } else {
            setErrorInfo(data, false, "#ErrorInfo", "#ConfigInfo");
        }
       
    });

}
//推房后台推房
function RecommendProperty(id) {
    var url = "/RecommendProperty/RecommendProperty";
    var sendData = { id: id                
    };
    Loading();
    $.post(url, sendData, function(data) {
    EndLoading();
    $(".ErrorInfo").html("");
        if (data == "true") {
            configAlert("提交成功", "#ConfigInfo");
            SearchRecommendPropertyList(0, 10);
        } else {
            setErrorInfo(data, false, ".ErrorInfo", ".ConfigInfo");
        }      
    });

}
//推房后台取消推房
function DeRecommendProperty(id) {
    var url = "/RecommendProperty/DeRecommendProperty";
    var sendData = { id: id
    };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $(".ErrorInfo").html("");
        if (data == "true") {
            configAlert("提交成功", "#ConfigInfo");
            SearchRecommendPropertyList(0, 10);
        } else {
            setErrorInfo(data, false, ".ErrorInfo", ".ConfigInfo");
        }

    });

}
//选择推房
function UpdateAllRecommendPropertyState(state) {
    var url = "/RecommendProperty/UpdateRecommendPropertyState";
    var idsArr = new Array();
    $.each($("input[name='CheckboxRIds']"), function(i, n) {
        if (n.checked) {
            idsArr.push(n.value);
        }
    });
    if (idsArr == null || idsArr == "") {
        return;
    }
    var ids = idsArr.join(",");
    var sendData = { ids: ids,state:state };
    Loading();
    $.post(url, sendData, function(data) {
    EndLoading();
    $(".ErrorInfo").html("");
        if (data == "true") {
            configAlert("操作成功", "#ConfigInfo");
            SearchRecommendPropertyList(0,10);
        } else {
            setErrorInfo(data, false, ".ErrorInfo", ".ConfigInfo");
        }       
    });
}
//选择删除
function flagTrashedAllRecommendProperty() {
    if (confirm("确定删除选择的房源推荐?")) {
        var url = "/RecommendProperty/FlagTrashedAll";
        var idsArr = new Array();
        $.each($("input[name='CheckboxRIds']"), function(i, n) {
            if (n.checked) {
                idsArr.push(n.value);
            }
        });
        if (idsArr == null || idsArr == "") {
            return;
        }
        var ids = idsArr.join(",");
        var sendData = { ids: ids };
        Loading();
        $.post(url, sendData, function(data) {
        EndLoading();
        $(".ErrorInfo").html("");
            if (data == "true") {
                configAlert("删除成功", "#ConfigInfo");
                SearchRecommendPropertyList(0, 10);
            } else {
                setErrorInfo(data, false, "#ErrorInfo", "#ConfigInfo");
            }
        });
    } else {
        return;
    }
}


//查找首推房源
function SearchRecommendPropertyList(pageIndex, pageSize) {    
    var recommendDateTime = $("#SeachRecommendDateTime").val();
    if (recommendDateTime == "") {        
        setErrorInfo("请选择查找时间!", true, ".ErrorInfo", ".ConfigInfo");
        return;
    }
    var url = "/RecommendProperty/List"
    var sendData = { pageIndex: pageIndex
                    , pageSize: pageSize
                    , ReferenceId: $("#IndexRecommendCategory").val()
                    , RefId: $("#SeachRecommendRifId").val()
                    , RecommendDateTime: recommendDateTime

    };
    Loading();
    $.post(url, sendData, function(data) {
    EndLoading();
    $(".ErrorInfo").html("");
        $("#RecommendPropertyList").html(data);
       
    });

}
//隐藏推荐项
function resetSelect() {
    hideObjById('DivCreateRecommend');
}
//获取推荐模块下拉列表
function getRecommendRef() {
    var url = "/RecommendProperty/deptIndexModules"
    var sendData = { pageRefId: $("#formPageRefId").val() };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#SpanSeachRecommendRifId").html(data);
    });
}

//获取推荐模块下拉列表
function getPageRecommendRef(pageRef, dept, moduleCategory, showId) {
    var url = "/RecommendProperty/pagedeptIndexModules"
    var sendData = { pageRefId: pageRef, deptId: dept, moduleCategory: moduleCategory };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        if (showId)
            $("#" + showId).html(data);
        else
            $("#SpanDeptIndexModuleId").html(data);
    });
}

//推房结束
//*********************************************
//******************************************************************************
//客服操作
//查找客服信息
function SearchAdvisoryList(pageIndex,pageSize) {
    var url = "/Advisory/List"
    var sendData = { OperateState: $("#SearchOperateState").val()
                    , RegTimeStart: $("#SearchRegTimeStart").val()
                    , RegTimeEnd: $("#SearchRegTimeEnd").val()
                    , pageIndex: pageIndex
                    , pageSize: pageSize     
};
Loading();
$.post(url, sendData, function(data) {
    EndLoading();
    $("#AdvisoryList").html(data);
});
}
function SearchAdvisoryConfigList() {
    var url = "/AdvisoryConfig/List"
    var sendData = {
    };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#AdvisoryConfigList").html(data);
    });
}
//获得客服配置
function DetailsAdvisoryConfig(id) {
    var url = "/AdvisoryConfig/Details", sendData = { id: id };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#AdvisoryConfigShow").html(data);
        showNiWindow('AdvisoryConfigShow', '', '查看详细');
        DetailsAdvisoryConfigReBack();
    });
}
//修改处理状态
function UpdateAdvisoryOperateState(id,state) {
    var url = "/Advisory/UpdateOperateState";
    var sendData = { id: id, state: state
    };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();        
        if (data == "true") {
            configAlert("提交成功", "#ConfigInfo");
            SearchAdvisoryList(0,10);
        } else {
            setErrorInfo(data);
        }

    });

}

//客服结束
//*****************************************************************************

//****************************************************************************************************************************************
//积分操作
//得到积分规则集合
function tagScoreOperate(type) {
    ShowORHideDIV('DivScore_Content', false);
    ShowORHideDIV('DivScoreRule_Content', false);
    ShowORHideDIV('DivScoreHistory_Content', false);
    if (type == "Score") {
        ListScore(0, 10);
        ShowORHideDIV('DivScore_Content', true);
    }
    else if (type == "ScoreRule") {
        ListScoreRule(0, 10);
        ShowORHideDIV('DivScoreRule_Content', true);
    }
    else if (type == "ScoreHistory") {
        ListScoreHistory(0, 10,"true");
        ShowORHideDIV('DivScoreHistory_Content', true);
    }
}
//得到积分规则集合
function ListScoreRule(pageIndex, pageSize) {
    var url = "/Score/ListDefaultScoreRule", sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#ListScoreRule").html(data);
    });
}
//得到积分集合
function ListScore(pageIndex, pageSize) {
    var url = "/Score/ListScore", sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#ListScore").html(data);
    });
}
//得到积分历史记录集合
function ListScoreHistory(pageIndex, pageSize,isno) {
    var url = "/Score/ListScoreHistory", sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize,
        isno:isno
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#ListScoreHistory").html(data);
    });
}
//获得积分规则
function DetailsScoreRule(id) {
    var url = "/Score/DetailsDefaultScoreRule", sendData = { DefaultScoreRuleId: id };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#ScoreRuleShow").html(data);
        showNiWindow('ScoreRuleShow', '', '查看详细');
        DetailsScoreRuleReBack();
    });
}

//显示或隐藏房源发布级别
function showPublishProperty(obj, operateObj, triggerValue) {
    if ($("#" + obj).val() == triggerValue) {
        $("#" + operateObj).show();
    }
    else {
        $("#" + operateObj).hide();
    }
}

//以下是网点积分规则
//得到积分规则集合
function ListDeptScoreRule(pageIndex, pageSize) {
    var url = "/Score/ListScoreRule", sendData = {
        pageIndex: pageIndex,
        pageSize: pageSize
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#ListScoreRule").html(data);
    });
}

//获得积分规则
function DetailsDeptScoreRule(id) {
    var url = "/Score/DetailsScoreRule", sendData = { ScoreRuleId: id };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#ScoreRuleShow").html(data);
        showNiWindow('ScoreRuleShow', '', '查看详细');
        DetailsScoreRuleReBack();
    });
}
//积分结束
//****************************************************************************************************************************************
//****************************************************************************************************************************************
///点击率

//点击
function CreatePropertyCTR(id) {
    var url = "/PropertyCTR/Create", sendData = { pId: id };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        $("#showMoodsCount").val(data);
    });
}

//点击率结束
//****************************************************************************************************************************************


//将DIV显示在页面的中间
function showDivCenter(id, offsetID) {
    var top, left;
    if (document.documentElement && document.documentElement.scrollTop) {
        top = document.documentElement.scrollTop;
        left = document.documentElement.scrollLeft;
    } else if (document.body) {
        top = document.body.scrollTop;
        left = document.body.scrollLeft;
    }
    var obj = $("#" + id);
    var offsetObj = offsetID ? $("#" + offsetID) : obj;

    var winD = winDimensions();
    var offTop = parseInt(top + (parseInt(winD.winHeight) - parseInt(offsetObj[0].offsetHeight > 0 ? offsetObj[0].offsetHeight : offsetObj.height())) / 2);
    var offLeft = parseInt(left + (parseInt(winD.winWidth) - parseInt(offsetObj[0].offsetWidth > 0 ? offsetObj[0].offsetWidth : offsetObj.width())) / 2);
    if (offTop < 0) offTop = 0;
    if (offLeft < 0) offLeft = 0;

    obj.css({ top: offTop + "px", left: offLeft + "px" });
}

//测试
var testSellFV = false;
var testRentFV = false;


//****************************************************************************************************************************************
///角色设置
//列表
function roleList() {
    Loading();
    var url = "/Role/List";
    var sendData = {};
    $.post(url, sendData, function(data) {
        $("#List").html(data);
        EndLoading();
    }
    );
}

//创建设为初始化
function roleCreateSetDefault() {
    $("#RoleName").val("");
    $("#RoleName").focus();
}

//创建
function roleCreate() {
    Loading();
    $("#addButton").attr("disabled", "true");
    var roleName = $("#RoleName").val();
    var url = "/Role/Create";
    var sendData = { RoleName: roleName };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            roleCreateSetDefault();
            configAlert("添加成功", "#ConfigInfo");
            $("#addButton").attr("disabled", "");
            roleList();
        }
        else {
            setErrorInfo(data);
            $("#addButton").attr("disabled", "");
        }
    });
}

//修改
function roleEdit(id) {
    Loading();
    var roleName = $("#RoleName" + id).val();
    var url = "/Role/Edit";
    var sendData = { id: id, RoleName: roleName };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            configAlert("修改成功", "#ConfigInfo");
            roleList();
        }
        else {
            setErrorInfo(data);
        }
    });
}

//查看角色列表
function displayRoleOperateRoles(Rid, reback) {
    Loading("载入中...");
    $("#RoleOperateRolesDisplay").html("<img src=\"../../Content/images/loading/loading_process.gif\" />正在打开设置角色操作对象信息...");
    showNiWindow("RoleOperateRolesDisplay", "prompt", "设置角色操作对象");
    $.post("/RoleOperateRoles/List/", { Rid: Rid }, function(data) {
        EndLoading();
        $("#RoleOperateRolesDisplay").html(data);
        showNiWindow("RoleOperateRolesDisplay", "prompt", "设置角色操作对象");
        if (reback) eval(reback);
    });
}

//添加操作角色
function addRoleOperateRoles(crid, reBack) {
    Loading("正在添加...");
    var rid = $("#hileRoleID").val();
    var url = "/RoleOperateRoles/Create";
    var sendData = {
        formRoleId: rid,
        formOperateRoleId: crid
    };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            if (!reBack) displayRoleOperateRoles(rid, "configAlert('<p>添加成功</p>', '.ConfigInfo');");
            else eval(reBack);
        }
        else {
            setErrorInfo(data, true, ".ErrorInfo", ".ConfigInfo");
        }
    });
}
//移除操作角色
function deleteRoleOperateRoles(id, reBack) {
    Loading("正在移除...");
    var rid = $("#hileRoleID").val();
    var url = "/RoleOperateRoles/Delete";
    var sendData = {
        id: id
    };
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            if (!reBack) displayRoleOperateRoles(rid, "configAlert('<p>移除成功</p>', '.ConfigInfo');");
            else eval(reBack);
        }
        else {
            setErrorInfo(data, true, ".ErrorInfo", ".ConfigInfo");
        }
    });
}

//角色设置结束
//****************************************************************************************************************************************
//*********操作开始******************************
var thisOperationIndex = 0;
//查看操作列表
function ShowOperation(pn) {
    if (!pn) pn = 0;
    thisOperationIndex = pn;
    $("#DivShowOperation").show();
    $("#DivShowOperation").html("<img src=\"../../Content/images/loading/loading_process.gif\" />正在打开操作列表,第" + (thisOperationIndex + 1) + "页...");
    $.post("/Operation/Index", { pn: thisOperationIndex }, function(data) {
        $("#" + showManageDivID).html(data);
        $("#ButtonShowOperation").hide();
        $("#ButtonHideOperation").show();
        //        HidePrivilege();
        //        HideResourcesGroup();
        //        HideResources();
    });
}
//关闭操作列表
function HideOperation() {
    $("#DivShowOperation").hide();
    $("#ButtonShowOperation").show();
    $("#ButtonHideOperation").hide();
}
//添加编辑操作
function EditOperation(id) {
    var url = "/Operation/Edit";
    if (!id) {
        id = "";
        url = "/Operation/Create";
    }
    var sendData = {
        id: id
        , OperationName: $("#Operation_OperationName" + id).val()
        , OperationCNName: $("#Operation_OperationCNName" + id).val()
        , Description: $("#Operation_Description" + id).val()
    };
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            ShowOperation(thisOperationIndex);
            if (!id) {
                $("#DivCreateOperation :text").val("");
                configAlert("添加成功", "#ConfigInfo");
            }
            else {
                configAlert("编辑成功", "#ConfigInfo");
            }
        }
        else {
            setErrorInfo(data);
        }
    });
}
//*********操作结束******************************
//*********权限开始******************************
var thisPrivilegeIndex = 0;
var thisPrivilegeOpId = 0;
var thisPrivilegeReId = 0;
//查看权限列表
function ShowPrivilege(pn, opId, reId) {
    if (!pn) pn = 0;
    thisPrivilegeIndex = pn;
    thisPrivilegeOpId = opId;
    thisPrivilegeReId = reId;
    var sendData = { pn: thisPrivilegeIndex };
    if (opId) {
        sendData.opId = opId;
    }
    else if (reId) {
        sendData.reId = reId;
    }
    $("#DivShowPrivilege").show();
    $("#DivShowPrivilege").html("<img src=\"../../Content/images/loading/loading_process.gif\" />正在打开权限列表,第" + (thisPrivilegeIndex + 1) + "页...");
    $.post("/Privilege/List", sendData, function(data) {
        $("#DivShowPrivilege").html(data);
        $("#ButtonShowPrivilege").hide();
        $("#ButtonHidePrivilege").show();
        //        HideOperation();
        //        HideResourcesGroup();
        //        HideResources();
    });
}
//关闭权限列表
function HidePrivilege() {
    $("#DivShowPrivilege").hide();
    $("#ButtonShowPrivilege").show();
    $("#ButtonHidePrivilege").hide();
}
//层级选择资源(根据资源组选择资源)
function SelectResources(id, parentValue, value) {
    ;
    $("#SpanPrivilege_ResourcesGroupId" + id).html(GetMenuChildsHtml("allReGroup", "", "Privilege_ResourcesGroupId" + id, parentValue, "onchange=\"$('#SpanPrivilege_ResourcesId" + id + "').html(GetMenuChildsHtml('allReGroup',$(this).val(),'Privilege_ResourcesId" + id + "','',''));\""));
    $('#SpanPrivilege_ResourcesId' + id).html(GetMenuChildsHtml('allReGroup', $("#Privilege_ResourcesGroupId" + id).val(), 'Privilege_ResourcesId' + id, value, ''));
}
//添加编辑操作
function EditPrivilege(id) {
    var url = "/Privilege/Edit";
    if (!id) {
        id = "";
        url = "/Privilege/Create";
    }
    var sendData = {
        id: id
        , PrivilegeName: $("#Privilege_PrivilegeName" + id).val()
        , PrivilegeCNName: $("#Privilege_PrivilegeCNName" + id).val()
        , DefaultValue: $("#Privilege_DefaultValue" + id).val()
        , Description: $("#Privilege_Description" + id).val()
        , Sort: $("#Privilege_Sort" + id).val()
    };
    if ($("#Privilege_OperationId" + id).val()) {
        sendData.OperationId = $("#Privilege_OperationId" + id).val()
    }
    if ($("#Privilege_ResourcesId" + id).val()) {
        sendData.ResourcesId = $("#Privilege_ResourcesId" + id).val()
    }
    Loading();
    $.post(url, sendData, function(data) {
        EndLoading();
        if (data == "true") {
            ShowPrivilege(thisPrivilegeIndex, thisPrivilegeOpId, thisPrivilegeReId);
            if (!id) {
                $("#DivCreatePrivilege :text").val("");
                configAlert("添加成功", "#ConfigInfo");
            }
            else {
                configAlert("编辑成功", "#ConfigInfo");
            }
        }
        else {
            setErrorInfo(data);
        }
    });
}

function SetResourceValue(id, DroupDownId, showObj) {
    $("#" + DroupDownId).val(id);
    if (showObj) {
        showObjById(showObj);
    }
}
//*********权限结束******************************


//网点首页模块设置

//载入当前用户所创建部门的模块列表
function ListDeptIndexModule() {
    Loading("载入列表...");
    $.post("/DeptIndexModule/List", {}, function(data) {
        EndLoading();
        $("#List").html(data);
    });
}

//显示编辑
function ShowEditDeptIndexModule(id, refId, pageRefId) {
    showEdit(id);
    getReferenceById(DeptIndexModule, "SpanformRefId" + id, "formRefId", "formRefId", refId);
    getReferenceById(IndexRecommendPageCategory, "SpanformPageRefId" + id, "formPageRefId", "formPageRefId", pageRefId);
    $('#formEditDeptIndexModule' + id).ajaxForm({
        beforeSubmit: function(formData, jqForm, options) {
            Loading("保存中...");
        },
        success: function(data, statusText) {
            EndLoading();
            if (statusText == "success") {
                if (data == "true") {
                    configAlert("<p>保存成功!</p>", "#ConfigInfo");
                    ListDeptIndexModule();
                }
                else {
                    setErrorInfo(data, true, "#ErrorInfo", "#ConfigInfo");
                }
            }
            else { alert('请求失败!'); }
        }
    });
}

//首页,控制当前用户选择所在省市镇
var hideSetCurrUserPositionHandle = null; //延迟隐藏
function ShowSetCurrUserPosition() {
    clearTimeout(hideSetCurrUserPositionHandle);
    $('#selectUserPositionPCT').show(100);
}
function HideSetCurrUserPosition() {
    hideSetCurrUserPositionHandle = setTimeout(function() { $('#selectUserPositionPCT').fadeOut(300); }, 1000);
}
function SetCurrUserPosition() {
    if (!$('#SelectUserPosition_P').val()) { $('#SelectUserPosition_P').focus(); return false; }
    if (!$('#SelectUserPosition_C').val()) { $('#SelectUserPosition_C').focus(); return false; }
    if (!$('#SelectUserPosition_T').val()) { $('#SelectUserPosition_T').focus(); return false; }
    location.href = "/Home/SetCurrUserPosition/" + escape($('#SelectUserPosition_T').val()) + "?goToUrl=" + escape(location.href);
}


//右下角提示功能
/*
showDivObj:在哪显示(jQuery对象,最好是绝对定位的,效果会好点),如果为空则是在右下角显示
str:显示字符串
showTime:显示的时间,单位毫秒
className:附加的class
*/
function showTooltip(showDivObj, str, showTime, className, rebackFunc) {
    var p = showDivObj ? showDivObj : $("#showTooltipDiv"), pc;
    if (p == null || p.length <= 0) {
        p = $("<div></div>").attr("id", "showTooltipDiv").css({ position: "absolute" });
        $(document.body).append(p);
    }
    pc = p.find("#showTooltipDivContent");
    if (pc == null || pc.length <= 0) {
        pc = $("<div id='showTooltipDivContent'></div>");
        p.append(pc);
    }

    var t = $("<div class='ShowTooltip'></div>").html(str);
    if (className) t.addClass(className);
    pc.append(t);
    p.css({ width: pc.attr("offsetWidth") + "px", height: pc.attr("offsetHeight") + "px" });

    if (!showDivObj) {
        var scrollPosition = getScrollTop(), windOffset = winDimensions();
        p.css({ left: (scrollPosition.left + windOffset.winWidth - pc.attr("offsetWidth") - 17) + "px",
            top: (scrollPosition.top + windOffset.winHeight - pc.attr("offsetHeight") - 17) + "px"
        });
    }

    setTimeout(function() {
        t.fadeOut(500, function() { t.remove(); if (rebackFunc) rebackFunc(); });
    }, showTime);
}


/*
显示增加用户积分(并附带分数滚动的效果)
*/
var currUserAllScore = 0;
var showAddUserScoreEffectHandle = 0; //显示积分效果的控制句柄
var showUserScoreID = ".PointsColor";//#showUserScore";
function addUserScoreShow(score) {
    score = parseFloat(score);
    var showUserScore = $(showUserScoreID);
    if (showUserScore == null || showUserScore.lengt <= 0) {
        alert("要显示积分的层不存在");
        return 1;
    }
    var oldScore = 0;
    try { oldScore = parseFloat($("#showUserScore").html()); }
    catch (e) { alert("要显示积分的层ID错误!该层内只能放数字(积分)"); return 1; }
    if (currUserAllScore == 0) currUserAllScore = oldScore;
    if (showAddUserScoreEffectHandle !== 0) {
        clearTimeout(showAddUserScoreEffectHandle);
        showAddUserScoreEffectHandle = 0;
        showAddUserScoreEffectTempScore = 0;
        showUserScore.html(currUserAllScore);
    }
    currUserAllScore += score;

    showAddUserScoreEffect(oldScore, score < 0 ? -1 : 1);
    
}
//最多滚动20次,总时间最多消耗1000毫秒(每次滚动加1/20差分,得到的滚动分不满1分算1分)
//fuPa=-1|1
var showAddUserScoreEffectTempScore = 0;
var showAddUserScoreEffectAllCount = 20;
var showAddUserScoreEffectAllTime = 1000;
var showAddUserScoreEffectATime = parseInt(showAddUserScoreEffectAllTime / showAddUserScoreEffectAllCount);
function showAddUserScoreEffect(oldScore, fuPa) {
    if (showAddUserScoreEffectTempScore == 0) {
        showAddUserScoreEffectTempScore = parseInt((currUserAllScore - oldScore) / 20);
        if (showAddUserScoreEffectTempScore * fuPa < 1) showAddUserScoreEffectTempScore = 1 * fuPa;
    }
    if (oldScore * fuPa < currUserAllScore * fuPa) {
        var showUserScore = $(showUserScoreID);
        var theScore = oldScore + showAddUserScoreEffectTempScore;
        if (theScore * fuPa > currUserAllScore * fuPa) theScore = currUserAllScore;
        showUserScore.html(theScore);
        if (currUserAllScore * fuPa > theScore * fuPa) {
            showAddUserScoreEffectHandle = setTimeout(function() { showAddUserScoreEffect(theScore, fuPa) }, showAddUserScoreEffectATime);
        }
        else {
            showAddUserScoreEffectTempScore = 0;
        }
    }
}
//网点首页模块设置结束
//*********************************************************************************************************************************************************************************************************
// 打卡
function clickMenuToCoding() {
    Loading("打卡领积分喽...");
    //这边把按钮的值改变一下。
    codingAlready();
    var url = "/Home/Coding";
    var sendData = {};
    $.post(url, sendData, function(data) {
        EndLoading();
        //alert(data);
        eval(data);
        iscoding = "True";
    });
}
//积分操作
function minusTotalScore(minusScore) {
    $(".PointsColor").html(parseInt($(".PointsColor").html()) - minusScore);
}
//已打卡 改变状态
function codingAlready() {
    $("#LinkCoding").addClass("cardDisabled");
    $("#LinkCoding").removeAttr("onclick");
}
//**********************************************************************************************************************************************************************************************************
