﻿// Turn TD into button
// These functions turn table cells into a button with a rollover state (relevant CSS in main CSS file), [and take the link from the first a href found in the cell]
// Could be rewritten to make the table-type selection a bit more generic

	function setUpTdButtons() {
		var tbls,i,j,k;
		tbls=document.getElementsByTagName('table');
		for(i in tbls) {
			if(tbls[i].className=="homeBoxes") {
				tds=tbls[i].getElementsByTagName('td');
				k=0;
				for(j=0;j<tds.length;j++) {
					//get url, apply onclick function
						tds[j].onclick=function(){addLink(this);};

					//apply onmouseover functions
					if (tbls[i].className=="homeBoxes"){
						if (Math.round(j/4)*4==j){
							tds[j].onmouseover=function(){homeTdBgOn(this, "1");};
						} else {
							tds[j].onmouseover=function(){homeTdBgOn(this, "2");};
						}


					k++;if(k==5){k=0;};
					}
					tds[j].onmouseout=function(){homeTdBgOff(this);};
				}

			}
		}
	}

	function homeTdBgOn(td,tdNum) {
		td.className="homeBlock"+tdNum;
	}

	function homeTdBgOff(td) {
		td.className="";
	}
	function addLink(me){
		links=me.getElementsByTagName('a');
		if(links.length>0){
				window.location=links[0];
		}
	}

//
// Pop-up script
var aNoteWin

var agt=navigator.userAgent.toLowerCase() // Make easier for testing
var isIE4;

this.major = parseInt(navigator.appVersion)
this.ie = (agt.indexOf("msie") != -1);
isIE4 = (this.ie && (this.major == 4));

function GetPositionLeft(nWindowLeft) {

	// Get client width and height
	var nClientWidth;
	nClientWidth = self.screenLeft;

	// Work-out window placements
	if (nClientWidth >= 0) {
		nWindowLeft = nClientWidth + 5;
	}

	return nWindowLeft;
}

function GetPositionTop(nWindowTop) {

	// Get client width and height
	var nClientHeight;
	nClientHeight = self.screenTop;

	// Work-out window placements
	nWindowTop = nClientHeight;

	return nWindowTop;
}


function popupsizable(topic,width,height) {

	if (isIE4) {
		var nWindowTop = GetPositionTop(nWindowTop);
		var nWindowLeft = GetPositionLeft(nWindowLeft);

		nWindowTop = nWindowTop + 70;
		nWindowLeft = nWindowLeft + 10;


	} else {
		var nWindowTop = 10;
		var nWindowLeft = 155;
	}
	
	if (self.aPopUp3 == null) {
		name = "SchemeInfo";
		aPopUp = window.open(topic,'SchemeDetails','scrollbars=yes,location=no,status=no,menubar=1,directories=no,top='+ nWindowTop +',left='+ nWindowLeft +',width='+width+',height='+height+',titlebar=no');
		self.aNoteWin = aPopUp;
	}
	else {
		name = "SchemeInfo";
		closePicture()
		aPopUp = window.open(topic,'SchemeDetails','scrollbars=yes,location=no,status=no,menubar=1,directories=no,top='+ nWindowTop +',left='+ nWindowLeft +',width='+width+',height='+height+',titlebar=no');
		self.aNoteWin = aPopUp;
	}
}

function closePicture(which) {
	if (self.aPopUp != null) {
		self.aPopUp = null;
		self.aNoteWin.close();
	}
}

//
// Attach load events

	if (window.attachEvent) {
		window.attachEvent("onload", setUpTdButtons);
	} else if (window.addEventListener){
		window.addEventListener("load", setUpTdButtons, false)
	} else if (document.addEventListener){
		document.addEventListener('load', setUpTdButtons, false);
	}
