
////////////////////getElementsByClassName = function(cl) 
////////////////////{
////////////////////   var retnode = [];
////////////////////   var myclass = new RegExp('\\b'+cl+'\\b');
////////////////////   var elem = this.getElementsByTagName('*');
////////////////////
////////////////////   for (var i = 0; i < elem.length; i++)
////////////////////   {
////////////////////      var classes = elem[i].className;
////////////////////      if (myclass.test(classes)) retnode.push(elem[i]);
////////////////////   }
////////////////////   return retnode;
////////////////////};
////////////////////
////////////////////function getElementsByClassNameEx(elem,cl)
////////////////////{
////////////////////   elem.getElementsByClassName = getElementsByClassName;
////////////////////   return elem.getElementsByClassName(cl);
////////////////////}
////////////////////
////////////////////document.getElementsByClassName = getElementsByClassName;

   var firstuse = true;
   var chk;
   var chkindex;
   var gamedays;
   var nclubs;
   var clubs;
   var loggedin = false;
   var pw = '';

   var months = new Array();
   months[months.length]="Jan";
   months[months.length]="Feb";
   months[months.length]="Mar";
   months[months.length]="Apr";
   months[months.length]="May";
   months[months.length]="Jun";
   months[months.length]="Jul";
   months[months.length]="Aug";
   months[months.length]="Sep";
   months[months.length]="Oct";
   months[months.length]="Nov";
   months[months.length]="Dec";

   var fadeinterval=33;  									// for the whitebox ... the millseconds between fade ins
   var wbfader = null;										// the timeout handle
   var wb;											// the background pane element handle
   var wbp;											// the content pane element handle
   
   var year;
   var month;
   var day;

   var dbUsername = '';										// for the php integration
   var dbPassword = '';
   var dbHostaddr = '';
   var phpmate    = 'resultsfiles.php';

   var wbflag = new Array();
   var gameday = new Array();									// 1 == sunday

   gd = new Array(); gd[0] = 2; gd[1] = 'A'; gd[2] = 'westclub';   gd[3] = '1:00pm';  gd[4] = ''; gameday[gameday.length] = gd;	// monday afternoon
   gd = new Array(); gd[0] = 3; gd[1] = 'A'; gd[2] = 'northclub';  gd[3] = '1:00pm';  gd[4] = ''; gameday[gameday.length] = gd;	// tuesday afternoon
   //gd = new Array(); gd[0] = 3; gd[1] = 'E'; gd[2] = 'pelicanbay'; gd[3] = '6:30pm';  gd[4] = ''; gd[5] = new Date(2011,3,25,0,0,0); gameday[gameday.length] = gd;	// tuesday evening
   gd = new Array(); gd[0] = 3; gd[1] = 'E'; gd[2] = 'pelicanbay'; gd[3] = '6:30pm';  gd[4] = ''; gameday[gameday.length] = gd;	// tuesday evening
   gd = new Array(); gd[0] = 4; gd[1] = 'A'; gd[2] = 'westclub';   gd[3] = '1:00pm';  gd[4] = ''; gameday[gameday.length] = gd;	// wednesday afternoon
   gd = new Array(); gd[0] = 5; gd[1] = 'A'; gd[2] = 'northclub';  gd[3] = '1:00pm';  gd[4] = ''; gameday[gameday.length] = gd;	// thursday afternoon
   gd = new Array(); gd[0] = 6; gd[1] = 'A'; gd[2] = 'pelicanbay'; gd[3] = '1:00pm';  gd[4] = ''; gameday[gameday.length] = gd;	// friday afternoon
   //gd = new Array(); gd[0] = 0; gd[1] = 'A'; gd[2] = 'northclub';  gd[3] = '12:30pm'; gd[4] = ''; gd[5] = new Date(2011,3,30,0,0,0); gameday[gameday.length] = gd;	// saturday afternoon
   gd = new Array(); gd[0] = 0; gd[1] = 'A'; gd[2] = 'northclub';  gd[3] = '12:30pm'; gd[4] = ''; gameday[gameday.length] = gd;	// saturday afternoon

   var specialevents = new Array();

   results = new Array();
   resultx = new Array();
   
//////////////////////
////////////////////// calRequest
//////////////////////

function calRequest(params)
{
   var xmlhttp = newRequest();          							// get a request handle
   var phpmate = "cal.php";                                                           
   var txt = '';

   xmlhttp.open('POST', phpmate, false);                                                        // make a SYNCHRONOUS request
   xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   xmlhttp.send(params);
   txt = xmlhttp.responseText;                                                                  // FIX: snarf the response for debugging

   return txt;                                                                                  // return the raw response (a form in HTML)

} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// getRequest
function fileRequest(params)
{
   var xmlhttp = newRequest();          							// get a request handle
   var phpmate = "t.php";                                                           
   var txt = '';

   xmlhttp.open('POST', phpmate, false);                                                        // make a SYNCHRONOUS request
   xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   xmlhttp.send(params);

   txt = xmlhttp.responseText;                                                                  // FIX: snarf the response for debugging

   return txt;                                                                                  // return the raw response (a form in HTML)

} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// getRequest

function getSpecialEvents()
{
   txt = calRequest('op=java');
   eval(txt);
   return txt;

} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// getSpecialEvents


function makeWhiteboxes()
{
   for (i=0;i<clubs.length;i++)
      wbflag[i] = false;
}

function makeWhitebox(c,html,maphtml)
{
 
   if (html == undefined) html = getClub(c);
   html = html.replace(/~q/g,"'");
   
   newwb = document.createElement('div');
   newwb.setAttribute('id',c);
   newwb.setAttribute('class','wbx');
   newwb.innerHTML=html;
   wbp.appendChild(newwb);
}

function popupformcreate()
{
   var popup = document.createElement('div');
   popup.setAttribute('ID','popupform');
   popup.setAttribute('style','position:fixed;top:100px;left:100px;widthx:200px;heightx:200px;background-color:goldenrod;visibility:hidden');
   document.body.appendChild(popup);
}

function popupformhide()
{
   var p = document.getElementById('popupform');
   p.style.visibility = 'hidden';
}

function popupformsave()
{
   var p        = document.getElementById('popupform');
   var gamedate = document.getElementById('gamedate').value;
   var gametime = document.getElementById('gametime').value;
   var gametype = document.getElementById('gametype').value;
   var gamecost = document.getElementById('gamecost').value;
   var gamenote = document.getElementById('gamenote').value;
   var txt      = calRequest('op=set&password=' + pw + '&gamedate=' + gamedate + '&gametime=' + gametime + '&gametype=' + gametype + '&gamecost=' + gamecost + '&gamenote=' + encodeURI(gamenote));

   specialevents = new Array();
   getSpecialEvents();
   fillDateCells(year, month, day);
   popupformhide();
}

function popupform(d,game)
{
   d = d.substr(0,4) + '-' + d.substr(5,2) + '-' + d.substr(d.length-2);
   var gametime = games[game]['gametime'];
   var ampm = gametime.substr(gametime.length-2);
   var time = gametime.substr(0,gametime.length-2);
   var hour = time.split(':')[0];
   var minute = time.split(':')[1];
   if (ampm == 'pm' && hour < 12) hour = hour * 1 + 12;
   var t = hour + ":" + minute;
   var c = '';
   var n = '';
   var popuptemplate  = '<table>';
       popuptemplate += '<tr><th>Date: </th><td><input id=gamedate type=text value="' + d + '"/></td></tr>';
       popuptemplate += '<tr><th>Time: </th><td><input id=gametime type=text value="' + t + '"/></td></tr>';
       popuptemplate += '<tr><th>Type: </th><td><select id=gametype>';
       popuptemplate += '<option value="">Normal Game</option>';
       popuptemplate += '<option value="Club%20Championship">Club Championship</option>';
       popuptemplate += '<option value="Club%20Appreciation">Club Appreciation</option>';
       popuptemplate += '<option value="International%20Fund">International Fund</option>';
       popuptemplate += '<option value="NAP%20Qualifier">NAP Qualifier</option>';
       popuptemplate += '<option value="Charity%20Game">Charity Game</option>';
       popuptemplate += '<option value="Silver%20Points">Silver Points</option>';
       popuptemplate += '<option value="nogame">No Game</option>';
       popuptemplate += '<option value="Novice%20Game">Novice Game</option>';
       popuptemplate += '</select></td></tr>';
       popuptemplate += '<tr><th>Cost: </th><td><input id=gamecost type=text value="' + c + '"/></td></tr>';
       popuptemplate += '<tr><th>Note: </th><td><input id=gamenote type=text value="' + n + '"/></td></tr>';
       popuptemplate += '</table>';
       popuptemplate += '<input type=button value="' + 'Save'   + '" onclick="popupformsave();"/>';
       popuptemplate += '<input type=button value="' + 'Cancel' + '" onclick="popupformhide();"/>';
       
   var popup = document.getElementById('popupform');
   popup.innerHTML = popuptemplate;
   popup.style.visibility = 'visible';
}


// btn
//
// called when onmouseover / onmouseout for buttons
// on over the font is bold, on out the font is normal

function btn(b,onoff)
{
   b.style.fontWeight = onoff ? 'bold' : 'normal';
}
//if (document.addEventListener) {  document.addEventListener("DOMContentLoaded", init, false);}

function checkkey(e)
{
   var keycode;

   if (window.event)
      { keycode = e.keyCode; }
   else
      if (e.which)
         { keycode = e.which; }
      else
         keycode = 'x';

   if (!loggedin && pw.length < 12) pw += keycode;
   if (pw.length == 10) loggedin = checkLogin();
   if (loggedin) {popupformcreate(); wboff(); }
   if (keycode == 27) wboff();
}
function checkLogin()
{
   return (calRequest('op=auth&password=' + pw) == '1'); 
}

// whenready
//
// called when the body is loaded (basically the init function)
// and also onresize (to redo the layout)

function whenReady()
{

   var txt = calRequest('op=getdata&variable=clubs&query=' + escape("SELECT * FROM clubs"));
   clubs = tableToArray('clubs',txt,false);

   nclubs = 0;
   for (c in clubs)
      if (clubs[c]['seq'] != 0) nclubs++;						// seq indicates whether the 'club' is an actual club or not

   txt = calRequest('op=getdata&variable=games&query=' + escape("SELECT * FROM gamedays"));
   games = tableToArray('games',txt,false);

   getSpecialEvents();


   var html      = '';
   var i         = 0;
   var w         = document.body.offsetWidth;
   var sidew     = w * .15;
sidew = 0;
   var mainw     = w - (sidew * 1);
   var headarea  = document.getElementById('masthead'); 
   var logoarea  = document.getElementById('mainlogo'); 
   var clubarea  = document.getElementById('theclubs'); 
  // var leftarea  = document.getElementById('leftpane'); 
   var mainarea  = document.getElementById('mainpane');

   wb  = document.getElementById('whitebox');							// find the whitebox (background box)
   wbp = document.getElementById('whiteboxpane');						// and the whiteboxpane (the one that has the content)

   //logoarea.innerHTML    = '<img style="margin:5px;" alt="Naples Bridge Clubs" width="' +  mainw / 2 + '" src="http://islandparkbridge.com/NaplesBridgeClubs_Title884x100V1 copy.jpg" >';
   //logoarea.style.width  = mainw / 2;
   //logoarea.style.left   = sidew + 'px';
   //logoarea.style.top    = 0     + 'px';
   //logoarea.style.width  = (mainw / 2) + 'px';

   //var ti = logoarea.offsetHeight;
   var ti = mainw * (61 / 1076);
   var wi = mainw / nclubs * .5;

   i = 0;
   for (c in clubs)
   {
      if (clubs[c]['seq'] != 0)
      {
      html += '<img alt="' + clubs[c]['ClubName'] + '"' + 
                  //' style="' + 'xxxposition:absolute;xxxtop:' + (ti + 5) + 'px;xxxleft:' + (.15*wi + sidew + i * wi) + 'px;width:' + wi*.8 + 'px;"' +
                  ' class=menuitem style="width:15%;margin-left:5%;"' + 
                  ' src="' + clubs[c]['ClubImage'] + '"' + 
                  ' onclick="wbon('  + "'" +  clubs[c]['club'] + "'" + ",'',''"   + ');" >';
      i++;
      }
   }

   clubarea.innerHTML = html;
   //clubarea.style.position   = 'absolute';
   //clubarea.style.left   = ( mainw / 2) + 'px';
   //clubarea.style.top    = -ti     + 'px';
   //clubarea.style.width  = (mainw / 2) + 'px';

   //leftarea.style.width    = .9 * sidew + 'px';
   
   //headarea.style.width  = mainw + 'px';
   //headarea.style.height = 0     + 'px';
   //headarea.style.left   = sidew + 'px'; 
   //headarea.style.height = ti * 1.2 + 'px';

   //mainarea.style.top = ti * 1 + 'px';// + clubarea.offsetHeight;
   //mainarea.style.left = sidew + 'px';
   //mainarea.style.width = mainw + 'px';

   //clubarea.style.backgroundColor = 'orange';
   //leftarea.style.backgroundColor = 'skyblue';
   //mainarea.style.backgroundColor = 'green';
   //headarea.style.backgroundColor = 'red';

   document.body.style.visibility='visible';
   makeWhiteboxes();

   if (firstuse) {firstuse=false; wbon('motd','','');
   moveDate(0,0);
   }
}

function fillDateCells(year, month, day)
{
   var i;   
   var z = 0;
   var xxx;
   var m;
   var a;
   var e;
   var gametimes = ['A','E'];
   var gametimestime = ['afternoon','evening'];
   
   var today   = new Date();
       today   = new Date(today.getFullYear(),today.getMonth(),today.getDate(),0,0,0);	// strip off the time
   var cdate   = new Date(year,month,day,0,0,0);
   var weekday = cdate.getDay();
   var bg = 'white';
   var cells = document.getElementsByClassName('calcell');

   var soff = -7 - weekday;
   day = day + soff;
   var template = "<div class=calitem><div id='!ID!' onclick='showitem(this);' date='!DATE!' club='!CLUB!' game='!GAME!' ><img class='calclub' alt='!CLUBNAME!' src='!CLUBIMAGE!'><div class=caltime>!GAMETIME! !SPECIAL!</div></div></div>";
   var template = "<div class=calitem><div id='!ID!' onclick='showitem(this);' date='!DATE!' club='!CLUB!' game='!GAME!' ><div class=caltime><b>!CLUBLABEL!</b> !GAMETIME! !SPECIAL!</div><hr style='margin:0;padding:0'></div></div>";
  
   cdate = new Date(year,month,day,0,0,0);
   for (c in clubs)
      break;

   chk = new Array();

   for (i=0;i<cells.length;i++)
   {
      a = '';
      z++;
      xxx = months[cdate.getMonth()] + ' ' + cdate.getDate();
      for (game in games)
      {
         if (games[game]['weekday'] == (z%7) && gameOn(game,cdate))
         {
            club = clubOf(games[game]['club']);
            sd = SpecialDate(cdate,games[game]['gametime']);
            if ((sd.indexOf('nogame') < 0) || loggedin)
            {
               a += template.replace(/!DATE!/,filedate(cdate))
                            .replace(/!CLUB!/,club)
                            .replace(/!CLUBNAME!/,clubs[club]['ClubName'])
                            .replace(/!ID!/,"G"+game+"I"+i)
                            .replace(/!GAME!/,game)
                            .replace(/!CLUBIMAGE!/,clubs[club]['ClubImage'])
                            .replace(/!CLUBLABEL!/,games[game]['label'])
                            .replace(/!GAMETIME!/,games[game]['gametime'])
                            .replace(/!SPECIAL!/,sd);
               if (cdate < today) chk[chk.length] = "G"+game+"I"+i;
            }
         }
      }
      cells[i].innerHTML = '<div class=caldate>' + xxx + '</div>' + a;
      day++;
      cdate = new Date(year,month,day,0,0,0);
   }
   chkindex = chk.length-1; 
   setTimeout('checkitems();',100);
}

function gameOn(game,cdate)
{
   var s = games[game]['starts'];
   var e = games[game]['ends'];

   if (s == '' || e == '') return true;							// if there are no range qualifiers then the game is on

   var months='janfebmaraprmayjunjulaugsepoctnovdec';
   var smth = months.indexOf(s.substr(0,3)) / 3;
   var emth = months.indexOf(e.substr(0,3)) / 3;
   var sday = s.substr(4,2) * 1;
   var eday = e.substr(4,2) * 1;
   var syr = cdate.getFullYear();
   var eyr = cdate.getFullYear();

   var cmth = cdate.getMonth();
   var cday = cdate.getDate();

   s = 'x' + ((smth < 10) ? '0' : '') + smth + ((sday < 10) ? '0' : '') + sday;
   e = 'x' + ((emth < 10) ? '0' : '') + emth + ((eday < 10) ? '0' : '') + eday;
   c = 'x' + ((cmth < 10) ? '0' : '') + cmth + ((cday < 10) ? '0' : '') + cday;
   
   //alert(game + '===>' + s + '=>>' + c + '==> ' + e);

   return (s <= c && c <= e);
}

function checkitems()
{
   if (chkindex < 0 || chkindex >= chk.length) return;
   var elem = document.getElementById(chk[chkindex]);
   chkindex--;   
   var game = elem.getAttribute('game');
   var date = elem.getAttribute('date');
   var club = elem.getAttribute('club');

   var href='http://results.islandparkbridge.com/Pelican Bay Results/' + date + games[game]['suffix'] + '.HTM';
   var rx = inResults(href,date,games[game]['suffix']);
   if (!rx) elem.style.display='none';

   setTimeout('checkitems();',100);
}

function showitem(elem)
{
   var game = elem.getAttribute('game');
   var date = elem.getAttribute('date');
   var club = elem.getAttribute('club');

   var href='http://results.islandparkbridge.com/Pelican Bay Results/' + date + games[game]['suffix'] + '.HTM';
   var rx = inResults(href,date,games[game]['suffix']);
   if (rx)
      wbframe(href);
   else
      if (loggedin)
      {
         popupform(date,game);
      }
      else
         wbon(clubs[club]['club']);
}

function clubOf(club)
{
   for (c in clubs)
      if (clubs[c]['club'] == club) break;
   return c;
}


function sqldate(cdate)
{
   return cdate.getFullYear() + '-' + ((cdate.getMonth()+1) < 10 ? '0' : '') + (cdate.getMonth()+1) + '-' + (cdate.getDate() < 10 ? '0' : '') + cdate.getDate();
}

function SpecialDate(cdate,ctime)
{
   for (i = 0; i < specialevents.length;i++)
   {
      if (specialevents[i][0].toDateString() == cdate.toDateString() && specialevents[i][1] == ctime)
      {
         return('&nbsp;' + specialevents[i][3] + 
         '<br><div style="font-weight:bold;color:red;xtext-decoration:blink;">' + 
          specialevents[i][2] + '<br>' + specialevents[i][4] + '</div>');
      }
   }
   return ('');
}


function inResults(cdate,filedate,session)
{
   var params = "filename=" + escape('results/Pelican Bay Results/' + filedate + session + '.HTM');

   var txt = fileRequest(params);

   return txt.indexOf('OK') >= 0;

}


function moveDate(y,m)
{
   var cdate;

   if (y == m) 											// 'today' button ... also on first load of the page
      cdate = new Date();
   else
      cdate = new Date(year + y, month , day + (m * 28), 0, 0, 0);					// otherwise increment month or year

   month     = cdate.getMonth();
   day       = cdate.getDate();
   year      = cdate.getFullYear();

   fillDateCells(year, month, day);
}

function Holiday(cdate,xxx)
{
   var rv = '';
   /**********************************
   var i;
   for (i = 0; i < specialevents.length;i++)
   {
      if (specialevents[i][0].toDateString() == cdate.toDateString() && specialevents[i][1] == ctime)
      {
         return('&nbsp;' + specialevents[i][3] + 
         '<br><div style="font-weight:bold;color:red;xtext-decoration:blink;">' + 
          specialevents[i][2] + '<br>' + specialevents[i][4] + '</div>');
      }
   }
   return ('');
   **********************************/

   switch (xxx)
   {
      case 'Dec 25': rv='Merry Christmas'; break;
      case 'Jan 1': rv='Happy New Year'; break;
   }
   return (rv);
}

function paddedDate(cdate)
{
   var year  = cdate.getFullYear(); // 1790 vs 2010 ???
   var yr    = year.toString().substring(2);
   var month = cdate.getMonth() + 1;
       month = (month <= 9 ? '0' : '') + month;
   var day   = cdate.getDate();
       day   = (day <= 9 ? '0' : '') + day;
   return(yr + month + day);
}

//////////////////////
////////////////////// filedate
//////////////////////

function filedate(cdate)
{
   var year  = cdate.getFullYear(); // 1790 vs 2010 ???
   var yr    = year.toString().substring(2);
   var month = cdate.getMonth() + 1;
       month = (month <= 9 ? '0' : '') + month;
   var day   = cdate.getDate();
       day   = (day <= 9 ? '0' : '') + day;
   return(year + '/' + month + '/' + yr + month + day);
}


//////////////////////
////////////////////// postRequest
//////////////////////

function postRequest(params)
{
   var xmlhttp = newRequest();                                                                  // get a request handle
   var txt = '';

   params += '&dbuser=' + dbUsername + '&dbpass=' + dbPassword + '&dbhost=' + dbHostaddr;       // add the credentials

   xmlhttp.open('POST', phpmate, false);                                                        // make a SYNCHRONOUS request
   xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
   xmlhttp.send(params);

   txt = xmlhttp.responseText;                                                                  // FIX: snarf the response for debugging

   return txt;                                                                                  // return the raw response (a form in HTML)

} /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// postRequest

//////////////////////
////////////////////// wbframe
//////////////////////

function wbframe(url)
{
   window.open(url);										// simply open a new window
}

//////////////////////
////////////////////// wboff
//////////////////////

function wboff()
{
/*********************
   var n = document.getElementsByTagName('div');						// find all the divs and sift through them
   for (i=0;i<n.length;i++)									// for those that are in the whitebox
   {
      if ((n[i].className == 'wbx') ||
          (n[i].className == 'locationmap')) n[i].style.display = 'none';			// turn them off
   }
   var wbxs = document.getElementsByClassName('wbx');
*********************/

   wbp.innerHTML='';

   wb.style.visibility = wbp.style.visibility = 'hidden';					// hide the whitebox(background) and the pane (content)
   wb.style.height = '100%';
   wbp.style.height = '';

   if (wbfader != null) clearTimeout(wbfader);
}

function getClub(c)
{
 //  var params = "op=getdata&variable=club&query=" + escape("SELECT * FROM clubs WHERE club='" + c + "'");
 //  var txt = calRequest(params);
   for (cx in clubs)
      if (clubs[cx]['club'] == c) break;

   club = clubs[cx];

   var template = document.getElementById('club_template').innerHTML.replace(/%21/g,'!');
   var html = template.replace(/!CLUBNAME!/g,"'"+club['ClubName']+"'")
                      .replace(/!CLUBADDRESS!/,club['ClubAddress'])
                      .replace(/!CLUBPHONE!/,club['ClubPhone'])
                      .replace(/!CLUBIMAGE!/,club['ClubImage'])
                      .replace(/!CLUBMAP!/,club['ClubGoogleMap'])
                      .replace(/!CLUBMAPIMAGE!/,club['ClubMapImage'])
                      .replace(/!CLUBNOTES!/,club['ClubNotes']);
   return html;
}

function wbDB(c,d,t)
{
   var season_qualifier = 'Fall';
   var year_qualifier = '2011';

   var params = "op=getdata&variable=lessons&query=" + escape("SELECT * FROM lessons WHERE yr='" + year_qualifier + "' AND season='" + season_qualifier + "'");
   var params = "op=getdata&variable=lessons&query=" + escape("SELECT * FROM lessons");
   var txt = calRequest(params);
   var lessons = tableToArray('lessons',txt,false);
   var lesson;

   var html = '';
   var subhtml = '';

   var header_template = document.getElementById('lessons_header_template').innerHTML.replace(/%21/g,"!");
   var template = document.getElementById('lessons_template').innerHTML.replace(/%21/g,"!");
   var spades   = "<span style='color:black'>&spades;</span> ";
   var hearts   = "<span style='color:red'>&hearts;</span> ";
   var clubs    = "<span style='color:black'>&clubs;</span> ";
   var diamonds = "<span style='color:red'>&diams;</span> ";

   for (lesson in lessons)
   {
      lessons[lesson]['description'] = lessons[lesson]['description']
          .replace(/!SHCD!/g, spades + hearts + clubs + diamonds);
      if (lessons[lesson]['nickname'] == 'heading')
      {
      html += header_template.replace(/!TITLE!/,lessons[lesson]['title'])
                      .replace(/!WHOFOR!/,lessons[lesson]['whofor']) 
                      .replace(/!SESSION!/,lessons[lesson]['session']) 
                      .replace(/!STARTS!/,lessons[lesson]['starts']) 
                      .replace(/!DAYTIME!/,lessons[lesson]['daytime']) 
                      .replace(/!DESC!/,lessons[lesson]['description']) ;
      }
      else
      {
      html += template.replace(/!TITLE!/,lessons[lesson]['title'])
                      .replace(/!WHOFOR!/,lessons[lesson]['whofor']) 
                      .replace(/!SESSION!/,lessons[lesson]['session']) 
                      .replace(/!STARTS!/,lessons[lesson]['starts']) 
                      .replace(/!DAYTIME!/,lessons[lesson]['daytime']) 
                      .replace(/!DESC!/,lessons[lesson]['description']) ;
      }
   }

   wbon(c,d,t,html);
}

//////////////////////
////////////////////// wb
//////////////////////

function wbon(c,d,t,html,maphtml)
{
   i = 0;
   for (cx in clubs)
   {
      if (clubs[cx]['club'] == c)
      {
         makeWhitebox(c,html,maphtml);
         //////           if (!wbflag[i]) makeWhitebox(c,html,maphtml);
         break; 
      }
      else
         i++;
   }

   var ctxt = document.getElementById(c);							// and the specific content
   var cmap = document.getElementById(c+'map');							// and the associated 'map' frame

   var i;
   for (i = 0; i<ctxt.childNodes.length;i++)
   {
      if (ctxt.childNodes[i].className == 'location')
      {
         if (ctxt.childNodes[i].innerHTML =='') return;
         //alert('X' + ctxt.childNodes[i].innerHTML + 'X');
      }
   }

   ctxt.style.display = 'inline';								// make the content active

   if (cmap)
      cmap.style.display = 'inline';								// and make the 'map' (if any) active as well
 
   if (wb.offsetHeight < wbp.offsetHeight * 1.05) 						// resize the whitebox (background) so that it is a
      wb.style.height = wbp.offsetHeight * 1.05 + 'px';						// little larger than the pane (if it isn't already)

   document.body.focus();
   wbfader = setTimeout("wbfade(1);",fadeinterval);						// trigger the gradual fadein
}

//////////////////////
////////////////////// wbfade
//////////////////////

function wbfade(remaining)
{
   var degree = (remaining / 8);								// determine how visible the elements should be

   try { wb.filters.alpha.opacity = degree * 100 * .65; } 					// set the opacity degree for the background up to 65%
   catch (e) { wb.style.opacity = degree * .65; }

   try { wbp.filters.alpha.opacity = degree * 100; } 						// and the opacity degree for the content up to 100%
   catch (e) { wbp.style.opacity = degree; }
   
   wb.style.visibility  = wbp.style.visibility = 'visible';					// make sure both are now visible
   
   if (degree < 1)										// if we still have work to do
      wbfader = setTimeout("wbfade(" + (remaining+1) + ");",fadeinterval);			// schedule it!!!
   else
      wbfader = null;										// otherwise stop
}



