
//
//  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 );
}


/**
 *
 */
function setWinMsg_lenght( width, height )
{
  msgDOM = findDOM( 'msgBOX', 1 );
  objBOX = findDOM( 'msgBOX_box', 1 );

  msgDOM.width = width+'px';
  objBOX.width = (width-16)+'px';

  msgDOM.height = height+'px';
  objBOX.height = (height-16)+'px';
}// End setWinMsg_lenght( width, height )

/**
 *  setWinMsg_position( top, left )
 */
function setWinMsg_position( top, left )
{
  msgDOM = findDOM( 'msgBOX', 1 );
  msgDOM.top=top+'px';
  msgDOM.left=left+'px';
}//  End setWinMsg_position()



/**
 *  setWinMsg_on()
 */
function setWinMsg_on( obj )
{
  var cmd = '';
  cmd += '<label id="msgBOX_label" for="msgBOX_titulo">Titulo do Coluna</label>';
  cmd += '<input id="msgBOX_titulo" type="text" value="'+objDOM.value+'" class="msgBOX_input">';
  cmd += '<br /><br /><button id="msgBOX_btnGravar">Gravar</button>';
  cmd += '<br /><br /><button id="msgBOX_btnFechar">Fechar</button>';

  msgDOM.visibility='visible';
  objBOX = findDOM( 'msgBOX_box', 0 );
  objBOX.innerHTML = cmd;

  msgBox_ID = findDOM( "msgBOX_btnGravar", 0 );
  msgBox_ID.attachEvent( 'onclick', msgBox_click );

  msgBox_ID = findDOM( "msgBOX_btnFechar", 0 );
  msgBox_ID.attachEvent( 'onclick', setWinMsg_off );



}// End setWinMsg_on()

function msgBox_click( obj )
{
//  alert( 'Obj: ' + objID );
//  alert('old Titulo:' + objDOM.value );
//  alert('novo Titulo:' + msgBOX_titulo.value );
  
//  objDOM.value = msgBOX_titulo.value;
  
  Mensage.setDBgrid_col( 'othuki' + ':' +
                          objID   + ':' +
                          colID   + ':' +
                          msgBOX_titulo.value );
  
  setWinMsg_off();
}// End




/**
 *  setWinMsg_off()
 */
function setWinMsg_off()
{
  var cmd = '<label id="">Mensagem</label>';

  msgDOM = findDOM( 'msgBOX', 1 );
  msgDOM.top=1000+'px';
  msgDOM.left=1000+'px';
  msgDOM.visibility='hidden';
  objBOX = findDOM( 'msgBOX_box', 0 );
  objBOX.innerHTML = cmd;
}// End setWinMsg_off()




