var months = new Array("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC");
var days = new Array("Su", "Mo", "Tu", "We", "Th", "Fr", "Sa");

var DATE_FORMAT = "mm/dd/yyyy";
var DECIMAL_SEPARATOR = ".";
var THOUSAND_SEPARATOR = ",";
var MESSAGE_INVALID_NUMBER = "You have entered an invalid number.";
var MESSAGE_NUMBER_RANGE = "Please enter a number in the following range:";

/**
	Parses the date into a Date object.  If an invalid date is provided, current date on the client machine is returned.

	Input Format:  mm/dd/yyyy as String
	Output: Date Object
*/
function Format_ParseDate(val)
{
	var splits = val.split(DATE_SPLITTER);

	if (splits.length == 3 && regexOneOrMoreDigits.test(splits[0]) && regexOneOrMoreDigits.test(splits[1]) && regexOneOrMoreDigits.test(splits[2]))
	{
		var year = parseInt(splits[2]);
		var month = 1;
		var day = 1;

		if (splits[0].charAt(0) == '0' || splits[0].charAt(0) == '_')
			month = parseInt(splits[0].substring(1));
		else
			month = parseInt(splits[0]);

		if (splits[1].charAt(0) == '0' || splits[1].charAt(0) == '_')
			day = parseInt(splits[1].substring(1));
		else
			day = parseInt(splits[1]);

		month--;

		return new Date(year, month, day);
	}
	else
	{
		return undefined;
	}
}

/**
 * Parses a date into the locale representation for calendar method
 * 
 * @param day dd String
 * @param month mm String
 * @param year yyyy String
 * @return String formated 'MMM DD YYYY' or 'MM/DD/YYYY' 
 */
function format_ParseDateToLocale(date, formatted) {
  month = date.getMonth()+1;
  fullMonth = months[date.getMonth()];
  day = date.getDate();
  fullYear = date.getFullYear()
  if (formatted) {
    return fullMonth + " " + day + " " + fullYear;
  } else {
    return month + "/" + day + "/" + fullYear;
  }
}

/*
	Returns the given date (as specified by day, month and year parameters) in a user friendly format

	Output Example: September 01, 2006
	Output Example: September 11, 2006
*/
function Format_GetDay(day, month, year)
{
	var thisDate = new Date(year, month - 1, day);

	var s = "";

	s += months[month - 1];

	s += " ";
	if (thisDate.getDate() < 10)
		s += "0";
	s += thisDate.getDate();
	s += " ";

	s += thisDate.getFullYear();

	return s;
}

function Format_ParseDecimalAsNumber(value)
{
	return Format_ParseDecimal(value);
}

function Format_ParseDecimal(value)
{
    // remove any spaces in the value
    /*This is a failsafe for values that are passed as numeric and not
    actual string values*/
    value = value + "";
  var retValue = value.replace(/ /gi,'');
    // remove the thousand separator
    retValue = retValue.replace(/,/gi,'');

	// return
	return retValue;
}
