<!-- Begin
// news.js - provides functions to display news and events as requested
// Copyright 2005 SimpleWebDesign.co.uk romiley.co.uk

// Define some constants...


//---------------------------------------------------------------------------------------------
// displaynews - this builds and returns a table of num news items
function displaynews( num )
{
  // Verify the type of the input parameter
  num *= 1 ;

	// Open the table that the news items will go into
	replyString = "<TABLE ALIGN='CENTER'>" ;

  // Write a row for each record we want to display
  for( i = (nHeading.length-1) ; (i > -1) && (num > 0) ; num--, i-- )
	{
	  // Display the image if there is one
		replyString += "<TR><TD>" ;
	  if( nImage[i] != "" )
  	  replyString += "<IMG SRC='Images/" + nImage[i] + "' ALT='" + nHeading[i] + "' TITLE='" + nHeading[i] + "' ALIGN='RIGHT'>" ;
		
		// Display the details
		replyString += "<SPAN CLASS='BodyHeading'>" + nHeading[i] + "</SPAN><BR>" ;
		replyString += "<SPAN CLASS='date'>" + nDate[i] + "</SPAN><BR><BR>" ;

		replyString += nText[i] + "<BR><BR>" ;

		replyString += "<SPAN CLASS='BodyBold'>For more information:</SPAN><BR>" ;
    if( nContactName[i] != "" )
  		replyString += "<SPAN CLASS='BodyBold'>Contact: </SPAN>" + nContactName[i] + "<BR>" ;
    if( nContactNo[i] != "" )
  		replyString += "<SPAN CLASS='BodyBold'>Phone: </SPAN>" + nContactNo[i] + "<BR>" ;
    if( nEmail[i] != "" )
		{
		  recipient = nEmail[i] ;
			recipienturl = "mailto:" + recipient ;
  		replyString += "<SPAN CLASS='BodyBold'>EMail: </SPAN>" + recipient.link(recipienturl) + "<BR>" ;
		}
    if( nURL[i] != "" )
		{
		  hyperlink = nURL[i] ;
			hyperlinkurl= "http://" + hyperlink ;
  		replyString += "<SPAN CLASS='BodyBold'>Web: </SPAN><A HREF='" + hyperlinkurl + "' TARGET='_blank'>" ;
			replyString += hyperlink + "</A>  " ;
			replyString += "<SPAN CLASS='subscript'>(Link opens in a new window)</SPAN><BR>" ;
		}
		
		if( (i > 0 ) && (num > 1) )
		  replyString += "<P ALIGN='CENTER'><IMG SRC='Resources/horizbar.jpg' WIDTH='360' HEIGHT='2'></P>" ;

		replyString += "</TD></TR>" ;
	}	

  // Now close off the table and return
	replyString += "</TABLE>" ;
  return( replyString ) ;
}

//---------------------------------------------------------------------------------------------
// displayevents - this builds and returns a table of num events
function displayevents( num )
{
  // Verify the type of the input parameter
  num *= 1 ;

	// Open the table that the news items will go into
	replyString = "<TABLE ALIGN='CENTER'>" ;

  // Write a row for each record we want to display
  for( i = 0 ; (i < eHeading.length ) && (num > 0) ; i++ )
	{
	  // If the date has passed, we're not interested
		var CurrentDate = ( Date.parse( Date() ) )*1 - 86400000 ;
		var EventDate = ( Date.parse( eDate[i] ) )*1 ;
		if( EventDate < CurrentDate )
      continue ;
		
	  // Display the image if there is one
		replyString += "<TR><TD>" ;
	  if( eImage[i] != "" )
  	  replyString += "<IMG SRC='Images/" + eImage[i] + "' ALT='" + eHeading[i] + "' TITLE='" + eHeading[i] + "' ALIGN='RIGHT'>" ;
		
		// Display the details
		replyString += "<SPAN CLASS='BodyHeading'>" + eHeading[i] + "</SPAN><BR>" ;
		replyString += "<SPAN CLASS='date'>" + eDate[i] + "</SPAN><BR><BR>" ;

		replyString += eText[i] + "<BR><BR>" ;

		replyString += "<SPAN CLASS='BodyBold'>For more information:</SPAN><BR>" ;
    if( eContactName[i] != "" )
  		replyString += "<SPAN CLASS='BodyBold'>Contact: </SPAN>" + eContactName[i] + "<BR>" ;
    if( eContactNo[i] != "" )
  		replyString += "<SPAN CLASS='BodyBold'>Phone: </SPAN>" + eContactNo[i] + "<BR>" ;
    if( eEmail[i] != "" )
		{
		  recipient = eEmail[i] ;
			recipienturl = "mailto:" + recipient ;
  		replyString += "<SPAN CLASS='BodyBold'>EMail: </SPAN>" + recipient.link(recipienturl) + "<BR>" ;
		}
    if( eURL[i] != "" )
		{
		  hyperlink = eURL[i] ;
			hyperlinkurl= "http://" + hyperlink ;
  		replyString += "<SPAN CLASS='BodyBold'>Web: </SPAN><A HREF='" + hyperlinkurl + "' TARGET='_blank'>" ;
			replyString += hyperlink + "</A>  " ;
			replyString += "<SPAN CLASS='subscript'>(Link opens in a new window)</SPAN><BR>" ;
		}
		
		if( (i < (eHeading.length - 1) ) && (num > 1) )
		  replyString += "<P ALIGN='CENTER'><IMG SRC='Resources/horizbar.jpg' WIDTH='360' HEIGHT='2'></P>" ;

		replyString += "</TD></TR>" ;
		
		// We've displayed an item ; decrement num
		num-- ;
	}	

  // Now close off the table and return
	replyString += "</TABLE>" ;
  return( replyString ) ;
}

//---------------------------------------------------------------------------------------------
// displaynews - this builds and returns a table of num news items
function displaynewslink( num )
{
  // Don't return anything if we're already displaying everything we can
	if( num >= nHeading.length )
	  return( "" ) ;
	
	replyString = "<DIV ALIGN='RIGHT' CLASS='date'>" ;
  replyString += "<A HREF='./news.html?newsitems=all&events=all'>Display more news stories</A>" ;
	replyString += "</DIV>" ;
	
  return( replyString ) ;
}

//---------------------------------------------------------------------------------------------
// displaynews - this builds and returns a table of num news items
function displayeventslink( num )
{
  // Don't return anything if we're already displaying everything we can
	if( num >= eHeading.length )
	  return( "" ) ;
	
	replyString = "<DIV ALIGN='RIGHT' CLASS='date'>" ;
  replyString += "<A HREF='./news.html?newsitems=all&events=all'>Display more events</A>" ;
	replyString += "</DIV>" ;
	
  return( replyString ) ;
}

//---------------------------------------------------------------------------------------------
// getnexteventidx - returns the index of the next event
function getnexteventidx( num )
{
  for( i = 0 ; (i < eHeading.length ) ; i++ )
	{
	  // If the date has passed, we're not interested
		var CurrentDate = ( Date.parse( Date() ) )*1 - 86400000 ;
		var EventDate = ( Date.parse( eDate[i] ) )*1 ;
		if( EventDate < CurrentDate )
      continue ;
	  break ;
	}

  if( i == eHeading.length )
    return( -1 ) ;
	else
    return( i ) ;
}

//---------------------------------------------------------------------------------------------
// URLParse - removes URL encoded parameters (e.g. '+') from the string
function URLParse(str)
{
  str = "" + str;
  while (true)
  {
    var i = str.indexOf ('+') ;
    if (i < 0)
      break;
    str = str.substring(0,i) + ' ' + str.substring(i+1,str.length) ;
  }
  return unescape(str);
}

//---------------------------------------------------------------------------------------------
// getParams - gets parameters from the URL and stuffs them into the args[] array
function getParams()
{
  args = new Array() ;
  var argstring = window.location.search ;
  if( argstring.charAt (0) != '?' )
    return;
  argstring = argstring.substring(1, argstring.length) ;
  var argarray = argstring.split('&') ;
  var i ;
  var singlearg ;

  for( i = 0; i < argarray.length; ++i )
  {
    singlearg = argarray[i].split('=') ;
    if( singlearg.length != 2 )
      continue ;
    var key = URLParse(singlearg[0] ) ;
    var value = URLParse(singlearg[1] ) ;
    args[key] = value;
  }
}
//---------------------------------------------------------------------------------------------

// End -->

