//经纪人信息js

//取出动态数据源基地址
//var BASEPATH= G_TGPATH;
//动态刷新间隔已分钟为单位
var REFRESHTIME = 1;
//静态刷新间隔已小时为单位
var STREFRESHTIME = 60;

var __ajax_cache = true;

//标签
var CK_JJR_LABEL_USERS = "JJR_LABEL_USERS";
//用户所属标签
var CK_JJR_USER_LABELS = "JJR_USER_LABELS";


//权限定义
var G_Rights = [];
var G_Actions = [];
var G_groups = [];
var G_users = [];
var G_broker = {};

//投顾数组
var G_brokers = [];
//营销数组
var G_managers = [];
var G_groupslable = [];
//var G_groupslable_hash=[];
var G_users_hash = [];
var G_brokers_hash = [];
var G_managers_hash = [];
var G_users_hash_name = [];
var G_brokers_hash_name = [];
var G_managers_hash_name = [];


//初始化
var xmlHttp = null;
var userinfo = [];
var result = null;
var sqsid = null; //券商编号
var sbid = null; //经济人编号
var scid = null; //经济人编号

var CK_MAIL_VERSION = "CK_MAIL_VERSION"; //邮件版本号key 值
var DATA_MAIL_SAVE_LIST = "";

//拼用户key列表
function set_key_list() {
    userinfo = getSysUser();
    sqsid = userinfo[2];
    sbid = userinfo[0];
    DATA_MAIL_SAVE_LIST = "";
    DATA_MAIL_SAVE_LIST += '[';
    DATA_MAIL_SAVE_LIST += '{"key":"MD:' + sqsid + '","nm":"数据字典"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MS:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"经纪人下用户静态数据"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MJ:1:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"经纪人下用户静态数据"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MJ:2:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"经纪人下用户静态数据"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MJ:3:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"经纪人下用户静态数据"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MK:1:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"用户详细信息"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MK:2:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"用户详细信息"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MK:3:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"用户详细信息"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MC:1:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"获取经纪人的用户列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MC:2:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"获取经纪人的用户列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MC:3:' + sqsid.toLowerCase() + ':' + sbid.toLowerCase() + '","nm":"获取经纪人的用户列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCB:1:' + sqsid.toLowerCase() + ':1","nm":"获取投顾列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCB:1:' + sqsid.toLowerCase() + ':2","nm":"获取投顾列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCB:1:' + sqsid.toLowerCase() + ':3","nm":"获取投顾列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCB:2:' + sqsid.toLowerCase() + ':1","nm":"获取投顾列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCB:2:' + sqsid.toLowerCase() + ':2","nm":"获取投顾列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCB:2:' + sqsid.toLowerCase() + ':3","nm":"获取投顾列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCB:3:' + sqsid.toLowerCase() + ':1","nm":"获取投顾列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCB:3:' + sqsid.toLowerCase() + ':2","nm":"获取投顾列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCB:3:' + sqsid.toLowerCase() + ':3","nm":"获取投顾列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCM:1:' + sqsid.toLowerCase() + ':1","nm":"获取营销列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCM:1:' + sqsid.toLowerCase() + ':2","nm":"获取营销列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCM:1:' + sqsid.toLowerCase() + ':3","nm":"获取营销列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCM:2:' + sqsid.toLowerCase() + ':1","nm":"获取营销列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCM:2:' + sqsid.toLowerCase() + ':2","nm":"获取营销列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCM:2:' + sqsid.toLowerCase() + ':3","nm":"获取营销列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCM:3:' + sqsid.toLowerCase() + ':1","nm":"获取营销列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCM:3:' + sqsid.toLowerCase() + ':2","nm":"获取营销列表"}';
    DATA_MAIL_SAVE_LIST += ',{"key":"MCM:3:' + sqsid.toLowerCase() + ':3","nm":"获取营销列表"}';
    DATA_MAIL_SAVE_LIST += ']';

    var dataobj = eval('(' + DATA_MAIL_SAVE_LIST + ')');
    return dataobj;
}
/*
*判断邮件版本，不同则删除缓存数据，同时将新版本写入缓存
*/
function checkversions() {
    var odata = client_data_load(CK_MAIL_VERSION, "0");
    if (odata != null) {
        if ((odata.dValue.replace(/\n/g, "")) != web_version) {
            var delist = set_key_list();
            for (var i = 0; i < delist.length; i++) {
                var ccc = client_data_save(delist[i].key, "0", "", "0");
            }
            client_data_save(CK_MAIL_VERSION, "1", web_version, "0");
        }
    } else {
        client_data_save(CK_MAIL_VERSION, "1", web_version, "0");
    }
}
//----------------------------------------------------
// 工具的方法
//----------------------------------------------------
function getRequest() {
    var xmlhttp = null;
    if (window.XMLHttpRequest) {
        // code for all new browsers
        xmlhttp = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        // code for IE5 and IE6
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
    }
    if (!xmlhttp) {
        throw 'request object initialize fail!';
    }
    try {
        return xmlhttp;
    } finally {
        xmlhttp = null;
    }
}


//+---------------------------------------------------
//| 动态网页ajax加载 同步加载 并作2次尝试
//+---------------------------------------------------
function ajax_load_sync(url) {
    var req = getRequest();
    var callURL = ajax_url_random(url);
    req.open('GET', callURL, false);
    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    try {
        req.send(null);
    }
    catch (e) {
        url = null;
        req = null;
        return "";
    }
    if (req.status != 200) {
        req.open("GET", callURL, false);
        req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        try {
            req.send(null);
        }
        catch (e) {
            url = null;
            req = null;
            return "";
        }
    }
    var data = req.responseText;
    callURL = null;
    req = null;
    return data;
}

//+---------------------------------------------------
//| 动态网页ajax加载 同步加载 并作2次尝试
//+---------------------------------------------------
function ajax_load_sync_post(url, tmpdata) {
    var req = getRequest();
    var callURL = tmpdata + '&_rand=' + Math.random();
    req.open('POST', url, false);
    req.setRequestHeader("contentType", "text/html;charset=uft-8") //指定发送的编码
    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    try {
        req.send(callURL);
    }
    catch (e) {
        url = null;
        req = null;
        return "";
    }
    if (req.status != 200) {
        req.open("POST", url, false);
        req.setRequestHeader("contentType", "text/html;charset=uft-8") //指定发送的编码
        req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        try {
            req.send(callURL);
        }
        catch (e) {
            url = null;
            req = null;
            return "";
        }
    }
    var data = req.responseText;
    callURL = null;
    req = null;
    return data;
}
//+---------------------------------------------------
//| ajax加载，并缓存到客户端
//+---------------------------------------------------
function ajax_load_cache_sync(url) {
    var callURL = ajax_url_random(url);
    var cachedata = null;
    if (__ajax_cache) {
        cachedata = ajax_url_cache_get(url);
    }
    var req = getRequest();
    req.open('GET', callURL, false);
    req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    if (__ajax_cache) {
        req.setRequestHeader(
			'If-Modified-Since',
			cachedata === null ? 'Thu, 01 Jan 1970 00:00:00 GMT' : cachedata['expire']
		);
    }
    try {
        req.send(null);
    }
    catch (e) {
        url = null;
        req = null;
        return "";
    }
    var data = "";

    if (req.status == 200) {
        if (__ajax_cache) {
            data = req.responseText;
            ajax_url_cache_set(url, req.getResponseHeader('Last-Modified'), data);
        }
    }
    else if (req.status == 304) {
        data = cachedata['text'];
        req = null;
    }
    else {
        data = "";
    }
    callURL = null;
    cachedata = null;
    req = null;
    return data;
}

//+---------------------------------------------------   
//| 获取客户端保存的字符串数据
//| 说明：只取从客户端读到数据的文本部分
//+---------------------------------------------------   
function getClientData(keyName) {
    var data = getClientDataWithTime(keyName);
    try {
        if (data === null) {
            return null;
        }
        if (typeof (data.dValue) === 'undefined') {
            return null;
        }
        return data.dValue;
    } finally {
        data = null;
    }
}

//+---------------------------------------------------   
//| 获取客户端保存的数据对象
//| 说明：取到的数据是一个对象，其格式：{TimeStamp: Date, dValue: 保存的数据}
//+---------------------------------------------------   
function getClientDataWithTime(keyName) {
    if (typeof (client_data_load) === 'undefined') {
        return null;
    }
    return client_data_load(keyName, 0);
}

//+---------------------------------------------------
//| 静态文件缓存
//+---------------------------------------------------

function ajax_cache_enable() {
    __ajax_cache = true;
}

function ajax_cache_disable() {
    __ajax_cache = false;
}

function ajax_url_cache_key(url) {
    var pos = url.lastIndexOf('/');
    var l_url = url.substr(pos + 1);

    pos = l_url.indexOf('.');
    if (pos > 0) {
        l_url = l_url.substr(0, pos);
    }
    try {
        return 'w_' + l_url;
    } finally {
        pos = null;
        l_url = null;
    }
}

function ajax_url_cache_get(url) {
    var dataobj = {};
    var key = ajax_url_cache_key(url);
    var dvalue = getClientData(key);
    try {
        if (dvalue === null) {
            return null;
        }
        try {
            var dataobj = eval('(' + dvalue + ')');
            return dataobj;
        }
        catch (e) {
            return null;
        }
    } finally {
        dvalue = null;
        key = null;
        dataobj = null;
    }
}

function ajax_url_cache_set(url, expire, text) {
    var key = ajax_url_cache_key(url);
    client_data_save(key, "1", "{\"expire\":\"" + expire.toString() + "\",\"text\":\"" + text.replace(/\"/g, "\\\"") + "\"}", "0");
    key = null;
}

function ajax_url_random(url) {
    if (url.indexOf('?') > 0) {
        url += '&_rand=' + Math.random();
    }
    else {
        url += '?_rand=' + Math.random();
    }
    return url;
}




//基本数据字典
function loadBaseData() {
    set_key_list(); ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    userinfo = null;
    var odata = client_data_load("MD:" + sqsid.toLowerCase(), "0");
    if (odata != null) {
        var now = new Date();
        var df = (now.getTime() - odata.TimeStamp.getTime()) / 60 / 1000;
        if (df < STREFRESHTIME) {
            try {
                result = eval('(' + odata.dValue + ')');
            }
            catch (e) {
                result = null;
            }
            odata = null;
            return result;
        }
    }
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    var url = G_TGPATH() + "/inter/qursysset.do?qsid=" + sqsid.toLowerCase();
    var data = ajax_load_sync(url);
    client_data_save("MD:" + sqsid.toLowerCase(), "1", data, "0");
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

//获取经纪人的用户的静态数据
function loadStaticData() {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    scid = userinfo[0];
    userinfo = null;
    var odata = client_data_load("MS:" + sqsid.toLowerCase() + ":" + scid.toLowerCase(), "0");
    if (odata != null) {
        var now = new Date();
        var df = (now.getTime() - odata.TimeStamp.getTime()) / 60 / 1000;
        if (df < REFRESHTIME) {
            try {
                result = eval('(' + odata.dValue + ')');
            }
            catch (e) {
                result = {};
            }
            odata = null;
            try {
                return result;
            } finally {
                result = null;
            }
        }
    }
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    var url = rdata + "/file/subBroker.do?bid=" + scid.toLowerCase() + "&qsid=" + sqsid.toLowerCase();
    var data = ajax_load_cache_sync(url);
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    client_data_save("MS:" + sqsid.toLowerCase() + ":" + scid.toLowerCase(), "1", data, "0");
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

//获取用户的经纪人列表
//type=1全部,2名字id
function loadData(type) {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    scid = userinfo[0];
    userinfo = null;
    var odata = client_data_load("MJ:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + scid.toLowerCase(), "0");
    if (odata != null) {
        var now = new Date();
        var df = (now.getTime() - odata.TimeStamp.getTime()) / 60 / 1000;
        if (df < REFRESHTIME) {
            try {
                result = eval('(' + odata.dValue + ')');
            }
            catch (e) {
                result = null;
            }
            odata = null;
            try {
                return result;
            } finally {
                result = null;
            }
        }
    }
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //var url = rdata +"/inter/qurbrokerlist.do?qsid=" + sqsid.toLowerCase() + "&cid=" + scid.toLowerCase() + "&type=" + type;
    //var data = ajax_load_sync(url);	
    //client_data_save("MJ:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + scid.toLowerCase(),"1",data,"0");

    //var url = "http://192.168.3.188:8299/investAnalysisPlate/inter/qurbrokerlist.do?qsid=" + sqsid.toLowerCase() + "&cid=" + scid.toLowerCase() + "&type=" + type+"&st=1";
    var url = rdata + "/inter/qurbrokerlist.do?qsid=" + sqsid.toLowerCase() + "&cid=" + scid.toLowerCase() + "&type=" + type + "&st=1";
    //var url = "http://localhost:8080/investAnalysisPlate/inter/qurbrokerlist.do?qsid=" + sqsid.toLowerCase() + "&cid=" + scid.toLowerCase() + "&type=" + type;
    var data = ajax_load_sync(url);

    client_data_save("MJ:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + scid.toLowerCase(), "1", data, "0");
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

//获取经纪人权限列表
//type=3 //经纪人权限
function loadBrokerRight(type, Refreshflg) {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    sbid = userinfo[0];
    userinfo = null;
    var url = G_TGPATH() + "/inter/qurbroker.do?qsid=" + sqsid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&type=" + type;
    var data = ajax_load_sync(url);
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

//获取用户详细信息
//type=3
function loadCustomerBase(type, Refreshflg) {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    sbid = userinfo[0];
    userinfo = null;
    if (Refreshflg == false) {
        var odata = client_data_load("MK:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + sbid.toLowerCase(), "0");
        if (odata != null) {
            var now = new Date();
            var df = (now.getTime() - odata.TimeStamp.getTime()) / 60 / 1000;
            if (df < REFRESHTIME) {
                try {
                    result = eval('(' + odata.dValue + ')');
                }
                catch (e) {
                    result = null;
                }
                odata = null;
                try {
                    return result;
                } finally {
                    result = null;
                }
            }
        }
    }
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    var url = rdata + "/inter/qurcustomer.do?qsid=" + sqsid.toLowerCase() + "&cid=" + sbid.toLowerCase() + "&type=" + type;
    var data = ajax_load_sync(url);
    client_data_save("MK:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + sbid.toLowerCase(), "1", data, "0");
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

//获取经纪人的用户列表
//type=1全部,2名字id,3盯盘
function loadCustomer(type, qsid, bid) {
    result = null;
    sqsid = qsid;
    sbid = bid;
    if (qsid == null || qsid == "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过检查本地缓存
    {
        userinfo = getSysUser();
        sqsid = userinfo[2];
        sbid = userinfo[0];
        userinfo = null;
        var odata = client_data_load("MC:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + sbid.toLowerCase(), "0");
        if (odata != null) {
            var now = new Date();
            var df = (now.getTime() - odata.TimeStamp.getTime()) / 60 / 1000;
            if (df < REFRESHTIME) {
                try {
                    result = eval('(' + odata.dValue + ')');
                }
                catch (e) {
                    result = null;
                }
                odata = null;
                try {
                    return result;
                } finally {
                    result = null;
                }
            }
        }
    }
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    var url = rdata + "/inter/qurcustomerlist.do?qsid=" + sqsid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&type=" + type.toLowerCase();
    //	if(type=="4")
    //	{
    //	url="http://192.168.3.188:9021/investAnalysisPlate//inter/qurcustomerlist.do?qsid=55556&bid=zhouyb888&type=4";
    //	}
    var data = ajax_load_sync(url);
    if (qsid == null || qsid == "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过保存本地缓存
    {
        client_data_save("MC:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + sbid.toLowerCase(), "1", data, "0");
    }
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}
/*
*检查短期权限
*/
function checkRightShort(cid, procuids) {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    sbid = userinfo[0];
    userinfo = null;
    var url = G_TGPATH() + "/inter/checksprdt.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&cid=" + cid.toLowerCase() + "&pid=" + procuids.toLowerCase();
    var data = ajax_load_sync_post(url, tmpdata);
    if (data == "") {
        result = "";
    }
    else {
        try {
            result = eval('(' + data + ')').scd;
        }
        catch (e) {
            url = null;
            result = "";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}
/*
*设置短期权限
*/
function setRightShort(cid, procuids, seq,sc) {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    sbid = userinfo[0];
    userinfo = null;
    var url = G_TGPATH() + "/inter/sprdtcus.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&cid=" + cid.toLowerCase() + "&pid=" + procuids.toLowerCase() + "&mid=" + seq.toLowerCase() + "&sc=" + sc ;
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = "";
    }
    else {
        try {
            result = eval('(' + data + ')').scd;
        }
        catch (e) {
            url = null;
            result = "";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}


/*
*分配试用权限
*参数：qsid:劵商ID,bid:经纪人ID; cid:客户ID1,客户ID2; pid:服务包ID1,服务包ID2;返回数据：
*/
function SetTrialRight(cid, procuids) {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    sbid = userinfo[0];
    userinfo = null;
    var url = G_TGPATH() + "/inter/trycus.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&cid=" + cid.toLowerCase() + "&pid=" + procuids.toLowerCase();
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = "";
    }
    else {
        try {
            result = eval('(' + data + ')').scd;
        }
        catch (e) {
            url = null;
            result = "";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}
/*
*产品中心分配试用权限（产品中心新增4类模板）
*参数：qsid:劵商ID,bid:经纪人ID; cid:客户ID1,客户ID2; pid:服务包ID1,服务包ID2 t:产品类型;sdate:开始时间；edate：结束时间；返回数据：
*/
function SetTrialRightProductCenter(cid, procuids,ct,sdate,edate) {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    sbid = userinfo[0];
    userinfo = null;
    var url = G_TGPATH() + "/inter/trycuspc.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&cid=" + cid.toLowerCase() + "&pid=" + procuids.toLowerCase() +"&t=" + ct +"&s=" + sdate + "&e=" + edate;
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = "";
    }
    else {
        try {
            result = eval('(' + data + ')').scd;
        }
        catch (e) {
            url = null;
            result = "";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

/*
*分配长期权限
*/
function SetProcus(cid, procuids, procuidates) {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    sbid = userinfo[0];
    var url = null;
    url = G_TGPATH() + "/inter/procus.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&cid=" + cid.toLowerCase() + "&pid=" + procuids.toLowerCase() + "&deli=" + procuidates.toLowerCase();
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = null
    }
    else {
        try {
            result = eval('(' + data + ')').scd;
        }
        catch (e) {
            url = null;
            result = null;
        }
    }
    try {
        return result;
    } finally {
        url = null;
        result = null;
    }
}


//返回权限定义，静态数据
function load_Base() {
    var BaseData = loadBaseData();
    G_Rights = {};
    if (BaseData == null) {
        return;
    }
    var i = 0;
    if (typeof (BaseData.p) == "object") {
        G_Rights = BaseData.p;
        for (var key in BaseData.p) {
            G_Rights[key].img = key + ".gif";
            i++;
        }
    }
    i = 0;
    G_Actions = [];
    for (var key in BaseData.a) {
        G_Actions[i] = {};
        G_Actions[i].id = key;
        G_Actions[i].name = BaseData.a[key].nm;
        i = i + 1;
    }
    i = null;
    BaseData = null;
}

//获取当前登录用户信息
function getSysUser() {
    var obj = client_core_interface();
    var ret = f_client_call("G_SYS_UserName", "");
    try {
        ret = ret.toLowerCase();
        return ret.split("\r\n");
    } finally {
        ret = null;
        obj = null;
    }
}

//返回经纪人JSON数据
function load_BrokerData(type) {
    var G_Broker_All = {}; //所有经纪人信息	
    G_Broker_All = loadData(type); //读取json数据	
    return G_Broker_All;
}

//返回客户JSON数据
function load_CustomerData(type, qsid, bid) {
    setcustomerkeyboard(); //获取只能键盘需要数据，并注册
    var Customer_All = {}; //所有经纪人信息	
    Customer_All = loadCustomer(type, qsid, bid); //读取json数据	
    try {
        return Customer_All;
    } finally {
        Customer_All = null;
    }
}

//返回经纪人权限数据
function load_AllBrokerRight(type, Refreshflg) {
    G_broker = {}; //经纪人权限信息	
    G_broker = loadBrokerRight(type, Refreshflg); //读取json数据	
    return G_broker;
}

function padLeft(str, lenght) {
    if (str.length >= lenght) {
        return str;
    }
    else {
        return padLeft("0" + str, lenght);
    }
}
/*加载所有客户信息数组
*/
function load_AllUsers() {
    G_users = [];
    G_users_hash = [];
    G_users_hash_name = [];

    var users = load_CustomerData("4", "", "");
    var StaticData = loadStaticData();
    G_users = users;
    var user_groups = load_users_groups();
    for (var i = G_users.length - 1; i >= 0; i--) {
        if (typeof (StaticData[G_users[i].id]) != "undefined") {
            G_users[i].interactLvl = typeof (StaticData[G_users[i].id].interactLvl) != "undefined" ? StaticData[G_users[i].id].interactLvl : "0";
            if (typeof (StaticData[G_users[i].id].act) != "undefined") {
                G_users[i]["act"] = StaticData[G_users[i].id].act;
            }

            //////			if (typeof(user_groups[G_users[i].id]) != "undefined")
            //////			{
            //////				G_users[i]["group"] = user_groups[G_users[i].id];
            //////			}


            if (typeof (G_users[i]["label"]) != "undefined") {
                G_users[i]["group"] = G_users[i]["label"];
            }
        }
        else {
            G_users[i].interactLvl = "0";
        }
        var tmpqp = "";
        var reString = GetOrderList(G_users[i].nm);
        var tmp1 = reString.split("|");
        for (var jj = 0; jj < tmp1.length; jj++) {
            var tmp2 = tmp1[jj].split(",");
            tmpqp += padLeft(tmp2[1], 5);
        }
        G_users[i].qp = tmpqp;
        G_users[i].type = "customer";
        G_users_hash[G_users[i].id] = G_users[i];
        G_users_hash_name[G_users[i].nm] = G_users[i].id;
    }
    try {
        return G_users;
    } finally {
        user_groups = null;
        StaticData = null;
        users = null;
    }
}

function load_groups() {
    G_groups = [];
    //	var odata = client_data_load(CK_JJR_LABEL_USERS,"0");
    var odata = load_jjr_lable_userinfo();
    if (odata != null) {
        try {
            //	G_groups = eval('('+ odata.dValue +')');
            G_groups = eval('(' + odata + ')');
        }
        catch (e) {
            G_groups = [];
        }
    }
    try {
        return G_groups;
    } finally {
        odata = null;
    }
}

function load_users_groups() {
    var result = {};
    var odata = client_data_load(CK_JJR_USER_LABELS, "0");
    if (odata != null) {
        try {
            result = eval('(' + odata.dValue + ')');
        }
        catch (e) {
            result = {};
        }
    }
    try {
        return result;
    } finally {
        odata = null;
        result = null;
    }
}


/*加载所有投顾信息数组
*/
function load_AllBrokers() {
    G_brokers = [];
    G_brokers_hash = [];
    G_brokers_hash_name = [];

    //	var users = loadBrokers("4","","");
    var users = loadBrokers("2", "3", "", "");
    var StaticData = loadStaticData();
    G_brokers = users;
    //	var user_groups = load_users_groups();
    for (var i = G_brokers.length - 1; i >= 0; i--) {
        if (typeof (StaticData[G_brokers[i].id]) != "undefined") {
            G_brokers[i].interactLvl = typeof (StaticData[G_brokers[i].id].interactLvl) != "undefined" ? StaticData[G_users[i].id].interactLvl : "-";
            if (typeof (StaticData[G_brokers[i].id].act) != "undefined") {
                G_brokers[i]["act"] = StaticData[G_brokers[i].id].act;
            }
            //			if (typeof(user_groups[G_brokers[i].id]) != "undefined")
            //			{
            //				G_brokers[i]["group"] = user_groups[G_brokers[i].id];
            //			}
        }
        else {
            G_brokers[i].interactLvl = "-";
        }
        var tmpqp = "";
        var reString = GetOrderList(G_brokers[i].nm);
        var tmp1 = reString.split("|");
        if (tmp1 != "") {
            for (var jj = 0; jj < tmp1.length; jj++) {
                var tmp2 = tmp1[jj].split(",");
                tmpqp += padLeft(tmp2[1], 5);
            }
        } else {
            tmpqp = "";
        }
        G_brokers[i].qp = tmpqp;
        G_brokers[i].type = "broker";
        G_brokers_hash[G_brokers[i].id] = G_brokers[i];
        G_brokers_hash_name[G_brokers[i].nm] = G_brokers[i].id;

    }
    try {
        return G_brokers;
    } finally {
        //		user_groups = null;
        StaticData = null;
        users = null;
    }
}

/*加载所有营销信息数组
*/
function load_AllManagers() {
    G_managers = [];
    G_managers_hash = [];
    G_managers_hash_name = [];
    var users = loadManagers("2", "2", "", "");
    var StaticData = loadStaticData();
    G_managers = users;
    //	var user_groups = load_users_groups();
    for (var i = G_managers.length - 1; i >= 0; i--) {
        if (typeof (StaticData[G_managers[i].id]) != "undefined") {
            G_managers[i].interactLvl = typeof (StaticData[G_managers[i].id].interactLvl) != "undefined" ? StaticData[G_managers[i].id].interactLvl : "-";
            if (typeof (StaticData[G_managers[i].id].act) != "undefined") {
                G_managers[i]["act"] = StaticData[G_managers[i].id].act;
            }
            //			if (typeof(user_groups[G_managers[i].id]) != "undefined")
            //			{
            //				G_managers[i]["group"] = user_groups[G_managers[i].id];
            //			}
        }
        else {
            G_managers[i].interactLvl = "-";
        }
        var tmpqp = "";
        var reString = GetOrderList(G_managers[i].nm);
        var tmp1 = reString.split("|");
        if (tmp1 != "") {
            for (var jj = 0; jj < tmp1.length; jj++) {
                var tmp2 = tmp1[jj].split(",");
                tmpqp += padLeft(tmp2[1], 5);
            }
        }
        else {
            tmpqp = "";
        }
        G_managers[i].qp = tmpqp;
        G_managers[i].type = "manager";
        G_managers_hash[G_managers[i].id] = G_managers[i];
        G_managers_hash_name[G_managers[i].nm] = G_managers[i].id;

    }
    try {
        return G_managers;
    } finally {
        //		user_groups = null;
        StaticData = null;
        users = null;
    }
}

/*加载所有分组信息数组
*/
function load_AllGroupsLable() {
    G_groupslable = [];
    //	G_groupslable_hash=[];
    G_groupslable = [{ "id": "_broker_", "nm": "全部投顾", "ol": "0", "fc": "Q", "qp": "quanbutougu", "interactLvl": "-", "type": "group", "num": "0" }, { "id": "_manager_", "nm": "全部客户经理", "ol": "0", "fc": "Q", "qp": "quanbukehujingli", "interactLvl": "-", "type": "group", "num": "0" }, { "id": "_customer_", "nm": "全部股民", "ol": "0", "fc": "Q", "qp": "quanbugumin", "interactLvl": "-", "type": "group", "num": "0"}];
    G_groupslable[0].num = typeof (G_brokers.length) != "undefined" ? G_brokers.length : "0";
    G_groupslable[1].num = typeof (G_managers.length) != "undefined" ? G_managers.length : "0";
    G_groupslable[2].num = typeof (G_users.length) != "undefined" ? G_users.length : "0";

    var tmpgroups = load_groups();
    for (var i = 0; i < tmpgroups.length; i++) {
        var tmpobject = { "id": "", "nm": "", "ol": "0", "fc": "-", "qp": "-", "interactLvl": "-", "num": "0" };
        tmpobject.id = "_" + tmpgroups[i].id + "_";
        tmpobject.nm = tmpgroups[i].name;
        tmpobject.ol = "0";
        tmpobject.fc = "-";
        tmpobject.qp = "-";
        tmpobject.interactLvl = "-";
        tmpobject.type = "group";
        tmpobject.num = tmpgroups[i].users.length;
        tmpobject.users = tmpgroups[i].users;
        G_groupslable.push(tmpobject);
    }
    try {
        return G_groupslable;
    } finally {
        tmpgroups = null;
    }
}



/*
*获取所有投顾列表
*type=1全部,2名字id,3盯盘
*/

function loadBrokers(type, st, qsid, bid) {
    result = null;
    sqsid = qsid;
    sbid = bid;
    if (qsid == null || qsid == "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过检查本地缓存
    {
        userinfo = getSysUser();
        sqsid = userinfo[2];
        sbid = userinfo[0];
        userinfo = null;
        var odata = client_data_load("MCB:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + st.toLowerCase(), "0");
        if (odata != null) {
            var now = new Date();
            var df = (now.getTime() - odata.TimeStamp.getTime()) / 60 / 1000;
            if (df < REFRESHTIME) {
                try {
                    result = eval('(' + odata.dValue + ')');
                }
                catch (e) {
                    result = null;
                }
                odata = null;
                try {
                    return result;
                } finally {
                    result = null;
                }
            }
        }
    }
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //http://192.168.3.188:8299/investAnalysisPlate/inter/qurbrokerlist.do?qsid=8888&type=2&st=2
    var url = rdata + "/inter/qurbrokerlist.do?qsid=" + sqsid.toLowerCase() + "&st=" + st.toLowerCase() + "&type=" + type.toLowerCase();
    var data = ajax_load_sync(url);
    if (qsid == null || qsid == "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过保存本地缓存
    {
        client_data_save("MCB:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + st.toLowerCase(), "1", data, "0");
    }
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

/*
*获取所有投顾列表
*type=1全部,2名字id,3盯盘
*/

function loadManagers(type, st, qsid, bid) {
    result = null;
    sqsid = qsid;
    sbid = bid;
    if (qsid == null || qsid == "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过检查本地缓存
    {
        userinfo = getSysUser();
        sqsid = userinfo[2];
        sbid = userinfo[0];
        userinfo = null;
        var odata = client_data_load("MCM:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + st.toLowerCase(), "0");
        if (odata != null) {
            var now = new Date();
            var df = (now.getTime() - odata.TimeStamp.getTime()) / 60 / 1000;
            if (df < REFRESHTIME) {
                try {
                    result = eval('(' + odata.dValue + ')');
                }
                catch (e) {
                    result = null;
                }
                odata = null;
                try {
                    return result;
                } finally {
                    result = null;
                }
            }
        }
    }
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //http://192.168.3.188:8299/investAnalysisPlate/inter/qurbrokerlist.do?qsid=8888&type=2&st=3
    var url = rdata + "/inter/qurbrokerlist.do?qsid=" + sqsid.toLowerCase() + "&st=" + st.toLowerCase() + "&type=" + type.toLowerCase();
 
    var data = ajax_load_sync(url);
    if (qsid == null || qsid == "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过保存本地缓存
    {
        client_data_save("MCM:" + type.toLowerCase() + ":" + sqsid.toLowerCase() + ":" + st.toLowerCase(), "1", data, "0");
    }
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}
/*
*更新所有投顾信息在线状态
*/
function Update_AllBrokers_online() {
    var G_brokers_hash_ol = [];
    var tmpusers = loadBrokersorManagers_online("2", "3", "", "");
    for (var i = tmpusers.length - 1; i >= 0; i--) {
        G_brokers_hash_ol[tmpusers[i].id] = tmpusers[i];
    }
    for (var i = G_brokers.length - 1; i >= 0; i--) {
        if (typeof (G_brokers_hash_ol[G_brokers[i].id]) != "undefined") {
            if (typeof (G_brokers_hash_ol[G_brokers[i].id].ol) != "undefined") {
                G_brokers[i].ol = G_brokers_hash_ol[G_brokers[i].id].ol;
            }
        }
    }
    tmpusers = null;
    G_brokers_hash_ol = null;
}

/*
*更新所有营销信息在线状态
*/
function Update_AllManagers_online() {
    var G_managers_hash_ol = [];
    var tmpusers = loadBrokersorManagers_online("2", "2", "", "");
    for (var i = tmpusers.length - 1; i >= 0; i--) {
        G_managers_hash_ol[tmpusers[i].id] = tmpusers[i];
    }
    for (var i = G_managers.length - 1; i >= 0; i--) {
        if (typeof (G_managers_hash_ol[G_managers[i].id]) != "undefined") {
            if (typeof (G_managers_hash_ol[G_managers[i].id].ol) != "undefined") {
                G_managers[i].ol = G_managers_hash_ol[G_managers[i].id].ol;
            }
        }
    }
    tmpusers = null;
    G_managers_hash_ol = null;
}
/*
*更新所有客户信息数组
*/
function Update_AllUsers_online() {
    var G_users_hash_ol = [];
    var tmpusers = loadCustomer_online("3", "", "");
    for (var i = tmpusers.length - 1; i >= 0; i--) {
        G_users_hash_ol[tmpusers[i].id] = tmpusers[i];
    }
    for (var i = G_users.length - 1; i >= 0; i--) {
        if (typeof (G_users_hash_ol[G_users[i].id]) != "undefined") {
            if (typeof (G_users_hash_ol[G_users[i].id].ol) != "undefined") {
                G_users[i].ol = G_users_hash_ol[G_users[i].id].ol;
            }
        }
    }
    tmpusers = null;
    G_users_hash_ol = null;

}

/*
*刷新当前投顾在线状态信息
*type=1全部,2名字id,3盯盘
*/
function loadBrokersorManagers_online(type, st, qsid, bid) {
    result = null;
    sqsid = qsid;
    sbid = bid;
    if (qsid == null || qsid == "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过检查本地缓存
    {
        userinfo = getSysUser();
        sqsid = userinfo[2];
        sbid = userinfo[0];
        userinfo = null;
    }
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //http://192.168.3.188:8299/investAnalysisPlate/inter/qurbrokerlist.do?qsid=8888&type=2&st=2
    var url = rdata + "/inter/qurbrokerlist.do?qsid=" + sqsid.toLowerCase() + "&st=" + st.toLowerCase() + "&type=" + type.toLowerCase();
    var data = ajax_load_sync(url);
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}
/*
*获取经纪人的用户列表在线状态
*/
function loadCustomer_online(type, qsid, bid) {
    result = null;
    sqsid = qsid;
    sbid = bid;
    if (qsid == null || qsid == "") //如果传入的券商ID不为空则认为直接从远程获取信息，跳过检查本地缓存
    {
        userinfo = getSysUser();
        sqsid = userinfo[2];
        sbid = userinfo[0];
        userinfo = null;
    }
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    var url = rdata + "/inter/qurcustomerlist.do?qsid=" + sqsid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&type=" + type.toLowerCase();
    var data = ajax_load_sync(url);
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

function loadMailList_online(tmpseqs, reply) {
    result = null;
    userinfo = getSysUser();
    sqsid = userinfo[2];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //	rdata = "http://192.168.3.188:9032/investAnalysisPlate/";
    var url = rdata + "/mail/mailList.do?qsid=" + sqsid.toLowerCase() + "&r=" + reply;
    var tmpdata = "seqs=" + tmpseqs;
    var data = ajax_load_sync_post(url, tmpdata);
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

function loadMailInfo_online(seq) {
    result = null;
    userinfo = getSysUser();
    sqsid = userinfo[2];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //	rdata = "http://192.168.3.188:9032/investAnalysisPlate/";
    var url = rdata + "/mail/mailInfo.do?qsid=" + sqsid.toLowerCase();
    var tmpdata = "seq=" + seq;
    var data = ajax_load_sync_post(url, tmpdata);
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}


function getUserSign() {
    result = null;
    userinfo = getSysUser();
    var sqsid = userinfo[2];
    var account = userinfo[0];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //	rdata = "http://192.168.3.188:9032/investAnalysisPlate2/";
    var url = rdata + "/sign/get.do?qsid=" + sqsid.toLowerCase() + "&account=" + account.toLowerCase() + "&type=1";
    var data = ajax_load_sync(url);
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

function saveUserSign(SignText) {
    userinfo = getSysUser();
    result = null;
    var sqsid = userinfo[2];
    var account = userinfo[0];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //	rdata = "http://192.168.3.188:9032/investAnalysisPlate2/";
    var url = rdata + "/sign/save.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&account=" + account.toLowerCase() + "&name=签名&sign=" + encodeURIComponent(SignText) + "&type=1";
    tmpdata = tmpdata.replace(/%20/g, "+");
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = "";
    }
    else {
        try {
            result = eval('(' + data + ')').scd;
        }
        catch (e) {
            url = null;
            result = "";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

function addRemark(RemarkText, cid) {
    userinfo = getSysUser();
    result = null;
    var sqsid = userinfo[2];
    var account = userinfo[0];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //	rdata = "http://192.168.3.188:9021/investAnalysisPlate/";
    var url = rdata + "/inter/instRemarks.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&bid=" + account.toLowerCase() + "&cid=" + cid.toLowerCase() + "&ct=" + encodeURIComponent(RemarkText);
    tmpdata = tmpdata.replace(/%20/g, "+");
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = "";
    }
    else {
        try {
            result = eval('(' + data + ')').scd;
        }
        catch (e) {
            url = null;
            result = "";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

/*
*获取经纪人标签信息
*/
function load_jjr_lable_userinfo() {
    result = null;

    userinfo = getSysUser();
    var sqsid = userinfo[2];
    var sbid = userinfo[0];
    userinfo = null;

    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    var url = rdata + "/inter/qurLabel.do?qsid=" + sqsid.toLowerCase() + "&bid=" + sbid.toLowerCase();
    //	url="http://192.168.3.188:9021/investAnalysisPlate/inter/qurLabel.do?qsid=55556&bid=zhouyb888";
    var data = ajax_load_sync(url);
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = data;
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

/*
*设置智能键盘数据源
*/
function setcustomerkeyboard() {
    var tmpCustomerData = loadCustomer("2", "", "");
    var tmpdata = "";
    if (typeof (tmpCustomerData) != "undefined" && tmpCustomerData.length > 0) {
        for (var i = tmpCustomerData.length - 1; i >= 0; i--) {
            if (typeof (tmpCustomerData[i].id) != "undefined" && typeof (tmpCustomerData[i].nm) != "undefined") {
                tmpdata += tmpCustomerData[i].id + "," + tmpCustomerData[i].nm + "\r\n";
            }
            else {
                tmpdata = "";
            }
        }
        MSG_SYS_REGSMARTKB(tmpdata);
    }
}


/*
*待办事项处理结果
修改接口：
http://192.168.3.87:8080/investAnalysisPlate/inter/updateTask.do
参数：qsid=55555&id=3&s=2012-12-21&e=2012-12-22&st=1&bid=xuexq888&t=1&msg=fafdfsfdfs
说明：
t:1为处理
qsid:券商ID，必须
id:待办事项ID，必须taskid
s:使用期限（开始时间）格式为 yyyy-MM-dd HH:mm:ss
e:使用期限（结束时间）
bid:客户经理ID
msg:留言
*/
function updateTask(taskid, t, stime, etime, msg) {
    userinfo = getSysUser();
    result = null;
    var sqsid = userinfo[2];
    var sbid = userinfo[0];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //	rdata="http://192.168.3.56:8080/investAnalysisPlate/";
   // rdata = "http://192.168.3.87:9020/investAnalysisPlate/";
    var url = rdata + "/inter/updateTask.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&id=" + taskid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&t=" + t.toLowerCase() + "&msg=" + encodeURIComponent(msg) + "&s=" + stime + "&e=" + etime;
    tmpdata = tmpdata.replace(/%20/g, "+");
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = "-1";
    }
    else {
        try {
            result = data;
        }
        catch (e) {
            url = null;
            result = "-1";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}
/*
*待办事项批量处理结果
修改接口：
http://192.168.3.87:8080/investAnalysisPlate/inter/batchupdateTask.do
参数：qsid=55555&ids=3&s=2012-12-21&e=2012-12-22&st=1&bid=xuexq888&t=1&msg=fafdfsfdfs
说明：
t:1为处理
qsid:券商ID，必须
ids:待办事项ID，必须taskid
s:使用期限（开始时间）格式为 yyyy-MM-dd HH:mm:ss
e:使用期限（结束时间）
bid:客户经理ID
msg:留言
*/
function batchupdateTask(taskid, t, stime, etime, msg) {
    userinfo = getSysUser();
    result = null;
    var sqsid = userinfo[2];
    var sbid = userinfo[0];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    //	rdata="http://192.168.3.56:8080/investAnalysisPlate/";
   // rdata = "http://192.168.3.87:9020/investAnalysisPlate/";
    var url = rdata + "/inter/batchUpdateTask.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&ids=" + taskid.toLowerCase() + "&bid=" + sbid.toLowerCase() + "&t=" + t.toLowerCase() + "&msg=" + encodeURIComponent(msg) + "&s=" + stime + "&e=" + etime;
    tmpdata = tmpdata.replace(/%20/g, "+");
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = "-1";
    }
    else {
        try {
            result = data;
        }
        catch (e) {
            url = null;
            result = "-1";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}
/*
*
新增接口
URL:http://192.168.3.87:9020/investAnalysisPlate/inter/saveTask.do
参数：qsid=55555&cid=xuexq666&pid=1&mid=1&st=0&bid=xuexq888&msg=fafdfsfdfs
说明：
qsid:券商ID，必须
cid:客户ID，必须
pid:产品ID，必须
mid:邮件ID
st:状态 可不填
bid:客户经理ID，必须
msg:留言
*/
function createTask(bid, pid, msg) {
    userinfo = getSysUser();
    result = null;
    var sqsid = userinfo[2];
    var scid = userinfo[0];
    var mid = "";
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
  //  rdata = "http://192.168.3.87:9020/investAnalysisPlate/";
    //	rdata="http://192.168.3.56:8080/investAnalysisPlate/";
    var url = rdata + "/inter/saveTask.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&cid=" + scid.toLowerCase() + "&pid=" + pid.toLowerCase() + "&msg=" + encodeURIComponent(msg) + "&bid=" + bid.toLowerCase() + "&mid=" + mid.toLowerCase();
    tmpdata = tmpdata.replace(/%20/g, "+");
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = "-1";
    }
    else {
        try {
            result = data;
        }
        catch (e) {
            url = null;
            result = "-1";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}
/*
*
修改代办事项邮件ID
URL:http://192.168.3.87:9020/investAnalysisPlate/inter/updateTask.do
参数：qsid=55555&id=3&mid=333333
说明：
qsid:券商ID，必须
id:待办事项ID，必须
mid:邮件ID，必须
返回值跟新增接口一样

*/
function updateTaskmail(taskid, mid) {
    userinfo = getSysUser();
    result = null;
    var sqsid = userinfo[2];
    var scid = userinfo[0];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
 //   rdata = "http://192.168.3.87:9020/investAnalysisPlate/";
    var url = rdata + "/inter/updateTask.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&id=" + taskid.toLowerCase() + "&mid=" + mid.toLowerCase();
    tmpdata = tmpdata.replace(/%20/g, "+");
    var data = ajax_load_sync_post(url, tmpdata);
    if (data == "") {
        result = "-1";
    }
    else {
        try {
            result = data;
        }
        catch (e) {
            url = null;
            result = "-1";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

/*
*
查询待办事项状态
URL:http://192.168.3.87:9020/investAnalysisPlate/inter/getTaskstatus.do
参数：qsid=55555&tid=3
说明：
qsid:券商ID，必须
tid:待办事项ID，必须
返回值为0：未办 1：已办  -1：已删除或出错

*/
function getTaskstatus(taskid) {
    userinfo = getSysUser();
    result = null;
    var sqsid = userinfo[2];
    var scid = userinfo[0];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
   // rdata = "http://192.168.3.87:9020/investAnalysisPlate/";
    var url = rdata + "/inter/getTaskStatus.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&tid=" + taskid.toLowerCase();
 
    tmpdata = tmpdata.replace(/%20/g, "+");
    var data = ajax_load_sync_post(url, tmpdata);
    if (data == "") {
        result = "-1";
    }
    else {
        try {
            result = data;
        }
        catch (e) {
            url = null;
            result = "-1";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}

/*
*阅读邮件判断帐号 类型 
*type=1 //经纪人权限
* return  0 未知 ，1 投顾或营销 ，2 客户 
*/
function getUsersRoleState(checkID) {
    userinfo = getSysUser();
    RoleObj = null;
    sqsid = userinfo[2];
   // sbid = userinfo[0];
    userinfo = null;
    var result="0";
    var url = G_TGPATH() + "/inter/qurbroker.do?qsid=" + sqsid.toLowerCase() + "&bid=" + checkID.toLowerCase() + "&type=1";
    var data = ajax_load_sync(url);
    if (data == "") {
        result = "0";
    }
    else {
        try {
            RoleObj = eval('(' + data + ')');
            if (typeof (RoleObj.id) != "undefined") {
            	result = "1";
            }else{
            	result = "2";
            }
        }
        catch (e) {
            url = null;
            RoleObj = {};
            result = "0";
        }
    }
    try {
        return result;
    } finally {
        RoleObj = null;
        data = null;
        url = null;
    }
}


/*
*待办事项批量更新 更新处理邮件id
修改接口：
http://192.168.3.87:8080/investAnalysisPlate/inter/batchupdateTask.do
参数：qsid=55555&ids=3&s=2012-12-21&e=2012-12-22&st=1&bid=xuexq888&t=1&msg=fafdfsfdfs
说明：
r:1为更新邮件
qsid:券商ID，必须
ids:待办事项ID，必须taskid
mid:邮件id
*/
function batchupdateTask_mail(taskid,mid) {
    userinfo = getSysUser();
    result = null;
    var sqsid = userinfo[2];
    var sbid = userinfo[0];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    var url = rdata + "/inter/batchUpdateTask.do";
    var tmpdata = "qsid=" + sqsid.toLowerCase() + "&ids=" + taskid.toLowerCase() + "&r=1&mid=" + mid.toLowerCase();
    tmpdata = tmpdata.replace(/%20/g, "+");
    var data = ajax_load_sync_post(url, tmpdata);
    //	var data = ajax_load_sync(url);
    if (data == "") {
        result = "-1";
    }
    else {
        try {
            result = data;
        }
        catch (e) {
            url = null;
            result = "-1";
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}
/*
*跳转到待办事项
*//*
function gototaskpage(pid)
{
	userinfo = getSysUser();  
    var sqsid = userinfo[2];
    var sbid = userinfo[0];
    userinfo = null;
	var url = G_TGPATH() + "/productCenter/initAt.do";
	url += "?qsid="+sqsid.toLowerCase()+"&bid="+sbid.toLowerCase()+"&pid="+ pid;
	openMain(url);


}*/


/*
*获取产品简要信息
*pid:产品id,type : 1（详细）2（简要）
*返回格式：{"pid":"产品ID","pname":"产品名称","bid":"投顾帐号"，"status":"上下架状态","type":"产品类型"}
*请求1http://192.168.3.87:9020/investAnalysisPlate/inter/getProduct.do?qsid=55555&pid=01008 以后要扩展的话加参数
*/
function getProdInfo(pid,ctype) {
    result = null;
    userinfo = getSysUser();
    var sqsid = userinfo[2];
//    var account = userinfo[0];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    var url = rdata + "/inter/getProduct.do?qsid=" + sqsid.toLowerCase() + "&pid=" + pid + "&type="+ctype;
    var data = ajax_load_sync(url);
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}


//获取单个用户详细信息
//type=3
function loadCustomeroneinfo(tcid) {
    userinfo = getSysUser();
    result = null;
    sqsid = userinfo[2];
    userinfo = null;
    var rdata = G_TGPATH();
    if (rdata == "") {
        return {};
    }
    var url = rdata + "/inter/qurcustomer.do?qsid=" + sqsid.toLowerCase() + "&cid=" + tcid.toLowerCase() + "&type=3";
    var data = ajax_load_sync(url);    
    if (data == "") {
        result = {};
    }
    else {
        try {
            result = eval('(' + data + ')');
        }
        catch (e) {
            url = null;
            result = {};
        }
    }
    try {
        return result;
    } finally {
        result = null;
        data = null;
        url = null;
    }
}