function URLEncode(Str){
    if (Str == null || Str == "") {
        return "";
    }
    var newStr = "";
    function toCase(sStr){
        return sStr.toString(16).toUpperCase();
    };
    for (var i = 0, icode, len = Str.length; i < len; i++) {
        icode = Str.charCodeAt(i);
        if (icode < 0x10) {
            newStr += "%0" + icode.toString(16).toUpperCase();
        }
        else 
            if (icode < 0x80) {
                if (icode == 0x20) {
                    newStr += "+";
                }
                else 
                    if ((icode >= 0x30 && icode <= 0x39) || (icode >= 0x41 && icode <= 0x5A) || (icode >= 0x61 && icode <= 0x7A)) {
                        newStr += Str.charAt(i);
                    }
                    else {
                        newStr += "%" + toCase(icode);
                    }
            }
            else 
                if (icode < 0x800) {
                    newStr += "%" + toCase(0xC0 + (icode >> 6));
                    newStr += "%" + toCase(0x80 + icode % 0x40);
                }
                else {
                    newStr += "%" + toCase(0xE0 + (icode >> 12));
                    newStr += "%" + toCase(0x80 + (icode >> 6) % 0x40);
                    newStr += "%" + toCase(0x80 + icode % 0x40);
                }
    }
    return newStr;
};
if (!UT) 
    var UT = {};
UT.JSONRequest = function(url, id, onload, onerror){
    this.url = url;
    this.onload = onload;
    this.onerror = onerror ? onerror : this.defaultError;
    this.init(url, id);
};
UT.JSONRequest.prototype = {
    init: function(url, id){
        this.script = document.createElement("script");
        this.script.setAttribute("type", "text/javascript");
        this.script.setAttribute("src", url);
        if (id) 
            this.script.setAttribute("id", id);
        document.getElementsByTagName("head")[0].appendChild(this.script);
        var request = this;
        if (this.script) {
            if (document.all) {
                var script = this.script;
                this.script.onreadystatechange = function(){
                    var state = script.readyState;
                    if (state == "loaded" || state == "interactive" || state == "complete") {
                        request.onload.call(request);
                    }
                };
            }
            else {
                this.script.onload = function(){
                    request.onload.call(request);
                };
            }
        }
        else {
            request.onerror.call(this);
        }
    },
    defaultError: function(){
        alert("\u521b\u5efa\u8282\u70b9\u5931\u8d25!\u8bf7\u4f7f\u7528\u6d4f\u89c8\u5668\u4fee\u590d\u5de5\u5177\u4fee\u590d!");
    }
};
UT.addEvent = function(element, eventName, eventFunction){
    if (document.attachEvent) {
        element.attachEvent("on" + eventName, eventFunction);
    }
    else {
        element.addEventListener(eventName, eventFunction, false);
    }
};
function getIconHtml(){
    var innerHtml = '<a id="lim4957" class="text1" href="javascript:void(0);" onclick="openChat(this)" lim:skill="4957" lim:config="110713">\u552e\u524d\u54a8\u8be2</a>';
  //  innerHtml += '<a id="lim4958" class="text2" href="javascript:void(0);" onclick="openChat(this)" lim:skill="4958" lim:config="110714">\u6280\u672f\u652f\u6301</a>';
    if (document.URL.indexOf("ip-guard.com") != -1) {
       innerHtml += '<a class="text3" href="/chs/support_service/business_contact.aspx">\u901a\u8fc7Email\u54a8\u8be2</a>';
    }
    else {
        innerHtml += '<a class="text3" href="/support_service/business_contact.aspx">\u901a\u8fc7Email\u54a8\u8be2</a>';
    }
    return innerHtml;
}

function start(){
    var url = "http://chat.live800.com/live800/chatClient/script/getStatus.jsp?company=76626";
    url += "&skills=" + URLEncode("4957;4958") + "&tm=" + (new Date()).getTime();
    new UT.JSONRequest(url, "status", function(){
        var e = document.getElementById('floatDiv');
        if (status['4957'] == "1" || status['4958'] == "1") {
            e.className = "online";
        }
        else {
            // e.className = "offline";
            e.className = "online";
        }
        var lim4957 = document.getElementById('lim4957'), lim4958 = document.getElementById('lim4958');
        lim4957.innerHTML = (status['4957'] == "1") ? "\u5728\u7ebf" : "\u7559\u8a00";
        // lim4958.innerHTML = (status['4958'] == "1") ? "\u6280\u672f\u652f\u6301(\u5728\u7ebf)" : "\u6280\u672f\u652f\u6301(\u7559\u8a00)";
        lim4957.className += (status['4957'] == "1") ? " online" : " online";
       // lim4957.className += (status['4957'] == "1") ? " online" : " offline";
      //  lim4958.className += (status['4958'] == "1") ? " online" : " offline"
    });
}

function openChat(el){
    var skill = el.getAttribute("lim:skill"), config = el.getAttribute("lim:config"), Url = "http://chat.live800.com/live800/chatClient/chatbox.jsp?companyID=76626&jid=6555151082";
    Url += "&skillId=" + skill;
    Url += "&configID=" + config;
    Url += "&enterurl=" + URLEncode(document.URL);
    el.newWindow = window.open(Url, "chatbox76626", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=570,height=424");
}

function scrollPlace(){
    var divObj = document.getElementById("floatDiv");
    var top = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
    if (divObj) {
        divObj.style.top = top + 100 + "px";
        divObj.style.right = 10 + "px";
    }
};
var floatHtml = '';
if (document.getElementById('icon_static')) {
    floatHtml = '<div id="floatDiv" class="hidden">' + getIconHtml() + '</div>';
}
else {
    floatHtml = '<div id="floatDiv" class="hidden" style="position:absolute">' + getIconHtml() + '</div>';
}
document.write(floatHtml);
UT.addEvent(window, "load", start);
setInterval("scrollPlace()", 50);

