
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, showflyer, showflyer_w, showflyer_h, showdetail) {
   this.showdate = showdate;
   this.showday = showday;
   this.showtime = showtime;
   this.showclub = showclub;
   this.showtown = showtown;
   this.showdir = showdir;
   this.showflyer = showflyer;
   this.showflyer_w = showflyer_w;
   this.showflyer_h = showflyer_h;
   this.showdetail = showdetail;
}


function camouflagesun_nextgig() {
 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 todays_mm = "";
 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_temp = new TwoDim(100);
 gigcal_temp[18] = new Gig("20120225","Saturday","9:00 PM","Shark City","Glendale Hts.","/camouflagesun_gigsmain.html#sc0225","sharkcity_logo.jpg","135","25","opening for INFINITY");
 gigcal_temp[17] = new Gig("20111029","Saturday","09:00 PM","Chicago Loop Halloween 2011","Streamwood","/camouflagesun_gigsmain.html#loop1029","halloweenparty.jpg","152","83","");
 gigcal_temp[16] = new Gig("20110806","Saturday","07:00 PM","Taste of Roselle 2011","Roselle","/camouflagesun_gigsmain.html#tor0806","","","","");
 gigcal_temp[15] = new Gig("20110604","Saturday","09:00 PM","Dan Reeves Benefit at The Chicago Loop","Streamwood","/camouflagesun_gigsmain.html#loop0604","chicago-loop_logo.gif","200","64","");
 gigcal_temp[14] = new Gig("20110429","Friday","9:00 PM","Shark City","Glendale Hts.","/camouflagesun_gigsmain.html#sc0429","sharkcity_logo.jpg","135","25","Opening for Cabo Wabo");
 gigcal_temp[13] = new Gig("20101211","Saturday","11:00 PM","Penny Road Pub","So. Barrington","/camouflagesun_gigsmain.html#prp1211","prp_logo.jpg","85","66","");
 gigcal_temp[12] = new Gig("20101030","Saturday","09:00 PM","Chicago Loop Halloween 2010","Streamwood","/camouflagesun_gigsmain.html#loop1030","halloweenparty.jpg","","","");
 gigcal_temp[11] = new Gig("20100731","Saturday","06:30 PM","Taste of Roselle 2010","Roselle","/camouflagesun_gigsmain.html#tor0731","","","","");
 gigcal_temp[10] = new Gig("20100618","Friday","09:00 PM","Chicago City Limits","Schaumburg","/camouflagesun_gigsmain.html#ccl0618","","","","");
 gigcal_temp[9] = new Gig("20100313","Saturday","09:00 PM","Chicago Loop","Streamwood","/camouflagesun_gigsmain.html#loop1010","","","","");
 gigcal_temp[8] = new Gig("20100116","Saturday","10:00 PM","Chicago City Limits","Schaumburg","/camouflagesun_gigsmain.html#ccl0116","","","","");
 gigcal_temp[7] = new Gig("20091010","Saturday","09:00 PM","Chicago Loop","Streamwood","/camouflagesun_gigsmain.html#loop1010","","","","");
 gigcal_temp[6] = new Gig("20090802","Sunday","04:00 PM","Taste of Roselle 2009","Roselle","/camouflagesun_gigsmain.html#tor0802","","","","");
 gigcal_temp[5] = new Gig("20090620","Saturday","09:00 PM","Streets of Chicago","Elgin","/camouflagesun_gigsmain.html#soc0620","","","","");
 gigcal_temp[4] = new Gig("20090313","Friday","09:00 PM","Chicago City Limits","Schaumburg","/camouflagesun_gigsmain.html#ccl0313","","","","opening for Jak Tripper");
 gigcal_temp[3] = new Gig("20090220","Friday","09:00 PM","Famous Freddies Roadhouse","Mt Prospect","/camouflagesun_gigsmain.html#ff0220","","","","opening for Deja Groove");
 gigcal_temp[2] = new Gig("20081212","Friday","09:00 PM","Chicago City Limits","Schaumburg","/camouflagesun_gigsmain.html#ccl","","","","opening for Cover Gurl");
 gigcal_temp[1] = new Gig("20081121","Friday","09:00 PM","Famous Freddies Roadhouse","Mt Prospect","/camouflagesun_gigsmain.html#ff1121","","","","");


// reverse order the array to get most recent date

 gigcal = new TwoDim(100);

var x = 1;

   for (var i = gigcal_temp.length; i > 0; i--) 
   {
    gigcal[x]= gigcal_temp[i] ; x++; 
   }



 // 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 + "/camouflagesun_gigsmain.html" + quote + " target=" + quote + "_top" + quote;
 genData += " title=" + quote + "See All Shows" + quote;
 genData += ">";
 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));
    todays_mm = parseInt(todays_key.substring(4,6));
	//if (todays_mm < 10) { todays_mm = "0" + todays_mm;}


  // check for gigdate equal to tomorrows date

  if ((gigcal[x].showdate - 1) == todays_key)
  {
    genData += "<STRONG>&nbsp&nbsp TOMORROW!</STRONG>";
  }


  // check for gigdate equal to todays date

  if (gigcal[x].showdate == todays_key)
  {
   genData += "<STRONG>&nbsp&nbsp TONIGHT!</STRONG>";
  }

  // check for gigdate equal to this week

  if (
      gigcal[x].showdate - 7 == todays_key
   || gigcal[x].showdate - 6 == todays_key
   || gigcal[x].showdate - 5 == todays_key
   || gigcal[x].showdate - 4 == todays_key
   || gigcal[x].showdate - 3 == todays_key
   || gigcal[x].showdate - 2 == todays_key
   || ((gigcal[x].showdate - 7) - 70) == todays_key
   || ((gigcal[x].showdate - 6) - 69) == todays_key
   || ((gigcal[x].showdate - 5) - 68) == todays_key
   || ((gigcal[x].showdate - 4) - 67) == todays_key
   || ((gigcal[x].showdate - 3) - 66) == todays_key
   || ((gigcal[x].showdate - 2) - 65) == todays_key
   || ((gigcal[x].showdate - 7) - 71) == todays_key
   || ((gigcal[x].showdate - 6) - 70) == todays_key
   || ((gigcal[x].showdate - 5) - 69) == todays_key
   || ((gigcal[x].showdate - 4) - 68) == todays_key
   || ((gigcal[x].showdate - 3) - 67) == todays_key
   || ((gigcal[x].showdate - 2) - 66) == todays_key
	 )
  {
   genData += "<STRONG>&nbsp&nbsp This Week!</STRONG>";
  }


  else
  
  {
  // check for gigdate equal to todays month

  if (nextgig_mm+1 == todays_mm && gigcal[x].showdate != todays_key && (gigcal[x].showdate - 1) != todays_key)
  {
   genData += "<STRONG>&nbsp&nbsp This Month!</STRONG>";
  }

  // check for gigdate equal to todays next month

  if (nextgig_mm + 1 == todays_mm+1)
  {
   genData += "<STRONG>&nbsp&nbsp Next Month!</STRONG>";
  }


} // end else check for gigdate equal to this week



  // 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 flyer if available in array

    if (gigcal[x].showflyer != "") {
    genData += "<A HREF=" + quote + "/camouflagesun_gigsmain.html" + quote + " target=" + quote + "_top" + quote;
    //genData += " title=" + quote + "See All Shows" + quote;
    genData += ">";
    genData += "<img src=" + quote + gigcal[x].showflyer + quote ;
	genData += " border=" + quote + "0" + quote;

    genData += " height=" + quote + gigcal[x].showflyer_h + quote;
    genData += " width=" + quote + gigcal[x].showflyer_w + quote; 
	genData += ">";
 	genData += "</a>";
 	genData += "<br>";
   }


  // generate html for gig details if available in array

    if (gigcal[x].showdetail != "") {
    genData += gigcal[x].showdetail ;
	genData += "<br>";
    }


  // generate html for gig directions if available in array

    if (gigcal[x].showdir != "") {
    genData += "<A HREF=" + quote + gigcal[x].showdir + quote ;
	genData += " target=" + quote + "_top" + quote ;
	genData += ">[Directions]</a><br>";
    }
    else
    {
    genData += "<br>";
    }


  }


     document.write(genData);
     genData = "";



}




