/*
Copyright (c) 2005, goIT
Please contact info@goIT.co.uk or visit www.goIT.co.uk

No part of this script may be used without written permission.
*/

//Define constants for all pages
var blnShowEmptyTopics = true;
var strHomePage = 'index'; //or 'default' depending on webserver
var strCompanyName = 'Fluevent Engineering Services Limited';
var strHeading = '';
var strMenuItems = new Array(11);
var strTopicItems = new Array(11);
  //create a 2D array
  strTopicItems[0] = new Array(11);
  strTopicItems[1] = new Array(11);
  strTopicItems[2] = new Array(11);
  strTopicItems[3] = new Array(11);
  strTopicItems[4] = new Array(11);
  strTopicItems[5] = new Array(11);
  strTopicItems[6] = new Array(11);
  strTopicItems[7] = new Array(11);
  strTopicItems[8] = new Array(11);
  strTopicItems[9] = new Array(11);
  strTopicItems[10] = new Array(11);

strMenuItems[1] = 'Home';
strMenuItems[2] = 'Contact';

function PageURL()
{
	//Returns the current page without path details or file extension
	//Note : if at index page, returns page0101
	var strURL = document.location.href;
	while (strURL.indexOf('/', 0) != -1) {
		strURL = strURL.substr(strURL.indexOf('/', 0) + 1, strURL.length - strURL.indexOf('/'));
	}
	while (strURL.indexOf('.', 0) != -1) {
		strURL = strURL.substr(0, strURL.indexOf('.', 0));
	}
	if ((strURL == strHomePage) || (strURL.length == 0)) {
		strURL = 'page0101';
	}
	return strURL;
}

function InitialPageConfig() {
	var strURL;
	var objObj;
	var intMenu;
	var intTopic;
	var strPageMenu;
	var strPageTopic;
	var strIndex;
	var strA;
	var intA;

	//Load up common texts	
	document.title = strCompanyName + ' - ' + strHeading;
	document.getElementById('tdHeadingCompanyName').innerHTML = strHeading;
	document.getElementById('spnSiteDesignCompanyName').innerHTML = strCompanyName;
	document.getElementById('imgCompanyLogo').alt = strCompanyName + ' ' + strMenuItems[1];

	//Display and select the current page on the menu and topic selection buttons
	strURL = PageURL();
	strPageMenu = strURL.substr(4, 2);
	strPageTopic = strURL.substr(6, 2);

	for (intA = 0; intA < document.getElementsByTagName('TD').length; intA++) {
		objObj=document.getElementsByTagName('TD')[intA];
		if (objObj.id.length > 0) {
			strIndex=objObj.id.substr(objObj.id.length - 2, 2);
			if (isNaN(strIndex) == false) {
				if (((objObj.id.toUpperCase().substr(0, 6)) == 'TDMENU') && (strMenuItems[Number(strIndex)] != undefined)) {
					objObj.style.display = '';
					objObj.innerHTML = strMenuItems[Number(strIndex)];
				}
				if (((objObj.id.toUpperCase().substr(0, 7)) == 'TDTOPIC') && (strTopicItems[Number(strPageMenu)] [Number(strIndex)] != undefined)) {
					objObj.parentNode.style.display = '';
					objObj.innerHTML = strTopicItems[Number(strPageMenu)] [Number(strIndex)];
				}
				if (((objObj.id.toUpperCase().substr(0, 6) == 'TDMENU') && (strIndex == strPageMenu))
				|| (((objObj.id.toUpperCase().substr(0, 7)) == 'TDTOPIC') && (strIndex == strPageTopic))) {
					strA = objObj.style.backgroundImage;
					strA = strA.substring(4,strA.length-1);
					if (strA.toUpperCase().substr(strA.length - 7, 7) == 'OFF.GIF') {
						strA = strA.substr(0, strA.length - 7) + 'On.gif';
						objObj.style.backgroundImage = 'url(' + strA + ')';
						objObj.style.cursor = 'default';
					}
				}
			}
		}
	}
	if ((blnShowEmptyTopics == true) || (document.getElementById('tdTopic01').parentNode.style.display == '')) {
		document.getElementById('tblTopics').style.display = '';
	}
}

function MenuOver(e) {
	var objSource;
	var strA;

	if (window.event) e = window.event;
	objSource = e.srcElement? e.srcElement : e.target;

	if (objSource.id.length >= 7) {
		if ((objSource.id.toUpperCase().substr(0, 6) == 'TDMENU') || (objSource.id.toUpperCase().substr(0, 7) == 'TDTOPIC')) {
			strA = objSource.style.backgroundImage;
			strA = strA.substring(4,strA.length-1);
			if (strA.toUpperCase().substr(strA.length-7, 7) == 'OFF.GIF') {
				strA=strA.substr(0, strA.length - 7) + 'Over.gif';
				objSource.style.backgroundImage = 'url(' + strA + ')';
			}
		}
	}
}

function MenuOut(e) {
	var objSource;
	var strA;

	if (window.event) e = window.event;
	objSource = e.srcElement? e.srcElement : e.target;

	if (objSource.id.length > 'tdMenu'.length) {
		if (objSource.id.toUpperCase().substr(0, 'tdMenu'.length) == 'TDMENU') {
			strA = objSource.style.backgroundImage;
			strA = strA.substring(4,strA.length-1);
			if (strA.toUpperCase().substr(strA.length - 8, 8) == 'OVER.GIF') {
				strA = strA.substr(0, strA.length - 8) + 'Off.gif';
				objSource.style.backgroundImage = 'url(' + strA + ')';
			}
		}
	}
	if (objSource.id.length > 'tdTopic'.length) {
		if (objSource.id.toUpperCase().substr(0, 'tdTopic'.length) == 'TDTOPIC') {
			strA = objSource.style.backgroundImage;
			strA = strA.substring(4,strA.length-1);
			if (strA.toUpperCase().substr(strA.length - 8, 8) == 'OVER.GIF') {
				strA = strA.substr(0, strA.length - 8) + 'Off.gif';
				objSource.style.backgroundImage = 'url(' + strA + ')';
			}
		}
	}
}

function MenuTopicSelection(e) {
	//jump to pagexxyy where xx is taken from tdMenu ID or yy is taken from tdTopic ID
	var objSource;
	var strImage;
	var strMenu;
	var strTopic;
	var strNowURL;
	var strTargetURL;

	strNowURL = PageURL();
	strMenu = strNowURL.substr(4, 2);
	strTopic = strNowURL.substr(6, 2);
	if (window.event) e = window.event;
	objSource = e.srcElement? e.srcElement : e.target;

	strImage = objSource.style.backgroundImage;
	strImage = strImage.substring(4,strImage.length-1);

	if (objSource.id.length > 6) {
		if (objSource.id.toUpperCase().substr(0, 6) == 'TDMENU') {
			if (strImage.toUpperCase().substr(strImage.length - 8, 8) == 'OVER.GIF') {
				strMenu = objSource.id.substr(objSource.id.length - 2, 2);
				strTopic = '01';
			}
		}
		if (objSource.id.toUpperCase().substr(0, 7) == 'TDTOPIC') {
			if (strImage.toUpperCase().substr(strImage.length - 8, 8) == 'OVER.GIF') {
				strTopic = objSource.id.substr(objSource.id.length - 2, 2);
			}
		}
		if (objSource.id.toUpperCase().substr(objSource.id.length - 11, 11) == 'COMPANYLOGO') {
			strMenu = '01';
			strTopic = '01';
		}
		strTargetURL = 'page' + strMenu + strTopic;
		if (strTargetURL != strNowURL) {
			if (strTargetURL == 'page0101') {
				strTargetURL = strHomePage;
			}
			document.location.href = strTargetURL + '.htm';
		}
	}
}

function ShowLargeImage(blnShowControls,e) {
	var objSource;
	var strURL;

	if (window.event) e = window.event;
	objSource = e.srcElement? e.srcElement : e.target;

	if (objSource.tagName.toUpperCase() == 'IMG') {
		strURL = objSource.src; 
		strURL = strURL.replace(/\.jPg$/i,'_Big.jpg');
		strURL = strURL.replace(/\.gif$/i,'_Big.gif');
		strURL = strURL.replace(/\.bmp$/i,'_Big.bmp');
		if (blnShowControls == false) {
			window.open(strURL, 'goIT_popup', 'channelmode=no,directories=no,fullscreen=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no', true);
		}
		if (blnShowControls == true) {
			window.open(strURL, 'goIt_popup', 'channelmode=no,directories=no,fullscreen=no,location=no,menubar=yes,resizable=yes,scrollbars=yes,status=no,titlebar=no,toolbar=no', true);
		}
	} 
}

