//Copyright (C) Ben Parbury - All Rights Reserved. Unauthorized copying of this file, via any medium is strictly prohibited. Written by Ben Parbury <ben@gridlockinteractive.com> 2014
var gTelemetry = new Telemetry();

function Telemetry()
{
	this.ShouldPost = function()
	{
		if(gIni.Get("game", "telemetry", 0) == 0)
		{
			return false;
		}

		if(gRecordingSystem.IsPlaying())
		{
			return false;
		}
		
		var urlVars = getUrlVars();
		if(urlVars["disablepost"])
		{
			return false;
		}
		
		return true;
	}
	
	this.PostStat = function(statName)
	{
		if(this.ShouldPost())
		{
			var levelName = gLevelSystem.GetLevelName().toLowerCase();
			var levelSet = gLevelSystem.GetLevelSet().toLowerCase();
	
			var formData = new FormData();
			formData.append("levelset", levelSet)
			formData.append("level", levelName)
			formData.append("stat", statName.toLowerCase());
		
			var xmlhttp = GetXMLRequest();
	
			xmlhttp.open("POST", "http://polyology.webfactional.com/telemetry/", true);
			xmlhttp.send(formData);
		}
	}
	
	this.PostGlobalStat = function(statName, value)
	{
		if(this.ShouldPost() && value > 0)
		{
			var formData = new FormData();
			formData.append("stat", statName.toLowerCase());
			formData.append("value", value);
			
			var xmlhttp = GetXMLRequest();
	
			xmlhttp.open("POST", "http://polyology.webfactional.com/globalTelemetry/", true);
			xmlhttp.send(formData);
		}
	}
}
