//取得小财神在线,返回包含在线/不在线图标及启动小财神的链接
//type=0   表示传入的id为用户ID
//type=1   表示传入的id为公司ID
//type=2   表示传入的id为IMID
//from代表在哪里用,具体如下:
//from=10为Search站点无搜索结果页及搜索结果页用
//from=11为Search站点列表页弹浮层用
//from=12为Search站点详细页用
//from=20为Biz站点用
//from=30为SNS站点Industry/GroupIndex.aspx页面用
//from=31为SNS站点PersonalIndex.aspx页面用
//from=40为SHOP站点(http://shop.tc.mainone.cn/)首页用
function Get_XCS_Online(id, type, from) {    
    var typename = "";
    if (type == 0) { typename = "user"; }
    if (type == 1) { typename = "product"; }
    var date = Math.round(Math.random() * 1000000);
    var strUrl = "http://search.tc.mainone.cn/ajax/IM/checkonline.xhtml?jsoncallback=?";    

    //==================================================================================================================
    if (from == 10)
    { document.write("<a id='search_a_href_offoron_10_" + date + "' title='在线洽谈'></a>"); }
    if (from == 11) {
        return;
        document.write("<span id='search_span_offoror_11_" + date + "' style='margin-left:60px;'></span>");        
    }
    if (from == 12)
    { document.write("<a class='xcs' id='search_span_offoror_12_" + date + "'></a>"); }

    //==================================================================================================================
    if (from == 20)         //启动铭万客服
    {
        document.write("<a href=javascript:MainOneStartChat(" + id + ",-1," + type + ")><img src=http://img.techcenter.mainone.cn/biz/20110527/images/online.gif /></a>");
        return;
    }        
    if (from == 40)         //启动铭万客服
    {
        document.write("<a href=javascript:MainOneStartChat(" + id + ",-1," + type + ") class='red_online'>在线客服</a>");        
        return;
    }
    if (from == 41) {
        document.write("<a href=javascript:MainOneStartChat(" + id + ",-1," + type + ") class='onlineBtn_lw'></a>");
        return;
    }
    //==================================================================================================================
    if (from == 30) {
        document.write("<li><a id='sns_li_offoron_30_" + date + "'></a></li>");
    }
    if (from == 31) {
        document.write("<li><a id='sns_li_offoron_31_" + date + "' class='p2'></a></li>");
    }
    $.ajax({
        type: "GET",
        url: strUrl,
        data: "userid=" + id + "&type=" + typename + "&type1=im&ran=" + date,
        dataType: "json",
        success: function (html) {
            if (html != null && html != "") {
                if (from == 10) {
                    {
                        /*
                        info.StockTitle = temp;         //在线(1)/离线(0)
                        info.StockUrl = strIMIDs;       //IMID
                        info.Keyword = strRan;          //对象唯一标识
                        */
                        var str = "";
                        if (html.StockTitle == "0")        //不在线
                        {
                            str = "<s class='xcsoff'></s>";
                        }
                        if (html.StockTitle == "1")        //在线
                        {
                            str = "<s class='xcson'></s>";
                        }
                        $("#search_a_href_offoron_10_" + html.Keyword).attr("href", "javascript:MainOneStartChat(" + id + "," + html.StockUrl + "," + type + ")");
                        $("#search_a_href_offoron_10_" + html.Keyword).html(str);
                    }
                }
                if (from == 30) {
                    $("#sns_li_offoron_30_" + html.Keyword).attr("href", "javascript:MainOneStartChat(" + id + "," + html.StockUrl + "," + type + ")");
                    if (html.StockTitle == "0")  //离线
                    { $("#sns_li_offoron_30_" + html.Keyword).html("<img src='http://img.techcenter.mainone.cn/SNS/20110531/images811/i-icon33.gif' alt='小财神' />"); }
                    if (html.StockTitle == "1")  //在线
                    { $("#sns_li_offoron_30_" + html.Keyword).html("<img src='http://img.techcenter.mainone.cn/SNS/20110531/images811/i-icon3.gif' alt='小财神' />"); }
                }
                if (from == 31) {
                    $("#sns_li_offoron_31_" + html.Keyword).attr("href", "javascript:MainOneStartChat(" + id + "," + html.StockUrl + "," + type + ")");
                    if (html.StockTitle == "0") {
                        $("#sns_li_offoron_31_" + html.Keyword).html("离线");
                        $("#sns_li_offoron_31_" + html.Keyword).attr("class", "p22");
                    }
                    if (html.StockTitle == "1") {
                        $("#sns_li_offoron_31_" + html.Keyword).html("在线");
                    }
                }
                if (from == 11) {
                    $("#search_span_offoror_11_" + html.Keyword).html("<a href=javascript:MainOneStartChat(" + id + "," + html.StockUrl + "," + type + ") class='orgbtn2'></a>");
                }

                if (from == 12) {
                    $("#search_span_offoror_12_" + html.Keyword).attr("href", "javascript:MainOneStartChat(" + id + "," + html.StockUrl + "," + type + ")");
                    $("#search_span_offoror_12_" + html.Keyword).html("<img src='http://img.techcenter.mainone.cn/b2b/20110609/images/ico_xcs.gif' width='77' height='18' vspace='5' alt='' />");
                }
            }
        }
    });
}

//启动聊天主窗口
function MainOneStartChat(id,imid, type) {
    //type=0   表示传入的id为用户ID
    //type=1   表示传入的id为公司ID
    //type=2   表示传入的id为IMID
    if (type == 2)
    { imid = id; }    
    if (newCheckMainOneIMInstalled()) //检查是否安装
    {        
        window.location = "MOOnline://Message/Chat?From=web&uid=" + imid + "#"
    }
    else {
        window.open("http://search.b2b.cn/common/WebTalk.php?id=" + id + "&imid=" + imid + "&type=" + type, "短信洽谈室", "left=200,top=200,width=600,height=453,menubar=no,toolbar=no,dependent=yes,chrome=yes,modal=yes");
    }
}

//检测是否安装软件
function newCheckMainOneIMInstalled() {
    //IE判断方法
    if (navigator.userAgent.indexOf("MSIE") >= 0) {
        try {
            var obj = new ActiveXObject("MOOnline.MOInstall");
            if (obj) {
                delete obj;
                return true;
            }
        }
        catch (e) { }
    }

    //火狐判断方法
    if (navigator.userAgent.indexOf("Firefox") >= 0) {
        var plugin = document.embeds[0];
        if (plugin != null)
        { return true; }
    }    
    return false;    
}
