function showurlin(url, dest, options) {
	switch(dest) {
	case 'popup':
		window.open(url, 'popup', options);
		break;
	case 'original':
    	if (window.opener && window.opener.location)
			window.opener.location.href = url;
		break;
	default:
	}
}

function imgSwap(obj, newsrc) {
	obj.oldsrc = obj.src;
	obj.src = newsrc;
	return true;
}

function imgRestore(obj) {
	if(obj.oldsrc) obj.src = obj.oldsrc;
	return true;
}

//** IE Mac compatibility code (prototypes ROCK!) **
if(typeof Array.prototype.push=='undefined')
  Array.prototype.push=function(){
    var i=0;
    b=this.length,a=arguments;
    for(i;i<a.length;i++)this[b+i]=a[i];
    return this.length
  };
// Utility Functions
window.loadTasks = new Array();
window.unloadTasks = new Array();
window.onload = driverInit;
window.onunload = driverFinish;

function registerLoadTask(fn) {
	window.loadTasks.push(fn);
}

function registerUnloadTask(fn) {
	window.unloadTasks.push(fn);
}

function driverInit() {
	for(var i in window.loadTasks) {
		if(typeof window.loadTasks[i] == 'string')
			eval(window.loadTasks[i]);
	}
}

function driverFinish() {
	for(var i in window.unloadTasks) {
		eval(window.unloadTasks[i]);
	}
}
var menuShowDelay = 200;
var menuHideDelay = 500;
window.visibleMenus = new Array();

function menuMouseOver(node) {
	var menu = findMenu(node);
	if(!menu) return;
	if(menu.showPending) {window.clearTimeout(menu.showPending); menu.showPending = false;}
	if(menu.hidePending) {window.clearTimeout(menu.hidePending); menu.hidePending = false;}
	if(menu.style.visibility == 'visible') return;
	menu.showPending = setMenuShowTimeout(menu, menuShowDelay);
}

function menuMouseOut(node) {
	var menu = findMenu(node);
	if(!menu) return;
	if(menu.showPending) {window.clearTimeout(menu.showPending); menu.hidePending = false;}
	if(menu.hidePending) {window.clearTimeout(menu.hidePending); menu.showPending = false;}
	if(menu.style.visibility == 'hidden') return;
	menu.hidePending = setMenuHideTimeout(menu, menuHideDelay);
}

function findMenu(node) {
	if(typeof node.getElementsByTagName != 'undefined') {
		var children = node.getElementsByTagName('DIV');
		if(children)
			return children[0];
		else
			return null;
	}
	else {
		var children = node.childNodes;
		for(var i=0; i < children.length; i++)
			if (children[i].nodeName == 'DIV')
				return children[i];
		return null;
	}
}


function showElement(object_id){
  var object = document.getElementById(object_id);
  return (object.style.visibility='visible');
}

function hideElement(object_id){
  var object = document.getElementById(object_id);
  return (object.style.visibility='hidden');
}

function setMenuShowTimeout(object, delay) {
    return setTimeout('showMenu("'+object.id+'")', delay);
}

function setMenuHideTimeout(object, delay) {
    return setTimeout('hideMenu("'+object.id+'")', delay);
}

/*
 * New Stuff
 */

function hideMenusNow() {
	var vis = window.visibleMenus;
	var newvis = new Array();
	var i = 0;
	for(i=0; i < vis.length; i++) {
		var menu = vis[i];
		if(menu.hidePending) {
			window.clearTimeout(menu.hidePending);
			menu.hidePending = false;
			menu.style.visibility = 'hidden';
		}
		else {
			newvis.push(vis[i]);
		}
	}
	window.visibleMenus = newvis;
	if (newvis.length == 0) showSelectControls(document.body)
}

function hideMenu(id) {
	var menu = document.getElementById(id);
	if(!menu) return;
	var vis = window.visibleMenus;
	var newvis = new Array();
	menu.style.visibility = 'hidden';
	for(var i = 0; i < vis.length; i++) {
		if(vis[i] != menu) {
			newvis.push(vis[i]);
		}
	}
	window.visibleMenus = newvis;
	if (newvis.length == 0) showSelectControls(document.body)
}

function showMenu(id) {
	var menu = document.getElementById(id);
	if(!menu) return;
	hideMenusNow();
	menu.style.visibility = 'visible';
	if(window.visibleMenus.length == 0) hideSelectControls(document.body);
	window.visibleMenus.push(menu);
}

function hideSelectControls(root) {
	var selectControls = root.getElementsByTagName('SELECT');
	for(var i = 0 ; i < selectControls.length; i++) {
		selectControls[i].style.visibility = 'hidden';
		selectControls[i]._hiddenByRefract = true;
	}
}

function showSelectControls(root) {
	var selectControls = root.getElementsByTagName('SELECT');
	for(var i = 0 ; i < selectControls.length; i++) {
		if(selectControls[i]._hiddenByRefract) selectControls[i].style.visibility = 'visible';
	}
}

