//NOTICE: All of these functions are dependant
//        on each other for their information.
//        Make changes with care.

//This function provides the full date and time.
function TheDate(){
	var now = new Date();

	return now;
	}


//This function provides just the year.
function TheYear01(){
	var now = TheDate();
	var year1 = now.getFullYear();

	return year1;
	}


//This function provides the shortened year.
function TheYear02(){
	var year2 = TheYear01();

	var A = year2.toString();
	var B = A.substring(2,4);
	year2 = parseInt(B);	

	return year2;
	}


//This function provides the shortened year with a zero.
function TheYear03(){
	var year3 = TheYear02();

	if (year3 < 10)
	{
		year3 = "0" + year3;
	};

	return year3;
	}

//This function provides the year for next year.
function TheYear04(){
	var now = TheDate();
	var year1 = now.getFullYear();
	    year1 = year1 + 1;

	return year1;
	}


//This function provides the number of days that have past this year, including today.
//The function also accounts for leap year.
function DaysPast(){
	var year = TheYear01();
	var now = TheDate();
	var firstday = new Date("January 1, "+ year);
	var daysgone =  now.getTime() - firstday.getTime();
	daysgone = Math.floor((daysgone / (1000 * 60 * 60 * 24)) + 1); 

	return daysgone;
	}

//This function provides the number of days that have past this year, minus today.
//The function also accounts for leap year.
function DaysPast01(){
	var year = TheYear01();
	var now = TheDate();
	var firstday = new Date("January 1, "+ year);
	var daysgone =  now.getTime() - firstday.getTime();
	daysgone = Math.floor((daysgone / (1000 * 60 * 60 * 24))); 

	return daysgone;
	}

//This function provides the number of days remaining for the current year.
//The function also accounts for leap year.
function RemainingDays(){
	var year = TheYear01();
	var now = TheDate();
	var lastday = new Date("December 31, "+ year);
	var daysleft =  lastday.getTime() - now.getTime();
	daysleft = Math.floor((daysleft / (1000 * 60 * 60 * 24)) +1);

	return daysleft;
	}


//This function provides the total number of days in the current year.
//The function also accounts for leap year.
function TotalDaysInYear(){
	var daysleft = RemainingDays();
	var daysgone = DaysPast();
	var totaldays = daysleft + daysgone;

	return totaldays;
	}


//This function provides the number of the day of the week.
function DayOfWeekNum(){
	var now = TheDate();
	var ThisDay = now.getDay();
	
	if (ThisDay == 0)
		{
		ThisDay = 7;	
		};

	return ThisDay;
	}


//This function provides the weekday of the current year in text form.
function DayOfWeek(){
	var ThisDay = DayOfWeekNum()
	var Day=new Array();

	Day[1]="Monday";
	Day[2]="Tuesday";
	Day[3]="Wednesday";
	Day[4]="Thursday";
	Day[5]="Friday";
	Day[6]="Saturday";
	Day[7]="Sunday";

	return Day[ThisDay];
	}


//This function provides the numeral month.
function TheMonth01(){
	var now = TheDate();
	var themonth=now.getMonth();
	themonth = themonth +1;

	return themonth;
	}

function TheMonth02(){
	var now = TheDate();
	var themonth=now.getMonth();
	themonth = themonth +1;
	
	if (themonth < 10)
	{
		themonth = "0" + themonth;
	};

	return themonth;
	}

//This funtion provides the month in the form of text.
function TheMonthText(){
	var now = TheDate();
	var TextMonth = TheMonth01();
	var Month=new Array();

	Month[1]="January";
	Month[2]="February";
	Month[3]="March";
	Month[4]="April";
	Month[5]="May";
	Month[6]="June";
	Month[7]="July";
	Month[8]="August";
	Month[9]="September";
	Month[10]="October";
	Month[11]="November";
	Month[12]="December";

	return Month[TextMonth];
	}


//This funtion provides the month in the lower case form of text.
function TheMonthText02(){
	var now = TheDate();
	var TextMonth = TheMonth01();
	var Month=new Array();

	Month[1]="january";
	Month[2]="february";
	Month[3]="march";
	Month[4]="april";
	Month[5]="may";
	Month[6]="june";
	Month[7]="july";
	Month[8]="august";
	Month[9]="september";
	Month[10]="october";
	Month[11]="november";
	Month[12]="december";

	return Month[TextMonth];
	}

//This function provides the day of the month.
function TheDay01(){
	var now = TheDate();
	var theday=now.getDate();
	
	return theday;
	}


//This function provides the day of the month.
function TheDay02(){
	var theday = TheDay01();

	if (theday < 10)
	{
		theday = "0" + theday;
	};
	
	return theday;
	}

//This Function provides the full date with the day of the week.
function FullDate01(){
	var weekday = DayOfWeek();
	var textmonth = TheMonthText();
	var theday = TheDay02();
	var theyear = TheYear01();

	var alldate = weekday + ", " + textmonth + " " + theday + ", " + theyear;

	return alldate;

	}


//This Function provides the normal full date.
function FullDate02(){
	var weekday = DayOfWeek();
	var textmonth = TheMonthText();
	var theday = TheDay02();
	var theyear = TheYear01();

	var alldate = textmonth + " " + theday + ", " + theyear;

	return alldate;

	}


//This Function provides the abbreviated full date.
function FullDate03(){
	var themonth = TheMonth02();
	var theday = TheDay02();
	var theyear = TheYear01();

	var alldate = themonth + "/" + theday + "/" + theyear;

	return alldate;

	}


//This Function provides the abbreviated full date.
function FullDate04(){
	var themonth = TheMonth02();
	var theday = TheDay02();
	var theyear = TheYear03();

	var alldate = themonth + "/" + theday + "/" + theyear;

	return alldate;

	}

//This function tells the user the last day the page was updated.
function LastupDate01(){
	var lastUpdate = new Date(document.lastModified);
	var pagemonth = lastUpdate.getMonth() + 1;
	var pageday = lastUpdate.getDate();
	var pageyear=lastUpdate.getFullYear();

	if (pagemonth < 10)
	{
		pagemonth = "0" + pagemonth;
	};

	if (pageday < 10)
	{
		pageday = "0" + pageday;
	};
	
	var TellPageDate = pagemonth + '/' + pageday + '/' + pageyear;

	return TellPageDate;
	}


//This function tells the user the last day the page was updated.
function LastupDate02(){
	var lastUpdate = new Date(document.lastModified);
	var pagemonth = lastUpdate.getMonth() + 1;
	var pageday = lastUpdate.getDate();
	var pageyear=lastUpdate.getFullYear();

	if (pagemonth < 10)
	{
		pagemonth = "0" + pagemonth;
	};

	if (pageday < 10)
	{
		pageday = "0" + pageday;
	};

	var A = pageyear.toString();
	var B = A.substring(2,4);
	pageyear = parseInt(B);	

	if (pageyear < 10)
	{
		pageyear = "0" + pageyear;
	};
	
	var TellPageDate = pagemonth + '/' + pageday + '/' + pageyear;

	return TellPageDate;
	}


//Quick Test to see if current year is a leap year.
function TestForLeap(){
	var testdays = TotalDaysInYear();
	var leaptest = (testdays > 365);

	return leaptest;
	}


function weekNo() {

	var totalDays = DaysPast();
	var now = TheDate();
	var year = TheYear01();
	var thedate = new Date("January 1, "+ year);
	var firstday = thedate.getDay() + 1;

	var diff = 7 - firstday;
	var week =  Math.round((totalDays + diff - firstday) / 7); 
	
	return week;
}


function weekleft() {

	var totalDays = DaysPast();
	var now = TheDate();
	var year = TheYear01();
	var thedate = new Date("January 1, "+ year);
	var firstday = thedate.getDay() + 1;

	var diff = 7 - firstday;
	var week = 52 - Math.round((totalDays + diff - firstday) / 7); 
	
	return week;
}
