// Tasmanian State Championship Tournament 2007 Countdown Timer
// created by Dale Fyfe and some kind person at fillweb.com who wrote basically the whole of the javascript functions
// My part in this was basically to edit the functions to configure it for our own tournament and then integrate it into our existing web pages
// This code is used without permission - though it is stated as being free java script. If you are the author of this work and would like some more kudo's for your effort
// do not hesitate to contact the admin at dale@area52.com.au so that it can be done :D thank you! changed to the original code are marked with comments where appropriate.
// implemented on 14/3/2007

var timerID = 0;
var timerRunning = 0;
var today = 0;
var startday = 0;
var secPerDay = 0;
var minPerDay = 0;
var hourPerDay = 0;
var secsLeft = 0;
var secsRound = 0;
var secsRemain = 0;
var minLeft = 0;
var minRound = 0;
var minRemain = 0;
var timeRemain = 0;

/* This function will stop the clock */
function stopclock()
{
        if(timerRunning)
                clearTimeout(timerID);
        timerRunning = false;
}

/* This function will start the clock */
function startclock()
{
        stopclock();
        countdown();
}

function startclock_cn()
{
        stopclock();
        showtime_cn();
}

/* This function will display the count-up */
function countdown()
{
        startday = new Date("July 17, 2010 09:00 GMT+11");// date changed for the Event time of the Tournament by Dale Fyfe
        today = new Date();
        secsPerDay = 1000 ;
        minPerDay = 60 * 1000 ;
        hoursPerDay = 60 * 60 * 1000;
        PerDay = 24 * 60 * 60 * 1000;
        /* Seconds */
        secsLeft = (startday.getTime() - today.getTime()) / 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 = ((startday.getTime() - today.getTime()) / 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 = ((startday.getTime() - today.getTime()) / 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 = ((startday.getTime() - today.getTime()) / PerDay);
        daysLeft = (daysLeft - 0.5);
        daysRound = Math.round(daysLeft);
        daysRemain = daysRound;
        /* Time */
        if (daysRemain < 2)
        {
                day_rem = " day, "
        }
        else
        {
                day_rem = " days, "
        }
        if (hoursRemain < 2)
        {
                hour_rem = " hour, "
        }
        else
        {
                hour_rem = " hours, "
        }
        if (minRemain < 2)
        {
                min_rem = " minute, "
        }
        else
        {
                min_rem = " minutes, "
        }
        if (secsRemain < 2)
        {
                sec_rem = " second"
        }
        else
        {
                sec_rem = " seconds"
        }
		// String for the title of the event to count down to changed by Dale Fyfe
        daysRemain = "" + daysRemain + day_rem;
		hourRemain = "" + hoursRemain + hour_rem;
		minRemain = "" + minRemain + min_rem;
		secsRemain = "" + secsRemain + sec_rem;
        document.counter.days.value = daysRemain;
		document.counter.hours.value = hourRemain;
		document.counter.minutes.value = minRemain;
		document.counter.secs.value = secsRemain;
        timerID = setTimeout("countdown()",1000);
        timerRunning = true;
}