

function URLEncode(plaintext)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	//var plaintext = document.URLForm.F1.value;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "%20";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "%20";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	//document.URLForm.F2.value = encoded;
	plaintext = encoded;
	return plaintext;
};

var rf = document.referrer.toString();
var dl = document.location.toString();
var dt = document.title.toString();

rf = URLEncode(rf);
dl = URLEncode(dl);
dt = URLEncode(dt);

var urlstr = "&dt=" + dt + "&dl=" + dl + "&rf=" + rf + "&wsa_custom_str=" + "^^^^";

//-----------------------------------------------------------------

var proactivepopHTML = "<DIV id='layer1_websitealive' style='position:absolute; z-index:10000; background-color:#ccc; border:1px; border-style:solid; border-color:#000000; padding:0px; visibility:hidden;'></DIV>"

document.write(proactivepopHTML);




function callServer(url) {

	var sRn=Math.random();

	var head = document.getElementsByTagName('head').item(0);
	var old  = document.getElementById('vtracker');
	if (old){
		if (old.readyState=="loading"){	//let the old script complete
			return;
		}
		head.removeChild(old);
	}
	try{

		var s	= document.createElement('script');
		url		= url + '&random=' + sRn;
		
		s.src	= url;
		s.type	= 'text/javascript';
		s.defer = true;
		s.id	= 'vtracker';
		void(head.appendChild(s));
		
	}catch(e){
		
	return;
	}
}

		
function processWH()
{	
	

	var url = "http://www.websitealive3.com/1901/visitor/vTrackerSrc.asp?groupid=1901&websiteid=0&departmentid=568&sessionid_=381071918748" + urlstr;
	
	callServer(url);
}		


var timerIDWSA = 0;

//----------------------------------------------------------------------------
// Code to determine the browser and version.
//----------------------------------------------------------------------------

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

function checkLocationWSA(p_top) {
	
	var browser = new Browser();
	
	if (browser.isIE)
		y="document.documentElement.scrollTop";
	
	if (browser.isNS)
		y="window.scrollY";

	yy=eval(y);
	yy = yy + p_top + 'px';
	
	document.getElementById('layer1_websitealive').style.top = yy;
	
	if (timerIDWSA){
		//alert('kill timerIDWSA:' +timerIDWSA);
		clearTimeout(timerIDWSA);
	}
	
	timerIDWSA = setTimeout("checkLocationWSA("+p_top+")",500);
	//alert(timerIDWSA);
}

function startCheckWSA(p_top){
	timerIDWSA = setTimeout("checkLocationWSA("+p_top+")",500);
}

function stopCheckWSA(){
	
	//alert('stopping timerIDWSA:' + timerIDWSA);
	if (timerIDWSA){
		//alert('stopCheckWSA() running on:'+timerIDWSA);
		clearTimeout(timerIDWSA);
		timerIDWSA = 0;
		}
}

function chatInvite(proactiveid,p_left,p_top,p_width,p_height,p_backgroundimage,p_backgroundimage_ssl,p_linebreaks,p_align,p_scrolling,p_version)
{
	if (p_scrolling == 'Y'){
		startCheckWSA(p_top);
	}
	
	var HTML;
	HTML = "";

	if (p_version == '2'){
	
		HTML = HTML + "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr><td width='99%'></td><td width='1%'><img src='http://www.websitealive3.com/1901/misc/close.gif' width='15' height='14' onclick=javascript:stopCheckWSA();window.open('http://www.websitealive3.com/1901/Visitor/vInvite.asp?action=decline&groupid=1901&websiteid=0&departmentid=568&sessionid_=381071918748','popInvite','width=10,height=10');document.getElementById('layer1_websitealive').style.display='none';document.getElementById('layer1_websitealive').style.visibility='hidden'; style='cursor:pointer;'></td></tr><tr><td colspan='2'><img src='http://www.websitealive3.com/1901/misc/spacer.gif' width="+p_width+" height="+p_height+" onclick=javascript:stopCheckWSA();window.open('http://www.websitealive3.com/1901/Visitor/vInvite.asp?action=accept&groupid=1901&departmentid=568&sessionid_=381071918748','popInvite','width=450,height=400');document.getElementById('layer1_websitealive').style.display='none';document.getElementById('layer1_websitealive').style.visibility='hidden'; style='cursor:pointer;'></td></tr></table>"
	
	}else{
	
		for(i = 0; i < p_linebreaks; i++)
		{
			HTML = HTML + "<br>"
		}
		
		HTML = HTML + "<input type='button' style='margin-top:10px;' name='Submit' value='Accept' onclick=javascript:stopCheckWSA();window.open('http://www.websitealive3.com/1901/Visitor/vInvite.asp?action=accept&groupid=1901&websiteid=0&departmentid=568&sessionid_=381071918748','popInvite','width=450,height=400');document.getElementById('layer1_websitealive').style.display='none';document.getElementById('layer1_websitealive').style.visibility='hidden';>&nbsp;<input type='button' style='margin-top:10px;' name='Submit' value='Reject' onclick=javascript:stopCheckWSA();window.open('http://www.websitealive3.com/1901/Visitor/vInvite.asp?action=decline&groupid=1901&departmentid=568&sessionid_=381071918748','popInvite','width=10,height=10');document.getElementById('layer1_websitealive').style.display='none';document.getElementById('layer1_websitealive').style.visibility='hidden';>";
	
	}
	
	var obj;
	obj = document.getElementById("layer1_websitealive");

	if (obj.style.visibility != "visible")
	{
		obj.style.top = p_top + 'px'; 
		obj.style.left = p_left + 'px';	
	
		obj.style.width = p_width + 'px'; 
		obj.style.height = p_height + 'px';

		
			obj.style.backgroundImage = "url("+ p_backgroundimage +")";
		
		
		obj.style.textAlign = p_align;
		obj.style.display = "inline";
		obj.style.visibility = "visible";
		obj.innerHTML = HTML;
	}
	//window.alert(HTML);
}

function chatChat()
{
	var obj;
	obj = document.getElementById("layer1_websitealive");
	obj.style.display = "none";
	obj.style.visibility = "hidden";
}

//This function gets the sessiontimeout set by admin. If visitor has left page open longer then sessiontimeout, then they will stop pinging the server.

function checkProcess(landingTime)
{
	
	var sessiontimeout = 1800;
	
	var newTime = new Date();
	var tDiff = (newTime - landingTime) / 1000; // diff in seconds
	
	//alert(tDiff);
	if ((sessiontimeout == 0) || (sessiontimeout > tDiff))	//if no timeout or still active
	{
		processWH();	//keep processing;
	}else{
		//do nothing		
	}	
	
}

//initial call to vTrackerSrc.
processWH();

//continuous call to vTrackerSrc, if conditions are met.
var landingTime = new Date();
setInterval("checkProcess(landingTime);",8000);