if (typeof(lpServerName) == "undefined") 
	lpServerName = "server.iad.liveperson.net";
if (typeof(lpSkill) == "undefined") 
	skillparam = "";
else
	skillparam = "&skill=" + escape(lpSkill);
if (typeof(lpOperator) == "undefined") 
	operatorParam = "";
else
	operatorParam = "&operator=" + escape(lpOperator);
if (typeof(lpChannel) == "undefined")
	channelParam = "";
else
	channelParam = "&channel=" + escape(lpChannel);
var LPREPSTATEONLINE = "online";
var LPREPSTATEOFFLINE = "offline";
var LPREPSTATEOCCUPIED = "occupied";
var LPREPSTATEUNKNOWN = "unknown";

var lpDOM = (document.getElementById) ? true : false;
var lpIE = (document.all) ? true : false;
var lpMAC_IE = ((navigator.platform) && (navigator.platform.toUpperCase().indexOf("MAC") >= 0) && (lpIE));
var lpFindRepstateImage = new Image();
var LPProtocol = document.location.toString().indexOf("https") == 0 ? "https" : "http";

if ((! lpIE) && (lpDOM))
{
	lpFindRepstateImage = document.createElement('IMG');
	lpFindRepstateImage.style.visibility = "hidden";
	document.body.appendChild(lpFindRepstateImage);
} else
if (lpMAC_IE)
{
	document.writeln("<div style='visibility:hidden'><img src='blank' id='lpFindRepstateImage' name='lpFindRepstateImage'></div>");
	lpFindRepstateImage = document.lpFindRepstateImage;
}

function lpGetDate()
{
	var d = new Date();
	return d.getTime();
}

function lpFindRepstateCheckImage() {
	if (((lpDOM && !lpIE) || (lpMAC_IE)) && (! lpFindRepstateImage.complete))
		return false;
	var imageWidth = lpFindRepstateImage.width;
	if (imageWidth > 0) {
		if (imageWidth == 40) {
			lpNotifyRepstate(LPREPSTATEONLINE);
		} else 
		if (imageWidth == 50) {
			lpNotifyRepstate(LPREPSTATEOFFLINE);
		} else
		if (imageWidth == 60) {
			lpNotifyRepstate(LPREPSTATEOCCUPIED);
		} else
			lpNotifyRepstate(LPREPSTATEUNKNOWN);
		return true;
	}
	return false;
}

function lpFindRepstateLoopImage() {
	if (lpFindRepstateCheckImage())
		return;
	setTimeout("lpFindRepstateLoopImage()", 1000);
}

function lpCheckFindRepstate() {
	lpFindRepstateImage.src = LPProtocol + "://" + lpServerName + "/hc/" + lpNumber + "/?cmd=repstate&site=" + lpNumber + "&useSize=true" + skillparam + operatorParam + channelParam + "&d=" + lpGetDate();
	lpFindRepstateLoopImage();
}
	
function lpNotifyRepstate(state) {
	if (typeof(repStateNotifyFunction) != "undefined")
			repStateNotifyFunction(state);
}

setTimeout("lpCheckFindRepstate()", 500);
