/*All about the new client design that we write*/

var CEventDispatcher = new _CEventDispatcher() ;

_CEventDispatcher.prototype.subscribe = _CEventDispatcher_subscribe ;
_CEventDispatcher.prototype.publish = _CEventDispatcher_publish ;
_CEventDispatcher.prototype.unsubscribe = _CEventDispatcher_unsubscribe ;
_CEventDispatcher.prototype.getInstance = _CEventDispatcher_getInstance ;
/*
 * Event Dispatcher Constructor
 */
function _CEventDispatcher()
{
    //handlers are required for unsubscribe process
    this.handlers = Hashtable.getInstance() ;
    return this;
}// end of function

function _CEventDispatcher_getInstance()
{
    return new _CEventDispatcher();
}

/**
 * Event Dispatcher Publish
 */
function  _CEventDispatcher_publish(name, message)
{
    if(message instanceof Array)
    {
      sf.publish(name, message);
    }else
    {
      var argArray = new Array();
      argArray[0] = message;
      sf.publish(name, argArray);
    }

    return ;
}// end of publish


/**
 * Event Dispatcher Subscribe
 */
function _CEventDispatcher_subscribe(name, object, callbackFunction)
{
    //this.m_queues.put(name, callbackFunction) ;
    var handler = sf.subscribe(name, object, callbackFunction);
    if(handler)
    	this.handlers.put(name, handler);
    return ;
}// end of subsribe

/**
 * Event Dispatcher unsubscribe
 */

function _CEventDispatcher_unsubscribe(name)
{    
	var handler = null;
    if(this.handlers)
		handler = this.handlers.get(name);
		
	if(handler)	
	{
		sf.unsubscribe(handler);
		this.handlers.remove(name);
	}
		
    return handler;
}// end of subsribe

/////////////////////////////////////////Start of Controller///////////////////////////////////////////////////////////////

var CController = new _CController() ;

//Constructor of _CContoller object
function _CController()
{
    this.m_topics = null;
    this.m_cache = null;
    this.m_eventDispatcher = null ;
    this.init = _CController_init ;
    this.m_ctx = null ;
    this.getContext =  _CController_getContext ;
    this.getInstance = _CController_getInstance;
    this.service = _CController_service;
    this.getEventDispatcher = _CController_getEventDispatcher ;
    this.destroy =  _CController_destroy ;

    return this;
}// end of ctr

/*
        Contoller Event dispatcher
*/
function _CController_getEventDispatcher()
{
    return this.m_eventDispatcher ;
}

/*
        Contoller INIT
*/
function _CController_init()
{
    // init for controller
    this.m_topics = Hashtable.getInstance() ;
    this.m_cache = Hashtable.getInstance() ;
    this.m_eventDispatcher =CEventDispatcher.getInstance()  ;
}// end of function

/*
Contoller getInstance
*/
function _CController_getInstance()
{
    var oController = new _CController()
    oController.init();
    return oController;
}// end of function

/*
Contoller Service function
*/
function _CController_service(context)
{
  this.m_ctx = context ;
  // FIX ME.. call the process method
  if(context.getCurrentViewComponent())
      return context.getCurrentViewComponent().process(context);
  else
    return null;
}// end of service function

/*Contoller Context*/
function _CController_getContext()
{
    return this.m_ctx ;
}

/*
Contoller Destroy
*/
function _CController_destroy()
{
    alert("Not Implemented!") ;
}// end of function

/////////////////////////////////////////End of Contoller///////////////////////////////////////////////////////////////
/////////////////////////////////////////Start of IViewCompoent///////////////////////////////////////////////////////////////

var IViewComponent = new _IViewComponent(null/*Context*/, null /*Component ID*/, null /*Component Name*/, false /*Is Data Required*/, null/*Mode read/write*/, null/*componentUrl*/ ) ;

/*IVIewComponent Constructor*/
function _IViewComponent(context/*Context*/,componentId /*Component ID*/, componentName /*Component Name*/, isDataReqd /*Data Required for Component*/, mode /*Mode*/, componentUrl/*Component URL*/)
{
    this.m_context  = null  ;
    this.m_componentName = null ;
    this.m_isDataReqd = false ;
    this.m_componentId = null ;
    this.m_mode = null ;
    this.m_componentUrl = null ;
    if(context) this.m_context = context ;
    if(componentName) this.m_componentName = componentName ;
    if(isDataReqd) this.m_isDataReqd = isDataReqd ;
    if(mode) this.m_mode = mode ;
    if(componentUrl) this.m_componentUrl = componentUrl ;
    if(componentId) this.m_componentId = componentId ;

    this.m_attributes = Hashtable.getInstance() ;
    this.getInstance = _IViewComponent_getInstance;
    this.callbackHandler = _IViewComponent_callbackHandler ;
    this.getContext = _IViewComponent_getContext;
    this.getComponentName = _IViewComponent_getComponentName ;
    this.isDataRequired = _IViewComponent_isDataRequired ;
    this.setDataRequired = _IViewComponent_setDataRequired ;
    this.getMode = _IViewComponent_getMode ;
    this.setMode = _IViewComponent_setMode ;
    this.renderView = _IViewComponent_renderView ;
    this.hide = _IViewComponent_hide ;
    this.show = _IViewComponent_show ;
    this.getComponentUrl = _IViewComponent_getComponentUrl ;
    this.setComponentUrl = _IViewComponent_setComponentUrl ;
    this.getComponentId = _IViewComponent_getComponentId ;
    this.setAttribute = _IViewComponent_setAttribute ;
    this.getAttribute = _IViewComponent_getAttribute ;
    this.removeAttribute = _IViewComponent_removeAttribute ;
    // to be  called after datacomponent is done
    this.handleData = _IViewComponent_handleData ;
    // To be called by View handler
    this.handle = _IViewComponent_handle ;
    // process method to be called by Controller
    this.process = _IViewComponent_process ;


    return this ;
}// end of function


function _IViewComponent_handleData()
{
    throw this.getComponentId() +"::_IViewComponent_handleData has to be implemented by Child!"  ;
}

function _IViewComponent_handle()
{
    throw this.getComponentId() + "::_IViewComponent_handle() child has to implement it! "   ;
}

/*View Component setAttribute*/
function _IViewComponent_setAttribute(key,value)
{
    this.m_attributes.put(key,value);
}
function _IViewComponent_removeAttribute(key)
{
  this.m_attributes.remove(key);
}
/*View Component getAttribute*/
function _IViewComponent_getAttribute(key)
{
    return this.m_attributes.get(key);
}

/*View Component getInstance*/
function _IViewComponent_getInstance(context,componentId, componentName, isDataReqd, mode, componentUrl)
{
    this.m_context =  context ;
    this.m_componentName = componentName ;
    this.m_isDataReqd = isDataReqd ;
    this.m_mode = mode ;
    this.m_componentId = componentId ;
    this.m_componentUrl = componentUrl ;
    return new _IViewComponent(context,componentId , componentName, isDataReqd, mode, componentUrl);
}
/*View Component ID*/
function _IViewComponent_getComponentId()
{
    return this.m_componentId ;
}

/*View Component COntext*/
function _IViewComponent_getContext()
{
    return this.m_context ;
}
/*View Component Name*/
function _IViewComponent_getComponentName()
{
    return this.m_componentName ;
}
/*View Component is DataRequired*/
function _IViewComponent_isDataRequired()
{
    return this.m_isDataReqd ;
}
/*View Component setDataRequired*/
function _IViewComponent_setDataRequired(dataRdq)
{
    this.m_isDataRequired = dataRqd ;
}
/*View Component Process*/
function _IViewComponent_process(ctx)
{
    //abstract, should be overridden by child class
    throw this.getComponentId()+"::_IViewComponent_process(ctx) has to be implmented by Child" ;
    //return ;
}
/*View Component Mode*/
function _IViewComponent_getMode()
{
    return this.m_mode ;
}
/*View Component setMode*/
function _IViewComponent_setMode(mode)
{
    this.m_mode = mode ;
}
/*View COmponent render View*/
function _IViewComponent_renderView()
{
    // abstract .. should be implemented by child class
    throw this.getComponentId()+ "::_IViewComponent_renderView() has to be implemented by Child" ;
    //return ;
}
/*view component hide*/
function _IViewComponent_hide()
{
    throw this.getComponentId()+ "::_IViewComponent_hide() has to be implemented by Child" ;
    //let this be done by child again
    //return ;
}
/*view component calbackhandler*/
function _IViewComponent_callbackHandler()
{
    // let child implement this.
    throw this.getComponentId()+"::_IViewComponent_callbackHandler has to be implmented by Child " ;
}
/*view component show*/
function _IViewComponent_show()
{
    //let this be done by child again
    throw this.getComponentId()+"::_IViewComponent_show() has to be implemented by Child" ;
    //return ;
}
/*view component url*/
function _IViewComponent_getComponentUrl()
{
    return this.m_componentUrl ;
}
/*set view component url*/
function _IViewComponent_setComponentUrl(url)
{
    this.m_componentUrl = url ;
}


/////////////////////////////////////////End of IViewCompoent///////////////////////////////////////////////////////////////
/////////////////////////////////////////Start of IDataComponent////////////////////////////////////////////////////////////
var IDataComponent = new _IDataComponent(null/*Context*/, null /*Component Name*/, null /*Data Object*/, null /*Read URL*/, null /*Write URL*/) ;

/*Data COmponent Constructor*/
function _IDataComponent(context,componentName, dataObject, readUrl, writeUrl)
{
    this.m_context = context;
    this.m_componentName = componentName ;
    this.m_dataObject = dataObject ;
    this.m_attributes = Hashtable.getInstance() ;
    this.m_readUrl = readUrl ;
    this.m_writeUrl = writeUrl ;

    this.getInstance = _IDataComponent_getInstance ;
    this.getDataObject = _IDataComponent_getDataObject ;
    this.getReadUrl = _IDataComponent_getReadUrl ;
    this.setReadUrl = _IDataComponent_setReadUrl ;

    this.getWriteUrl = _IDataComponent_getWriteUrl ;
    this.setWriteUrl = _IDataComponent_setWriteUrl ;
    this.setDataObject = _IDataComponent_setDataObject ;
    this.callbackDataHandler = _IDataComponent_callbackDataHandler ;
    this.read = _IDataComponent_read ;
    this.write = _IDataComponent_write ;
    this.setAttribute = _IDataComponent_setAttribute ;
    this.getAttribute = _IDataComponent_getAttribute ;
    this.getContext = _IDataComponent_getContext ;
    this.getComponentName =_IDataComponent_getComponentName ;

    // to be called by message function
    this.handle = _IDataComponent_handle ;

    return this;
}// end of function

function _IDataComponent_setAttribute(key , value )
{
  this.m_attributes.put( key , value );
}// end of function
function _IDataComponent_getAttribute( key )
{
  return this.m_attributes.get( key ) ;
}// end of function

function _IDataComponent_getComponentName()
{
    return this.m_componentName ;
}// end of function



function _IDataComponent_getContext()
{
    return this.m_context ;
}

function _IDataComponent_callbackDataHandler()
{
    throw  this.getComponentName()+"::_IDataComponent_callbackDataHandler has to implemented by child" ;
}

function _IDataComponent_handle()
{
    throw this.getComponentName()+"::_IDataComponent_handle() has to be implemented by Child!" ;
}

/*Data Component Read*/
function _IDataComponent_read()
{
    // read functionality
    throw this.getComponentName()+"::_IDataComponent_read() has to be implemented by Child" ;
}
/*Data Component write*/
function _IDataComponent_write(dataObject)
{
    // write functionality
    throw this.getComponentName()+"::_IDataComponent_write() has to be implemented by Child" ;
}
/*Data Component getinstance*/
function _IDataComponent_getInstance(context,componentName, dataObject, readUrl, writeUrl)
{
    return new _IDataComponent(context,componentName, dataObject, readUrl, writeUrl) ;
}
/*Data Component dataobject*/
function _IDataComponent_getDataObject()
{
    return this.m_dataObject ;
}
/*data component read url*/
function _IDataComponent_getReadUrl()
{
    return this.m_readUrl ;
}
/*set data component read url*/
function _IDataComponent_setReadUrl(readUrl)
{
    this.m_readUrl = readUrl ;
}
/*get datacomponent write url*/
function _IDataComponent_getWriteUrl()
{
    return this.m_writeUrl ;
}
/*set datacomponent write url*/
function _IDataComponent_setWriteUrl(writeUrl)
{
    this.m_writeUrl = writeUrl ;
}
/*data component data object*/
function _IDataComponent_setDataObject(_dataObject)
{
    this.m_dataObject = _dataObject ;
}
/*data component data object*/
function _IDataComponent_getDataObject()
{
    return this.m_dataObject ;
}

/////////////////////////////////////////End of IDataComponent////////////////////////////////////////////////////////

/////////////////////////////////////////Start of Context////////////////////////////////////////////////////////////
var CContext = new _CContext(null/*WebsiteInfo*/, null /*currentView Component*/, null /*Current Data Component*/) ;

function _CContext(websiteInfo,currentViewComponent, currentDataComponent)
{
    this.m_websiteInfo = websiteInfo ;
    this.m_currentViewComponent = currentViewComponent ;
    this.m_currentDataComponent = currentDataComponent ;
    this.m_viewComponentMap = Hashtable.getInstance () ;
    this.m_dataComponentMap = Hashtable.getInstance() ;
    this.m_attributes = Hashtable.getInstance() ;

    this.getInstance =  _CContext_getInstance ;
    this.addViewComponent = _CContext_addViewComponent ;
    this.getViewComponent = _CContext_getViewComponent ;
    this.removeViewComponent =  _CContext_removeViewComponent;

    this.addDataComponent = _CContext_addDataComponent ;
    this.getDataComponent = _CContext_getDataComponent ;
    this.removeDataComponent =  _CContext_removeDataComponent;

    this.getCurrentViewComponent = _CContext_getCurrentViewComponent ;
    this.getCurrentDataComponent = _CContext_getCurrentDataComponent ;
    this.setCurrentViewComponent =  _CContext_setCurrentViewComponent ;
    this.setCurrentDataComponent =  _CContext_setCurrentDataComponent ;
    this.setAttribute = _CContext_setAttribute ;
    this.getAttribute = _CContext_getAttribute ;
    this.removeAttribute = _CContext_removeAttribute ;

    return this;
}// end of function

function _CContext_removeAttribute(key)
{
    this.m_attributes.remove(key);
}

function _CContext_setAttribute(key,value)
{
    this.m_attributes.put(key,value);
}
function _CContext_getAttribute(key)
{
    return this.m_attributes.get(key);
}
function _CContext_getViewComponent(name)
{
    return this.m_viewComponentMap.get(name) ;
}
function _CContext_getDataComponent(name)
{
    return this.m_dataComponentMap.get(name) ;
}

function _CContext_addDataComponent(name,component)
{
    this.m_dataComponentMap.put(name,component) ;
}

function _CContext_removeDataComponent(name)
{
    this.m_dataComponentMap.remove(name) ;
}
function _CContext_getInstance(websiteInfo, currentViewComponent,currentDataComponent)
{
    return new _CContext(websiteInfo, currentViewComponent,currentDataComponent) ;
}
function _CContext_addViewComponent(componentViewName, component)
{
    this.m_viewComponentMap.put(componentViewName, component) ;
}
function  _CContext_removeViewComponent(componentViewName)
{
    this.m_viewComponentMap.remove(componentViewName) ;
}

function _CContext_getCurrentViewComponent()
{
    return this.m_currentViewComponent ;
}
function _CContext_getCurrentDataComponent()
{
    return this.m_currentDataComponent ;
}

function _CContext_setCurrentDataComponent(component)
{
    this.m_currentDataComponent =  component;
}

function _CContext_setCurrentViewComponent(component)
{
    this.m_currentViewComponent =  component;
}


/////////////////////////////////////////End of Context////////////////////////////////////////////////////////////
/////////////////////////////////////////Start of IWebsiteInfo////////////////////////////////////////////////////////////

var IWebsiteInfo = new _IWebsiteInfo(null /*Subscriber Oid */,null /*WebsiteOid*/, null /*Website Name */, null /* Cobrand Name */,
                        null /* CobrandOid */ , null /* Default cobrand oid  */ , null /*Region*/, null /*Website Host*/, null /* Image server Host */, false /*Is Secure Host*/) ;

function _IWebsiteInfo(subsriberOid /*Subscriber Oid */,websiteOid /*WebsiteOid*/, websiteName /*Website Name */, cobrandName /* Cobrand Name */,
                        cobrandOid /* CobrandOid */ , defaultCobrandOid /* Default cobrand oid  */ , region /*Region*/,
                        websiteHost /*Host*/, imageserverHost /*Image server Host*/, isSecure /*Connection*/)
{

    this.m_subscriberOid = subsriberOid ;
    this.m_websiteOid = websiteOid ;
    this.m_websiteName = websiteName ;
    this.m_cobrandName = cobrandName ;
    this.m_cobrandOid = cobrandOid ;
    this.m_defaultCobrandOid = defaultCobrandOid ;
    this.m_region = region ;
    this.m_host = websiteHost ;
    this.m_imageHost = imageserverHost ;
    this.m_isSecure = isSecure ;

    this.getInstance = _IWebsiteInfo_getInstance ;
    this.getWebsiteOid = _IWebsiteInfo_getWebsiteOid ;
    this.getWebsiteName = _IWebsiteInfo_getWebsiteName ;
    this.getSubscriberOid = _IWebsiteInfo_getSubscriberOid ;
    this.getCobrandOid = _IWebsiteInfo_getCobrandOid ;
    this.getCobrandName =  _IWebsiteInfo_getCobrandName ;
    this.getDefaultCobrandOid = _IWebsiteInfo_getDefaultCobrandOid ;
    this.getHost = _IWebsiteInfo_getHost ;
    this.getImageHost = _IWebsiteInfo_getImageHost ;
    this.isSecure = _IWebsiteInfo_isSecure ;
    this.getRegion = _IWebsiteInfo_getRegion ;
    this.toString = _IWebsiteInfo_toString ;

    return this ;
}// end of ctr

function _IWebsiteInfo_toString()
{
        var __string = "SubscriberOid ; " + this.m_subscriberOid  +"\n" +
                                                "WebsiteOid : " + this.m_websiteOid   +"\n" +
                                                "WebsiteName ;" + this.m_websiteName   +"\n" +
                                                "CobrandName :" + this.m_cobrandName   +"\n" +
                                                "CobrandOid : " + this.m_cobrandOid   +"\n" +
                                                "Default Cobrand Oid :" + this.m_defaultCobrandOid   +"\n" +
                                                "Region: " + this.m_region   +"\n" +
                                                "Host :" + this.m_host   +"\n" +
                                                "ImageHost :" + this.m_imageHost   +"\n" +
                                                "Secure ? " + this.m_isSecure  ;
        return __string ;
}

function _IWebsiteInfo_getInstance (subsriberOid /*Subscriber Oid */,websiteOid /*WebsiteOid*/, websiteName /*Website Name */, cobrandName /* Cobrand Name */,
                        cobrandOid /* CobrandOid */ , defaultCobrandOid /* Default cobrand oid  */ , region /*Region*/,
                        websiteHost /*Host*/, imageserverHost /*Image server Host*/, isSecure /*Connection*/)
{
        return new _IWebsiteInfo(subsriberOid /*Subscriber Oid */,websiteOid /*WebsiteOid*/, websiteName /*Website Name */, cobrandName /* Cobrand Name */,
                        cobrandOid /* CobrandOid */ , defaultCobrandOid /* Default cobrand oid  */ , region /*Region*/,
                        websiteHost /*Host*/, imageserverHost /*Image server Host*/, isSecure /*Connection*/)
} // end of getInstance

function _IWebsiteInfo_getWebsiteOid()
{
    return this.m_websiteOid ;
}
function _IWebsiteInfo_getWebsiteName()
{
    return this.m_websiteName ;
}
function _IWebsiteInfo_getSubscriberOid()
{
    return this.m_subscriberOid ;
}
function _IWebsiteInfo_getCobrandOid()
{
    return this.m_cobrandOid ;
}
function _IWebsiteInfo_getCobrandName()
{
    return this.m_cobrandName ;
}
function _IWebsiteInfo_getDefaultCobrandOid()
{
    return this.m_defaultCobrandOid ;
}
function _IWebsiteInfo_getHost()
{
    return this.m_host ;
}
function _IWebsiteInfo_getImageHost()
{
    return this.m_imageHost ;
}
function _IWebsiteInfo_isSecure()
{
    return this.m_isSecure ;
}
function _IWebsiteInfo_getRegion()
{
    return this.m_region ;
}
/////////////////////////////////////////End  of IWebsiteInfo////////////////////////////////////////////////////////////

  function loadViewComponent(viewComponent)
  {
     var pageUrl = viewComponent.getComponentUrl();
     if(!pageUrl) return ;

     var kw =
      {
          url: pageUrl,
          handleAs: "text",
          //timeout: 5000,
          //load: function(type, data, evt)
          load: function(response, ioArgs)
          {
              //document.myForm.myBox.value = data;
              //dojo.byId("div1").innerHTML = data;
              //dojo.byId("boxLoadTime").innerHTML = new Date();
              try
              {
                  viewComponent.callbackHandler(response) ;
              }catch(err)
              {
                    console.error("loadViewComponent( "+viewComponent.getComponentId()+" ) Error " + err  +" ( "+err.description +" )" +" : URL  :"  + pageUrl);
                    throw err;
              }
              //return response;
          },
          error: function(response, ioArgs) {
              console.debug("(loadViewComponent)HTTP status code: "+ ioArgs.xhr.status);
              //return response;
          }
      };
      dojo.xhrGet(kw);
  }

  dataLoadingInProgress=false;
  function loadDataFromDataHost(dataHost, dataComponent)
  {
	dataLoadingInProgress=true;
    var fetchUrl=dataComponent.getReadUrl();
    if(fetchUrl)
    {
      if(typeof designDataCache != 'undefined' && designDataCache[fetchUrl]){//caching the stuff for Intl sites.
      	if(djConfig.isDebug)
      	console.debug("clientV2 :: returning data of ["+fetchUrl+"] from cache");
      	dataComponent.callbackDataHandler(designDataCache[fetchUrl]);	
      	return;
      }else{
      dojo.io.script.get({
          url: dataComponent.getReadUrl(),
          checkString: "taskLoaded", //This means (typeof(taskLoaded) != undefined) indicates that the script loaded.
          transport: "ScriptSrcTransport",
          callbackParamName : "__taskLoaded" ,
          jsonParamName: "__taskLoaded",
          //handleAs: "json",
          //load: function(type, data, event, kwArgs) {
          load: function(response, ioArgs){
              // data is converted into an object automatically by Dojo
              // in this case, the JSON object has a element called message
              dataComponent.callbackDataHandler(response);
              if(typeof designDataCache != 'undefined')designDataCache[fetchUrl]=response;
              dataLoadingInProgress=false;
              return response;
          },
          //error: function(type, data, event, kwArgs) {
          error: function(response, ioArgs) {
              console.debug("(loadDataFromDataHost)HTTP status code: "+ ioArgs.xhr.status);
              return response;
          }
      });
      }
    }

     /*
     var pageUrl = dataComponent.getReadUrl();

     var kw =
      {
         //iframeProxyUrl: dataHost + "/default/javascript/dojo/xip_server.html",
         url: pageUrl,
         transport: "ScriptSrcTransport",
         jsonParamName: "jCallBack",
         load: function(type, data, evt)
         {
              try
              {
                  alert("data " + data);
                  dataComponent.callbackDataHandler(data) ;
              }catch(err)
              {
                  alert("loadDataComponent( "+dataComponent.getComponentName()+" )  Error " + err);
                  throw err;
              }

          },
          error: function(type, data, evt)
          {
            //alert("An error occurred while fetching the data for the data component: " + pageUrl+"\t"  + type);
          },
          method: "GET"
      };

      dojo.io.bind(kw);
      */
  }


  function loadDataComponent(dataComponent)
  {

     var pageUrl = dataComponent.getReadUrl();

     var kw =
      {
         url: pageUrl,
         //load: function(type, data, evt)
         load: function(response, ioArgs)
         {
              //document.myForm.myBox.value = data;
              //dojo.byId("div1").innerHTML = data;
              //dojo.byId("boxLoadTime").innerHTML = new Date();
              try
              {
                  dataComponent.callbackDataHandler(response) ;
              }catch(err)
              {
                  console.debug("loadDataComponent( "+dataComponent.getComponentName()+" )  Error:" + err.description);
                  throw err;
              }
              return response;
          },
          //error: function(type, data, evt)
          error: function(response, ioArgs)
          {
              console.debug("(loadDataFromDataHost)HTTP status code: "+ ioArgs.xhr.status);
              return response;
          }
      };
      dojo.xhrGet(kw);
  }

  function loadAvatarDataComponent()
  {  
     var pageUrl = __getAvatarDataUrl;

     var kw =
      {
         url: pageUrl,
         //load: function(type, data, evt)
         load: function(response, ioArgs)
         {
              //document.myForm.myBox.value = data;
              //dojo.byId("div1").innerHTML = data;
              //dojo.byId("boxLoadTime").innerHTML = new Date();
              try
              {                         
                  oController.getEventDispatcher().publish("avatarDataRetrieved",response);
              }catch(err)
              {
                  console.debug("loadDataComponent( "+dataComponent.getComponentName()+" )  Error:" + err.description);
                  throw err;
              }
              return response;
          },
          //error: function(type, data, evt)
          error: function(response, ioArgs)
          {
              console.debug("(loadDataFromDataHost)HTTP status code: "+ ioArgs.xhr.status);
              return response;
          }
      };
      dojo.xhrGet(kw);
  }


/////////////////////////Dojo pub/sub ///////////////////////////////////

var sf = sf  ||  {} ;

// low-level delegation machinery
sf._listener = {
  // create a dispatcher function
  getDispatcher: function(){
    // following comments pulled out-of-line to prevent cloning them
    // in the returned function.
    // - indices (i) that are really in the array of listeners (ls) will
    //   not be in Array.prototype. This is the 'sparse array' trick
    //   that keeps us safe from libs that take liberties with built-in
    //   objects
    // - listener is invoked with current scope (this)
    return function(){
      var ap=Array.prototype, c=arguments.callee, ls=c._listeners, t=c.target;
      // return value comes from original target function
      var r=t && t.apply(this, arguments);
      // invoke listeners after target function
      for(var i in ls){
        if(!(i in ap) && ls[i]){
          ls[i].apply(this, arguments);
        }
      }
      // return value comes from original target function
      return r;
    }
  },
  // add a listener to an object
  add: function(/*Object*/ source, /*String*/ method, /*Function*/ listener){
    // Whenever 'method' is invoked, 'listener' will have the same scope.
    // Trying to supporting a context object for the listener led to
    // complexity.
    // Non trivial to provide 'once' functionality here
    // because listener could be the result of a dojo.hitch call,
    // in which case two references to the same hitch target would not
    // be equivalent.

    // The source method is either null, a dispatcher, or some other function
    var f = source[method];
    // Ensure a dispatcher
    if(!f||!f._listeners){
      var d = sf._listener.getDispatcher();
      // original target function is special
      d.target = f;
      // dispatcher holds a list of listeners
      d._listeners = [];
      // redirect source to dispatcher
      f = source[method] = d;
    }
    // The contract is that a handle is returned that can
    // identify this listener for disconnect.
    //
    // The type of the handle is private. Here is it implemented as Integer.
    // DOM event code has this same contract but handle is Function
    // in non-IE browsers.
    //
    // We could have separate lists of before and after listeners.
    return f._listeners.push(listener) ; /*Handle*/
  },
  // remove a listener from an object
  remove: function(/*Object*/ source, /*String*/ method, /*Handle*/ handle){
    var f = (source||dojo.global)[method];
    // remember that handle is the index+1 (0 is not a valid handle)
    if(f && f._listeners && handle--){
      delete f._listeners[handle];
    }
  }
};

// Multiple delegation for arbitrary methods.

// This unit knows nothing about DOM,
// but we include DOM aware
// documentation and dontFix
// argument here to help the autodocs.
// Actual DOM aware code is in event.js.

sf.connect = function(/*Object|null*/ obj,
            /*String*/ event,
            /*Object|null*/ context,
            /*String|Function*/ method,
            /*Boolean*/ dontFix){
  var a=arguments, args=[], i=0;
  // if a[0] is a String, obj was ommited
  args.push(dojo.isString(a[0]) ? null : a[i++], a[i++]);
  // if the arg-after-next is a String or Function, context was NOT omitted
  var a1 = a[i+1];
  args.push(dojo.isString(a1)||dojo.isFunction(a1) ? a[i++] : null, a[i++]);
  // absorb any additional arguments
  for(var l=a.length; i<l; i++){  args.push(a[i]); }
  // do the actual work
  return sf._connect.apply(this, args); /*Handle*/
}

// used by non-browser hostenvs. always overriden by event.js
sf._connect = function(obj, event, context, method){
  var l=dojo._listener, h=l.add(obj, event, dojo.hitch(context, method));
  return [obj, event, h, l]; // Handle
}

sf.disconnect = function(/*Handle*/ handle){
  // summary:
  //    Remove a link created by dojo.connect.
  // description:
  //    Removes the connection between event and the method referenced by handle.
  // handle:
  //    the return value of the dojo.connect call that created the connection.
  if(handle && handle[0] !== undefined){
    sf._disconnect.apply(this, handle);
    // let's not keep this reference
    delete handle[0];
  }
}

sf._disconnect = function(obj, event, handle, listener){
  listener.remove(obj, event, handle);
}

// topic publish/subscribe

sf._topics = {};

sf.subscribe = function(/*String*/ topic, /*Object|null*/ context, /*String|Function*/ method){
  //  summary:
  //    Attach a listener to a named topic. The listener function is invoked whenever the
  //    named topic is published (see: dojo.publish).
  //    Returns a handle which is needed to unsubscribe this listener.
  //  context:
  //    Scope in which method will be invoked, or null for default scope.
  //  method:
  //    The name of a function in context, or a function reference. This is the function that
  //    is invoked when topic is published.
  //  example:
  //  | dojo.subscribe("alerts", null, function(caption, message){ alert(caption + "\n" + message); };
  //  | dojo.publish("alerts", [ "read this", "hello world" ]);

  // support for 2 argument invocation (omitting context) depends on hitch
  return [topic, sf._listener.add(sf._topics, topic, sf.hitch(context, method))]; /*Handle*/
}

sf.unsubscribe = function(/*Handle*/ handle){
  //  summary:
  //    Remove a topic listener.
  //  handle:
  //    The handle returned from a call to subscribe.
  //  example:
  //  | var alerter = dojo.subscribe("alerts", null, function(caption, message){ alert(caption + "\n" + message); };
  //  | ...
  //  | dojo.unsubscribe(alerter);
  if(handle){
    sf._listener.remove(sf._topics, handle[0], handle[1]);
  }
}

sf.publish = function(/*String*/ topic, /*Array*/ args){
  //  summary:
  //    Invoke all listener method subscribed to topic.
  //  topic:
  //    The name of the topic to publish.
  //  args:
  //    An array of arguments. The arguments will be applied
  //    to each topic subscriber (as first class parameters, via apply).
  //  example:
  //  | dojo.subscribe("alerts", null, function(caption, message){ alert(caption + "\n" + message); };
  //  | dojo.publish("alerts", [ "read this", "hello world" ]);

  // Note that args is an array, which is more efficient vs variable length
  // argument list.  Ideally, var args would be implemented via Array
  // throughout the APIs.
  var f = sf._topics[topic];
  if(f){
    f.apply(this, args||[]);
  }
}

sf.connectPublisher = function( /*String*/ topic,
                  /*Object|null*/ obj,
                  /*String*/ event){
  //  summary:
  //    Ensure that everytime obj.event() is called, a message is published
  //    on the topic. Returns a handle which can be passed to
  //    dojo.disconnect() to disable subsequent automatic publication on
  //    the topic.
  //  topic:
  //    The name of the topic to publish.
  //  obj:
  //    The source object for the event function. Defaults to dojo.global
  //    if null.
  //  event:
  //    The name of the event function in obj.
  //    I.e. identifies a property obj[event].
  //  example:
  //  | dojo.connectPublisher("/ajax/start", dojo, "xhrGet"};
  var pf = function(){ sf.publish(topic, arguments); }
  return (event) ? sf.connect(obj, event, pf) : sf.connect(obj, pf); //Handle
};




sf._hitchArgs = function(scope, method /*,...*/){
  var pre = sf._toArray(arguments, 2);
  var named = sf.isString(method);
  return function(){
    // arrayify arguments
    var args = sf._toArray(arguments);
    // locate our method
    var f = named ? (scope||dojo.global)[method] : method;
    // invoke with collected args
    return f && f.apply(scope || this, pre.concat(args)); // mixed
  } // Function
}

sf.hitch = function(/*Object*/scope, /*Function|String*/method /*,...*/){
  // summary:
  //    Returns a function that will only ever execute in the a given scope.
  //    This allows for easy use of object member functions
  //    in callbacks and other places in which the "this" keyword may
  //    otherwise not reference the expected scope.
  //    Any number of default positional arguments may be passed as parameters
  //    beyond "method".
  //    Each of these values will be used to "placehold" (similar to curry)
  //    for the hitched function.
  // scope:
  //    The scope to use when method executes. If method is a string,
  //    scope is also the object containing method.
  // method:
  //    A function to be hitched to scope, or the name of the method in
  //    scope to be hitched.
  // example:
  //  | dojo.hitch(foo, "bar")();
  //    runs foo.bar() in the scope of foo
  // example:
  //  | dojo.hitch(foo, myFunction);
  //    returns a function that runs myFunction in the scope of foo
  if(arguments.length > 2){
    return sf._hitchArgs.apply(dojo, arguments); // Function
  }
  if(!method){
    method = scope;
    scope = null;
  }
  if(sf.isString(method)){
    scope = scope || dojo.global;
    if(!scope[method]){ throw(['f.hitch: scope["', method, '"] is null (scope="', scope, '")'].join('')); }
    return function(){ return scope[method].apply(scope, arguments || []); }; // Function
  }
  return !scope ? method : function(){ return method.apply(scope, arguments || []); }; // Function
}


sf._toArray = function(/*Object*/obj, /*Number?*/offset, /*Array?*/ startWith){
  // summary:
  //    Converts an array-like object (i.e. arguments, DOMCollection)
  //    to an array. Returns a new Array object.
  // obj:
  //    the object to "arrayify". We expect the object to have, at a
  //    minimum, a length property which corresponds to integer-indexed
  //    properties.
  // offset:
  //    the location in obj to start iterating from. Defaults to 0. Optional.
  // startWith:
  //    An array to pack with the properties of obj. If provided,
  //    properties in obj are appended at the end of startWith and
  //    startWith is the returned array.
  var arr = startWith||[];
  for(var x = offset || 0; x < obj.length; x++){
    arr.push(obj[x]);
  }
  return arr; // Array
}

sf.isString = function(/*anything*/ it){
  // summary: Return true if it is a String
  return typeof it == "string" || it instanceof String; // Boolean
}

