//Namespace: nbaAjaxWrapper
window.nbaAjaxWrapper = function(){};
window.respJSONobj = null;

 
//Object to hold error/results returned by Ajax call
nbaAjaxWrapper.responseObj = function (oCode, oMsg){
   this.code = oCode;
   this.msg = oMsg;
} 

//Class to wrap prototype Ajax.Request to provide a 
//more elegant approach to error handling and reporting.
nbaAjaxWrapper.AjaxRequester = Class.create(Ajax.Request, {
    initialize: function($super, url, options) {
         $super(url,nbaAjaxWrapper.AjaxOptions(options));
    }
})
 
//Option object to pass to nbaAjaxWrapper.AjaxRequester wrapper.
nbaAjaxWrapper.AjaxOptions = function (options) {
    return Object.extend({
     asynchronous:false,
     //evalScripts:true,
     //evalJSON:true,
     //contentType:"application/json",
     
     onLoading: function(request){
     	//Element.hide('nbaListFilters');
     },
     onException: function(request,exception) {
     	//alert(3);
       	options.respCallBack( new nbaAjaxWrapper.responseObj(3, exception))
     },
     onFailure: function(t) {
     	//alert(2);
       	options.respCallBack( new nbaAjaxWrapper.responseObj(2, (t.status + ": " + t.statusText)) );
     },
     on404: function(t) {
     	//alert(1);
       	options.respCallBack( new nbaAjaxWrapper.responseObj(1, (t.status + ": " + t.statusText)) );
     },
     onSuccess: function(t){
     	//alert(0);
       	options.respCallBack( new nbaAjaxWrapper.responseObj(0, t.responseText.evalJSON()) );
    }
  }, options || {});
}
 
//Ajax Callback Handler
nbaAjaxWrapper.AjaxResponseHandler = function(resObj){
	respJSONobj = null;
    if (resObj.code == 0){
        respJSONobj = resObj.msg;
    }else{
        nbaAjaxWrapper.MsgLogger(resObj.msg);
   }
}

nbaAjaxWrapper.MsgLogger = function(oMsg, oStatuDiv){
	if (oStatuDiv){
		$(oStatuDiv).innerHTML = oMsg;
	}else{
		alert(oMsg);	
	}
}


