var nothingSelected = "Application Error : Error:\nPlease make sure you select an element before\nusing the management icons";
var alreadySelected = "Application Error : Error:\nThis already exists in the destination, we can't\nhave two the same now can we?";
var nonSelectable = "Application Error : Error:\nThis element is non-selectable. It cannot be added";
var unableToDelete = "Application Error : Error:\nThis element is unable to be removed from this area";
var cannotView = "Application Error : Please Select a VALID Element before trying to view this preview";
var selectElementBeforeClick = "Application Error : Please Select a VALID Element before pressing this button";
var oneSelectOnly = "Application Error : You can only select ONE element for this menu. You already have an element in your destination window,\nPlease remove it before trying to add another";
function CheckArray(source,value) {
		for(i=0; i<source.options.length; i++) {
			if (source.options[i].value == value) {intReturn=1; return true;}
		}
		intReturn=0;
		return false;
}
function addElement(source,destination,hidden){
		var index = source.selectedIndex;
		var destination = destination;
		var hidden = hidden;
		if(index <0 ) {	// nothing selected
				alert(nothingSelected);
		} else {
		for(var i=0; i<source.options.length; i++) {
			if (source.options[i].selected) {
				var srcValue = source.options[i].value;
				var srcText = source.options[i].text;
					if (srcValue == "0") {
						alert(nonSelectable); 
						return;
					} else if (CheckArray(destination, srcValue)) {
						alert(alreadySelected); 
						return;
					}
				}
		}
		var objOption = new Option(source.options[index].text,source.options[index].value);
		destination.options[destination.options.length+1];
		destination.options[destination.options.length] = objOption;
		hidden.value+= "," + source.options[index].value; /* insert data into the hidden field lurking somewhere in the form */
		source.options[index] = null;
		}
}
var MaximumReached = "You can select a maximum number of options for this menu. \n\nYou have already reached your maximum allowed selected options, and are unable to add another without first removing one of your selections.";
function addLimitedElement(source,destination,hidden,maximum){
		var index = source.selectedIndex;
		var destination = destination;
		var hidden = hidden;
		if(index <0 ) {	// nothing selected
			alert(nothingSelected);
		} else {
		for(var i=0; i<source.options.length; i++) {
			if (source.options[i].selected) {
				var srcValue = source.options[i].value;
				var srcText = source.options[i].text;
					if (srcValue == "0") {
						alert(nonSelectable); 
						return;
					} else {
						
						if (destination.options.length == maximum) { alert(MaximumReached); return; }
						
					}
				}
		}
		var objOption = new Option(source.options[index].text,source.options[index].value);
		destination.options[destination.options.length+1];
		destination.options[destination.options.length] = objOption;
		hidden.value+= "," + source.options[index].value; /* insert data into the hidden field lurking somewhere in the form */
		source.options[index] = null;
		}
}
function addSingleElement(source,destination,hidden){
		var index = source.selectedIndex;
		var destination = destination;
		var hidden = hidden;
		if(index <0 ) {	// nothing selected
			alert(nothingSelected);
		} else {
		for(var i=0; i<source.options.length; i++) {
			if (source.options[i].selected) {
				var srcValue = source.options[i].value;
				var srcText = source.options[i].text;
					if (srcValue == "0") {
						alert(nonSelectable); 
						return;
					} else {
						
						if (destination.options.length == 1) { alert(oneSelectOnly); return; }
						
					}
				}
		}
		var objOption = new Option(source.options[index].text,source.options[index].value);
		destination.options[destination.options.length+1];
		destination.options[destination.options.length] = objOption;
		hidden.value+= "," + source.options[index].value; /* insert data into the hidden field lurking somewhere in the form */
		source.options[index] = null;
		}
}
function displayCategories(source, destin) {
	var index = source.selectedIndex;
	var arrValue = source.options[index].value;
	clearOptions(destin);
	if (index > -1 && arrValue > 0) {
		var tempValueArray = new Array();
		tempValueArray = eval("emplCatValueArray_" + arrValue);
		var tempTextArray = new Array();
		tempTextArray = eval("emplCatTextArray_" + arrValue);
		for (i=0; i<tempTextArray.length; i++) {
			var tempText, tempValue;
			tempValue = tempValueArray[0];
			tempText = tempTextArray[i];
			tempValue = tempValueArray[i];
			var objOption = new Option(tempText, tempValue);
			destin.options[destin.options.length+1];
			destin.options[destin.options.length] = objOption;
		}
	}
}
function clearOptions(source) {
	for(i=source.options.length; i>-1; i--) {
		source.options[i] = null;
	}
}
function addHiddenVars(hidden,vars) {
	var hidden = hidden;
	var vars = vars;
	hidden.value=vars;
} 
function rmElement(source,destination,hidden){
	var index = source.selectedIndex;
	var hidden = hidden;
	if(index <0 ) {	// nothing selected
		alert(unableToDelete);
	} else {
		var objOption = new Option(source.options[index].text,source.options[index].value);
		destination.options[destination.options.length+1];
		destination.options[destination.options.length] = objOption;
		source.options[index] = null;
	}
	/* re-populate the hidden field with new shorted id array */
	var hiddenStr = "";
	for(var i=0; i<source.options.length; i++) {
		hiddenStr = hiddenStr + source.options[i].value + ",";
	}
	hidden.value= hiddenStr;
}
