// Set the correct classes in the stocklists
var colorStocklist = function()
{
  $$('#stocklist table tr').each(
    function(item,n){
      if(n%2 === 1)
      { item.addClass('dark'); }
      item.removeClass('empty');
      if(item.getElement('td').get('text').match(/^\s*$/))
	// /^\s*$/ - contains only whitespace characters
      { item.addClass('empty'); }
    });
};

window.addEvent('domready',function(){
                  colorStocklist();
                  $$('#stocklistlinks a').each(
                    function(item, index, array){
                      var href = item.get('href');
                      item.set('href', '#');
                      item.addEvent
                      ('click', function(){
                         var stocklist = $('stocklist');
                         stocklist.getElement('h1').set('text', item.get('text'));
                         stocklist.getElement('div.bottomrightcorner')
                           .set('html', '<p class="loading"> Loading <br /> Stocklist ... </p>')
                         // Element.get returns a Request.HTML instance
                         // So that I can use the Request method addEvent
                           .get('load').get(href + '?altTemplate=ajaxBody')
                         // When it's loaded you need to set the colors again
                           .addEvent('complete', function(){
                                       colorStocklist();
                                     });
                         return false;
                       });
                    });
		});


