/*
	map.string.js
	
	functions for parsing and modifying strings
	
*/

// DEFINE STRING CLASS
stringClass = function() {}; // empty class constructor


//*****************************************************************************
// BEGIN STRING METHODS
//*****************************************************************************


//*****************************************************************************
// FORMATCURRENCY
//*****************************************************************************

//formatCurrency returns a string in USD format with two decimals in all cases
//should be replaced by dojo.i18n.currency.format when that works, or call it when it works

stringClass.prototype.formatCurrency = function(data) { //version 1.0
	var numString = new String(data);
	if(isNaN(parseFloat(numString))){
		return data;
	}
	var before = numString;
	var after = "00";
	if(numString.indexOf(".") > -1){
		before = numString.split(".")[0];
		after = numString.split(".")[1];
	}
	var commaRegEx  = new RegExp('(-?[0-9]+)([0-9]{3})');
    	while(commaRegEx.test(before)) {
    		before = before.replace(commaRegEx, '$1,$2');
    	}
	while(after.length < 2){
		after = after+"0";
	}
	if(after.length > 2){
		after = after.substring(0,2);
	}
	return "$" + before + "." + after;
}

// END FORMATCURRENCY
//*****************************************************************************


/*****************************************************************************************/
// FUNCTION REPLACERETURNS
/*****************************************************************************************/

/*
   replaces newline characters in a string with "<br />" tags
   commonly used when data designed to be displayed in a textarea needs to be displayed in
   a read only mode, such as in a div or table cell
*/

stringClass.prototype.replaceReturns = function(text) {
  	var tmp = text.replace(/[\f\n]|\r\n|\r/g,'<br />');

	return(tmp);
}
// END FUNCTION REPLACERETURNS
/*****************************************************************************************/



// END STRING METHODS
//*****************************************************************************


//*****************************************************************************
// ADD STRING CLASS TO MAPCLASS
//*****************************************************************************
mapClass.prototype.string = new stringClass();

