function CheckTextBoxAgainstMaxLength(txtBox, size)
{
	if (txtBox.value.length >= size)
	{
		alert("Entry can't be longer than " + size + " characters");
		return false;
	}
	else
		return true;
}

function SetDivHeightForSearchResults(tableID, divID, numberOfRowsToDisplay, heightOfdiv)
{		
		var numberOfRows = document.getElementById(tableID).getElementsByTagName("TR").length;
		
		if(numberOfRows == 0)
		{
			document.getElementById(divID).style.display = "none";
		}
		else if(numberOfRows < numberOfRowsToDisplay)
		{
			var heightToDisplay = numberOfRows * heightOfdiv / numberOfRowsToDisplay;
			document.getElementById("divDisplay").style.height = heightToDisplay + "px";
		}
		else
		{
			document.getElementById("divDisplay").style.height = heightOfdiv + "px";
		}
}

var submitted = false;

function CheckSubmission()
{
	if(!submitted)
	{
		submitted = true;
		return true;
	}
	else
	{
		return false;
	}
}

function BookMarkPage(bookmarkURL, bookMarkTitle)
{
	if (document.all)
		window.external.AddFavorite(bookmarkURL, bookMarkTitle);
}

function DisplayHelp(pagename)
{
	var page;
	page = location.href;
	DisplayCentreWindow(900, 450, 'help.aspx?helpPage=' + page.substr(page.lastIndexOf("/") + 1));
}

function DisplayCentreWindow(width, height, url)
{
	var horizontalPosition = (screen.width - width)/2;
	var verticalPosition = (screen.height - height)/2;
	if (horizontalPosition < 0) horizontalPosition = 0;
	if (verticalPosition < 0) verticalPosition = 0;
	
	var windowprops = "height=" + height +",width=" + width + ",top=" + verticalPosition + ",left=" + horizontalPosition + ",location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=no,status=yes";
	window.open(url, target='_new', windowprops);
}

function toggler(ID)
{
	myID = document.getElementById(ID); 
	myID.style.display = (myID.style.display == 'block') ? 'none' : 'block';
}

function toggleWithImage(ID, imageID, firstImage, secondImage)
{
	toggler(ID);
	myImage = document.getElementById(imageID);
	
	tidySrc = myImage.src.substr(myImage.src.lastIndexOf("/", myImage.src.lastIndexOf("/") - 1) + 1);
	
	myImage.src = (tidySrc == secondImage) ? firstImage : secondImage;
}