//==========================================================================================//
// Begin HTML ListBox (<SELECT> control) General code
//==========================================================================================//
function Selection(key1,key2,value,value_type,caption) {
	this.key1=key1;
	this.key2=key2;
	this.value=value;
	this.value_type=value_type;
	this.caption=caption;
}
function lbToggleSelections(list,sel) {
	for(var i=list.length-1;i>=0;i--) list.options[i].selected=sel;
	return true;
}
function lbToggleMatches(list,match,source,idx,sel) {
	var src,ary,targ,val,count=0; //SEM 9/16/2005
	for(var i=list.length-1;i>=0;i--){
		src=source.toLowerCase();
		targ=(src=="text")?list.options[i].text:list.options[i].value;
		val=targ;
		if(src=="value"){ary=targ.split("|");val=ary[idx];}
		if(val==match){list.options[i].selected=sel;count++;} //SEM 9/16/2005
	}
	return count; //SEM 9/16/2005
}
//==========================================================================================//
// Begin CSUWebList Filter code
//==========================================================================================//
function FilterTarget(list,targAtt,targIdx,srcAtt,srcIdx) {
	this.targetList=list;
	this.targetAttribute=targAtt;
	this.targetIndex=targIdx;
	this.sourceAttribute=srcAtt;
	this.sourceIndex=srcIdx;
}
function CSUWebList(name,style,mode) {
	this.length=0;
	this.listName=name;
	this.listStyle=(!!style)?style.toLowerCase():"htmlselect";
	this.filters=new Array;
	this.filterTargets=new Array;
	this.filterMode="additive";
	this.numSelections=0;
	this.selectionMode=(!!mode)?mode.toLowerCase():"multiple";
}
CSUWebList.prototype.setFilterMode=function(mode){this.filterMode=mode;}
CSUWebList.prototype.addFilter=function(weblist){this.filters[this.filters.length]=weblist;}
CSUWebList.prototype.addFilterTarget = function(list,targAtt,targIdx,srcAtt,srcIdx) {
	var srcAttribute=(!srcAtt)?"value":srcAtt;
	var srcIndex=(isNumeric(srcIdx))?srcIdx:0;
	this.filterTargets[this.filterTargets.length] = new FilterTarget(list,targAtt,targIdx,srcAttribute,srcIndex);
	list.addFilter(this);
}
CSUWebList.prototype.getPageElement = function (name,win) {
	var elm,doc=(!win)?self.document:win.document;
	if(doc.getElementById)elm=doc.getElementById(name);
	else if(doc.all) elm=doc.all[name];
	else if (doc.layers){
		for (var i=0,imax=doc.forms[0].length;i<imax;i++)
			if (doc.forms[0].elements[i].name==name)
				{elm=doc.forms[0].elements[i];break;}
	}
	return elm;
}
CSUWebList.prototype.toggleSelections=function(selected){
	var list=this.getPageElement(this.listName);
	if(!list)return false;
	for(var i=list.length-1;i>=0;i--)list.options[i].selected=selected;
}
CSUWebList.prototype.applyFilters=function(selected){for(var i=0,iMax=this.filters.length;i<iMax;i++)this.filters[i].applyAsFilter(selected);}
CSUWebList.prototype.clearFilters=function(){for(var i=this.filters.length-1;i>=0;i--)this.filters[i].toggleSelections(false);}
CSUWebList.prototype.applyAsFilter = function(selected, aSiblingFilters) {
	var filterList=this.getPageElement(this.listName);
	if(!filterList)return false;
	var i,imax,j,jmax,ary=[],val,filterTarget,filterTargetHtmlList,count;
	for (i=0,imax=this.filterTargets.length;i<imax;i++) {
		filterTarget=this.filterTargets[i];
		filterTargetHtmlList=this.getPageElement(filterTarget.targetList.listName); //SEM 9/16/2005
		// Clear "target" list and "sibling" list selections if in "exclusive" mode.
		if (filterTarget.targetList.filterMode == "exclusive") {
			// Clear selections in the target list.
			lbToggleSelections(this.getPageElement(filterTarget.targetList.listName),false);
			// Clear selections in any "sibling" lists (which are specified by the aSiblingFilters argument).
			for (j=1,jmax=arguments.length;j<jmax;j++)
				lbToggleSelections(this.getPageElement(arguments[j]),false);
		}
		// Set selections in the target list(s) based upon the selection in the filter list.
		for (j=0,jmax=filterList.length,count=0;j<jmax;j++)
			if (filterList.options[j].selected==true) {
				val=filterList.options[j].value;
				if (filterTarget.sourceAttribute=="value") {
					ary=filterList.options[j].value.split("|");
					val=ary[filterTarget.sourceIndex];
				}
				count+=lbToggleMatches(this.getPageElement(filterTarget.targetList.listName),val,filterTarget.targetAttribute,filterTarget.targetIndex,selected) //SEM 9/16/2005
			}
		if((!!filterTargetHtmlList)&&(!!filterTargetHtmlList.onchange)){filterTargetHtmlList.onchange();} //SEM 9/16/2005
	}
	
	return false;
}
//*********************************************************************************************//
// BEGIN: Revised for *all* list types.
//*********************************************************************************************//
CSUWebList.prototype.getItemToken=function(str,idx){return str.split("|")[idx];}
CSUWebList.prototype.appendListItemToArray=function(idx,val,ary,unique){
	var itm=(idx==null||idx<0)?val:this.getItemToken(val,idx),fnd=0;
	if(unique){
		for(var i=ary.length-1;i>=0;i--)if(ary[i]==itm){fnd=1;break;}
		if(!fnd)ary[ary.length]=itm;
	}
	else{ary[ary.length]=itm;}
	return true;
}
CSUWebList.prototype.getNumSelections=function(){
	switch(this.listStyle.toLowerCase()) {
		case "htmlselect": return this.getNumSelections_HTMLSelect();
		case "htmltable": return this.getNumSelections_HTMLTable();
		default:return 0;
	}
}
CSUWebList.prototype.getNumSelections_HTMLSelect=function(){
	var list=getPageElement(this.listName),count=0;
	if(!list)return 0;
	for(var i=0,imax=list.length;i<imax;i++)if(list.options[i].selected)count++;
	this.numSelections=count;
	return count;
}
CSUWebList.prototype.getNumSelections_HTMLTable=function() {
	if(this.selectionMode=="none")return "";
	var itm,count=0,pre=(this.selectionMode=="multipleselect")?"cb":"rb";
	for(var i=0,imax=document.forms[0].elements.length;i<imax;i++){
		itm=document.forms[0].elements[i];
		if((itm.id.substring(0,this.listName.length+2)==(pre+this.listName))&&(itm.checked))count++;
	}
	this.numSelections=count;
	return count;
}
CSUWebList.prototype.getSelections_HTMLSelect=function(idx,unique){
	var list=getPageElement(this.listName);
	if(!list)return null;
	var ary=[],uniq=(arguments.length==2)?unique:false;
	for(var i=0,imax=list.length;i<imax;i++)
		if(list.options[i].selected)this.appendListItemToArray(idx,list.options[i].value,ary,uniq);
	this.numSelections=ary.length;
	return(ary.length>0?ary.toString():"");
}
CSUWebList.prototype.getSelections_HTMLTable=function(idx,unique) {
	if(this.selectionMode=="none")return "";
	var itm,ary=[],uniq=(arguments.length==2)?unique:false,pre=(this.selectionMode=="multipleselect")?"cb":"rb";
	for(var i=0,imax=document.forms[0].elements.length;i<imax;i++){
		itm=document.forms[0].elements[i];
		if(itm.id.substring(0,this.listName.length+2)==(pre+this.listName))
			if(itm.checked)this.appendListItemToArray(idx,itm.value,ary,uniq);
	}
	this.numSelections=ary.length;
	return(ary.length>0?ary.toString():"");
}
CSUWebList.prototype.getSelections=function(idx,unique) {
	switch(this.listStyle.toLowerCase()) {
		case "htmlselect": return this.getSelections_HTMLSelect(idx,unique);
		case "htmltable": return this.getSelections_HTMLTable(idx,unique);
		default:return "";
	}
}
CSUWebList.prototype.getSelectionsAsArray=function(idx,unique) {
	var str=this.getSelections(idx,unique);
	return (!!str)?str.split(","):null;
}
//*********************************************************************************************//
// END: Revised for *all* list types.
//*********************************************************************************************//
function CSUWebList_Resize(listname,inc){var sz=this.getPageElement(listname).size+inc;if(sz>0)this.getPageElement(listname).size=sz;}
//==========================================================================================//
// End CSUWebList Filter code
//==========================================================================================//
//==========================================================================================//
// Begin CSUWebList Sorting code
//==========================================================================================//
function Trim(str){return str.replace(/^\xA0*|\xA0*$/g,"");}
function wlSortByDate(a,b){
	var aval=(a[0].length==0)?Date.parse("1/1/1900"):Date.parse(a[0]);
	var bval=(b[0].length==0)?Date.parse("1/1/1900"):Date.parse(b[0]);
	return(a[1]=="ASC")?((aval<bval)?-1:1):((aval>bval)?-1:1);
}
function wlSortByNumber(a,b){
	var aval=(a[0].length==0)?parseFloat(0):parseFloat(a[0]);
	var bval=(b[0].length==0)?parseFloat(0):parseFloat(b[0]);
	return(a[1]=="ASC")?((aval<bval)?-1:1):((aval>bval)?-1:1);
}
function wlSortByString(a,b){
	var aval=(a[0].length==0)?"":a[0].toLowerCase();
	var bval=(b[0].length==0)?"":b[0].toLowerCase();
	return(a[1]=="ASC")?((aval<bval)?-1:1):((aval>bval)?-1:1);
}
CSUWebList_sort.sortDirection="ASC";
CSUWebList_sort.sortIndex=0;
function CSUWebList_sort(list,idx,posStr){
	var i,val,aryPos=posStr.split("|"),arySel=[],aryItm,sPos=aryPos[idx],ePos,hasval=false;
	//numSelections=0; 
	if(idx!=CSUWebList_sort.sortIndex)CSUWebList_sort.sortDirection="ASC";
	for (i=0,imax=list.length;i<imax;i++){
		ePos=(idx==(aryPos.length-1))?list.options[i].text.length-1:aryPos[idx+1]-1;
		// Create an array of various values based on the current list item that will be
		// used by the sort operation.
		aryItm=new Array(5);
		aryItm[0]=Trim(list.options[i].text.substring(sPos,ePos));
		aryItm[1]=CSUWebList_sort.sortDirection;
		aryItm[2]=list.options[i].value;
		aryItm[3]=list.options[i].text;
		aryItm[4]=list.options[i].selected;
		arySel[arySel.length]=aryItm;
		// Make sure there's at least *one* non-blank (empty) value in the sort column.
		// Otherwise, there's no reason to perform the sort.
		if(!hasval)if(aryItm[0].length>0){val=aryItm[0];hasval=true;}
	}
	if(hasval==true){ // There's at least one non-blank value in the sort column, so we can perform the sort.
		// Determine the data type of the SortIndex column in order to choose the most
		// appropriate function for performing the sort.
		if (arySel.length>0){
			if (!isNaN(Date.parse(val))) arySel.sort(wlSortByDate); // Sort by date.
			else if (!isNaN(parseFloat(val))) arySel.sort(wlSortByNumber); // Sort by number.
			else arySel.sort(wlSortByString); // Sort by string.
		}
		// Toggle the sort direction for the next possible sort.
		CSUWebList_sort.sortDirection=(CSUWebList_sort.sortDirection=="ASC")?"DESC":"ASC";
		CSUWebList_sort.sortIndex=idx;
		// Clear the list and re-add the items in their now-sorted order.
		list.length=0;
		for (i=0,imax=arySel.length;i<imax;i++){
			list.length++;
			list.options[i].value=arySel[i][2];
			list.options[i].text=arySel[i][3];
			list.options[i].selected=arySel[i][4];
		}
	}
}
//==========================================================================================//
// End CSUWebList Sorting code
//==========================================================================================//