var startTime = new Date();       
window.onbeforeunload = function(){
  var endTime = new Date();
  var timeSpent = (endTime - startTime);
  if (window.XMLHttpRequest) {
			// code for IE7+, Firefox, Chrome, Opera, Safari
			xmlhttp = new XMLHttpRequest();
  }
  else 
  {
	// code for IE6, IE5
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  
	var url = "tracking.php?time=" + timeSpent +"&page="+window.location+"&sid="+document.cookie.match(/PHPSESSID=[^;]+/);
	xmlhttp.open("GET", url, false);
	xmlhttp.send(null);
}    


