// Setting Form Elements, Getting Querystring elements
// keithpursglove@orange.net
// (c) 2001

function clsSelectJS() {

	// TODO make multi Browser
	//this.create = _createNav4;

	this.tagAttr = "selectjs";
	this.optArray = null;
	this.nStart = 0;
	this.firstOptionUse = true;	
	this.firstOptionVal = -1;
	this.firstOptionText = "All";	
	this.filterJumpUse = false;
	this.filterJumpPage = "";
	this.filterJumpFieldName = "";
	this.filterJumpReloadSelect = "";
	this.filterJumpReloadPrefix = "";
	this.DataIsEncoded = false;
	this.form = "frmCriteria";
	this.name = "";
	
	this.size = 1;
	this.multiple = false;
	
	this.jumpFilter = _jumpFilter;
	this.jumpReload = _jumpReload;
	this.show = _writeSelectOptionsNumEx;
	this.selectOptionByValue = _selectOptionByValue;

	function _writeSelectOptionsNumEx() {
		document.write("<select name='" + this.tagAttr + "' ");
		if (this.size > 1) {
			document.write(" size='" + this.size + "' ");
		}
		if (this.multiple) {
			document.write(" multiple ");
		}		
		if (this.filterJumpUse) {
			if (this.filterJumpReloadSelect == "") {
				document.write(" onchange=\"" + this.name + ".jumpFilter();\"")
			}
			else {
				document.write(" onchange=\"" + this.name + ".jumpReload();\"")			
			}
		}
		document.write(">");
		if (this.firstOptionUse) {		
			document.write("<option value='" + this.firstOptionVal + "'>" + this.firstOptionText + "</option>");
		}
		if (this.optArray != null) {
			if (this.DataIsEncoded) {
				var sItems;
				for(var iLoop = 0; iLoop < this.optArray.length; iLoop++) {
					sItems = this.optArray[iLoop].split("|");
					document.write("<option value='" + sItems[1] + "'>" + unescape(sItems[2]) + "</option>");
				}
			}
			else {
				for(var iLoop = 0; iLoop < this.optArray.length; iLoop++) {
					document.write("<option value='" + (iLoop+1) + "'>" + this.optArray[iLoop] + "</option>");
				}
			}
		}
		document.write("</select>");
	}

	function _jumpFilter() {
		eval('var oElement = ' + this.form + '.' + this.tagAttr);		
		window.location=this.filterJumpPage+'?command=setcriteria&field='+ this.filterJump +'&value=' + oElement.value;
	}
	
	function _jumpReload() {
		eval("var oSelect = " + this.form + "." + this.tagAttr + ";");
		//alert("change: " + this.tagAttr + ", " + oSelect.name);
	
		var lIndex = oSelect.selectedIndex;
		var lValue = oSelect.options[lIndex].value;
		
		eval("var oArray = " + this.filterJumpReloadPrefix + (lValue-1) + ";");	
		eval("var oSelect2 = " + this.form + "." + this.filterJumpReloadSelect + ";");
		oSelect2.options.length = 0;
		
		if (this.DataIsEncoded) {
			var sItems;
			for(var iLoop = 0; iLoop < oArray.length; iLoop++) {
				sItems = oArray[iLoop].split("|");
				oSelect2.options[iLoop] = new Option(unescape(sItems[2]), sItems[1]);
			}
		}
		else {
			for(var iLoop = 0; iLoop < oArray.length; iLoop++) {
				oSelect2.options[iLoop] = new Option(oArray[iLoop], iLoop + 1);
			}
		}
	}
	
	function _selectOptionByValue(nOption) {
		eval('var theElement = ' + this.form + '.' + this.tagAttr);
		for (var iLoop = 0; iLoop < theElement.options.length; iLoop++) {
			if (theElement.options[iLoop].value == nOption) {
				theElement.options[iLoop].selected = true;
			}
			else {
				theElement.options[iLoop].selected = false;
			}
		}
	}	
}

/*	
function writeSelectOptionsEx(tagAttr, optArray, nStart, firstVal, firstText) {
var iLoop;
document.write("<select " + tagAttr + ">");
//alert(typeof firstVal);
switch(typeof firstVal) {
case 'string':
document.write("<option value='" + firstVal + "'>" + firstText + "</option>");
break;
case 'object':
for (iLoop = 0; iLoop < firstVal.length; iLoop++) {
document.write("<option value='" + firstVal[iLoop].value + "'>" + firstVal[iLoop].text + "</option>");
}
break;
default:
break;
}

if (optArray[0].value) {
for (iLoop = 0; iLoop < optArray.length; iLoop++) {
document.write("<option value='" + optArray[iLoop].value + "'>" + optArray[iLoop].text + "</option>");
}
}
else {
for(iLoop = 0; iLoop < optArray.length; iLoop++) {
document.write("<option value='" + optArray[iLoop] + "'>" + optArray[iLoop] + "</option>");
}
}
document.write("</select>");

}


*/
/*	// dont think used anywhere
function writeSelectOptions(frmElement, optArray) {
addSelectOptionsEx(frmElement, optArray, 0);
}
*/

/*
function writeSelectOptions(tagAttr, optArray) {
var iLoop;
document.write("<select " + tagAttr + ">");
//alert(typeof firstVal);
if (optArray[0].value) {
for (iLoop = 0; iLoop < optArray.length; iLoop++) {
document.write("<option value='" + optArray[iLoop].value + "'>" + optArray[iLoop].text + "</option>");
}
}
else {
for(iLoop = 0; iLoop < optArray.length; iLoop++) {
document.write("<option value='" + optArray[iLoop] + "'>" + optArray[iLoop] + "</option>");
}
}
document.write("</select>");
}
*/

/* END ::  WRITE SELECT TAG FOR OPERA COMPAT */

function writeArrayAsCommaList(optArray) {
var iLoop;
for(iLoop = 0; iLoop < optArray.length - 1; iLoop++) {
document.write(optArray[iLoop] + ", ");
}
document.write(optArray[iLoop+1] + ".");
}

//////////////////

function getQueryField(strField) {
var nPosField = location.search.indexOf(strField + "=");
if (nPosField < 1) {
return "";
}
var nPosAmp = location.search.indexOf("&", nPosField);
if (nPosAmp < 1) {
nPosAmp = location.search.length;
}
return location.search.substring(nPosField+strField.length+1, nPosAmp);
}
function arraySelectItem(strValue, strText) {
this.value = strValue;
this.text = strText;
}
