/* Initializations */
var fixclock = -3600000; /* Y2K Tool Clock Correction */
var fixclock = 0 
var timerID;
var timerRunning = false;
var today = new Date();
var enday = new Date();

var secPerDay = 0;
var minPerDay = 0;
var hourPerDay = 0;
var PerDay = 0;

var secsLeft = 0;
var secsRound = 0;
var secsRemain = 0;

var minLeft = 0;
var minRound = 0;
var minRemain = 0;

var daysLeft = 0;
var daysRound = 0;
var daysRemain = 0;

var hoursLeft = 0;
var hoursRound = 0;
var housRemain = 0;

var dayStat;
var hourStat;
var minStat;
var secStat;
var Only;
var LeftUntil;

/* This function will stop the clock */

function stopclock() 
{
if(timerRunning)
clearTimeout(timerID);
timerRunning = false;
}

/* This function will start the clock */

function startclock() 
{
stopclock();
showtime();
}

/* 
This is the heart of the script

today is the date today, wow.
enday is the date you want to count til. For this example enday is 
January 1st in the year 2000.
secsPerDay will be used to get the seconds per day, double wow.
you should be able to figure out minPerDay, hoursPerDay, and PerDay.
*/


function showtime() 
{
today = new Date();
enday = new Date("January, 1 2000 00:00");
enday.setYear(2000);
/*enday.setYear(today.getYear());*/
secsPerDay = 1000 ;
minPerDay = 60 * 1000 ;
hoursPerDay = 60 * 60 * 1000;
PerDay = 24 * 60 * 60 * 1000;


/*Seconds*/

/*
secsLeft is the raw seconds remaining until the date.
secsRound is the rounded seconds remaining until the date.
secsRemain is the re-configured seconds. The seconds need to be
limited from 59 to 0 much like a real clock counts. This will do it.
*/


// secsLeft = (enday.getTime() + fixclock - today.getTime()) / minPerDay;
secsLeft = (today.getTime() - (enday.getTime() + fixclock) ) / minPerDay;

secsRound = Math.round(secsLeft);

secsRemain = secsLeft - secsRound;

secsRemain = (secsRemain < 0) ? secsRemain = 60 - ((secsRound - secsLeft) 
* 60) : secsRemain = (secsLeft - secsRound) * 60;

secsRemain = Math.round(secsRemain);



/*Minutes*/

/*
minLeft is the raw minutes remaining until the date.
minRound is the rounded seconds remaining until the date.
minRemain is the re-configured minutes. The minutes need to be
limited from 59 to 0 much like a real clock. Gosh I feel like a
skipping record. Oh well.
*/


// minLeft = ((enday.getTime() + fixclock - today.getTime()) / hoursPerDay);
minLeft = ((today.getTime() - (enday.getTime() + fixclock)) / hoursPerDay);

minRound = Math.round(minLeft);

minRemain = minLeft - minRound;

minRemain = (minRemain < 0) ? minRemain = 60 - ((minRound - minLeft)  * 
60) : minRemain = ((minLeft - minRound) * 60);

minRemain = Math.round(minRemain - 0.495);



/*Hours*/

/*
hoursLeft is the raw hours remaining until the date.
hoursRound is the rounded hours remaining until the date.
hoursRemain is the re-configured hours. The hours need to be
limited from 23 to 0 much like a real clock. I think you're starting
to get the picture, no?
*/


// hoursLeft = ((enday.getTime() + fixclock - today.getTime()) / PerDay);
hoursLeft = ((today.getTime() - (enday.getTime() + fixclock)) / PerDay);

hoursRound = Math.round(hoursLeft);

hoursRemain = hoursLeft - hoursRound;

hoursRemain = (hoursRemain < 0) ? hoursRemain = 24 - ((hoursRound - 
hoursLeft)  * 24) : hoursRemain = ((hoursLeft - hoursRound) * 24);

hoursRemain = Math.round(hoursRemain - 0.5);


/*Days*/

/*
daysLeft is the raw days remaining until the date.
daysRound is the rounded days remaining until the date.
daysRemain is the re-configured days. The days need to be 
rounded, guess daysRound is not needed, but it sure looks 
good don't it?
*/


// daysLeft = ((enday.getTime() + fixclock - today.getTime()) / PerDay);
daysLeft = ((today.getTime() - (enday.getTime() + fixclock)) / PerDay);

daysLeft = (daysLeft - 0.5);

daysRound = Math.round(daysLeft);

daysRemain = daysRound;

/*Clean-Up*/

/*
This will make the screen look nice. It will add the words
days, hours, minutes, and seconds (or the singular depending
on the number). 
*/


if (daysRemain == 1) dayStat = " day, ";
        else dayStat = " days, "; 

if (hoursRemain == 1) hourStat = " hour, ";
        else hourStat = " hours, ";

if (minRemain == 1) minStat = " minute, ";
        else minStat = " minutes, ";

if (secsRemain == 1) secStat = " second";
        else secStat = " seconds";

Only = "Over ";
// LeftUntil = " left until the year 2000.";
LeftUntil = " since the year 2000 began.";

/*Time*/

/*
timeRemain is the simplified version of the Clean-Up. It makes it
more elegant.
document.clock.face.value is used to show the time remaining.
timeID controls the refresh rate of the clock. The number is the rate in 
milliseconds.
The if statement will stop the clock when the time has expired.
*/

/*
timeRemain = daysRemain + hoursRemain + minRemain + secsRemain;
*/

/*
for form display
*/

document.clock.face.value = Only + daysRemain + dayStat + hoursRemain + hourStat 
+ minRemain + minStat + secsRemain +secStat + LeftUntil;

// window.status = "Time Remaining: " + daysRemain + dayStat + hoursRemain + 
// window.status = "Elapsed Time Since 2000 Began: " + daysRemain + dayStat + hoursRemain + 
hourStat + minRemain + minStat + secsRemain +secStat;
timerID = setTimeout("showtime()",100);
timerRunning = true;

if (daysRemain == -1) 
{

document.clock.face.value = "Welcome to the year 2000!";
window.status = "Welcome to the year 2000!";
clearTimeout(timerID);
timerRunning = false;

}

if (daysRemain < -1) 
{

document.clock.face.value = "The day has arrived......";
window.status = "The day has arrived......";
clearTimeout(timerID);
timerRunning = false;

}

}

// End hiding script from old browsers -->

