function getElementPosition( $obj )
{
  var elemTop = parseInt($obj.offsetTop);
  var elemLeft = parseInt($obj.offsetLeft);
  var element = $obj;

  while (element.offsetParent !== null ){

    var element = element.offsetParent;
    elemTop += parseInt(element.offsetTop);
    elemLeft += parseInt(element.offsetLeft);
  }

  var result = {'top': elemTop, 'left': elemLeft};
  return result;
}

/*
function loadLeaderboardByGame( $obj )
{
    var $pars = '';
    var $url = '/admin/ajax/leaderboard-list/gameId/'+$obj.value+'/';
    var $myAjax = new Request( { 'method': 'get', 'url': $url } )
                      .send( $pars )
                      .success = createLeaderbordSelect;
}

function createLeaderbordSelect( originalRequest )
{
   alert( 'Hello' );
}
*/

function getById( elementId )
{
    return document.getElementById( elementId );
}

function getObjectInfo( $obj )
{
    if( typeof( $obj ) === 'string' )
    {
        $obj = getById( $obj );
    }

    var width  = $obj.offsetWidth;
    var height = $obj.offsetHeight;
    var tag   = $obj.tagName;


    return { 'width': width, 'height': height, 'tag': tag };
}

function openPopup(theURL, widt, heig, resizable)
{ //v3.0
  var $left = screen.width / 2 - 200;
  var $top = screen.height / 2 - 250;

  if ( widt )
  {
    $left = parseInt( screen.width / 2 - widt / 2 );
  }

  if ( heig )
  {
    $top = parseInt( screen.height / 2 - heig / 2 );
  }

  features = '';

  if ( widt )
  {
    features += ', width='+widt;
  }
  if ( heig )
  {
    features += ', height='+heig;
  }
  /*
  if ( scrollbars )
  {
    features += ', scrollbars=1';
  }
  */
  if ( resizable )
  {
    features += ', resizable=1';
  }
  if ( features.indexOf(',') == 0 )
  {
    features = features.substr(1);
  }

  window.open(theURL, '', features + ", left=" + $left + ", top=" + $top + ', scrollbars=yes, toolbar=1, status=1' );//+ ', scrollbars=1'     +', location=1, toolbar=1, menubar=1');
  //status=1, toolbar=1,
}

loading = {
  show: function( action )
  {

    if ( !getById('screen') )
    {
      var div              = document.createElement('DIV');
      div.style.filter     = 'alpha(opacity=50)';
      div.style.opacity    = '0.5';
      div.style.top        = '0px';
      div.style.left       = '0px';
      div.style.background = '#efefef';
      div.style.position   = 'absolute';

      div.id = 'screen';
      div.align = 'left';
      div.innerHTML = "<a href='javascript: void(0)' onClick='loading.hide()'>close</a>&nbsp;&nbsp;&nbsp;";
      document.body.appendChild(div);
      //$('loadData').style.left = parseInt(document.body.clientWidth / 2 ) + 'px';
    }

    div.style.width  = document.body.offsetWidth + 'px';
    div.style.height = document.body.offsetHeight + 'px';

    if ( window.ActiveXObject )
    {
      var $scrollTop = document.documentElement.scrollTop;
      var $scrollLeft = document.documentElement.scrollLeft;
      if ( $scrollTop !== 0 || undefined == $scrollTop )
      {
        $scrollTop = document.body.scrollTop;
        $scrollLeft = document.body.scrollLeft;
        if (!$scrollTop)
        {
          $scrollTop = 0;
          $scrollLeft = 0;
        }
      }

      //$('loadData').style.top = 200 + $scrollTop + 'px';
      div.style.width = parseInt( div.style.width ) + $scrollLeft;
    }
    else
    {
      //$('loadData').style.top = 200 + parseInt(window.pageYOffset) + 'px';//parseInt(screen.height / 2) + 'px';
      div.style.width = parseInt( div.style.width ) + parseInt(window.pageXOffset) + 'px';
    }


/*
    if ( action !== false )
    {
      $('loadData').show();
    }
*/
  },

  hide: function()
  {
    if ( getById('screen') )
    {
      getById('screen').style.display = 'none';
    }
    //$('loadData').hide();
  }
}