/**************************************************************************
/ New Functions adding more functionality. */

// .serializeObject() - Jquery function to convert a form to a JSON format { a:b }
// $.fn.serializeObject = function() {     var o = {};     var a = this.serializeArray();     $.each(a, function() {         if (o[this.name]) {             if (!o[this.name].push) {                 o[this.name] = [o[this.name]];             }             o[this.name].push(this.value || '');         } else {             o[this.name] = this.value || '';         }     });     return o; }; 











/*************************************************************************************
The JavaScript Library V2.0

A recopilation of the best FREE Javascript functions.

The code exposed here has been found all over the Internet and considered Public 
Domain. This library works with browsers that doesnt support javascript

Last Modified: 01/14/2003 Scott Solomon
-->Fixed nested comment in IsChar Function Comment Block
-->Fixed isNumber not being declared
*************************************************************************************/

/**************************************************************
			Available Functions

function DetectBrowser()
function OpenURL(URL, Form)
function DaysInMonth(dDate)
function Abs(Number)
function Len(string)
function Chr(CharCode)
function Asc(string)
function LTrim(String)
function RTrim(String)
function Trim(String)
function Left(String, Length)
function Right(String, Length)
function Mid(String, Start, Length)
function InStr(String1, String2)
function Sgn(Integer)
function LBound(array)
function UBound(array)
function Join(array, Delimiter)
function ReturnString(Number, Character)
function Split(Expression, Delimiter)
function Space(Number)
function Replace(Expression, Find, Replace)
function IsChar(Expression)
function IsNumber(Expression)
function IsAlphanumeric(Expression)
function ReverseString(Expression)
function StrConv(String, Conversion)
function ComboAdd(Object, Value, String)
function ComboDel(Object)
function FormatNumber(Expression, NumDigitsAfterDecimal)
function FormatCurrency(Expression)
function FormatPercent(Expression, NumDigitsAfterDecimal)
function FormatDateTime(DateTime, FormatType)
function Mask(Expression, Mask)
function IsEmail(Expression)
function DayOfWeek(dDate)
function AddDays(DaysToAdd)
function AllowOnly(Expression)
function GeneratePopupMenu(arrMenu, FontFace, FontSize)
function IsDate(dateStr)
function CheckBoxes(f_form, Start, Length, Method)
function DateDiff(Date1, Date2)
function MinutesDiff(Date1, Date2)
**************************************************************/

/**************************************************************
 DetectBrowser: Return a string that contains the current 
                browser name and version used.

 Parameters:

 Returns: String
***************************************************************/
function DetectBrowser()
{
	var temp = navigator.appName;
	temp = temp.toLowerCase();

	if (temp == 'microsoft internet explorer')
		return 'IE' + navigator.appVersion;
	else
		return 'NS' + navigator.appVersion;
}

/**************************************************************
 OpenURL: Return a concatenated string with all the 'objects
          values' contained in a FORM HTML in the format:

 Parameters:
      URL  = URL to redirect
      Form = Form name (be sure not to use QUOTES when passing
             the Form name)

 Returns: URL

 Example: var redirect = OpenURL('mytest.asp', frmMyForm)
          alert(redirect)
          window.nagivate(redirect)
***************************************************************/
function OpenURL(theURL, theForm)
{
	if (theURL.length == 0 || theURL == null)
		return (false);

	var form_length = theForm.elements.length;
	var myform = theForm;
	var mytype = '';
	var temp = theURL + '?';

	for (var i = 0; i < form_length; i++)
	{
		mytype = myform.elements[i].type;
		mytype = mytype.toLowerCase();
		if (mytype == 'text' || mytype == 'hidden' || mytype == 'select-one' ||
		    mytype == 'checkbox' || mytype == 'radio' || mytype == 'select-multiple')
		{
			var t = myform.elements[i].name;
			if (t == null || t == '')
				t = myform.elements[i].id;
			if (mytype == 'text' || mytype == 'hidden')
				temp = temp + t + "=" + escape(myform.elements[i].value);
			else if (mytype == 'checkbox' || mytype == 'radio')
				temp = temp + t + "=" + escape(myform.elements[i].checked);
			else if (mytype == 'select-one' || mytype == 'select-multiple')
				temp = temp + t + "=" + escape(myform.elements[i][myform.elements[i].selectedIndex].value);
			if (i < form_length - 1)
				temp = temp + "&";
		}
	}
	temp = temp.substring(temp, temp.length - 1);

	return temp;
} 

/**************************************************************
 jscrlf: Return Carriage Return + Line Feed

 Returns: Carriage Return + Line Feed
***************************************************************/
function jscrlf()
{
  return Chr(10) + Chr(13);
}

/**************************************************************
 wrapjs: Return wrapped text.

 Parameters:
      itemdesc = String to wrap
      wrapat = Integer of how many chars per line

 Returns: String
***************************************************************/
function WrapJS(itemdesc,wrapat)
{
  if (Len(itemdesc) > wrapat)
	return (Left(itemdesc,wrapat) + jscrlf() + Mid(itemdesc,(wrapat*1)+1,wrapat) + jscrlf() + Mid(itemdesc,(wrapat*2)+1,wrapat));
  else
	return (itemdesc);
}

/**************************************************************
 DaysInMonth: Return number of days in a month.

 Parameters:
      dDate = Date to process. If date is null, false is
              returned.

 Returns: Integer
***************************************************************/
function DaysInMonth(dDate)
{
	if (dDate == null)
		return (false);

	dDate = new Date(dDate);
	var dt1, cmn1, cmn2, dtt, lflag, dycnt;
	var temp1 = dDate.getMonth() + 1;
	var temp2 = dDate.getYear();
	dt1 = new Date(temp2, temp1 - 1, 1);
	cmn1 = dt1.getMonth();
	dtt = dt1.getTime() + 2332800000;
	lflag = true;
	dycnt = 28;
	while (lflag)
	{
		dtt = dtt + 86400000;
		dt1.setTime(dtt);
		cmn2 = dt1.getMonth();
		if (cmn1 != cmn2)
			lflag = false;
		else
			dycnt = dycnt + 1;
	}
	if (dycnt > 31)
		dycnt = 31;

    return dycnt;
}

/**************************************************************
 Abs: Returns a value of the same type that is passed to it 
      specifying the absolute value of a number.

 Parameters:
      Number = The required number argument can be any valid 
               numeric expression. If number contains Null, 
               false is returned; if it is an uninitialized 
               variable, false is returned.

 Returns: Long
***************************************************************/
function Abs(theNumber)
{
	theNumber = theNumber.toLowerCase();
	RefString = "0123456789.-";

	if (theNumber.length < 1) 
		return (false);

	for (var i = 0; i < theNumber.length; i++) 
	{
		var ch = theNumber.substr(i, 1);
		var a = RefString.indexOf(ch, 0);
		if (a == -1)
			return (false);
	}

	if (theNumber < 0)
		return (theNumber * -1);

	return theNumber;
}

/**************************************************************
 Len: Returns a Long containing the number of characters in a 
      string or the number of bytes required to store a 
      variable.

 Parameters:
      string = Any valid string expression. If string contains 
               null, false is returned.

 Returns: Long
***************************************************************/
function Len(theString)
{
	if (theString == null)
		return (false);

	return String(theString).length;
}

/**************************************************************
 Chr: Returns a String containing the character associated 
      with the specified character code.

 Parameters:
      CharCode = Long that identifies a character.

 Returns: String
***************************************************************/
function Chr(CharCode)
{
	return String.fromCharCode(CharCode);
}

/**************************************************************
 Asc: Returns an Integer representing the character code 
      corresponding to the first letter in a string

 Parameters:
      String = The required string argument is any valid 
               string expression. If the string if not in 
               the range 32-126, the function return ZERO

 Returns: Integer
***************************************************************/
function Asc(string)
{
	var symbols = " !\"#$%&'()*+'-./0123456789:;<=>?@";
	var loAZ = "abcdefghijklmnopqrstuvwxyz";
	symbols += loAZ.toUpperCase();
	symbols += "[\\]^_`";
	symbols += loAZ;
	symbols += "{|}~";
	var loc;
	loc = symbols.indexOf(string);
	if (loc > -1)
	{ 
		Ascii_Decimal = 32 + loc;
		return (32 + loc);
	}
	return (0);
}

/**************************************************************
 LTrim: Returns a String containing a copy of a specified 
        string without leading spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function LTrim(theString)
{
	var i = 0;
	var j = theString.length - 1;

	if (theString == null)
		return (false);

	for (i = 0; i < theString.length; i++)
	{
		if (theString.substr(i, 1) != ' ' &&
		    theString.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (theString.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function RTrim(theString)
{
	var i = 0;
	var j = theString.length - 1;

	if (theString == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (theString.substr(j, 1) != ' ' &&
			theString.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (theString.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without both leading and trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function Trim(theString)
{
	if (theString == null)
		return (false);

	return RTrim(LTrim(theString));
}

/**************************************************************
 Left: Returns a String containing a specified number of 
       characters from the left side of a string.

 Parameters:
      String = String expression from which the leftmost 
               characters are returned. If string contains null, 
               false is returned.
      Length = Numeric expression indicating how many characters 
               to return. If 0, a zero-length string ("") is 
               returned. If greater than or equal to the number 
               of characters in string, the entire string is 
               returned. 

 Returns: String
***************************************************************/
function Left(theString, Length)
{
	if (theString == null)
		return (false);

	return theString.substr(0, Length);
}

/**************************************************************
 Right: Returns a String containing a specified number of 
        characters from the right side of a string.

 Parameters:
      String = String expression from which the leftmost 
               characters are returned. If string contains null, 
               false is returned.
      Length = Numeric expression indicating how many characters 
               to return. If 0, a zero-length string ("") is 
               returned. If greater than or equal to the number 
               of characters in string, the entire string is 
               returned. 

 Returns: String
***************************************************************/
function Right(theString, Length)
{
	if (theString == null)
		return (false);

    var dest = '';
    for (var i = (theString.length - 1); i >= 0; i--)
		dest = dest + theString.charAt(i);

	theString = dest;
	theString = theString.substr(0, Length);
	dest = '';

    for (var i = (theString.length - 1); i >= 0; i--)
		dest = dest + theString.charAt(i);

	return dest;
}

/**************************************************************
 Mid: Returns a String containing a specified number of 
      characters from a string

 Parameters:
      String = String expression from which characters are 
               returned. If string contains null, false is 
               returned.
      Start  = Number. Character position in string at which 
               the part to be taken begins. If Start is 
               greater than the number of characters in 
               string, Mid returns a zero-length string ("").
      Length = Number of characters to return. If omitted 
               false is returned. 

 Returns: String
***************************************************************/
function Mid(theString, Start, Length)
{
	if (theString == null)
		return (false);

	if (Start > theString.length)
		return '';

	if (Length == null || Length.length == 0)
		return (false);

	return theString.substr((Start - 1), Length);
}

/**************************************************************
 InStr: Returns a Long specifying the position of the first 
        occurrence of one string within another. Is String1
        or String2 are null, false is returned.

 Parameters:
      String1 = String expression being searched.
      String2 = String expression sought

 Returns: Integer
***************************************************************/
function InStr(String1, String2)
{
	var a = 0;

	if (String1 == null || String2 == null)
		return (false);

	String1 = String1.toLowerCase();
	String2 = String2.toLowerCase();

	a = String1.indexOf(String2);
	if (a == -1)
		return 0;
	else
		return a + 1;
}

/**************************************************************
 Sgn: Returns an Integer indicating the sign of a number. If
      Integer is not a number the functions return false.

 Parameters:
      Integer = The number argument can be any valid numeric 
                expression.

 Returns: Integer       -1 If Integer < 0
                         0 If Integer = 0
                         1 If Integer > 0
                     false If Parameter IS NOT NUMERIC
***************************************************************/
function Sgn(Integer)
{
	Number = Integer.toLowerCase();
	RefString = "0123456789-";

	if (Number.length < 1) 
		return (false);

	for (var i = 0; i < Number.length; i++) 
	{
		var ch = Number.substr(i, 1);
		var a = RefString.indexOf(ch, 0);
		if (a == -1)
			return (false);
	}
	if (Integer < 0)
		return (-1);
	else if (Integer == 0)
		return (0);
	else
		return (1);
}

/**************************************************************
 LBound: Returns a Long containing the smallest available 
         subscript for the indicated dimension of an array

 Parameters:
      array = Array to verify

 Returns: Integer       (-1 if Array does not contain
                            any subscript)
***************************************************************/
function LBound(array)
{
	var i = 0;
	var temp = '';

	if (array.length == 0)
		return (-1);

	for (i = 0; i < array.length; i++)
	{
		temp = array[i];
		if (temp != null)
		{
			var temp = i;
			return temp;
		}
	}
	return (-1);
}

/**************************************************************
 UBound: Returns a Long containing the largest available 
         subscript for the indicated dimension of an array

 Parameters:
      array = Array to verify

 Returns: Integer       (-1 if Array does not contain
                            any subscript)
***************************************************************/
function UBound(array)
{
	return (array.length - 1);
}

/**************************************************************
 Join: Returns a string created by joining a number of 
       substrings contained in an array.

 Parameters:
      array     = One-dimensional array containing substrings 
                  to be joined
      Delimiter = String character used to separate the 
                  substrings in the returned string. 
                  If delimiter is a zero-length string (""), 
                  all items in the list are concatenated 
                  with no delimiters. 

 Returns: String
***************************************************************/
function Join(array, Delimiter)
{
	var temp = '';

	if (array.length == 0)
		return '';

	if (Delimiter.length == 0)
		Delimiter = ' ';

	for (var i = 0; i < array.length; i++)
	{
		temp = temp + array[i];
		if (i < array.length - 1)
			temp = temp + Delimiter;
	}
	return temp;
}

/**************************************************************
 ReturnString: Returns a String containing a repeating 
               character string of the length specified

 Parameters:
      Number    = Length of the returned string. If number 
                  is less than 1, false is returned.
      Character = Character code specifying the character or 
                  string expression whose first character is 
                  used to build the return string. If character 
                  contains null, false is returned. 

 Returns: String
***************************************************************/
function ReturnString(theNumber, Character)
{
	var temp = '';

	if (theNumber < 1)
		return (false);

	if (Character.length == 0)
		return (false);

	if (Character.length > 1)
		Character = Character.charAt(0);

	for (var i = 0; i < theNumber; i++)
	{
		temp = temp + Character;
	}

	return temp;
}

/**************************************************************
 Split: Returns a zero-based, one-dimensional array containing 
        a specified number of substrings

 Parameters:
      Expression = String expression containing substrings and 
                   delimiters. If expression is a zero-length 
                   string(""), Split returns an empty array, 
                   that is, an array with no elements and no 
                   data.
      Delimiter  = String character used to identify substring 
                   limits. If delimiter is a zero-length 
                   string (""), a single-element array 
                   containing the entire expression string 
                   is returned.

 Returns: String
***************************************************************/
function Split(Expression, Delimiter)
{
	var temp = Expression;
	var a, b = 0;
	var array = new Array();

	if (Delimiter.length == 0)
	{
		array[0] = Expression;
		return (array);
	}

	if (Expression.length == '')
	{
		array[0] = Expression;
		return (array);
	}

	Delimiter = Delimiter.charAt(0);

	for (var i = 0; i < Expression.length; i++) 
	{
		a = temp.indexOf(Delimiter);
		if (a == -1)
		{
			array[i] = temp;
			break;
		}
		else
		{
			b = (b + a) + 1;
			var temp2 = temp.substring(0, a);
			array[i] = temp2;
			temp = Expression.substr(b, Expression.length - temp2.length);
		}
	}

	return (array);
}

/**************************************************************
 Space: Returns a String consisting of the specified number 
        of spaces

 Parameters:
      Number = Number of spaces you want in the string.

 Returns: String
***************************************************************/
function Space(theNumber)
{
	var temp = '';

	if (theNumber < 1)
		return '';

	for (var i = 0; i < theNumber; i++)
	{
		temp = temp + ' ';
	}
	return temp;
}

/**************************************************************
 Replace: Returns a string in which a specified substring has 
          been replaced with another substring a specified 
          number of times.

 Parameters:
      Expression = String expression containing substring to 
                   replace
      Find       = Substring being searched for.
      Replace    = Replacement substring.

 Returns: String
***************************************************************/
function Replace(Expression, Find, Replace)
{
	var temp = Expression;
	var a = 0;

	for (var i = 0; i < Expression.length; i++) 
	{
		a = temp.indexOf(Find);
		if (a == -1)
			break;
		else
			temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}

	return temp;
}

/**************************************************************
 IsChar: Returns a Boolean value indicating whether an 
         expression can be evaluated as a character (this 
         not only includes alpha chars but all symbols such as
         

 Parameters:
    - Expression = Variant containing a numeric expression or 
                   string expression.

 Returns: Boolean
***************************************************************/
function IsChar(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789";

	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1);
		var a = RefString.indexOf(ch, 0);
		if (a != -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 IsNumber: Returns a Boolean value indicating whether an 
           expression can be evaluated as a number (this
           includes values like $15,656.00)

 Parameters:
      Expression = Variant containing a numeric expression or 
                   string expression.

 Returns: Boolean
***************************************************************/
function IsNumber(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789.-";

	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1);
		var a = RefString.indexOf(ch, 0);
		if (a == -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 IsAlphanumeric: Returns a Boolean value indicating whether an 
                 expression can be evaluated as a number or
                 char.

 Parameters:
      Expression = Variant containing a numeric expression or 
                   string expression.

 Returns: Boolean
***************************************************************/
function IsAlphanumeric(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "abcdefghijklmnopqrstuvwxyz0123456789 ";

	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1);
		var a = RefString.indexOf(ch, 0);
		if (a == -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 ReverseString: Returns a string in which the character order 
                of a specified string is reversed

 Parameters:
      Expression = The expression argument is the string whose 
                   characters are to be reversed. If expression 
                   is a zero-length string (""), a zero-length 
                   string is returned. If expression is null,
                   false is returned.

 Returns: String
***************************************************************/
function ReverseString(Expression)
{
	if (Expression == null)
		return (false);

    var dest = '';
    for (var i = (Expression.length - 1); i >= 0; i--)
		dest = dest + Expression.charAt(i);
    return dest;
}

/**************************************************************
 StrConv: Returns a String converted as specified in the
          Parameters Section.

 Parameters:
      String     = String expression to be converted.
      Conversion = Number specifying the type of conversion 
                   to perform.
                   1 = TO UPPER CASE
                   2 = to lower case
                   3 = To Proper Case
                   If Conversion is null or not specified 1
                   is set as default.

 Returns: String
***************************************************************/
function StrConv(theString, Conversion)
{
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;

	if (Conversion == null || Conversion.length == 0)
		Conversion = '1';

	if (Conversion != '1' && Conversion != '2' && Conversion != '3')
		Conversion = '1';

	if (Conversion == '1')
		return theString.toUpperCase();

	if (Conversion == '2')
		return theString.toLowerCase();

	//Proper Case
	tmpStr = theString.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)
	{
		for (index = 0; index < strLen; index++)
		{
			if (index == 0)
			{
				tmpChar = tmpStr.substring(0, 1).toUpperCase();
				postString = tmpStr.substring(1, strLen);
				tmpStr = tmpChar + postString;
			}
			else
			{
				tmpChar = tmpStr.substring(index, index + 1);
				if (tmpChar == " " && index < (strLen - 1))
				{
					tmpChar = tmpStr.substring(index + 1, index + 2).toUpperCase();
					preString = tmpStr.substring(0, index + 1);
					postString = tmpStr.substring(index + 2,strLen);
					tmpStr = preString + tmpChar + postString;
				}
			}
		}
	}
	return tmpStr;
}

/**************************************************************
 ComboAdd: Add a new item to a SELECT HTML object at runtime.

 Parameters:
      Object = SELECT Object ID
      Value  = Value of the String ... option VALUE="?????"....option
      String = String to add.

 Returns: None
***************************************************************/
function ComboAdd(theObject, Value, theString)
{
	Value = Trim(Value);
	theString = Trim(theString);
	
	if (Value.length < 1 || theString.length < 1)
		return false;

	theObject[theObject.length] = new theObject(theString, Value);
	theObject.selectedIndex = theObject.length;

	return true;
}

/**************************************************************
 FormatNumber: Returns an expression formatted as a number.

 Parameters:
      Expression            = Expression to be formatted.
      NumDigitsAfterDecimal = Numeric value indicating how
                              many places to the right of the
                              decimal are displayed.

 Returns: String
***************************************************************/
function FormatNumber(Expression, NumDigitsAfterDecimal)
{
	var iNumDecimals = NumDigitsAfterDecimal;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal;
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals);
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-" + strWhole + "." + strDec;
	}
	else
	{
		return strWhole + "." + strDec;
	}
}

/**************************************************************
 FormatCurrency: Returns an expression formatted as a currency 
                 value using the currency symbol $.

 Parameters:
      Expression = Expression to be formatted.

 Returns: String
***************************************************************/
function FormatCurrency(Expression)
{
	var iNumDecimals = 2;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal;
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals);
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (strWhole=="") {
		strWhole = "0";
		}
	if (bNegative)
	{
		return "-$" + strWhole + "." + strDec;
	}
	else
	{
		return "$" + strWhole + "." + strDec;
	}
}
