﻿/*
 * Javascript each page should execute
 */
 
var CSS_DIR = "css/";										// directory where the style sheets reside
var CSS_NN4_WINDOWS = "nn4windows.css";						// style sheet for Netscape 4 for Windows
var CSS_NN4_LINUX = "nn4linux.css";							// style sheet for Netscape 4 for Linux
var CSS_IE4 = "ie4.css";									// style sheet for IE4 and greater
var CSS_OPERA_WINDOWS = "operawindows.css";					// style sheet for Opera for Windows
var CSS_OPERA_LINUX = "operalinux.css";						// style sheet for Opera for Linux
var START_STYLE_TAG = "<LINK REL=\"stylesheet\" HREF=\"";	// start of HTML style sheet tag
var END_STYLE_TAG = "\" TYPE=\"text/css\">";				// end of HTMl style sheet tag
var ADMIN_SUBDIR = "admin";									// subdir where admin pages reside
var SUBDIRECTORIES = new Array(								// all subdirectories with HTML/PHP files
	"nederlands",
	"english",
	"php",
	ADMIN_SUBDIR
);

/*
 * Returns:	the filename of this document
 */
function getFileName() {
	var path = location.pathname;
	var i = path.length - 1;
	while((i > 0) && (path.charAt(i) != '/') && (path.charAt(i) != '\\')) i--;
	start = ++i;
	while((i < path.length) && (path.charAt(i) != '?')) i++;
	return path.substring(start, i);
} 

/*
 * Checks if this document resides in a subdirectory
 *
 * Returns:	true:	if it does
 *			false:	if not
 */
function documentInSubdir() {
	pagePath = self.document.location.pathname;
	for (i = 0; i < SUBDIRECTORIES.length; i++) {
		thisDir = SUBDIRECTORIES[i];
		if ((pagePath.indexOf(thisDir + "/") >= 0) ||
			(pagePath.indexOf(thisDir + "\\") >= 0)) {
			return true;
		}
	}
	return false;
}

/*
 * Checks whether only the style sheet should be loaded for this document
 */
function onlyLoadStyleSheet() {
	return self.document.location.pathname.indexOf("/" + ADMIN_SUBDIR + "/") >= 0 ||    // admin part
		self.document.location.pathname.indexOf("/" + ADMIN_SUBDIR + "/") >= 0 ||    // admin part
		self.name.indexOf("popup") == 0;                                           // popup window
}


/*
 * Returns:	the name of the style sheet to use in this browser
 */
function getStyleSheetFileName() {
	var result = "";
	if (NN4plus) {
		result = LINUX ? CSS_NN4_LINUX : CSS_NN4_WINDOWS;
	} else if (IE4plus) {
		result = CSS_IE4;
	} else if (OPERA) {
		result = LINUX ? CSS_OPERA_LINUX : CSS_OPERA_WINDOWS;
	}
	result = CSS_DIR + result;
	if (documentInSubdir()) result = "../" + result;

	return result;
}


/*
 * Loads the browser-specific style sheet
 */
function loadStyleSheet() {
	if (CSS) {
		document.open();
		document.write(START_STYLE_TAG + getStyleSheetFileName() + END_STYLE_TAG);
		//document.write("<LINK REL=\"shortcut icon\" HREF=\"../images/page/favicon.ico\">");
		document.close();
	}
}

/*
 * Main code
 */
 
// Which browser do we have?
var NN = (navigator.appName == "Netscape");
var NN2 = NN && (navigator.userAgent.indexOf("Mozilla/2") != -1);
var NN3 = NN && (navigator.userAgent.indexOf("Mozilla/3") != -1);
var NN4 = NN && (navigator.userAgent.indexOf("Mozilla/4") != -1);

var IE = navigator.userAgent.indexOf("MSIE") != -1;
var IE3 = navigator.userAgent.indexOf("MSIE 3") != -1;
var IE4 = navigator.userAgent.indexOf("MSIE 4") != -1;

var OPERA = navigator.userAgent.indexOf("Opera") != -1;

// Define some families
var NN3plus = NN && (parseInt(navigator.appVersion) >= 3);
var NN4plus = NN && (parseInt(navigator.appVersion) >= 4);
var IE4plus = IE && (parseInt(navigator.appVersion) >= 4);

var OPERA = navigator.userAgent.indexOf("Opera") != -1;

// Do we have style sheets?
if (IE) var IEcss = document.all ? true : false;
if (NN) var NNcss = parent.document.layers ? true : false;
//var CSS = (IEcss || NNcss || OPERA);
var CSS = true;   // every browser should know style sheets nowadays

// Which OS are we using?
var LINUX = navigator.userAgent.indexOf("Linux") != -1;
var WINDOWS = navigator.userAgent.indexOf("Windows") != -1;

var fileName = getFileName();

// Check if we're in the right frame
if (onlyLoadStyleSheet()) {
	loadStyleSheet();
} else if (self == top) {
	var suffixStart = fileName.lastIndexOf(".");
	document.location = "index.html?" + fileName.substr(fileName, suffixStart);
} else {
	checkEnvironment(fileName);
	loadStyleSheet();
}
