/* ==============================================================
	FRAW GENERIC JAVASCRIPT ROUTINES MODULE v0.11

	The purpose of this script is to provide additional function-
	ality to the main indexes of the FRAW web site.

	Copyright (C) 2011 Paul Mobbs/Free Range Network.
	
	Produced by Paul Mobbs/the electrohippie collective 2009
	Released under the Gnu General Public License v3.0 -- for a 
	copy of the license goto
	http://www.fraw.org.uk/gpl-3.html
	or see 
	http://www.gnu.org/licenses/
	
	This program is free software: you can redistribute it and/or 
	modify it under the terms of the GNU General Public License as 
	published by the Free Software Foundation, either version 3 of 
	the License, or (at your option) any later version.
	
	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.
*/


// --------------------------------------------------------------

// BROWSER ALERT TEST
// This routine checks the identity of the browser in order to  
// add additional information to the page for browsers that appear 
// to have a proprietary design.
function browser_alert()
{
	var idInfoString = new Array( "Microsoft", "MSIE", "Windows", "Macintosh", "Mac OS", "Opera", "Chrome");
	var agent = navigator.userAgent; 
	var ptr = 0;

	// check for incidence of each ID string
	for( ptr = 0; ptr < idInfoString.length; ptr++) 
	{ 
		if( agent.indexOf( idInfoString[ ptr]) > -1) 
		{
			return( 1);
		}
	}
	return( 0);
}


// --------------------------------------------------------------


// ONLOAD EXECUTION ROUTINE
// This routine is called by 'onload' from the BODY tag and 
// ensures that the page is being displayed in the 'top' window.
function load()
{
	if( parent.frames[ 1])
	{
			parent.location.href = self.location.href;
	}
}


// --------------------------------------------------------------

// KEY ID QUERY ROUTINE
// This routine is called automatically from a web page and tests
// the search object for a key parameter and then automatically 
// forwards to the requested file.
function query()
{
	var queryString = window.location.search;
	queryString = queryString.toLowerCase();
	queryString = queryString.substr( 1);
	queryString = queryString.replace(/\-/g,'');
	queryString = queryString.replace(/_/g,'');
	queryString = queryString.replace(/ /g,'');
	if( queryString.length > 0)
	{
		window.location.href = '/redirect.html?' + queryString;
	}
}


// --------------------------------------------------------------

// KEY INDEX REDIRECTION ROUTINE
// This function takes an address string from the navigation bar 
// drop down index and automatically forwards to the requested page.
function redirect( index)
{
	window.location.href = index;
}


// --------------------------------------------------------------

// WHAT AM I?
// This routine returns the identity string of the browser.
function whatami()
{
	var agent = navigator.userAgent; 
	var message = '\n\nYour browser SHOULD NOT trigger the "Browser Alert!" script.';

	// check for incidence of each ID string
	if( browser_alert()) 
	{
		message = '\n\nYour browser SHOULD trigger the "Browser Alert!" script.';
	}

	// show alert message
	alert( 'Browser identity --\n\n"' + agent + '"' + message);
}


// ==============================================================

// END OF SCRIPT


