function Abo() {
		this.arrAbo = new Array();
		this.arrAboText = new Array();		
}

function init(){
// initializes global variables (aliases) for the other functions to use. makes life easier
	window.unitSelect = document.extsearch.elements["tx_onjeunesse_pi1[Unit][]"];
	window.aboSelect = document.extsearch.elements["tx_onjeunesse_pi1[Abo][]"];
}

function is_array(input){
    return typeof(input)=='object'&&(input instanceof Array);
 }


function selAbo(obj) {
	
	window.unitSelect = document.extsearch.elements["tx_onjeunesse_pi1[Unit][]"];
	window.aboSelect = document.extsearch.elements["tx_onjeunesse_pi1[Abo][]"];
	clearAbo();
	fillAbo(obj);
}


function clearAbo() {
		//aboSelect = document.extsearch.elements["tx_onjeunesse_pi1[Abo][]"];
		aboLength = aboSelect.options.length;
		for (i = 0; i < aboLength; i++){
			aboSelect.options[0] = null;
		}
}

function fillAbo(obj) {
		arrAbo = obj.arrAbo;
		arrAboText = obj.arrAboText;
		var selUnit = new Array();
		var z=0;
		for (i = 0; i < unitSelect.length; i++){
			if(unitSelect.options[i].selected == true) {
				selUnit[z] = unitSelect.options[i].value;
				z++;
			}
		} 	
		
		if(selUnit.length>0) {
			for(u=0; u<selUnit.length; u++) {
				if(is_array(arrAbo[selUnit[u]])) {
					for(i=0; i<arrAbo[selUnit[u]].length;i++) {
							currLength = aboSelect.options.length;
							AddMe = new Option(arrAboText[selUnit[u]][i], arrAbo[selUnit[u]][i]);
							aboSelect.options[currLength] = AddMe;
					}
				}
								   
			}
		}
}

function addSelected(){
/* function to add the selected item from the Unselected Box to the Selected Box
 * var addThisSelection - flag for determining whether we should add the selection to the Selected Box
 * var theIndex - the index position of the selected option
 * var theName - the text element of the selected option
 * var theId - the value element of the selected option
 */
	var addThisSelection = 1;
	var theIndex = dUnselected.selectedIndex;
	var theName = dUnselected.options[theIndex].text;
	var theId = dUnselected.options[theIndex].value;

/* 
 * if they haven't selected anything to be added, addThisSelection should = 0
 * else if they have selected something to be added, check if that one has been added already
 */
	if (theIndex == 0){
		addThisSelection = 0;
	} else {
		for (i = 0; i < dSelected.options.length; i++){
			if (dSelected.options[i].text == theName){
				alert("You've already added " + theName);
				addThisSelection = 0;
			}
		}
	}

/* if addThisSelection != 0, create an Option object called AddMe and add that Object to the selected Box
 * if this is the first addition, we want it in the first index
 * otherwise, we'll just tack him to the end of the selected options.
 */
	if (addThisSelection != 0){
		AddMe = new Option(theName, theId);
		if (dSelected.options[0].value == 0){
			dSelected.options[dSelected.options.length-1] = AddMe;
		} else {
			dSelected.options[dSelected.options.length] = AddMe;
		}
	}
}

function removeSelected(){
/*
 * if they have not selected anything to be removed, don't do anything
 * otherwise, remove the selected option.
 * if there are no more options in the Selected Box,
 * then we have to add an Option object ("Blank") at index 0
 * to maintain the size of the box, add &nbsp's instead of an empty string
 */
	if(dSelected.options.selectedIndex == -1){
		// do nothing
	} else if (dSelected.options[0].value != 0){
		dSelected.options[dSelected.options.selectedIndex] = null;
		if(dSelected.options.length == 0){
			Blank = new Option("", 0);
			dSelected.options[dSelected.options.length] = Blank;
		}
	}

}

function getSelected(){
/* 
 just here to show you that theId remains intact
 */
	for (i = 0; i < dSelected.options.length; i++){
		alert(dSelected.options[i].text + " id=" + dSelected.options[i].value);
	}
}

function displayText(obj) {
var el = document.getElementById(obj);
if ( el.style.display != 'none' ) {
el.style.display = 'none';
}
else {
el.style.display = '';
}
}

