
//
//  retorna o caminho da Unit JS incorporada.
//  ========================================================================= //
//  name = nome do arquivo JS
//
function _getPathUnit(name)
{
  var r='';
  var i;
  var tags=document.getElementsByTagName("SCRIPT");

  for(var a=0;a<tags.length;a++)
  {
    i=tags[a].src.indexOf(name);
    if(i>=0) r= (i==0) ? '' : tags[a].src.substr(0,i);
  }
  return r;
}

function mudar_atrib( txt )
{
  var ix  = txt.indexOf( ':' );
  var iix = txt.indexOf( '=', ix );

  var comp_ = txt.substr( 0, ix );
  var atrb_ = txt.substr( ix +1, iix - (ix +1) );
  var val_  = txt.substr( iix +1 );
  
  setGrid_off();
  obj_DOM = findDOM( comp_, 1 );
  
  switch( atrb_ )
  {
    case 'top':
    case 'left':
      setStyle( obj_DOM, atrb_, val_ );
      break;
    default:
      //alert( 'Opção não disponível...' );
  }// End switch()

  setGrid_on( comp_ );
}


function setGrid_off()
{
  box_RAD_LT = findDOM( 'boxRAD_LT', 0 );
  box_RAD_LT.style.visibility = 'hidden';
  box_RAD_LM = findDOM( 'boxRAD_LM', 0 );
  box_RAD_LM.style.visibility = 'hidden';
  box_RAD_LB = findDOM( 'boxRAD_LB', 0 );
  box_RAD_LB.style.visibility = 'hidden';

  box_RAD_RT = findDOM( 'boxRAD_RT', 0 );
  box_RAD_RT.style.visibility = 'hidden';
  box_RAD_RM = findDOM( 'boxRAD_RM', 0 );
  box_RAD_RM.style.visibility = 'hidden';
  box_RAD_RB = findDOM( 'boxRAD_RB', 0 );
  box_RAD_RB.style.visibility = 'hidden';

  box_RAD_TM = findDOM( 'boxRAD_TM', 0 );
  box_RAD_TM.style.visibility = 'hidden';
  box_RAD_BM = findDOM( 'boxRAD_BM', 0 );
  box_RAD_BM.style.visibility = 'hidden';
}

function setGrid_on( objID )
{
  ix = objID.indexOf('_');
  if ( ix != -1)
  {
    if( objID.indexOf('body') != -1 )
    {
      obj_nome = objID.substr(ix +1);
    }else
    {
      obj_nome = objID.substr(0, ix);
    }// End
  }else
  {
    obj_nome = objID;
  }
//alert('objeto: ' + obj_nome);
  objMovDOM   = findDOM( obj_nome, 0 );
  objMovSTYLE = findDOM( obj_nome, 1 );
//alert('0');

  if( obj_nome.indexOf('page') == -1 )
  {
    top_     = getTOP(objMovDOM)  -5;
    left_    = getLEFT(objMovDOM) -5;
    width_   = getWIDTH(objMovDOM)  +3;
    height_  = getHEIGHT(objMovDOM) +3;

    if ( event )
    {
      posX = event.x;
      posY = event.y;
    }else
    {
      posX        = null;
      posY        = null;
      objMovDOM   = null;
      objMovSTYLE = null;
    }// End
    /**
     *  monta a grid de Edição  -----------------------------------------  //
     */
    box_RAD_LT = findDOM( 'boxRAD_LT', 0 );
    box_RAD_LT.style.top  = top_ + 'px';
    box_RAD_LT.style.left = left_ + 'px';
    box_RAD_LT.style.visibility = 'visible';

    box_RAD_LM = findDOM( 'boxRAD_LM', 0 );
    box_RAD_LM.style.top  = ( top_ + (height_ /2) ) + 'px';
    box_RAD_LM.style.left = left_ + 'px';
    box_RAD_LM.style.visibility = 'visible';

    box_RAD_LB = findDOM( 'boxRAD_LB', 0 );
    box_RAD_LB.style.top  = ( top_ + height_ ) + 'px';
    box_RAD_LB.style.left = left_ + 'px';
    box_RAD_LB.style.visibility = 'visible';

    box_RAD_RT = findDOM( 'boxRAD_RT', 0 );
    box_RAD_RT.style.top  = top_ + 'px';
    box_RAD_RT.style.left = (left_ + width_) + 'px';
    box_RAD_RT.style.visibility = 'visible';

    box_RAD_RM = findDOM( 'boxRAD_RM', 0 );
    box_RAD_RM.style.top  = (top_ + (height_ /2)) + 'px';
    box_RAD_RM.style.left = (left_ + width_ ) + 'px';
    box_RAD_RM.style.visibility = 'visible';

    box_RAD_RB = findDOM( 'boxRAD_RB', 0 );
    box_RAD_RB.style.top  = (top_ + height_ ) + 'px';
    box_RAD_RB.style.left = (left_ + width_ ) + 'px';
    box_RAD_RB.style.visibility = 'visible';

    box_RAD_TM = findDOM( 'boxRAD_TM', 0 );
    box_RAD_TM.style.top  = top_  + 'px';
    box_RAD_TM.style.left = (left_ + (width_/2) ) + 'px';
    box_RAD_TM.style.visibility = 'visible';

    box_RAD_BM = findDOM( 'boxRAD_BM', 0 );
    box_RAD_BM.style.top  = (top_ + height_ ) + 'px';
    box_RAD_BM.style.left = (left_ + (width_/2) ) + 'px';
    box_RAD_BM.style.visibility = 'visible';
  }else
  {
    box_RAD_LT = findDOM( 'boxRAD_LT', 0 );
    box_RAD_LT.style.visibility = 'hidden';

    box_RAD_LM = findDOM( 'boxRAD_LM', 0 );
    box_RAD_LM.style.visibility = 'hidden';

    box_RAD_LB = findDOM( 'boxRAD_LB', 0 );
    box_RAD_LB.style.visibility = 'hidden';

    box_RAD_RT = findDOM( 'boxRAD_RT', 0 );
    box_RAD_RT.style.visibility = 'hidden';

    box_RAD_RM = findDOM( 'boxRAD_RM', 0 );
    box_RAD_RM.style.visibility = 'hidden';

    box_RAD_RB = findDOM( 'boxRAD_RB', 0 );
    box_RAD_RB.style.visibility = 'hidden';

    box_RAD_TM = findDOM( 'boxRAD_TM', 0 );
    box_RAD_TM.style.visibility = 'hidden';

    box_RAD_BM = findDOM( 'boxRAD_BM', 0 );
    box_RAD_BM.style.visibility = 'hidden';
  }// End

//  alert('width: ' + getWIDTH(objMovDOM) );
//  alert('height: '+ getHEIGHT(objMovDOM) );
}

function setStyle( obj_DOM, atrb_, val_ )
{
  cmd = "obj_DOM." + atrb_ + "= val_ + 'px';"
  eval( cmd );
}


