// ******************************
// **    Standard JS File     **
// **  CopyWrite David Beale  **
// **       04/09/2002        **
// *****************************


// **********************
// ** Global Variables **
// **********************


// Create ImageButton code array
var ImageButtons = new Array();



// *******************
// ** Include Files **
// *******************

IncludeScript('scripts/config.js');



// **********************
// ** Global Functions **
// **********************



// Include a .js file at the position of the call to this function
function IncludeScript(FileName)
{
	document.write('<script language="javascript" type="text/javascript" src="' + FileName + '"></script>');
}





// Netscape 4.7 browser test
Net47 = ( (navigator.appName=="Netscape") && (parseInt(navigator.appVersion) < 5) );

// Internet Explorer browser test
IE = (navigator.appName=="Microsoft Internet Explorer");




// Perform standared onLoaded functions
function HandlePageLoaded()
{

	// Evaluate ImageButton code array
	for (Count=0; Count<ImageButtons.length; Count++)
		eval(ImageButtons[Count]);

}




// Create a Link 
function Link(Text, StatusText, URL, StyleClass)
{
	return("<a href='" + URL + "' class='" + StyleClass + "' onmouseover='window.status=" + '"' + StatusText + '"' + ";return  true;' onmouseout='window.status=" + '""' + ";return  true;'>" + Text + "</a>");
}




// Add bookmark
function DoBookmark(URL, Title)
{
	if (IE)
		window.external.AddFavorite('http://' + URL, Title);
	else
		alert('Close this Message Box and then Press CTRL-D, to Bookmark this Site.');
}



// Create Email link
// If no Address is given then EmailAddress variable is used 
function CreateEmail(StyleClass, Text, Address)
{
	if (Address == "")
		Address = EmailAddress;

	document.write('<a href="mailto:' + Address + '" class="' + StyleClass + '" onmouseover="window.status=' + "'" + Address + "'" + ';return true;" onmouseout="window.status=' + "''" + '";return true;>' + Text + '</a>');
}



// Execute an email
// If no Address is given then EmailAddress variable is used 
function ExecuteEmail(Address)
{
	if (Address == "")
		Address = EmailAddress;
	
	window.location.href = "mailto:" + Address;
}



// Recommend Site by Email
function RecommendSite(URL)
{
	var MailStr = "I recomend you visit http://" + URL; 
	window.location.href = "mailto:?subject=Visit " + URL + "&body=" + MailStr;
}



// This function creates an html ImageButton
function ImageButton(Name, URL, StatusText, Caption, NormalImageURL, HighlightedImageURL)
{
	// If no StatusText, use URL
	if (StatusText == '')
		StatusText = URL;

	// Create Normal Image
	eval(Name + "Normal = new Image();");
	eval(Name + "Normal.src = '" + NormalImageURL +"';");

	// Create Highlighted Image
	eval(Name + "Highlighted = new Image(" + Name + "Normal.width, " + Name + "Normal.height);");
	ImageButtons[ImageButtons.length] = Name + "Highlighted.src = '" + HighlightedImageURL +"';";
	
	// Write the button
	document.write('<a href="' + URL + '" onfocus="this.blur()" onmouseover="SwapImage(');
	document.write("'" + Name + "','" + Name + "Highlighted'");
	document.write(');window.status=' + "'" + StatusText + "';return true" + '" onmouseout="SwapImage(');
	document.write("'" + Name + "','" + Name + "Normal'");
	document.write(');window.status=' + "''" + ';return true"><img alt="' + Caption + '" src="' + NormalImageURL + '" border="0" name="' + Name + '" align="absbottom"></a>');
}



// This function swaps images
function SwapImage(oldButton,newButton)
{
	if (document.images)
		document.images[oldButton].src=eval(newButton + ".src");

}




// Create a menu system
// StyleClass CSS must define a link style, a plane style and a 'stylename'HighLight style 
function CreateMenu(StyleClass, MenuArray)
{
	document.write('<font class="' + StyleClass + '">');	

	// Loop througth each menu item
	for (Count=1; Count<MenuArray.length; Count+=2)
	{
		var FileName = ExtractFilename(document.location.pathname);
		// Handle root page
		if ((FileName == "") || (FileName == "/")) FileName = "index.html";

		if ( MenuArray[Count+1] == FileName )
			// Current Page
			document.write('<font class="' + StyleClass + 'HighLight">' + MenuArray[Count] + '</font>');
		else
			// Normal Link		
			document.write('<a href="' + MenuArray[Count+1] + '" class="' + StyleClass + '" onfocus="this.blur()" onmouseover="window.status=' + "'" + MenuArray[Count] + "'" + ';return true;" onmouseout="window.status=' + "''" + ';return true;">' + MenuArray[Count] + '</a>');
		
		// Insert break chars
		if (Count < MenuArray.length-2) document.write(MenuArray[0]);
	}

	document.write('</font>');
}





// Create a graphical menu system
//  
function CreateGraphicalMenu(MenuArray)
{
	// Loop througth each menu item
	for (Count=1; Count<MenuArray.length; Count+=6)
	{
		var FileName = ExtractFilename(document.location.pathname);
		// Handle root page
		if ((FileName == "") || (FileName == "/")) FileName = "index.html";	

		if ( MenuArray[Count+1] == FileName)
			// Current Page
			document.write("<img src='" + MenuArray[Count+5] + "' align='absbottom'>");		
		else 
			// Normal Link		
			ImageButton(MenuArray[Count], MenuArray[Count+1], MenuArray[Count+2], MenuArray[Count+3], MenuArray[Count+4], MenuArray[Count+5]);		
		
		// Insert break chars
		if (Count < MenuArray.length-2) document.write(MenuArray[0]);
	}
}




// Write a Cookie
function setCookie(name, value, life)
{
	var exp = new Date();                                          // make new date object
	exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * life));     // set it life days ahead
	document.cookie = name + "=" + escape(value) + "; path=/; expires=" + exp.toGMTString();
}



// Read a Cookie
function getCookie(name)
{
	var cname = name + "=";               
	var dc = document.cookie;             
	    if (dc.length > 0) {              
	    begin = dc.indexOf(cname);       
	        if (begin != -1) {           
	        begin += cname.length;       
	        end = dc.indexOf(";", begin);
	            if (end == -1) end = dc.length;
	            return unescape(dc.substring(begin, end));
	        }
	    }
	return null;
}



// Delete a Cookie
function delCookie(name)
{
	document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}




// Return the filename from a path
function ExtractFilename(filepath)
{
	// Move backward through path
	for (var CharCount=filepath.length-1; 0<=CharCount; CharCount--)
	{
		if ( (filepath.substring(CharCount, CharCount+1) == '/') || (filepath.substring(CharCount, CharCount+1) == '\\') )
			return filepath.substring(CharCount+1, filepath.length).toLowerCase();
	}

	return filepath.toLowerCase();
}


