
var servertime 	= 1166464686 * 1000;
var MSECSINDAY = 1000 * 60 * 60 * 24;
//servertime = servertime +(71 * MSECSINDAY);
servertime = servertime - (new Date(servertime).getDate() * MSECSINDAY) + MSECSINDAY; 
var time = new Date(servertime);	
var thistime = new Date(servertime);	

var interval = 0;
//var time = new Date();
//var todayDate = time.getDate();
var todayDate = 1;
var todayDay = time.getDay();
var month, date, year;
var daynames = new Array("S", "M", "T", "W", "T", "F", "S");
var monthnames = new Array();
monthnames[1] = "January";
monthnames[2] = "February";
monthnames[3] = "March";
monthnames[4] = "April";
monthnames[5] = "May";
monthnames[6] = "June";
monthnames[7] = "July";
monthnames[8] = "August";
monthnames[9] = "September";
monthnames[10] = "October";
monthnames[11] = "November";
monthnames[12] = "December";

MonthEnd = new Array(12);
MonthEnd[0]  = 31;
MonthEnd[1]  = 28;
MonthEnd[2]  = 31;
MonthEnd[3]  = 30;
MonthEnd[4]  = 31;
MonthEnd[5]  = 30;
MonthEnd[6]  = 31;
MonthEnd[7]  = 31;
MonthEnd[8]  = 30;
MonthEnd[9]  = 31;
MonthEnd[10] = 30;
MonthEnd[11] = 31;

var OLDclink = "http://www.centralvalley.com/portal/getout/accesscentral/search/index.html?AC_type=event&AC_occur_start_date_time=%3D%20";
var clink  = "http://search.fresnobee.com/search-bin/search.pl.cgi?product=Events&sf_meta_product=Events&live_template=http%3A%2F%2Fwww.fresnobee.com%2Fshopping%2Fevents%2Findex.html&collection=NONE&fields=*&results_per_page=10&aggregate_key=meta_rollup&sort=events_event_occur_start_dt%20asc&sf_meta_object_type=Event_Event&sf_events_event_occur_start_dt=%3E";
 
getNextDate(interval);
printCalTop();
document.write("<tr>");
//if(todayDay != 0) { time = new Date(time - (MSECSINDAY * todayDay)); }
for (x = 0;  x < todayDay; x++)
{
    document.write("<td>&nbsp;</td>");
}
printCalWeeks();
document.write("</table>");

function zeroFill(x)
{
 if(x < 10) { x = "0" + x; }
 return x;
}

function getNextDate(interval)
{
 time = new Date(time.getTime() + interval);
 month = time.getMonth() + 1;
 date = time.getDate();
 year = time.getYear() + 1900;

 if (year > 2100)
 {
    year = year - 1900;
 }
}

function printCalWeeks()
{
 //document.write("<tr>");
 for(x = todayDay; x < 35; x++)
 {
  if(x % 7 == 0) { document.write("</tr><tr>"); }
  if(date == todayDate) 
  {
   dayclasstag = "calCurrDay"; 
   cellclasstag = "calCurrBG";
  }
  else 
  {
   dayclasstag = "calDate"; 
   cellclasstag = "calBG";
  }
 
var nextDayToPrint= date;
var nextMonthToPrint = month;
var nextYearToPrint = year;
if((date+1) == MonthEnd[month-1]+1)
{
//   if(month <= 10) {
//      nextMonthToPrint+=1;
//   } else {
//      nextMonthToPrint=0;
//      nextYearToPrint+=1;
//   }
//   nextDayToPrint=1;
//} else {
//   nextDayToPrint+=1;
    fillDate();
    for (y = 6 - time.getDay() ; y >= 0; y--)
    {
        //alert(y);
        if ((time.getDay() % 7) != 0)
        {
            document.write("<td>&nbsp;</td>");
        }
    }
    break;
}
else
{
    nextDayToPrint+=1;
}

fillDate();

 }
 document.write("</tr>");
}
function fillDate()
{
    var nextDayToPrint= date;
    var nextMonthToPrint = month;
    var nextYearToPrint = year;
    linkdate ="+" + month + "%2F" + date + "%2F" + year;
    altlinkdate = nextMonthToPrint + "%2F" + nextDayToPrint + "%2F" + nextYearToPrint + "+23:59:59";
    thislink = clink + linkdate + "+%3B+%3C+" + altlinkdate;

//%3E+7%2F6%2F2004+%3B+%3C+7%2F7%2F2004

    document.write("<td align='center' class='" + cellclasstag + "'>");
    if(time >= thistime)
    {
        document.write("<a href='" + thislink + "' class='" + dayclasstag + "'>" + date + "</a>"); }
    else
    {
        document.write("<span class='calPastDate'>" + date + "</span>"); }
    document.write("</td>");
    getNextDate(MSECSINDAY);
}

function printCalTop()
{
 document.write("<table border='0' class='calBG' ellpadding='0' cellspacing='0' width='140' height='100%'>");
 document.write("<tr><td colspan='7' align='center' class='calBG'>" + monthnames[month] + "</td></tr>");
 document.write("<tr>");
 for(x = 0; x < 7; x++) { document.write("<td align='center' class='calDayName'>" + daynames[x] + "</td>"); }
 document.write("</tr>");
}

