// LOAD VARS ---

var timeOnPage = 1;


// MAIN STATS TRACKING ----

function trackStats(client) {

	var ajax;
	
	try{
		ajax = new XMLHttpRequest();
	} catch (e){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}

	ajax.onreadystatechange = function(){
		if(ajax.readyState == 4){
			//alert(ajax.responseText);
			updateStat(ajax.responseText);
		}
	}

	var thisdate = new Date();
	var timer = thisdate.getTime();
	
	//alert(client);
	
	pageTime();
	
	ajax.open("GET", "statTrack/_trackStats.php?client=" + client + "&page=" + window.location + "&auth=" + timer, true);
	ajax.send(null);

}

// END MAIN TRACK SCRIPT ====


// TIME ON PAGE COUNTER ----

function pageTime() {
	timeOnPage++;
	t=setTimeout("pageTime()",1000) ;
}

// END T.O.P SCRIPT ====


// UPDATE TIME ON PAGE ----

function updateStat(id) {

	var ajax;
	
	try{
		ajax = new XMLHttpRequest();
	} catch (e){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				return false;
			}
		}
	}

	ajax.onreadystatechange = function(){
		if(ajax.readyState == 4){
			setTimeout("updateStat("+id+")", 500);
		}
	}

	var thisdate = new Date();
	var timer = thisdate.getTime();
	
	ajax.open("GET", "statTrack/_updateStat.php?id=" + id + "&time=" + timeOnPage + "&auth=" + timer, true);
	ajax.send(null);

}