// Gaia Ajax Copyright (C) 2008 - 2009 Gaiaware AS. details at http://gaiaware.net/

/* 
 * Gaia Ajax - Ajax Control Library for ASP.NET
 * Copyright (C) 2008 - 2009 Gaiaware AS
 * All rights reserved.
 * This program is distributed under either GPL version 3 
 * as published by the Free Software Foundation or the
 * Gaia Commercial License version 1 as published by
 * Gaiaware AS
 * read the details at http://gaiaware.net
 */

/* ---------------------------------------------------------------------------------------------------------------
   A class to keep generic ClientSide utilities and DOM functions. 
   --------------------------------------------------------------------------------------------------------------- */
Gaia.ClientUtils = Class.create(Gaia.Control, {

  // "Constructor"
  initialize: function(element, options){
    this.initializeClientUtils(element, options);
  },


  initializeClientUtils: function(element, options){
    // Calling base class constructor
    this.initializeControl(element, options);

    Gaia.Control._registeredInvisibleControls.push(this);

    // We MUST have an ID for our control to be retrievable...
    // Faking one here!
    // The ClientUtils doesn't render ANY HTML at ALL so therefore we must "fake" an ID in order for it to be retrievable
    // by the $G method which is used internally to retrieve objects...!
    this.element = {id:element};

  },
  
  // clones the position of an element to position it below the other one
  setClonePosition: function(source, target){   
    try {
      $(target).clonePosition(source, {
      setHeight: false, 
      offsetTop: $(source).offsetHeight,
      setWidth: false
      });
      
    }
    catch (e) {}
    
    return this;
  },
  
  setVisible: function(value){
    return this;
  },
 
  destroy: function(){
    for(var idx = 0, length = Gaia.Control._registeredInvisibleControls.length; idx < length; ++idx) {
        if (Gaia.Control._registeredInvisibleControls[idx] == this)
            break;
    }
    if (idx < length)
        Gaia.Control._registeredInvisibleControls.splice(idx, 1);
        
    Gaia.Control._registeredControls.unset(this.element.id);
  },

  _getElementPostValue: function(){
    return '';
  }
});

Gaia.ClientUtils.browserFinishedLoading = true;
