

    var handleSuccess = function(o){

	    if(o.responseText != undefined){
	        // use parseJSON from json.js -- otherwise you would need to use eval("(" + o.responseText + ")")
	        var response = o.responseText.parseJSON();
	      
	        if (response ==null || response.JSONResponse==null)
	        	return;
	        
	      	response = response.JSONResponse;
	      	
	        if (response.ErrorMessage == undefined)
	        {
	            response.Components.each(function(component) {
	                var targetContainerName = component.ComponentId + "Container";
	                var targetContainer = $(targetContainerName);
	                targetContainer.innerHTML = component.Response;

                    // load script from response-- if applicable
                    var scripts  = targetContainer.getElementsByTagName("script");
                    if (scripts && (scripts.length > 0))
                    {
                        // should loop through scripts array -- even though there should only by one
                        var script = targetContainer.getElementsByTagName("script")[0];
                        eval(script.innerHTML);
                    }
        	        
    	            // call init function upon load of EACH component -- this could be moved and performed once all components are loaded
	                var target = $(component.ComponentId);
	                if (target && (typeof target.init == 'function'))
	                {
	                    target.init();
	                }
	            });
	        }
	        else // show error message
	        {
	            alert(response.ErrorMessage);
	        }	        
	    }
    }

    var handleFailure = function(o){

	    if(o.responseText !== undefined){
	    	window.location = "error.jsp"
	    }
    }

    var callback = function(argument){
        this.success = handleSuccess;
        this.failure = handleFailure;
        this.argument = argument;
    }

