// JavaScript Document
function linkAlert(URL){
}

function largeWarn(URL){
}

//This function resets the page width to a larger size if a table within the body is detected to be larger than the screen.
//This is to account for right-hand teasers existing on the same page as a table that is wider than the screen.
function setPageWidth() {
	var intCounter;
	var intLength;
	var intScreenWidth;
	var intTableWidth;
	var intNewWidth;
	var intNavWidth;
	var intLeftNavWidth;
	var intRightNavWidth;
	var intOldRightNavWidth;
	var intOldMainbodyWidth;
	var intTableTop;
	var intRightNavHeight;
	var intTableHeight;
	var objTables = document.getElementsByTagName("table");
	
	intLength = objTables.length;
	intScreenWidth = document.body.clientWidth;
	intOldRightNavWidth = document.getElementById('rght').clientWidth
	intOldMainBodyWidth = document.getElementById('mainbody').clientWidth
	
	//intScreenWidth holds the actual amount of pixels left over the middle content when you subtract the space
	//taken up by the left had navigation and the right hand teasers.
	intNavWidth = Math.round((intScreenWidth / 100) * 61);
	intLeftNavWidth = Math.round((intScreenWidth / 100) * 10);
	intRightNavWidth = Math.round((intScreenWidth / 100) * 35);
	intScreenWidth = Math.round((intScreenWidth / 100) * 39);
	intRightNavHeight = document.getElementById('rght').clientHeight + findPosY(document.getElementById('rght'))

	for (intCounter = 0; intCounter < intLength; intCounter++) {
	intTableHeight = findPosY(objTables[intCounter]);
	
		//Only resize the page for the first two tables, any others should be below the teasers by then and can be set to roughly the mainboyd width.
		if (intCounter == 0) {
			intTableWidth = objTables[intCounter].clientWidth;
			
			if (intTableWidth > intScreenWidth) {
				intNewWidth = intTableWidth + intNavWidth - intLeftNavWidth;
				document.getElementById('rght').style.width = intRightNavWidth + "px";
				document.getElementById('mainbody').style.width =  intNewWidth + "px";
				document.getElementById('header').style.width =  (document.getElementById('lft').clientWidth + document.getElementById('mainbody').clientWidth - 25) + "px";
				document.getElementById('headerback').style.width =  (document.getElementById('lft').clientWidth + document.getElementById('mainbody').clientWidth) + "px";
				
				intTableTop = findPosY(objTables[intCounter]);
				if (intTableTop > intRightNavHeight) {
					document.getElementById('rght').style.width = intOldRightNavWidth;
					document.getElementById('mainbody').style.width = intOldMainBodyWidth;
					document.getElementById('header').style.width =  intOldMainBodyWidth;
					document.getElementById('headerback').style.width =  intOldMainBodyWidth;
					objTables[intCounter].style.width = (intOldMainBodyWidth - 100);
				}
			}
			else if (intTableHeight > intRightNavHeight) {
				objTables[intCounter].style.width = (intOldMainBodyWidth - 100);
			}
		}
		else if (intTableHeight > intRightNavHeight) {
				objTables[intCounter].style.width = (intOldMainBodyWidth - 100);
		}
	}
}
//Find the position of the object, adding any parent element offsets to find the total offset from the tops of the page.
function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/* CLEARS SEARCH FIELD */
function clearSearchField() {
          if (document.searchBox.searchText.value == "Enter search terms") {
            document.searchBox.searchText.value = "";
          }
        }
		
function checkSubmit() {
	if ((document.searchBox.searchText.value == "Enter search terms") || (document.searchBox.searchText.value == "")) {
		alert("You have not entered a search term.");
		document.searchBox.searchText.value = "";
		document.searchBox.searchText.focus();
		return false;
	}
	return true;
}
