//<script language="JavaScript">
	/**
	 * This functions removes all blank entries from a list
	 */
	function realign(list){
		
		if (list.length > 0){
			var u=0
			
			while (u < list.length) {
				if (list.options[u].text == "") {
				
					// Try to find next non-empty option
					var v = u + 1
					while (v < list.length && list.options[v].text == "") {
						v = v + 1
					}
					
					// Check if everything after current was empty
					if (v == list.length)
						break
					else {
						list.options[u].text = list.options[v].text
						list.options[u].value = list.options[v].value
						list.options[v].text = ""
						list.options[v].value = ""
					}
				}
				u = u + 1
			}
			
			while (u < list.length)
				list.length = list.length - 1
		}
	}

	/**
	 * This function removes all selected entries from a list
	 */
	function removeEntries(sel_list){
	
		// Check for no selection
		if (sel_list.selectedIndex == -1)
			return
		
		// Check for blank line being selected
		if (sel_list.length == 1 && sel_list.options[0].value == "dud")
			return
		
		// Remove all selected options
		var o = 0
		while (o < sel_list.length) {
			if (sel_list.options[o].selected == true){
				sel_list.options[o].text=""
				sel_list.options[o].value=""
				sel_list.options[o].selected = false
			}
			o = o+1
		}
		
		if (sel_list.options[o-1].text == ""){
			sel_list.length=sel_list.length-1
		}
		realign(sel_list)		

		// Insert blank line if nothing remains
	}

	/**
	 * Adds all selected entries from one list to the other list
	 */
	function addEntries(from_list, sel_list){
		for (var i=0;i<from_list.length;i++) {
		    var e = from_list.options[i]
		    if (e.selected == true)
				addEntry(e.text, e.value, sel_list)
		}
	}

	/**
	 * Adds a single entry to a list (no duplicates allowed)
	 */
	function addEntry(text, value, sel_list) {	
		// Replace the blank sentinel
		if ((sel_list.length == 1) && (sel_list.options[0].value == "dud")) {
			sel_list.options[0].text = text
			sel_list.options[0].value = value
		} else {

			// Is this entry already in the list?
			var listLength = sel_list.length
			var a=0
			while (a < listLength) {
				if (text == sel_list.options[a].text){ 
					break;
				}
				a=a+1
			}
			sel_list.options[a] = new Option(text);
			sel_list.options[a].value = value;
			sel_list.options[a].selected=true;
			sel_list.selectedIndex=a;
		}	
	}
	
	/**
	 * Selects all entries in the list when submit is pressed
	 */
	function selectsubmit(sel_list){
		var sel=0
	
		if ((sel_list.length == 1) && (sel_list.options[sel].value == "dud")) {
			sel_list.options[sel].text = ""
			sel_list.options[sel].value = ""
		}

		var categoryListLength = sel_list.length
		var i = 0
		while (i < categoryListLength) {
		   sel_list.options[i].selected = true
		   i=i+1
		}
		return (true)
	}
	
	/**
	 * This function is called when a link is pressed.
	 * All selected categories are saved and we are redirected to
	 * the selected link's target.  The link's action is ignored (returns false)
	 */
	function linksubmit(targetpage, targetsubject, targetsupcat, pageform){
		pageform.pageNum.value = targetpage;
		pageform.subjId.value = targetsubject;
		pageform.supCatId.value = targetsupcat;
		pageform.action=pageform.action+"#categorySel";
		if (pageform.category != null)
			selectsubmit(pageform.category);
		pageform.submit();
		return (false);
	}

	//submit for category page (here mainly so we don't have to recompile page to change it)
	function categoryPageSubmit(frm,lnk){
		frm._LMaction.value='submit'; 
		selectsubmit(frm.category); 
		frm.submit();
		return false;
	}

