
function TwoDim(n) {
   this.length = n ;
   for (var i = 1; i <= n; i++) { this[i] = 0; }
   return this
}

function Gig(showdate, showday, showtime, showclub, showtown, showdir) {
   this.showdate = showdate;
   this.showday = showday;
   this.showtime = showtime;
   this.showclub = showclub;
   this.showtown = showtown;
   this.showdir = showdir;
}


function mednextgig() {
 var genData = "";
 var quote='"';
 var colon=';';

 var    nextgig_line1 = "";
 var    nextgig_line2 = "";
 var    nextgig_dir = "";
 var    nextgig_day = "";
 var    nextgig_yyyy = "";
 var    nextgig_mm = "";
 var    nextgig_dd = "";
 var    nextgig_date = "";

 var day = "";
 var month = "";
 var weekday = "";
 var year = "";
 var todays_day = "";
 var todays_date = "";
 var todays_key = "";
 var dayoe = "";
 var dayright = "";
 var day2 = "";
 var day3 = "";

 var gigday = "";
 var gigmonth = "";
 var gigweekday = "";
 var gigyear = "";
 var gigtodays_day = "";
 var gigtodays_date = "";
 var gigkey = "";


 // gigcal is the array for the gig dates (obviously)
 // Two dimensional arrays can only be accomplished by redefining storage areas
 // --- therefore ---
 // TwoDim is needed to declare storage for the "rows" of the gigcal array (number of gigs)
 // Gig is needed to declare the "columns" of the gigcal array and holds the physical string data
 // The array needs to be entered IN ORDER.  The first entry, gigcal[1] being the highest date.


 gigcal = new TwoDim(10);
 gigcal[1] = new Gig("20050807","Sunday","07:00 PM","Taste of Roselle","Roselle","http://www.roselle.il.us/news/currenteventstaste.html");



 // build arrays from showdate for formatting printable dates with Day of the week, Month and Day

 gigweekday_array = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")

 gigmonth_array = new Array("January ", "February ", "March ", "April ", "May ", "June ", "July ", "August ",
  "September ", "October ", "November ", "December ")

 gigday_array = new Array("0","1","2","3","4","5","6","7","8","9","10",
                           "11","12","13","14","15","16","17","18","19","20",
                           "21","22","23","24","25","26","27","28","29","30","31");

  // get current date info

  newdate=new Date();
  weekday = newdate.getDay();
  month = newdate.getMonth();
  day = newdate.getDate();
  year = newdate.getYear();
  if (year < 2000 ) { year = year + 1900 ; }

  // month starts at 0.  bump month by 1 for actual and zero fill.

  month++;
  if (month < 10) { month = "0" + month;}

  // zero fill day

  if (day < 10) { day = "0" + day;}


  // set odd or even day

  dayright = ( ((day * 10) / 2)  -  (10 * parseInt(day / 2))  );
  if (dayright == "0") { dayoe = "e" ; } else { dayoe = "o"; }


  // build key for todays date in same format as showdate in array
  // "" used to declare string function and NOT math function

  todays_key = "" + year + month + day;


  // loop thru the gigcal array from highest showdate to lowest
  // select the LAST gigcal array record with the showdate greater than todays date

  var x = 0;

   for (var i = 1; i <= gigcal.length; i++) { if (gigcal[i].showdate >= todays_key) { x = i; }
   }




     genData = "";
 genData += "<CENTER>";
 genData += "<strong>";
 genData += "<FONT SIZE=3>";
 genData += "<A HREF=" + quote + "http://www.mediarocks.com/gigsmain.html" + quote + " target=" + quote + "_top" + quote + ">";
 genData += "NEXT GIG:</a>";
 genData += "</strong>";



  // if there is not a showdate more recent than todays date print slug (based on odd/even day)

  if (x == 0)
  {
    genData += "<br>";
    genData += "<br>";
    genData += "</strong>";

    if (dayoe == "o")
     { genData += "<i>currently nothing scheduled</i><br>"; }
    if (dayoe == "e")
     { genData += "<i>nothing currently scheduled</i><br>"; }


    genData += "<br>";
  }
  else
  {

  // format showdate into printable date - Weekday Month Day, Year

    nextgig_yyyy = gigcal[x].showdate.substring(0,4);
    nextgig_mm = gigcal[x].showdate.substring(4,6);
    nextgig_mm --;
    if (nextgig_mm < 0) { nextgig_mm = 11; }
    nextgig_dd = parseInt(gigcal[x].showdate.substring(6,8));


  // check for gigdate equal to tomorrows date

  if ((gigcal[x].showdate - 1) == todays_key)
  {
    genData += "<STRONG>&nbsp&nbsp TOMORROW!</STRONG><br>";
  }


  // check for gigdate equal to todays date

  if (gigcal[x].showdate == todays_key)
  {
   genData += "<STRONG>&nbsp&nbsp TONIGHT!</STRONG><br>";
  }

  // check for gigdate not equal to today or tommorrows date

  if ((gigcal[x].showdate - 1) != todays_key && gigcal[x].showdate != todays_key)
  {
    genData += "<br>";
  }

  // generate html for gig date and location info

    genData += gigcal[x].showday + " " + gigmonth_array[nextgig_mm] + gigday_array[nextgig_dd] + ", ";
    genData += nextgig_yyyy + " ~ " + gigcal[x].showtime;
    genData += "<br>";
    genData += "</strong>";
    genData += gigcal[x].showclub + " ~ " + gigcal[x].showtown;
    genData += "<br>";
    genData += "</font>";


  // generate html for gig directions if available in array

    if (gigcal[x].showdir != "") {
    genData += "<FONT SIZE=2>";
    genData += "<A HREF=" + quote + gigcal[x].showdir + quote + " target=" + quote + "_top" + quote + ">[Directions]</a><br>";
    genData += "</font>";
    }
    else
    {
    genData += "<br>";
    }
  }


     document.write(genData);
     genData = "";



}



