<!--
function makeCurrency(dblValue) // assumes the input of a double, rounded to two decimal places
	//Programmers: Clinton T. Graham, Damon M. Titus, John C. Anderson, Greg Simkins - old function
	{
	var strValue;
	strValue = "" + dblValue; // make a string
	if (strValue.indexOf('.') > -1)
		{
		strValue = strValue.substring(0, strValue.indexOf('.') + 3);
		}

	// adds trailing zeroes if necessary
	if (strValue.substring(strValue.length - 3, strValue.length - 2) != '.')  
		{
		if (strValue.substring(strValue.length - 2, strValue.length - 1) == '.')
			{
			strValue += "0";
			}
			else
			{
			strValue += ".00";
			}
		}

		return strValue;
	}

function removeCurrency( strValue ) {
/************************************************
DESCRIPTION: Removes currency formatting from
  source string.

PARAMETERS:
  strValue - Source string from which currency formatting
     will be removed;

RETURNS: Source string with commas, dollar signs and parenthesis removed.
*************************************************/
  var objRegExp = /\(/;
  var strMinus = '';

  //check if negative
  if(objRegExp.test(strValue)){
    strMinus = '-';
  }

  objRegExp = /\)|\(|[,]/g;
  strValue = strValue.replace(objRegExp,'');
  if(strValue.indexOf('$') >= 0){
    strValue = strValue.substring(1, strValue.length);
  }
  return strMinus + strValue;
}

function addCurrency( strValue ) {
/************************************************
DESCRIPTION: Formats a number as currency.

PARAMETERS:
  strValue - Source string to be formatted

REMARKS: Assumes number passed is a valid
  numeric value in the rounded to 2 decimal
  places.  If not, returns original value.
*************************************************/
  var objRegExp = /-?[0-9]+\.[0-9]{2}$/;

    if( objRegExp.test(strValue)) {
      objRegExp.compile('^-');
      strValue = addCommas(strValue);
      if (objRegExp.test(strValue)){
        strValue = '(' + strValue.replace(objRegExp,'') + ')';
      }
 //     return '$' + strValue;
      return strValue;
    }
    else
      return strValue;
}

function addCommas( strValue ) {
/************************************************
DESCRIPTION: Inserts commas into numeric string.

PARAMETERS:
  strValue - source string containing commas.

RETURNS: String modified with comma grouping if
  source was all numeric, otherwise source is
  returned.

REMARKS: Used with integers or numbers with
  2 or less decimal places.
*************************************************/
  var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})');

    //check for match to search criteria
    while(objRegExp.test(strValue)) {
       //replace original string with first group match,
       //a comma, then second group match
       strValue = strValue.replace(objRegExp, '$1,$2');
    }
  return strValue;
}
function sumform(myform)
	{
		var total = 0, val = 0;
		var min = 10; // minimum donation
		var strValue;

		// for each form element
		for (i = 0; i < myform.elements.length; i++) 
		{
			// if that element is a donation amount
			if (myform.elements[i].name.indexOf('price') == 0 || 
				myform.elements[i].name.indexOf('memAmount') == 0) 
			{
				val = removeCurrency(myform.elements[i].value); // remove commas

				val =  val.replace(/[^\d^\.]*/gi,'');  // remove any non-number or not decimal
				val = Math.round(parseFloat(val) * 100) / 100;

				// if a valid number
				if (!isNaN(val)) 
				{
					total = Math.round((total + val) * 100) / 100;
					strValue = makeCurrency(val);
					//myform.elements[i].value = strValue; // redisplay the value, as currency
					myform.elements[i].value = addCommas(strValue); // redisplay the value, as currency with commas
				}
				else
				{
					alert("Sorry, your donation amount is invalid.\nPlease enter a valid number.");
					strValue = makeCurrency(0);
					myform.elements[i].value = strValue; // reset the element to nothing
				}
			}
		}
		if (total >= min) 
		{
			total = makeCurrency(total); // display the total on the form
			myform.totalprice.value = "$ " + addCommas(total); // display the total on the form
		}
		else
		{
			myform.totalprice.value = ""; // reset the element to nothing
			alert("Sorry, there is a minimum total donation of $" + min + ".00.");
		}
}
function validateprice(myform)
{
		var val = 0;
		var strValue;

		if (myform.price.value != '') 
		{
			val = removeCurrency(myform.price.value); // remove commas
			
			val =  val.replace(/[^\d^\.]*/gi,'');  // remove any non-number or not decimal
			val = Math.round(parseFloat(val) * 100) / 100;

			// if a valid number
			if (!isNaN(val)) 
			{
				val = Math.round((val) * 100) / 100;
				strValue = makeCurrency(val);
				//myform.price.value = strValue; // redisplay the value, as currency
				myform.price.value = addCommas(strValue); // redisplay the value, as currency with commas
			}
			else
			{
				alert("Sorry, your donation amount is invalid.\nPlease enter a valid number.");
				strValue = '0.00'; //makeCurrency(0);
				myform.price.value = strValue; // reset the element to nothing
			}
		}
}
// -->

