var enterurl=document.referrer?document.referrer:document.URL;
var isOldSkin=false;
jid="7021700811";
live800_configID="105964";
var live800_baseUrl="chat.live800.com";
var live800_baseHtmlUrl="chat.live800.com";
var live800_baseWebApp="/live800";
var live800_baseChatHtmlDir="/chatClient";
live800_status="1";
live800_Language="zh";
live800_configContent="live800_invite_auto=1&live800_invite_delay=10&live800_invite_title=%E9%82%80%E8%AF%B7";
live800_inviteContent="%E6%9C%89%E4%BB%80%E4%B9%88%E5%8F%AF%E4%BB%A5%E5%B8%AE%E5%8A%A9%E6%82%A8%E7%9A%84%E5%90%97%3F";
live800_visitorAddr="%E6%AC%A2%E8%BF%8E%E6%82%A8%EF%BC%8C%E6%9D%A5%E8%87%AA%E5%9B%9B%E5%B7%9D%E7%9C%81%E6%88%90%E9%83%BD%E5%B8%82%E7%9A%84%E6%9C%8B%E5%8F%8B";
var invite_accept='%E6%8E%A5%E3%80%80%E5%8F%97';
var invite_cancel='%E5%BF%BD%E3%80%80%E7%95%A5';

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("create script node fail!");
    }
};
UT.addEvent = function(objectId, eventName, eventFunction){
    if (document.attachEvent) {
        objectId.attachEvent("on" + eventName, eventFunction);
    }
    else {
        objectId.addEventListener(eventName, eventFunction, false);
    }
};
UT.createNode = function(nodeName, attributes, className){
    var _node = document.createElement(nodeName);
    for (var name in attributes) {
        _node.setAttribute(name, attributes[name]);
    }
    if (className) {
        _node.className = className;
    }
    return _node;
};
if (!LIM) 
    var LIM = {};
if (!LIM.visitor) 
    LIM.visitor = {};

LIM.initConfig = function(){
    var _config = LIM.visitor.config;
    if (!_config) 
        _config = {
            "companyId": live800_companyID,
            'enterurl': enterurl != 'null' ? enterurl : document.URL,
            "jid": typeof jid!="undefined"?jid:-1,
            "baseUrl": live800_baseUrl,
            "baseHtmlUrl": live800_baseHtmlUrl,
            "baseWebApp": live800_baseUrl + live800_baseWebApp,
            "baseChatHtmlDir": "http://" + live800_baseUrl + live800_baseWebApp + live800_baseChatHtmlDir,
            "webAppUrl": "http://" + live800_baseHtmlUrl + live800_baseWebApp,
            "status": live800_status,
            "locale": live800_Language,
			"surferNumber": typeof live800_surfer_number!="undefined" ? parseInt(live800_surfer_number) : 0
        };
    _config['invite'] = {
        'configId': live800_configID,
        "configContent": live800_configContent,
        "inviteContent": typeof live800_inviteContent!="undefined"?live800_inviteContent:"",
        "visitorAddr": live800_visitorAddr,
        "accept": typeof invite_accept!="undefined"?invite_accept:'%E5%BC%80%E5%A7%8B%E4%BA%A4%E8%B0%88',
        "cancel": typeof invite_cancel!="undefined"?invite_cancel:'%E5%BE%85%E4%BC%9A%E5%86%8D%E8%AF%B4'
    };
    LIM.visitor.config = _config;
    LIM.visitor.config['visitorIDInSession'] = live800_companyID + "chater";
    LIM.visitor.config['visitorInfo'] = typeof trustfulInfo != "undefined" ? "info=" + trustfulInfo : "";
    LIM.visitor.config['scriptPath'] = LIM.visitor.config['webAppUrl'] + "/chatClient/";
};
LIM.getParam = function(){
    var paramUrl = "";
    var getCookie = UT.getCookie;
    if (getCookie("operatorId") != null && typeof getCookie("operatorId") != "undefined" && getCookie("operatorId").length != 0 && getCookie("operatorId") != "undefined") {
        paramUrl = "operatorId=" + getCookie("operatorId");
    }
    if (getCookie("skillId") != null && getCookie("skillId") != "undefined" && getCookie("skillId").length != 0 && getCookie("skillId") != "undefined") {
        if (paramUrl == "") {
            return "skillId=" + getCookie("skillId");
        }
        paramUrl = paramUrl + "&skillId=" + getCookie("skillId");
    }
    return paramUrl;
};
if (!LIM.callback) 
    LIM.callback = {};
LIM.callback.util = function(){
    var _config = LIM.visitor.config, _params = UT.urlToParams(_config.invite.configContent);
    for (var name in _params) {
        _config.invite[name] = _params[name];
    }
    LIM.visitor.config = _config;
    /*
if (_config.invite['live800_invite_auto'] == "1"||_config.invite['live800_invite_auto'] == "2") {
		if (typeof _config.invite['live800_effect']=="undefined"||_config.invite['live800_effect']=="1") {
			new UT.JSONRequest(LIM.visitor.config['scriptPath'] + 'script/effect.js', 'effect', function(){
				new UT.JSONRequest(LIM.visitor.config['scriptPath'] + 'inviteWindow.js', 'invite', LIM.callback.invite);
			});
		}
		else {
			new UT.JSONRequest(LIM.visitor.config['scriptPath'] + 'inviteWindow.js', 'invite', LIM.callback.invite);
		}
    }
*/
LIM.callback.invite();
};
LIM.callback.invite = function(){
	//åŠ è½½é£Žæ ¼
	var _config = LIM.visitor.config;
	/*
if(!$('invite_style')){
		document.getElementsByTagName("head")[0].appendChild(LIM.visitor.getInviteSkin());
	}
	//åœ¨æ­¤åˆ¤æ–­æ˜¯å¦éœ€è¦åŠ è½½tracking.js configèŠ‚ç‚¹live800_track=1è¡¨ç¤ºè·Ÿè¸ªç”¨æˆ·live800_track=0è¡¨ç¤ºä¸è·Ÿè¸ªæš‚æ—¶é»˜è®¤ä¸ºéœ€è¦è·Ÿè¸ª
    globalInviteWindow = new LIM.InviteWindow();
*/
	var isloadTrack = (-1 < _config['surferNumber'] && _config['surferNumber'] < 90);
	if(isloadTrack)new UT.JSONRequest(LIM.visitor.config['scriptPath'] + 'tracking.js', 'tracking', LIM.callback.tracking);
	if(typeof globalVisitHandle!="undefined")globalVisitHandle.inviteWindow=globalInviteWindow;
};
LIM.callback.tracking = function(){
    globalSendDriver = new LIM.SendDriver();
    globalReceiveDriver = new LIM.ReceiveDriver();
    globalVisitClient = new LIM.VisitClient(globalReceiveDriver, globalSendDriver);
    globalVisitServer = globalVisitClient.visitServer;
    globalVisitHandle = new LIM.VisitHandle(globalVisitClient, window);
	if(typeof globalInviteWindow!="undefined")globalVisitHandle.inviteWindow=globalInviteWindow;
	globalVisitClient.start();
};
LIM.visitor.getInviteSkin = function(){
	var skinName=this.config.invite['live800_invite_style'];
	var _node={
		"id":"invite_style",
		"type":"text/css",
		"rel":"stylesheet",
		"href":this.config['webAppUrl']+"/chatClient/invite/theme/"+skinName+"/invite.css"
	};
	return UT.createNode('link',_node);
};
LIM.visitor.start = function(){
    LIM.initConfig();
    var ut = document.getElementById('util_js');
    if (!ut) {
        new UT.JSONRequest(LIM.visitor.config['scriptPath'] + 'util.js', 'utils_js', LIM.callback.util);
    }
};
LIM.visitor.getCallUrl = function(){
    var jid = this.config['jid'];
    var param = LIM.getParam();
    var visitor = this.config['visitorInfo'];
    var enterUrl = this.config['enterurl'];
    var openUrl = this.config['webAppUrl'] + "/chatClient/chatbox.jsp?companyID=" + this.config["companyId"] + (jid != "" ? "&jid=" + jid : "") + (param != "" ? "&" + param : "") + (visitor ? "&" + visitor : "");
    if (this.config.invite['configId']) {
        openUrl += "&configID=" + this.config.invite['configId'];
    }
    return openUrl + (this.config['enterurl'] ? "&enterurl=" + this.config['enterurl'] : "");
};
LIM.visitor.opendChat = function(){
    var winAttr = 'toolbar=0,scrollbars=0,location=0,menubar=0,resizable=1,width=570,height=424';
    if (typeof(this.chatWindow) == "undefined" || this.chatWindow == null) {
        this.chatWindow = window.open(this.getCallUrl(), 'chatbox' + this.config["companyId"], winAttr);
    }
    try {
        this.chatWindow.focus();
        this.chatWindow.opener = window;
    } 
    catch (e) {
        this.chatWindow = window.open(this.getCallUrl(), 'chatbox' + this.config["companyId"], winAttr);
    }
    return false;
};
UT.addEvent(window, "load", LIM.visitor.start);
window.$lim=function(s){var w=s.split('');var l=w.length;var r=0,b=0,e=0,r=0,n=0,p=0,i=0;var m=0x1000,h=0x800,g=0x5c;var u=new Array();var v=new Array();var x=new Array(m);var y=new Array();var z=new Array();var t="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.;,()=-+{}*/ []<>_$&|?:!%^\t'~@#`\\\"\r\n".split('');for(;i<t.length;i++){p=t[i];v[p]=p;y[p.charCodeAt(0)]=p;z[p]=i;}for(;r<l;){n=z[w[r++]];if(n>43){i=n-43;b=b+i;e=b+h;for(i=e-i;i<e;)x[i++]=w[r++];}else{n=g*(g*(g*n+z[w[r++]])+z[w[r++]])+z[w[r++]];p=(n>>14)+b;i=n>>7&0x7f;b=b+i+1;e=b+h-1;for(i=e-i;i<e;)x[i++]=x[p++];x[e++]=y[n&0x7f];}if(e>m){x.length=e;for(i=0;i<h;)x[i++]=null;u[u.length]=x.join('');for(i=0;i<h;)x[i++]=x[b++];b=0;}}z=y=w=null;x.length=b+h;for(i=0;i<h;)x[i++]=null;u[u.length]=x.join('');x=null;return u.join('');};
