function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function pageWidth() {
  return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}
function pageHeight() {
 return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}



////////////////////////////////////////////////////
//  Atualizar refresh na area da página sendo mostrada
/////////////////////////////////////////////////////
function refreshArea(areaID,areaPanel,serverPage){
//  WebtoolWaitingMessage (areaID,"");
  closePanel(areaPanel)
  WebtoolAjax ("GET",serverPage,areaID,"");
}


////////////////////////////////////////////////////
//  Controle do Painel
/////////////////////////////////////////////////////
function openAlertaWin(panelWidth,nlinhas,areaAlert,posID){
  var panelHeight =(nlinhas*19)+30;
  openPanelCursor (panelWidth,panelHeight,areaAlert,posID);

}
//  Reduzir Window Panel
function zoonInPanel (areaID,width,height){
 var theObject = document.getElementById(areaID);
 theObject.style.height = height + "px";
 theObject.style.width = width + "px";
}
// Panel de edição
function openPanel2 (panelWidth,panelHeight,areaID){
 var theObject = document.getElementById(areaID);
 theObject.style.visibility = "visible";
 theObject.style.height = panelHeight + "px";
 theObject.style.width = panelWidth + "px";
 posx = 1;posy=1;
 theObject.style.left = posx + "px";
 theObject.style.top = posy + "px";
}

function openPanelCursor(panelWidth,panelHeight,areaID,posID) {
//Cursor Y = posição do cursor desde o TOP sem considerar se
// a página teve scroll para baixo.
// offsetY = posição do início da Janela

 var cursorY = findPosY(document.getElementById(posID));
 var theObject = document.getElementById(areaID);
 //////////// calcula posicionamento /////////////
 var xyscroll = getScrollXY();
 var offsetX = 90; //xyscroll[0];
 var offsetY = xyscroll[1];
 var posx = 0;
 var posy = 0;
 var larguraPagina = pageWidth();
 var alturaPagina = pageHeight();
 if (larguraPagina <= panelWidth) {
	posx = 0;
 }else {
    posx = larguraPagina - panelWidth;
    posx = ((posx/2) + offsetX);
 }
//Alterar o fixo 50 do topo para algo perto do cursor
   var cursorTopoOffsetY = cursorY - offsetY ;
// posy = offsetY + 50;
  posy = offsetY + cursorTopoOffsetY;
 //////////////////////////////////////

 theObject.style.visibility = "visible";
 theObject.style.height = panelHeight + "px";
 theObject.style.width = panelWidth + "px";
 theObject.style.left = posx + "px";
 theObject.style.top = posy + "px";
}

function openPanel(panelWidth,panelHeight,areaID) {
 var theObject = document.getElementById(areaID);
 //////////// calcula posicionamento /////////////
 var xyscroll = getScrollXY();
 var offsetX = xyscroll[0];
 var offsetY = xyscroll[1];
 var posx = 0;
 var posy = 0;
 var larguraPagina = pageWidth();
 var alturaPagina = pageHeight();
 if (larguraPagina <= panelWidth) {
	posx = 0;
 }else {
    posx = larguraPagina - panelWidth;
    posx = ((posx/2) + offsetX);
 }
 posy = offsetY + 50;
 //////////////////////////////////////

 theObject.style.visibility = "visible";
 theObject.style.height = panelHeight + "px";
 theObject.style.width = panelWidth + "px";
 theObject.style.left = posx + "px";
 theObject.style.top = posy + "px";
}

// Fechar painel
function closeAlertPanel(){
  closePanel('pnlalert');
}

// Fechar painel
function closePanel(areaID) {
 var theObject = document.getElementById(areaID);
  theObject.innerHTML = "";
 theObject.style.visibility = "hidden";
 theObject.style.height = "0px";
 theObject.style.width = "0px";
}




