function getBaseURL()
{
    return baseUrl;
}

var PanelHandler=Class.create({
   //Most basic template for panels
   initialize:function(containerId,parentHandler)
   {
       this.parentHandler=parentHandler;
       this.myDocument=(this.parentHandler==null)?$(document):this.parentHandler.getContextDocument();
       this.baseURL=(this.parentHandler==null)?getBaseURL():this.parentHandler.getBaseUrl();
       this.containerId=containerId;

       this.vSECTION_MESSAGEBOX_ID=null;
       this.messageBox=null;

       this.debugMode=(this.parentHandler==null)?false:this.parentHandler.isDebugMode();
   },

   getParentHandler:function()
   {return this.parentHandler;},

   getContainerId:function()
   {return this.containerId;},

   getEContainer:function()
   {return UtilityService.prototype.getFirstMatching(this.myDocument, "id", this.containerId);},

   getContextDocument:function()
   {return this.myDocument;},

   getBaseUrl:function()
   {return this.baseURL;},

   loadComponents:function(className,paramsHash)
   {//Method to ask the servlet for a basic GUI component structure to populate panel
       //paramsHash must always include template:panelGUIType

       //var url=this.getBaseUrl()+"&method=getGUI"+"&template="+panelGUIType;
       var url=this.getBaseUrl()+"&method=getGUI&"+Object.toQueryString(paramsHash);
       //alert("Loading components using: "+url);
       new Ajax.Request(url,
       {
           onSuccess:function(response)
           {
               //alert(response.responseText);
               var attr="class";
               var attrValue=className;
               //alert("Looking for ["+attr+":"+attrValue+"]\nResponse is:\n"+response.responseText);
               var element=UtilityService.prototype.getElementFromResponse(response, attr, attrValue);

               if(element!=null)
               {
                   this.getEContainer().update(element.innerHTML);
                   //Once the basic components are loaded it is possible to create handlers over those components
                   this.loadComponentsHandlers();
               }

           }.bind(this)
       });

   },

   //This method will be overriden
   loadComponentsHandlers:function()
   {},

   isDebugMode:function()
   {return this.debugMode},

   setDebugMode:function(debugMode)
   {this.debugMode=debugMode;},

   writeToLog:function(message)
   {
       if(this.isDebugMode())
        UtilityService.prototype.writeToLog(message);
   },

   getMessageBox:function()
   {
       if(this.vSECTION_MESSAGEBOX_ID!=null)
       {return this.messageBox;}
       else if(this.parentHandler!=null)
       { return this.parentHandler.getMessageBox();}

       this.writeToLog("No default messageBox")
       return null;
   },

   initEvents:function()
   {}

});

var MessageBox=Class.create(PanelHandler,
{
   initialize:function($super,containerId,parentHandler)
   {
       $super(containerId,parentHandler);
       this.getEContainer().innerHTML="Loading...";
       this.getEContainer().hide();
   },

   activateBox:function(message)
   {
       this.getEContainer().innerHTML=message;
       //this.getEContainer().absolutize();

       var top=-this.getEContainer().viewportOffset().top;
       var left=-this.getEContainer().viewportOffset().left+this.getContextDocument().viewport.getWidth()/2-150/2;

       this.getEContainer().setStyle({"top":top,"left":left,width:"150px",height:"30px"});
       this.getEContainer().show();
   },

   deactivateBox:function()
   {this.getEContainer().hide();}
}
);