	//Init the "dual" lists.
	function initMyList(fromList, toList)
	{
		$("#" + fromList + " option:selected").appendTo("#" + toList);
		$("#" + toList + " option:selected").removeAttr("selected");
		registerClickToMoveListener(fromList, toList);
	}
	
	//Register listeners to move items between the "dual" lists
	function registerClickToMoveListener(fromList, toList)
	{	
			
		$("#" + fromList).click(function()
		{
			$("#" + fromList + " option:selected").appendTo("#" + toList).removeAttr("selected");
		 	performSort(toList);

		});		
		$("#" + toList).click(function()
		{
			$("#" + toList + " option:selected").appendTo("#" + fromList).removeAttr("selected");
			performSort(fromList);
		});
	}	
	
	//Sorts the list based on the Text of the options.
	function performSort(list)
	{
		var arrVals = [];
		var options = $("#" + list + " option");
		options.each(function(){
			arrVals.push({val:$(this).val(),text: $(this).text()});
		});
		 
		arrVals.sort(function(a, b){
		    if(a.text>b.text){
		        return 1;
		    }
		    else if (a.text==b.text){
		        return 0;
		    }
		    else {
		        return -1;
		    }
		});
	
		for (var i = 0, l = arrVals.length; i < l; i++)
		{
			$(options[i]).val(arrVals[i].val).text(arrVals[i].text).attr("title", arrVals[i].text).removeAttr("selected");
	    }
	}
	
	//Registes a keyup filter event to the Input which
	//filters all items with cssClassToFilter. (in a select)					
	function registerKeyupFilter(inputName, select)
	{
		var hiddenSelect = document.createElement('select') ;
		hiddenSelect.style.display = 'none';
		hiddenSelect.id = select + 'Hidden'; 
		document.body.appendChild(hiddenSelect);
		$("#" + inputName).keyup(function(event) {  
		    //if esc is pressed or nothing is entered  
		    if (event.keyCode == 27 || $(this).val() == '') {  
		       //if esc is pressed we want to clear the value of search box  
		       $(this).val('');  		                 
		    }
			filter(select, $(this).val());  
		       
		});
	}
	
	//filter results based on query  
	function filter(selector, query)
	{  
	  query =   $.trim(query).toUpperCase(); //trim white space  
	  $("#" + selector + " option" ).each(function() {  
	  		optionText = $(this).text().toUpperCase();	  		 
	  		if( optionText.indexOf(query) == -1 )
		  		$(this).appendTo("#" +selector + "Hidden");  
	  });  
	  $("#" + selector + "Hidden option" ).each(function() {  
	  		optionText = $(this).text().toUpperCase();	  		 
	  		if( optionText.indexOf(query) != -1 )
		  		$(this).appendTo("#" + selector);  
	  });
	  
	  performSort(selector);	  
	  
	}  
	
	function setTextFromEphoxApplet(ephoxInstanceName)
	{		
		$("#" + ephoxInstanceName + "_inithtml").val(getHtml(ephoxInstanceName));
	}
	
	function setOptionsTitleFromTextValue(selectName)
	{
		$("#"+ selectName + " option").each( function() {   
			$(this).attr("title", $(this).text());
		});
	}
	

					      
