// ==============================================================================
// WhosOn LiveStats & Chat Gateway script http://www.whoson.com
// ==============================================================================
// This script should be placed in the root directory of your web site. It should
// be included in each page you want to track.
// Place the Include on your page at the place where you want the Click-To-Chat 
// graphic to appear.
// ===============================================================================

var sWOGateway       = "whoson.equorum.com:8080";    // specify the external address:port of the WhosOn Gateway server
var sWOGatewaySSL    = "whoson.equorum.com:8443"; // specify the external address:port of the WhosOn Gateway server SSL interface
var sWODomain        = "www.equorum.com";  // the domain you are monitoring
var sWODepartment    = ""; // optional department
var sWOChatstart     = "http://whoson.equorum.com/chat/chatstart.htm"; // url to the chatstart.htm page 
var sWOLanguage      = ""; // language for the chat window
var sWOBackgroundURL = ""; // optional custom background url
var sWOResponse      = "Y"; // set to a blank string if you do NOT want a visible chat link
var sWOInvite        = "Y";  // set to a blank string if you do NOT want invite requests to be polled
var sWOPreselect     = ""; // set to D to pre-select Department before starting chat, O to pre-select Operator

var sWOSession;
var sWOUrl;
var sWOUser="";
var sWOPage="";
var sWOProtocol=window.location.protocol;

var sWOStatUrl;  // fbf

// specify a user name here if you want a specific user name instead of a session cookie
// sWOUser="my user";

// specify a page name here if you want a specific page name shown in WhosOn instead of the window.location
// sWOPage="my page";

var sWOCost=0;    // specify a visit cost 
var sWORevenue=0; // specify the revenue generated by the visitor

// optional contact information. Specify values for these variables if you want contact info for the visitor passed to WhosOn
var sWOName="";
var sWOCompany="";
var sWOEmail="";
var sWOTelephone="";

if(sWOUser==""){
	// create a unique session cookie for the visitor
	var dt=new Date();
	var sWOCookie=document.cookie.toString();
	if(sWOCookie.indexOf("whoson")==-1){
		sWOSession=parseInt(Math.random()*1000)+"-"+dt.getTime();
		document.cookie="whoson="+sWOSession+";expires=Fri, 31-Dec-2010 00:00:00 GMT;";
	}
	sWOCookie=document.cookie.toString();
	if(sWOCookie.indexOf('whoson')==-1){
		sWOSession="";
	} else {
		var s=sWOCookie.indexOf("whoson=")+7;
		var e=sWOCookie.indexOf(";",s);
		if(e==-1)e=sWOCookie.length;
		sWOSession=sWOCookie.substring(s,e);
	}
}

if(sWOProtocol=="https:")sWOGateway=sWOGatewaySSL;
if(sWOUser!="")sWOSession=sWOUser;
if(sWOPage=="")sWOPage=escape(window.location);
if(sWOProtocol=="file:")sWOProtocol="http:";

sWOUrl=sWOProtocol+"//"+sWOGateway+"/stat.gif?u="+sWOSession+"&d="+sWODomain;
if(sWODepartment.length>0)sWOUrl+="&t="+escape(sWODepartment);
sWOUrl+="&p='"+sWOPage+"'&r='"+escape(document.referrer)+"'";
if(sWOCost!=0)sWOUrl+="&c="+sWOCost;
if(sWORevenue!=0)sWOUrl+="&v="+sWORevenue;
if(sWOName!="" || sWOCompany!="" || sWOEmail!="" || sWOTelephone!="")sWOUrl+="&n="+sWOName+"|"+sWOCompany+"|"+sWOEmail+"|"+sWOTelephone;

//sWOStatUrl = sWOUrl; // fbf

if(sWOResponse==""){
	if(document.layers)document.write("<layer name=\"WhosOn\" visibility=hide><img src=\""+sWOUrl+"\" height=1 width=1><\/layer>");
	else document.write("<div id=\"WhosOn\" STYLE=\"position:absolute;visibility:hidden;\"><img src=\""+sWOUrl+"\" height=1 width=1><\/div>");
} else {
	sWOUrl+="&response=g";sWOChatstart+="?domain="+sWODomain+"&lang="+sWOLanguage;
	if(sWOBackgroundURL!="")sWOChatstart+="&bg="+sWOBackgroundURL;
	if(sWODepartment.length>0)sWOChatstart+="&dept="+escape(sWODepartment);
	if(sWOPreselect.length>0)sWOChatstart+="&select="+sWOPreselect;
	document.write("<a target=\"_blank\" href=\""+sWOChatstart+"\" onclick=\"javascript:window.open('"+sWOChatstart+"','new_win','width=484,height=361');return false;\"><img border=\"0\" src=\""+sWOUrl+"\"><\/a>");
}
sWOUrl=sWOProtocol+"//"+sWOGateway+"/invite.js?domain="+sWODomain;
if(sWOInvite=="Y")document.write("<sc"+"ript language='Javascript' src='"+sWOUrl+"'><\/scr"+"ipt>");
//
// fbf - added support for recording time for a single page visit.
//function writeWhosOn(sWOGateway,sWODomain,sWOPage)
//{
//	var sWOSession;
//	var sWOUrl;
//	var sWOProtocol=window.location.protocol;
//	var iWO=new Image(1,1);
//
//	// create a unique session cookie for the visitor if not already created
//	var dt=new Date();
//	var sWOCookie=document.cookie.toString();
//	if(sWOCookie.indexOf("whoson")==-1){
//		sWOSession=parseInt(Math.random()*1000)+"-"+dt.getTime();
//		document.cookie="whoson="+sWOSession+";expires=Fri, 31-Dec-2010 00:00:00 GMT;";
//	}
//	sWOCookie=document.cookie.toString();
//	if(sWOCookie.indexOf('whoson')==-1){
//		sWOSession="";
//	} else {
//		var s=sWOCookie.indexOf("whoson=")+7;
//		var e=sWOCookie.indexOf(";",s);
//		if(e==-1)e=sWOCookie.length;
//		sWOSession=sWOCookie.substring(s,e);
//	}
//	if(sWOPage=="")sWOPage=escape(window.location);
//	if(sWOProtocol=="file:")sWOProtocol="http:";
//	sWOUrl=sWOProtocol+"//"+sWOGateway+"/stat.gif?u="+sWOSession+"&d="+sWODomain;
//	sWOUrl+="&p='"+sWOPage+"'&r='"+escape(document.referrer)+"'";
//	iWO.src=sWOUrl;
//	return;
//}
function pingwhoson() {
	sWOStatUrl=sWOProtocol+"//"+sWOGateway+"/stat.gif?u="+sWOSession+"&d="+sWODomain;
	var exitPage = sWOPage + '*EXIT*';
	exitPage = escape(exitPage);
	sWOStatUrl+="&p='"+exitPage+"'&r='"+escape(document.referrer)+"'";
//	var req = Spry.Utils.loadURL("GET", sWOStatUrl, false);
		var iWO=new Image(1,1);
		iWO.src=sWOStatUrl;
}
//var isEventSupported = (function(){
//  var TAGNAMES = {
//    'select':'input','change':'input',
//    'submit':'form','reset':'form',
//    'error':'img','load':'img','abort':'img'
//  }
//  function isEventSupported(eventName) {
//    var el = document.createElement(TAGNAMES[eventName] || 'div');
//    eventName = 'on' + eventName;
//    var isSupported = (eventName in el);
//    if (!isSupported) {
//      el.setAttribute(eventName, 'return;');
//      isSupported = typeof el[eventName] == 'function';
//    }
//    el = null;
//    return isSupported;
//  }
//  
//  return isEventSupported;
//})();
//if(isEventSupported("beforeunload")) {
//try {
	//window.onbeforeunload=pingwhoson;
//	window.onunload=pingwhoson;
//}
//catch(err) {}
//}

//$(document).ready(function(){
//    $(window).bind("beforeunload", pingwhoson);
//});
try {
	window.onbeforeunload=pingwhoson;
}
catch(err) {}

