/*


var path = "http://www.bbk.ac.uk/study/ce/templates";
var path = "http://betula.ccs.bbk.ac.uk/fce-test";
document.write('<link rel="stylesheet" href="' + path +  '/additional.css" type="text/css" />');


*/
var browser;

if ( (document.getElementById) && (  navigator.appVersion.indexOf('MSIE')>=0 ) ) {
	
		browser = "ie";
		
	
} else {
	
	browser = "stan";
	
}
	
	
if ( (browser == 'ie') && (navigator.appVersion.indexOf('7.')>=0) ) {
	
	browser = 'ie7';
	
	
}

function searchFormTest() {
	
	if  (document.forms['search'].words.value == '' ) {
	
		return false;
		
	} else {
	
		return true;
		
	}
	
	
}


window.onload = function() {
	
	
	displayAddInit();	
	init();	
	if ( browser == 'ie7') {
		document.getElementById("body").style.width="90%";
	}
		
		
}

function init() {
	colresizer();
	window.onresize=getwidth;	
}

function sortNumber(a, b) {
	
	return a - b
	
	}
	
	
function getCurrentWidth() {
	
	theWidth = parseFloat(document.getElementById('sitecontainer').offsetWidth);	
	window.onresize=fixIEminwidth(theWidth);	
	
	
		
}
	
function fixIEminwidth(thisWidth) {
	
	var sitecondiv = parseFloat(thisWidth);
	if ( (browser=='ie') && (browser!='ie7')  ) {
		
		
		if (  sitecondiv <=750)  { 
				
				document.getElementById('sitecontainer').style.width='750px';
				
				
		} else  {
				bodywidth = window.innerWidth;;
;
				document.getElementById('sitecontainer').style.width=bodywidth;
				
				
			
		}
		
	
		
	}
	

	
}

function getwidth() {

	var theWidth = document.body.offsetWidth;
	
	// only do this for IE to get round min-width problem
	if ( (browser=='ie'>=0) && (browser!='ie7')  ) {
	
	
		if (parseFloat(theWidth) <=750) {
			document.getElementById('sitecontainer').style.width = "750";
		
		} else if ( parseFloat(theWidth) >=750 ) {
	
			document.getElementById('sitecontainer').style.width = "100%";
	
		}
	}
	
		colresizer();
}

function colresizer() {
	
	//
	
	
	if ( (browser=='ie') && (browser!='ie7')  ) {
		window.onresize=getwidth;
		
	}

	divarray = new Array('content-col-1', 'content-col-2', 'content-col-3');
	
	divheights = new Array();

	for (i=0; i <=divarray.length-1; i++) {
	
			
			divheights[i] = String(document.getElementById(divarray[i]).offsetHeight);
			//alert("divheights" + i + ": " + divheights[i]);
				
		}
		
	divheights.sort(sortNumber);
	/*for (i=0; i<=divheights.length-1; i++) {
	
		alert("Sorted divheight" + i + ": " + divheights[i]);
	
	}*/
	
	
	var padding;
	
	if (navigator.appVersion.indexOf('MSIE')>=0) {
		
		padding=115;		
		
	} else {
	
		padding=95;
	}

	var thegreatestHeight = parseFloat(divheights[2]) + padding;
	//alert("Highest number:" + thegreatestHeight);
	var maxheight = String(thegreatestHeight);
	var topmargin = maxheight + "px";
	
	
	var foot = document.getElementById('footer');
	foot.style.position='absolute';
	foot.style.top=topmargin;
	

	

	
	
} // end function

/* show addresses -- for award and module page */






	function displayAddInit() {
		


	
		var mainbody = document.getElementById("content-col-2");
		var pagelinks = mainbody.getElementsByTagName("a");
		var pagedivs = mainbody.getElementsByTagName("div");
		var sublink;
		
		
		// assign ids to divs automatically
		for (var i=0; i <= pagedivs.length-1; i++) {
			
			
			
			divClass = pagedivs[i].className;
			
			if (divClass == 'address') {
			
				
				
				pagedivs[i].setAttribute('id', 'add' + i);
				generatedId = pagedivs[i].getAttribute('id');
				
				

				// create anchors
				sublink = document.createElement("a");
				sublink.setAttribute("href", "#");
				var theid = "show"+i;
				sublink.setAttribute("id",theid);
				sublink.className="reflink-show";
				var topNodeId = document.getElementById(generatedId).id;
				sublink.setAttribute("href", "javascript:showhide('" + theid + "', '" +  topNodeId + "')");
				linkText = document.createTextNode("Show full address");
				sublink.appendChild(linkText);
				
				// Oddly, IE counts the element numbers differently from other browsers
				if ( (browser=='ie') || (browser == 'ie7')) {
					
					var genId = document.getElementById(generatedId);
									
					
					if ( genId.childNodes.length  == 3) {
						
						linkdivholder = document.getElementById(generatedId).childNodes[1];
				
						
					} else if (genId.childNodes.length == 4) {
						
						linkdivholder = document.getElementById(generatedId).childNodes[2];

					
					}
					
					
					noOfNodes = document.getElementById(generatedId).childNodes.length;
					
					/*for (k=0; k <= parseFloat(noOfNodes)-1; k ++) {
						
						alert( 	document.getElementById(generatedId).childNodes[k].nodeName );
						
					}*/
					
					
					//alert( "class name=" + linkdivholder.className ); 
				} else {
					linkdivholder = document.getElementById(generatedId).childNodes[3];
				}
				
				linkdivholder.appendChild(sublink);

				
			
			
			}
		
		}
		

	
	}
	
	

	function showhide(linkid, divid) {
	
		
	
		var reflink = document.getElementById(linkid);
		var idtoshowhide;
		
		if ( (browser == 'ie') || (browser=='ie7')) {
				
				whichNode = document.getElementById(divid);
				//alert(whichNode.childNodes.length);
				
				if (whichNode.childNodes.length == 3) {
				
					idtoshowhide = whichNode.childNodes[2];
					
				} else if ( whichNode.childNodes.length == 4 ) {
				
					idtoshowhide = whichNode.childNodes[3];
					
				
				}
				
				//alert(idtoshowhide.className);
				
				
				
		} else {
			
				idtoshowhide = document.getElementById(divid).childNodes[5];
				//alert(idtoshowhide.getAttribute("class"));
				
		
		}		
		
		
		
		
		
		
		var isVisible = idtoshowhide.className;
		
		
		
		if ( isVisible == 'show-full-address') {
		
			idtoshowhide.className='hide-full-address';
			reflink.innerHTML = 'Hide full address';
			reflink.className='reflink-hide';
		
		} else if ( isVisible == 'hide-full-address' ) {
		
			reflink.innerHTML = 'Show full address';
			
			reflink.setAttribute("class", "reflink-show");
			idtoshowhide.className='show-full-address';
		
		}
	
	
	}

