/*function Function().prototype.StName()
{
	var st;
	st = this.toString();
	st = st.substring(st.indexOf(" ")+1, st.indexOf("("))
	return st;
}

function Function.prototype.DeriveFrom(fnBase)
{
	var prop;
	if (this == fnBase)
	{
		alert("Error - cannot derive from self");
		return;
	}
	for (prop in fnBase.prototype)
	{
		if (typeof(fnBase.prototype[prop]) == "function" && !this.prototype[prop])
		{
			this.prototype[prop] = fnBase.prototype[prop];
		}
	}
	this.prototype[fnBase.StName()] = fnBase;
}*/

var dmw;
var dm_enabled = false;

function dm(m)//debug message
{
	if(!dm_enabled)
	{
		return(0);
	}
	if(dmw)
	{
		if(dmw.closed)
		{
			dmw = null;
		}
	}
	if(!dmw)
	{
		dmw = window.open("dm.htm", "dw", "left=0,top=0,width=500,height=700");
	}
	if(dmw)
	{
		/*var b = dmw.document.getElementById("b");
		if(b)
		{
			b.innerHTML+= m + "<br>";
			return(0);
		}*/
		if(dmw.AddDM)
		{
			dmw.AddDM(m);
		}
		else
		{
			var js = "dm('" + m + "');";
			window.setTimeout(js, 100, "JavaScript");
		}
	}
	return(-1);
}

function em(m)//error message
{
	dm("ERROR " + m);
}

function im(m)//info message
{
	//return(0);
	dm("INFO " + m);
}

//em("valami");
//im("valami2");
//dm("valami3");

function GetObjByID(ID)
{
	return(document.getElementById(ID));
}

function C_MeasurementUnit(name)
{
	var l_name;
	this.GetName = GetName;
	this.SetName = SetName;
	this.GetValue = GetValue;
	this.SetName(name);
	
	function GetName()
	{
		return(this.l_name);
	}
	
	function SetName(name)
	{
		this.l_name = name;
	}
	
	function GetValue(value)
	{
		return(value.toString() + this.GetName());
	}
}

/*function C_MU_PX()
{
	this.C_MeasurementUnit("px");
}

C_MU_PX.DeriveFrom(C_MeasurementUnit);

mu_px = new C_MU_PX();*/
mu_px = new C_MeasurementUnit("px");
//mu_in = new C_MeasurementUnit("in");
//alert(mu_px.GetName());
//alert(mu_px.l_name());
//alert(mu_px);

var Units = new Array(mu_px);
//var Units = new Array(mu_px, mu_in);

function C_MeasuredValue(defaultUnit)
{
	var l_value;
	var l_unit;
	var l_defaultUnit;
	this.CreateByValue = CreateByValue;
	this.CreateByString = CreateByString;
	this.GetValue = GetValue;
	this.SetValue = SetValue;
	this.GetUnit = GetUnit;
	this.SetUnit = SetUnit;
	this.GetMeasuredValue = GetMeasuredValue;
	this.l_defaultUnit = defaultUnit;
	
	function CreateByValue(value, unit)
	{
		this.SetValue(value);
		this.SetUnit(unit);
		return(0);
	}
	
	function CreateByString(str)
	{
		str = str.toString();
		var strLength;
		strLength = str.length;
		if(!str || strLength < 1)
		{
			return(-1);
		}
		var value;
		var unitName;
		var strUnitName;
		var unit;
		var unitNameLength;
		var strLWOUN;//strLengthWithoutUnitName;
		for(var i = 0; i < Units.length; i++)
		{
			unit = Units[i];
			unitName = unit.GetName();
			unitNameLength = unitName.length;
			strLWOUN = strLength - unitNameLength;
			//alert(str);
			if(unitNameLength < strLength)
			{
				strUnitName = str.substr(strLWOUN, unitNameLength);
				//alert(strUnitName);
				if(strUnitName == unitName)
				{
					value = str.substr(0, strLWOUN).valueOf();
					return(this.CreateByValue(value, unit));
				}
			}
		}
		if(this.l_defaultUnit)
		{
			return(this.CreateByValue(str.valueOf(), this.l_defaultUnit));
		}
		return(-2);
	}
	
	function GetValue()
	{
		return(this.l_value);
	}
	
	function SetValue(value)
	{
		this.l_value = value.valueOf();
	}
	
	function GetUnit()
	{
		return(this.l_unit);
	}
	
	function SetUnit(unit)
	{
		this.l_unit = unit;
	}
	
	function GetMeasuredValue()
	{
		if(this.l_unit)
		{
			return(this.l_unit.GetValue(this.l_value));
		}
		return(null);
	}
}

/*mv = new C_MeasuredValue(mu_px);
//mv.CreateByString("500");
//mv.CreateByString(500);
mv.CreateByString(new Number("500"));
alert(mv.GetValue());*/
//alert(mv.GetUnit().GetName());
