
	// used as a common component of mmfuel, mmderv and mmgraderv
	function jsel_makeMenu( arr, field, skip, lookup)
	{
		// alert("makeMenu {"+arr+"} skip "+skip+" lookup "+lookup);
		if (field == null)
			return;
		if (field.options == null)
			return;
		field.options.length = arr.length-skip+1;
		field.disabled = false;
		field.selectedIndex = 0;
		if (lookup == null)
		{
			field.options[0].value = "Empty";
			field.options[0].text = "Please select";
			field.options[0].disabled = false;
		} else {
			field.options[0].value = "ANY";
			field.options[0].text = "All fuel types";
			field.options[0].disabled = false;
		}

		for (var i=skip ; i<arr.length ; ++i)
		{
			if (lookup == null)
			{
				val = arr[i];
			} else {
				val = lookup[arr[i]];
			}			
			field.options[i-skip+1].value = val;		
			// if val contains special characters, replace with UNICODE value inorder to display correctly
			if (val.search(/&#233;/gi) != -1) {
				val = val.replace(/&#233;/gi, '\u00E9')
			}
			if (val.search(/&#39;/gi) != -1) {
				val = val.replace(/&#39;/gi, '\u0027')
			}
			field.options[i-skip+1].text = val;
			field.options[i-skip+1].disabled = false;
		}
		return(field.options.length);
	}

	// empties out a menu and disables - used when going back a selection level, ie from model back to make, resets model
	function jsel_blankMenu( field)
	{
		if (field == null)
			return;
		if (field.options == null)
			return;
		field.options.length = 1;
		field.options[0].value = "Empty";
		field.options[0].text = "None";
		field.options[0].disabled = true;
		field.disabled = true;
	}

	function jsel_autofitIframe(id)
	{
		if (!window.opera && !document.mimeType && document.all && document.getElementById){
			parent.document.getElementById(id).style.height = (this.document.body.offsetHeight+20)+"px";
		} else if(document.getElementById) {
			parent.document.getElementById(id).style.height = (this.document.body.scrollHeight+20)+"px"
		}
	}

	function jsel_tcProcessBackSelect( num)
	{
		var sel = document.proDep[jsel_formnames[num]];
		jsel_tcProcessSelect(num+1, sel);
	}

	function jsel_tcProcessSelect( num, sel)
	{
		var ref = sel.selectedIndex;
		jsel_tcProcessSelectDirect(num, ref);
	}


/*
 *	Event section
 *		for attaching js functions to document events (onload etc)
 */
	function jsel_addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}


/*
 *	Callback section
 *		for attaching js functions to menu selections
 */
 	var callbackLevel = null;
	function jsel_callbackInit( totalMenuLevels)
	{
		if (callbackLevel == null)
		{
			callbackLevel = new Array();
			for (var i=0 ; i<totalMenuLevels ; ++i)
			{
				callbackLevel[i] = new Array();
			}
		}
	}
	
	// menuLevel is 1 based (1 is first menu, 2 second... etc)
	function jsel_callbackAttach( callbackFunctionName, menuLevel)
	{
		var arr = callbackLevel[menuLevel-1];
		arr[arr.length] = callbackFunctionName;
		// alert(jsel_callbackShowAttached());
	}

	function jsel_callbackShowAttached()
	{
		var s="";
		for (var i=0 ; i<callbackLevel.length ; ++i)
		{
			for (var j=0 ; j<callbackLevel[i].length ; ++j)
			{
				s += ('callback['+i+']['+j+']: '+callbackLevel[i][j]) + '\r\n';
			}
		}
		return(s);
	}

	function jsel_callbackProcess(menuLevel)
	{
		// alert(menuLevel);
		for (var i=0 ; i<callbackLevel[menuLevel-1].length ; ++i)
		{
			var functionToCall = callbackLevel[menuLevel-1][i]+'(menuLevel)';
			eval(functionToCall);
		}
	}

/*
 *	Array functions
 */
	function jsel_swap(arr, left, right)
	{
		var temp = arr[left];
		arr[left] = arr[right];
		arr[right] = temp;
	}

	function jsel_insert(arr, pos, elem)
	{
		for (var i=arr.length-1 ; i>=pos ; i--)
			arr[i+1] = arr[i];
		arr[pos] = elem;
	}
	
	function jsel_pop(arr)
	{
		var temp = arr[arr.length - 1];
		arr[arr.length - 1] = null;
		arr.length--;
		return(temp);
	}

