/**
 * This function will change the visibility of an element to visible.
 * It is designed to support as many browsers as possible, 
 * but .... 
 * @param elementID a String containing the ID of the element. Required.
 */
function showElement(elementId, displayType){
	var theRef = getRefToElement(elementId);
	if ( !theRef ){
		alert("Duff browser - can't do anything");
		return;
	}
	
	if (theRef.style){
		// DOM object capable
		if (theRef.style.display == '' || theRef.style.display == 'none'){
			if (typeof(displayType) != 'undefined'){
				theRef.style.display = displayType;
			}
		}
		theRef.style.visibility = 'visible';
	}else{
		// Layers browser
		theRef.visibility = 'show';
	}
}

/**
 * This function will change the visibility of an element to hidden.
 * It is designed to support as many browsers as possible, 
 * but .... 
 * @param elementID a String containing the ID of the element. Required.
 */
function hideElement(elementId){
	var theRef = getRefToElement(elementId);
	if ( !theRef ){
		// Duff browser - can't do anything.
		return;
	}
	
	if (theRef.style){
		// DOM object capable
		if (theRef.style.display && theRef.style.display != 'none'){
			theRef.style.display = 'none';
		}
		theRef.style.visibility = 'hidden';
	}else{
		// Layers browser
		theRef.visibility = 'hide';
	}
}
/**
 * This function will return an element using the id of the <el> tag. It is 
 * designed to support all kinds of browsers, but... we cannot do everything.
 * @param elementID a String containing the ID of the element. Required.
 * @param oDoc a "document" element. Not required, default is the current document.
 *                Used for layers backward compatibility.
 * @returns A reference to the element, false if none can be found, or the object 
 * 			supplied if this was not a string.
 */
function getRefToElement(elementID,oDoc) {
	if (typeof(elementID)=='string'){
		if( document.getElementById ) {
			// DOM supported
			return document.getElementById(elementID); 
		}
	
		if( document.all ) {
			// proprietary DOM supported
			return document.all[elementID]; 
		}
	
		if( !oDoc ) { 
			oDoc = document; 
		}
	
		if( document.layers ) {
			// layers support.
			if( oDoc.layers[elementID] ) { 
				return oDoc.layers[elementID]; 
			} else {
				//repeatedly run through all child layers
				for( x = 0, y; !y && x < oDoc.layers.length; x++ ) {
					//on success, return that layer, else return nothing
					y = getRefToElement(elementID,oDoc.layers[x].document); 
				}
				return y; 
			} 
		}
	}
	return elementID;
}

function findElementPosition(oEl){
	if ( !oEl || (!oEl.offsetParent && !oEl.x)){
		return [10000, 10000];
	}
	
	if ( typeof( oEl.offsetParent ) != 'undefined' ){
		for( var posX = 0, posY = 0; oEl; oEl = oEl.offsetParent){
			posX += oEl.offsetLeft;
			posY += oEl.offsetTop;
		}
		return [posX, posY];
	}
	if ( typeof( oEl.x ) != 'undefined' ){
		return [oEl.x, oEl.y]
	}
	return [10000, 10000];
}

function findMousePosition(evt){
	if (!evt){
		if (window.event){
			evt = window.event;
		}else{
			return;
		}
	}
	var Xcoord;
	var Ycoord;
	if ( typeof( evt.pageX) == 'number' ){
		// Most browsers 
		Xcoord = evt.pageX;
		Ycoord = evt.pageY;
	}else if ( typeof (evt.clientX) == 'number'){
		Xcoord = evt.clientX;
		Ycoord = evt.clientY;
		var badOldBrowser = (window.navigator.userAgent.indexOf( 'Opera' ) + 1) ||
			(window.ScriptEngine && ScriptEngine().indexOf( 'InScript' ) + 1) ||
			(navigator.vendor == 'KDE');
			
		if (!badOldBrowser){
			if (document.body && ( document.body.scrollLeft || document.body.scrollTop)){
				// ie 4, 5, 6
				Xcoord += document.body.scrollLeft;
				Ycoord += document.body.scrollTop;
			}else if ( document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop )) {
				Xcoord += document.documentElement.scrollLeft;
				Ycoord += document.documentElement.scrollTop;
			}
		}
	}else{
		return;
	}
	return [Xcoord, Ycoord];
}
