//<script type="text/javascript">
	var UseDebugger = false;
	var KeepAliveActive = true;
	var ShowKeepAliveUI = true;
	var LastPing = new Date();
	var LastStroke = new Date();
	var KeepAliveDuration = 600000;  //In milliseconds 600000 --> 10 Minutes.
	var ForceKillDuration = 1500000 //In milliseconds 1500000 --> 25 Minutes.
	var KeepAliveKillDialogID;


	if(ShowKeepAliveUI){
		document.write('<div id="keepalivedebugger" style="display:none"></div>');
		document.write('<div id="keepalivesession" style="padding-left: 20px; font-size: 80%"></div>');
		document.write('<div id="keepalivekeys" style="padding-left: 20px; font-size: 80%"></div>');
	}

	function KeepAliveRequest(kill){
		KeepAliveDEBUG("KeepAliveRequest Sent: " + LastPing);
		if(KeepAliveActive){
			LastPing = new Date();
			var Path = "https://secure3.convio.net/nccn/admin/AdminHomePage";
			var Args = "pagename=adminabout&mfc_popup=true";
			var TimeDif = window.LastPing.getTime() - window.LastStroke.getTime();
			console.log(TimeDif, " < ", window.KeepAliveDuration, " " ,kill);
			if(TimeDif < window.KeepAliveDuration && kill != "KILL"){
				var KeepAliveRequestObj = new XHR({method: 'get', onSuccess:KeepAliveUpdater}).send(Path,Args);
				if(ShowKeepAliveUI){
					$("keepalivesession").innerHTML = "Keep-Alive Active: " + LastPing + " :: Current ping rate: 1 every " + ((KeepAliveDuration / 1000) / 60) + " minutes -- [<a href=\"javascript:void(0);\" onclick=\"KeepAliveKill();\">Disable</a>]";
				}
			}
			else{
				LastPing = new Date();
				clearInterval(window.KeepAliveID);
				var KeepAliveRequestObj = new XHR({method: 'get', onSuccess:KeepAliveUpdater}).send(Path,Args);
				if(ShowKeepAliveUI){
					$("keepalivesession").innerHTML = "Keep-Alive <b><font color=\"#ff0000\">Disabled</font></b> at " + LastPing + " [<a href=\"javascript:void(0);\" onclick=\"KeepAliveReset(LastPing);\">RE-ENABLE</a>]<div><b>NOTE: You will be required to log in if you've been idle for more than " + ((ForceKillDuration / 1000) / 60) + " minutes since the time indicated.</b></div>";
					$("keepalivekeys").style.display = "none";
				}
				KeepAliveActive = false;
				KeepAliveKillDialogID = setTimeout(keepAliveString,ForceKillDuration); //Activates built-in Convio Keep Alive dialog
			}
		}
	}

	function KeepAliveUpdater(data){
		try{
			console.log("keep alive sent");
		}catch(e){}
	}

	function KeyStrokes(e){
		if(KeepAliveActive){
			LastStroke = new Date();
			if(ShowKeepAliveUI){
				$("keepalivekeys").innerHTML = "Last Action: " + LastStroke;
				$("keepalivekeys").style.display = "block";
			}
		}
	}

	function KeepAliveReset(DisabledAt){
		var ResetDate = new Date();
		var TimeDif = ResetDate.getTime() - DisabledAt.getTime();
		if(TimeDif > window.ForceKillDuration){ location.reload(); }
		else{
			clearTimeout(window.KeepAliveKillDialogID);
			KeepAliveActive = true;
			window.KeepAliveID = setInterval(KeepAliveRequest,KeepAliveDuration);
			window.LastPing = new Date();
			window.LastStroke = new Date();
			KeepAliveRequest();
		}
	}

	function KeepAliveKill(){
		KeepAliveRequest("KILL");
	}

	function KeepAliveDEBUG(info){
		if(UseDebugger && ShowKeepAliveUI){
			$("keepalivedebugger").innerHTML = "<b>Debug Message:</b> " + info;
			$("keepalivedebugger").style.display = "block";
		}
	}

	function DisableConvioKeepAlive(){
		/*	Convio doesn't provide an ID for it's setTimeout function.  It's been requested
				so when it's in, it will go here */
		//clearTimeout(window.consKeepAliveID);

		//Until then, the only way is this sort of hamfisted approach that only sort of works:
		window.keepAliveString = "void(0);";
		window.forceKeepAliveString = "void(0);";
		resetTimeout();
	}

	DisableConvioKeepAlive();
	var KeepAliveID = setInterval(KeepAliveRequest,KeepAliveDuration);
	document.onkeypress = KeyStrokes;
	document.onclick = KeyStrokes;
	document.onload = KeepAliveRequest();

//</script>


