function toggleVisibility(whichLayer)
{
	if (document.getElementById) 
	{
		// this is the way the standards work
		var element = document.getElementById(whichLayer);
		if (element.style.display == "block") 
			element.style.display = "none";
		else
			element.style.display = "block";
	}
	else if (document.all) 
	{
		// this is the way old msie versions work
		var element = document.all[whichlayer];
		if (element.style.display == "none")
			element.style.display = "block";
		else
			element.style.display = "none";
	}
	else if (document.layers) {
	// this is the way nn4 works
		if (document.layers[whichLayer].display == "none") {
			document.layers[whichLayer].display = "block";
			}
		else {
			document.layers[whichLayer].display = "none";
			}
	}
}

function toggleInlineVisibility(whichLayer)
{
	var element = document.getElementById(whichLayer)
	if (element.style.display == "none")
		element.style.display = "inline";
	else
		element.style.display = "none";
}
	


function makeVisible(whichLayer) 
{
	if (document.getElementById) {
	// this is the way the standards work
			document.getElementById(whichLayer).style.display = "block";
	}
	else if (document.all) {
	// this is the way old msie versions work
			document.all[whichlayer].style.display = "block";
	}
	else if (document.layers) {
	// this is the way nn4 works
			document.layers[whichLayer].display = "block";
	}
}

function makeInvisible(whichLayer) 
{
	if (document.getElementById) {
	// this is the way the standards work
			document.getElementById(whichLayer).style.display = "none";
	}
	else if (document.all) {
	// this is the way old msie versions work
			document.all[whichlayer].style.display = "none";
	}
	else if (document.layers) {
	// this is the way nn4 works
			document.layers[whichLayer].display = "hidden";
	}
}

function setElementOpacity(element, opacity)
{
	if(typeof(element.style.MozOpacity)=='string')
		element.style.MozOpacity=opacity;
	else if(typeof(element.style.filter)=='string')
		element.style.filter='alpha(opacity:'+opacity*100+')';
	else if(typeof(element.style.KHTMLOpacity)=='string')
		element.style.KHTMLOpacity=opacity;
	else if(typeof(element.style.opacity)=='string')
		element.style.opacity=opacity;
}

// The functions findPosX, findPosY, positionLayer and findObject were taken from http://www.quirksmode.org/js/findpos.html#
//	It accurately finds the absolute position of an element
function getPosition(obj)
{
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent)
	{
		do
		{
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
		while (obj = obj.offsetParent)
	}

	return [curleft,curtop];
}

// Get the scroll position of the browser
//
function getBrowserScroll()
{
	var scrollX = 0;
	var scrollY = 0;
	if (window.pageYOffset)
	{
		scrollX = window.pageXOffset;
		scrollY = window.pageYOffset;
	}
	else if (document.body.parentElement)
	{
		scrollX = document.body.parentElement.scrollLeft;
		scrollY = document.body.parentElement.scrollTop;
	}
	return [scrollX, scrollY];
}


// Function to place an absolute-positioned DIV
function positionLayer(obj, lyr, offset_x, offset_y)
{
        var newX = findPosX(obj) + offset_x;
        var newY = findPosY(obj) + offset_y + 5+2 * obj.style.height;
        var x = new findObject(lyr);
        x.style.top = newY + 'px';
        x.style.left = newX + 'px';
}

// Get an object by name, method depends on browser
function findObject(name)
{
	if (document.getElementById) {
	 	this.obj = document.getElementById(name);
	 	this.style = document.getElementById(name).style;
		}
	else if (document.all) {
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers) {
			this.obj = document.layers[name];
			this.style = document.layers[name];
			}
}

function findHeight(object)
{
	var x = new findObject(object);
	return object.style.height;
}


// Get the window height
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}



// Footer code from: http://alistapart.com/articles/footers
//
// Set the footer
function positionElementAtBottom(element) {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('content').offsetHeight;
			var footerElement = document.getElementById(element);
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
			}
			else {
				footerElement.style.top = '0px';
			}
		}
	}
}

// Set an element to the middle of the page
function positionElementInMiddle(element) {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentElement = document.getElementById(element);
			var contentHeight = contentElement.offsetHeight;
			if (windowHeight - contentHeight > 0) {
				contentElement.style.position = 'relative';
				contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
			}
			else {
				contentElement.style.position = 'static';
			}
		}
	}
}

function limitText(limitField, limitCount, limitNum) 
{
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
