<!--

/*
Calculators
*/

function FormatCurrency(strValue)
{
	var strDecimalSeparator = '.';
	var strThousandSeparator = ',';
	var nPos = strValue.indexOf('.');
	var nNeg = strValue.indexOf('-');
	var nLen = parseInt(strValue, 10).toString().length;

	if (nPos > 0)
		strValue = strValue.substr(0, nPos) + strDecimalSeparator + strValue.substr(nPos + 1, strValue.length - nPos);
	else
		nPos = strValue.length;

	if(nNeg==-1)
	{
		while (nLen > 3)
		{
			nPos -= 3;
			strValue = strValue.substr(0, nPos) + strThousandSeparator + strValue.substr(nPos, strValue.length - nPos + 1);
			nLen -= 3;
		}
	}
	else
	{
		while (nLen > 4)
		{
			nPos -= 3;
			strValue = strValue.substr(0, nPos) + strThousandSeparator + strValue.substr(nPos, strValue.length - nPos + 1);
			nLen -= 3;
		}
	}
          
	return strValue;           
}

function checkValue(thisinput)
{
	thisinput.value = isNaN(parseInt(thisinput.value,10)) ? 0 : parseInt(thisinput.value,10);
}

function validateCurrencyInput(evt)
{
	if(document.all) //it's IE
	{
		var nKeyCode = window.event.keyCode;
		if (nKeyCode != 37 &&                  		// Left cursor
			nKeyCode != 39 &&                  		// Right cursor
			nKeyCode != 8  &&                  		// Backspace
			nKeyCode != 9  &&                  		// Tab
			nKeyCode != 46 &&                  		// Delete
			nKeyCode != 16 &&                  		// Shift
			nKeyCode != 35 &&                  		// End
			nKeyCode != 36 &&                  		// Home
			nKeyCode != 190 &&                  	// .
			(nKeyCode < 96 || nKeyCode > 105) &&  	// 0 - 9 on keypad
			(nKeyCode < 48 || nKeyCode > 57))  		// 0 - 9

			return false;
		else
		{
			return true;
		}
	}
	else if(document.layers) //it's netscape
	{
		// To be fixed in Netscape
		//var nKeyCode = evt.which;
		//if (nKeyCode != 37 &&                  		// Left cursor
		//	nKeyCode != 39 &&                  		// Right cursor
		//	nKeyCode != 8  &&                  		// Backspace
		//	nKeyCode != 9  &&                  		// Tab
		//	nKeyCode != 46 &&                  		// Delete
		//	nKeyCode != 16 &&                  		// Shift
    	//   nKeyCode != 35 &&                  		// End
    	//    nKeyCode != 36 &&                  		// Home
    	//    nKeyCode != 46 &&                  		// .
		//	(nKeyCode < 48 || nKeyCode > 57))  		// 0 - 9

		//	return false;
		//else
		//{
			return true;
		//}
	}
}

// -->

