// JavaScript Document

function windowResize(lmw, rmw) {

	var isIE = false;
	var isMoz = false;
	var isSafari = false;

	if (window.innerWidth) {
		/* Catches Firefox, Safari, Opera */
		isMoz = true;
		if (navigator.appVersion.search(/safari/i) > -1) {
			isSafari = true;
			/* Sarafi seems to do this differently ... */
			/* and Safari doesn't tell you anything helpful about scroll bars */
			var currWidth = window.innerWidth;
			var currHeight = window.innerHeight;
			var currScrollHeight = window.document.body.scrollHeight;
		} else {
			/* Use scollWidth rather than innerWidth to account for vertical scroll bars */
			/* Only required for Firefox, Safari, Opera ... */
			/* var currWidth = window.innerWidth; */
			var currWidth = window.document.body.scrollWidth;
			var currHeight = window.innerHeight;
		}
	}	else if (document.documentElement) {
		/* IE7 */
		isIE = true;
		var currWidth = document.documentElement.clientWidth;
		var currHeight = document.documentElement.clientHeight;
		var currScroll = document.documentElement.scrollHeight;
	}	else if (document.all) {
		/* Older browsers, perhaps - not got one that does it */
		var currWidth = document.body.clientWidth;
		var currHeight = document.body.clientHeight;
		var currScroll = document.body.scrollHeight;
	}

	if (lmw === undefined) {	lmw = 200; }
	if (rmw === undefined) {	rmw = 200; }

	var topBannerHeight = 120;
	var topMenuHeight = 28;
	var leftMenuWidth = lmw;
	var rightMenuWidth = rmw;
	var botMenuHeight = 28;
	var trBorder = 0;
	var trSpacing = 1;

	if (isSafari) {
		//alert(navigator.appVersion);
		/*window.status = "currWidth: " + (currWidth + "px") + " currHeight: " + currHeight + " currScrollHeight: " + currScrollHeight;*/
	}
	
	/* 5 * spacing, 8 * border */

	if (document.getElementById) {
		/* Catches IE, Firefox, Safari, Opera */
		var divBack = document.getElementById("divBack");
		var eMainTable = document.getElementById("tblMain");
		/* Get reference to table elements */
		var eTopBanner = document.getElementById("trTopBanner");
		var eTopMenu = document.getElementById("trTopMenu");
		var eBotMenu = document.getElementById("trBotMenu");
		var eMainBlock = document.getElementById("trMainBlock");
		var eMainContent = document.getElementById("MainContent");
		var eMainTD = document.getElementById("tdMainContent");
		/* Check if menus are there */
		if (! document.getElementById("tdLeftMenu")) {
			leftMenuWidth = 0;
		}
		if (! document.getElementById("tdRightMenu")) {
			rightMenuWidth = 0;
		}
	} else {
		/* Not sure what this catches ... old IE perhaps? */
		var divBack = document.all.divBack;
		var eMainTable = document.all.tblMain;
		/* Get reference to table elements */
		var eTopBanner = document.all.trTopBanner;
		var eTopMenu = document.all.trTopMenu;
		var eBotMenu = document.all.trBotMenu;
		var eMainBlock = document.all.trMainBlock;
		var eMainContent = document.all.MainContent;
		var eMainTD = document.all.tdMainContent;
	}
	
	/* Firefox, Safari, Opera need these */
	/* Opera needs the position value set, and consequently you have to set the width !! */
	/* If the height of the content is larger than the div, the screen scrolls automatically  */
	/* However, we need to take the vertical scroll bar into account when setting the width  */
	/* Safari doesn't behave quite as expected ... may need some different width resizing */
	/*eMainTable.style.width = (currWidth + "px");*/
	/*if (isSafari == false) {
		divBack.style.width = (currWidth + "px");
	}*/
	
	if (isSafari) {
		if (currScrollHeight > (currHeight + 20)) {
			currWidth = (currWidth - 15);
		}
	}
	divBack.style.width = (currWidth + "px");
	divBack.style.height = (currHeight + "px");
	divBack.style.position = "absolute";	
	
	/* Need to set the height of the centre block, but only for IE													*/
	/* and only if the content is not bigger than the client window - IE does not deal helpfully */
	/* Firefox, Safari and Opera all behave similarly, and don't need the centre height set 	*/
	if (isIE) {
		/* alert('IE'); */
		/* get main block div height */
		var currDivHeight = eMainContent.offsetHeight;
		var currBlockHeight = eMainBlock.offsetHeight;
		eTopBanner.style.height = (topBannerHeight + "px");
		eTopMenu.style.height = (topMenuHeight + "px");
		eBotMenu.style.height = (botMenuHeight + "px");
		/*eMainContent.style.height = " ";
		/* If clause required here to check if content is scrolled */
		/*alert("ch: " + currHeight + " cs: " + currScroll);*/
		/*window.status = ("ch: " + currHeight + " cs: " + currScroll + " cdh: " + currDivHeight + " cbh: " + currBlockHeight);*/
		if (currHeight > (topBannerHeight + topMenuHeight + currDivHeight + botMenuHeight)) {
			/* Expand the central block to put the menu at the bottom of the screen */
			/* eMainBlock.style.height = ((currHeight - topBannerHeight - topMenuHeight - botMenuHeight - 26) + "px"); */
			eMainBlock.style.height = ((currHeight - topBannerHeight - topMenuHeight - botMenuHeight - 26) + "px");
		} else {
			/* Set the block height to be the same as the div height */
			eMainBlock.style.height = (currDivHeight + "px");
		}
		/* ... and apparently the same for the width */
		eMainContent.style.width = ((currWidth - leftMenuWidth - rightMenuWidth - 40) + "px");	
	}
}


function fontAdjust(direction) {
	
	var change = 0;
	
	if (direction == '+') {
		change = 3;
	} else {
		change = -3;
	}
	
	var ap = document.getElementsByTagName("p");
	for (n = 0; n < ap.length; n++) {
		i = ap[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 10;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 10) {
			fsize = 10;
		}
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}

	var ah1 = document.getElementsByTagName("h1");
	for (n = 0; n < ah1.length; n++) {
		i = ah1[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 20;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 20) {
			fsize = 20;
		}
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}
	
	var ah2 = document.getElementsByTagName("h2");
	for (n = 0; n < ah2.length; n++) {
		i = ah2[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 20;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 20) {
			fsize = 20;
		}
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}

	var ah3 = document.getElementsByTagName("h3");
	for (n = 0; n < ah3.length; n++) {
		i = ah3[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 18;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 18) {
			fsize = 18;
		}
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}
	
	var ah4 = document.getElementsByTagName("h4");
	for (n = 0; n < ah4.length; n++) {
		i = ah4[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 14;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 14) {
			fsize = 14;
		}
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}

	var ah5 = document.getElementsByTagName("h5");
	for (n = 0; n < ah5.length; n++) {
		i = ah5[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 12;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 12) {
			fsize = 12;
		}
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}
	
	var ah6 = document.getElementsByTagName("h6");
	for (n = 0; n < ah6.length; n++) {
		i = ah6[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 11;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 11) {
			fsize = 11;
		}		
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}
	
	var alab = document.getElementsByTagName("label");
	for (n = 0; n < alab.length; n++) {
		i = alab[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 10;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 10) {
			fsize = 10;
		}
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}
	
	var aleg = document.getElementsByTagName("legend");
	for (n = 0; n < aleg.length; n++) {
		i = aleg[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 10;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 10) {
			fsize = 10;
		}
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}

	var ain = document.getElementsByTagName("input");
	for (n = 0; n < ain.length; n++) {
		i = ain[n];
		//p = Number(i.style.fontSize);
		// The size is a string with formatting on theend - either pt or px
		// Split into parts and then increment
		fsize = i.style.fontSize;
		fsize = fsize.replace(/[^0-9\.]+/, '');
		funit = i.style.fontSize;
		funit = funit.replace(/[0-9\.]+/, '');
		if (fsize.length == 0) {
			fsize = 10;
			funit = "pt";
		}
		//alert("current size: " + i.style.fontSize + " size: " + fsize + " unit: " + funit);
		fsize = Number(fsize) + change;
		if (fsize < 10) {
			fsize = 10;
		}
		//alert("new size: " + fsize + funit);
		i.style.fontSize = String(fsize) + funit;
	}

} 