﻿var winmode = "width=560px,height=455px,status=no,resizable=no,location=no,menubar=no,toolbar=no,status=no";
var Url = {encode : function (string) {return escape(this._utf8_encode(string));},decode : function (string) {return this._utf8_decode(unescape(string));},_utf8_encode : function (string) {string = string.replace(/\r\n/g,'\n');var utftext = '';for (var n = 0; n < string.length; n++) {var c = string.charCodeAt(n);if (c < 128) {utftext += String.fromCharCode(c);} else if((c > 127) && (c < 2048)) {utftext += String.fromCharCode((c >> 6) | 192);utftext += String.fromCharCode((c & 63) | 128);} else {utftext += String.fromCharCode((c >> 12) | 224);utftext += String.fromCharCode(((c >> 6) & 63) | 128);utftext += String.fromCharCode((c & 63) | 128);}}return utftext;},_utf8_decode : function (utftext) {var string = '';var i = 0;var c = c1 = c2 = 0;while ( i < utftext.length ) {c = utftext.charCodeAt(i);if (c < 128) {string += String.fromCharCode(c);i++;} else if((c > 191) && (c < 224)) {c2 = utftext.charCodeAt(i+1);string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));i += 2;} else {c2 = utftext.charCodeAt(i+1);c3 = utftext.charCodeAt(i+2);string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));i += 3;}}return string;}}
var LC_Title = encodeURIComponent(document.title);
var LC_Location = encodeURIComponent(document.URL);
var LC_Referrer = "";
try
{
    LC_Referrer = encodeURIComponent(parent==self?window.document.referrer:top.document.referrer);
}
catch(x){}
var LC_UserLang = navigator.appName=="Netscape"?navigator.language:navigator.userLanguage;
var LC_VisitorName="";
var LC_VisitorEmail="";
if(typeof(LC_Companys)=="undefined" || LC_Companys==null)
{
    var LC_Companys = new Array();
}
var LC_LiveChat = "即时语|即時語|LiveChat";
var LC_ServerError = "错误的服务器地址，请设置正确的服务器路径，或联系服务供应商！|錯誤的伺服器位址，請設置正確的伺服器路徑，或聯繫服務供應商！|Invalid server url, please verify server url and try again or contact service provider.";
var LC_SettingNotFound = "没有找到设置信息，请检查引用代码或联系管理员！|沒有找到設置資訊，請檢查引用代碼或聯繫管理員！|Setting not found, please check the Page Code or contact administrator.";
var LC_WebSiteNotFound = "没有找到指定公司网站，请检查引用代码或联系管理员！|沒有找到指定公司網站，請檢查引用代碼或聯繫管理員！|Web Site not found, please check the Page Code or contact administrator.";
var LC_CompanyNotFound = "没有找到指定公司，请检查引用代码或联系管理员！|沒有找到指定公司，請檢查引用代碼或聯繫管理員！|Company not found, please check the Page Code or contact administrator.";
var LC_PageSettingNotFound = "没有找到页面设置信息，请检查引用代码或联系管理员！|沒有找到頁面設置資訊，請檢查引用代碼或聯繫管理員！|Page setting not found, please check the Page Code or contact administrator.";
var LC_ParameterError = "公司初始化错误，缺少参数！|公司初始化錯誤，缺少參數！|Company object initializing failed, not enough parameters!";
var LC_IPRejectedPrompt = "对不起，您的IP被过滤！|對不起，您的IP被過濾！|You have been banned!";
var LC_OpenedWinPrompt = "您已经打开聊天窗口或者打开的间隔太短！|您已經打開聊天視窗或者打開的間隔太短！|You have already opened the chat window or You open up window period very shortly";
var LC_InvitePrompt = "即时语在线客服邀您对话|即時語線上客服邀您對話|LiveChat";
var LC_AcceptInvitePrompt = "开始交谈|接受|Accept";
var LC_RejectInvitePrompt = "暂不交谈|拒絕|Refuse";
var LC_InitError = "错误|錯誤|Error";
var LC_ServerADD = "服务器地址|伺服器地址|Server Url";
var LC_DIV = "";
var LC_InviRefreshTime = 10;
var LC_SystemIgnoreTag = 0;

function LC_Company()
{
    this.LC_InviteShow = false;
	this.LC_OutPutDiv = null;
	this.LC_CompanyID = 0;
	this.LC_WebSiteID = 0;
	this.LC_VisitorID = "";
	this.LC_VisitorLang = "";
    this.LC_VisitorName="";
    this.LC_VisitorEmail="";
	this.LC_BaseUrl = "";
	this.LC_InviteUrl = "";
	this.LC_WebRoot = "";
	this.LC_CompanyName = "";
	this.LC_ContactName = "";
	this.LC_ContactEmail = "";
	this.LC_UserProcess = true;
	this.LC_SystemInvite = "";
	this.LC_SystemInviteText = "";
	this.LC_ServiceInviteText = "";
	this.LC_ServiceType = 0;
	this.LC_InviteBox_Height = 250;
	this.LC_InviteBox_Width = 200;
	this.LC_InviteBox_Top = 200;
	this.LC_InviteBox_Left = 100;
	this.LC_ShowAD = 1;
    this.LC_IPRejected = false;
    this.LC_SystemIgnore = 0;
    this.EnableInviteChecker = true;
    this.ToParameters = function(){return this.LC_VisitorID;};
	this.InitCompany = function(outputdivid)
	{
	    LC_SystemIgnoreTag = this.LC_SystemIgnore;
	    this.LC_IPRejected = false;
		if(outputdivid && outputdivid!="")
		{
			var t_div = document.getElementById(outputdivid);
			if(t_div)this.LC_OutPutDiv = t_div;
		}
		LC_Companys.push(this);
		if(this.LC_ServiceType == 1)this.LC_ShowAD = 0;
		this.ShowLinkIcon();
	};
	this.InitRejectedIPUser = function(outputdivid)
	{
	    LC_SystemIgnoreTag = this.LC_SystemIgnore;
	    this.LC_IPRejected = true;
		if(outputdivid && outputdivid!="")
		{
			var t_div = document.getElementById(outputdivid);
			if(t_div)this.LC_OutPutDiv = t_div;
		}
		LC_Companys.push(this);
		this.ShowLinkIcon();
	};
	this.ShowLinkIcon = function()
	{
		if(this.LC_ShowAD==1)
		{
			var mj=new JsLoader();
			mj.load(this.LC_WebRoot + "Images/LiveChatAD.js", null);
		}
		var outHTML = "";
		if(this.LC_OutPutDiv)
		{
			outHTML = "<a href='javascript:LC_ClickLink(" + this.LC_CompanyID + ");'><img src='" + this.LC_WebRoot + "Images/LinkIcon_" + this.LC_CompanyID + ".gif' border='0'/></a>";
    		var inviteframe = document.getElementById("scrInvitation" + this.LC_CompanyID);
			if(!inviteframe && !this.LC_IPRejected) outHTML += "<script id='scrInvitation" + this.LC_CompanyID + "'></script>";
			this.LC_OutPutDiv.innerHTML = outHTML;
		}
		else
		{
		    if(this.LC_IPRejected)return;
    		var inviteframe = document.getElementById("scrInvitation" + this.LC_CompanyID);
		    if(!inviteframe)
		    {
				var mj=new JsLoader();
				mj.load("","scrInvitation" + this.LC_CompanyID);
	        }
		}
		if(!this.LC_IPRejected)
		{
		    if(this.LC_VisitorID!="") this.LoadInviteFrame();
            if(this.LC_SystemInvite==1 && get_cookie("chatwindowopened")!="1" && get_cookie("rejectinvite")!="1")
                setTimeout("ReceivedInvite(" + this.LC_CompanyID + ",0,'')", this.LC_SystemInviteTimespan * 1000);
        }
	};
	this.LoadInviteFrame = function()
	{
		var inviteframe = document.getElementById("scrInvitation" + this.LC_CompanyID);
		if(inviteframe)
		{
		    if(!this.LC_InviteShow)
		    {
		        this.LC_InviteShow = true;
//socket
                //var u = this.LC_InviteUrl;
                //var x = this.ToParameters();
                //setTimeout(function(){
                //inviteframe.src = u + "?Parameter=" + x;},3000);
//httpHandler
                this.LC_InviteUrl = this.LC_WebRoot + "GetInvite.livechat?companyid=" + this.LC_CompanyID + "&websiteid=" + this.LC_WebSiteID;
                this.EnableInviteChecker = true;
                setTimeout("StartInviteChecker(" + this.LC_CompanyID + ")", LC_InviRefreshTime * 1000);
		    }
		}
	};
	this.StopInviteFrame = function()
	{
	    StopInviteChecker(this.LC_CompanyID);
		/*socket
		var inviteframe = document.getElementById("scrInvitation");
		if(inviteframe)
		{
		    //inviteframe.src = "about:blank";
		}*/
	};
	this.Request = function(groupid)
	{
	    var url = this.LC_WebRoot + "Chat.aspx?companyid=" + this.LC_CompanyID + "&websiteid=" + this.LC_WebSiteID + 
	    "&visitorname=" + Url.encode(this.LC_VisitorName) + "&visitoremail=" + Url.encode(this.LC_VisitorEmail) + "&groupid=" + groupid + "&r=" + Math.random();
	    window.open(url,"", winmode);
	};
	this.Click = function()
	{
	    var inviteBoxDiv = document.getElementById('c35ComLiveChat' + this.LC_CompanyID);
	    if(inviteBoxDiv)
	    {
	        inviteBoxDiv.style.display = 'none';
	    }
        if(get_cookie("chatwindowopened")=="1")
        {
            alert(getPromptStringByLang(this.LC_VisitorLang, LC_OpenedWinPrompt));
            return;
        }
	    if(this.LC_IPRejected)
	    {
	        alert(getPromptStringByLang(this.LC_VisitorLang, LC_IPRejectedPrompt));
	        return;
	    }
        //document.cookie = "rejectinvite=1;";
	    if(this.LC_UserProcess && this.LC_UserProcess==1)
	    {
	        var url = this.LC_WebRoot + "GroupSelection.aspx?companyid=" + this.LC_CompanyID + "&websiteid=" + this.LC_WebSiteID + "&r=" + Math.random();
	        if(typeof(LiveChatShowGroup)!="undefined")
	        {
	            if(LiveChatShowGroup!="")
	                url += "&showgroup=" + encodeURIComponent(LiveChatShowGroup);
	        }
		    window.open(url,"", winmode);
		}
		else
		{
		    window.open(this.LC_WebRoot + "Chat.aspx?companyid=" + this.LC_CompanyID + "&websiteid=" + this.LC_WebSiteID + "&r=" + Math.random(),"", winmode);
		}
		
	};
	this.ProcessInvite = function(serviceid)
	{
	    var inviteBoxDiv = document.getElementById('c35ComLiveChat' + this.LC_CompanyID);
	    if(inviteBoxDiv)
	    {
	        inviteBoxDiv.style.display = '';
	    }
	    else
	    {
            inviteBoxDiv = document.createElement('div');
            inviteBoxDiv.id = 'c35ComLiveChat' + this.LC_CompanyID;
            inviteBoxDiv.name = 'c35ComLiveChat' + this.LC_CompanyID;
            inviteBoxDiv.frameBorder = '0';
            inviteBoxDiv.style.position = 'absolute';
            inviteBoxDiv.style.top = (this.LC_InviteBox_Top*1) + 'px';
            inviteBoxDiv.style.left = (this.LC_InviteBox_Left*1) + 'px';
            inviteBoxDiv.style.width = ((this.LC_InviteBox_Width*1) + 4) + 'px';
            inviteBoxDiv.style.height = ((this.LC_InviteBox_Height*1) + 30) + 'px';
            inviteBoxDiv.innerHTML = "";
	    inviteBoxDiv.style.zIndex = 10000;
	        document.body.appendChild(inviteBoxDiv);
	        var testad;
	        var mheight=0;
	        var mweight = ((this.LC_InviteBox_Width*1) + 2);
	        var adhtm = "";
	        var addivid= "LiveChat" + this.LC_CompanyID + "AD1";
	        if(this.LC_ShowAD==1)
	        {
	            adhtm = "<div style='z-index:10000;border:1px solid #283564;background:#FFFFFF none repeat scroll 0 0;'><div id='" + addivid + "'></div></div>";
	            mheight=((this.LC_InviteBox_Height*1) + 30);
	        }
	        else
	        {
	            adhtm = "";
	            mheight=((this.LC_InviteBox_Height*1) + 30);
	        }
	        var html = '<div id="divMain' + this.LC_CompanyID + '" style="width:' + mweight + 'px;height:' + mheight + 'px;"><div style="background:#D8D8D8 none repeat scroll 0 0;position:absolute;">';
	        html += '<div style="height:' + (this.LC_InviteBox_Height*1 + 2) + 'px;position:relative;width:' + ((this.LC_InviteBox_Width*1) + 4) +'px;">';
	        html += '<div style="background:transparent url(' + this.LC_WebRoot + 'Style0/skin/chat_top_bg.gif) repeat scroll 0 0;clear:both;color:#FFFFFF;height:25px;">';
	        html += '<div style="background:transparent url(' + this.LC_WebRoot + 'Style0/skin/chat_topr_bg.gif) no-repeat scroll right center;float:right;height:25px;width:9px;"></div>';
	        html += '<div style="font-size:12px;background:transparent url(' + this.LC_WebRoot + 'Style0/skin/chat_topl_bg.gif) no-repeat scroll 0 0;line-height:25px;padding-left:32px;">';
	        html += getPromptStringByLang(this.LC_VisitorLang, LC_InvitePrompt) + '</div></div><div style="clear:both;"></div>';
	        html += '<div style="background:#849FE4 none repeat scroll 0 0;border-color:-moz-use-text-color #283564 #283564;border-style:none solid solid;border-width:0 1px 1px;padding:1px;">';
	        html += '<div style="background:transparent url(' + this.LC_WebRoot + 'images/RequestPicture_' + this.LC_CompanyID + '.gif) repeat scroll 0 0;border:1px solid #0A3869">';
	        html += '<table width="' + (this.LC_InviteBox_Width*1 - 2) + '" border="0" cellpadding="0" cellspacing="0" height="' + (this.LC_InviteBox_Height*1) + '">';
	        html += '<tbody><tr><td width="135">&nbsp;</td><td style="font-size:12px;color:#020202;line-height:32px;padding-left:20px;padding-top:20px;">';
	        html += Url.decode(this.LC_SystemInviteText) + '</td></tr><tr><td>&nbsp;</td><td height="40"><table width="180" align="right" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td width="92">';
	        var btn = '<div style="color:#52649A;cursor:pointer;height:18px!important;line-height:16px!important;line-height:18px;padding-top:4px;text-indent:20px;vertical-align:top;width:80px;font-size:12px;';
	        btn += 'background:transparent url(' + this.LC_WebRoot + 'Style0/skin/button_request.gif) repeat scroll 0 0;" ';
	        btn += ' onmouseover="this.style.background=\'transparent url(' + this.LC_WebRoot + 'Style0/skin/button_request_over.gif) ';
	        btn += ' repeat scroll 0 0\'" onmouseout="this.style.background=\'transparent url(' + this.LC_WebRoot + 'Style0/skin/button_request.gif) ';
	        btn += ' repeat scroll 0 0\'" onmousedown="this.style.background=\'transparent url(' + this.LC_WebRoot + 'Style0/skin/button_request_down.gif) ';
	        btn += ' repeat scroll 0 0\'" onmouseup="this.style.background=\'transparent url(' + this.LC_WebRoot + 'Style0/skin/button_request.gif) ';
	        btn += ' repeat scroll 0 0\'" ';
    	    html += btn + ' onclick="javascript:AcceptCompanyInvite('+this.LC_CompanyID+','+serviceid+');">' + getPromptStringByLang(this.LC_VisitorLang, LC_AcceptInvitePrompt)  + '</div></td><td>';
	        html += btn + ' onclick="javascript:RejectCompanyInvite('+this.LC_CompanyID+','+serviceid+');">' + getPromptStringByLang(this.LC_VisitorLang, LC_RejectInvitePrompt)  + '</div></td></tr></tbody></table></td></tr></tbody></table></div></div>' + adhtm + '</div></div></div>';
	        inviteBoxDiv.innerHTML += html;
			if(this.LC_ShowAD==1)
			{
			    if(typeof(LIVECHATAD) != "undefined")
			    {
				    eval("var x=new LIVECHATAD();x.RunSlideText(1,GetLanguage(),addivid,mweight)");
				}
			}
	    }
	};
	this.AcceptInvite = function(serviceid)
	{
	    document.cookie = "rejectinvite=1;";
	    if(serviceid>0)
	    {
		    AcceptInvite(this.LC_WebRoot,this.LC_CompanyID,this.LC_WebSiteID, this.LC_VisitorID, serviceid);
		}
		else
		{
	        if(this.LC_UserProcess && this.LC_UserProcess==1)
	        {
		        window.open(this.LC_WebRoot + "GroupSelection.aspx?companyid=" + this.LC_CompanyID + "&websiteid=" + this.LC_WebSiteID + "&browserLang=" + GetLanguage() + "&r=" + Math.random(),"", winmode);
		    }
		    else
		    {
		        window.open(this.LC_WebRoot + "Chat.aspx?companyid=" + this.LC_CompanyID + "&websiteid=" + this.LC_WebSiteID + "&browserLang=" + GetLanguage() + "&r=" + Math.random(),"", winmode);
		    }
		}
	};
	this.RejectInvite = function(serviceid)
	{
	    document.cookie = "rejectinvite=1;";
		var rejectEle = rejectEle = document.createElement('img');
	    rejectEle.id = "c35ComLiveChatImg";
	    rejectEle.name = "c35ComLiveChatImg";
	    rejectEle.style.display="none";
	    rejectEle.src = this.LC_WebRoot + "rejectinvite.live?companyid=" + this.LC_CompanyID + "&websiteid=" + this.LC_WebSiteID;
	};
}
//var EnableInviteChecker=true;
//var InviteUrl = "";
function StartInviteChecker(companyid)
{
    var com = GetCompanyObject(companyid);
    if(!com)return;
    if(LC_SystemIgnoreTag ==0 && get_cookie("chatwindowopened")!="1" 
        && get_cookie("rejectinvite")!="1" && com.EnableInviteChecker && com.LC_InviteUrl != "")
    {
        var inviteframe = document.getElementById("scrInvitation" + companyid);
        if(inviteframe)
        {
            var _parentElement = inviteframe.parentNode;
            if(_parentElement){
                _parentElement.removeChild(inviteframe);  
            }
        }
        var mj=new JsLoader();
        var u = com.LC_InviteUrl + "&r=" + Math.random();
        mj.load(u, "scrInvitation" + companyid);
    }
}
function StopInviteChecker(companyid)
{
    var com = GetCompanyObject(companyid);
    if(!com)return;
    com.EnableInviteChecker = false;
}
function GetLanguage()
{
    var language;
    if (navigator.appName == 'Netscape') 
        language = navigator.language; 
    else 
        language = navigator.browserLanguage; 
    
    language = language.toLowerCase();
    
    if(language.indexOf('cn') > -1 || language.indexOf('chs') > -1)
        language = "zh-CN";
    else if(language.indexOf('zh') > -1)
        language = "zh-CHT";
    else
        language = "en-US";

    return language;
}

function AcceptCompanyInvite(companyid,serviceid)
{
	var com = GetCompanyObject(companyid);
	if(com)
	    com.AcceptInvite(serviceid);
    var inviteBoxDiv = document.getElementById('c35ComLiveChat' + companyid);
    if(inviteBoxDiv)
    {
        inviteBoxDiv.style.display = 'none';
    }
}
function RejectCompanyInvite(companyid,serviceid)
{
	var com = GetCompanyObject(companyid);
	if(com)
	    com.RejectInvite(serviceid);
    var inviteBoxDiv = document.getElementById('c35ComLiveChat' + companyid);
    if(inviteBoxDiv)
    {
        inviteBoxDiv.style.display = 'none';
    }
}
function AcceptInvite(webroot,companyid,websiteid, visitorid, serviceNo)
{
   window.open(webroot + "chat.aspx?action=AcceptInvite&companyid=" + companyid + "&websiteid=" + websiteid + "&serviceNo=" + serviceNo + "&visitorid=" + visitorid + "&r=" + Math.random(),"_blank",winmode);
}
if(typeof(CompanyLoadedCount) == "undefined")
    var CompanyLoadedCount = 0;

function InitCompany(companyid,websiteid,outputdivid)
{
	if(typeof(LiveChatServer)!= "undefined" && LiveChatServer!="")
	{
		if(!LiveChatServer.endWith("/"))
			LiveChatServer += "/";
	}
	else
	{
		alert(getPromptStringByLang(GetLanguage(), LC_ParameterError));
		return;
	}
    InitCompanyV2(companyid,websiteid,outputdivid,LiveChatServer);
}
function InitCompanyV2(companyid,websiteid,outputdivid,webroot)
{
    if(CheckCompanyExist(companyid))
    {
        return;
    }
    LC_DIV = outputdivid;
	if(webroot && webroot!="")
	{
		if(!webroot.endWith("/"))
			webroot += "/";
	}
	else
	{
		alert(getPromptStringByLang(GetLanguage(), LC_ParameterError));
		return;
	}
	var cookie = get_cookie('VisitorInfo_Name');
    if (cookie != null && cookie != '')
    {
        var cookieValue = cookie.substring(cookie.indexOf('=') + 1,cookie.length);
        if (cookieValue != null || cookieValue!='')
        {
            LC_VisitorName = unescape(cookieValue);
        }
    }
    cookie = get_cookie('VisitorInfo_Email');
    if (cookie != null && cookie != '')
    {
        cookieValue = cookie.substring(cookie.indexOf('=') + 1,cookie.length);
        if (cookieValue != null || cookieValue!='')
        {
            LC_VisitorEmail = unescape(cookieValue);
        }
    }
	try
	{
		if(CompanyLoadedCount == 0)
		{
			CompanyLoadedCount ++;
			var jsurl = webroot + companyid + "-" + websiteid + ".live?t=" + LC_Title + "&u=" + LC_Location + "&r=" + LC_Referrer +
			"&name="+escape(LC_VisitorName)+"&email="+LC_VisitorEmail+"&d=" + outputdivid + "&browserLang=" + GetLanguage() + "&random=" + Math.random();
			var mj=new JsLoader();
			mj.load(jsurl, "LC_CompanyJS_" + companyid);
		}
		else
		{
			CompanyLoadedCount++;
			var url = webroot + companyid + "-" + websiteid + ".live?t=" + LC_Title + 
							"&u=" + LC_Location + "&r=" + LC_Referrer +"&name="+escape(LC_VisitorName)+"&email="+LC_VisitorEmail+"&d=" + outputdivid + "&browserLang=" + GetLanguage() + "&random=" + Math.random();
            setTimeout(function(){
                var mj=new JsLoader();
                mj.load(url, "LC_CompanyJS_" + companyid);
            },3000);
		}
	}
	catch(e)
	{
		alert(e.message);
	}
}
function CheckCompanyExist(companyid)
{
	for ( var i=0 ; i < LC_Companys.length ; i++ )
	{
		if(LC_Companys[i].LC_CompanyID==companyid)
			return true;
	}
	return false;
}
function GetCompanyObject(companyid)
{
	for ( var i=0 ; i < LC_Companys.length ; i++ )
	{
		if(LC_Companys[i].LC_CompanyID==companyid)
			return LC_Companys[i];
	}
	return null;
}
function LC_ClickLink(companyid)
{
	var com = GetCompanyObject(companyid);
	if(com)
		com.Click();
}
function LC_RequestGroup(companyid,groupid)
{
    var com = GetCompanyObject(companyid);
    if(com)
        com.Request(groupid);
}
function ReceivedInvite(companyid, serverid, word)
{
    if(serverid>0)
        document.cookie = "rejectinvite=0;";
    if(get_cookie("chatwindowopened")=="1" || get_cookie("rejectinvite")=="1")
        return;

	if(companyid && typeof(companyid)!="undefined" && companyid !="")
	{
		var com = GetCompanyObject(companyid);
		if(com)
			com.ProcessInvite(serverid);
		else
		{
			if(this.LC_VisitorLang=="")this.LC_VisitorLang = GetLanguage();
			alert(getPromptStringByLang(this.LC_VisitorLang, LC_ParameterError));
		}
	}
}
String.prototype.endWith = function(oString)
{   
	var reg = new RegExp(oString + "$");   
	return reg.test(this); 
}
function getPromptStringAuto(str)
{
    var langcookie = GetLanguage();
    var lang = 0;
    switch(langcookie.toLowerCase())
    {
        case "zh-cn":
            break;
        case "zh-tw":
            lang = 1;
            break;
        case "zh-cht":
            lang = 1;
            break;
        case "zh-hk":
            lang = 1;
            break;
        default:
            lang = 2;
            break;
    }
    var items=str.split('|');
    return items[lang];
}
function getPromptString(companyyid, str)
{
    var langcookie = get_cookie(companyyid + ".VisitorCard.Language");
    if(!langcookie)langcookie=GetLanguage();
    var lang = 0;
    switch(langcookie.toLowerCase())
    {
        case "zh-cn":
            lang = 0;
            break;
        case "zh-tw":
            lang = 1;
            break;
        case "zh-cht":
            lang = 1;
            break;
        case "zh-hk":
            lang = 1;
            break;
        default:
            lang = 2;
            break;
    }
    var items=str.split('|');
    return items[lang];
}
function getPromptStringByLang(langstr, str)
{
	if(!langstr || langstr=="")langstr=GetLanguage();
    var lang = 0;
    switch(langstr.toLowerCase())
    {
        case "zh-cn":
            lang = 0;
            break;
        case "zh-tw":
            lang = 1;
            break;
        case "zh-cht":
            lang = 1;
            break;
        case "zh-hk":
            lang = 1;
            break;
        default:
            lang = 2;
            break;
    }
    var items=str.split('|');
    return items[lang];
}
var get_cookie = function(Name)
{
    var search = Name + "="
    var returnvalue = "";
    if (document.cookie.length > 0) {
        var offset = document.cookie.indexOf(search)
        if (offset != -1) {
            offset += search.length
            var end = document.cookie.indexOf(";", offset);
            if (end == -1)
                end = document.cookie.length;
            returnvalue=unescape(document.cookie.substring(offset, end))
            }
    }
    return returnvalue;
}
function LoadJs(id, jsurl)
{
	var oHead = document.getElementsByTagName('HEAD').item(0); 
	var newFrame = document.createElement('SCRIPT');
	newFrame.id = id;
	newFrame.src = jsurl;
	oHead.appendChild(newFrame); 
}
function JsLoader(){
    this.load=function(url,eid){
    var ss=document.getElementsByTagName("script");  
    for(i=0;i<ss.length;i++)
    {   
      if(ss[i].src && ss[i].src.indexOf(url)!=-1)
      {   
        this.onsuccess(); 
        return;   
      }
    }
    s=document.createElement("script");
	if(eid)s.id = eid;
    s.type="text/javascript";  
    s.src=url;
    var head=document.getElementsByTagName("head")[0];  
    head.appendChild(s);  
    var self=this;
    s.onload=s.onreadystatechange=function()
    {
    if(this.readyState && this.readyState=="loading")
      return;   
      self.onsuccess();  
    }
    s.onerror=function(){
    head.removeChild(s);   
    self.onfailure();    } 
    };
    this.onsuccess=function(){}; 
    this.onfailure=function(){};
}
function ShowServerErrorMessage(str, comserver)
{
    var d = document.getElementById(LC_DIV);
    if(d)
    {
        d.innerHTML = "<a href='javascript:void(0)' onclick='alert(&quot;" + getPromptStringAuto(LC_LiveChat) + getPromptStringAuto(LC_InitError) + "\\r\\n\\r\\n" + str + "\\r\\n\\r\\n" + (typeof(LiveChatServer) != 'undefined' && LiveChatServer?LiveChatServer:"LiveChatServer") + " " + getPromptStringAuto(LC_InitError) + (comserver==""?"":"(" + getPromptStringAuto(LC_ServerADD) + comserver + ")") + "&quot;);'>" + getPromptStringAuto(LC_LiveChat) + getPromptStringAuto(LC_InitError) + "</a>";
    }
    else
    {
        alert(getPromptStringAuto(LC_LiveChat) + getPromptStringAuto(LC_InitError) + "\r\n\r\n" + str + "\r\n\r\n" + (typeof(LiveChatServer) != 'undefined' && LiveChatServer?LiveChatServer:"LiveChatServer") + " " + getPromptStringAuto(LC_InitError) + (comserver==""?"":"(" + getPromptStringAuto(LC_ServerADD) + comserver + ")"));
    }
}
function LCRedirect(companyid, websiteid, div, ip, weburl)
{
    InitCompanyV2(companyid, websiteid, div, weburl);
}