﻿/// <reference path="jQuery.js" />
/******************************************************************/
//博客圈子共用全局变量
/******************************************************************/
var NumericButtonCount = 4;
//垃圾文件处理全局变量
var InitUploadFilesControl = "";
var FinishUploadFilesControl = "";
/****************************************************************
* 分页导航（共用）
****************************************************************/
function CreatePageNav(pageIndex, pageCount, pageScript, className) {

    var startPage = pageIndex - NumericButtonCount;
    if (startPage < 1) {
        startPage = 1;
    }
    var endPage = pageIndex + NumericButtonCount;
    if (endPage > pageCount) {
        endPage = pageCount;
    }
    var s = "";
    s = "<div width=100% align=left class='" + className + "'>";

    if (pageIndex != 1) {
        s = s + pageUrl(1, "首页", pageScript);
        s = s + pageUrl(pageIndex - 1, "上一页", pageScript);

    }

    for (var i = startPage; i <= endPage; i++) {
        if (pageIndex != i) {
            s = s + " " + pageUrl(i, i, pageScript) + " ";
        }
        else {
            s = s + " " + pageFont(i) + " ";
        }
    }
    if (pageIndex != pageCount && pageCount != 0) {

        s = s + pageUrl(pageIndex + 1, "下一页", pageScript);
        s = s + pageUrl(pageCount, "尾页", pageScript);

    }
    s = s + "</div>";

    return s;
}
function pageFont(i) {
    return "<font color=red><b>" + i + "</b></font>";
}
function pageUrl(i, explain, pageScript) {

    var script = pageScript.replace("{0}", i);
    var a;

    a = " <a href=\"javascript:void(0);\" onclick=\"javascript:" + script + "\">" + explain + "</a>";

    return a;
}

/****************************************************************
* 常用属性重写
****************************************************************/
Date.prototype.formatt = function(format) //author: meizz
{

    var o = {
        "M+": this.getMonth() + 1, //month
        "d+": this.getDate(),    //day
        "h+": this.getHours(),   //hour
        "m+": this.getMinutes(), //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    };
    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }
    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}

String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.LTrim = function() {
    return this.replace(/(^\s*)/g, "");
}
String.prototype.RTrim = function() {
    return this.replace(/(\s*$)/g, "");
}
String.prototype.IsNullOrEmpty = function() {
    if (this.LTrim().RTrim().length == 0) {
        return true;
    }
    else {
        return false;
    }
}

function $(_sId) {
    return document.getElementById(_sId);
}
/****************************************************************
* 通过JS来接收URL参数
****************************************************************/
function request(key) {
    if (typeof (this) == "undefined") return false;
    if (this.length > 0) {
        var s = this.split("&");
        for (var i in s) {
            var sp = s[i].split("=");
            if (sp[0] == key) return (sp[1]);
        }
        return false;
    }
    else return false;
}
function getAllKey() {
    if (typeof (this) == "undefined") return false;
    var arr = new Array;
    if (this.length > 0) {
        var s = this.split("&");
        for (var i in s) {
            var sp = s[i].split("=");
            arr.push(sp[0]);
        }
        return arr;
    }
    else return false;
}
String.prototype.request = request;
String.prototype.getAllKey = getAllKey;

/****************************************************************
* 通过JS实现UrlEncode和UrlDecode
****************************************************************/
function UrlEncode(str) {
    var i, temp, p, q;
    var result = "";
    for (i = 0; i < str.length; i++) {
        temp = str.charCodeAt(i);
        if (temp >= 0x4e00) {
            execScript("ascCode=hex(asc(\"" + str.charAt(i) + "\"))", "vbscript");
            result += ascCode.replace(/(.{ 2 })/g, "%$1");
        }
        else {
            result += escape(str.charAt(i));
        }
    }
    return result;
}
function UrlDecode(str) {
    var i, temp;
    var result = "";
    for (i = 0; i < str.length; i++) {
        if (str.charAt(i) == "%") {
            if (str.charAt(++i) == "u") {
                temp = str.charAt(i++) + str.charAt(i++) + str.charAt(i++) + str.charAt(i++) + str.charAt(i);
                result += unescape("%" + temp);
            }
            else {
                temp = str.charAt(i++) + str.charAt(i);
                if (eval("0x" + temp) <= 160) {
                    result += unescape("%" + temp);
                }
                else {
                    temp += str.charAt(++i) + str.charAt(++i) + str.charAt(++i);
                    result += Decode_unit("%" + temp);
                }
            }
        }
        else {
            result += str.charAt(i);
        }
    }
    return result;
}

/****************************************************************
* 控制排名层的显示与关闭

****************************************************************/
var tempLayer = null;

function showLayer(name) {

    //var layer=eval(name);
    var layer = $(name);

    if (tempLayer == null) {
        layer.innerHTML = layer.info;
        layer.style.display = "";
        tempLayer = layer;
        return;
    }
    if (tempLayer != null && tempLayer != layer) {
        tempLayer.style.display = "none";
        layer.innerHTML = layer.info;
        layer.style.display = "block";
        tempLayer = layer;
        return;
    }
    if (tempLayer == layer) {
        layer.style.display = "none";
        tempLayer = null;
        return;
    }


}


/****************************************************************
* Iframe框架自适应
****************************************************************/
function iframeAutoFit() {

    try {
        if (window != parent) {
            var a = parent.document.getElementsByTagName("IFRAME");
            for (var i = 0; i < a.length; i++) //author:meizz
            {
                if (a[i].contentWindow == window) {
                    var h1 = 0, h2 = 0;
                    a[i].parentNode.style.height = a[i].offsetHeight + "px";
                    a[i].style.height = "0px";
                    if (document.documentElement && document.documentElement.scrollHeight) {
                        h1 = document.documentElement.scrollHeight;
                    }
                    if (document.body) h2 = document.body.scrollHeight;

                    var h = Math.max(h1, h2);
                    if (document.all) { h += 0; }
                    if (window.opera) { h += 0; }
                    a[i].style.height = a[i].parentNode.style.height = h + "px";
                }
            }
        }
    }
    catch (ex) { }
}
/****************************************************************
* 参数初始化

****************************************************************/
function InitParams(param, value) {
    var aParams = new Array();
    aParams = param.split('@');
    var aParamNames = new Array();
    var length = aParams.length;

    for (var j = 0; j < length; j++) {
        var i = aParams[j].indexOf('=', 0);

        var aParam = new Array();
        aParam[0] = aParams[j].substring(0, i);
        aParam[1] = aParams[j].substring(i + 1, aParams[j].length);
        value[aParam[0]] = aParam[1];

    }
}

/******************************************************************/
//获取数据填充的DIV（主要区别于前台和后台显示）共用函数
/******************************************************************/
function GetContentDiv(aParamValues) {
    var contentDiv;
    if (aParamValues["ContentDivId"] != null) {
        contentDiv = parent.document.getElementById(aParamValues["ContentDivId"]);
    }
    else {
        contentDiv = document.getElementById(aParamValues["DataDivId"]);
    }
    if (contentDiv == null)//如果为NULL,则为本身的DIV容器
    {
        contentDiv = document.getElementById(aParamValues["DataDivId"]);
    }
    return contentDiv;
}
function InitContentDiv(aParamValues, contentDiv) {


    if (aParamValues["ContentDivId"] != null) {
        contentDiv.innerHTML = "<div id=" + aParamValues["DataDivId"] + " width='100%'>" + contentDiv.innerHTML + "</div>";
        contentDiv.parentNode.parentNode.style.height = "auto"; //为了于IE7.0兼容，所有的拖动DIV的区域高度为自动   
    }
}

/******************************************************************/
//固定列表条数
/******************************************************************/
function InitFixed(list, pageSize, isFixed) {
    //if (isFixed == "1") {
    if (true) {//暂时所有的栏目都固定条数
        for (var i = list.length; i < pageSize; i++) {
            list.push(null);
        }
    }
    return list;
}

/******************************************************************/
//获取日期格式
/******************************************************************/
function GetDateFormat(dateType, date) {
    var dateStr = "";

    switch (dateType) {
        case "1":
            dateStr = date.formatt("yyyy-MM-dd");
            break;
        case "2":
            dateStr = date.formatt("MM/dd");
            break;
        case "3":
            dateStr = date.formatt("yyyy-MM-dd hh:mm:ss");
            break;
        case "4":
            dateStr = date.formatt("hh:mm:ss");
            break;
        case "5":
            dateStr = date.formatt("MM/dd hh:mm:ss");
            break;
        default:
            dateStr = date.formatt("MM/dd");
            break;
    }
    return dateStr;
}

/******************************************************************/
//整除
/******************************************************************/
function Div(exp1, exp2) {
    var n1 = Math.round(exp1); //四舍五入
    var n2 = Math.round(exp2); //四舍五入

    var rslt = n1 / n2; //除


    if (rslt >= 0) {
        rslt = Math.floor(rslt); //返回值为小于等于其数值参数的最大整数值。

    }
    else {
        rslt = Math.ceil(rslt); //返回值为大于等于其数字参数的最小整数。

    }

    return rslt;
}

function InitJsonContent(arr) {
    arr = arr.replace("\n", "");
    arr = arr.replace("\r", "");
    arr = arr.replace("\\", "\\\\");
    arr = arr.replace("\"", "\\\"");
    arr = arr.replace("/", "\\/");
    arr = arr.replace("\'", "\\\'");
    return arr;
}

/******************************************************************/
//复制到剪贴板
/******************************************************************/
function CopyToClipboard(txt) {
    if (window.clipboardData) {
        window.clipboardData.clearData();
        window.clipboardData.setData("Text", txt);
    }
    else if (navigator.userAgent.indexOf("Opera") != -1) {
        window.location = txt;
    }
    else if (window.netscape) {
        try {
            netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
        }
        catch (e) {
            alert("您的firefox安全限制限制您进行剪贴板操作，请打开’about:config’将signed.applets.codebase_principal_support’设置为true’之后重试");
            return false;
        }
        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);
    }
}
/******************************************************************/
//收藏本页
/******************************************************************/
function BookMarkSite(title, url) {
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "")
}

function GetPosition(ATarget) {
    var left = 0;
    var top = 0;
    var el = ATarget;

    while (el != null) {
        left += el["offsetLeft"];
        top += el["offsetTop"];
        el = el.offsetParent;
    }

    return { x: left, y: top };
}


/******************************************************************/
//举报
/******************************************************************/
function SetReport(objectId, type, path) {
    openWindow('/include/SetReport.aspx?id=' + objectId + "&t=" + type, '345', '306', '我要举报', false);
}

/******************************************************************/
//查看报表结果
/******************************************************************/
function ViewSignUpResult(id, tableName, title) {
    openWindow("/OperationManage/Chart/ViewSignUpResult.aspx?sutId=" + id + "&tableName=" + tableName + "&title=" + escape(title), '600', '480', "统计图表", false);
}

/******************************************************************/
//发布讨论
/******************************************************************/
function AddCircleDiscuss(circleId, path) {
    openWindow(path + 'CircleManage/addCircleDiscuss.aspx?pkId=' + circleId, '720', '500', '发布讨论', true);
}

function GetCssWidth(parentCssName, cssName) {
    var hideDiv = document.getElementById("hideDiv");
    if (hideDiv == null) {
        hideDiv = parent.document.getElementById("hideDiv");
    }
    if (hideDiv == null) return 60;
    var parentDiv = hideDiv.parentNode;

    parentDiv.className = parentCssName;
    hideDiv.style.display = "block";
    hideDiv.className = cssName;
    var width = hideDiv.offsetWidth
    if (width == 0) {
        width = 60;
    }
    hideDiv.style.display = "none";
    return width;
}

function GetCssHeight(parentCssName, cssName) {
    var hideDiv = document.getElementById("hideDiv");
    if (hideDiv == null) {
        hideDiv = parent.document.getElementById("hideDiv");
    }
    if (hideDiv == null) return "100%";
    var parentDiv = hideDiv.parentNode;

    parentDiv.className = parentCssName;
    hideDiv.style.display = "block";
    hideDiv.className = cssName;
    var height = hideDiv.offsetHeight
    if (height == 0) {
        height = "100%";
    }
    hideDiv.style.display = "none";
    return height;

}

/******************************************************************/
//所有包含编辑器的页面都必须调用
/******************************************************************/
function ByPassCheck(id) {
    document.getElementById(id).contentWindow.bypassCheck();
}
/******************************************************************/
//按回车指定按钮
/******************************************************************/
var enter = "";
function keyDown() {
    if (event.srcElement.type == "textarea") {
        return;
    }
    if (event.keyCode == 13) {
        if (enter != "") {
            var key = document.getElementById(enter);
            key.click();
        }
        event.returnValue = false;
    }
}
function setKeyDown(id, name, focus) {
    enter = id.replace(name, "");
    enter = enter + focus;
}

/******************************************************************/
//标签自动切换JS代码
/******************************************************************/
function scifod(obj, titleDiv, contentDiv, widgetTabTitleCss, tabJsFunction) {
    scifodlist = InitWidgetTabTitleDiv(titleDiv);
    scifodInfo = InitWidgetTabContentDiv(contentDiv);
    for (i = 0; i < scifodlist.length; i++) {
        if (obj == scifodlist[i]) {
            jQuery(scifodlist[i]).removeClass().addClass("" + widgetTabTitleCss + "").addClass("TabTitle_Dis");
            jQuery(scifodInfo[i]).removeClass().addClass("dis").addClass("TabContent");            
        }
        else {
            jQuery(scifodlist[i]).removeClass().addClass("" + widgetTabTitleCss + "").addClass("TabTitle_UnDis");
            jQuery(scifodInfo[i]).removeClass().addClass("undis").addClass("TabContent");        
           
        }
    }
    try {
        eval(tabJsFunction);
    }
    catch (e) { }
}

function InitWidgetTabTitleDiv(titleDivId) {
    var counter = 0;
    var widgetTabTitleDivList = [];
    jQuery("#" + titleDivId + " div").each(function() {
        if (jQuery(this).attr("li") == "WidgetTabTitle") {
            widgetTabTitleDivList[counter] = this;
            counter++;
        }
    });
    return widgetTabTitleDivList;
}

function InitWidgetTabContentDiv(contentDivId) {
    var counter = 0;
    var widgetTabContentDivList = [];
    jQuery("#" + contentDivId + " div").each(function() {
        if (jQuery(this).attr("li") == "WidgetTabContent") {
            widgetTabContentDivList[counter] = this;
            counter++;
        }
    });   
    return widgetTabContentDivList;
}
/******************************************************************/
//设置图片自适应
/******************************************************************/
function SetPotoSize(divPhotoId, photoId) {
    var divPhoto = $(divPhotoId);

    if (divPhoto.document.getElementById(photoId) != null) {
        divPhoto.document.getElementById(photoId).style.width = "100%";
        divPhoto.document.getElementById(photoId).style.height = "100%";
    }
}

/******************************************************************/
//栏目布局后台编辑时，从iframe处copy内容（共用）
/******************************************************************/
function InitIframeData(param, dataDivId, boxCss) {

    var aParamValues = new Array();
    InitParams(param, aParamValues);
    aParamValues["DataDivId"] = dataDivId;
    var div = GetContentDiv(aParamValues);
    div.className = "clearfix " + boxCss; //整体样式

    div.innerHTML = $(dataDivId).innerHTML;
    div.parentNode.parentNode.style["overflow"] = "hidden";
    InitContentDiv(aParamValues, div);

}

function InitIframeData(param, dataDivId, boxCss, style) {
    var aParamValues = new Array();
    InitParams(param, aParamValues);
    aParamValues["DataDivId"] = dataDivId;
    var div = GetContentDiv(aParamValues);
    div.className = "clearfix " + boxCss; //整体样式
    div.style.cssText = style;
    div.innerHTML = $(dataDivId).innerHTML;
    div.parentNode.parentNode.style["overflow"] = "hidden";
    InitContentDiv(aParamValues, div);

}

/******************************************************************/
//使得在FireFox中也可以使用innerText属性

/******************************************************************/

if (navigator.userAgent.indexOf("MSIE") <= 0) {
    HTMLElement.prototype.__defineGetter__("innerText",
     function() {
         return this.textContent;
     }
     );
    HTMLElement.prototype.__defineSetter__("innerText",
     function(sText) {
         this.textContent = sText;
     }
     );
}

/******************************************************************/
//初始化类别下拉框
/******************************************************************/
function IntImageArticleCategory(cateID) {
    var cate = document.getElementById(cateID)
    var optionList = cate.getElementsByTagName("option");
    for (var i = 0; i < optionList.length; i++) {
        if (optionList[i].innerText.indexOf("[图]") > 0)
            optionList[i].style.color = "red";
    }
}


/******************************************************************/
//图片翻滚样式示意图
/******************************************************************/
var FlashStyleList = new Array();
FlashStyleList["1"] = "<img src=\"/Include/FlashScript/FlashStyle1/FlashStyle1.jpg\" width=\"80\" height=\"100\">";
FlashStyleList["2"] = "<img src=\"/Include/FlashScript/FlashStyle3/FlashStyle3.jpg\" width=\"80\" height=\"66\">";
FlashStyleList["3"] = "<img src=\"/Include/FlashScript/FlashStyle4/FlashStyle4.jpg\" width=\"80\" height=\"42\">";
FlashStyleList["4"] = "<img src=\"/Include/FlashScript/FlashStyle5/FlashStyle5.jpg\" width=\"80\" height=\"90\">";
FlashStyleList["5"] = "<img src=\"/Include/FlashScript/FlashStyle6/FlashStyle6.jpg\" width=\"80\" height=\"77\">";

function GetFlashStyle(style) {
    return FlashStyleList[style];
}

/******************************************************************/
//导航栏显示
/******************************************************************/
function ShowNav(navId, showNavId, hasChildChannel) {
    if (hasChildChannel == "1") {
        showNav = $(showNavId);
        nav = $(navId);
        showNav.innerHTML = nav.innerHTML;
    }
}

/******************************************************************/
//只能录入整数
/******************************************************************/
function IsDigit() {

    return ((event.keyCode >= 48) && (event.keyCode <= 57));

}

function IsValueNull(v) {
    if (v.Trim() == "") {
        return false;
    }
    else {
        return true;
    }
}

/******************************************************************/
//选中全部复选框　
/******************************************************************/
function CheckAll(controlId, checkAllControl) {
    var control = $(controlId);
    var nodeList = control.getElementsByTagName("input");
    for (var i = 0; i < nodeList.length; i++) {
        var node = nodeList[i];
        if (node.type == "checkbox" && !node.disabled) {
            node.checked = checkAllControl.checked;
        }
    }
}

/******************************************************************/
//关闭openWindow　
/******************************************************************/
function CloseDialog() {
    parent.document.getElementById('dialogBox').style.display = 'none';
    parent.document.getElementById('dialogBoxBG').style.display = 'none';
    parent.document.getElementById('dialogBoxShadow').style.display = "none";
}
function CloseDialog1() {
    document.getElementById('dialogBox').style.display = 'none';
    document.getElementById('dialogBoxBG').style.display = 'none';
    document.getElementById('dialogBoxShadow').style.display = "none";
}

/******************************************************************/
//转化字符为数字，默认值为0
/******************************************************************/
function ConvertToNumber(number) {
    var n = parseInt(number, 10);
    if (isNaN(n)) {
        n = 0;
    }
    return n;
}

/******************************************************************/
//定时更新在线用户
/******************************************************************/
function RefreshOnlineUser(userId, spanMessage) {

    try {
        jQuery.ajax({
            type: "POST",
            contentType: "application/json",
            data: "{ userId: '" + userId + "'}",
            dataType: "json",
            url: "/Service/CommonService.asmx/UpdateActiveUser",
            success: function(result) {
                onUpdateActiveUserForBlogSuccess(result.d, spanMessage);
            }
        });
    }
    catch (e)
    { }
}
function RefreshOnlineUserForBlog(userId, spanMessage) {

    try {
        jQuery.ajax({
            type: "POST",
            contentType: "application/json",
            data: "{ userId: '" + userId + "'}",
            dataType: "json",
            url: "/Service/ShareService.asmx/UpdateActiveUser",
            success: function(result) {
                onUpdateActiveUserForBlogSuccess(result.d, spanMessage);
            }
        });
    }
    catch (e)
    { }
}

function onUpdateActiveUserForBlogSuccess(result, spanMessage) {
    document.getElementById(spanMessage).innerText = result[0];
    if (document.getElementById(spanMessage + "t")) {
        document.getElementById(spanMessage + "t").innerText = result[0];
    }
    if (document.getElementById(spanMessage + "1")) {
        document.getElementById(spanMessage + "1").innerText = result[1];
        document.getElementById(spanMessage + "2").innerText = result[2];
    }
}

/******************************************************************/
//弹出登录框
/******************************************************************/
var IsNeedLogin = 0;
function PopLogin(fun) {
    if (fun == null) fun = "";
    openWindow('/OperationManage/PopLogin.aspx?callback=' + fun, '300', '200', '登录', true);
}
/******************************************************************/
//弹出验证码确认框
/******************************************************************/
function VerifyCode(fun) {
    if (fun == null) fun = "";
    openWindow('/OperationManage/ShowVerifyCode.aspx?callback=' + fun, '300', '200', '验证码确认', true);
}

/******************************************************************/
//大类导航点击
/******************************************************************/
function SetTopNav(navId, currentObj) {
    var left = $("left");
    var top = $("ECS_NAV");
    if (currentObj != null) {
        var objList = top.document.getElementsByTagName("li");
        for (var i = 0; i < objList.length; i++) {
            var obj = objList[i];
            if (obj.t == "top") {
                obj.className = "";
            }
        }
        currentObj.className = "navselected";
    }

    objList = left.document.getElementsByTagName("ul");
    for (var i = 0; i < objList.length; i++) {
        var obj = objList[i];
        if (obj.t == "left") {
            obj.style.display = "none";
        }
    }

    var leftNav = document.getElementById(navId);
    if (leftNav != null) {
        leftNav.style.display = "block";
    }
    var tdleft = parent.document.getElementById("tdLeft");
    if (tdleft != null) {
        tdleft.className = "ECS_L";
    }
}
/******************************************************************/
//小类导航点击
/******************************************************************/
function SetLeftNav(url, currentObj) {
    var left = $("left");
    var objList = left.document.getElementsByTagName("li");
    for (var i = 0; i < objList.length; i++) {
        var obj = objList[i];
        if (obj.t == "left") {
            obj.className = "";
        }
    }

    currentObj.className = "navselected";
    if (url.indexOf("javascript:") >= 0)//调用ＪＳ
    {
        eval(url);
    }
    else {
        var main = parent.document.getElementById("main");
        main.src = url;
    }
}


/******************************************************************/
//初始化图片所在DIV高度和宽度
/******************************************************************/
function InitDivWidthAndHeight(div, width, height) {
    var w = ConvertToNumber(width);
    var h = ConvertToNumber(height);
    if (w != 0) {
        div.style.width = w + "px";
    }
    if (h != 0) {
        div.style.height = h + "px";
    }
}

/******************************************************************/
//显示消息界面
/******************************************************************/
function ShowMessage() {
    var main = document.getElementById("main");
    main.src = "/BlogManage/Message/ManageInBoxMessage.aspx";
}

String.format = function() {

    if (arguments.length == 0) {
        return null;
    }

    var str = arguments[0];

    for (var i = 1; i < arguments.length; i++) {

        var re = new RegExp('\\{' + (i - 1) + '\\}', 'gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}

/******************************************************************/
//cookie操作
/******************************************************************/
function GetCookie(sName) {
    var aCookie = document.cookie.split(";");
    for (var i = 0; i < aCookie.length; i++) {
        var aCrumb = aCookie[i].split("=");

        if (sName.Trim() == aCrumb[0].Trim())
            return unescape(aCrumb[1].Trim());
    }
    return null;
}

function SetCookie(name, value) {
    var argv = arguments;
    var argc = arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : '/';
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;
    document.cookie = name + "=" + escape(value) +
       ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
       ((path == null) ? "" : ("; path=" + path)) +
       ((domain == null) ? "" : ("; domain=" + domain)) +
       ((secure == true) ? "; secure" : "");
}

function SetDemandCookie(videoId, obj) {

    var cookie = GetCookie("Edjoy_VideoDemand_List");
    if (cookie == null) {
        SetCookie("Edjoy_VideoDemand_List", videoId);
        jQuery(obj).unbind("mouseover").unbind("mouseout");
        obj.src = "/Images/Video/qlsed.gif";
        result += "," + videoId;
        obj.alt = "从点播单移除";
    }
    else {
        var ss = cookie.split(',');
        var result = "0";
        var isExist = 0;

        for (var i = 0; i < ss.length; i++) {
            if (ss[i] == videoId) {
                isExist = 1;
                continue;
            }
            if (ss[i] == "0") continue;
            result += "," + ss[i];
        }
        if (isExist == 1) {
            jQuery(obj).hover(function() { obj.src = "/Images/Video/qlh.gif" }, function() { obj.src = "/Images/Video/qls.gif" });
            obj.src = "/Images/Video/qls.gif";
            obj.alt = "添加到点播单";
        }
        else {
            jQuery(obj).unbind("mouseover").unbind("mouseout");
            obj.src = "/Images/Video/qlsed.gif";
            result += "," + videoId;
            obj.alt = "从点播单移除";
        }
        SetCookie("Edjoy_VideoDemand_List", result);
    }
}

function SetAllVideoDemand() {

    var cookie = GetCookie("Edjoy_VideoDemand_List");
    if (cookie == null) {
        cookie = "0";
    }
    jQuery("img[li=VideoDemand]").each(function() {
        var l = jQuery(this).parent().parent().width();
        l = l - 23;
        jQuery(this).parent().css("left", l + "px").css("bottom", "24px");
        jQuery(this).show();
        var ss = cookie.split(',');
        var isExist = 0;
        for (var i = 0; i < ss.length; i++) {
            if (ss[i] == this.v) {
                isExist = 1;
                break;
            }
        }
        if (isExist == 1) {
            this.src = "/Images/Video/qlsed.gif";
            this.alt = "从点播单移除";
        }
        else {
            jQuery(this).hover(function() { this.src = "/Images/Video/qlh.gif" }, function() { this.src = "/Images/Video/qls.gif" });
        }
    });
}

function SetAllVideoArticleImage() {

    jQuery("img[li=VideoArticleImage]").each(function() {
        jQuery(this).parent().css("left", "25px").css("bottom", "30px");
        jQuery(this).show();
    });
}

/****************************************************************/
//******自定义提交报表****************************************/


var Oxsir = {};
Oxsir.WebResear = {};
Oxsir.hasInputed = false;

//单选框、多选框
Oxsir.WebResear.CheckFormcb = function(o, id) {

    var txtbox = document.getElementById(id);
    txtbox.value = "";
    if (o && txtbox) {
        txtbox.isOperate = '1';
        var objs = document.getElementsByName(o.name);

        var flag = 0;
        for (var i = 0; i < objs.length; i++) {
            if (objs[i].checked) {
                if (flag == 0) {
                    txtbox.value = objs[i].itemName;
                    flag = 1;
                }
                else {
                    txtbox.value = txtbox.value + "|" + objs[i].itemName;
                }
            }

        }

    }
    // alert(txtbox.value);
}

//下拉框
Oxsir.WebResear.CheckFormSelect = function(o, id) {
    var txtbox = document.getElementById(id);

    if (o && txtbox) {
        txtbox.value = o.options[o.selectedIndex].text;
        txtbox.isOperate = '1';
        //   alert(txtbox.value);
    }

}

//文本框
Oxsir.WebResear.CheckFormtxb = function(o, id) {
    var txtbox = document.getElementById(id);
    if (o && txtbox) {
        txtbox.isOperate = '1';
        txtbox.value = o.value;
        // alert(txtbox.value);
    }
}



//上传文件
Oxsir.WebResear.uploadfile = function(divId, hiddenId) {
    var hidden = document.getElementById(hiddenId);
    var div = document.getElementById(divId);
    if (hidden && div) {
        hidden.isOperate = '1';
        openWindow('/Editor/UploadDataInput.aspx?rid=' + hidden.pkId + '&hiddenId=' + hiddenId + '&divId=' + divId + '&lastFilename=' + hidden.value + '&directory=UserFiles/Admin/DataInputFiles/' + hidden.tableName, '400', '110', '上传文件', true);
    }
}


Oxsir.WebResear.SetUploadInfo = function(divId, hiddenId, uploadfileName) {
    var hidden = document.getElementById(hiddenId);
    var div = document.getElementById(divId);
    if (hidden && div) {
        hidden.value = uploadfileName;
        div.innerHTML = uploadfileName;
    }
}


//时间设置

Oxsir.WebResear.SetTime = function(divId, hiddenId) {
    var hidden = document.getElementById(hiddenId);
    var div = document.getElementById(divId);

    new Calendar().show(div);

}


//数据提交
Oxsir.IsVerifyCode = false;
Oxsir.IsLogin = false;

Oxsir.CliendID = "";
Oxsir.tableName = "";
Oxsir.tableId = "";
Oxsir.signUpDataPkId = "";
Oxsir.isNeedVerify = "";
Oxsir.isAdminEdit = 0;




Oxsir.WebResear.SignUpDataInput = function(CliendID, tableName, tableId, signUpDataPkId, isNeedVerify, isAdminEdit) {

    Oxsir.CliendID = CliendID;
    Oxsir.tableName = tableName;
    Oxsir.tableId = tableId;
    Oxsir.signUpDataPkId = signUpDataPkId;
    Oxsir.isNeedVerify = isNeedVerify;
    Oxsir.isAdminEdit = isAdminEdit;

    if (IsNeedLogin == 1 && !Oxsir.IsLogin)//未登录者，而需要登录才能提交的，显示登录界面
    {
        PopLogin("Oxsir.WebResear.SetLogin");
        return;
    }
    if (isNeedVerify == 1 && !Oxsir.IsVerifyCode)//提交需要验证码
    {
        VerifyCode("Oxsir.WebResear.SetVerifyCode");
        return;
    }
    
    if (Oxsir.hasInputed) {
        //alert("不能重复提交数据！");
        _error_msg_show("不能重复提交数据", '', 'forbid', "错误");
        return;
    }

    var hiddenName = CliendID + "Hidden";
    var list = document.getElementsByName(hiddenName);

    var dataInputLists = new Array();
    var listStr = "[";
    for (var i = 0; i < list.length; i++) {
        //         alert(list[i].value);
        if (list[i].dataType == "datetime") {

            list[i].value = document.getElementById(list[i].dataId).value;

            list[i].isOperate = "1";
        }
        if (list[i].AllowNull == "0" && list[i].value.Trim() == "") {
            //alert(" “" + list[i].showName + "” 不能为空！");
            document.getElementById(list[i].dataId).focus();
            _error_msg_show(" “" + list[i].showName + "” 不能为空！", '', 'forbid', "错误");
            return;
        }
      
        if (listStr == "[") {
            listStr += "{\"_coloumName\":\"" + list[i].columnName + "\",\"_showName\":\"" + list[i].showName + "\",\"_coloumValue\":\"" + list[i].value + "\",\"_isOnly\":\"" + list[i].IsOnly + "\",\"_allowNull\":\"" + list[i].AllowNull + "\"}";
        }
        else {
            listStr += ",{\"_coloumName\":\"" + list[i].columnName + "\",\"_showName\":\"" + list[i].showName + "\",\"_coloumValue\":\"" + list[i].value + "\",\"_isOnly\":\"" + list[i].IsOnly + "\",\"_allowNull\":\"" + list[i].AllowNull + "\"}";
        }

    }

    listStr = listStr + "]";
    
    jQuery.ajax({
        type: "POST",
        contentType: "application/json",
        data: "{ tableName:'" + tableName + "', tableId:'" + tableId + "',signUpDataPkId:'" + signUpDataPkId + "',listStr:'" + listStr + "',isAdminEdit:'" + isAdminEdit + "'}",
        dataType: "json",
        url: "/Service/SystemService.asmx/SignUpDataInput",
        success: function(result) {
            Oxsir.WebResear.SignUpDataInputResult(result.d, CliendID);
        }
    });

}

//设置登录状态
Oxsir.WebResear.SetLogin = function() {
    Oxsir.IsLogin = true;
    Oxsir.WebResear.SignUpDataInput(Oxsir.CliendID, Oxsir.tableName, Oxsir.tableId, Oxsir.signUpDataPkId, Oxsir.isNeedVerify, Oxsir.isAdminEdit);
}
//设置验证码状态
Oxsir.WebResear.SetVerifyCode = function() {
    Oxsir.IsVerifyCode = true;
    Oxsir.WebResear.SignUpDataInput(Oxsir.CliendID, Oxsir.tableName, Oxsir.tableId, Oxsir.signUpDataPkId, Oxsir.isNeedVerify, Oxsir.isAdminEdit);
}

Oxsir.WebResear.SignUpDataInputResult = function(result, CliendID) {
    if (result.Result) {
        Oxsir.hasInputed = true;
        //alert("数据提交成功！");
        _error_msg_show(result.Explain, '', 'smile', "成功");


    }
    else {
        if (result.Explain == "") {
            //alert("数据提交失败！");
            _error_msg_show("不能重复提交数据", '', 'forbid', "错误");
        }
        else {
            //alert(result.Explain);
            _error_msg_show(result.Explain, '', 'forbid', "错误");
        }
    }
}

//选择上传文件改名字段

Oxsir.WebResear.EditSignUpFileNameFieldName = function(o, hiddenId) {
    var hidden = document.getElementById(hiddenId);
    hidden.value = o.options[o.selectedIndex].value;


}

//确定 修改文件名

Oxsir.WebResear.OkEditSignUpFileNameFieldName = function() {
    var list = document.getElementsByName("SystemSignUpFieldName");

    if (list.length == 0) {
        alert("没有需要改名字段！");
        return;
    }
    var question = confirm("确实要修改文件名吗？")

    if (question == "0") {
        return false;

    }
    var tableId = list[0].tableId;
    var tableName = list[0].tableName;
    var dataInputLists = new Array();

    for (var i = 0; i < list.length; i++) {
        var dataInput = new EdJoy.Web.Service.SystemSignUpEditFileNameInfo();
        dataInput.FileField = list[i].fileName;
        dataInput.SelectField = list[i].value;
        dataInputLists.push(dataInput);
    }
    document.getElementById("signupphotoProgress").style.display = "";
    EdJoy.Web.Service.SystemService.EditSignUpDataInputFileName(tableName, tableId, dataInputLists, Oxsir.WebResear.SignUpDataInputResult1, null, null);



}


Oxsir.WebResear.SignUpDataInputResult1 = function(result, CliendID) {
    if (result.Result) {
        document.getElementById("signupphotoProgress").style.display = "none";
        alert("文件名修改成功！");

    }
    else {
        if (result.Explain == "") {
            document.getElementById("signupphotoProgress").style.display = "none";
            alert("文件名修改出错，请重试！");
        }
        else {
            alert(result.Explain);
        }
    }
}



function ShowReplyDiv(containerClientId) {

    var div = $(containerClientId + "_div");
    var editor = $(containerClientId + "_editor");
    var content = $(containerClientId + "_content");
    var check = $(containerClientId + "_check");
    if (div.style.display == "block") {
        check.checked = false;
        editor.src = "";
        content.value = "";
        div.style.display = "none";
    }
    else {
        editor.src = "/editor/SimpleEweb.html?id=" + containerClientId + "_content" + "&style=standard";
        div.style.display = "block";
    }
}

function MessageForShare(t, objectId) {
    openWindow('/OperationManage/SendMessageForShare.aspx?t=' + t + '&pkId=' + objectId, '440', '350', '分享', true);
}


function SubscribeVideoAlbum(albumid) {
    openWindow('/OperationManage/Video/AddSubscribeForAlbum.aspx?albumId=' + albumid, '300', '150', '订阅专辑', true);
}

function SubscribeVideoForUser(userId) {
    openWindow('/OperationManage/Video/AddSubscribeForUser.aspx?userId=' + userId, '300', '150', '订阅用户视频', true);
}

function DownFile(name, path, url) {

    document.getElementById("path").value = path;
    document.getElementById("name").value = name;
    document.getElementById("downLoadFile").action = url + "OperationManage/DownFile.aspx";
    document.getElementById("downLoadFile").submit();
}

//数据报表中选择单位用户
function SelectUnitMemberUser(txtId)
{
    openWindow('/OperationManage/SelectSingleUser.aspx?unitMemberNameClientId=' + txtId, '400', '250', '选择用户', true);
}

//数据报表中选择单位部门
function SelectDepartment(txtId)
{
    openWindow("/OperationManage/SelectDepartment.aspx?isShow=1&departNameClientId="+txtId, 180, 250, '选择单位部门', true);
}