/*
	<meta http-equiv="content-type" 	content="text/html;charset=iso-8859-1">
	
	<meta name="author" 				content="Thomas Wilson">
	<meta name="host" 					content="wehostmacs.com">
	<meta name="host-admin" 			content="noc@wehostmacs.com">
	<meta name="keys"					content="brainfarts, add, apple">

	<meta name="creation" 				content="08/28/2005">
	<meta name="last_modified"			content="11/04/2005">
*/

/* ------------------------------------------------------------------- */
/*             Globals: Vars global to all routines                    */
/* ------------------------------------------------------------------- */

var myDomainName	= "brainfarts.com";
var debugWindow		= null;
var wDebugSwitches	= null;
		
var modDays			= new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var modMonths		= new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

var debugWinMsg		= 'Where\'s the friggin\' debug window?\n\nIf popups are being blocked '	+
			  		  'the debug window will not be allowed to open.\n\nTo see debug messages '	+
			  		  'you must disable the popup blocking feature, then reload the page.';

//
// == All the following routines need to be available early,
// == while the frames are loading and initializing, so the
// == frameset source is a convenient place for them to live.
//
// == They are all easily accessible using the "top" property
// == of the base window object [ie - top.functionName();]
//

function debugPrint(textToPrint) {
	if (debugWindow != null)
		with (debugWindow) {
			document.write(textToPrint.fontsize(1) + '<br>\n');
			debugWindow.scrollBy(0, 50);
		};
};

function getPageModDate(whichPage) {
	var getterFound = false;
	var modDate = 'not available';

	if (document.getElementsByName) {
		getterFound = true;

		var meta_creation = main.document.getElementsByName("creation");
		var meta_modified = main.document.getElementsByName("last_modified");

		modDate = meta_modified[0].content;
	};

	if (top.sw_debugWindow) {
		s = whichPage.location.pathname;
		m = "no mod date"
		
		if (whichPage.document.lastModified)
			m = whichPage.document.lastModified;
	
		debugPrint('<br>getPageModDate(' + removePath(whichPage.location.pathname) + ') [' +  m + ']');
		
		if (getterFound) {
			debugPrint('META: creation is ' + meta_creation[0].content);
			debugPrint('META: last_modified is ' + meta_modified[0].content);
	
		}
	
		else
			debugPrint('META: getElementsByName() not available in this browser...');
	};

	if (top.sw_useLastModified && whichPage.document.lastModified) {
		var pageDate = new Date(whichPage.document.lastModified);

		return (pageDate.getDate() + " "
			  + modMonths[pageDate.getMonth()] + " "
			  + pageDate.getFullYear()
			  );
	}

	else
		return (modDate);
};


/* ------------------------------------------------------------------- */
/*                                UTILITIES                            */
/* ------------------------------------------------------------------- */
function isAlphabetic(aChar) {
	if ((aChar > 64 && aChar < 91) || (aChar > 96 && aChar < 123))
		return true;
	
	return false;
};


function removePath(aURL) {
	return (aURL.substring(aURL.lastIndexOf('/')+1, aURL.length));
};


//
// -- Return the height that the main window will be created with
//
// -- Since the width of a window can't be set without also setting the height (lame!)
// -- I try to calculate the height from the screen size. This was previously done for
// -- Navigator using the Java awt via LiveConnect which not only required Java to be
// -- enabled, but with the Navigator 4 browsers caused users to endure a painfully
// -- long Java startup sequence.
//
// -- Since only browsers with versions > 4.0 are now supported, the screen object
// -- is now used instead to determine the user's screen size.
//
// -- If the browser is either Navigator or Explorer and the version is >= 4, set the
// -- window height based on the monitor size. Otherwise use a default height.
//
// -- Window Heights: (screen = window)
// --	480 =  390
// --	600 =  510
// --	640 =  550
// --	768 =  678
// --	800 =  710
// --	840 =  750
// --	960 =  870
// --  1200 = 1110
//
function getWindowHeight() {
	var overhead		=  90;		// overhead of the browser window (Netscape on a Mac)
	var window_height	= 390;		// height for a 640x480 screen size
	var debug_allowance	=  20;		// allow 20 pixels for the location text box if sw_showLocation == true

	if (!top.sw_showLocation)
		debug_allowance =  0;

	if (screen)
		window_height = screen.availHeight - (overhead + debug_allowance);

	if (top.sw_showScreenInfo)
		with (screen)
			alert('Height:  ' + height			+ '\n' +
				  'H_Avail: ' + availHeight		+ '\n' +
				  'H_Open: 	' + window_height	+ '\n' +
				  'Width:   ' + width			+ '\n' +
				  'W_Avail: ' + availWidth		+ '\n' +
				  'W_Open: 	' + getWindowWidth()
			);
			
			return (window_height);
};


//
// -- Return the width that the main window will be created with
//
function getWindowWidth() {
	var scrollBar		=  16;		// Width of a scroll bar
	var window_width	= 870;		// width for a non Netscape 640x480 screen size

	//
	// -- These browsers add the width of a scroll bar to the specified width
	//
	if ((top.browser == "Explorer") || (top.browser == "iCab"))
		window_width = window_width - scrollBar;

	return (window_width);
};

				  
//
// -- Establish the frame set for this page.
//
function setUpFrames() {
	//
	// -- Create a new window for "BrainFarts Productions" so I can limit
	// -- the viewers navigation options. It'll save confusion at the expense
	// -- of a little inconvenience. The original browser window remains anyway.
	//
	if (!top.sw_testPopupAlert) {
		if (top.sw_showLocation)
			var newWindow = window.open('index_frameset.html',
										'brainfarts',
										'resizable,status,menubar,width=' +
										 getWindowWidth() +
										',height=' +
										 getWindowHeight() +
										',location');
		
else
			var newWindow = window.open('index_frameset.html',
										'brainfarts',
										'resizable,status,menubar,width=' +
										 getWindowWidth() +
										',height=' +
										 getWindowHeight());
	};

	if (newWindow) {
		//
		// -- If the home page was linked to from outside brainfarts.com,
		// -- return the referring page to its original location.
		//
		if ((document.referrer.toLowerCase().indexOf(document.domain.toLowerCase()) == top.notMyDomain) ||
		   (document.referrer.toLowerCase().indexOf('brainfarts') == top.notMyDomain)) {
			
			if (newWindow.opener.history.length > 0)
				newWindow.opener.history.back()			// return the calling browser window to its original URL

			//
			// -- Opera on Macs places the title bar of a new window behind the menu bar.
			// -- There's no way to move the window 'cause the title bar can't be accessed
			// -- This moves the window down enough to expose the title bar.
			//
			var macMenuBar = 20;						// height of the Mac menu bar

			if ((OS = "Mac") && (browser = "Opera"))
				newWindow.moveBy(0, macMenuBar + 4);

			//
			// -- No popup blocker so prevent error messages
			//
			jsPopupMessage	= 0;
			htmlPopupMessage= 0;
			newWindow.focus();							// insure brainfarts is the front window
		};
	}

	else
		doPopupAlert();
};


//
// -- Create a new window for debug messages to be written to.
//
function openDebugWindow() {
	var wDebugOffsetX	=  50;
	var wDebugOffsetY	=   0;
	var wDebugWidth		= 400;
	var wDebugHeight	= getWindowHeight();
	var wAttributes		= 'resizable,width='	+
						   wDebugWidth			+
						  ',height='			+
						   wDebugHeight;

	debugWindow = window.open('',
							  'brainfarts_debugger',
							   wAttributes);

	if (debugWindow != null) {
		debugWindow.document.title = 'Brainfarts Debugger';
		debugWindow.moveBy(getWindowWidth() + wDebugOffsetX, wDebugOffsetY);
		debugWindow.document.open();

		debugPrint('');
		debugPrint('Debugger activated');
		debugPrint('Browser: ' + navigator.appName + '[' + browser + ']');
		debugPrint('Version: ' + navigator.appVersion + '[' + version + ']');
	}

	else
		alert(debugWinMsg);
};


//
// -- Create a new window for debug switches.
//
function showDebugSwitches() {
	var wDebugOffsetX	=  16;
	var wDebugOffsetY	=  -22;
	var wDebugWidth		= 400;
	var wDebugHeight	= 130;
						  
	switch (top.brsr_class) {
		case 'Safari' :	
			wDebugHeight += 53;
			
			break;
		
		case 'FireFox' :
			if (OS == 'Windows')
				wDebugHeight += 10;
			
			break;
	};
	
	var wAttributes		= 'resizable,width='	+
						   wDebugWidth			+
						  ',height='			+
						   wDebugHeight			+
						  ',location';

	wDebugSwitches = window.open('index_debug.html',
								 'debug_switches',
								  wAttributes);

	if (wDebugSwitches != null) {
		wDebugSwitches.document.title = 'Debug Switches';
		wDebugSwitches.moveBy(getWindowWidth() - wDebugOffsetX, wDebugOffsetY);

		if (top.sw_debugWindow) {
			debugPrint('');
			debugPrint('Debug switches available');
		};
	}

	else
		alert(debugWinMsg);
};


//
// -- close any debug windows that are open when the frameset goes away
//
function closeDebugWindows() {
	if (debugWindow != null) {
		debugWindow.close();
		debugWindow = null;
	};

	if (wDebugSwitches != null) {
		wDebugSwitches.close();
		wDebugSwitches = null;
	};
};


//
// -- This routine is only called by pages that display the "not done" image.
// -- The image's container is set to "visibility:hidden" within the default
// -- style sheet to prevent it from displaying before the alternate style sheet
// -- can load. Once the page has loaded this routine is called to make the
// -- image visible. It only effects the image loaded be the default style sheet.
//
// -- Currently (3.9.06) the following pages display the "not done" image:
//
// -- 		/pages/main_content_frames/apple_main.html
// -- 		/pages/main_content_frames/brainfarts_main.html
// -- 		/pages/main_content_frames/contents_main.html
//
function not_done_init() {
	setTimeout('top.main.document.getElementById("not_done").style.visibility="visible"', halfSecond);
};


function environment_init() {
	return true;
};


