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


function showCalendar(requestDate,affid,affcode){
    // find selected day
  {
        selected_day = 0;
        selected_month = 0;
    }
    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;
    
    rd = requestDate.replace(/-/g,'/');
    rightnow = new Date(rd);
    day = rightnow.getDay();
    month = rightnow.getMonth();
    date = rightnow.getDate();
    year = (rightnow.getFullYear()%100) + 2000;
    
    
    //build previous month date
		if (rightnow.getMonth() == 0) {
		    previous = new Date(rightnow.getYear() - 1, 11, 1);
		}else{
		    previous = new Date(rightnow.getYear(), rightnow.getMonth() - 1, 1);
		}
    pmonth = previous.getMonth()+1;
    pdate  = previous.getDate();
    pyear  = (previous.getFullYear()%100) + 2000;
     
     
    //build next month date
		if (rightnow.getMonth() == 0) {
		    next = new Date(rightnow.getYear() , 1, 1);
		}else{
		    next = new Date(rightnow.getYear(), rightnow.getMonth() + 1, 1);
		}
    nmonth = next.getMonth()+1;
    ndate  = next.getDate();
    nyear  = (next.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;
       
    schedule_url =  "racing_schedule.php?affid="+affid+"&affcode="+affcode;   
    pl = schedule_url+"&date=" + pyear+ "-" + pmonth + "-" + pdate;
    nl = schedule_url+"&date=" + nyear+ "-" + nmonth + "-" + ndate;
    
    document.write("<table cellspacing=0 class=smallCal>");
    document.write("<tr><td class=headerCol1><a href=\""+pl+"\"><</a> </td><td colspan=5 class=headerCol2>" + months[month] + " " + year + "</td><td class=headerCol3><a href=\""+nl+"\">></a> </td></tr>");
    document.write("<tr class=days>");
    document.write("<td>Sun</td>");
    document.write("<td>Mon</td>");
    document.write("<td>Tue</td>");
    document.write("<td>Wed</td>");
    document.write("<td>Thu</td>");
    document.write("<td>Fri</td>");
    document.write("<td>Sat</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 class=\"pastDates\"><a href=\""+schedule_url+"&date=" + (year - 1) + "-12-" + count +"\">" + count + "</a></td>");
         else
            document.write("<td class=\"pastDates\"><a href=\""+schedule_url+"&date=" + year + "-" + month + "-" + count +"\">" + count + "</a></td>");
    
      count++;
      }
    }
    else{
    count = (days[month-1]-6);
     for(i=1;i<8;i++){
      if(month==0)
         document.write("<td class=\"pastDates\">c-<a href=\""+schedule_url+"&date=" + year + "-12-" + count + +"\">" + count + "</a></td>");
      else
         document.write("<td class=\"pastDates\"><a href=\""+schedule_url+"&date=" + year + "-" + month + "-" + count +"\">" + count + "</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 != date){
                document.write("<td class=\"currentMonth\"><a href=\""+schedule_url+"&date=" + year + "-" + (month+1) + "-" + count+"\">");
                 document.write("" + count + "</a></td>");
        }
        else{
            document.write("<td class=\"today\"><a href=\""+schedule_url+"&date=" + year + "-" + (month+1) + "-" + count+"\">");
        		document.write("" + count + "</a></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 class=futureDates><a href=\""+schedule_url+"&date=" + (year+1) + "-01-" + daycount +"\">" + daycount + "/a></td>");
        else   
           document.write("<td class=futureDates><a href=\""+schedule_url+"&date=" + year + "-" + (month+2)+ "-" + daycount + "\">" + daycount + "</a></td>");
    
        count++;
        daycount++;
      }
    }
    else{
      daycount = 1;
       if(count > 35){
          for(i=count; i<42; i++){
            if(month==11)
               document.write("<td class=futureDates><a href=\""+schedule_url+"&date=" + (year+1) + "-01-" + daycount +"\">" + daycount + "</a></td>");
            else   
               document.write("<td class=futureDates><a href=\""+schedule_url+"&date=" + year + "-" + (month+2)+ "-" + daycount + "\">" + daycount + "</a></td>");
    
            count++;
            daycount++;
         }
      }
      else if(count < 35){
          for(i=count;i<35;i++){
            if(month==11)
               document.write("<td class=futureDates><a href=\""+schedule_url+"&date=" + (year+1) + "-01-" + daycount +"\"><font color='999999'>" + daycount + "</a></td>");
            else    
               document.write("<td class=futureDates><a href=\""+schedule_url+"&date=" + year + "-" + (month+2)+ "-" + daycount + "\">" + daycount + "</a></td>");
    
          count++;
          daycount++;
         }
      }
    }
    document.write("</tr>");
    document.write("</table>");
    //End-->
}
