var selectCombo = function ($)
{
	$.fn.selectCombo = function(url, target, aParam)
	{		
		var fnHandler = function() 
		{
			var targetLabel = target.replace(/#/,'');
			targetLabel = "label[@for='" + targetLabel + "']";
				
//			$("option:first", this).attr("selected","selected");

			if ($(this).val() == '')
			{
				$(targetLabel).hide();
				$(target).hide();
			}
				
			var fnChange = function()
			{
				var fnUpdate = function(j)
				{
					var options = '';
					
					for(var i = 0; i < j.length; i++)
						options += '<option value="' + j[i].value + '">' + j[i].key + '</option>';
					$(target).html(options);
					$("option:first", target).attr("selected","selected");
					$(targetLabel).show();
					$(target).show();
				};
			
				if ($(this).val() == '')
				{
					$(targetLabel).hide();
					$(target).hide();
				}
				else
				{
					if (aParam != null)
						$.getJSON(url, {q: $(this).val(), a: $(aParam).val()}, fnUpdate);
					else
						$.getJSON(url, {q: $(this).val()}, fnUpdate);
				}
				
			}
				
			$(this).change(fnChange);
			$(this).change();

		};
	
		return this.each(fnHandler);	
	}
};

selectCombo (jQuery);

