function CProperties()
{
	this.Properties = new Array();
	this.PropHash = new Array();
	this.ChemProp = new Array();
	this.ChemHash = new Array();
	this.Types = new Array();
	
	this.A = AddProperty;
	this.C = AddChemProp;
	this.P = AddParent;
	this.Get = GetProperty;
	
	this.ChemQuali = new Array();
	this.ChemQuali[0] = new CQualiProp(0, "Non Satisfactory", '', '');
	this.ChemQuali[1] = new CQualiProp(1, "Limited", '', '');
	this.ChemQuali[2] = new CQualiProp(2, "Satisfying", '', '');
}
function AddProperty(id)
{
	var index = this.Properties.length;
	this.Properties[index] = new CProperty(AddProperty.arguments);
	this.PropHash[id] = index;
}
function AddChemProp(id)
{
	var index = this.ChemProp.length;
	var prop = new CProperty(AddChemProp.arguments);
	prop.QualiProp = p.ChemQuali;
	this.ChemProp[index] = prop;
	this.ChemHash[-id] = index;
}
function AddParent(parent)
{
	var args = AddParent.arguments;
	for (var i=1; i<args.length; i++)
	{
		this.Types[args[i]] = parent;
	}
}
function GetProperty(id)
{
	if (id > 0)
		return this.Properties[this.PropHash[id]];
	else
		return this.ChemProp[this.ChemHash[-id]];
}
function CProperty(args)
{
	//var args = CProperty.arguments;
	//id, type, parentid, name, description, quantiprop
	this.Id = args[0];
	this.Type = args[1];
	this.ParentId = args[2];

	this.Name = args[3];
	this.ListName = this.Name;
	this.FullName = this.Name;
	if (this.ParentId != 0)
	{
		var parent = p.Get(this.ParentId);
		parent.QualiProp = new Array();
		this.FullName = parent.FullName +  ">>" + this.Name;
		for (var i=0; i<this.FullName.split(">>").length; i++)
			this.ListName = "...." + this.ListName;
	}
	this.Definition = args[4];
	this.Description = args[5];
	this.MinValue = args[6];
	this.MaxValue = args[7];
	this.Unit = args[8];
	this.QuantiProp = args[9];
	this.QualiProp = new Array();
	this.QualiHash = new Array();

	for (var i=0; i<args.length-10; i=i+4)
	{
		this.QualiProp[i/4] = new CQualiProp(args[i+10], args[i+11], args[i+12], args[i+13]);
		this.QualiHash[this.QualiProp[i/4].Id] = i/4;
	}
	
	this.Get = GetQualiProp;
	this.IsType = IsType;
	this.GetComments = GetDefinition;
}
function GetQualiProp(id)
{
	if (this.Id < 0)
		return this.QualiProp[id];
	else
		return this.QualiProp[this.QualiHash[id]];
}
function GetDefinition(isMetric)
{
	var ret = this.Definition;
	if (this.MinValue != null && this.MaxValue != null)
	{
		ret += " (between ";
		if (isMetric)
		{
			ret += this.MinValue + " and " + this.MaxValue + " " + this.Unit;
		}
		else
		{
			var v = u.Convert(this.Unit, 1);
			ret += (Math.round(eval(u.Convert(this.Unit, this.MinValue).Value)*1000)/1000) + " and " + (Math.round(eval(u.Convert(this.Unit, this.MaxValue).Value)*1000)/1000) + " " + v.Unit;
		}
		ret += ")";
	}
	return ret;
}
function IsType(type)
{
	if (this.Type == type)
	{
		return true;
	}
	else if (p.Types[type] == this.Type)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function CQualiProp(id, name, minvalue, maxvalue)
{
	this.Id = id;
	this.Name = name;
	this.MinValue = minvalue;
	this.MaxValue = maxvalue;
}
function CQuantiProp(id, quali)
{
	this.Id = id;
	this.Quali = quali;
}
function CUnitList()
{
	this.Unit = new Array();
	this.A = AddUnit;
	this.Convert = lConvert;
}
function AddUnit(m, e, me, em) //m=metric ; e=english
{
	this.Unit[this.Unit.length] = new CUnit(m, e, me, em);
}
function cVal(t, v)
{
	this.Unit = t;
	this.Value = v;
}
function lConvert(unit, val)
{
	for (var i=0; i<this.Unit.length; i++)
	{
		var t = this.Unit[i];
		if (t.Metric == unit)
			return new cVal(t.English, t.MtoE(val));
		else if (t.English == unit)
			return new cVal(t.Metric, t.EtoM(val));
	}
	return new cVal(unit, val);
}
function CUnit(e, m, me, em)
{
	this.English = e;
	this.Metric = m;
	this.MetricToEnglish = me;
	this.EnglishToMetric = em;
	this.MtoE = uMtoE;
	this.EtoM = uEtoM;
}
function uMtoE(val)
{
	return eval(this.MetricToEnglish.replace("{0}", val));
}
function uEtoM(val)
{
	return eval(this.EnglishToMetric.replace("{0}", val));
}
var p = new CProperties();
var u = new CUnitList();
var n = '';