﻿/*
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Author:			aleonard
Date:			2007.06.29
Description:	Javascript prototype resource file for the application.
				This script is compiled into the assembly
Revisions:
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
*/

/*
-------------------------------------------------------------------------------
Author:			aleonard
Date:			2007.06.29
Description:	Adds an 'isLeapYear' method to the Date object
-------------------------------------------------------------------------------
*/
Date.prototype.isLeapYear = 
	function isLeapYear()
		{
			intYear = this.getFullYear();

			if(intYear%4 == 0)
			{
				if(intYear%100 != 0)
				{
					return true;
				}
				else
				{
					if(intYear%400 == 0)
						return true;
					else
						return false;
				}
			}
		return false;
		}

/*
-------------------------------------------------------------------------------
Author:			aleonard
Date:			2007.06.29
Description:	Adds an 'isDate' method to the Date object
				If the passed in string is a valid date then the date object
				is set to the parsed date
Parameters:
	strDate		String to test
-------------------------------------------------------------------------------
*/
Date.prototype.isDate = 
	function isDate(strDate)
		{
			if(isNaN(Date.parse(strDate)))
			{
				return false;
			}
			else
			{
				this.setTime(Date.parse(strDate));
				return true;
			}
		}
		
/*
-------------------------------------------------------------------------------
Author:			aleonard
Date:			2007.06.29
Description:	Adds a format method to the Date object
Parameters:
	strFormat	String defining the output format:
				MMM		Full month name
				NNN		Abbreviated month name
				MM		Month number padded to two digits if necessary
				M		Month number
				dd		Day of the month padded to two digits if necessary
				d		Day of the month
				EE		Full day name
				E		Abbreviated day name
				yyyy	Four digit year
				yy		Two digit year

				All other characters and spaces are left untouched
-------------------------------------------------------------------------------
*/
Date.prototype.format = 
	function format(strFormat)
		{
			var strOut = new String(strFormat);
			var arrMonths = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
			var arrShortMonths = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
			var arrDays = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
			var arrShortDays = new Array('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
			var strYear = new String(this.getFullYear().toString());
			var intMonth = new Number(this.getMonth());
			var intDate = new Number(this.getDate());
			var intDay = new Number(this.getDay());

			//Format the month
			strOut = strOut.replace('MMM', arrMonths[intMonth].toString());
			strOut = strOut.replace('NNN', arrShortMonths[intMonth].toString());
			strOut = strOut.replace('MM', (intMonth + 1).toString().length == 1 ? '0' + (intMonth + 1).toString() : (intMonth + 1).toString());
			strOut = strOut.replace('M', (intMonth + 1).toString());
			
			//Format the day
			strOut = strOut.replace('dd', intDate.toString().length == 1 ? '0' + intDate.toString() : intDate.toString());
			strOut = strOut.replace('d', intDate.toString());
			strOut = strOut.replace('EE', arrDays[intDay].toString());
			strOut = strOut.replace('E', arrShortDays[intDay].toString());
			
			//Format the year
			strOut = strOut.replace('yyyy', strYear);
			strOut = strOut.replace('yy', strYear.substr(strYear.length - 2, 2));
			
			return strOut;
		}

/*
-------------------------------------------------------------------------------
Author:			aleonard
Date:			2007.07.02
Description:	Adds an 'append' method to the String object
				Appends a delimeter and a string to the string object
Parameters:
	str			String to append
	delimeter	String to separate the original string and the appended string
-------------------------------------------------------------------------------
*/
String.prototype.append =
	function append(str, delimeter)
		{
			if(this.length == 0)
			{
				return str;
			}
			else
			{
				return this.toString() + delimeter + str;
			}
		}