/**
 * selectCombo for jQuery v 1.2.3
 * 
 * Copyright (c) 2007 Shelane Enos
 * Dual licensed under the MIT (MIT-LICENSE.txt) 
 * and GPL (GPL-LICENSE.txt) licenses.
 *
 */
 (function($){
$.fn.selectCombo = function(url, target, settings){
var defaults = {hidetarget: false, indicator: false, pageload: false};
$.extend(defaults, settings);
return this.each(function(){
var qobj = this;
var targetlabel = target.replace(/#/, '');
	targetlabel = "label[@for='" + targetlabel + "']";

if(defaults.indicator != false)
	$(defaults.indicator).hide();
	
hidetargetinfo = function(){
	if($(qobj).attr('id') != $(target).attr('id')){
		$(targetlabel).hide();
		$(target).hide();
	}
}
if(defaults.hidetarget && ($(target).val() == '' || $(target).val() == null))
	hidetargetinfo();
loadOptions = function(){
	qval = $(qobj).val();
	if(defaults.indicator != false)
		$(defaults.indicator).show();
	if($(qobj).attr('id') != $(target).attr('id'))
		$(target).empty();
/*
	$.getJSON(url, {q: qval}, function(j){
		var setoptions = '';
		if(j.length > 0){
			for (var i = 0; i < j.length; i++) 
				setoptions += '<option value="' + j[i].oV + '">' + j[i].oT + '</option>';
			$(target).html(setoptions);
			$("option:first", target).attr("selected","selected");
			$(targetlabel).show();
			$(target).show();
		}
		else if(defaults.hidetarget){
			hidetargetinfo();
			$(target).html(setoptions);
		}
		if(defaults.indicator != false)
			$(defaults.indicator).hide();
	});//end JSON
*/

	$.get(url, {q: qval}, function(j){
		var setoptions = '';
		
		if(j.length > 0){
			for (var i = 0; i < j.length; i++) 
				setoptions += '<option value="' + j[i]['oV'] + '">' + j[i]['oT'] + '</option>';
			$(target).html(setoptions);
			$("option:first", target).attr("selected","selected");
			$(targetlabel).show();
			$(target).show();
		}
		else if(defaults.hidetarget){
			hidetargetinfo();
			$(target).html(setoptions);
		}
		if(defaults.indicator != false)
			$(defaults.indicator).hide();
	});//end AJAX

//$(target).load(url, {qobj: qval});
}

$(this).change(loadOptions);//end change fn

if(defaults.pageload && $(qobj).val() != ''){
	loadOptions();
}

});//end return for each
}
})(jQuery);