// webchat_report_hit.js
// -----------------------------------------------------------------------------
// Report page visit to Chat Server, and - if sWOInvite is ste to 'Y' -
// poll for Chat Invites sent to the visitor
//
// Project    > dmClubNewYear08:C37
// Copyright  > (C) Digital Mail Limited (2005-2008)
// Author     > RAK for DML
// -----------------------------------------------------------------------------

var sWOGateway       = dmx_chatserver + ':8080'; // specify the address:port of the WhosOn Gateway server
var sWOGatewaySSL    = dmx_chatserver + ':8443'; // specify the address:port of the WhosOn Gateway server SSL interface
var sWODomain        = document.domain;  // the domain you are monitoring
var sWODepartment    = ''; // optional department
var sWOChatstart     = 'http://' + dmx_chatserver + '/chat/chatstart.htm'; // url to the chatstart.htm page 
var sWOLanguage      = 'en'; // language for the chat window
var sWOBackgroundURL = ''; // optional custom background url
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 = dmb1_session_ref.length > 0 ? dmb1_session_ref.substring(0, 23) : 'UNKNOWN';
var sWOPage = window.location.pathname.substring(1) + '?dmb1_SessRef=' + dmb1_session_ref + '_c';
var sWOProtocol = window.location.protocol;

var sWOCost=0;    // specify a visit cost 
// var sWORevenue= typeof dmx_init_response != 'undefined' ? dmx_init_response.QntItems : 0; // specify the revenue generated by the visitor
var sWORevenue=0; // specify the revenue generated by the visitor

// -----------------------------------------------------------------------------

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 (dmb1_session_ref.slice(-2) != '_c') {
	document.write("<div id=\"WhosOn\" STYLE=\"position:absolute;visibility:hidden;\"><img src=\""+sWOUrl+"\" height=1 width=1><\/div>");
	sWOUrl=sWOProtocol + '//' + sWOGateway + '/invite.js?domain=' + sWODomain;
}

if (sWOInvite == 'Y') {
	var domain = document.domain;
	var bg_img = 'http://' + domain + '/dmx/core/webchat/images/chat_bg.jpg';
	document.write('<script language="javascript" src="/dmx/core/webchat/js/webchat_invite.js"><\/script>');
}
