<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->


<!-- Begin

// find selected day
urlvar = unescape(document.location);
if(urlvar.indexOf('date') != -1) {
    urlvarstr = urlvar.split("?");

    selected_day = urlvarstr[1].slice(13,15);
    if(selected_day.charAt(0) == '0')
        selected_day = urlvarstr[1].slice(14,15);
    
    else
        selected_day = urlvarstr[1].slice(13,15);

    selected_month = urlvarstr[1].slice(10,12);
    if(selected_month.charAt(0) == '0')
        selected_month = urlvarstr[1].slice(11,12);
    
    else
        selected_month = urlvarstr[1].slice(10,12);
}
else {
    selected_day = 0;
    selected_month = 0;
}

schedule_url = new String("/php/racing_schedule.php");

months = new Array("January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December");

days = new Array(12);
days[0]=31;
days[1]=28;
days[2]=31;
days[3]=30;
days[4]=31;
days[5]=30;
days[6]=31;
days[7]=31;
days[8]=30;
days[9]=31;
days[10]=30;
days[11]=31;

rightnow = new Date();
day = rightnow.getDay();
month = rightnow.getMonth();
date = rightnow.getDate();
year = (rightnow.getFullYear()%100) + 2000;

// is this leap year
if(((year%4==0) && !(year%100==0)) || (year%400==0))
days[1]++;

daysBefore = date;

while(daysBefore > 7)
daysBefore -= 7;

daysBefore = day - daysBefore + 1;

if(daysBefore < 0)
daysBefore += 7;

document.write("<table align='center' border='1' cellpadding='3' cellspacing='0' width='30%' bgcolor='#b0a78e'>");
document.write("<tr><td colspan=7 bgcolor='993300'><font color=white><center><strong>" + months[month] + " " + year + "</strong></center></font></td></tr>");
document.write("<tr>");
document.write("<td align=center><font color=black>Sun</font></td>");
document.write("<td align=center><font color=black>Mon</font></td>");
document.write("<td align=center><font color=black>Tue</font></td>");
document.write("<td align=center><font color=black>Wed</font></td>");
document.write("<td align=center><font color=black>Thu</font></td>");
document.write("<td align=center><font color=black>&nbsp;Fri&nbsp;</font></td>");
document.write("<td align=center><font color=black>Sat</font></td>");
document.write("</tr>");
document.write("<tr>");

// fill beginning spaces before first day of month
if(month == 0)
count = (days[11] - (daysBefore - 1));
else
count=(days[month-1] - (daysBefore - 1));
if(daysBefore > 0){
  for(i = 0; i < daysBefore; i++){
     if(month == 0)
        document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + (year - 1) + "-12-" + count +"\"><font color='999999'>" + count + "</font></a></td>");
     else
        document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + month + "-" + count +"\"><font color='999999'>" + count + "</font></a></td>");

  count++;
  }
}
else{
count = (days[month-1]-6);
 for(i=1;i<8;i++){
  if(month==0)
     document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + year + "-12-" + count + +"\"><font color='999999'>" + count + "</font></a></td>");
  else
     document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + month + "-" + count +"\"><font color='999999'>" + count + "</font></a></td>");

  count++;
 }
document.write("</tr>");
}
count = 1;
rowcount = 0;
daycount = daysBefore;

//days of the month

for (b=0;((b<days[month]+1)&&(count <= days[month]));b++){
  if(count < 10){
     if(count != date){
       if(count == selected_day && selected_month == (month+1))
         document.write("<td bgcolor=\"#99CCCC\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + (month+1) + "-" + "0" + count+"\">");
       else
         document.write("<td bgcolor=\"#FFFFEE\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + (month+1) + "-" + "0" + count+"\">");
     }
     else 
     document.write("<td bgcolor=\"#ffcc99\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + (month+1) + "-" + "0" + count+"\">");
   }
  else{
    if(count != date){
     if(count == selected_day && selected_month == (month+1))
       document.write("<td bgcolor=\"#99CCCC\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + (month+1) + "-" + count+"\">");
     else
       document.write("<td bgcolor=\"#FFFFEE\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + (month+1) + "-" + count+"\">");
    }
    else
     document.write("<td bgcolor=\"#ffcc99\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + (month+1) + "-" + count+"\">");
   }
  if(count == date){
     document.write("<font color = #336633><strong>" + count + "</font>");
  }
  else if (count <= days[month]){
     document.write("<font color='#336633'>" + count + "</font>");
  }

  document.write("</a>");
  document.write("</td>");
  count++;
  daycount++;

  if(daycount == 7){
     document.write("</tr>");
     document.write("<tr>");
     daycount=0;
  }
}

// calendar days for next month

count = (count + daysBefore) - 1;
daycount = 1;

if(count == 35 || count == 42){
  for(i=1; i<8; i++){
    if(month==11)
       document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + (year+1) + "-01-" + daycount +"\"><font color='999999'>" + daycount + "</font></a></td>");
    else   
       document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + (month+2)+ "-" + daycount + "\"><font color='999999'>" + daycount + "</font></a></td>");

    count++;
    daycount++;
  }
}
else{
  daycount = 1;
   if(count > 35){
      for(i=count; i<42; i++){
        if(month==11)
           document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + (year+1) + "-01-" + daycount +"\"><font color='999999'>" + daycount + "</font></a></td>");
        else   
           document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + (month+2)+ "-" + daycount + "\"><font color='999999'>" + daycount + "</font></a></td>");

        count++;
        daycount++;
     }
  }
  else if(count < 35){
      for(i=count;i<35;i++){
        if(month==11)
           document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + (year+1) + "-01-" + daycount +"\"><font color='999999'>" + daycount + "</font></a></td>");
        else    
           document.write("<td bgcolor=\"#DFDFCE\" align=center><a href=\""+schedule_url+"?date=" + year + "-" + (month+2)+ "-" + daycount + "\"><font color='999999'>" + daycount + "</font></a></td>");

      count++;
      daycount++;
     }
  }
}
document.write("</tr>");
document.write("</table></p>");
//End-->
