
var globalMonth = 0;
var globalYear = 0;

function leapYear(year){
   if (year % 4 == 0) // basic rule
   {
     return true; // is leap year
   }
   /* else */ // else not needed when statement is "return"
   return false; // is not leap year
}

function getDays(month, year){
   // create array to hold number of days in each month
   var ar = new Array(12);
   ar[0] = 31; // January
   ar[1] = (leapYear(year)) ? 29 : 28; // February
   ar[2] = 31; // March
   ar[3] = 30; // April
   ar[4] = 31; // May
   ar[5] = 30; // June
   ar[6] = 31; // July
   ar[7] = 31; // August
   ar[8] = 30; // September
   ar[9] = 31; // October
   ar[10] = 30; // November
   ar[11] = 31; // December

   // return number of days in the specified month (parameter)
   return ar[month];
}

function getMonthName(month){
   // create array to hold name of each month
   var ar = new Array(12);
   ar[0] = "January";
   ar[1] = "February";
   ar[2] = "March";
   ar[3] = "April";
   ar[4] = "May";
   ar[5] = "June";
   ar[6] = "July";
   ar[7] = "August";
   ar[8] = "September";
   ar[9] = "October";
   ar[10] = "November";
   ar[11] = "December";

   // return name of specified month (parameter)
   return ar[month];
}





function setCal(xmonth,xyear)
{
   if((xyear == "2005")||(xyear == "2006")||(xyear == "2007")||(xyear == "2008")||(xyear == "2009")||(xyear == "2010")||(xyear == "0"))
   {
      if(xmonth == 13) //current month - initial occurance
      {
         // standard time attributes
         var now = new Date();
         var year = now.getFullYear();
         var month = now.getMonth();
         globalMonth = month;
         globalYear = year;
         var monthName = getMonthName(month);
         var date = now.getDate();
         now = null;
      }
      else
      {
         var year = xyear;
         var month = xmonth;
         var monthName = getMonthName(month);
         globalMonth = month;
         globalYear = year;
         var now = new Date();
         var currmonth = now.getMonth();
         var curryear = now.getFullYear();
         if((xmonth == currmonth)&&(xyear == curryear))
         {
            var date = now.getDate();
         }
         else
         {
            var date = 0;
         }
         now = null;
      }

      // create instance of first day of month, and extract the day on which it occurs
      var firstDayInstance = new Date(year, month, 1);
      var firstDay = firstDayInstance.getDay();
      firstDayInstance = null;

      // number of days in current month
      var days = getDays(month, year);

      // call function to draw calendar and get resulting text string
      monthhtml = drawCal(firstDay + 1, days, date, month, monthName, year);
      writeToFrame(monthhtml);
   }
   else
   {
      alert("Schedule only active for years 2005-2010.");
   }

}

function drawCal(firstDay, lastDate, date, month, monthName, year)
{
   //calculate prev & next months
   var prevmonth = (month*1) - 1;
   var prevyear = year;
   if(prevmonth == -1)
   {
      prevmonth = 11;
      prevyear = (prevyear*1) - 1;
   }

   var nextmonth = (month*1) + 1;
   var nextyear = year;
   if(nextmonth == 12)
   {
      nextmonth = 0;
      nextyear = (nextyear*1) + 1;
   }



   // create basic table structure
   var text = ""; // initialize accumulative variable to empty string
   text += '<html>';
   text += '<head>';
   text += '<LINK REL="stylesheet" TYPE="text/css" HREF="cal.css">';
   //text += '<LINK REL="stylesheet" TYPE="text/css" HREF="admin.css">';
   text += '</head>';
   text += '<body bgcolor="#000000" style="margin:0 0 0 0;">';




   text += '<TABLE BORDER=0 CELLSPACING=1 cellpadding=3 width="100%" bgcolor="#555555">'; // table settings
   text += '<td colspan=7 bgcolor="#000000">';
      //table within a table
      text += '<table cellspacing="0" cellpadding="0" border="0" width="100%"><tr>';
      text += '<td>';
      text += '&nbsp\;&nbsp\;<a href="javascript:top.setCal(' + prevmonth + ',' + prevyear + ')" class="clinx" title="Previous month">&lt\;&nbsp\;PREV</a>';
      text += '</td>';
      text += '<td width="98%" align="center">';
      text += '<FONT COLOR="#d499ff" SIZE=6 face="trebuchet ms"><i>'; // set font for table header
      text += monthName + ' ' + year; 
      text += '</i></FONT>'; // close table header's font settings
      text += '</td>';
      text += '<td>';
      text += '<a href="javascript:top.setCal(' + nextmonth + ',' + nextyear + ')" class="clinx" title="Next month">NEXT&nbsp\;&gt\;</a>&nbsp\;&nbsp\;';
      text += '</td>';
      text += '</tr></table>';
   text += '</td>';



   // variables to hold constant settings
   var openCol = '<TD BGCOLOR="#000000" WIDTH="14%">';
   openCol += '<FONT COLOR="#d499ff" face="verdana" size="1">';
   var closeCol = '</FONT></TD>';

   // create array of abbreviated day names
   var weekDay = new Array(7);
   weekDay[0] = "Sun";
   weekDay[1] = "Mon";
   weekDay[2] = "Tue";
   weekDay[3] = "Wed";
   weekDay[4] = "Thu";
   weekDay[5] = "Fri";
   weekDay[6] = "Sat";
 	
   // create first row of table to set column width and specify week day
   text += '<TR ALIGN="center" VALIGN="center">';
   for (var dayNum = 0; dayNum < 7; ++dayNum) {
     text += openCol + weekDay[dayNum] + closeCol; 
   }
   text += '</TR>';
 	
   // declaration and initialization of two variables to help with tables
   var dayOfMonth = 1;
   var curCell = 1;

   for (var row = 1; row <= Math.ceil((lastDate + firstDay - 1) / 7); ++row)
   {
      text += '<TR VALIGN="top">';
      for (var col = 1; col <= 7; ++col)
      {
         if ((curCell < firstDay) || (dayOfMonth > lastDate))
         {
            text += '<TD  HEIGHT="70" BGCOLOR="#000000">\&nbsp\;</TD>';
            curCell++
         }
         else
         {
            if ((dayOfMonth == date)&&(date != 0)) // current cell represents today's date
            {
               daybgcolor = "#333333";
            }
            else
            {
               daybgcolor = "#000000";
            }
            text += '<TD HEIGHT="70" BGCOLOR="' + daybgcolor + '"><font face="verdana" size=2 color="#d499ff">' + dayOfMonth + '</font><br>';
               MonthYear = monthName+year;
               mymonth = eval(MonthYear + "dates");
               if(dayOfMonth < 10){y="d0"+dayOfMonth}else{y="d"+dayOfMonth};
               gigone = mymonth.substring(mymonth.indexOf(y)+4,mymonth.indexOf(y)+6);
               gigtwo = mymonth.substring(mymonth.indexOf(y)+7,mymonth.indexOf(y)+9);
               todaygig1 = unescape(eval('gig' + gigone + '["calendar_name"]'));
               todaygig2 = unescape(eval('gig' + gigtwo + '["calendar_name"]'));
               todaygigs1 = "";
               todaygigs2 = "";
               gigone_band = eval('gig' + gigone + '["which_band"]');
               gigtwo_band = eval('gig' + gigtwo + '["which_band"]');
               if(gigone-0 > 0)
               {
                  if(gigone_band == "stan") { sorn = "s"; } else { sorn = "n"; }
                  todaygigs1 = '<a href="javascript:top.popGigInfo(\'' + gigone + '\')" class="infolinx' + sorn + '" onClick="this.blur()" title="Click for more information">' + todaygig1 + '</a>';
               }
               if(gigtwo-0 > 0)
               {
                  if(gigtwo_band == "stan") { sorn = "s"; } else { sorn = "n"; }
                  todaygigs2 = '<a href="javascript:top.popGigInfo(\'' + gigtwo + '\')" class="infolinx' + sorn + '" onClick="this.blur()" title="Click for more information">' + todaygig2 + '</a>';
               }
               todaygigs = todaygigs1 + '<br>' + todaygigs2;
            text += todaygigs;
            text += '</TD>';
            dayOfMonth++;
         }
      }
      text += '</TR>';
   }
 	
   // close all basic table tags
   text += '</TABLE>';

   text += '<font size="1" face="verdana,arial" color="#d499ff"><b>Color key:</b>&nbsp\;&nbsp\;&nbsp\;<font color="#00dd00">Stanley & Stanley</font>&nbsp\;&nbsp\;&nbsp\;<font color="#00ccff">Nightbridge Entertainment</font></font>';

   text += '</body>';
   text += '</html>';

   // return accumulative HTML string
   return text;
}


function writeToFrame(monthhtml)
{
   top.calframe.document.clear();
   top.calframe.document.open();
   top.calframe.document.write(monthhtml);
   top.calframe.document.close();
}




function initialLoad()
{
   setCal(13,0);
}



function popGigInfo(zgig)
{
   pop_which_band = eval('gig' + zgig + '["which_band"]')
   pop_calendar_name = eval('gig' + zgig + '["calendar_name"]');
   pop_info_name = eval('gig' + zgig + '["info_name"]');
   pop_address = eval('gig' + zgig + '["address"]');
   pop_time = eval('gig' + zgig + '["time"]');
   pop_comment = eval('gig' + zgig + '["comment"]');

   if(pop_which_band == "stan")
   {
      pop_which_band = "Stanley & Stanley";
   }
   else
   {
      pop_which_band = "Nightbridge Entertainment";
   }


   infoBox = window.open('giginfo.html', 'theInfo', 'width=370,height=260,resizable=yes');

}



