/*
Yes, I wrote this code, but with lots of "input" from http://www.w3schools.com/js/default.asp - thanks for all the great information!
webmaster@djsteiner.com
<body onload="startTime()">
*/


var d=new Date();
var day=(d.getDay()==0 || d.getDay()==6)?2:1;
var hh=d.getHours()
var mm=d.getMinutes();

/*
2012 FEDERAL HOLIDAYS

http://www.opm.gov/Operating_Status_Schedules/fedhol/2012.asp

New Year’s Day - Sunday, January 1
Memorial Day - Monday, May 28
Independence Day - Wednesday, July 4
Labor Day - Monday, September 3
Thanksgiving Day - Thursday, November 22 & Friday, November 23
Christmas Day - Tuesday, December 25

*/

// SETS HOLIDAY DATES
var holiday=((d.getMonth()==0 && d.getDate()==1) || 
(d.getMonth()==4 && d.getDate()==28) || 
(d.getMonth()==6 && d.getDate()==4) || 
(d.getMonth()==8 && d.getDate()==5) || 
(d.getMonth()==10 && d.getDate()==22) || 
(d.getMonth()==10 && d.getDate()==23) || 
(d.getMonth()==11 && d.getDate()==25))?1:2;


function startTime()
{
var d=new Date();
var day=(d.getDay()==0 || d.getDay()==6)?2:1;
var hh=d.getHours()
var mm=d.getMinutes();

var h=(d.getHours()>12)?(d.getHours()-12):d.getHours();
var m=d.getMinutes();
var s=d.getSeconds();
var ampm=(hh>=12)?" p.m.":" a.m.";


m=checkTime(m);
s=checkTime(s);


// sets start of greeting
if (hh<12)
{
var start="Good morning and welcome to Dog Central. Where is your dog playing today?";
}
else if (hh>=12 && hh<17)
{
var start="Good afternoon and welcome to Dog Central. Where is your dog playing today?";
}
else if (hh>=17 && hh<19)
{
var start="Good evening and welcome to Dog Central. Where is your dog playing today?";
}
else if (hh>=19)
{
var start="Good evening and welcome to Dog Central. Where is your dog playing tomorrow?";
}
else
{
var start="Hello and welcome to Dog Central.";
}


// sets end of greeting
if (hh==7 && mm>=10 && day==1 && holiday==2)
{
var ending="<br>If they were here, they could have been playing for up to " + mm + " minutes already!";
}
else if (hh==8 && day==1 && holiday==2)
{
var ending="<br>If they were here, they could have been playing for over 1 hour already!";
}
else if (hh>8 && hh<19 && mm<2 && day==1 && holiday==2)
{
var ending="<br>If they were here, they could have been playing for up to " + (hh-7) + " hours already!";
}
else if (hh>8 && hh<19 && mm>=2 && day==1 && holiday==2)
{
var ending="<br>If they were here, they could have been playing for up to " + (hh-7) + " hours and " + mm + " minutes already!";
}
else
{
var ending=" ";
}


// sets time left
if (hh>=7 && hh<17 && mm>=2 && mm<=58 && day==1 && holiday==2)
{
var timeleft=" We're open for the next " + (18-hh) + " hours and " + (60-mm) + " minutes. ";
}
else if (hh>=7 && hh<17 && mm>58 && day==1 && holiday==2)
{
var timeleft=" We're open for the next " + (18-hh) + " hours. ";
}
else if (hh>=7 && hh<17 && mm<2 && day==1 && holiday==2)
{
var timeleft=" We're open for the next " + (19-hh) + " hours. ";
}
else
{
var timeleft=" ";
}


document.getElementById('welcome').innerHTML=start + ending;
document.getElementById('play').innerHTML=timeleft;
document.getElementById('test').innerHTML=h+":"+m+":"+s;

t=setTimeout('startTime()',500);
// END FUNCTION startTime()
}


// adds a zero in front of numbers<10
function checkTime(i)
{
if (i<10)
{
i="0" + i;
}
return i;
}


// suffix1 code - for current date
var suf1 = d.getDate();

if (suf1==1 || suf1==21 || suf1==31)
{
suffix1="st";
}
else if (suf1==2 || suf1==22)
{
suffix1="nd";
}
else if (suf1==3 || suf1==23)
{
suffix1="rd";
}
else
{
suffix1="th";
}


// displays name month code
var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";


// displays hours, time of operation for current day

if (holiday==1 && hh>=4 && hh<19)
{
var hours1=("Because of the federal holiday, we're open <b>today</b>, " + month[d.getMonth()] + " " + d.getDate() + suffix1 + ", from 8 a.m.-9 a.m.," + "<br> 1 p.m.-2 p.m. and 6 p.m.-7 p.m. <b>for boarding only</b>.");
var hours3=("Because of the federal holiday, we're open <b>today</b>, " + month[d.getMonth()] + " " + d.getDate() + suffix1 + "," + "<br>from 8 a.m.-9 a.m., 1 p.m.-2 p.m. and 6 p.m.-7 p.m. <b>for boarding only</b>.");
var hours4=("Today's Hours (" + (d.getMonth() + 1) + "/" + d.getDate() + "): 8a-9a, 1p-2p and 6p-7p");
}
else if (day==1 && hh>=4 && hh<19)
{
var hours1=("We're open today, " + month[d.getMonth()] + " " + d.getDate() + suffix1 + ", from 7 a.m. to 7 p.m. ");
var hours3=("We're open today, " + month[d.getMonth()] + " " + d.getDate() + suffix1 + ", from 7 a.m. to 7 p.m. ");
var hours4=("Today's Hours (" + (d.getMonth() + 1) + "/" + d.getDate() + "): 7 a.m. to 7 p.m.");
}
else if (day==2 && hh>=4 && hh<19)
{
var hours1=("We're open today, " + month[d.getMonth()] + " " + d.getDate() + suffix1 + ", from 8 a.m.-9 a.m., 1 p.m.-2 p.m. and 6 p.m.-7 p.m.");
var hours3=("We're open today, " + month[d.getMonth()] + " " + d.getDate() + suffix1 + ", from 8 a.m.-9 a.m.,<br>" + "1 p.m.-2 p.m. and 6 p.m.-7 p.m.");
var hours4=("Today's Hours (" + (d.getMonth() + 1) + "/" + d.getDate() + "): 8a-9a, 1p-2p and 6p-7p");
}
else
{
var hours1=(" ");
var hours3=(" ");
var hours4=(" ");
}

/*
Jan=0, 31
Feb=1, 28 or 29 in 2012, 2016, 2020, 2024, 2028, 2032, 2036, 2040...
Mar=2, 31
Apr=3, 30
May=4, 31
Jun=5, 30
Jul=6, 31
Aug=7, 31
Sep=8, 30
Oct=9, 31
Nov=10, 30
Dec=11, 31
*/


// calculates nextmonth & nextdate variable
if (d.getMonth()==1 && d.getDate()<28)
{
var nextmonth=(d.getMonth());
var nextdate=(d.getDate()+1);
}
else if (d.getMonth()==1 && d.getDate()==28)
{
var nextmonth=(d.getMonth()+1);
var nextdate=(1);
}
else if ((d.getMonth()==3 || d.getMonth()==5 || d.getMonth()==8 || d.getMonth()==10) && (d.getDate()<30))
{
var nextmonth=(d.getMonth());
var nextdate=(d.getDate()+1);
}
else if ((d.getMonth()==3 || d.getMonth()==5 || d.getMonth()==8 || d.getMonth()==10) && (d.getDate()==30))
{
var nextmonth=(d.getMonth()+1);
var nextdate=(1);
}
else if ((d.getMonth()==0 || d.getMonth()==2 || d.getMonth()==4 || d.getMonth()==6 || d.getMonth()==7 || d.getMonth()==9 || d.getMonth()==11) && (d.getDate()<31))
{
var nextmonth=(d.getMonth());
var nextdate=(d.getDate()+1);
}
else if ((d.getMonth()==0 || d.getMonth()==2 || d.getMonth()==4 || d.getMonth()==6 || d.getMonth()==7 || d.getMonth()==9) && (d.getDate()==31))
{
var nextmonth=(d.getMonth()+1);
var nextdate=(1);
}
else
{
var nextmonth=(0);
var nextdate=(1);
}


// calculates next weekday
if (d.getDay()<=5)
{
var nextweekday=(d.getDay()+1);
}
else
{
var nextweekday=(0);
}


// names day of week
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";


// suffix2 code - for tomorrows date
if (nextdate==1 || nextdate==21 || nextdate==31)
{
suffix2="st";
}
else if (nextdate==2 || nextdate==22)
{
suffix2="nd";
}
else if (nextdate==3 || nextdate==23)
{
suffix2="rd";
}
else
{
suffix2="th";
}


/*
2012 FEDERAL HOLIDAYS

http://www.opm.gov/Operating_Status_Schedules/fedhol/2012.asp

New Year’s Day - Sunday, January 1
Memorial Day - Monday, May 28
Independence Day - Wednesday, July 4
Labor Day - Monday, September 3
Thanksgiving Day - Thursday, November 22 & Friday, November 23
Christmas Day - Tuesday, December 25

*/

// SETS TOMORROWS HOLIDAY DATES
var nextholiday=(
((d.getMonth()-11)==0 && (d.getDate()-30)==1) || 
(d.getMonth()==4 && (d.getDate()+1)==28) || 
(d.getMonth()==6 && (d.getDate()+1)==4) || 
(d.getMonth()==8 && (d.getDate()+1)==5) || 
(d.getMonth()==10 && (d.getDate()+1)==22) || 
(d.getMonth()==10 && (d.getDate()+1)==23) || 
(d.getMonth()==11 && (d.getDate()+1)==25))?1:2;


if (d.getFullYear()==2012 && d.getMonth()==1 && d.getDay()>27 && uh==0)
{
var hours2=(" ");
}
else if (nextholiday==1 && hh>=4)
{
var hours2=("Because of tomorrow's federal holiday, we're open from 8 a.m.-9 a.m., 1 p.m.-2 p.m." + "<br> and 6 p.m.-7 p.m. on " + weekday[nextweekday] + ", " +  month[nextmonth] + " " + nextdate + suffix2 +  " <b>for boarding only</b>.");
}
else if (d.getDay()<=4 && hh>=4 && holiday==1)
{
var hours2=("We're open tomorrow, " + weekday[nextweekday] + ", " +  month[nextmonth] + " " + nextdate + suffix2 + ", from 7 a.m. to 7 p.m.");
}
else if (d.getDay()>=5 && hh>=4 && holiday==1)
{
var hours2=("We're open tomorrow, " + weekday[nextweekday] + ", " +  month[nextmonth] + " " + nextdate + suffix2 + ", from 8 a.m.-9 a.m., 1 p.m.-2 p.m.<br>" +"and 6 p.m.-7 p.m.");
}
else if (d.getDay()>0 && d.getDay()<=4 && hh>=4 && hh<=17)
{
var hours2=("Our hours of operation tomorrow, " + weekday[nextweekday] + ", " +  month[nextmonth] + " " + nextdate + suffix2 + ", are the same as today.");
}
else if (d.getDay()==6 && hh>=4 && hh<=17)
{
var hours2=("Our hours of operation tomorrow, " + weekday[nextweekday] + ", " +  month[nextmonth] + " " + nextdate + suffix2 + ", are the same as today.");
}
else if (d.getDay()<=4 && hh>=4)
{
var hours2=("We're open tomorrow, " + weekday[nextweekday] + ", " +  month[nextmonth] + " " + nextdate + suffix2 + ", from 7 a.m. to 7 p.m.");
}
else if (d.getDay()>=5 && hh>=4)
{
var hours2=("We're open tomorrow, " + weekday[nextweekday] + ", " +  month[nextmonth] + " " + nextdate + suffix2 + ", from 8 a.m.-9 a.m., 1 p.m.-2 p.m.<br>" +"and 6 p.m.-7 p.m.");
}
else
{
var hours2=(" ");
}

