var gIni = new IniReader;

function IniReader()
{
	this.sections = new Array();

	this.Init = function()
	{
		var inifile = null;
	
		if(gCommands)
		{
			xhttp = Command("inifile");
			if(xhttp && xhttp.responseText)
			{
				inifile = xhttp.responseText;
			}
		}
		
		this.Parse(inifile);
	}
	
	
	this.Parse = function(inifile)
	{
		if(inifile)
		{
			var section = null;
			var lines = inifile.split(/\n/)
			for(var i = 0; i < lines.length; i++)
			{
				var line = lines[i];
				line = line.trim();
				if(line.charAt(0) == '[' && line.charAt(line.length - 1) == ']')
				{
					section = line.substring(1, line.length - 1).toLowerCase();
				}
				else if(section != null)
				{
					if(line.indexOf("=") != -1)
					{
						var config = line.split("=");
						if(config.length == 2)
						{
							var variableName = config[0].trim().toLowerCase();
							var variable = config[1].trim();
							if(!isNaN(variable))
							{
								variable = parseInt(variable);
							}
							if(!this.sections[section])
							{
								this.sections[section] = new Array();
							}
							this.sections[section][variableName] = variable;
						}
					}
				}
			}
		}
	}
	
	this.Get = function(sectionName, variableName, defaultValue)
	{
		var section = this.sections[sectionName]
		if(section)
		{
			variable = section[variableName];
			if(variable != null)
			{
				return variable;
			}
		}
		
		return defaultValue;
	}
	
	this.Init();
}
