# Surgeweb plain HTML interface
# Util level stuff much shared between html and ajax interfaces

var U=undefined;

function fld_expand(e,dummy,el){
//	if (!e) e = window.event
	if(!el){
		var t = target(e);
		var el = ancestor_by_tag(t,'li');
	}
	var v_old,v_new;
	if (class_contains(el,"open")){
		v_old="open";v_new="closed";
	}else{
		v_old="closed";v_new="open";
	}
	class_remove(el,v_old);
	class_add(el,v_new);
}
function target(e){
	var src;
	if(e.target){
		src = e.target;
	}else if(e.srcElement){
		src = e.srcElement;
	}
	if (src.nodeType==3) src = src.parentNode;
	return src;
}
# Find parent of an object
function pe(e){
	return e.parentNode?e.parentNode:e.parentElement;
}



# ***********
function dge(a) { return document.getElementById(a); }
function ClientHeight(){
	var y=500
	if (self.innerHeight)
		y = self.innerHeight
	else if (document.documentElement && document.documentElement.clientHeight)
		y = document.documentElement.clientHeight
	else if (document.body)
		y = document.body.clientHeight
	return y
}
var CLASSNAME = "className";

function class_remove(o,name){
	o[CLASSNAME] = o[CLASSNAME].replace(' '+name,'').replace(name,'');
}
function class_add(o,name){
    var val = o[CLASSNAME];
	if (val.indexOf(name) == -1) 
		o[CLASSNAME] += (val?' ':'')+name;
}
function class_contains(o,name){
    return (o[CLASSNAME].indexOf(name) != -1);
}
function class_set(o,name){
    o[CLASSNAME]=name;
}

# ***************
function open_popup(cmd,nowarn)
{
	var new_win = window.open(cgibase+cmd,"","left=100,right=100,dependent=1,hotkeys=0,menubar=0,personalbar=0,resizable=1,scrollbars=1,width=700,height=500,status=0,titlebar=0,toolbar=1,z-lock=1");	
	if (!new_win) alert("Popup could not be opened. If you have a popup blocker please allow popups.");
	return new_win;
}


function stopEvent(e) {
	if(!e) alert('invalid stopEvent call');
	
	//e.cancelBubble is supported by IE - this will kill the bubbling process.
	e.cancelBubble = true;
	e.returnValue = false;

	//e.stopPropagation works only in Firefox.
	if (e.stopPropagation) {
		e.stopPropagation();
		e.preventDefault();
	}
#	return false;
}
