/* 
 * Gaia Ajax Widgets, an Ajax Widget Library
 * Copyright (C) 2007  Frost Innovation AS
 * All rights reserved.
 * This program is distributed under either GPL version 2 
 * as published by the Free Software Foundation or the
 * Gaia Commercial License version 1 as published by
 * Frost Innovation AS
 * read the details at http://ajaxwidgets.com/
 */



/* ---------------------------------------------------------------------------
   Class basically wrapping the common functions of ContainerWidgets 
   (Window, AutoCompleter etc)
   --------------------------------------------------------------------------- */
WebControl.Container = function(){}

WebControl.Container.prototype = {

  forceAnUpdate: function(){
    // Destroying all CHILDREN controls
    this.destroyChildrenControls();
  },

  reInit: function(){
    this.element = $(this.element.id);
  },

  destroyChildrenControls: function(){
    // First we need to destroy all CHILD (Gaia) widgets...!!
    $A(this.element.childNodes).each(function(el){
      this._destroyAllChildren(el);
    }.bind(this));
  },

  destroyContainer: function(elId){
    // Destroying all IN-Visible controls with in container (e.g. Timer is IN-Visible)
    var arrayToBeRemoved = new Array();
    Control._itsRegisteredInvisibleControls.each(function(idx){
      if( idx.element.id.indexOf(elId) == 0 ){
        arrayToBeRemoved.push(idx);
      }
    }.bind(this));
    arrayToBeRemoved.each(function(idx){
      var idxNo = 0;
      Control._itsRegisteredInvisibleControls.each(function(idxInner){
        if( idxInner.element.id == idx.element.id )
          throw $break;
        idxNo += 1;
      });
      Control._itsRegisteredInvisibleControls.splice(idxNo, 1)[0];
      idx.destroy();
    });
  }
};
