/*******************************************************************************
* navigator. OBJECT METHODS
* appCodeName 		- The name of the browser's code such as "Mozilla".
* appMinorVersion 	- The minor version number of the browser.
* appName 			- The name of the browser such as "Microsoft Internet Explorer" or "Netscape Navigator".
* appVersion 		- The version of the browser which may include a compatability value and operating system name.
* cookieEnabled 	- A boolean value of true or false depending on whether cookies are enabled in the browser.
* cpuClass 			- The type of CPU which may be "x86"
* mimeTypes 		- An array of MIME type descriptive strings that are supported by the browser.
* onLine 			- A boolean value of true or false.
* opsProfile
* platform 			- A description of the operating system platform. In my case it is "Win32" for Windows 95.
* plugins 			- An array of plug-ins supported by the browser and installed on the browser.
* systemLanguage 	- The language being used such as "en-us".
* userAgent 		- In my case it is "Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)" which describes the browser associated user agent header.
* language			- Returns the default language of the browser version (ie: en-US). NS and Firefox only.
* userLanguage 		- The languge the user is using such as "en-us". IE ONLY
* userProfile
*******************************************************************************/ 

function isCookieEnabled() {
	return navigator.cookieEnabled;
}

function getClientBrowser() {
	var clientBrowser = '';
	if(/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
		var clientBrowser = 'FireFox';
		var version = new Number(RegExp.$1);
	 	if (version>=3) { clientBrowser = clientBrowser+' 3.x' } 
	 	else if(version>=2) { clientBrowser = clientBrowser+' 2.x' } 
	 	else if(version>=1) { clientBrowser = clientBrowser+' 1.x' }
	} else if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
		var clientBrowser = 'IE';
		var version = new Number(RegExp.$1);
	 	if (version>=8) { clientBrowser = clientBrowser+' 8.x' }
	 	else if (version>=7) { clientBrowser = clientBrowser+' 7.x' }
		else if (version>=6) { clientBrowser = clientBrowser+' 6.x' }
		else if (version>=5) { clientBrowser = clientBrowser+' 5.x' }
	} else if(/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)) {
		var clientBrowser = 'Opera';
		var version = new Number(RegExp.$1);
		if (version>=10) { clientBrowser = clientBrowser+' 10.x' }
		else if (version>=9) { clientBrowser = clientBrowser+' 9.x' }
		else if (version>=8) { clientBrowser = clientBrowser+' 8.x' }
		else if (version>=7) { clientBrowser = clientBrowser+' 7.x' }
	} else if(/Safari/.test(navigator.userAgent)) {
		var clientBrowser = 'Safari';
		// TO DO
	} else if(/Chrome/.test(navigator.userAgent)) {
		var clientBrowser = 'Chrome';
		// TO DO
	} else if(/Konqueror/.test(navigator.userAgent)) {
		var clientBrowser = 'Konqueror';
		// TO DO
	} else if(/Netscape/.test(navigator.userAgent)) {
		var clientBrowser = 'Netscape';
		// TO DO
	} else if(/OmniWeb/.test(navigator.userAgent)) {
		var clientBrowser = 'OmniWeb';
		// TO DO
	} else if(/Camino/.test(navigator.userAgent)) {
		var clientBrowser = 'Camino';
		// TO DO
	} else if(/iCab/.test(navigator.userAgent)) {
		var clientBrowser = 'iCab';
		// TO DO
	} else {
		clientBrowser = 'unknown'; 
	}
	return clientBrowser;
}

/*
GEO LOCATION : GOOGLE API

	google.loader.ClientLocation
	# lientLocation.latitude — supplies the low resolution latitude associated with the client's IP address
	# ClientLocation.longitude — supplies the low resolution longitude associated with the client's IP address
	# ClientLocation.address.city — supplies the name of the city associated with the client's IP address
	# ClientLocation.address.country — supplies the name of the country associated with the client's IP address
	# ClientLocation.address.country_code — supplies the name of the ISO 3166-1 country code associated with the client's IP address
	# ClientLocation.address.region — supplies the country specific region name associated with the client's IP address


*/
 
//------------------------------------------------------------------------------

var attached=false;
if(window.attachEvent) { //IE, Opera
	window.attachEvent("onunload", hitUnLoad);
	window.attachEvent("onload", hitLoad);
	var attached=true;
}
if(!attached && window.addEventListener) { //FF, Opera, Google Chrome, Safari
	window.addEventListener("onload", hitLoad, false);
	window.onload = hitLoad;
	window.addEventListener("unload", hitUnLoad, false);
	window.unload = hitUnLoad;
//	window.addEventListener("onunload", hitUnLoad, false);
//	window.onunload = hitUnLoad;
} 

function hitUnLoad() { sendGEvent('UNLOAD', _gtoken); }
function hitLoad() { sendGEvent('LOAD', _gtoken); }

function getGMTOffset() {
	var visitortime = new Date();
	return visitortime.getTimezoneOffset()/60;
}

function sendGEvent(event, token) {
	var xmlHttp;
	try { // Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	} catch(e) { // Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	    } catch(e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				return false;
			}
		}
	}

	url = document.location.href;
	url = url + '+stat';
	url = url + '+event='+event;
	url = url + '+utime='+getGMTOffset();
	url = url + '+token='+token;
	//alert(url);
	xmlHttp.open("GET", url, true);
	xmlHttp.send(null);
}
