
// LIQUID IT Form Tools JavaScript Functions
// © Copyright 2006 by Marc Neureiter
// VERSION INFORMATION: 01.01.2006

function strTrim(str)
{
	if (str.length == 0) return "";
	var cont, pos1 = 0, pos2 = str.length - 1;
	do
	{
		var ch = str.substr(pos1, 1);
		cont = (ch == " " || ch == "\t" || ch == "\r" || ch == "\n");
		pos1++;
	} while (cont);
	if (pos1 <= str.length)
	{
		do
		{
			var ch = str.substr(pos2, 1);
			cont = (ch == " " || ch == "\t" || ch == "\r" || ch == "\n");
			pos2--;
		} while (cont);
	}
	return str.substr(pos1-1, pos2 - pos1 + 3);
}

function numberFormat(value, decdelim, decprecision, decadddigits)
{
	
	if (value == "") return "";
	
	var delimpos = value.indexOf(decdelim);
	var int = "";
	var dec = "";
	var pos = 0;
	if (delimpos == -1)
		int = value;
	else
	{
		int = value.substr(0, delimpos);
		dec = value.substr(delimpos + 1);
		
	}
	if (int != "")
	{
		while (int.substr(pos, 1) == "0") pos++;
		int = int.substr(pos);
	}
	if (dec != "")
	{
		dec = dec.substr(0, decprecision);
		pos = dec.length - 1;
		while (pos >= 0 && dec.substr(pos, 1) == "0") pos--;
		dec = dec.substr(0, pos + 1);
	}
	var ret = "";
	if (decadddigits)
		while (dec.length < decprecision) dec = dec.concat("0");
	if (int == "")
		ret = "0";
	else
		ret = int;
	if (dec != "")
		ret += decdelim + dec;
	return ret;
	
}
