// JavaScript Document
// dragons_contents.js
// by Michael Lofgren, created 18/1/2004
// Purpose: Provide the main functions that are called in every Dragons
//		contents page. Initially this includes code ensuring that frames
//		work correctly, and the file last modified date/time string code.

// A generic function run in the header of every content page, to make
// the code more extensible.
function contentHeadFunction(menustr) 
{
	contentFrameFunction();
} //end contentHeadFunction()

//Handles putting the content page into the frame set (the content page
//part of it anyway), and renaming the title bar correctly
function contentFrameFunction() 
{
	readPageConfig();

	if (top.navframes == "on") {
		//Execute the first section if the code is not loading in the contentFrame frame etc
		if ((window.name != 'contentFrame') && (window.name != 'booker_')
				&& !((self.innerHeight == 0) && (self.innerWidth == 0))) {
			var hashstr = '';
			var URLstr;
			
			if (location.hash.length > 0) {
				hashstr = '@' + location.hash.substring(1, location.hash.length);
			} 
			URLstr = '/index.html?' + location.pathname + hashstr + '~contentFrame';
			//alert(URLstr);
			top.location.replace(URLstr);
		} else { //This section runs if the rest of this page is going to load into the right spot.
			//Replace frameset title with this page's title
			top.document.title = self.document.title;
		} 
	} 
} //end contentFrameFunction()

//If frames are on, turn 'em off, and vice versa.
//This is the callback for the toggle frames button at the bottom of
//each content page.
function toggleFrames() 
{
	readPageConfig();

	if (top.navframes == "on") top.navframes = "off";
	else top.navframes = "on";
	setPageConfig();
	
//	readPageConfig();
} //end toggleFrames()

//Returns a string indicating the date the file was last modified.
//This is called at the bottom of each content page.
function getUpdateDateString() 
{
	var browserName = navigator.appName; 
	var lastmodstr = document.lastModified;
	var outputstr;
	//Split into an array of words that were separated by whitespace
	var datetime = lastmodstr.split(" ");

	//Handle different browsers differently
	if (browserName == "Netscape") { 
		//Assume format is "day, dd mmm yyyy hh:mm:ss GMT"
		var filedate;
		var datestr, timestr, gmtstr;			
				
		if (datetime.length >= 6) { //Should be correct format?
			var monthval = "";
				
			//Convert month to numbered format
			switch (datetime[2]) {
				case "Jan": monthval = '01'; break;
				case "Feb": monthval = '02'; break;
				case "Mar": monthval = '03'; break;
				case "Apr": monthval = '04'; break;
				case "May": monthval = '05'; break;
				case "Jun": monthval = '06'; break;
				case "Jul": monthval = '07'; break;
				case "Aug": monthval = '08'; break;
				case "Sep": monthval = '09'; break;
				case "Oct": monthval = '10'; break;
				case "Nov": monthval = '11'; break;
				case "Dec": monthval = '12'; break;
			}
			if (monthval != "") datetime[2] = monthval;
			
			//Assemble new string
			datestr = datetime[1] + "/" + datetime[2] + "/" + datetime[3];
			timestr = datetime[4];
			gmtstr = datetime[5];
			outputstr = datestr + " " + timestr + " " + gmtstr;
		} else {
			//For Firefox, format is "mm/dd/yyyy hh:mm:ss" (local time)
			var tempdate;
			var datestr, timestr;			
			datestr = datetime[0]; timestr = datetime[1];
					
			tempdate = datestr.split("/"); //split date into month, date, year
			
			//Assemble string
			datestr = tempdate[1] + "/" + tempdate[0] + "/" + tempdate[2];
			outputstr = datestr + " " + timestr;
			//outputstr = lastmodstr; //Use original string
		}
		
	} else if (browserName == "Microsoft Internet Explorer") {
		//For IE, format is "mm/dd/yyyy hh:mm:ss" (local time)
		var tempdate;
		var datestr, timestr;			
		datestr = datetime[0]; timestr = datetime[1];
				
		tempdate = datestr.split("/"); //split date into month, date, year
		
		//Assemble string
		datestr = tempdate[1] + "/" + tempdate[0] + "/" + tempdate[2];
		outputstr = datestr + " " + timestr;
	} else { //Other
		outputstr = lastmodstr; //Use original string
	}
		
	return outputstr;
} //end getUpdateDateString()

	//Construct email address in format name@subdomain.basedomain
	//dispstring is the string to display to the user, or "" if want the email address.
	function mailhider(name, subdomain, basedomain, dispstring) 
	{
		document.write('<a href=\"mailto:' + name + '@' + subdomain + '.' + basedomain + '\">');
		if (dispstring == "") {
			document.write(name + '@' + subdomain + '.' + basedomain + '</a>');
		} else {
			document.write(dispstring + '</a>');				
		}
	} //end contentHeadFunction()
	
	//mailhider("hithere", "dragons.org", "au", "");
