window.onerror = function(){return true;};
if(!live800)var live800={};
if(!live800.Sys){live800.Sys={};}
if(!live800.utils){live800.utils={};}

//proxy function 
if(live800_codeType=="steady"){
	if (!window.Sys){
		window.Sys=live800.Sys;	
	}else{
		if(!window.Sys.getObj)window.Sys.getObjt=live800.Sys.getObj;
	}
};
/**
 * Sys utils
 */
live800.navigateToUrl=function(url,targetWndName,attr){
	try{parent.closeMini();}catch(e){;}
	var wnd,link=document.getElementById("live800:link");
	if(document.all&&isNeedCheckDomainBinding){
		if(document.URL.indexOf("preview.jsp")>-1){
			wnd=window.open(url,targetWndName,attr);
		}else{
			try {
				wnd=window.open("about:blank",targetWndName,attr);
				link.target=targetWndName;
				link.href=url;
				link.click();	
			} catch (e) {
				//wnd=window.open(url,name,attr);
			}
		}
	}else{
		wnd=window.open(url,targetWndName,attr);
	}
	wnd.focus();
	return false;
};
live800.Sys.urlDecode=function(str){
	if("undefined" == typeof decodeURIComponent){
		return unescape(str).replace(/\+/g, ' ').replace(/%2B/g,'+');
  	} else {
		return unescape(str).replace(/\+/g, ' ').replace(/%2B/g,'+');
  	}
};
live800.Sys.getObj=function(id){
	return document.getElementById(id);
};
live800.Sys.urlToParams=function(urlContent){
	cmdMap = new Array();
	cmdParams = new Array();
    pos = -1;
    while (true)
	{
        newPos = urlContent.indexOf('&', pos+1);
        if (newPos>=0) {
            encodedProperty = urlContent.substring(pos+1, newPos);
        }
        else {
            encodedProperty = urlContent.substring(pos+1, urlContent.length);
        }

        equalsPos = encodedProperty.indexOf('=');
        paramName = encodedProperty.substring(0, equalsPos);
        paramValue = live800.Sys.urlDecode(encodedProperty.substring(equalsPos+1, encodedProperty.length));

        cmdParams[paramName] = paramValue;

        if (newPos==-1) {
            break;
        }
        pos = newPos;
    }
	return cmdParams;
};
live800.utils.paramsToUrl=function(params){
	var urlString="";
	for(var i in params){
		if(params[i]!=""){
			urlString+=params[i]+"&";
		}
	}
	return urlString.substring(0,urlString.length-1);
};
live800.utils.setCookie=function(name,value){
	if(typeof(value)=="undefined")return;
	var Days = 30;
    var exp  = new Date();    //new Date("December 31, 9998");
        exp.setTime(exp.getTime() + Days*24*60*60*1000);
        document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
};
live800.utils.getCookie=function(name){
    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
	arr=document.cookie.match(reg);
    if(arr){return unescape(arr[2]);}else{return null;}
};
live800.utils.delCookie=function(name){
	 var exp = new Date();
        exp.setTime(exp.getTime() - 1);
   	 var cval=this.getCookie(name);
        if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
};
live800.utils.setLiveCookie=function(){
	this.delCookie("operatorId");
	this.delCookie("skillId");
	var params=live800.params;
	if(typeof params["live800_operator"]!="undefined"&&params["live800_operator"].length!=0&&params["live800_operator"]!="undefined")
	{
		this.setCookie("operatorId",params["live800_operator"]);
	}
	if(typeof params["live800_skill"]!="undefined"&&params["live800_skill"].length!=0&&params["live800_skill"]!="undefined")
	{
		this.setCookie("skillId",params["live800_skill"]);
	}
};
live800.utils.getGid=function(){
	if(typeof jid!="undefined"){
		return "jid="+jid;
	}else{
	return "";
	}
};
live800.utils.getParam=function(){
	var url="";
	var params = live800.Sys.urlToParams(live800_configContent);
	if(typeof params["live800_operator"]!="undefined"&&params["live800_operator"].length!=0&&params["live800_operator"]!="undefined"){
		url="operatorId="+params["live800_operator"];
	}
	if(typeof params["live800_skill"]!="undefined"&&params["live800_skill"].length!=0&&params["live800_skill"]!="undefined"){
		url=url+"skillId="+params["live800_skill"];
	}
	return url;
};
live800.utils.getTrustfulVisitorInfo=function(){
	var visitorInfoUrl="";
	if(typeof trustfulInfo!="undefined"&&trustfulInfo.length>0&&trustfulInfo!=null&&trustfulInfo!="null"){
		visitorInfoUrl="info="+trustfulInfo;
	}
	return visitorInfoUrl;
};
live800.utils.URLEncode=function(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;
};
live800.utils.getEnterUrl=function(){
	var url="";
	if(enterurl=="null"){
		enterurl=document.URL;}
	url=this.URLEncode(enterurl);
	return "enterurl="+url;
};
live800.params=live800.Sys.urlToParams(live800_configContent);
live800.utils.setLiveCookie();
if(live800_companyID == null || live800_companyID == ""){throw new Error("miss companyID");}
else{
var params=live800.params;
var utils=live800.utils;
var lim_protocol=document.location.protocol.substring(0,document.location.protocol.length-1);
preferences = new Array();
preferences["companyID"] = live800_companyID;
preferences["configID"] = live800_configID;
preferences["text"] =  (params["live800_text"] !=null ? unescape(params["live800_text"]) : unescape("%u5728%u7EBF%u5BA2%u670D"));
preferences["protocol"] =(lim_protocol=="file")?"http":lim_protocol;
preferences["baseUrl"] = live800_baseUrl;
preferences["baseHtmlUrl"] = live800_baseHtmlUrl;
preferences["baseWebapp"] = live800_baseWebApp;
preferences["baseChatHtmlDir"] = live800_baseChatHtmlDir;
preferences["visitorIDInSession"] = preferences["companyID"] + "chater";

var urlParams={
	'jid':utils.getGid(),
	'enterUrl':utils.getEnterUrl(),
	'info':utils.getTrustfulVisitorInfo(),
	'param':utils.getParam()
};
var layerHtml="";
if (document.body.getAttribute('lim:initchat') != "1") {
	layerHtml += '<a id="live800iconlink" target="_self" href="javascript:void(0)" onclick="return live800.navigateToUrl(\'' + this.preferences["protocol"] + "://" + this.preferences["baseUrl"] + this.preferences["baseWebapp"] + this.preferences["baseChatHtmlDir"] + "/chatbox.jsp?companyID=" + this.preferences["companyID"] + "&configID=" + this.preferences["configID"] + "&" + utils.paramsToUrl(urlParams) + '\', \'chatbox' + this.preferences["companyID"] + '\', globalWindowAttribute);">';
	layerHtml += preferences["text"];
	layerHtml += '</a>';
}
function text_generate()
{	
	return layerHtml;
}
if((typeof live800_codeType)=="undefined"){live800_codeType = null;}
if(live800_codeType=="custom"||live800_codeType==null||live800_codeType==""||live800_codeType=="null"){
		if(!live800.Sys.getObj("live"+live800_configID)){
			document.write(layerHtml);
		}
	}
}
if(live800.utils.getCookie("operatorId")=="undefined"){
	live800.utils.delCookie("operatorId");
}
if(live800.utils.getCookie("skillId")=="undefined"){
	live800.utils.delCookie("skillId");
}
if(!document.getElementById("live800:link")){
	document.write("<a href='javascript:void(0);' id='live800:link' style='visibility:hidden;position:absolute'>&nbsp;</a>");
}

