/*
Activehits script created by physicsguytt
*/

//This function gets the script parameters
function get_script_param(url) {
	url=url.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  //Fixes the URL
	var regex=new RegExp("[\\?&]"+url+"=([^&#]*)");  //Regular Expression for selecting anything after a ? or &
	var results=regex.exec(document.getElementById("activehits").src);  //The script must have an ID of 'activehits' for this part of the script to work
	if(results==null){return null;}
  	else {return results[1];}
}
function setCookie(c_name,value,exdays) {  //This function sets a cookie.  Copied from W3Schools
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
setCookie("javascript_enabled",1,1); //Call the function, this will allow PHP to know if javascript is enabled or not
//Every time the page loads call this function.  This function adds a hit to the hit counter.
window.onload=function() {
	if (!get_script_param("nohit")) {  //If we told the script not to record hits from this page...
	    var xmlhttp;  
	    if(window.XMLHttpRequest) {xmlhttp = new XMLHttpRequest();}  
	    else {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}  
	    xmlhttp.open("GET", "control.php?sendhit=true", false);
	    xmlhttp.send();
	    document.getElementById("activehits_hits").innerHTML=xmlhttp.responseText; //Display the hits to the users
	}
}
//Shows how many hits there are (without this, you'd have to refresh the page to see how many hits there were since you last refreshed it, not
//making the script very 'active'...
function showHits() {
	//Basically, this is the same thing as above
	var xmlhttp;  
    if(window.XMLHttpRequest) {xmlhttp = new XMLHttpRequest();}  
    else {xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");}  
    xmlhttp.open("GET", "control.php?gethits="+Date.now(), false);  //Very simply echoes out the contents of the hits file, and sends it back here
    xmlhttp.send();
    document.getElementById("activehits_hits").innerHTML=xmlhttp.responseText;
}
setInterval("showHits()",5000); //Remember, the more the refreshes, the harder it is on your server!  This number is in milliseconds, default is
//1000, meaning '1 second'.  So, every 1 second, the number on remote browsers will update to show your hit.

