var webchat_companyID = "keycons.com.cn";
var enterurl = "null";
var isOldSkin = false;
var webchat_Root = "http://www.ukeas.com.cn:887/";
var webchat_Url = "http://www.ukeas.com.cn:887/ChatBox.aspx";
var webchat_winName = "xsunt_webchat";
var globalWindowAttribute = 'toolbar=0,scrollbars=0,location=0,menubar=0,resizable=1,width=570,height=424,top=' + (screen.height - 424) / 2 + ',left=' + (screen.width - 570) / 2;
var webchat_AjaxHandler = "http://www.ukeas.com.cn:887/AjaxHandler.ashx?usw=ukeas.com.cn";
var webchat_configContent = "webchat_float=1&webchat_floatToRight=1&webchat_floatTop=180&webchat_floatSide=5&webchat_switch=0&webchat_closeIcon=0";
var webchat_opencommand = "OpenChatWindow('9999', 'UKEAS总机')";

function EncodeUrl(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
}

function OpenChatWindow(cs, name) {
    var openUrl = webchat_Url;
    if (openUrl.indexOf("?") < 0)
        openUrl += "?dp=1"; //add a dummy param

    if (typeof cs != "undefined")
        openUrl += "&cs=" + cs;
    if (typeof name != "undefined")
        openUrl += "&name=" + name;
    openUrl += "&companyID=" + webchat_companyID;
    openUrl += "&enterurl=" + EncodeUrl(document.URL);
    openUrl += "&tm=" + (new Date()).getTime();
    var winName = typeof webchat_winName == "undefined" ? "XWebChatWindow" : webchat_winName;
    var winAttr = globalWindowAttribute;
    var chatWindow = window.open(openUrl, winName, winAttr);
    chatWindow.focus();
}
