/*
'**************************************************************************************************
'File Name:		_Math.js
'Object Type:	Javascript file
'
'Author Name:	Mark E. Watkins - Daugherty Systems, Inc.
'Creation Date:	11/06/2003
'
'Purpose:		Used as a library of functions pertaining to math and numbers.  The file is included 
'				in any pages needing access to its functions.
'
'
'Include Dependencies:
'None.
'
'
'Date Changed		Changed By		Reason
'--------------------------------------------------------------------------------------------------
'
'
'**************************************************************************************************
*/

//
//Variable declarations.

//
//Constant declarations.

///////////////////////////////////////////////////////
//
// FUNCTIONS
//
///////////////////////////////////////////////////////
function parseFloatVL(sNumber) {
	return parseFloat(sNumber.replace(",",""));
}

function isInRange( iNumber, iLow, iHigh ) { 
	//
	//Purpose:
	//Returns whether or not 'iNumber' is within the range
	//of 'iLow' and 'iHigh'.
	//
	if ( isEmpty(iNumber) ) 
		return (isInRange.arguments[1] == true);
	if ( isNaN(iNumber) ) return false;
	if ( isNaN(iLow) ) return false;
	if ( isNaN(iHigh) ) return false;
	//
    return ((iNumber >= iLow) && (iNumber <= iHigh));
}
function formatNumber( poControl, piDecimalPlaces, pbForceLeadingZero ) { 
	//
	//Purpose:
	//Sets the value of 'poControl' formatted as a number.  Formats with _n_ decimal places.
	//
	if ( poControl.value == undefined || poControl.value == "" ) poControl.value = "0";
	if ( piDecimalPlaces == undefined ) piDecimalPlaces = 2;
	if ( pbForceLeadingZero == undefined ) pbForceLeadingZero = false;
	
	//
	//Determine if the control value is empty...if so, set it.
    if ( poControl.value.length == 0 || parseFloat(poControl.value) == 0 ) poControl.value = "0.";
    //
    //Determine if the control value is missing a decimal...if so, append '.00' on the end.
    if ( poControl.value.indexOf(".") == -1 ) poControl.value += ".";
    //
    //Determine if the control value is missing a leading zero and it has been requested to have one.
    if ( pbForceLeadingZero && poControl.value.indexOf(".") == 0 ) poControl.value = "0" + poControl.value;
    //
    //Determine if the control value has only one decimal place...if so, append '0' on the end.
    if ( ((poControl.value.length-1) - poControl.value.indexOf(".")) < piDecimalPlaces ) 
		do { 
			poControl.value += "0";
		} while( ((poControl.value.length-1) - poControl.value.indexOf(".")) < piDecimalPlaces )
}
function formatTextAsNumber( pfValue, piDecimalPlaces, pbForceLeadingZero ) { 
	//
	//Purpose:
	//Sets the value of 'poControl' formatted as a number.  Formats with _n_ decimal places.
	//
	if ( piDecimalPlaces == undefined ) piDecimalPlaces = 2;
	if ( pbForceLeadingZero == undefined ) pbForceLeadingZero = false;
	
	//
	//Determine if the control value is empty...if so, set it.
    if ( pfValue.length == 0 || parseFloat(pfValue) == 0 ) pfValue = "0.";
    //
    //Determine if the control value is missing a decimal...if so, append '.00' on the end.
    if ( pfValue.indexOf(".") == -1 ) pfValue += ".";
    //
    //Determine if the control value is missing a leading zero and it has been requested to have one.
    if ( pbForceLeadingZero && pfValue.indexOf(".") == 0 ) pfValue = "0" + pfValue;
    //
    //Determine if the control value has only one decimal place...if so, append '0' on the end.
    if ( ((pfValue.length-1) - pfValue.indexOf(".")) < piDecimalPlaces ) {
		do { 
			pfValue += "0";
		} while( ((pfValue.length-1) - pfValue.indexOf(".")) < piDecimalPlaces )
	}
	//
	if( pfValue.indexOf("NaN") > -1 )
		pfValue.replace("NaN", "0");
	return pfValue;
}
function roundNumber( pfValue ) {
	//
	//Purpose:
	//Rounds 'pfValue' to the nearest cent.
	//
	pfValue = parseFloat(pfValue);
	
	if( pfValue == 0 )
		return "0.00";
	else
		return formatTextAsNumber((Math.round(pfValue*100)/100).toString(), 2, false);
}
//eof: Mark E. Watkins

/*
function currency(num,currencyFormat){
 file:// currencyFormat = "$";
 num = Math.round(num*100)/100;
 num += "";
 if(num.indexOf(".") != -1){
   num = parseInt(num) + "." + (parseFloat(num) - parseInt(num))*100;
 }else{
   num += ".00"
 }

return (currencyFormat + num);
}


file://
**********************************************************************

function roundTo(num,pow){
  num *= Math.pow(10,pow);
  num = (Math.round(num)/Math.pow(10,pow))+ "" ;
  if(num.indexOf(".") == -1)
    num += "." ;
  while(num.length - num.indexOf(".") - 1 < pow)
    num += "0" ;
  return num ;
}

// Test
alert("$ "+roundTo(123.2,2))
*/