//==============================================================================
// JavaScript Notice Board
//==============================================================================
// Author:  Martin Flegg
// Email: martin.flegg@btinternet.com
// Version 0.1 - (21-Nov-2007)
//==============================================================================

// Configurable values are set to defaults here; you can override them before calling Noticeboard( ) from your HTML page

// Events[] is a SPARSE array; Call AddNotice( ) to populate it. 

var Notices = new Array;

// Each notice is defined by calling the AddNotice( ) routine with the following parameters:
//
//   AddEvent(PubDate, EndDate, Title, Image, Width, Height, Alt, Link, Notice)
//        PubDate       = is the publication date, a numeric value in the format YYYYMMDD
//        EndDate       = is the end date notice will display upto this date, a numeric value in the format YYYYMMDD 
//        Title         = is a string (may include embedded HTML tags such as <BR>, <strong>, etc.)
//        Image         = is the URL of the image if you want to display an image with this event
//        Width         = is the width of the image in pixels
//        Height        = is the height of the image in pixels
//        Alt           = is the alternate text of the image (for mouseover or non-graphic browser)
//        Link          = is the URL of the target page if a hyperlink is desired from this event entry
//        Notice        = notice text, is a string (may include embedded HTML tags such as <BR>, <strong>, etc.)

var today = new Date();
var yr = today.getFullYear();
var mo = today.getMonth()+1;
var dy = today.getDate();
var html;

// Notice constructor
function Notice(pubdate,title, image, width, height, alt, link, ntext) {
  
  this.pubdate = pubdate;
	this.title = title;
	if (link) this.link = link;
	if (image) {
	   this.image = image;
	   if (width) this.width = width;
	   if (height) this.height = height;
	   if (alt) this.alt = alt;
	}
	if (ntext)this.ntext = ntext;
}

function AddNotice(PubDate, EndDate, Title, Image, Width, Height, Alt, Link, Ntext) {
	var i;
	var tdate = (((yr * 100) + mo) * 100) + dy;

  if (PubDate <= tdate && tdate <= EndDate) {
	   i = Notices.length;
	   Notices[i++] = new Notice(PubDate,Title, Image, Width, Height, Alt, Link, Ntext);
  }
}

function Noticeboard( ) {
  var ymd;
  var nymd;
  var day;
  var mon;
  var yr;
  var fulldate;
  
  myObjectBubbleSort(Notices,Notices.length);

  for (var i = 0; i < Notices.length; i++) {
		
    html = '<p><br/></p> <div class="notice"> '
    
    if (Notices[i].image) {
      html += '<img ' + 'id="not_img'+ i + '" ' + 'class="img_sp" align="left" src="' + Notices[i].image + 
					   (Notices[i].width ? '"  width="' + Notices[i].width : '') +
					   (Notices[i].height ? '" height="' + Notices[i].height : '') +
					   (Notices[i].alt ? '" alt="' + Notices[i].alt : '') +					   
					   (Notices[i].alt ? '" title="' + Notices[i].alt : '') +
					   '" /> ';
    }
    nymd = Notices[i].pubdate;
    ymd = nymd.toString();
    day = ymd.substring(6,8);
    mon = ymd.substring(4,6);
    yr  = ymd.substring(0,4);
    fulldate = day+'/'+mon+'/'+yr;
    
    if (Notices[i].title) {
      html += '<h2>'+ ' ' + Notices[i].title + '</h2> ';
    }
    
    if (Notices[i].ntext) {
      html += '<p class="indented">' + Notices[i].ntext + '</p>';
    }
    
    if (Notices[i].link) {
      html +='<p class="indented"><a href="' + Notices[i].link + '">Link</a></p>';
    }  
    
    html += '<p class="indented"><i>Published on ' + fulldate + '</i></p>'; 
    
    html += ' </div> <div class="not-bottom"><div class="not-bot-right"></div></div><div class="notice-space"></div>';
  
    document.write(html);
  
  }
} 

function myObjectBubbleSort(arrayName,length) {
    for (var i=0; i<(length-1); i++)
        for (var j=i+1; j<length; j++)
            if (arrayName[j].pubdate > arrayName[i].pubdate) {
                var dummy = arrayName[i];
                arrayName[i] = arrayName[j];
                arrayName[j] = dummy;
            }
}
 

