//<SCRIPT LANGUAGE="JavaScript">

Date.prototype.Add = function( interval, i )
{
	var newdate = new Date( this );
	switch (interval)
	{
		case 'd':
		{
			newdate.setDate( this.getDate() + i );
			return newdate;
		}
		case 'w':
		{
			newdate.setDate( this.getDate() + i*7 );
			return newdate;		
		}
	
	}
}

Date.prototype.Diff = function (dEnd,interval)
{
	var iDateSInMS = this.getTime();
	var iDateEInMS = dEnd.getTime();
	var iDivisor;
	iDiffInMS = iDateEInMS - iDateSInMS
	switch (interval) 
	{
	 	case 'd' :
	 		iDivisor = oneDay;
       		break;
   		case 'w' :
       		iDivisor = oneWeek;
       		break;
    }	
	return Math.round(iDiffInMS/iDivisor)
}

Date.prototype.WeekStart = function ()
{
	var dDate = new Date(this)
	var iDateInMS = dDate.getTime()
	var iDay = dDate.getDay()
	while (iDay > 0)
	{
		iDateInMS = dDate.getTime()
		iDateInMS -= oneDay
		dDate.setTime(iDateInMS)
		iDay = dDate.getDay()
	} 
	return dDate
}

Date.prototype.WeekEnd = function ()
{
	var dDate = new Date(this)
	var iDateInMS = dDate.getTime()
	var iDay = dDate.getDay()
	while (iDay < 6)
	{
		iDateInMS = dDate.getTime()
		iDateInMS += oneDay
		dDate.setTime(iDateInMS)
		iDay = dDate.getDay()
	} 
	return dDate
}

Date.prototype.ModifyDate = function ModifyDate(sUnit,iValue)
{
	var dNewDate = new Date()
	var iDateInMS = this.getTime()
	switch (sUnit) 
	{
   		case 'd' :
   		case 'day' :
       		iNewDateInMS = iDateInMS + (oneDay * iValue)
       		dNewDate.setTime(iNewDateInMS)
       		break;
   		case 'w' :
   		case 'week' :
       		iNewDateInMS = iDateInMS + (oneWeek * iValue)
       		dNewDate.setTime(iNewDateInMS)
       		break;
    } 
	return dNewDate
}

Date.prototype.DatabaseDate = function()
{
	return (this.getMonth()+1) + '/' + this.getDate() + '/' + this.getFullYear()
}

Date.prototype.fDate = function()
{
	return (this.getMonth()+1) + '/' + this.getDate() + '/' + this.getFullYear()
}

Date.prototype.EnglishString = function()
{
	var d = this.getDate() 
	
	if (d<10)
		d = '0' + d
		
	var m = (this.getMonth()+1)

	if (m<10)
		m = '0' + m

	return d + '/' + m + '/' + this.getFullYear()
}

//</SCRIPT>
