String.prototype.trim = trim;
function trim()
{
	var re = /^\s*/ig;
	var re2 = /\s*$/ig;
	var tmp = new String(this);
	tmp = tmp.replace(re, "");
	return new String(tmp.replace(re2,""));
}
function addOptionToCombo(oCbo,oOption)
{
	if("object" != typeof oCbo) return false;
	if("object" != typeof oOption) return false;
	try {
		var oNewOpt = document.createElement("option");
		oNewOpt.text = oOption["text"].toString();
		oNewOpt.value = oOption["value"].toString();
		oNewOpt.selected = true;
		oCbo.options.add(oNewOpt);
		return true;
	} catch(e) { e.report(); return false; }
}
function getOptionFromCombo(oCbo, iSelectedIndex)
{
	if("object" != typeof oCbo) return null;
	if(isNaN( parseInt( iSelectedIndex ) )) return null;
	try {
		var oOption = new Object();
		oOption["text"] = oCbo.options[iSelectedIndex].text;
		oOption["value"] = oCbo.options[iSelectedIndex].value;
		return oOption;
	} catch(e) { e.report(); return null; }
}
function removeOptionFromCombo(oCbo, iSelectedIndex)
{
	if("object" != typeof oCbo) return false;
	if(isNaN( parseInt( iSelectedIndex ) )) return false;
	try {
		oCbo.options.remove(iSelectedIndex);
		return true;	
	} catch(e) { e.report(); return false; }
}
function swapCombo(oCboFrom, iSelectedIndexFrom, oCboTo)
{
	if("object" != typeof oCboFrom) return false;
	if(isNaN( parseInt( iSelectedIndexFrom ) )) return false;
	if("object" != typeof oCboTo) return false;
	try { 
		var oOption = getOptionFromCombo(oCboFrom, iSelectedIndexFrom);
		if(oOption == null) return false;
		addOptionToCombo(oCboTo,oOption);
		removeOptionFromCombo(oCboFrom, iSelectedIndexFrom);
	} catch(e) { e.report(); return false; }
	
}
var sFind = "";
function findInCombo(oCbo)
{
	if("object" != typeof oCbo) return false;
	var opts = oCbo.options;
	var len = opts.length;
	var sTxt = prompt("Enter text to search for:",sFind);
	if(sTxt == null) return false;
	if(sTxt.trim() == "") return false;
	var re = new RegExp(sTxt.toLowerCase()+"\\S*\\s*");
	re.ignoreCase = true;
	re.global = true;
	var si = (oCbo.selectedIndex <= 0) ? 0 : (parseInt(oCbo.selectedIndex) + 1);
	for(var i = si; i < len; i++)
	{
		if(opts[i].text.toLowerCase().match(re))
		{
			oCbo.selectedIndex=i;
			sFind = sTxt.trim();
			return;
		}
	}
	for(var i = 0; i < si; i++)
	{
		if(opts[i].text.toLowerCase().match(re))
		{
			oCbo.selectedIndex=i;
			sFind = sTxt.trim();
			return;
		}
	}
	alert(sTxt + " could not be found!");
}
// adds to cboname a value
function addToCombo(cboName,optVal,optText)
{
	try {
		var cbo = document.getElementsByName(cboName)[0];
		if("object" != typeof cbo) return;
		if(cbo.tagName != "SELECT") return;
		var opt = document.createElement("option");
		opt.value = optVal;
		opt.text = optText;
		opt.selected = true;
		cbo.options.add(opt); // The new way
		//cbo.options[cbo.options.length] = opt; // The old way
	} catch(e) { e.report(); return false; }
	return true;
}
function showCombos(boolShow)
{
	try {
		var cbos = document.getElementsByTagName("select");
		var d = (boolShow == true) ? "visible" : "hidden";
		for(var i = 0; i < cbos.length; i++) { cbos[i].style.visibility=d; }
	} catch(e) { e.report(); }
}
