﻿var lngCurrentBlock = 1;
var lngBlockLeft = 1;      
var lngBlockRight = 2;
 
var lngCurrentPage = 1;
var lngPageLeft = 1;      
var lngPageRight = 2;
          
var lngCurrentViewPanes = 2;

var lngZoomLevel = 0;

var lngImgWidth = 0;
var lngImgHeigth = 0;

function LoadBlockData(lngBlock)
{
  if (lngCurrentViewPanes == 1)
  {
    lngCurrentBlock = lngBlock + ((lngBlock >= 1 && lngBlock <= objBlockParameters.length) ? 0 : ((lngBlock < lngCurrentBlock) ? 1 : -1));  
    lngBlockLeft = lngCurrentBlock;
    lngBlockRight = lngCurrentBlock;    

    (new Function('LoadSingleBlockData' + objBlockParameters[lngCurrentBlock - 1]))();  
  }
  else
  {
    lngCurrentBlock = lngBlock + ((lngBlock >= 1 && lngBlock <= objBlockParameters.length) ? 0 : ((lngBlock < lngBlockLeft) ? 1 : -1)); 
    lngBlockLeft = lngCurrentBlock + ((lngBlock <= lngBlockLeft) ? 0 : -1);
    lngBlockRight = lngCurrentBlock + ((lngBlock <= lngBlockLeft) ? 1 : 0);
          
    (new Function('LoadLeftData' + objBlockParameters[lngBlockLeft - 1]))();
    (new Function('LoadRightData' + objBlockParameters[lngBlockRight - 1]))();
  }
  
  (new Function('ActionData' + objBlockParameters[lngBlock - 1]))(); 
}

function LoadPageData(lngPage)
{
  if (lngCurrentViewPanes == 1)
  {
    lngCurrentPage = lngPage + ((lngPage >= 1 && lngPage <= objPageParameters.length) ? 0 : ((lngPage < lngCurrentPage) ? 1 : -1));  
    lngPageLeft = lngCurrentPage;
    lngPageRight = lngCurrentPage;    

    (new Function('LoadSinglePageData' + objPageParameters[lngCurrentPage - 1]))();  
  }
  else
  {
    lngCurrentPage = lngPage + ((lngPage >= 1 && lngPage <= objPageParameters.length) ? 0 : ((lngPage < lngPageLeft) ? 1 : -1)); 
    lngPageLeft = lngCurrentPage + ((lngPage <= lngPageLeft) ? 0 : -1);
    lngPageRight = lngCurrentPage + ((lngPage <= lngPageLeft) ? 1 : 0);
          
    (new Function('LoadLeftData' + objPageParameters[lngPageLeft - 1]))();
    (new Function('LoadRightData' + objPageParameters[lngPageRight - 1]))();
  }
  
  (new Function('ActionData' + objPageParameters[lngPage - 1]))();        
}
  
function LoadSingleBlockData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
}
        
function LoadSinglePageData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
  document.getElementById('objPnlPageImage').style.display = "none";
  document.getElementById('objPnlPageLoad').style.display = "";
    
  document.getElementById('objImgPage').onload = function()
  {
    document.getElementById('objPnlPageLoad').style.display = "none";
    document.getElementById('objPnlPageImage').style.display = "";
  }

  document.getElementById('objHplPage').href = strURLJPGS + strFile;      
  document.getElementById('objImgPage').src = strURLJPGS + strFile;  
  document.getElementById('objLblPage').innerHTML = strText;       
}
                      
function LoadLeftData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
  if (lngBlock != -1)
  {
    LoadLeftBlockData(lngID, lngIdx, lngBlock, lngPage, strText, strFile);
  }
  else if (lngPage != -1)
  {
    LoadLeftPageData(lngID, lngIdx, lngBlock, lngPage, strText, strFile);
  }
}
 
function LoadLeftBlockData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
}

function LoadLeftPageData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
  document.getElementById('objPnlPageLeftImage').style.display = "none";
  document.getElementById('objPnlPageLeftLoad').style.display = "";
    
  document.getElementById('objImgPageLeft').onload = function()
  {
    document.getElementById('objPnlPageLeftLoad').style.display = "none";
    document.getElementById('objPnlPageLeftImage').style.display = "";
  }

  document.getElementById('objImgPageLeft').src = strURLThumbnails + strFile;
  document.getElementById('objLblPageLeft').innerHTML = strText;
}
 
function LoadRightData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
  if (lngBlock != -1)
  {
    LoadRightBlockData(lngID, lngIdx, lngBlock, lngPage, strText, strFile);
  }
  else if (lngPage != -1)
  {
    LoadRightPageData(lngID, lngIdx, lngBlock, lngPage, strText, strFile);
  }
}

function LoadRightBlockData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
}

function LoadRightPageData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
  document.getElementById('objPnlPageRightImage').style.display = "none";  
  document.getElementById('objPnlPageRightLoad').style.display = "";
   
  document.getElementById('objImgPageRight').onload = function()
  {
    document.getElementById('objPnlPageRightLoad').style.display = "none";
    document.getElementById('objPnlPageRightImage').style.display = "";
  }
      
  document.getElementById('objImgPageRight').src = strURLThumbnails + strFile;
  document.getElementById('objLblPageRight').innerHTML = strText; 
}
    
function ActionData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
  if (lngBlock != -1)
  {
    ActionBlockData(lngID, lngIdx, lngBlock, lngPage, strText, strFile);
  }
  else if (lngPage != -1)
  {
    ActionPageData(lngID, lngIdx, lngBlock, lngPage, strText, strFile);
  }
}
 
function ActionBlockData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
  if (document.getElementById('objCorpo_objCorpoNavegacao_objTreeViewn' + lngIdx) != null)
  {
    document.getElementById('objCorpo_objCorpoNavegacao_objTreeViewn' + lngIdx).click();
  }

  if (document.getElementById('objCorpo_objCorpoNavegacao_objTreeViewt' + (lngIdx + 1)) != null)
  {
    document.getElementById('objCorpo_objCorpoNavegacao_objTreeViewt' + (lngIdx + 1)).click();
  }
}

function ActionPageData(lngID, lngIdx, lngBlock, lngPage, strText, strFile)
{
}
 
function Zoom(lngAction)
{
  lngZoomLevel = (lngZoomLevel + ((lngAction == "+") ? 1 : -1)); 

  if (lngZoomLevel >= -5 && lngZoomLevel <= 0)
  {  
    lngImgWidth = ((lngImgWidth == 0) ? document.getElementById('objImgPage').width : lngImgWidth);
    lngImgHeigth = ((lngImgHeigth == 0) ? document.getElementById('objImgPage').height: lngImgHeigth);

    if (lngAction == "+")
    {
      document.getElementById('objImgPage').width = lngImgWidth / (1 + (0.20 * lngZoomLevel * -1));
      document.getElementById('objImgPage').height = lngImgHeigth / (1 + (0.20 * lngZoomLevel * -1));
    }
    else
    {
      document.getElementById('objImgPage').width = lngImgWidth / (1 + (0.20 * lngZoomLevel * -1));
      document.getElementById('objImgPage').height = lngImgHeigth / (1 + (0.20 * lngZoomLevel * -1));
    }

    document.getElementById('objPnlPageLoad').style.width = document.getElementById('objImgPage').width;
    document.getElementById('objPnlPageLoad').style.height = document.getElementById('objImgPage').height;
  }
  else
  {
    lngZoomLevel = (lngZoomLevel + ((lngAction == "+") ? -1 : 1));
  }  
}
  
function Visualize(lngViewPanes)
{
  lngCurrentViewPanes = lngViewPanes;
  
  if (lngCurrentViewPanes == 1)
  {
    document.getElementById('objPnlZoomIn').style.visibility = "visible"; 
    document.getElementById('objPnlZoomOut').style.visibility = "visible"; 
    
    document.getElementById('objPnlMultipage').style.display = "none";     
    document.getElementById('objPnlSinglePage').style.display = "";    
  }
  else
  {
    document.getElementById('objPnlZoomIn').style.visibility = "hidden"; 
    document.getElementById('objPnlZoomOut').style.visibility = "hidden";  
    
    document.getElementById('objPnlSinglePage').style.display = "none"; 
    document.getElementById('objPnlMultipage').style.display = "";        
  }
  
  LoadPageData(lngCurrentPage);  
}
      
function InitCorpoPaginadorData()
{
  if (document.getElementById('objCorpo_objPnlCorpo') != null)
  {
    Visualize(lngCurrentViewPanes);
  }
}

InitCorpoPaginadorData();