// Date Routines
//

function MakeArray(n)
{
	this.length = n;
	return this;
}

monthNames = new MakeArray(12);
monthNames[1] = "Jan";
monthNames[2] = "Feb";
monthNames[3] = "Mar";
monthNames[4] = "Apr";
monthNames[5] = "May";
monthNames[6] = "Jun";
monthNames[7] = "Jul";
monthNames[8] = "Aug";
monthNames[9] = "Sep";
monthNames[10]= "Oct";
monthNames[11]= "Nov";
monthNames[12]= "Dec";

day_Names = new MakeArray(7);
day_Names[0] = "Sun";
day_Names[1] = "Mon";
day_Names[2] = "Tue";
day_Names[3] = "Wed";
day_Names[4] = "Thu";
day_Names[5] = "Fri";
day_Names[6] = "Sat";

var Current_Date  = new Date();
var Current_Year  = Current_Date.getYear();
var Current_Day   = Current_Date.getDate();
if ( Current_Year < 1000 )	{ Current_Year += 1900; }
var Current_Month = Current_Date.getMonth();
var Current_Dow   = Current_Date.getDay();

var mon	= Current_Month;
var day	= Current_Day;
var yer	= GetCurrentDate();
var cal	= no2( day ) + "-" + monthNames[mon] + "-" + yer;
var msg	= "";

function no2( anum ) {
	return( ((anum<10) ? "0" : "") + anum );
}
function nos2( anum ) {
	return( ((anum<10) ? "&nbsp;" : "") + anum );
}

function GetCurrentDate() {
// Now set the Date variables
	dt	= new Date();
	mon	= dt.getMonth()+1;
	day	= dt.getDate();
	yer	= dt.getYear();
	if ( yer < 1000 ) { yer += 1900; }
// Now build the string for the calendar date.
	cal	= no2( day ) + "-" + monthNames[mon] + "-" + yer;

	Current_Date  = new Date();
	Current_Year  = Current_Date.getYear();
	Current_Day   = Current_Date.getDate();
	if ( Current_Year < 1000 )	{ Current_Year += 1900; }
	Current_Month = Current_Date.getMonth();

	return( yer );
}

function GetDate(){
	yer	= GetCurrentDate();
	return( cal );
}

function GetDow(){
	dt	= new Date();
	dowy	= dt.getDay();
	return( day_Names[dowy] );
}

function WriteDatem(){
	yer	= GetCurrentDate();
	document.write( cal );
}

function WriteDate(){
 	cal	= GetDate();
	document.write( cal );
}

function WriteDow(){
	adow	= " " + GetDow();
	document.write( adow );
}
function WriteDows(){
	adow	= GetDow();
	document.write( adow );
}
function WriteDateDT(){
	WriteDatem();
	document.write( ' ' );
	WriteDow();
	document.write( ' ' );
	WriteTime();
}
function WriteHoliDS(){
	WriteHoli();
	Write_Holiday();
	Write_Season();
}

function WriteTime(){
	tm	= Get_Time();
	document.write( tm );
}

function Get_Time(){
// Now set the Time variables
	dt2	= new Date();
	hrs	= dt2.getHours();
	min	= dt2.getMinutes();
	sec	= dt2.getSeconds();
// And then correct to civilian time
	phr	= (hrs>12)?hrs-12:hrs;
	tm	=  no2(phr) + ":";
	tm	+= no2(min) + ":";
	tm	+= no2(sec) + " ";
	tm	+= (hrs>=12) ? "pm" : "am";
	return( tm );
}

var tclk	= ""; // holds the time
// Show Clock continously
function aclock()
{
	var cdt	= new Date();
	var hrs	= cdt.getHours();
	var min	= cdt.getMinutes();
	var sec	= cdt.getSeconds();
	var ampm= ""; // holds the time

//if the first radio button is checked display 12-hours format time
	// add "AM" or "PM" if the 12-hours format is chosen
	// convert the hour to 12-hours format
	// javascript returns midnight as 0, but since the time is in the 12-hours format
	// force javascript to return 12
	ampm	= ((hrs >= 12) ? " PM" : " AM");
	hrs	= ((hrs == 0) ? "12" : (hrs > 12) ? hrs - 12 : hrs);

	hrs	= nos2(hrs);
	min	= no2(min);
	sec	= no2(sec);
	tclk	= hrs + ":" + min + ":" + sec + ampm;
	return( tclk );
}
// Show Clock continously
function clock()
{
	elem	= document.getElementById( "jsClock" );
	if ( elem )
	{
	elem.innerHTML = aclock();
	setTimeout("clock()", 1000);
	}
}
// Show Clock continously
function clock2()
{
	elem	= document.getElementById( "jsClock2" );
	if ( elem )
	{
	elem.innerHTML = aclock();
	setTimeout("clock2()", 1000);
	}
}
// Show Clock continously
function clock3()
{
	elem	= document.getElementById( "jsClock3" );
	if ( elem )
	{
	elem.innerHTML = aclock();
	setTimeout("clock3()", 1000);
	}
}
