﻿
/**********************************
* String trim prototype function
*
* This code from:
* http://www.nicknettleton.com/zine/javascript/trim-a-string-in-javascript
**********************************/
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/g, ''); }


/******************************************************* 
* Function: resetForm
* Author:  Eric Romanelli
* Date Created: 7-6-07
*
* Empties all text boxes on form, and set all select to 
* index 0 (first entry).  Recommend confirm with user first!
* Changelog:
*******************************************************/
function resetForm() {
	for (i = 0; i < document.forms.length; i++) {
		for (j = 0; j < document.forms[i].length; j++) {
			elm = document.forms[i].elements[j];
			if (elm.type == "text")
				elm.value = "";
			else if (elm.type == "select-one")
				elm.selectedIndex = -1;
		}
	}
}

/******************************************************* 
* Function: parseMoney
* Author:  Eric Romanelli
* Date Created: 7-6-07
*
* Converts a string formatted for currency into a float
*******************************************************/
function parseMoney(str) {
	str = str.replace(/\$|\,/g, '');
	return parseFloat(str);
}

/******************************************************* 
* Function: formatCurrency(int / float)
* Original:  Cyanide_7 (leo7278@hotmail.com) 
* Web Site:  http://www7.ewebcity.com/cyanide7 
*
* This script and many more are available free online at 
* The JavaScript Source!! http://javascript.internet.com 
*******************************************************/
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	
	if (isNaN(num))
		num = "0";
		
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	
	if (cents<10)
		cents = "0" + cents;
		
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));
			
	return (((sign)?'':'-') + num + '.' + cents);
}


