/**************************************************************************************************************************
	whatsnewTable.js
	Creates the table containing What's New topics
	
	External files:
		whatsnewtxt.js - contains the Whats New Array topic lines
		Images folder contains the image files

	Functions:
		insertAnchor(topic):	Inserts the anchor (<a href ...></a>) to point to the Presidents Message
		createWhatsNewTable():	Creates the What's New Table in the Home Page

	Whats New file structure: 
		Currently an Array containing 6 entries (0-5)
		Four topics, two lines each
		Any line may contain a <> or {} pair to identify which words to use as a URL reference to the Presidents Page
			<> is at the top of the Presidents Page
			{} is at the bottom of the Presidents Page - we insert "#Other" at end of anchor from glblAName

	Colors:
		No colors specified
			
**************************************************************************************************************************/

/* Preload images script */
var myimages=new Array()

function preloadimages(){
	for (i=0;i<preloadimages.arguments.length;i++){
		myimages[i]=new Image();
		myimages[i].src=preloadimages.arguments[i];
	}
}

/* The images to be preloaded inside parenthesis: (Extend list as desired.) */
preloadimages("images/Bullet1.gif","images/Line2.jpg","images/WhatsNewText.gif");

/* Declare global variables */

var anchorStart	   = '<a href="Common/PresMsg.html"';
var anchorHrefEnd  = '>';
var anchorEnd 	   = '</a>';
var anchorValue	   = '#Other';
var anchorName	   = 'anchorName=';
var anchorNull	   = '';

function insertAnchor(topic) {
/* Passed a topic line look for <> or {} to insert the Anchor URL reference to the President's html page */
/* Anchor model is : <a href="Common/PresMsg.html">some text</a>         */

	if ((topic.indexOf("<") > 0) && (topic.indexOf(">") > 0)) {						//Note we check for both < and >
		anchorString = new String();
		anchorString += topic.substring(0, topic.indexOf("<")); 					//String up to <
		anchorString += anchorStart+' onClick="setCookie(anchorName, anchorNull)"'+anchorHrefEnd;	//File name and call to set cookie
		anchorString += topic.substring((topic.indexOf("<")+1), topic.indexOf(">"));			//Insert anchored string
		anchorString += anchorEnd+topic.substring((topic.indexOf(">")+1), topic.length);		//End anchor and String after >
		return anchorString;
	} else  if ((topic.indexOf("{") > 0) && (topic.indexOf("}") > 0)) {					//Note we check for both { and }
		anchorString = new String();
		anchorString += topic.substring(0, topic.indexOf("{")); 					//String up to {
		anchorString += anchorStart+' onClick="setCookie(anchorName, anchorValue)"'+anchorHrefEnd;	//File name and call to set cookie
		anchorString += topic.substring((topic.indexOf("{")+1), topic.indexOf("}"));			//Insert anchored string
		anchorString += anchorEnd+topic.substring((topic.indexOf("}")+1), topic.length);		//End anchor and String after }
		return anchorString;
	} else  return topic;
}

function createWhatsNewTable() {
/**** Build the Whats New table from an external array file */
/**** Based on having four topics, 2 lines each             */
	whatsnewString = new String();

	//Table for all topics and images
	whatsnewString += '<!-- Table 5.1 Whats New -->';
	whatsnewString += '<TABLE WIDTH=385 BORDER=0 CELLPADDING=0 CELLSPACING=0>';
	whatsnewString += '<TR><TD><IMG SRC="Images/WhatsNewText.gif" WIDTH=362 HEIGHT=37 ALT=""></TD></TR>';
	
	if (whatsnewtopics.length == 0) {
		//Oops, we have an empty Whats New text file
		whatsnewString += 'Whats New file contains no topics! </td></tr>';
		return;
	} 	
	
	for (var i = 0; i < whatsnewtopics.length; i = i + 2) {
		whatsnewString += '<TR><TD class=bodybold>&nbsp;<IMG SRC="Images/Bullet1.gif" WIDTH=9 HEIGHT=10>&nbsp;';
		whatsnewString += insertAnchor(String(whatsnewtopics[i]))+'</TD></TR>';			//Insert the anchor (if needed) first line
		whatsnewString += '<TR><TD class=bodybold>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		whatsnewString += insertAnchor(String(whatsnewtopics[i+1]))+'</TD></TR>';		//Insert the anchor (if needed) second line

		if (i < 5) //We don't want the seperator bar after the last line
			whatsnewString += '<TR><TD><IMG SRC="Images/Line2.jpg" WIDTH=375 HEIGHT=7 ALT=""></TD></TR>';
	}

	whatsnewString += '</TABLE><!-- End Table 5.1 -->';

	//Write Table out
	var object=document.getElementById('whatsnew');
	object.innerHTML= whatsnewString;
	return true;
}