﻿
/*
Count down until any date script-
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/
//change the text below to reflect your own,
var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")

function countdown(yr,m,d,h,mm)
{
    theyear=yr;themonth=m;theday=d;thehour=h;theminute=mm;
    var today=new Date()
    var todayy=today.getYear()
    if (todayy < 1000)
        {todayy+=1900}
    var ampm="AM"
    if (h>11)
        {ampm="PM"}
    var todaym=today.getMonth()
    var todayd=today.getDate()
    var todayh=today.getHours()
    var todaymin=today.getMinutes()
    var todaysec=today.getSeconds()
    var mmm=""
    var hh=h
    var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
    var futurestring=montharray[m-1]+" "+d+", "+yr+" "+h
    futurestring+=":"+mm    
    var dd=Date.parse(futurestring)-Date.parse(todaystring)


    if (dd<-129649000)
        {
        var mydiv = document.getElementById("pnl_countdown");
        mydiv.style.display = "none"; //to hide it
        //mydiv.style.visibility = "block"; //to show it
        return
        }
    if (dd<1)
        {
        document.forms.frm.countdown_tb.value="";
        document.forms.frm.countdown_hdr.value="Opening Day!";  
        document.forms.frm.countdown_hdr2.value="Play Ball!";
        return
        }
    else
        {
        if (h>12)
            {hh=h-12}
        if (mm==0)
            {mmm=""}
        else if (mm<10)
            {mmm=":0"+mm}
            else 
                {mmm=":"+mm}    
        var futurestring2=montharray[m-1]+" "+d+", "+yr+" "+hh+mmm
        
        var dday=Math.floor(dd/(60*60*1000*24)*1)
        var ddd=""
        if (dday==1)
            {ddd=dday+" day "}
        if (dday>1)
            {ddd=dday+" days "}      
        var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
        
        var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
        var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1)
        var ss=dsec
        if (dsec<10)
            {ss="0"+dsec}
 

        document.forms.frm.countdown_tb.value=ddd+dhour+":"+dmin+":"+ss;
        document.forms.frm.countdown_hdr.value="Opening Day!";
        document.forms.frm.countdown_hdr2.value=futurestring2+" "+ampm;

        setTimeout("countdown(theyear,themonth,theday,thehour,theminute)",1000)
        }
    }
//enter the count down date using the format year/month/day
//countdown(2010,4,17,10)

