/*
    File Name: meetingtimes.js
    Purpose:  To display the OVCRC meeting times
*/

// Declare global variables
var mtgsArray = [ 
 ["Sunday",   "ministries.html", "#Sunday School",      "Sunday School",        "9:45am"],
 ["Sunday",   "ministries.html", "#AM worship",         "Morning Service",      "11:00am"],
 ["Sunday",   "ministries.html", "#Meals",         "Fellowship Meal (all bring something)",      "1st Sunday of the month"],
 ["Sunday",   "ministries.html", "#Meals",         "Fellowship Meal (Light Lunch)",      "All other Sundays of the month"],
 ["Sunday",   "ministries.html", "#Evening worship",    "Evening Service ",     "6:00pm"],
 ["Mid-week", "ministries.html", "#First Place",        "First Place 4 Health", "Mondays 6:45pm"],
 ["Mid-week", "ministries.html", "#MensLife",           "Men's Life",           "1st, 3rd, 5th  Wednesdays 7:30pm"],
 ["Mid-week", "ministries.html", "#Prayer Meeting",     "Prayer Meeting",       "2nd and 4th Wednesdays 7:30pm"],
 ["Mid-week", "ministries.html", "#Shepherding Groups", "Small Groups",         "Friday Nights"]
 ];
var mtgsCount = mtgsArray.length;


//*************************************************							
// Define a class for the Meeting
//*************************************************							
function Meeting(mtgDay, mtgHrefWindow, mtgHref, mtgName, mtgTime) {
    this.mtgDay = mtgDay;
    this.mtgHrefWindow = mtgHrefWindow;
    this.mtgHref = mtgHref;
    this.mtgName = mtgName;
    this.mtgTime = mtgTime;
}

// Declare a function for displaying the Meeting row
function view() {
  var start = 0
  var newHref = "";

  // Check if the mtgHrefWindow can be found in the location.href
//  alert ("location: " + location);
  var pos=location.href.indexOf(this.mtgHrefWindow, start);
  if (pos > 0)
  {
       newHref = this.mtgHref;
  } 
  else 
  {
//       alert ("this.mtgHrefWindown: " + this.mtgHrefWindow);
       newHref = this.mtgHrefWindow + this.mtgHref;
  }
//  alert("newHref = " + newHref + "pos= " + pos);

  with (this) document.write('<li><A href="' + newHref + '">' + mtgName + '</A> - ' + mtgTime +
                             '</li>');

}


// Declare function prototypes for the Meeting class
Meeting.prototype.view = view;

//************************************************
// Declare other functions
//************************************************

// function to display the Meeting list
function loadMtgTimes()
{
    var prevMtgDay = "";


    for (i = 0; i < mtgsCount; i++)
    {
        var mtgRow = new Meeting(mtgsArray[i][0], mtgsArray[i][1], mtgsArray[i][2], mtgsArray[i][3], mtgsArray[i][4]);
        
        if (mtgRow.mtgDay != prevMtgDay)
        {
             if (prevMtgDay != "")
             {
                document.write('</ul>');

             }

             document.write('<div>' + mtgRow.mtgDay + '</div>' + '<ul>');
             prevMtgDay = mtgRow.mtgDay;
        }
        mtgRow.view();
    }
    document.write('</ul>');

    
}


