var objMyAlert;

//读取URL传参
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return ""; //返回参数值
}

//显示错误提示层
function alertDisplay(id) {
    objMyAlert = $("#" + id);
    objMyAlert.attr("style", "display:none")
    //objMyAlert.removeClass("alert-error").addClass("alert-info");
    objMyAlert.attr("class", "alert-info");
}

//显示错误内容
function ShowError(id, remark) {

    objMyAlert = $("#" + id);
    //objMyAlert.removeClass('alert alert-Infoalert').addClass('alert alert-Myalert');
    objMyAlert.attr("class", "alert alert-Myalert");
    objMyAlert.html(remark);
    objMyAlert.attr("style", "display:block");
    setTimeout("alertDisplay('" + id + "')", 2000);
}

//关闭颜色框
function closecolorpanel() {
    $("#colorpanel").hide();
}

//显示错误内容 样式自定义
function ShowExtError(id, remark, objstylecontent) {
    objMyAlert = $("#" + id);
    //objMyAlert.removeClass('alert alert-Infoalert').addClass('alert alert-Myalert');
    objMyAlert.attr("class", "alert alert-Myalert");
    objMyAlert.html(remark);
    objMyAlert.attr("style", objstylecontent);
    setTimeout("alertDisplay('" + id + "')", 2000);
}


//显示提示内容
function ShowMsg(id, remark) {
    objMyAlert = $("#" + id);
    //objMyAlert.removeClass('alert alert-Myalert').addClass('alert alert-Infoalert');
    objMyAlert.attr("class", "alert alert-Infoalert");
    objMyAlert.html(remark);
    objMyAlert.attr("style", "display:block");
    setTimeout("alertDisplay('" + id + "')", 2000);
}

function alwaysShowMsg(id, remark) {
    objMyAlert = $("#" + id);
    // objMyAlert.removeClass('alert alert-Myalert').addClass('alert alert-Infoalert');
    objMyAlert.attr("class", "alert alert-Infoalert");
    objMyAlert.html(remark);
    objMyAlert.attr("style", "display:block");

}

//显示提示内容 样式自定义
function ShowExtMsg(id, remark, objstylecontent) {
    objMyAlert = $("#" + id);
    //objMyAlert.removeClass('alert alert-Myalert').addClass('alert alert-Infoalert');
    objMyAlert.attr("class", "alert alert-Infoalert");
    objMyAlert.html(remark);
    objMyAlert.attr("style", objstylecontent);
    setTimeout("alertDisplay('" + id + "')", 2000);
}

//显示错误内容
function ShowAlwaysError(id, remark) {
    objMyAlert = $("#" + id);
    //objMyAlert.removeClass('alert alert-Infoalert').addClass('alert alert-Myalert');
    objMyAlert.attr("class", "alert alert-Myalert");
    objMyAlert.html(remark);
    objMyAlert.attr("style", "display:block");
}

//完全替换字符串
function SuperReplace(content, str1, str2) {
    while (content.indexOf(str1) > -1) {
        content = content.replace(str1, str2);
    }
    return content;
}

//防连击waiting按钮样式
function BtnWaiting(btnname, level) {
    var btn = $("#" + btnname);
    if (btn != null && btn.length > 0) {
        if (level == 0) {
            btn.css("background-image", "url(./img/ajax-loaders/ajax-loader-8.gif)");
        }
        else if (level == 1) {
            btn.css("background-image", "url(../img/ajax-loaders/ajax-loader-8.gif)");
        }
        else if (level == 2) {
            btn.css("background-image", "url(../../img/ajax-loaders/ajax-loader-8.gif)");
        }

        btn.css("background-repeat", "no-repeat");
        btn.css("background-size", "200% 200%");
        btn.css("background-position", "-20px -10px");
        btn.attr("disabled", true);
    }
}

//恢复按钮样式
function BtnRecovery(btnname) {
    $("#" + btnname).css("background-image", "");
    $("#" + btnname).attr("disabled", false);
}

//直接跳转到对话窗体
function GoTalk(wechatkey) {
    window.location.href = "talk.html?wechatkey=" + wechatkey;
}

//前台页面打开管理窗体
function GoManage() {
	homeObj.showmanage();
}

//前台页面打开数据分析窗体
function GoData() {
    homeObj.showdata();
}

//前台页面打开地图窗体
function ShowMap(ToUser,pid,uin) {
	homeObj.showmap(ToUser,pid,uin);
}
//防止事件穿透
function Antipenetration(event) {
	event.stopPropagation();
}

$(function () {
    cssinit();
})
function cssinit() {
    $("#wrapper").css({
        height: $(window).height()
    });
    $("#page-wrapper").css({
        height: $(window).height()
    });
    $("#set-wrapper").css({
        height: $(window).height()
    });
    $("#content").css({
        height: $(window).height()
    });
    $(".right-content-container").css({
        height: $(window).height()
    });
    $("#page-inner").css({
        height: $(window).height()
    });

}
$(window).resize(function () {
    cssinit();
});

function initTree() {
    $('.inactive-m').unbind("click").click(function () {
        if ($(this).siblings('ul').css('display') == 'none') {
            $(this).parent('li').siblings('li').removeClass('inactives-m');
            $(this).addClass('inactives-m');
            $(this).siblings('ul').slideDown(100).children('li');
            if ($(this).parents('li').siblings('li').children('ul').css('display') == 'block') {
                $(this).parents('li').siblings('li').children('ul').parent('li').children('a').removeClass('inactives-m');
                //$(this).parents('li').siblings('li').children('ul').slideUp(0);

            }
        } else {
            //控制自身变成+号
            $(this).removeClass('inactives-m');
            //控制自身菜单下子菜单隐藏
            $(this).siblings('ul').slideUp(100);
            //控制自身子菜单变成+号
            $(this).siblings('ul').children('li').children('ul').parent('li').children('a').addClass('inactives-m');
            //控制自身菜单下子菜单隐藏
            $(this).siblings('ul').children('li').children('ul').slideUp(100);
            //控制同级菜单只保持一个是展开的（-号显示）
            $(this).siblings('ul').children('li').children('a').removeClass('inactives-m');
        }
    })
}

$(document).ready(function () {
    //权限判断
    var num = 0;
    var adminauth = "";
    var authJson = {};
    if (typeof (manageObj) != "undefined") {
        authJson = $.parseJSON(manageObj.getauth());
        adminauth = manageObj.getauthid();
    } else if (typeof (homeObj) != "undefined") {
        authJson = $.parseJSON(homeObj.getauth());
        adminauth = homeObj.getauthid();
    }
    if (adminauth.toString() == "-1") {
        //管理员权限
        if ($("#CreatPersonAndDept").length > 0) {
            $("#CreatPersonAndDept").html("创建部门/成员");
        }
    } else {
        //数据分析
        if (authJson.k12 == true) {
            if ($("#menuData").length > 0) {
                $("#menuData").hide();
            }
        }
        //机器人自动回复
        if (authJson.k20 == false) {
            if ($("#Robat").length > 0) {
                $("#Robat").hide();
            }
        }
		//关键词过滤
        if (authJson.k21 == false) {
        	if ($("#Sensitiv").length > 0) {
        		$("#Sensitiv").hide();
        	}
        }
        //参数设置
        if (authJson.k1 == false) {
            if ($("#canshu").length > 0) {
                $("#canshu").hide();
            }
        }
        //企业信息
        if (authJson.k16 == false) {
            if ($("#companymsg").length > 0) {
                $("#companymsg").hide();
            }
        }
        //微信号管理
        if (authJson.k17 == false) {
            if ($("#wechatmng").length > 0) {
                $("#wechatmng").hide();
            }
        }
        //组织架构
        if (authJson.k18 == false) {
            if ($("#deptmng").length > 0) {
                $("#deptmng").hide();
            }
        }
        //权限组管理
        if (authJson.k19 == false) {
            if ($("#authmng").length > 0) {
                $("#authmng").hide();
            }
        }
        //企业信息
        if (authJson.k16 == false && authJson.k16 == false && authJson.k18 == false && authJson.k19 == false) {
            if ($("#companyinfo").length > 0) {
                $("#companyinfo").hide();
            }
        }
        //添加人员按钮
        if ($("#liCreateDept").length > 0) {
            $("#liCreateDept").hide();
        }
      
    }
    

    if ($('[data-rel=popover]').length > 0 && typeof ($('[data-rel=popover]')) != "undefined") {
        $('[data-rel=popover]').popover({ container: 'body' });
    }
});
/******图片放大效果 开始*******/

function show_big_img(imgele) {
    var mainele = $("#zoomableContainerCopy");
    mainele.html($("#zoomableContainerMain").html());
    $(".zoomableContainerfade", mainele).show();
    $(".zoomableContainer", mainele).show();
    //$("#imageFullScreen", mainele).attr("src", imgele);
    //$('#imageFullScreen', mainele).smartZoom({ 'containerClass': 'zoomableContainer' });
    //$('#topPositionMap,#leftPositionMap,#rightPositionMap,#bottomPositionMap', mainele).bind("click", moveButtonClickHandler);
    homeObj.showbigform(imgele);
    $('#zoomInButton,#zoomOutButton', mainele).bind("click", zoomButtonClickHandler);
}

function zoomButtonClickHandler(e) {
    var scaleToAdd = 0.8;
    if (e.target.id == 'zoomOutButton')
        scaleToAdd = -scaleToAdd;
    $('#imageFullScreen').smartZoom('zoom', scaleToAdd);
}
function moveButtonClickHandler(e) {
    var pixelsToMoveOnX = 0;
    var pixelsToMoveOnY = 0;

    switch (e.target.id) {
        case "leftPositionMap":
            pixelsToMoveOnX = 50;
            break;
        case "rightPositionMap":
            pixelsToMoveOnX = -50;
            break;
        case "topPositionMap":
            pixelsToMoveOnY = 50;
            break;
        case "bottomPositionMap":
            pixelsToMoveOnY = -50;
            break;
    }
    $('#imageFullScreen').smartZoom('pan', pixelsToMoveOnX, pixelsToMoveOnY);
}

/******图片放大效果 结束*******/


//图片(img标签)的onerror事件
function nofind() {
    var img = event.srcElement;
    img.src = "../img/user.png";
    img.onerror = null; //控制不要一直跳动
}

//群头像(img标签)的onerror事件
function nogroupfind() {
    var img = event.srcElement;
    img.src = "../img/group.png";
    img.onerror = null; //控制不要一直跳动
}

function nowechatfind() {
    var img = event.srcElement;
    img.src = "../img/sign03.png";
    img.onerror = null; //控制不要一直跳动
}

//报表表格拖拽
function tableSlip() {
    var tTD; //用来存储当前更改宽度的Table Cell,避免快速移动鼠标的问题
    var table = document.getElementById("tableslip");
    if (table.rows[0] == undefined) {
        return;
    }
    for (j = 0; j < table.rows[0].cells.length; j++) {
        table.rows[0].cells[j].onmousedown = function () {
            //记录单元格
            tTD = this;
            if (event.offsetX > tTD.offsetWidth - 10) {
                tTD.mouseDown = true;
                tTD.oldX = event.x;
                tTD.oldWidth = tTD.offsetWidth;
            }
            //记录Table宽度
            //table = tTD; while (table.tagName != ‘TABLE') table = table.parentElement;
            //tTD.tableWidth = table.offsetWidth;
        };
        table.rows[0].cells[j].onmouseup = function () {
            //结束宽度调整
            if (tTD == undefined) tTD = this;
            tTD.mouseDown = false;
            tTD.style.cursor = 'default';
        };
        table.rows[0].cells[j].onmousemove = function () {
            //更改鼠标样式
            if (event.offsetX > this.offsetWidth - 10)
                this.style.cursor = 'col-resize';
            else
                this.style.cursor = 'default';
            //取出暂存的Table Cell
            if (tTD == undefined) tTD = this;
            //调整宽度
            if (tTD.mouseDown != null && tTD.mouseDown == true) {
                tTD.style.cursor = 'default';
                if (tTD.oldWidth + (event.x - tTD.oldX) > 0)
                    tTD.width = tTD.oldWidth + (event.x - tTD.oldX);
                //调整列宽
                tTD.style.width = tTD.width;
                tTD.style.cursor = 'col-resize';
                //调整该列中的每个Cell
                table = tTD; while (table.tagName != 'TABLE') table = table.parentElement;
                for (j = 0; j < table.rows.length; j++) {
                    table.rows[j].cells[tTD.cellIndex].width = tTD.width;
                }
                //调整整个表
                //table.width = tTD.tableWidth + (tTD.offsetWidth – tTD.oldWidth);
                //table.style.width = table.width;
            }
        };
    }
}

//历史记录，好友档案表格拖拽
function tableHisFileSlip() {
	var tTD; //用来存储当前更改宽度的Table Cell,避免快速移动鼠标的问题
	var table = document.getElementById("tbContent");
	if (table.rows[0] == undefined) {
	    return;
	}
	for (j = 0; j < table.rows[0].cells.length; j++) {
		table.rows[0].cells[j].onmousedown = function () {
			//记录单元格
			tTD = this;
			if (event.offsetX > tTD.offsetWidth - 10) {
				tTD.mouseDown = true;
				tTD.oldX = event.x;
				tTD.oldWidth = tTD.offsetWidth;
			}
			//记录Table宽度
			//table = tTD; while (table.tagName != ‘TABLE') table = table.parentElement;
			//tTD.tableWidth = table.offsetWidth;
		};
		table.rows[0].cells[j].onmouseup = function () {
			//结束宽度调整
			if (tTD == undefined) tTD = this;
			tTD.mouseDown = false;
			tTD.style.cursor = 'default';
		};
		table.rows[0].cells[j].onmousemove = function () {
			//更改鼠标样式
			if (event.offsetX > this.offsetWidth - 10)
				this.style.cursor = 'col-resize';
			else
				this.style.cursor = 'default';
			//取出暂存的Table Cell
			if (tTD == undefined) tTD = this;
			//调整宽度
			if (tTD.mouseDown != null && tTD.mouseDown == true) {
				tTD.style.cursor = 'default';
				if (tTD.oldWidth + (event.x - tTD.oldX) > 0)
					tTD.width = tTD.oldWidth + (event.x - tTD.oldX);
				//调整列宽
				tTD.style.width = tTD.width;
				tTD.style.cursor = 'col-resize';
				//调整该列中的每个Cell
				table = tTD; while (table.tagName != 'TABLE') table = table.parentElement;
				for (j = 0; j < table.rows.length; j++) {
					table.rows[j].cells[tTD.cellIndex].width = tTD.width;
				}
				//调整整个表
				//table.width = tTD.tableWidth + (tTD.offsetWidth – tTD.oldWidth);
				//table.style.width = table.width;
			}
		};
	}
}
//文本框去除 '"
function Canceller(content) {
    return content.replace(/["]/g, '').replace(/[']/g, '');
}
