
jQuery.fn.extend({
  setDatasourceUrl: function(url, options) {
    if (options && options.url)
       options.url = url; // just in case.
    var defaults = {
        url: url,
        busyClass: "ajaxActivity",
        busySelector: null,
        updateView: true,
        dataType:'json'
    };
    var optionsq = $.extend(defaults, options);
    return this.each(function() {
        this.options = optionsq;
        //$(this).bind("onDataReceived", options.onDataReceived); // creates a datareceived event for the data object.
    });
  },
  refresh: function() {
       return this.each(function () {
            if (this.options.busySelector) {
                $(this.options.busySelector).removeClass(this.options.busyClass);
                $(this.options.busySelector).addClass(this.options.busyClass);
            }
            $.ajax({
            			type: "GET",
            			url: this.options.url,
            			options: this.options,
            			e: this,
            			//complete: function () { alert('this.options.url='+this.options.url)},
            			success: function(data) {
                			if ((this.options) && (this.options.busySelector)){
                			    $(this.options.busySelector).removeClass(this.options.busyClass);
            			    }
                			//this.e.data = data;
                			$(this.e).trigger('onDataReceived', [data]);
                			processCommandQue();
            			},


            			error: function (event, XMLHttpRequest, ajaxOptions, thrownError) {
              			var stuff = [event, XMLHttpRequest, ajaxOptions, thrownError];
              			var x = stuff;
            			},
            			dataType: this.options.dataType
            		});
       })
  }
});


