function getElement(id) {
	if (document.all)
		return document.all[id];	
	else if (document.getElementById)
		return document.getElementById(id);

	return null;
}

function OpenWindow(Loc, Name) {
	var opts;

	if (arguments[2]) {
		opts = arguments[2];
	} else {
		opts = "width=640, height=480, left=50, top=0, resizable=yes, scrollbars=yes";
	}

	var wndh = window.open(Loc, Name, opts);
	wndh.focus();
}

Combobox = {
	add : function(id, name, value, selected) {
		Combobox.insert(id, getElement(id).options.length, name, value, selected);
		return getElement(id).options.length;
	},

	insert : function(id, pos, name, value, selected) {
		var newOption = new Option(name, value, selected, selected);
		getElement(id).options[pos] = newOption;
	},

	findByName : function(id, name) {
		var cbObj = getElement(id);
		
		for(var i=0; i<cbObj.options.length; ++i) {
			if (cbObj.options[i].text.indexOf(name) > -1)
				return i;
			
		}

		return -1;
	},

	findByValue : function(id, value) {
		var cbObj = getElement(id);
		
		for(var i=0; i<cbObj.options.length; ++i) {
			if (cbObj.options[i].value == value)
				return i;
		}

		return -1;
	},

	getValue : function(id, pos) {
		var cbObj = getElement(id);

		if ( (pos < cbObj.options.length) && (pos > -1) )
			return cbObj.options[pos].value;
		else
			return null;
	},

	getName : function(id, pos) {
		var cbObj = getElement(id);

		if ( (pos < cbObj.options.length) && (pos > -1) )
			return cbObj.options[pos].text;
		else
			return null;
	},

	getSelectedValue : function(id) {
		return Combobox.getValue(id, getElement(id).selectedIndex);
	},
	
	getSelectedIndex : function(id) {
		return getElement(id).selectedIndex;
	},

	setNameAndValue : function(id, pos, newName, newValue) {
		var cbObj = getElement(id);

		if ( (pos < cbObj.options.length) && (pos > -1) ) {
			cbObj.options[pos].value = newValue;
			cbObj.options[pos].text = newName;
		}
	},
	
	setSelectedIndex : function(id, newIndex) {
		var cbObj = getElement(id);
		
		if (! cbObj[newIndex])
			return;
			
		cbObj[newIndex].selected = true;
		cbObj.selectedIndex = newIndex;
	},

	selectAll : function(id, on) {
		var cbObj = getElement(id);
		
		var i=cbObj.options.length-1;
		while (i >= 0)
			cbObj.options[i--].selected = on;
	},
	
	setValue : function(id, pos, newValue) {
		var cbObj = getElement(id);

		if ( (pos < cbObj.options.length) && (pos > -1) )
			cbObj.options[pos].value = newValue;
	},

	setName : function(id, pos, newName) {
		var cbObj = getElement(id);

		if ( (pos < cbObj.options.length) && (pos > -1) )
			cbObj.options[pos].text = newName;
	},
	
	remove : function(id, value) {
		var pos = Combobox.findByValue(id, value);
		
		if (pos > -1)
			getElement(id).options[pos] = null;
	},
	
	removeIndex : function(id, index) {
		var cbObj = getElement(id);
		if (index > -1) {
			cbObj.options[index] = null;
		}
	},
	
	removeAll : function(id) {
		var cbObj = getElement(id);
		
		var i=cbObj.options.length-1;
		while (i >= 0) {
			cbObj.options[i] = null;			
			i--;
		}
                
	},

	size : function(id) {
		return getElement(id).options.length;
	}
}

function toggleDivVis(DivName) {
    getElement(DivName).style.display = (getElement(DivName).style.display == "none") ? "block" : "none";
}

var DivVisTabs = new Array(); // map of tab containers, one active tab each
function DivVisShowTab(key, id) {
	var index = -1;
	for (var i=0; i<DivVisTabs.length; ++i) {
		if (DivVisTabs[i][0] == key)
			index = i;
	}
	if (index == -1) { // no container for key yet, create one
		index = DivVisTabs.length;
		DivVisTabs[index] = new Array(key, "");
	}

	// hide old tab contents, show new one
	if (DivVisTabs[index][1] != "") {
		getElement(DivVisTabs[index][1]).style.display = "none"; // content div
		getElement(DivVisTabs[index][1]+"_tab").className = "";  // tab itself 
	}
	getElement(id).style.display = "block";
	getElement(id+"_tab").className = "active";
	DivVisTabs[index][1] = id; // remember selection
}

/* JS hilighting of html elements
 * courtesy of IE which supports CSS:hover only for <a> tags */
function hoverSetClass(element, newClassName) {
	if (!element)
		return;
	element.className = newClassName;
}
