function list_length ( lList, tDelim ) {
	var i, nStart=0, nListLen=1, nLen=lList.length, nDelimLen;
	
	if ( !tDelim )
		var tDelim=",";

	nDelimLen=tDelim.length;
	for ( i = 0; i < nLen; i ++ ) {
		if ( lList.substr ( i, nDelimLen ) == tDelim ) {
			nListLen ++;
			i += ( nDelimLen - 1 );
		}
	}

	return nListLen;
}

function list_get_at ( lList, nIndex, tDelim ) {
	var i, nStart=0, nCurIndex=0, nLen=lList.length, nDelimLen, tReturn="";
	
	if ( !tDelim )
		var tDelim=",";

	nDelimLen=tDelim.length;
	for ( i = 0; i < nLen; i ++ ) {
		if ( lList.substring ( i, i + nDelimLen ) == tDelim ) {
			nCurIndex ++;
			if ( nCurIndex == nIndex ) {
				tReturn = lList.substring ( nStart, i );
				break;
			}
			nStart = i + nDelimLen;
			i += ( nDelimLen - 1 );
		}
	}
	
	if ( tReturn == "" && nIndex == nCurIndex + 1 )
		tReturn=lList.substring ( nStart, i + 1 );
	
	return tReturn;
}

function replace ( string, text, by ) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function strip_chars ( tString, tStripChars ) {
	var i, c, tReturn = "";

    for ( i=0; i < tString.length; i ++ ) {
        c=tString.charAt ( i );
        if ( tStripChars.indexOf ( c ) == -1 )
			tReturn += c;
    }

    return tReturn;
}

function reformat ( tString ) {
	var arg, i, sPos=0, tReturn="";

	for ( i=1; i < reformat.arguments.length; i ++ ) {
		arg = reformat.arguments [ i ];
		if ( i % 2 == 1 )
			tReturn += arg;
		else {
			tReturn += tString.substring ( sPos, sPos + arg );
			sPos += arg;
		}
	}

	return tReturn;
}

// removes leading and trailing spaces from a string

function trim ( tString ) {
	var i, tReturn=tString + "";

	for ( i = 0; i < tReturn.length; i ++ ) {
		if ( tReturn.substring ( i, i + 1 ) != ' ' )
			break;
	}

	if ( i < tReturn.length )
		tReturn = tReturn.substring ( i );
	else
		tReturn = '';
	
	for ( i = tReturn.length - 1; i >= 0; i -- ) {
		if ( tReturn.substring ( i, i + 1 ) != ' ' )
			break;
	}

	if ( i == -1 )
		tReturn = '';
	else
		tReturn = tReturn.substring ( 0, i + 1 );
	
	return tReturn;
}
