	
	/**
	* Class: 	DateTime
	* Author: 	Mohammad Ruhul Amin
	* Date: 	15-Jan-2004
	*/
	function DateTime()
	{
		this._date = new Date();
		
		this.Clone = Clone;
		
		this.AddYear = AddYear;
		
		this.AddMonth = AddMonth;
		
		this.AddDay = AddDay;
		
		this.AddHours = AddHours;
		
		this.AddMinutes = AddMinutes;
		
		this.AddSeconds = AddSeconds;
		
		this.GetYear = GetYear;
		
		this.GetMonth = GetMonth;
		
		this.GetMonthFullName = GetMonthFullName;
		
		this.GetMonthShortName = GetMonthShortName;
		
		this.GetDay = GetDay;
		
		this.GetDaysInMonth = GetDaysInMonth;
		
		this.GetWeekDay = GetWeekDay;
		
		this.GetWeekDayFullName = GetWeekDayFullName;
		
		this.GetWeekDayShortName = GetWeekDayShortName;
		
		this.GetHours = GetHours;
		
		this.GetMinutes = GetMinutes;
		
		this.GetSeconds = GetSeconds;
		
		this.GetMilliseconds = GetMilliseconds;
		
		this.GetTime = GetTime;
		
		this.GetDate = GetDate;
		
		this.GetMillsecondsDifference = GetMillsecondsDifference;
		
		this.GetSecondsDifference = GetSecondsDifference;
		
		this.GetMinutesDifference = GetMinutesDifference;
		
		this.GetHoursDifference = GetHoursDifference;
		
		this.GetDayDifference = GetDayDifference;
		
		this.GetMonthDifference = GetMonthDifference;
		
		this.SetYear = SetYear;
		
		this.SetMonth = SetMonth;
		
		this.SetDay = SetDay;
		
		this.SetHours = SetHours;
		
		this.SetMinutes = SetMinutes;
		
		this.SetSeconds = SetSeconds;
		
		this.SetMilliseconds = SetMilliseconds;
		
		this.SetDate = SetDate;
		
		this.Compare = Compare;
		
		this.IsLeapYear = IsLeapYear;
		
		this.IsValidDate = IsValidDate;

		this.ParseDate = ParseDate;		
				
		this.toString = ToString;
	}
	
	
	/*
	* Method: Clone
	* Return: DateTime
	*/
	function Clone()
	{
		var resultDate = new DateTime();
		resultDate.SetYear(this.GetYear());
		resultDate.SetMonth(this.GetMonth());
		resultDate.SetDay(this.GetDay());
		resultDate.SetHours(this.GetHours());
		resultDate.SetMinutes(this.GetMinutes());
		resultDate.SetSeconds(this.GetSeconds());
		resultDate.SetMilliseconds(this.GetMilliseconds());
		return resultDate;
	}
	
	
	/*
	* Method: AddYear
	* Param: intYearToAdd [Number Of Years To Add]
	* Return: int [Current Year After Add Years]
	*/
	function AddYear(intYearToAdd)
	{
		this.SetYear(this.GetYear() + intYearToAdd);
		return this.GetYear();
	}
	
	
	/*
	* Method: AddMonth
	* Param: intMonthToAdd [Number Of Months To Add]
	* Return: int [Current Month After Add Months]
	*/
	function AddMonth(intMonthToAdd)
	{
		this.SetMonth(this.GetMonth() + intMonthToAdd);
		return this.GetMonth();
	}
	
	
	/*
	* Method: AddDay
	* Param: intDayToAdd [Number Of Days To Add]
	* Return: int [Current Day After Add Days]
	*/
	function AddDay(intDayToAdd)
	{
		this.SetDate(this.GetDate() + intDayToAdd);
		return this.GetDate();
	}
	
	
	function AddHours(intHoursToAdd)
	{
		this.SetHours(this.GetHours() + intHoursToAdd);
		return this.GetHours();
	}
	
	
	function AddMinutes(intMinutesToAdd)
	{
		this.SetMinutes(this.GetMinutes() + intMinutesToAdd);
		return this.GetMinutes();
	}
	
	
	function AddSeconds(intSecondsToAdd)
	{
		this.SetSeconds(this.GetSeconds() + intSecondsToAdd);
		return this.GetSeconds();
	}
	
	
	function GetDate()
	{
		return this._date;
	}
	
	
	function GetYear()
	{
		return this._date.getFullYear();
	}
	
	
	function GetMonth()
	{
		return (this._date.getMonth()+1);
	}
	
	
	function GetDay()
	{
		return this._date.getDate();
	}
	
	/*
	* Name: GetDaysInMonth([year, month])
	* Return: int
	*/
	function GetDaysInMonth()
	{
		var daysInMonth = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);
		var yr;
		var mn;
		
		if(arguments.length == 2)
		{
			yr = arguments[0];
			mn = arguments[1];
		}
		else
		{
			yr = this.GetYear();
			mn = this.GetMonth();
		}
		
		if(mn == 2)
		{
			if(this.IsLeapYear(yr))
			{
				return 29;
			}
		}
		
		return daysInMonth[mn];
	}
	
	function GetWeekDay()
	{
		return this._date.getDay();
	}
	
	function GetWeekDayFullName()
	{
		var weekDays = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
		
		return weekDays[this.GetWeekDay()];
	}
	
	function GetWeekDayShortName()
	{
		return (this.GetWeekDayFullName()).substr(0,3);
	}
	
	function GetHours()
	{
		return this._date.getHours();
	}
	
	
	function GetMinutes()
	{
		return this._date.getMinutes();
	}
	
	
	function GetSeconds()
	{
		return this._date.getSeconds();
	}
	
	
	function GetMilliseconds()
	{
		return this._date.getMilliseconds();
	}
	
	
	function GetTime()
	{
		return this._date.getTime();
	}
	
	
	function GetMillsecondsDifference(objDate)
	{
		return Math.abs(this.GetTime() - objDate.GetTime());
	}
	
	
	function GetSecondsDifference(objDate)
	{
		var intMillsecondsDiff = this.GetMillsecondsDifference(objDate);
		return (intMillsecondsDiff/1000);
	}
	
	
	function GetMinutesDifference(objDate)
	{
		var intScondsDiff = this.GetSecondsDifference(objDate);
		return (intScondsDiff/60);
	}
	
	
	function GetHoursDifference(objDate)
	{
		var intMinutesDiff = this.GetMinutesDifference(objDate);
		return (intMinutesDiff/60);
	}
	
	
	function GetDayDifference(objDate)
	{
		var intHoursDiff = this.GetHoursDifference(objDate);
		return (intHoursDiff/24);
	}
	
	
	function GetMonthDifference(objDate)
	{
		var intDayDiff = this.GetDayDifference(objDate);
		return (intDayDiff/30);
	}
	
	
	function GetMonthFullName()
	{
		var monthNameArray = new Array ('','January','February',
									'March','April', 'May', 
									'June', 'July', 'August', 
									'September', 'October', 
									'November', 'December');
									
		return monthNameArray[this.GetMonth()];
	}
	
	
	function GetMonthShortName()
	{
		return (this.GetMonthFullName()).substr(0,3);
	}
	
	
	function SetDate(intYear, intMonth, intDay)
	{
		this.SetYear(intYear);
		this.SetMonth(intMonth);
		this.SetDay(intDay);
	}
	
	
	function SetYear(intYear)
	{
		this._date.setFullYear(intYear);
	}
	
	
	function SetMonth(intMonth)
	{
		this._date.setMonth(intMonth-1);
	}
	
	
	function SetDay(intDay)
	{
		this._date.setDate(intDay);
	}
	
	
	function SetHours(intHours)
	{
		this._date.setHours(intHours);
	}
	
	
	function SetMinutes(intMinutes)
	{
		this._date.setMinutes(intMinutes);
	}
	
	
	function SetSeconds(intSeconds)
	{
		this._date.setSeconds(intSeconds);
	}
	
	
	function SetMilliseconds(intMilliseconds)
	{
		this._date.setMilliseconds(intMilliseconds);
	}
	
	/*
	* <name>IsLeapYear</name>
	* <param name="year" required="false" dataType="int" />
	* <return>boolean</return>
	*/
	function IsLeapYear()
	{
		var yr;
		
		if(arguments.length == 0)
		{
			yr = this.GetYear();
		}
		else
		{
			yr = arguments[0];
		}
		
		if((yr % 4 == 0) && ((yr % 100 != 0) || (yr % 400 == 0)))
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function Compare(objDateTime)
	{
		if(this.GetDate() > objDateTime.GetDate())
		{
			return 1;
		}
		
		if(this.GetDate() == objDateTime.GetDate())
		{
			return 0;
		}
		
		if(this.GetDate() < objDateTime.GetDate())
		{
			return -1;
		}
	}
	
	function ParseDate(dateText, format)
	{
		format = format.toLowerCase();
		
		var seperator = "-";
		
		if(format.indexOf("/") != -1)
		{
			seperator = "/";
		}
		
		var formatParts = format.split(seperator);
		
		if(formatParts.length != 3)
		{
			return null;
		}
		
		var parts = dateText.split(seperator);
		
		if(parts.length == 3)
		{
			var m = 0;
			var d = 0;
			var y = 0;
			
			if(formatParts[0].indexOf("m") != -1)
			{
				m = parseInt(formatParts[0],10);
			}
			else if(formatParts[0].indexOf("d") != -1)
			{
				d = parseInt(formatParts[0],10);
			}
			else if(formatParts[0].indexOf("y") != -1)
			{
				y = parseInt(formatParts[0],10);
			}
			
			if(formatParts[1].indexOf("m") != -1)
			{
				m = parseInt(formatParts[1],10);
			}
			else if(formatParts[1].indexOf("d") != -1)
			{
				d = parseInt(formatParts[1],10);
			}
			else if(formatParts[1].indexOf("y") != -1)
			{
				y = parseInt(formatParts[1],10);
			}
			
			if(formatParts[2].indexOf("m") != -1)
			{
				m = parseInt(formatParts[2],10);
			}
			else if(formatParts[2].indexOf("d") != -1)
			{
				d = parseInt(formatParts[2],10);
			}
			else if(formatParts[2].indexOf("y") != -1)
			{
				y = parseInt(formatParts[2],10);
			}
			
			if(m == 0 || y == 0 || d == 0)
			{
				return null;
			}
			
			if(!this.IsValidDate(y,m,d))
			{
				return null;	
			}
			
			var dt = new DateTime();
			
			dt.SetDate(y, m ,d);
			
			return dt;
		}
		
		return null;
	}
	
	
	function IsValidDate(intYear, intMonth , intDay)
	{
		if(intYear < 1900 || intYear > 2500)
		{
			return false;
		}
		
		if(intMonth < 1 || intMonth > 12)
		{
			return false;
		}
		
		var lastDayList = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
		
		var lastDay = lastDayList[intMonth];
		
		if(intMonth == 2)
		{
			if((intYear % 4 == 0) && ((intYear % 100 != 0) || (intYear % 400 == 0)))
			{
				lastDay = 29; 
			}
		}
		
		if(intDay < 1 || intDay > lastDay)
		{
			return false;
		}
		
		return  true;
	}
	
	/*function ToUSFormat()
	{
		return this->GetMonth()."/".this->GetDay()."/".this->GetYear();
	}
		
	function ToUKFormat()
	{
		return this->GetDay()."/".this->GetMonth()."/".this->GetYear();
	}
	
	function ToDBFormat()
	{
		return this->GetYear()."-".this->GetMonth()."-".this->GetDay();
	}*/
	
	function ToString()
	{
		return this._date.toString();
	}
	
	//End of class DateTime