/******************************************************************************
utilities.js
	Copyright (C) 2007 Atlantic Database Systems, Inc. All rights reserved.
	Define global items.
******************************************************************************/

/******************************************************************************
TrimR (szStr)
	Helper to trim blanks, etc. off the end of a string.
******************************************************************************/

function TrimR (szStr)
{
	while (szStr && szStr.length > 0 && szStr.charAt (szStr.length - 1) <= ' ')
		szStr = szStr.substring (0, szStr.length - 1);

	return szStr;
}

/******************************************************************************
TrimL (szStr)
	Helper to trim blanks, etc. off the front of a string.
******************************************************************************/

function TrimL (szStr)
{
	while (szStr && szStr.length > 0 && szStr.charAt (0) <= ' ')
		szStr = szStr.substring (1);

	return szStr;
}

/******************************************************************************
Trim (szStr)
	Helper to trim blanks, etc. off the front and end of a string.
******************************************************************************/

function Trim (szStr)
{
	return TrimL (TrimR (szStr));
}

/******************************************************************************
TrimLZ (szStr)
	Helper to trim leading zeros off the front of a string.
******************************************************************************/

function TrimLZ (szStr)
{
	while (szStr.length > 1 && (szStr.charAt (0) == '0' || szStr.charAt (0) == ','))
		szStr = szStr.substring (1);

	return szStr;
}

/******************************************************************************
numToString (num, nlz)
	Helper to format a number as a string with leading zeros.
******************************************************************************/

function numToString (num, nlz)
{
	var	szRes = num.toString ();

	while (szRes.length < nlz)
		szRes = '0' + szRes;

	return szRes;
}

/******************************************************************************
addPath (directory, filename)
	Add a file name to a directory.
******************************************************************************/

function addPath (directory, filename)
{
	var	sep = "/";

	if (directory.substr (-1, 1) == "/" || filename.substr (0, 1) == "/")
		sep = "";

	return directory + sep + filename;
}

