//===============================
// Kayako LiveResponse
// Copyright (c) 2001-2010
// http://www.kayako.com
// License: http://www.kayako.com/license.txt
//===============================

var sessionid_r0a2jpzi = "4lrkcgq534lzpi9zrvi8sjt6y0q57lcr";
var country_r0a2jpzi = "United States";
var countrycode_r0a2jpzi = "us";
var hasnotes_r0a2jpzi = "0";
var campaignid_r0a2jpzi = "";
var campaigntitle_r0a2jpzi = "";
var isfirsttime_r0a2jpzi = 1;
var timer_r0a2jpzi = 0;
var imagefetch_r0a2jpzi = 9;
var updateurl_r0a2jpzi = "";
var screenHeight = window.screen.availHeight;
var screenWidth = window.screen.availWidth;
var colorDepth = window.screen.colorDepth;
var timeNow = new Date();
var referrer = escape(document.referrer);
var windows, mac, linux;
var ie, op, moz, misc, browsercode, browsername, browserversion, operatingsys;
var dom, ienew, ie4, ie5, ie6, moz_rv, moz_rv_sub, ie5mac, ie5xwin, opnu, op4, op5, op6, op7, saf, konq;
var appName, appVersion, userAgent;
var appname = navigator.appName;
var appVersion = navigator.appVersion;
var userAgent = navigator.userAgent;
var dombrowser = "default";
var isChatRunning_r0a2jpzi = 0;
var title = document.title;
var proactiveImageUse_r0a2jpzi = new Image();
windows = (appVersion.indexOf('Win') != -1);
mac = (appVersion.indexOf('Mac') != -1);
linux = (appVersion.indexOf('Linux') != -1);
if (!document.layers) {
	dom = (document.getElementById ) ? document.getElementById : false;
} else {
	dom = false;
}
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
winH = myHeight;
winW = myWidth;
misc=(appVersion.substring(0,1) < 4);
op=(userAgent.indexOf('Opera') != -1);
moz=(userAgent.indexOf('Gecko') != -1);
ie=(document.all && !op);
saf=(userAgent.indexOf('Safari') != -1);
konq=(userAgent.indexOf('Konqueror') != -1);

if (op) {
	op_pos = userAgent.indexOf('Opera');
	opnu = userAgent.substr((op_pos+6),4);
	op5 = (opnu.substring(0,1) == 5);
	op6 = (opnu.substring(0,1) == 6);
	op7 = (opnu.substring(0,1) == 7);
} else if (moz){
	rv_pos = userAgent.indexOf('rv');
	moz_rv = userAgent.substr((rv_pos+3),3);
	moz_rv_sub = userAgent.substr((rv_pos+7),1);
	if (moz_rv_sub == ' ' || isNaN(moz_rv_sub)) {
		moz_rv_sub='';
	}
	moz_rv = moz_rv + moz_rv_sub;
} else if (ie){
	ie_pos = userAgent.indexOf('MSIE');
	ienu = userAgent.substr((ie_pos+5),3);
	ie4 = (!dom);
	ie5 = (ienu.substring(0,1) == 5);
	ie6 = (ienu.substring(0,1) == 6);
}

if (konq) {
	browsercode = "KO";
	browserversion = appVersion;
	browsername = "Konqueror";
} else if (saf) {
	browsercode = "SF";
	browserversion = appVersion;
	browsername = "Safari";
} else if (op) {
	browsercode = "OP";
	if (op5) {
		browserversion = "5";
	} else if (op6) {
		browserversion = "6";
	} else if (op7) {
		browserversion = "7";
	} else {
		browserversion = appVersion;
	}
	browsername = "Opera";
} else if (moz) {
	browsercode = "MO";
	browserversion = appVersion;
	browsername = "Mozilla";
} else if (ie) {
	browsercode = "IE";
	if (ie4) {
		browserversion = "4";
	} else if (ie5) {
		browserversion = "5";
	} else if (ie6) {
		browserversion = "6";
	} else {
		browserversion = appVersion;
	}
	browsername = "Internet Explorer";
}

if (windows) {
	operatingsys = "Windows";
} else if (linux) {
	operatingsys = "Linux";
} else if (mac) {
	operatingsys = "Mac";
} else {
	operatingsys = "Unkown";
}

if (document.getElementById)
{
	dombrowser = "default";
} else if (document.layers) {
	dombrowser = "NS4";
} else if (document.all) {
	dombrowser = "IE4";
}

function browserObject_r0a2jpzi(objid)
{
	if (dombrowser == "default")
	{
		return document.getElementById(objid);
	} else if (dombrowser == "NS4") {
		return document.layers[objid];
	} else if (dombrowser == "IE4") {
		return document.all[objid];
	}
}

function doRand_r0a2jpzi()
{
	var num;
	now=new Date();
	num=(now.getSeconds());
	num=num+1;
	return num;
}

function getCookie_r0a2jpzi(name) {
	var crumb = document.cookie;
	var index = crumb.indexOf(name + "=");
	if (index == -1) return null;
	index = crumb.indexOf("=", index) + 1;
	var endstr = crumb.indexOf(";", index);
	if (endstr == -1) endstr = crumb.length;
	return unescape(crumb.substring(index, endstr));
}

function setCookie_r0a2jpzi(name, value) {
	if(getCookie_r0a2jpzi(name))
	{
	  deleteCookie_r0a2jpzi(name)
	}

	document.cookie = name + '=' + escape(value);
}

function deleteCookie_r0a2jpzi(name) {
	var expiry = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

var autoProactiveDisplayed = parseInt(getCookie_r0a2jpzi('isProactiveDisplayed')) == 1 ? 1 : 0;
function elapsedTime_r0a2jpzi()
{
        if (timer_r0a2jpzi < 3600)
        {
                timer_r0a2jpzi++;
                imagefetch_r0a2jpzi++;

                if (imagefetch_r0a2jpzi > 10) {
                        imagefetch_r0a2jpzi = 0;
                        doStatusLoop_r0a2jpzi();

                                        }
                setTimeout("elapsedTime_r0a2jpzi();", 1000);
        }
}

function doStatusLoop_r0a2jpzi() {
	date1 = new Date();
	updateurl_r0a2jpzi = "http://noc.emagineconcept.com/visitor/index.php?_m=livesupport&_a=updatefootprint&time="+date1.getTime()+"&rand="+doRand_r0a2jpzi()+"&url="+encodeURIComponent(window.location)+"&isfirsttime="+encodeURIComponent(isfirsttime_r0a2jpzi)+"&sessionid="+encodeURIComponent(sessionid_r0a2jpzi)+"&referrer="+encodeURIComponent(document.referrer)+"&resolution="+encodeURIComponent(screenWidth+"x"+screenHeight)+"&colordepth="+encodeURIComponent(colorDepth)+"&platform="+encodeURIComponent(navigator.platform)+"&appversion="+encodeURIComponent(navigator.appVersion)+"&appname="+encodeURIComponent(navigator.appName)+"&browsercode="+encodeURIComponent(browsercode)+"&browserversion="+encodeURIComponent(browserversion)+"&browsername="+encodeURIComponent(browsername)+"&operatingsys="+encodeURIComponent(operatingsys)+"&pagetitle="+encodeURIComponent(title)+"&country="+encodeURIComponent(country_r0a2jpzi)+"&countrycode="+encodeURIComponent(countrycode_r0a2jpzi)+"&hasnotes="+encodeURIComponent(hasnotes_r0a2jpzi)+"&campaignid="+encodeURIComponent(campaignid_r0a2jpzi)+"&campaigntitle="+encodeURIComponent(campaigntitle_r0a2jpzi);
//	alert(updateurl);

	proactiveImageUse_r0a2jpzi = new Image();
	proactiveImageUse_r0a2jpzi.onload = imageLoaded_r0a2jpzi;
	proactiveImageUse_r0a2jpzi.src = updateurl_r0a2jpzi;

//	window.location.href = updateurl_r0a2jpzi;

	isfirsttime_r0a2jpzi = 0;
}

function startChat_r0a2jpzi(proactive)
{
	isChatRunning_r0a2jpzi = 1;

	docWidth = (winW-500)/2;
	docHeight = (winH-480)/2;

	chatwindow = window.open("http://noc.emagineconcept.com/visitor/index.php?_m=livesupport&_a=startclientchat&sessionid="+sessionid_r0a2jpzi+"&proactive="+proactive+"&departmentid=0&randno="+doRand_r0a2jpzi()+"&fullname=&email=","customerchat"+doRand_r0a2jpzi(), "toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=1,width=500,height=480,left="+docWidth+",top="+docHeight);

	hideProactiveChatData_r0a2jpzi();
}

function imageLoaded_r0a2jpzi() {
	if (!proactiveImageUse_r0a2jpzi)
	{
		return;
	}
	proactiveAction = proactiveImageUse_r0a2jpzi.width;

	if (proactiveAction == 3)
	{
		doProactiveForced_r0a2jpzi();
	} else if (proactiveAction == 4) {
		displayProactiveChatData_r0a2jpzi();
	} else {
	}
}

function writeProactiveRequestData_r0a2jpzi()
{
	docWidth = winW-446;
	docHeight = winH-270;
	classData = "DISPLAY: none; FLOAT: left; POSITION: absolute; TOP:"+docHeight+"px; LEFT:"+docWidth+"px; WIDTH: 426px; HEIGHT: 270px; Z-INDEX: 500;";
	writedata = "<style type=\"text/css\"> <!-- #proactivechatdiv { "+classData+" } --> </style>";
	writedata += "<div id=\"proactivechatdiv\" style=\""+classData+"\">";
	writedata += "<div id=\"chartwin\" style=\"width: 426px; height: 270px; position: absolute; position: fixed !important; right: 0px; bottom: 0px;\">	<div style=\"background:url(http://noc.emagineconcept.com/themes/client_default/bg_customerservice1.png); width:426px; height:94px; _background: none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'scale\', src=\'http://noc.emagineconcept.com/themes/client_default/bg_customerservice1.png\');\"></div>	<div style=\" background:url(http://noc.emagineconcept.com/themes/client_default/bg_customerservice2.png); width:426px; height:69px; _background: none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'scale\', src=\'http://noc.emagineconcept.com/themes/client_default/bg_customerservice2.png\');\">		<div style=\" width:102px; height:33px; float:left; margin-top:13px; margin-left:155px; margin-left:155px\\9; *margin-left:155px; _margin-left:78px; _position: relative;\"><a href=\"javascript:doProactiveRequest_r0a2jpzi();\"><img src=\"http://noc.emagineconcept.com/themes/client_default/btn_customerservice1.gif\" title=\"立即交谈\" alt=\"立即交谈\" width=\"102\" height=\"33\" border=\"0\" /></a></div>		<div style=\"width:103px; height:33px;; float:left; margin:13px 0 0 23px; _position: relative;\"><a href=\"javascript:closeProactiveRequest_r0a2jpzi();\"><img src=\"http://noc.emagineconcept.com/themes/client_default/btn_customesrervice0.gif\" alt=\"不用，谢谢！\" title=\"不用，谢谢！\" border=\"0\" /></a></div>	</div>	<div style=\" background-image:url(http://noc.emagineconcept.com/themes/client_default/bg_customesrcervice3.png); width:426px; height:107px; _background: none; _filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=\'true\', sizingMethod=\'scale\', src=\'http://noc.emagineconcept.com/themes/client_default/bg_customesrcervice3.png\');\"></div></div>";
	writedata += "</div>";
	document.write(writedata);
}

function displayProactiveChatData_r0a2jpzi()
{
	writeObj = browserObject_r0a2jpzi("proactivechatdiv");
	if (writeObj)
	{
		docWidth = winW-446;
		docHeight = winH-270;
		writeObj.top = docWidth;
		writeObj.left = docHeight;
	}
	switchDisplay_r0a2jpzi("proactivechatdiv");
}

function hideProactiveChatData_r0a2jpzi()
{
	hideDisplay_r0a2jpzi("proactivechatdiv");
}

function doProactiveForced_r0a2jpzi()
{
	switchDisplay_r0a2jpzi("proactivechatdiv");
	startChat_r0a2jpzi("6");
}

function doProactiveRequest_r0a2jpzi()
{
	startChat_r0a2jpzi("4");
}

function closeProactiveRequest_r0a2jpzi()
{
  setCookie_r0a2jpzi('isProactiveDisplayed', '1');

	rejectProactive = new Image();
	date1 = new Date();
	rejectProactive.src = "http://noc.emagineconcept.com/visitor/index.php?_m=livesupport&_a=resetproactivestatus&time="+date1.getTime()+"&rand="+doRand_r0a2jpzi()+"&sessionid="+sessionid_r0a2jpzi;

	hideProactiveChatData_r0a2jpzi();
}

function switchDisplay_r0a2jpzi(objid)
{
	result = browserObject_r0a2jpzi(objid);
	if (!result)
	{
		return;
	}

	if (result.style.display == "none")
	{
		result.style.display = "block";
	} else {
		result.style.display = "none";
	}
}

function hideDisplay_r0a2jpzi(objid)
{
	result = browserObject_r0a2jpzi(objid);
	if (!result)
	{
		return;
	}

	result.style.display = "none";
}

function resetChatStatus_r0a2jpzi()
{
	isChatRunning_r0a2jpzi = 0;
}

function runURL_r0a2jpzi(url)
{
	runURLImg = new Image();
	date1 = new Date();
	runURLImg.src = url;
}

writeProactiveRequestData_r0a2jpzi();
elapsedTime_r0a2jpzi();
document.write("<a href=\"javascript:startChat_r0a2jpzi(\'0\');\" onMouseOver=\"window.status=\'点击此处获得在线客服帮助\'; return true;\" onMouseOut=\"window.status=\'\'; return true;\"><img src=\"http://noc.emagineconcept.com/themes/client_default/staffonline-zh_CN.gif\" border=\"0\" alt=\"点击此处获得在线客服帮助\" title=\"点击此处获得在线客服帮助\"></a>");
