﻿//防止ASP.NET中URL传参数乱码
function escapecnurl(url) {
    var newurl, arrurl;
    if (typeof (url) == "undefined" || url == "") {
        return url;
    }
    else {
        if (url.indexOf("?") == -1) {
            newurl = url;
        }
        else {
            newurl = url.substring(0, url.indexOf("?") + 1);
            arrurl = url.substring(url.indexOf("?") + 1).split("&");
            for (var i = 0; i < arrurl.length; i++) {
                newurl += arrurl[i].split("=")[0] + "=" + escape(arrurl[i].split("=")[1]) + "&";
            }
            newurl = newurl.substring(0, newurl.length - 1);
        }
    }
    return newurl;
}
//打开指定页面的通用函数
function openpage(url, w, h, form) {
    if (isSpace(form)) {
        form = '';
    }
    var frm = window.open(escapecnurl(url), form, "scrollbars=yes, status=no, menubar=no ,resizable=1" + ",width=" + w + ",height=" + h + ",left=" + (window.screen.availWidth - w) / 2 + ",top=" + (window.screen.availHeight - h) / 2);
    frm.focus();
}
function openpage1(url, w, h, form) {
    if (isSpace(form)) {
        form = '';
    }
    var reg = new RegExp("-", "g");
    form = form.replace(reg, "_");
    var frm = window.open(escapecnurl(url), form, "scrollbars=no, status=no, menubar=no ,resizable=1" + ",width=" + w + ",height=" + h + ",left=" + (window.screen.availWidth - w) / 2 + ",top=" + (window.screen.availHeight - h) / 2);
    frm.focus();
}
function openpagefull(url, form, empname) {
    if (isSpace(form)) {
        form = '';
    }
    if (isSpace(empname)) {
        empname = '';
    }
    var frm = window.open(escapecnurl(url), form, "scrollbars=yes, status=yes, menubar=no ,resizable=1" + ",width=" + (window.screen.availWidth - 10) + ",height=" + (window.screen.availHeight - 50) + ",left=0,top=0");
    if (empname != '') {
        frm.window.status = '当前用户：' + empname;
    }
    frm.focus();
}
function openpagefull1(url, form, empname) {
    if (isSpace(form)) {
        form = '';
    }
    if (isSpace(empname)) {
        empname = '';
    }
    var frm = window.open(escapecnurl(url), form, "scrollbars=no, status=yes, menubar=no ,resizable=1" + ",width=" + (window.screen.availWidth - 10) + ",height=" + (window.screen.availHeight - 50) + ",left=0,top=0");
    if (empname != '') {
        frm.window.status = '当前用户：' + empname;
    }
    frm.focus();
}

//显示人员基本信息，在该页面中可进行对该人员的消息发送等操作
function EmpView(EmpID) {
    openpage("/iOffice/prg/mr/mrEmpView.aspx?empid=" + EmpID, 780, 660, "EmpView" + EmpID);
}
//远程人员信息
function rtEmpView(rtEmpID) {
    openpage1("/iOffice/prg/rt/mr/rtmrEmpBase.aspx?rtempid=" + rtEmpID, 700, 580, "rtEmpView" + rtEmpID);
}

//----------------------------------------常用操作开始-------------------------------------------
//发送手机短信
//mobile--姓名<手机号码>（用逗号分隔）,cont-要发送手机短信的内容
function SendMobile(mobile, cont) {
    openpage1("/iOffice/prg/if/ifMobileInfAdd.aspx?closed=1&mobile=" + mobile + "&cont=" + cont, 550, 550);
}

//发送即时消息
//EmpIDs--人员ＩＤ(用逗号分隔)
function SendInsInf(EmpIDs, cont) {
    openpage1("/iOffice/prg/set/SysEmp/ssInsInfAdd.aspx?closed=1&empids=" + EmpIDs + "&cont=" + cont, 620, 450);
}
//发送即时消息
//EmpIDs--人员ＩＤ(用逗号分隔)
function rtSendInsInf(rtEmpIDs, cont) {
    openpage1("/iOffice/prg/rt/set/rtssInsInfAdd.aspx?closed=1&rtempids=" + rtEmpIDs + "&cont=" + cont, 620, 450);
}

//发送传真
//rec--姓名<传真号码>(用逗号分隔)
function SendFax(rec) {
    openpage("/iOffice/prg/fax/faxSendEdit.aspx?closed=1&rec=" + rec, 600, 550);
}

//发送即时消息
//email--姓名<邮件地址>(用逗号分隔)
function SendMail(email) {
    openpage("/iOffice/prg/ml/mailnew.aspx?closed=1&email=" + email, 700, 650);
}

//打开对话窗口
function OpenChatMsg(chatid) {
    openpage1("/iOffice/prg/if/ifChatMsg.aspx?chatid=" + chatid, 600, 580);
}
//打开对话窗口
function rtOpenChatMsg(rtchatid) {
    openpage1("/iOffice/prg/rt/if/rtifChatMsg.aspx?rtchatid=" + rtchatid, 600, 580);
}

//----------------------------------------常用操作结束--------------------------------------------


//-------------------------------------标准化的人员、部门、通讯簿、客户、基本设置字典数据等选取------------------------------
//================================================选取人员===================================
//-------------------参数说明-----------------------------------------
//seltype--选取类型，用于邮件、短信等特殊选取人员时使用，一般可以为空,mobile,fax,email
//multsel-'确定是否只允许选取单个人员或多个人员或“所有人员”，0-只能单选,1-为可以选取多个人员,2-可以选取“所有人员”的特殊人员
//nameid-用于接收已选人员姓名的控件clientid
//valueid-用于接收已选人员EmpID的控件clientid
//clickid-用于产生事件控件clientid
//selempid-已选人员EmpIDID
//rightcode-范围控制码
//返回的所选人员姓名与EmpID值，均以","分隔

function SelEmp(seltype, multsel, nameid, valueid, clickid, selempid, rightcode) {
    if (isSpace(nameid)) {
        nameid = '';
    }
    if (isSpace(valueid)) {
        valueid = '';
    }
    if (isSpace(clickid)) {
        clickid = '';
    }
    if (isSpace(selempid)) {
        selempid = '';
    }
    if (isSpace(rightcode)) {
        rightcode = '';
    }
    openpage1("/iOffice/prg/set/ioPage/SelEmp.aspx?seltype=" + seltype + "&multsel=" + multsel + "&clickid=" + clickid + "&nameid=" + nameid + "&valueid=" + valueid + "&selempid=" + selempid + '&rightcode=' + rightcode, 600, 520, "SelEmp");
}
function rtSelEmp(seltype, multsel, nameid, valueid, clickid, rtselempid, rightcode) {
    if (isSpace(nameid)) {
        nameid = '';
    }
    if (isSpace(valueid)) {
        valueid = '';
    }
    if (isSpace(clickid)) {
        clickid = '';
    }
    if (isSpace(rtselempid)) {
        rtselempid = ''
    }
    if (isSpace(rightcode)) {
        rightcode = '';
    }
    openpage1("/iOffice/prg/rt/com/rtSelEmp.aspx?seltype=" + seltype + "&multsel=" + multsel + "&clickid=" + clickid + "&nameid=" + nameid + "&valueid=" + valueid + "&rtselempid=" + rtselempid + '&rightcode=' + rightcode, 600, 520, "rtSelEmp");
}

//================================================选取部门===================================
//-------------------参数说明-----------------------------------------
//seltype--选取类型，用于邮件、短信等特殊选取人员时使用，一般可以为空
//multsel-'确定是单选还是多选
//nameid-用于接收已选人员姓名的控件clientid
//valueid-用于接收已选部门编码DepID的控件clientid
//clickid-用于产生事件控件clientid

function SelDep(multsel, nameid, valueid, clickid, seldepid, mustsel) {
    if (isSpace(nameid)) {
        nameid = '';
    }
    if (isSpace(valueid)) {
        valueid = '';
    }
    if (isSpace(clickid)) {
        clickid = '';
    }
    if (isSpace(seldepid)) {
        seldepid = '';
    }
    if (isSpace(mustsel)) {
        mustsel = '';
    }
    openpage1("/iOffice/prg/set/ioPage/SelDep.aspx?multsel=" + multsel + "&clickid=" + clickid + "&nameid=" + nameid + "&valueid=" + valueid + "&seldepid=" + seldepid + "&mustsel=" + mustsel, 600, 480, "SelDep");
}

//================================================选取通讯簿===================================
//-------------------参数说明-----------------------------------------
//seltype--选取类型，用于邮件、短信等特殊选取人员时使用，一般可以为空
//nameid-用于接收已选人员姓名的控件clientid
function SelCommBook(seltype, nameid) {
    openpage1("/iOffice/prg/set/ioPage/SelCommBook.aspx?seltype=" + seltype + "&nameid=" + nameid, 600, 440, "SelCommBook");
}

//================================================选取客户信息===================================
//-------------------参数说明-----------------------------------------
//seltype--选取类型，用于邮件、短信等特殊选取人员时使用，一般可以为空
//nameid-用于接收信息的控件clientid
function SelFriend(seltype, nameid) {
    openpage1("/iOffice/prg/icrm/friend/crmselfriend.aspx?name=" + nameid + "&click=&mode=crm&id=" + "&type=" + seltype, 500, 480, "SelFriend");
}

//================================================选取基本设置字典数据============================
//txtBox-接收信息的控件clientid
//table-表名
//IDFieldName-ID字段名
//ValueFieldName-值字段名
//SortIDFieldName-排序字段名
function SelBase(txtBox, table, IDFieldName, ValueFieldName, SortIDFieldName) {
    openpage("/iOffice/prg/set/ioPage/SelBase.aspx?name=" + txtBox + "&table=" + table + "&IDFieldName=" + IDFieldName + "&ValueFieldName=" + ValueFieldName + "&SortIDFieldName=" + SortIDFieldName, 400, 500, "SelBase");
}

//=================================================选取通用字典数据==========================================
//mode-模块编码
//name-用于接收信息的控件clientid
function SelBaseDic(mode, name) {
    openpage("/iOffice/prg/set/iocom/ioDictionary.aspx?type=sel&amp;mode=" + mode + "&amp;name=" + name, 450, 500, "SelBaseDic");
}
//------------------------------------标准化的人员、部门、通讯簿、客户、基本设置字典数据等选取结束---------------------------------------------------------------------------------------------------------------


//打开到存档页面中
//----------------------------------------------------------------------------------------------
function savetoarc(Type, id) {
    openpage("/iOffice/prg/arc/arcSelKind.aspx?type=" + Type + "&id=" + id, 680, 520, "SaveToArc");
}
//---------------------------------------------------------------------------

//用于在DataGrid实现全选---------------------------------------------------
function All() {
    var whichIt = event.srcElement;
    while (whichIt.tagName.indexOf("FORM") == -1) {
        whichIt = whichIt.parentElement;
        if (whichIt == null) { return true; }
    }

    var length = whichIt.elements.length;

    var tocheck = whichIt.SelAll.checked;

    for (var i = 0; i < length; i++) {
        if (whichIt.elements[i].name != null) {
            if (whichIt.elements[i].name.indexOf("dgd") != -1 || whichIt.elements[i].name.indexOf("dg") != -1)
                if (whichIt.elements[i].name.indexOf("chk") != -1)
                if (whichIt.elements[i].disabled == false) {
                whichIt.elements[i].checked = tocheck;
            }
        }
    }
    return;
}

function SetAll() {
    var whichIt = event.srcElement;
    while (whichIt.tagName.indexOf("FORM") == -1) {
        whichIt = whichIt.parentElement;
        if (whichIt == null) { return true; }
    }
    if (1 == whichIt.SelAll.checked) {
        whichIt.SelAll.checked = 0;
    }
    else {
        whichIt.SelAll.checked = 1;
    }

    All()
    return;
}
//用于在DataGrid实再全选结束
//------------------------------------------------------------------------
//用JavaScript操作COOKIE---------------------------------------------------
function SetCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = "; expires=" + date.toGMTString();
    }
    else expires = "";
    document.cookie = name + "=" + value + expires + "; path=/";
}

function GetCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function isSpace(strMain) {
    var strComp = strMain
    try {
        if (strComp == "　" || strComp == "" || strComp == " " || strComp == null || strComp.length == 0 || typeof strMain == "undefined" || strMain == "undefined") {
            return true;
        }
        else {
            return false;
        }
    } catch (e) { return false; }
}

//用JavaScript操作COOKIE结束
//--------------------------------------------------------------------------------------------

//密码强度
//-------------------------------------------------------------------------------------------
var PasswordStrength = {
    Level: ["1", "0"],
    LevelValue: [20, 0], //强度值
    Factor: [2, 3, 2, 4], //字符加数,分别为小写字母，大写字母，数字，其它
    KindFactor: [0, -5, 10, 20, 25], //密码含几种组成的加数 
    Regex: [/[a-z]/g, /[A-Z]/g, /\d/g, /[^a-zA-Z0-9]/g] //字符正则数字正则其它正则
}
PasswordStrength.StrengthValue = function(pwd) {
    var strengthValue = 0;
    var ComposedKind = 0;
    for (var i = 0; i < this.Regex.length; i++) {
        var chars = pwd.match(this.Regex[i]);
        if (chars != null) {
            strengthValue += chars.length * this.Factor[i];
            ComposedKind++;
        }
    }
    strengthValue += this.KindFactor[ComposedKind];
    if (ComposedKind > 2) {
        return 2;
    } else {
        for (var i = 0; i < this.LevelValue.length; i++) {
            if (strengthValue >= this.LevelValue[i])
                return this.Level[i];
        }
    }
}
//-------------------------------------------------------------------------------------------

//--------------------------------------------------------------------------------------------
function closewin() {
    window.opener = null;
    window.open("", "_self");
    window.close();
    location.replace("/ioffice/DeskTop.aspx");
}

//---------------------------将文本替换为Html格式字符串----------------
function TextToHtml(sText) {
    sText = sText.replace(/\r\n/g, '<br>');
    sText = sText.replace(/[ ]/g, "&nbsp;");

    return sText;
}

//-------------------------------------------------------base64开始------------------------------------------
var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

function base64encode(str) {
    var out, i, len;
    var c1, c2, c3;

    len = str.length;
    i = 0;
    out = "";
    while (i < len) {
        c1 = str.charCodeAt(i++) & 0xff;
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt((c1 & 0x3) << 4);
            out += "==";
            break;
        }
        c2 = str.charCodeAt(i++);
        if (i == len) {
            out += base64EncodeChars.charAt(c1 >> 2);
            out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
            out += base64EncodeChars.charAt((c2 & 0xF) << 2);
            out += "=";
            break;
        }
        c3 = str.charCodeAt(i++);
        out += base64EncodeChars.charAt(c1 >> 2);
        out += base64EncodeChars.charAt(((c1 & 0x3) << 4) | ((c2 & 0xF0) >> 4));
        out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >> 6));
        out += base64EncodeChars.charAt(c3 & 0x3F);
    }
    return out;
}

function utf16to8(str) {
    var out, i, len, c;

    out = "";
    len = str.length;
    for (i = 0; i < len; i++) {
        c = str.charCodeAt(i);
        if ((c >= 0x0001) && (c <= 0x007F)) {
            out += str.charAt(i);
        } else if (c > 0x07FF) {
            out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
            out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        } else {
            out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
            out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
        }
    }
    return out;
}

//------------------------------------------------base64结束------------------------------------------------------

//----------------------------------------------Listbox获取选中的最后一个------------------------------------------
function getLstLastSel(oListbox) {
    var index = 0;
    for (var i = 0; i < oListbox.options.length; i++) {
        if (oListbox.options[i].selected) {
            index = i;
        }
    }
    return index;
}

//--------------------------------------------Listbox获取选中的最后一个结束----------------------------------------

function changeorder(Forward, grid, lblSelectedIndex, msg1, msg2) {
    var control;
    var Rowcount;
    var SelectedCount;
    var SelectedIndex;
    control = window.document.all(grid.replace(/\$/g, '_')).tBodies[0];
    Rowcount = control.children.length - 1;
    SelectedCount = 0;

    for (var i = 0; i < Rowcount; i++)
        if (control.children[i + 1].bgColor == '#ccddee') {
        SelectedCount += 1;
        SelectedIndex = i;
    }

    if (SelectedCount == 0) alert(msg1);
    if (SelectedCount > 1) alert(msg2);
    if (SelectedCount != 1) return;

    var clickControl;
    var controlIndex = SelectedIndex + 2;
    if (controlIndex < 10)
        clickControl = grid + '$ctl0' + controlIndex.toString(10);
    else
        clickControl = grid + '$ctl' + controlIndex.toString(10);

    var hidden = window.document.all(lblSelectedIndex);

    if (Forward == 0) {
        clickControl += '$cmdUp';
        hidden.value = SelectedIndex - 1;
    }
    else {
        clickControl += '$cmdDown';
        hidden.value = SelectedIndex + 1;
    }

    __doPostBack(clickControl, '');

}

var IsSubmittingSign;
IsSubmittingSign = false;


//---------------------------------------折叠-----------------------------------------------------------
function RequestByPost(empid, fold, mode) {
    var data;
    data = '<?xml version="1.0" encoding="utf-8"?>';
    data = data + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">';
    data = data + '<soap:Body>';
    data = data + '<SaveFoldCookies xmlns="http://tempuri.org/">';
    data = data + '<empid>' + empid + '</empid>';
    data = data + '<fold>' + fold + '</fold>';
    data = data + '<mode>' + mode + '</mode>';
    data = data + '</SaveFoldCookies>';
    data = data + '</soap:Body>';
    data = data + '</soap:Envelope>';
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    var URL = "/iOffice/prg/set/wss/ioCtlSet.asmx";
    xmlhttp.Open("POST", URL, true);
    xmlhttp.SetRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlhttp.SetRequestHeader("SOAPAction", "http://tempuri.org/SaveFoldCookies");
    xmlhttp.Send(data);
}


function iofoldset(obj, mode, empid, tableid, str1, str2) {
    var ftable = document.getElementById(tableid);
    var src = obj.children.tags('img')[0].src;
    ss = src.substring(src.length - 5, src.length - 4);
    if (ss == 'o') {
        obj.children.tags('img')[0].src = '/iOffice/img/idt_tle_c.gif';
        obj.title = str1;
        if (ftable != null) { ftable.style.display = 'block'; }
        RequestByPost(empid, 1, mode);
    }
    else {
        obj.children.tags('img')[0].src = '/iOffice/img/idt_tle_o.gif';
        obj.title = str2;
        if (ftable != null) { ftable.style.display = 'none'; }
        RequestByPost(empid, 0, mode);
    }
}
//---------------------------------------折叠-----------------------------------------------------------

//增加常用日程
function OpenCustom(cdate, src) {
    var frm1 = window.open("/iOffice/prg/cp/cpSchCustomSel.aspx?CDate=" + cdate + "&src=" + src, "custom", "scrollbars=yes status=not menubar=no resizable=0,width=450,height=560");
    l = (window.screen.availWidth - 450) / 2;
    t = (window.screen.availHeight - 580) / 2;
    frm1.window.moveTo(l, t);
    frm1.window.resizeTo(450, 580);
    frm1.focus();
}
//打开版本更新说明
function openupdate() {
    var newwin = window.open("/iOffice/prg/set/SysEmp/ssUpateInfo.aspx", "update", "location=no,scrollbars=yes menubar=no,status=yes,width=700,height=" + (screen.availHeight - 120) + " ,left=" + (screen.availWidth - 700) / 2 + " ,top=20");
    newwin.focus();
}

//打开关于
function openAbout() {
    openpage1("/iOffice/About.aspx", 520, 480, "openAbout")
}

//---------------------------------------首页webpart开始------------------------------------------------------------------------
function InitwpMenu(wpClientID, wpzoneClientID) {
    var obj = new WebPartMenu(document.getElementById(wpClientID + "Verbs"), document.getElementById(wpClientID + "VerbsPopup"), document.getElementById(wpClientID + "VerbsMenu"));
    obj.itemStyle = "border:1px solid #fff; background:#fff;color:black;white-space:nowrap;font-size:12px;";
    obj.itemHoverStyle = "border:1px solid #000;background:WhiteSmoke;text-decoration:underline;color: red;white-space:nowrap;font-size:12px;";
    obj.labelHoverColor = "";
    obj.labelHoverClassName = wpzoneClientID + "_Menu_0";
}
function scroll_webpart(n, wpid) {
    temp = n;
    document.getElementById("div_" + wpid).scrollTop = document.getElementById("div_" + wpid).scrollTop + temp;
    if (n == 0) return false;
    setTimeout("scroll_webpart(temp,'" + wpid + "')", 150);
}
//---------------------------------------首页webpart结束------------------------------------------------------------------------

