function MoneyCheckField(eobj, eid, LPos, RPos, Sign) 
{
	message = '';
	if (!MoneyCheck(eobj, eid, LPos, RPos))
	{
		alert(message);
		return (false);
	}
	return (true);
}

function MoneyCheckDefField(eobj, eid, LPos, RPos, Sign) 
{
	if (eobj.value.length == 0)
		eobj.value = 0;
	
	message = '';
	if (!MoneyCheck(eobj, eid, LPos, RPos, Sign))
	{
		alert(message);
		return (false);
	}
	return (true);
}	
//*******************
//** Function - MoneyCheck
//**            
//** Checks to see if the form element is a valid Money number
//** if valid it will format with $ and ,
//**          it will also add . and zero to right of decimal if decimals
//*******************

function MoneyCheck(eobj, eid, LPos, RPos, Sign) 
{
	estring=eobj.value;
	j=0;k=0;x=0;y=0;DecFnd=0;RPosCnt=0;LPosCnt=0;
	errormsg='';
	var ostring= new String();
	var rstring='';

	for (j=0; j < estring.length; j++)
	{
		if ((estring.substring(j, j+1) < "0") ||
		    (estring.substring(j, j+1) > "9"))
		{
			if (estring.substring(j, j+1) == ".")
				x++;
			else
				if (estring.substring(j, j+1) == "$")
					y++;
				else
					if (estring.substring(j, j+1) != ",")
					{
						errormsg = ' must be numeric.';
						break;
					}
					else;
		}
		else
		{
			ostring = ostring + estring.substring(j, j+1);
			if (x == 0)
				LPosCnt++;
			else
				RPosCnt++;
		}
	}

	if (x > 1 || y > 1) 
		errormsg = ' not a valid value.';;

	if (errormsg == '') 
		if (ostring.length > 0)
		{
			if (x == 1 && RPosCnt < RPos)
				for (;RPosCnt < RPos; RPosCnt++)
					ostring =  ostring + '0';
			for (;ostring.length < (RPos + 1); LPosCnt++)
				ostring = '0' + ostring;
			for (;RPosCnt < RPos; LPosCnt--, RPosCnt++);
		}

		if ((estring.length > 0) && (ostring.length == 0))
			errormsg = ' must be numeric.';
		else
		{
			if ((RPosCnt > RPos) || (LPosCnt > LPos))
			{
				errormsg = ' is invalid. Format is ('
				for (j=0; j < LPos; j++)
				{
					if ((LPos-j)%3 == 0 && (j > 0))
						errormsg = errormsg + ',';
					errormsg = errormsg + '9';
				}
				if (RPos > 0)
				{
					errormsg = errormsg + '.';
					for (j=0; j < RPos; j++)
						errormsg = errormsg + '9';
				}
				errormsg = errormsg + ').';
			}
		}
	
	if (errormsg != '')    
	{
		if (message == '')
			eobj.focus();
		message = message + '\n  * ' + eid + errormsg;
		return (false);
	}

	if (eobj.value.length > 0)
	{
		if (y > 0)
			rstring = rstring + '$';

		for (j=0; j < LPosCnt; j++)
		{
			if (((LPosCnt-j)%3 == 0) && (j > 0))
				rstring = rstring + ',';
			rstring = rstring + ostring.substring(j, j+1);
		}
	
		if (RPosCnt > 0)
			rstring = rstring + '.';
			for (j=LPosCnt; j < (RPosCnt+LPosCnt); j++)
				rstring = rstring + ostring.substring(j, j+1);

		eobj.value = rstring;
	}
	
	return (true);
}
//*******************
//** Function - MoneyStrip
//**            
//** Takes a valid money field and removes dollar signs and commas.
//*******************

function MoneyStrip(eobj) 
{
	var estring=eobj.value;
	var ostring='';

	for (j=0; j < estring.length; j++)
	{
		if (((estring.substring(j, j+1) >= "0") && (estring.substring(j, j+1) <= "9")) ||
			(estring.substring(j, j+1) == "."))
			ostring = ostring + estring.substring(j, j+1);
	}
	
	if (ostring.length == 0)
		ostring = '0';
		
	oobj = parseFloat(ostring);

	return (oobj);
}

