<script language="javascript">

<?php
  include( create_winPage_config( $modo_RAD ) );
//  include( CFG . "winPage.config.js.php" );
?>

/**
 *  winPage_mouseClick()
 */
  function winPage_mouseClick( objID )
  {
    ix = objID.indexOf( '_' );
    nObj = objID.substr( 0, ix );
    
    if( objID.indexOf('winPage') != -1 )
    {
      ix = objID.indexOf( '_' );
      st = objID.substr( 0, ix );
      
      //nrWinPage = getWinPage( objID );
      
      //objDOM = findDOM( st, 0);
    
      if( objID.indexOf('Fechar') != -1 )
      {
        // objDOM.style.visibility='hidden';
        setWinPage_visible( st, 'hidden' );
      }  
      if( objID.indexOf('Minimizar') != -1 )
      {
        alert( 'função não disponível...' );
      }  
      if( objID.indexOf('Restaurar') != -1 )
      {
        alert( 'função não disponível...' );
      }
    }else
    {
      setWinPage_deselect();
      //alert('clicou em: ' + nObj );
      //Mensage.get_winPage( nObj );
    }//End if()
  }// End function mainMenu_mouseClick( objID )

/**
 *  winPage_mouseDown()
 */  
  function winPage_mouseDown( objID )
  {
    if( objID.indexOf('winPage') != -1 &&
        objID.indexOf('_Frame')  == -1 &&
        objID.indexOf('_Fechar') == -1
       )
    {
      ix = objID.indexOf('_');
      st = objID.substr(0, ix);
    
      nr = st.substr( st.length -1 );
      //setUp_winPage( nr );
      setWinPage_selected( nr );

      objMovDOM   = findDOM( st, 0 );
      objMovSTYLE = findDOM( st, 1 );
    
      posX = event.x;
      posY = event.y;
    }
  }
  
/**
 *  winPage_mouseUP()
 */    
  function winPage_mouseUp( objID )
  {
    if( objID.indexOf('winPage') != -1 )
    {
      objMovDOM   = null;
      objMovSTYLE = null;
      posX        = null;
      posY        = null;
    }
  }//

/**
 *  winPage_mouseMove()
 */
  function winPage_mouseMove( objID, evt )
  {
    var xAtual = 0;
    var yAtual = 0;
    
    if( objID.indexOf('winPage') != -1 )
    {
      if(objMovDOM)
      {
        if (objMovSTYLE.left)
          xAtual = objMovSTYLE.left;
        else  
          if (objMovSTYLE.pixelLeft)
            xAtual = objMovSTYLE.pixelLeft;
          else
            if (objMovDOM.offsetLeft)  
              xAtual = objMovDOM.offsetLeft;
            else
              xAtual = '0';  

        if (objMovSTYLE.top)
          yAtual = objMovSTYLE.top;
        else  
          if (objMovSTYLE.pixelTop)
            yAtual = objMovSTYLE.pixelTop;
          else
            if (objMovDOM.offsetTop)  
              yAtual = objMovDOM.offsetTop;
            else
              yAtual = '0';  
//alert('xAtual: ' + xAtual + ' yAtual: '+ yAtual);

        incX = (evt.x - posX) + 1;
        incY = (evt.y - posY) + 1;
    
        newX = parseInt(xAtual) + parseInt(incX);
        newY = parseInt(yAtual) + parseInt(incY);
//alert('evtY:'+evt.y+' posY: '+posY+' incY: '+incY + ' atuY: '+yAtual+' newY: '+newY );

        if(newX > 0)
        {
          objMovDOM.style.left = newX+'px';
          posX = posX + incX;
        }
        if(newY > 0)
        {
          objMovDOM.style.top  = newY+'px';
          posY = posY + incY;
        }
      
        event.cancelBubble = true;

      }//End if(objMovDOM)
    }
  }

/**
 *  winPage_mouseOver()
 */
function winPage_mouseOver( objID, evt )
{
  if( objID.indexOf('winPage') != -1 )
  {
    if( objID.indexOf('Barra') != -1 )
    {
      styleDOM = findDOM( objID, 1 );
      styleDOM.cursor='move';
      //alert('winPage');
    }
    if( objID.indexOf('Fechar')    != -1 ||
        objID.indexOf('Minimizar') != -1 ||
        objID.indexOf('Restaurar') != -1
       )
    {
      styleDOM = findDOM( objID, 1 );
      styleDOM.cursor='default';
    }
  }
}

function refreshPage( nrPage )
{
  winPage2.window.location.reload();
  //alert('Comando: ' + nrPage);
}


function getWinPage( objID )
{
  ix  = objID.indexOf( '_' );
  ret = objID.substr( ix-1, 1 );

  return ret;
}// End function()










//  Conjunto de funções para manipular as propriedades do Objeto  //
//  ------------------------------------------------------------  //
function setWinPage_reload( winPageID )
{
  cmd = winPageID + '.window.location.reload();'
  eval( cmd );
}

function setWinPage_location( winPageID, new_page )
{
  cmd = winPageID + '.window.location = "/studio/' + new_page + '";';
  eval( cmd );
}

/**
 *  seta o Título da Page
 */
function setWinPage_titulo( winPageID, newVal )
{
  var cmd = winPageID + '_Titulo.innerHTML = "' + newVal + '";';
  eval( cmd );
}// End function()
 
/**
 *  seta a visibilidade da Page
 */
function setWinPage_visible( winPageID, newVal )
{
  if ( newVal.indexOf('visible') != -1 )
  {
    new_valor = "inherit";
  }else
  {
    new_valor = "hidden";
  }
  winPageSTYLE = findDOM( winPageID, 1 );
  winPageSTYLE.visibility = new_valor;
  
  //alert('teste: ' + winPageID );
}//End function()


/**
 *  Seleciona uma winPage
 */
function setWinPage_deselect()
{
    nPage = 'winPage' + winPage_selected;

    objMovSTYLE = findDOM( nPage, 1 );
    objMovSTYLE.zIndex = nr;

    nPage += '_barra';
    objMovSTYLE = findDOM( nPage, 1 );
    objMovSTYLE.backgroundColor = "#808080";
}//

/**
 *  Seleciona uma winPage
 */
function setWinPage_selected( nrPage_ativa )
{
  if ( nrPage_ativa != winPage_selected )
  {
    if ( winPage_tipo[ (winPage_selected -1) ] == 'normal' )
    {
      nr = 10 + parseInt( winPage_selected );
    }else
    {
      nr = 500;
    }// End
    nPage = 'winPage' + winPage_selected;

    objMovSTYLE = findDOM( nPage, 1 );
    objMovSTYLE.zIndex = nr;

    nPage += '_barra';
    objMovSTYLE = findDOM( nPage, 1 );
    objMovSTYLE.backgroundColor = "#808080";
  }
  if( winPage_tipo[ (nrPage_ativa -1) ] == 'normal' )
  {
    zIndex = 100;
  }else
  {
    zIndex = 500;
  }// End if()

  nPage = 'winPage' + nrPage_ativa;
  objMovSTYLE = findDOM( nPage, 1 );
  objMovSTYLE.zIndex = zIndex;

  nPage += '_barra';
  objMovSTYLE = findDOM( nPage, 1 );
  objMovSTYLE.backgroundColor = "#0000A0";

  winPage_selected = nrPage_ativa;
  
  nPage = 'winPAge' + nrPage_ativa;
  setWinPage_visible( nPage, "visible" );

}// End function()


  
</script>
