<!--
/*===========================================================================*\
|	* Notes *
|	This will be moved into the FormProcessor.js file so that we have just
|	one validation script.
|
|	* Index *
|	Main Object ---------- [00000]
|	Sub-Objects ---------- [00001]
|	  Date and Time ------ [00100]
|	    Filter Functions - [00101]
|	    Checking Functions [00102]
|	    Format Functions - [00103]
|	    Get Functions ---- [00104]
|	  Contact ------------ [00200]
|	    Checking Functions [00201]
|	  Location ----------- [00300]
|	  Misc. -------------- [00400]
|	    Misc. Functions -- [00301]
|	  Number ------------- [00500]
|	    Filter Functions - [00401]
|	    Checking Functions [00402]
|
|	* Date Formatting Codes *
|	Time:
|		Default format: "hh:i:s" (ex.: 15:43:28)
|		s or S = seconds with leading zeros (ex.: 04)
|		i or I = minutes with leading zeros (ex.: 08)
|		h      = 12 hour format with no leading zeros (ex.: 5)
|		H      = 12 hour format with leading zeros (ex.: 05)
|		hh     = 24 hour format with no leading zeros (ex.: 5 or 17)
|		HH     = 24 hour format with leading zeros (ex.: 05 or 17)
|		x      = am or pm in lower case (ex.: am or pm)
|		X      = am or pm in upper case (ex.: AM or PM)
|	Date:
|		Default format: "m/d/Y" (ex.: 3/5/2007)
|		d      = day date with no leading zeros (ex.: 6)
|		D      = day date with leading zeros (ex.: 06)
|		dd     = day date \w no leading zeros and suffix (ex.: 6th)
|		DD     = day date \w leading zeros and suffix (ex.: 06th)
|	  z or Z = day out of the year (ex.: 1 thru 365 or 366)
|		m      = month date \w no leading zeros (ex.: 3)
|		M      = month date \w leading zeros (ex.: 03)
|		mm     = short month name (ex.: Mar)
|		MM     = full month name (ex.: March)
|		y      = four digit year (ex.: 2007)
|		Y      = two digit year (ex.: 07)
\*===========================================================================*/

//////////////////////////////////////////////////////////////////////////
// Main Object                                                     [00000]
//------------------------------------------------------------------------
function Validator() {
	this.dateTime = new DateTimeFunctions(); // [00100]
	this.contact = new ContactFunctions();   // Not done [00200]
	this.location = new LocationFunctions(); // Not done [00300]
	this.misc = new MiscFunctions();         // Not done [00400]
	this.number = new NumberFunctions();     // [00500]
};
//========================================================================

//////////////////////////////////////////////////////////////////////////
// Sub-Object Declarations                                         [00001]
//------------------------------------------------------------------------

///// Date and Time /////                                          [00100]
//------------------------------------------------------------------------
function DateTimeFunctions() { //[10100]
	///Misc Functions///         //[00400]
	this.misc = new MiscFunctions();

	///Filter Functions///       //[00101]
	this.filterDate = FilterDateFunction;           //[10101]
	this.filterDateTime = FilterDateTimeFunction;   //[10102]
	this.filterTime = FilterTimeFunction;           //[10103]

	///Checking Functions///     //[00102]
	this.isValidDate = isValidDateFunction;         //[10104]
	this.isValidDateTime = isValidDateTimeFunction; //[10105]
	this.isValidTime = isValidTimeFunction;         //[10106]

	///Format Functions///       //[00103]
	this.formatAmPm = FormatAmPmFunction;           //[10107]
	this.formatDate = FormatDateFunction;           //[10108]
	this.formatDateTime = FormatDateTimeFunction;   //[10109]
	this.formatDay = FormatDayFunction;             //[10110]
	this.formatHour = FormatHourFunction;           //[10111]
	this.formatMinute = FormatMinuteFunction;       //[10112]
	this.formatMonth = FormatMonthFunction;         //[10113]
	this.formatSecond = FormatMinuteFunction;       //[10114]
	this.formatTime = FormatTimeFunction;           //[10115]
	this.formatYear = FormatYearFunction;           //[10116]

	///Get Functions///          //[00104]
	this.getMonthDate = GetMonthDateFunction;       //[10117]
	this.getDayOfWeek = GetDayNameOfWeekFunction;   //[10118]
	this.getDayNumOfWeek = GetDayNumOfWeekFunction; //[10119]
	this.getDayOfYear = GetDayOfYearFunction;       //[10120]
	this.getMonthDays = GetMonthDaysFunction;				//[10121]
	this.getMonthName = GetMonthNameFunction;       //[10122]

	                             //[00105]
	this.bDatePriority = bDatePriorityFunction;     //Not started //[10123]
};

/////Contact/////                                                  [00200]
//------------------------------------------------------------------------
function ContactFunctions() {  //[10201]
	///Misc Functions///         //[00400]
	this.misc = new MiscFunctions();

	///Filter Functions///       //[00201]
	this.filterPhone = FilterPhoneFunction;     //Not done //[10201]

	///Checking Functions///     //[00202]
	this.checkEmail = CheckEmailFunction;       //Not started //[10202]
	this.isValidEmail = isValidEmailFunction;   //[10203]
	this.isValidPhone = isValidPhoneFunction;   //[10204]
};

/////Location/////                                                 [00300]
//------------------------------------------------------------------------
function LocationFunctions() { //[10301]
	///Checking Functions///     //[00301]
};

/////Misc./////                                                    [00400]
//------------------------------------------------------------------------
function MiscFunctions() {     //[10400]
	///Misc. Functions///        //[00401]
	this.isRequired = isRequiredFunction; //Not started //[10401]
	this.AlphaFilter = AlphaOnlyFunction; //[10402]
	this.trim = TrimFunction;             //[10403]
	this.doesExist = DoesExistFunction;   //[10404]
};

/////Number/////                                                   [00500]
//------------------------------------------------------------------------
function NumberFunctions() {   //[10500]
  ///Misc Functions///         //[00500]
	this.misc = new MiscFunctions();

  ///Filter Functions///       //[00401]
	this.filterCurrency = FilterCurrencyFunction; //[10501]
	this.filterDecimal = FilterDecimalFunciton;   //[10502]
  this.filterInteger = FilterIntegerFunction;   //[10503]
	this.filterNumber = FilterNumberFunction;     //[10504]

	///Checking Functions///      //[00402]
	this.isDecimal = isDecimalFunction;           //[10505]
	this.isDigit = isDigitFunction;               //Not started //[10506]
	this.isDollar = isDollarFunction;             //Not started //[10507]
  this.isInteger = isIntegerFunction;           //[10508]

	///Number variables///
	this.decimalPlaces = 8;
	this.allowSigned = false;
};
//========================================================================

//////////////////////////////////////////////////////////////////////////
// Date and Time Functions                                         [10100]
//------------------------------------------------------------------------

/////Filter Functions/////                                         [00101]
//------------------------------------------------------------------------

///Filter Date: [10101]///
//Filters date into the either the sent format or the default format
//In:  string, string
//Out: string
function FilterDateFunction(sText, sFormat) {
	var bPass = false;
	var iStart = 1;
	var iEnd = 0;
	var iDay = 0;
	var iMonth = 0;
	var iYear = 0;

	sText = this.misc.trim(sText);

	if(!this.misc.doesExist(sFormat)) {
		sFormat = "m/d/Y";
	}

	if (this.isValidDate(sText, true)) {
		sDay = sText.substr(0, 3);
		if (this.getDayNumOfWeek(sDay) > 0) {
			iStart = sText.search(/( |,)/);
			iEnd = sText.length;
			sText = this.misc.trim(sText.substr((iStart + 1), (iEnd - iStart)));
			iStart = 1;
			iEnd = 0;
		}

		bPass = true;
		sText = sText.replace(/[^a-zA-Z0-9']+/g, "-");

		aText = sText.split("-");

		//Get year
		for (i = 0;i < aText.length;i++) {
			if (aText[i].search(/\d{4}/) > -1) {
				iYear = aText[i];
				aText.splice(i, 1);
				break;
			}
			else if (aText[i].search(/'\d{2}/) > -1) {
				iYear = aText[i].replace("'", "");
				aText.splice(i, 1);
				break;
			}
		}
		if ((iYear - 0) == 0) {
			iYear = aText[2];
			aText.splice(2, 1);
		}

		//Get month
		for (i = 0;i < aText.length;i++) {
			if (aText[i].search(/[a-zA-Z]{3,9}/) > -1) {
				iMonth = this.getMonthDate(aText[i]);
			}
			else {
				iMonth = aText[i] - 0;
			}
			if (((iMonth - 0) > 0) && ((iMonth - 0) < 13)) {
				aText.splice(i, 1);
				break;
			}
		}
		if (((iMonth - 0) < 0) || ((iMonth - 0) > 12)) {
			iMonth = 0;
		}

		//Get day
		iDay = aText[0].replace(/\D/g, "") - 0;

		if (((iYear - 0) >= 40) && (iYear.length < 3)) {
			iYear = (iYear - 0) + 1900;
		}

		if ((iYear - 0) < 40) {
			iYear = (iYear - 0) + 2000;
		}

		//alert("Year: ["+iYear+"]\nMonth: ["+iMonth+"]\nDay: ["+iDay+"]");
	}

	if (bPass) {
		sText = this.formatDate(sFormat, iDay, iMonth, iYear);
	}
	else {
		sText = "";
	}

	return sText;
};

///FilterDateTime: [10102]///
//Filters Date and Time into either the given format or the default format
//In:  string, string
//Out: string
function FilterDateTimeFunction(sText, sFormat) {
	var bPass = false;
	var bDateFirst = false;
	var iStart = 0;
	var iEnd = 0;
	var sDate = "";
	var sTime = "";
	var RegexDateFirst = /^([a-zA-Z]{3,9}(\, *| +))?(((\d{1,2}|[a-zA-Z]{3,9})(\/|\\|\-)\d{1,2}(\/|\\|\-)(\d{2}|\d{4}))|[a-zA-Z]{3,9}(\, *| *)\d{1,2}(th|rd|nd|st)?(,|.)?( *|\-|\/|\\)(('?)\d{2}|\d{4})) *(\d{1,2}:\d{2}(|:\d{2})(| *([aA]|[pP])[mM])|\d{1,2} *([aA]|[pP])[mM])$/;
	var RegexTimeFirst = /^(\d{1,2}:\d{2}(|:\d{2})(| *([aA]|[pP])[mM])|\d{1,2} *([aA]|[pP])[mM]) *([a-zA-Z]{3,9}(\, *| +))?(((\d{1,2}|[a-zA-Z]{3,9})(\/|\\|\-)\d{1,2}(\/|\\|\-)(\d{2}|\d{4}))|[a-zA-Z]{3,9}(\, *| *)\d{1,2}(th|rd|nd|st)?(,|.)?( *|\-|\/|\\)(('?)\d{2}|\d{4}))$/;
	var RegexDate = /([a-zA-Z]{3,9}(\, *| +))?(((\d{1,2}|[a-zA-Z]{3,9})(\/|\\|\-)\d{1,2}(\/|\\|\-)(\d{2}|\d{4}))|[a-zA-Z]{3,9}(\, *| *)\d{1,2}(th|rd|nd|st)?(,|.)?( *|\-|\/|\\)(('?)\d{2}|\d{4}))/;
	var RegexTime = /(\d{1,2}:\d{2}(|:\d{2})(| *([aA]|[pP])[mM])|\d{1,2} *([aA]|[pP])[mM])/;

	sText = this.misc.trim(sText);

	if(!this.misc.doesExist(sFormat)) {
		sFormat = "m/d/Y hh:i:s";
	}

	if (RegexDateFirst.test(sText)) {
		bPass = true;
		bDateFirst = true;
	}
	if (RegexTimeFirst.test(sText)) {
		bPass = true;
	}

	if (bPass) {
		if (bDateFirst) {
			iEnd = sText.search(RegexTime);
			sDate = sText.substr(0, (iEnd - 1));

			iStart = iEnd;
			iEnd = sText.length;

			sTime = sText.substr(iStart, iEnd);

			sDate = this.filterDate(sDate, "d/m/Y");
			sTime = this.filterTime(sTime, "hh:i:s");
		}
		else {
			iEnd = sText.search(RegexDate);
			sTime = sText.substr(0, (iEnd - 1));

			iStart = iEnd;
			iEnd = sText.length;

			sDate = sText.substr(iStart, iEnd);

			sDate = this.filterDate(sDate, "d/m/Y");
			sTime = this.filterTime(sTime, "hh:i:s");
		}

		aDate = sDate.split("/");
		aTime = sTime.split(":");

		sText = this.formatDateTime(sFormat, aDate[0], aDate[1], aDate[2], aTime[0], aTime[1], aTime[2]);
	}
	else {
		sText = "";
	}

	return sText;
};

///FilterTime: [10103]///
//Filters Time into either the given format or the default format
//In:  string, string
//Out: string
function FilterTimeFunction(sText, sFormat) {
	var bPass = false;
	var iHour = 0;
	var iMinute = 0;
	var iSecond = 0;
	var iAmPm = 0;
	var iStart = 0;
	var iEnd = 0;

	sText = this.misc.trim(sText);

	if(!this.misc.doesExist(sFormat)) {
		sFormat = "hh:i:s";
	}

	if (this.isValidTime(sText)) {
		iHour = sText.substr(0,2).replace(/\D/g, "");

		iStart = iHour.length;
		iEnd = sText.search(/:\d{2}(?=( |([aA]|[pP])|:|$))/);

		if ((iEnd - 0) > -1) {
			iEnd = ((iEnd - 0) + 3);
			iMinute = sText.substr(iStart, ((iEnd - 0) - iStart)).replace(/\D/g, "");

			iStart = (iEnd - 0) + 1;
			iEnd = sText.search(/:\d{2}:\d{2}( |([aA]|[pP])|$)/);

			if ((iEnd - 0) > -1) {
				iEnd = ((iEnd - 0) + 6);
				iSecond = sText.substr(iStart, (iEnd - iStart));
			}
		}

		if (sText.search(/[aA][mM]/) > -1) {
			iAmPm = 1;
		}
		else if (sText.search(/[pP][mM]/) > -1) {
			iAmPm = 2;
		}

		if ((iAmPm - 0) > 0) {
			if (((iAmPm - 0) == 1) && ((iHour - 0) == 12)) {
				iHour = 0;
			}
			else if (((iAmPm - 0) == 2) && ((iHour - 0) != 12)) {
				iHour = (iHour - 0) + 12;
			}
		}

		//alert("this.formatTime("+sFormat+", "+iHour+", "+iMinute+", "+iSecond+")");
		sText = this.formatTime(sFormat, iHour, iMinute, iSecond);
	}
	else {
		sText = "";
	}

	return sText;
};


/////Checking Functions/////                                       [00102]
//------------------------------------------------------------------------

///isValidDate: [10104]///
//Checks to see if a date is valid, if sent true for bAllowString it also checks month names
//In:  string, boolean
//Out: boolean
function isValidDateFunction(sText, bAllowString) {
	var bPass = false;
	var RegexStr = /^(([a-zA-Z]{3,9})(,|, *| +))?(((\d{1,2}|[a-zA-Z]{3,9})(\/|\\|\-)\d{1,2}(\/|\\|\-)(\d{2}|\d{4}))|[a-zA-Z]{3,9}(\, *| *)\d{1,2}(th|rd|nd|st)?(,|.)?( *|\-|\/|\\)(('?)\d{2}|\d{4}))$/;
	var RegexNum = /^(( *)(\d{2,4})( *)(\/|\\|\-)( *)(\d{1,2})( *)(\/|\\|\-)( *)(\d{1,2})( *)|( *)(\d{1,2})( *)(\/|\\|\-)( *)(\d{1,2})( *)(\/|\\|\-)( *)(\d{2}|\d{4})( *))$/;
	var iStart = 1;
	var iEnd = 0;
	var iDays = 0;
	var iDay = 0;
	var iMonth = 0;
	var iYear = 0;
	var sDay = "";
	var aText = new Array();

	sText = this.misc.trim(sText);

	if(!this.misc.doesExist(bAllowString)) {
		bAllowString = false;
	}

	if(bAllowString) {
		bPass = RegexStr.test(sText);
		if (!bPass) {
			bPass = RegexNum.test(sText);
		}
	}
	else {
		bPass = RegexNum.test(sText);
	}

	if (bPass) {
		bPass = false;

		sDay = sText.substr(0, 3);
		if (this.getDayNumOfWeek(sDay) > 0) {
			iStart = sText.search(/( |,)/);
			iEnd = sText.length;
			sText = this.misc.trim(sText.substr((iStart + 1), (iEnd - iStart)));
			iStart = 1;
			iEnd = 0;
		}

		sText = sText.replace(/[^a-zA-Z0-9']+/g, "-");

		aText = sText.split("-");

		//Get year
		for (i = 0;i < aText.length;i++) {
			if (aText[i].search(/\d{4}/) > -1) {
				iYear = aText[i];
				aText.splice(i, 1);
				break;
			}
			else if (aText[i].search(/'\d{2}/) > -1) {
				iYear = aText[i].replace("'", "");
				aText.splice(i, 1);
				break;
			}
		}
		if ((iYear - 0) == 0) {
			iYear = aText[2];
			aText.splice(2, 1);
		}

		//Get month
		for (i = 0;i < aText.length;i++) {
			if (aText[i].search(/[a-zA-Z]{3,9}/) > -1) {
				iMonth = this.getMonthDate(aText[i]);
			}
			else {
				iMonth = aText[i] - 0;
			}
			if (((iMonth - 0) > 0) && ((iMonth - 0) < 13)) {
				aText.splice(i, 1);
				break;
			}
		}
		if (((iMonth - 0) < 0) || ((iMonth - 0) > 12)) {
			iMonth = 0;
		}

		//Get day
		iDay = aText[0].replace(/\D/g, "") - 0;

		if (((iYear - 0) >= 40) && (iYear.length < 3)) {
			iYear = (iYear - 0) + 1900;
		}

		if ((iYear - 0) < 40) {
			iYear = (iYear - 0) + 2000;
		}

		//alert("Year: ["+iYear+"]\nMonth: ["+iMonth+"]\nDay: ["+iDay+"]");

		if (((iMonth - 0) < 13) && ((iMonth - 0) > 0)) {
			iDays = this.getMonthDays(iMonth, iYear);
			if (((iDay - 0) <= (iDays - 0)) && ((iDay - 0) > 0)) {
				bPass = true;
			}
		}
	}

	return bPass;
};

///isValidDateTime: [10105]///
//Checks a Date Time string to determine if the string is a valid date and time
//In:  string
//Out: boolean
function isValidDateTimeFunction(sText) {
	var bPass = false;
	var bDateFirst = false;
	var iStart = 0;
	var iEnd = 0;
	var sDate = "";
	var sTime = "";
	var RegexDateFirst = /^([a-zA-Z]{3,9}(\, *|\,|( +)))?(((\d{1,2}|[a-zA-Z]{3,9})(\/|\\|\-)\d{1,2}(\/|\\|\-)(\d{2}|\d{4}))|[a-zA-Z]{3,9}(\, *| *)\d{1,2}(th|rd|nd|st)?(,|.)?( *|\-|\/|\\)(('?)\d{2}|\d{4})) *(\d{1,2}:\d{2}(|:\d{2})(| *([aA]|[pP])[mM])|\d{1,2} *([aA]|[pP])[mM])$/;
	var RegexTimeFirst = /^(\d{1,2}:\d{2}(|:\d{2})(| *([aA]|[pP])[mM])|\d{1,2} *([aA]|[pP])[mM]) *([a-zA-Z]{3,9}(\, *| +))?(((\d{1,2}|[a-zA-Z]{3,9})(\/|\\|\-)\d{1,2}(\/|\\|\-)(\d{2}|\d{4}))|[a-zA-Z]{3,9}(\, *| *)\d{1,2}(th|rd|nd|st)?(,|.)?( *|\-|\/|\\)(('?)\d{2}|\d{4}))$/;
	var RegexDate = /([a-zA-Z]{3,9}(\, *|\,|( +)))?(((\d{1,2}|[a-zA-Z]{3,9})(\/|\\|\-)\d{1,2}(\/|\\|\-)(\d{2}|\d{4}))|[a-zA-Z]{3,9}(\, *| *)\d{1,2}(th|rd|nd|st)?(,|.)?( *|\-|\/|\\)(('?)\d{2}|\d{4}))/;
	var RegexTime = /(\d{1,2}:\d{2}(|:\d{2})(| *([aA]|[pP])[mM])|\d{1,2} *([aA]|[pP])[mM])/;

	sText = this.misc.trim(sText);

	if (RegexDate.test(sText)) {
		bPass = true;
		bDateFirst = true;
	}
	if (RegexTime.test(sText)) {
		bPass = true;
	}

	if (bPass) {
		bPass = false;
		if (bDateFirst) {
			iEnd = sText.search(RegexTime);
			sDate = sText.substr(0, (iEnd - 1));

			iStart = iEnd;
			iEnd = sText.length;

			sTime = sText.substr(iStart, iEnd);
		}
		else {
			iEnd = sText.search(RegexDate);
			sTime = sText.substr(0, (iEnd - 1));

			iStart = iEnd;
			iEnd = sText.length;

			sDate = sText.substr(iStart, iEnd);
		}

		if (this.isValidDate(sDate, true)) {
			if (this.isValidTime(sTime)) {
				bPass = true;
			}
		}
	}

	return bPass;
};

///isValidTime: [10106]///
//Checks a time string to determine if the string is a valid time string
//In:  string
//Out: boolean
function isValidTimeFunction(sText) {
	var bPass = false;
	var iHour = 0;
	var iMinute = 0;
	var iSecond = 0;
	var iAmPm = 0;
	var iStart = 0;
	var iEnd = 0;
	var Regex = /^(\d{1,2}:\d{2}(|:\d{2})(| *([aA]|[pP])[mM])|\d{1,2} *([aA]|[pP])[mM])$/;

	sText = this.misc.trim(sText);

	if (Regex.test(sText)) {
		iHour = sText.substr(0,2).replace(/\D/g, "");

		iStart = iHour.length;
		iEnd = sText.search(/:\d{2}(?=( |([aA]|[pP])|:|$))/);

		if ((iEnd - 0) > -1) {
			iEnd = ((iEnd - 0) + 3);
			iMinute = sText.substr(iStart, ((iEnd - 0) - iStart)).replace(/\D/g, "");

			iStart = (iEnd - 0) + 1;
			iEnd = sText.search(/:\d{2}:\d{2}( |([aA]|[pP])|$)/);

			if ((iEnd - 0) > -1) {
				iEnd = ((iEnd - 0) + 6);
				iSecond = sText.substr(iStart, (iEnd - iStart));
			}
		}

		if (sText.search(/[aA][mM]/) > -1) {
			iAmPm = 1;
		}
		else if (sText.search(/[pP][mM]/) > -1) {
			iAmPm = 2;
		}

		if ((iAmPm - 0) > 0) {
			if (((iHour - 0) > 0) && ((iHour - 0) < 13)) {
				if (((iMinute - 0) >= 0) && ((iMinute - 0) < 60)) {
					if (((iSecond - 0) >= 0) && ((iSecond - 0) < 60)) {
						bPass = true;
					}
				}
			}
		}
		else {
			if (((iHour - 0) >= 0) && ((iHour - 0) < 24)) {
				if (((iMinute - 0) >= 0) && ((iMinute - 0) < 60)) {
					if (((iSecond - 0) >= 0) && ((iSecond - 0) < 60)) {
						bPass = true;
					}
				}
			}
		}
	}

	return bPass;
};


/////Format Functions/////                                         [00103]
//------------------------------------------------------------------------

///FormatAmPm: [10107]///
//Sends back am or pm depending on the hour
//In:  integer, integer
//Out: string
function FormatAmPmFunction(iHour, iStyle) {
	sAmPm = "";

	if ((iHour > 11) && (iHour < 24)) {
		sAmPm = "Pm";
	}
	else {
		sAmPm = "Am";
	}

	if ((iStyle - 0) == 1) {
		sAmPm = sAmPm.toLowerCase();
	}
	else if ((iStyle - 0) == 2) {
		sAmPm = sAmPm.toUpperCase();
	}

	return sAmPm;
};

///FormatDate: [10108]///
//Formats a date string based on the format given and the integer values given
//In:  string, integer, integer, integer
//Out: string
function FormatDateFunction(sFormat, iDay, iMonth, iYear) {
	return this.formatDateTime(sFormat, iDay, iMonth, iYear, 0, 0, 0);
};

///FormatDateTime: [10109]///
//Formats a date and time string based on the format given and the integer values given
//In:  string, integer, integer, integer, integer, integer, integer
//Out: string
function FormatDateTimeFunction(sFormat, iDay, iMonth, iYear, iHour, iMinute, iSecond) {
	if(!this.misc.doesExist(sFormat)) {
		sFormat = "m/d/Y hh:i:s";
	}

	if(!this.misc.doesExist(iDay)) {
		iDay = 1;
	}

	if(!this.misc.doesExist(iMonth)) {
		iMonth = 1;
	}

	if(!this.misc.doesExist(iYear)) {
		iYear = 1900;
	}

	if(!this.misc.doesExist(iHour)) {
		iHour = 0;
	}

	if(!this.misc.doesExist(iMinute)) {
		iMinute = 0;
	}

	if(!this.misc.doesExist(iSecond)) {
		iSecond = 0;
	}

	//Replace hour
	if (sFormat.search(/[hH]{1,2}/) > -1) {
		sFormat = sFormat.replace(/H{2}/g, this.formatHour(iHour, 4));
		sFormat = sFormat.replace(/h{2}/g, this.formatHour(iHour, 3));
		sFormat = sFormat.replace(/H{1}/g, this.formatHour(iHour, 2));
		sFormat = sFormat.replace(/h{1}/g, this.formatHour(iHour, 1));
	}

	//Replace minute
	if (sFormat.search(/[iI]{1}/) > -1) {
		sFormat = sFormat.replace(/[iI]{1}/g, this.formatMinute(iMinute, 1));
	}

	//Replace second
	if (sFormat.search(/[sS]{1}/) > -1) {
		sFormat = sFormat.replace(/[sS]{1}/g, this.formatSecond(iSecond, 1));
	}

	//Replace year
	if (sFormat.search(/[yY]{1,2}/) > -1) {
		sFormat = sFormat.replace(/Y{1}/g, this.formatYear(iYear, 4));
		sFormat = sFormat.replace(/y{1}/g, this.formatYear(iYear, 2));
	}

	//Replace day of year
	if (sFormat.search(/[zZ]{1}/) > -1) {
		sFormat = sFormat.replace(/[zZ]{1}/g, this.getDayOfYear(iDay, iMonth, iYear));
	}

	//Replace day
	if (sFormat.search(/[dD]{1,2}/) > -1) {
		sFormat = sFormat.replace(/D{2}/g, this.formatDay(iDay, 4));
		sFormat = sFormat.replace(/d{2}/g, this.formatDay(iDay, 3));
		sFormat = sFormat.replace(/D{1}/g, this.formatDay(iDay, 2));
		sFormat = sFormat.replace(/d{1}/g, this.formatDay(iDay, 1));
	}

	//Replace month
	if (sFormat.search(/[mM]{1,2}/) > -1) {
		sFormat = sFormat.replace(/M{2}/g, this.formatMonth(iMonth, 4));
		sFormat = sFormat.replace(/m{2}/g, this.formatMonth(iMonth, 3));
		sFormat = sFormat.replace(/M{1}/g, this.formatMonth(iMonth, 2));
		sFormat = sFormat.replace(/m{1}/g, this.formatMonth(iMonth, 1));
	}

	//Replace am/pm
	if (sFormat.search(/[xX]{1}/) > -1) {
		sFormat = sFormat.replace(/x{1}/g, this.formatAmPm(iHour, 1));
		sFormat = sFormat.replace(/X{1}/g, this.formatAmPm(iHour, 2));
	}

	return sFormat;
};

///Format Day: [10110]///
//Formats the day based on the day number and style given
//In:  integer, integer
//Out: string
function FormatDayFunction(iDay, iStyle) {
	var sDay = "";
	if ((iStyle - 0) > 0) {
		sDay = iDay.toString();
		if (((iDay - 0) < 10) && (((iStyle - 0) == 2) || ((iStyle - 0) == 4))) {
			sDay = "0"+sDay;
		}
		if ((iStyle - 0) > 2) {
			if (((iDay - 0) > 10) && ((iDay - 0) < 14)) {
				sDay += "th";
			}
			else {
				switch (((iDay - 0) % 10)) {
					case 1:
						sDay += "st";
						break;
					case 2:
						sDay += "nd";
						break;
					case 3:
						sDay += "rd";
						break;
					default:
						sDay += "th";
						break;
				}
			}
		}
	}
	return sDay;
};

///FormatHour: [10111]///
//Sends back an hour string based on the hour given and the style option
//In:  integer, integer
//Out: string
function FormatHourFunction(iHour, iStyle) {
	var sHour = "";

	if ((iStyle - 0) < 3) {
		if ((iHour - 0) == 0) {
			iHour = 12;
		}
		if ((iHour - 0) > 12) {
			iHour -= 12;
		}
	}

	if (((iStyle - 0) == 1) || ((iStyle - 0) == 3)) {
		sHour = (iHour - 0);
	}
	else if (((iStyle - 0) == 2) || ((iStyle - 0) == 4)) {
		sHour = (iHour - 0);
		if ((iHour - 0) < 10) {
			sHour = "0"+(iHour - 0);
		}
	}

	return sHour;
};

///FormatMinute: [10112]///
//Sends back a minute string based on the minute and style given
//In:  integer, integer
//Out: string
function FormatMinuteFunction(iMinute, iStyle) {
	var sMinute = "";

	if ((iMinute - 0) < 10) {
		sMinute = "0"+(iMinute - 0);
	}
	else {
		sMinute = iMinute.toString();
	}

	return sMinute;
};

///FormatMonth: [10113]///
//Returns a month string based on the month given and the style option
//In:  integer, integer
//Out: string
function FormatMonthFunction(iMonth, iStyle) {
	var sMonth = "";
	if (((iStyle - 0) == 1) || ((iStyle - 0) == 2)) {
		sMonth = iMonth.toString();
		if ((iStyle - 0) == 2) {
			if ((iMonth - 0) < 10) {
				sMonth = "0" + sMonth;
			}
		}
	}
	else if (((iStyle - 0) == 3) || ((iStyle - 0) == 4)) {
		sMonth = this.getMonthName((iMonth - 0));
		if ((iStyle - 0) == 3) {
			sMonth = sMonth.substr(0, 3);
		}
	}
	return sMonth;
};

///FormatSecond: [10114]///
//Returns a string based on the second and style option given
//In:  integer, integer
//Out: string
function FormatSecondFunction(iSecond, iStyle) {
	return this.formatMinute(iSecond, iStyle);
};

///FormatTime: [10115]///
//Formats a time string based on the format given and the integer values given
//In:  string, integer, integer, integer
//Out: string
function FormatTimeFunction(sFormat, iHour, iMinute, iSecond) {
	return this.formatDateTime(sFormat, 1, 1, 1900, (iHour - 0), (iMinute - 0), (iSecond - 0));
};

///FormatYear: [10116]///
//Formats a year based on the year and style option given
//In:  integer, integer
//Out: string
function FormatYearFunction(iYear, iStyle) {
	var sYear = "";
	if ((iStyle - 0) > 0) {
		if (((iStyle - 0) == 2) || ((iStyle - 0) == 3)) {
			sYear = iYear.toString().substr(2,2);
			if ((iStyle - 0) == 3) {
				sYear = "'"+sYear;
			}
		}
		else if ((iStyle - 0) == 4) {
			sYear = iYear.toString();
		}
	}
	return sYear;
};

/////Get Functions/////                                            [00104]
//------------------------------------------------------------------------

///GetMonthDate: [10117]///
//Returns integer value of a month from the first three characters of a given string
//In:  string
//Out: integer
function GetMonthDateFunction(sText) {
	var iDate = 0;
	var aMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var sMonth = "";

	sText = this.misc.trim(sText).toLowerCase().replace(/[^a-zA-Z]/g, "");
	sText = sText.substr(0,3);
	if (sText.length == 3) {
		for (var i = 0;i < aMonths.length;i++) {
			sMonth = aMonths[i].substr(0,3).toLowerCase();
			if (sText == sMonth) {
				iDate = i + 1;
				break;
			}
		}
	}

	return iDate;
};

///GetDayNameOfWeek: [10118]///
//Returns the day name out of the week based on the integer given
//In:  integer, boolean
//Out: string
function GetDayNameOfWeekFunction(iDayOfWeek, bShort) {
	var aWeekDays = new Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
	var sWeekDay = "";

	if (!this.misc.doesExist(bShort)) {
		bShort = false;
	}

	if (((iDayOfWeek - 0) > 0) && ((iDayOfWeek - 0) < 8)) {
		sWeekDay = aWeekDays[(iDayOfWeek - 1)];
		if (bShort) {
			sWeekDay = sWeekDay.substr(0, 3);
		}
	}

	return sWeekDay;
};

///GetDayNumOfWeek: [10119]///
//Returns the day number out of the week based on the string given
//In:  string
//Out: integer
function GetDayNumOfWeekFunction(sText) {
	var iDayOfWeek = 0;
	var aWeekDays = new Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday");
	var sWeekDay = "";

	sText = this.misc.trim(sText).toLowerCase().replace(/[^a-zA-Z]/g, "");
	sText = sText.substr(0, 3);
	if (sText.length == 3) {
		for (var i = 0;i < 7;i++) {
			sWeekDay = aWeekDays[i].substr(0, 3).toLowerCase();
			if (sText == sWeekDay) {
				iDayOfWeek = i + 1;
				break;
			}
		}
	}

	return iDayOfWeek;
};

///GetDayOfYear: [10120]///
//Returns the day out of the year based on the day, month and year sent
//In:  integer, integer, integer
//Out: integer
function GetDayOfYearFunction(iDay, iMonth, iYear) {
	var iDayValue = 0;

	for (var i = 1;i < iMonth;i++) {
		//alert("iDayValue += this.getMonthDays("+i+", "+iYear+")\n"+iDayValue+" += "+this.getMonthDays(i, iYear));
		iDayValue += this.getMonthDays(i, iYear);
	}

	iDayValue += (iDay - 0);

	return iDayValue;
};

///GetMonthDays: [10121]///
//Returns the amount of days in the given month and year
//In:  integer, integer
//Out: integer
function GetMonthDaysFunction(iMonth, iYear) {
	var iDays = 0;
	var aMonthDays = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	if (((iMonth - 0) > 0) && ((iMonth - 0) < 13)) {
		iDays = (aMonthDays[(iMonth - 1)] - 0);
		if (((iMonth - 0) == 2) && ((iYear % 4) == 0)) {
			iDays++;
		}
	}

	return iDays;
};

///GetMonthName: [10122]///
//Returns the name of the month from the given month number, send true for bShort for short name
//In:  integer, boolean
//Out: string
function GetMonthNameFunction(iDate, bShort) {
	var aMonths = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
	var sMonth = "";

	if (!this.misc.doesExist(bShort)) {
		bShort = false;
	}

	if (((iDate - 0) > 0) && ((iDate - 0) < 13)) {
		sMonth = aMonths[(iDate - 1)];
	}

	if (bShort) {
		sMonth = sMonth.substr(0, 3);
	}

	return sMonth;
};

//[00105]
///bDatePriority: [10123]///
//Not started
function bDatePriorityFunction() {
};
//========================================================================

//////////////////////////////////////////////////////////////////////////
// Contact Functions                                               [10200]
//------------------------------------------------------------------------

/////Filter Functions/////                                         [00201]
//------------------------------------------------------------------------

///FilterPhone: [10201]///
//Filters string into specified format
//In:  string, string
//Out: string
function FilterPhoneFunction(sText, sFormat) {
	var aText = new Array();
	var aFormat = new Array();
	var sTmpFormat = "";
	//var Regex = /^\d{3}\-\d{4}$/;

	if (!this.misc.doesExist(sFormat)) {
		sFormat = "(xxx) xxx - xxxx";
	}

	sText = this.misc.trim(sText);
	if (this.isValidPhone(sText)) {
		sText = sText.replace(/\D+/g, "-");
		sTmpFormat = sFormat.replace(/\D+/g, "-");
		alert(sText);

		if (sText.substr(0,1) == "-") {
			sText = sText.substr(1, (sText.length - 1));
		}

		if (sTmpFormat.substr(0,1) == "-") {
			sTmpFormat = sTmpFormat.substr(1, (sTmpFormat.length - 1));
		}

		aText = sText.split("-");
		aFormat = sFormat.split("-");
		if (aText.length == 4) {
		}
		else if (aText.length == 3) {
		}
		if (aText.length == 2) {
		}
		else {
		}
	}

	return sFormat;
};

/////Checking Functions/////                                       [00202]
//------------------------------------------------------------------------

///CheckEmail: [10202]///
//Not started
function CheckEmailFunction() {
};

///isValidEmail: [10203]///
//Checks the string to see if the email address is a valid email address
//In:  string
//Out: boolean
function isValidEmailFunction(sText) {
	var bPass = false;
	var Regex = /^(([a-zA-Z0-9_\!\#\.\-\$\*\+\%\&\~])+|(\".+\"))\@((([a-zA-Z0-9_\-]+)\.)([a-zA-Z0-9]{2,4})|(\[((\d{1,3})\.){3}\d{1,3}\]))+$/;

	sText = this.misc.trim(sText);

	bPass = Regex.test(sText);

	return bPass;
};

///isValidPhone: [10204]///
//Checks the string to determine if it is a valid phone number
//In:  string
//Out: boolean
function isValidPhoneFunction(sText) {
	var bPass = false;
	var Regex = /^(\d{7,12}|((|\d{1,4}?)( *)(\()?( *)(\d{3,4}) *\)? *(\.| |-) *)?\d{3} *(\.|-| ) *\d{4})$/;

	sText = this.misc.trim(sText);

	bPass = Regex.test(sText);

	return bPass;
};
//========================================================================

//////////////////////////////////////////////////////////////////////////
// Location Functions                                              [10300]
//------------------------------------------------------------------------

/////Location Functions/////                                       [00301]
//------------------------------------------------------------------------

//========================================================================

//////////////////////////////////////////////////////////////////////////
// Misc Functions                                                  [10400]
//------------------------------------------------------------------------

/////Misc. Functions/////                                          [00401]
//------------------------------------------------------------------------

///isRequired: [10401]///
//Not started
function isRequiredFunction() {
	
};

///Trim: [10402]///
//Removes outside spaces and from the given string ad returns the trimed string
//In:  string
//Out: string
function AlphaOnlyFunction(sText) {
	return sText.replace(/[^A-Za-z0-9\-\_]/g, "");
};

///Trim: [10403]///
//Removes outside spaces and from the given string ad returns the trimed string
//In:  string
//Out: string
function TrimFunction(sText) {
	return sText.replace(/^\s*|\s*$/g, "");
};

///DoesExist: [10404]///
//Checks to see if sent object is alive and returns whether it is or not
//In:  object
//Out: boolean
function DoesExistFunction(oObject) {
	var bExists = true;
	var sTest = "";
	try {
		sTest = oObject.toString();
	}
	catch (e) {
		bExists = false;
	}
	return bExists;
};
//========================================================================

//////////////////////////////////////////////////////////////////////////
// Number Functions                                                [10500]
//------------------------------------------------------------------------

/////Filter Functions/////                                         [00501]
//------------------------------------------------------------------------

///FilterCurrency: [10501]///
//Filters string to be a valid number with a max of 2 decimal places
//In:  string, boolean
//Out: float
function FilterCurrencyFunction(sText, bSigned) {
	if (!this.misc.doesExist(bSigned)) {
		bSigned = this.allowSigned;
	}
	return this.filterNumber(sText, true, bSigned, 2);
};

///FilterDecimal: [10502]///
//Filters a string to be a valid number with a max of this.decimalPlaces in decimal places
//In:  string, boolean
//Out: float
function FilterDecimalFunciton(sText, bSigned) {
	if (!this.misc.doesExist(bSigned)) {
		bSigned = this.allowSigned;
	}
	return this.filterNumber(sText, true, bSigned, this.decimalPlaces);
};

///FilterInteger: [10503]///
//Filters a string to be a valid integer (no decimal places)
//In:  string, boolean
//Out: integer
function FilterIntegerFunction(sText, bSigned) {
	if (!this.misc.doesExist(bSigned)) {
		bSigned = this.allowSigned;
	}
	return this.filterNumber(sText, false, bSigned, this.decimalPlaces);
};

///FilterNumber: [10504]///
//Filters a number using options set in three parameters
//In:  string, boolean, boolean, boolean
//Out: float
function FilterNumberFunction(sText, bDecimal, bSigned, iDecPlaces) {
	var RegEx = /\D/;
	var bClean = false;
	var bHasNeg = false;
	var iDecPlace = 0;

	sText = this.misc.trim(sText);
	iDecPlace = sText.indexOf(".");

	if (!this.misc.doesExist(bDecimal)) {
		bDecimal = false;
	}
	if (!this.misc.doesExist(bSigned)) {
		bSigned = this.allowSigned;
	}
	if (!this.misc.doesExist(iDecPlaces)) {
		iDecPlaces = this.decimalPlaces;
	}

	if ((sText.indexOf("-") == 0) && (bSigned)) {
		bHasNeg = true;
	}

	while (!bClean) {
		if (sText.search(RegEx) < iDecPlace) {
			iDecPlace--;
		}
		sText = sText.replace(RegEx, "");
		bClean = !RegEx.test(sText);
	}

	if ((iDecPlace >= 0) && bDecimal) {
		sText = sText.slice(0,iDecPlace)+"."+sText.slice(iDecPlace, (iDecPlace + iDecPlaces));
	}

	if (bHasNeg) {
		sText = "-" + sText;
	}

	return (sText - 0);
};

/////Checking Functions/////                                       [00502]
//------------------------------------------------------------------------

///isDecimal: [10505]///
//Return whether given string is a propper decimal or not
//In:  string
//Out: boolean
function isDecimalFunction(sCheck) {
	var bIsDecimal = false;
	var RegEx = /[^\d\.-]|\.(?=.*\.)|(.+)-/;
	sCheck = this.misc.trim(sCheck);
	if (sCheck.length > 0) {
		bIsDecimal = !RegEx.test(sCheck);
	}
	return bIsDecimal;
};

///isDigit: [10506]///
//Not started
function isDigitFunction() {
};

///isDollar: [10507]///
//Not started
function isDollarFunction() {
};

///isInteger: [10508]///
//Returns whether given string is a valid integer
//In:  string
//Out: boolean
function isIntegerFunction(sCheck) {
	var bIsInt = false;
	var RegEx = /[^\d-]|(.+)-/;
	sCheck = this.misc.trim(sCheck);
	if (sCheck.length > 0) {
		bIsInt = !RegEx.test(sCheck);
	}
	return bIsInt;
}
//========================================================================

//-->
