<{include file="header.tpl"}>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="javascript:startLoop();">
<script language="Javascript">
var stoptimer = 0;
var currentsec=0;
var currentmin=0;
var currentmil=0;
var currenthour=0;
var footerloaded = false;
var visitorList = new Array();
var visitorLoopList = new Array();
var parseVisitorList = new Array();

function stopTimer() {
	stoptimer = 1;
	switchDisplay("timerdiv");
}

function startTimer() {
	switchDisplay("timerdiv");
	loopTimer();
}

function loopTimer(){
	currentmil+=1;
	if (currentmil==10){
		currentmil=0;
		currentsec+=1;
	}
	if (currentsec==60){
		currentsec=0;
		currentmin+=1;
	}
	if (currentmin == 60) {
		currenthour +=1;
		currentmin =0;
		currentsec=0;
	}
	Strsec=""+currentsec;
	Strmin=""+currentmin;
	Strmil=""+currentmil;
	if (Strsec.length!=2){
		Strsec="0"+currentsec;
	}
	if (Strmin.length!=2){
		Strmin="0"+currentmin;
	}
	var endval = currenthour+":"+Strmin+ ":"+Strsec;
	document.timerform.timer.value = endval;
	if (stoptimer != 1) {
		setTimeout("loopTimer();", 100);
	}
}


function insertVisitor(visitorsessionid, chatterid, status, department, operator, totaltime, currentpage, browser, country, visstate) {
	var listingObj = browserObject("listingbuffer");
	if (!listingObj)
	{
		return false;
	}
	
	visitorList[visitorsessionid] = [chatterid, totaltime, status, department, operator, currentpage, browser, country, visstate];
	visitorLoopList[visitorLoopList.length] = visitorsessionid;

	var chaticon = getChatIcon(visstate);
	var browsericon = getBrowserIcon(browser);

	var myDiv = document.createElement("div");
	myDiv.setAttribute("id", "div"+visitorsessionid);
	myDiv.innerHTML = '<table width="100%"  border="0" cellspacing="1" cellpadding="0"><tr align="center" bgcolor="#FFFFFF" class="smalltext" height="20"><td width="150"><strong><font color="#666666">'+ chaticon + chatterid +'</font></strong></td><td width="120"><strong><font color="#666666">'+ status +'</font></strong></td><td width="60"><form name="form'+visitorsessionid+'" class="swiftform"><input type="text" name="timer'+ visitorsessionid +'" value="'+ parseTime(totaltime) +'" class="swifttimer" disabled="true"></form></td><td><strong><font color="#666666">'+ browsericon + currentpage +'</font></strong></td><td width="120"><strong><font color="#666666">'+ country +'</font></strong></td></tr></table>';
	listingObj.appendChild(myDiv);
	

	return true;
}


function getChatIcon(visstate)
{
	var chaticon;
	if (visstate == 1)
	{
		chaticon = '<img src="<{$themepath}>icon_yellowdot.gif">&nbsp;';
	} else if (visstate == 2) {
		chaticon = '<img src="<{$themepath}>icon_greendot.gif">&nbsp;';		
	} else if (visstate == 3) {
		chaticon = '<img src="<{$themepath}>icon_reddot.gif">&nbsp;';		
	}

	return chaticon;
}

function getBrowserIcon(browser)
{
	var browsericon;
	if (browser == "IE")
	{
		browsericon = '<img src="<{$themepath}>icon_internetexplorer.gif">&nbsp;';
	} else if (browser == "MO") {
		browsericon = '<img src="<{$themepath}>icon_mozilla.gif">&nbsp;';		
	} else if (browser == "OP") {
		browsericon = '<img src="<{$themepath}>icon_opera.gif">&nbsp;';
	} else if (browser == "SF") {
		browsericon = '<img src="<{$themepath}>icon_safari.gif">&nbsp;';		
	}

	return browsericon;
}

function updateVisitor(visitorsessionid)
{
	if (!visitorList) {
		return false;
	} else if (!visitorList[visitorsessionid]) {
		return false;
	}

	var totaltime = parseTime(visitorList[visitorsessionid][1]);
	eval('document.form'+visitorsessionid+'.timer'+visitorsessionid+'.value = "'+ totaltime +'";');
}

function removeVisitor(visitorsessionid) {
	var listingObj = document.getElementById("listingbuffer");
	if (!listingObj)
	{
		return false;
	}

	var childObj = browserObject("div"+visitorsessionid);
	if (!childObj)
	{
		return false;
	}

	if (!visitorList)
	{
		return false;
	} else if (!visitorList[visitorsessionid]) {
		return false;
	}

	delete visitorList[visitorsessionid];

	// Find index of the visitor sessionid
	for (var i=0;i<visitorLoopList.length;i++)
	{
		var loopvisitorsessionid = visitorLoopList[i];
		if (loopvisitorsessionid = visitorsessionid)
		{
			visitorLoopList.splice(i, 1);
			break;
		}
	}

	listingObj.removeChild(childObj);

	return true;
}

function startLoop() {
	startTimer();
	visitorTimer();
}

function parseVisitor(visitorsessionid, chatterid, state, currentpage, pagetitle, referrer, countryname, browsercode, totaltime, visstate)
{
	if (!parseVisitorList)
	{
		return false;
	}

	parseVisitorList[parseVisitorList.length] = visitorsessionid;

	if (validSessionId(visitorsessionid) == false)
	{
		insertVisitor(visitorsessionid, chatterid, state, "", "", totaltime, currentpage, browsercode, countryname, visstate);		
	}
}

function addFootprint(visitorsessionid, pageurl, referrer)
{
	
}

function updateStaffTree(staffcode)
{
	alert(staffcode);
}

function validSessionId(visitorsessionid)
{
	if (!visitorList[visitorsessionid])
	{
		return false;
	}

	if (visitorList[visitorsessionid][0] != "")
	{
		return true;
	}

	return false;
}

function visitorTimer()
{
	if (!visitorLoopList)
	{
		return false;
	}

	for (var i=0;i<visitorLoopList.length;i++)
	{
		var visitorsessionid = visitorLoopList[i];
		visitorList[visitorsessionid][1]++;
		updateVisitor(visitorsessionid);
	}

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

function parseTime(nSeconds)
{
	var strResult;
	if (nSeconds >= 60)
	{
		var nMin = Math.floor(nSeconds/60);
		var nTrueSeconds = Math.floor(nSeconds-(nMin*60));

		if (nTrueSeconds <= 9)
		{
			var nFormatSeconds = "0"+nTrueSeconds;
		} else {
			var nFormatSeconds = nTrueSeconds;
		}

		if (nMin <= 9)
		{
			var nFormatMinute = "0"+nMin;
		} else {
			var nFormatMinute = nMin;
		}

		strResult = nFormatMinute+":"+nFormatSeconds;
	} else {
		if (nSeconds <= 9)
		{
			strResult = "00:0"+nSeconds;
		} else {
			strResult = "00:"+nSeconds;
		}
	}

	return strResult;
}

function endUpdate()
{
	if (!parseVisitorList)
	{
		return false;
	} else if (parseVisitorList.length == 0) {
		for (var i=0;i<visitorLoopList.length;i++)
		{
			var bVisitorsessionid = visitorLoopList[i];
			removeVisitor(bVisitorsessionid);
		}
	}
	
	for (var i=0;i<visitorLoopList.length;i++)
	{
		// Loop through the parse list and make sure this is in there
		var bVisitorsessionid = visitorLoopList[i];
		var foundVisitor = false;

		for (var x=0;x<parseVisitorList.length;x++)
		{
			if (parseVisitorList[x] == bVisitorsessionid)
			{
				foundVisitor = true;
			}
		}

		if (!foundVisitor)
		{
			removeVisitor(bVisitorsessionid);
		}
	}

	parseVisitorList = new Array();
}

</script>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="6"><img src="<{$themepath}>space.gif" width="1" height="6"></td>
  </tr>
  <tr>
    <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td align="left"><img src="<{$themepath}><{$product}>.gif"></td>
		<td align="right" width="50"><div id="timerdiv" style="display:none"><form name="timerform"><input type="text" name="timer" value="00:00" class="swifttimer" disabled="true"></form></div></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
      <tr height="2">
        <td bgcolor="#3894E5"><img src="<{$themepath}>space.gif" width="1" height="2"></td>
      </tr>
      <tr height="6">
        <td bgcolor="#83BFF5"><img src="<{$themepath}>space.gif" width="1" height="6"></td>
      </tr>
      <tr height="5">
        <td bgcolor="#C3E3FF"><img src="<{$themepath}>space.gif" width="1" height="5"></td>
      </tr>
    </table></td>
  </tr>
</table><br/>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="100%"  border="0" cellspacing="1" cellpadding="0">
      <tr align="center" bgcolor="#80A9EA" class="smalltext" height="20" background="<{$themepath}>tablebg.gif">
        <td width="150"><strong><font color="#FFFFFF">Chatter ID </font></strong></td>
        <td width="120"><strong><font color="#FFFFFF">Status</font></strong></td>
        <td width="60"><strong><font color="#FFFFFF"> Time </font></strong></td>
        <td><strong><font color="#FFFFFF">Current Page </font></strong></td>
        <td width="120"><strong><font color="#FFFFFF">Country</font></strong></td>
      </tr>
    </table><div id="listingbuffer"></td>
  </tr>
</table>
<div style="display: none;" name="iframeblock">
<iframe src="index.php?_m=livesupport&_a=monitorloop&sessionid=<{$sessionid}>" name="loopframe" border="1"></iframe>
</div>
</body>
</html>