/***********************************************************************
* Developed By...: Xett Development
* Website........: http://www.xett.com
* Author.........: Jonathan Crossett
* Project........: Webstats
* Last Modified..: 25-May-2005
* Description....: image.php - This is the web bug that ask as the data
*                  collector for the logging engine.  Little data
*                  processing is done here.  Data is passed along to the
*                  engine to parse and store the information
***********************************************************************/

// Set the Client ID different for each website clients
var site_id = 5;

// image.php location (ex. http://webstats.xett.com/v2/image.php)
var image_location = 'http://webstats.xett.com/v2/image.php';

// Taken from http://www.jan-winkler.de/hw/artikel/art_j02.htm
function base64_encode(decStr)
{
	var base64s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
	var bits;
	var dual;
	var i = 0;
	var encOut = '';

	while(decStr.length >= i + 3)
	{
		bits = (decStr.charCodeAt(i++) & 0xff) <<16 |
				(decStr.charCodeAt(i++) & 0xff) <<8 |
				decStr.charCodeAt(i++) & 0xff;

		encOut += base64s.charAt((bits & 0x00fc0000) >>18) +
				base64s.charAt((bits & 0x0003f000) >>12) +
				base64s.charAt((bits & 0x00000fc0) >> 6) +
				base64s.charAt((bits & 0x0000003f));
	}

	if(decStr.length -i > 0 && decStr.length -i < 3)
	{
		dual = Boolean(decStr.length -i -1);

		bits = ((decStr.charCodeAt(i++) & 0xff) <<16) |
				(dual ? (decStr.charCodeAt(i) & 0xff) <<8 : 0);

		encOut += base64s.charAt((bits & 0x00fc0000) >>18) +
				base64s.charAt((bits & 0x0003f000) >>12) +
				(dual ? base64s.charAt((bits & 0x00000fc0) >>6) : '=') +
				'=';
	}
	return(encOut);
}


// Get some javascript variables
var resolution = window.screen.width + 'x' + window.screen.height + 'x' + window.screen.colorDepth + 'bit';
var cookies = (navigator.cookieEnabled) ? 'yes' : 'no';
if (typeof navigator.cookieEnabled == "undefined" && !cookies)
{ 
	document.cookie="testcookie";
	cookies = (document.cookie.indexOf("testcookie") != -1) ? 'yes' : 'no';
}

/**
* Add any extra variables you would like logged by adding 
* &add_data[]=var_name::var_value to the end of the url where var_name is the
* name of the variable you would like to trace, and var_value is the data for
* that variable name.
*
* For clearer reports, you many want to change the value of document.  If left
* with the value of '', the document_url will be used.
*
* Note: Only use add_data[] for data that can only be accessed in javascript
*       such as screen resolution, and if cookies are enabled.
**/
document.write(
  '<img src="' + image_location + '?' +
  'site_id='   + site_id + '&' +
  'doc='       + base64_encode(document.URL) + '&' +
  'ref='       + base64_encode(document.referrer) + '&' +
  'js='        + 'yes&' +
  'cookies='   + cookies + '&' +
  'res='       + resolution +
  '" alt="" width="1" height="1" />'
);