﻿function Content_FormatRows()
{
  if(HF_ContentFormat.value != "rows")
  {
    blockOQP(true);
    
    oqp_toolbar.rows[0].cells[6].childNodes[hack_offset].childNodes[0].style.marginLeft = "-147px";
    oqp_toolbar.rows[0].cells[8].childNodes[hack_offset].childNodes[0].style.marginLeft = "-161px";
    
    HF_ContentUpdate.value = "update";
    HF_ContentType.value = "trans";
    HF_UpdateTrigger.value = "trans"
    HF_ContentFormat.value = "rows";
    
    forceLoad = true;
  }
}
function Content_FormatFree()
{
  if(HF_ContentFormat.value != "free" && !oqp_toolbar.rows[0].cells[8].childNodes[hack_offset].disabled)
  {
    blockOQP(true);
    
    oqp_toolbar.rows[0].cells[6].childNodes[hack_offset].childNodes[0].style.marginLeft = "-133px";
    oqp_toolbar.rows[0].cells[8].childNodes[hack_offset].childNodes[0].style.marginLeft = "-175px";
    
    HF_ContentUpdate.value = "update";
    HF_ContentType.value = "trans";
    HF_UpdateTrigger.value = "trans"
    HF_ContentFormat.value = "free";
    
    forceLoad = true;
  }
}

function Content_Zoom(ltr,dist)
{
  var tabindex = parseInt(HF_TabIndex.value);
  
  var tmp1 = parseInt(HF_FontSize1.value);
  var tmp2 = parseInt(HF_FontSize2.value);
  
  var isOrig = (HF_UthmaIsOrig.value == "true");
  
  if(tabindex != 2)
  {
    if( CBL_Show1.checked && CBL_Show2.checked )
    {
      if( ltr )
      {
        if( (dist > 0 && tmp1 < 28 ) || (dist < 0 && tmp1 > 10 ) )
        {
          Content_UpdateZoom(0,HF_FontSize1,tmp1 + dist); Commentaries_UpdateZoom(HF_FontSize1,tmp1 + dist);
          if( !isOrig )
          { Content_UpdateZoom(1,HF_FontSize1,tmp1 + dist); }
        }
      }
      else
      {
        if( isOrig )
        {
          if( (dist > 0 && tmp2 < 32 ) || (dist < 0 && tmp2 > 14 ) )
          { Content_UpdateZoom(1,HF_FontSize2,tmp2 + dist); }
        }
        else
        {
          if( (dist > 0 && tmp1 < 28 ) || (dist < 0 && tmp1 > 10 ) )
          {
            Content_UpdateZoom(0,HF_FontSize1,tmp1 + dist); Commentaries_UpdateZoom(HF_FontSize1,tmp1 + dist);
            Content_UpdateZoom(1,HF_FontSize1,tmp1 + dist);
          }
        }
      }
    }
    else if( CBL_Show1.checked )
    {
      if( (dist > 0 && tmp1 < 28 ) || (dist < 0 && tmp1 > 10 ) )
      { Content_UpdateZoom(0,HF_FontSize1,tmp1 + dist); Commentaries_UpdateZoom(HF_FontSize1,tmp1 + dist); }
    }
    else
    {
      if( isOrig )
      {
        if( (dist > 0 && tmp2 < 32 ) || (dist < 0 && tmp2 > 14 ) )
        { Content_UpdateZoom(0,HF_FontSize2,tmp2 + dist); }
      }
      else
      {
        if( (dist > 0 && tmp1 < 28 ) || (dist < 0 && tmp1 > 10 ) )
        { Content_UpdateZoom(0,HF_FontSize1,tmp1 + dist); }
      }
    }
  }
  else
  {
    if(searchResIsUthma)
    {
      if( isOrig )
      {
        if( (dist > 0 && tmp2 < 32 ) || (dist < 0 && tmp2 > 14 ) )
        { Content_UpdateZoom(0,HF_FontSize2,tmp2 + dist); }
      }
      else
      {
        if( (dist > 0 && tmp1 < 28 ) || (dist < 0 && tmp1 > 10 ) )
        { Content_UpdateZoom(0,HF_FontSize1,tmp1 + dist); }
      }
    }
    else
    {
      if( (dist > 0 && tmp1 < 28 ) || (dist < 0 && tmp1 > 10 ) )
      { Content_UpdateZoom(0,HF_FontSize1,tmp1 + dist); }
    }
  }
  
  OQP_Text_scroller.resizeY(); OQP_Text_scrollbar.resizeY();
}
function Content_ZoomDefault(ltr)
{
  var tabindex = parseInt(HF_TabIndex.value);
  
  var tmp1 = parseInt(HF_FontSize1.value);
  var tmp2 = parseInt(HF_FontSize2.value);
  var isOrig = (HF_UthmaIsOrig.value == "true");
  
  if(tabindex != 2)
  {
    if( CBL_Show1.checked && CBL_Show2.checked )
    {
      if( ltr )
      {
        if( tmp1 != 12 )
        { Content_UpdateZoom(0,HF_FontSize1,12); Commentaries_UpdateZoom(HF_FontSize1,12); }
      }
      else
      {
        if( isOrig )
        {
          if( tmp2 != 16 )
          { Content_UpdateZoom(1,HF_FontSize2,16); }
        }
        else
        {
          if( tmp1 != 12 )
          {
            Content_UpdateZoom(0,HF_FontSize1,12); Commentaries_UpdateZoom(HF_FontSize1,12);
            Content_UpdateZoom(1,HF_FontSize1,12);
          }
        }
      }
    }
    else if( CBL_Show1.checked )
    {
      if( tmp1 != 12 )
      { Content_UpdateZoom(0,HF_FontSize1,12); Commentaries_UpdateZoom(HF_FontSize1,12); }
    }
    else
    {
      if( isOrig )
      {
        if( tmp2 != 16 )
        { Content_UpdateZoom(0,HF_FontSize2,16); }
      }
      else
      {
        if( tmp1 != 12 )
        { Content_UpdateZoom(0,HF_FontSize1,12); }
      }
    }
  }
  else
  {
    if(searchResIsUthma)
    {
      if( isOrig )
      {
        if( tmp2 != 16 )
        { Content_UpdateZoom(0,HF_FontSize2,16); }
      }
      else
      {
        if( tmp1 != 12 )
        { Content_UpdateZoom(0,HF_FontSize1,12); }
      }
    }
    else
    {
      if( tmp1 != 12 )
      { Content_UpdateZoom(0,HF_FontSize1,12); }
    }
  }
  
  OQP_Text_scroller.resizeY(); OQP_Text_scrollbar.resizeY();
}

function Content_UpdateZoom(index,fontstore,newsize)
{
  var cellindex = hack_offset + parseInt(HF_TabIndex.value)*(1+hack_offset);
  var contenttable = OQP_Text.childNodes[cellindex].childNodes[hack_offset].childNodes[hack_offset].childNodes[hack_offset];
  
  fontstore.value = newsize;
  
  for(var i = 0; i < contenttable.rows.length; i++)
  { contenttable.rows[i].cells[index].style.fontSize = newsize + "pt"; }
}
function Commentaries_UpdateZoom(fontstore,newsize)
{
  var tabindex = parseInt(HF_TabIndex.value);
  var cellindex = hack_offset + tabindex*(1+hack_offset);
  
  if(tabindex != 2)
  {
    if( CBL_Show1.checked )
    {
      var tmp;
      var tmp2 = OQP_Text.childNodes[cellindex].childNodes[hack_offset].childNodes[hack_offset].childNodes;
      for(var i = hack_offset + (1 + hack_offset); i < tmp2.length; i = i + (1 + hack_offset))
      {
        tmp = t_oqp_cTabs.nextSibling.childNodes[0];
        while(tmp != null)
        {
          if(tmp.nodeType == 1)
          {
            tmp.style.fontSize = (newsize-1) + "pt";
          }
          
          tmp = tmp.nextSibling;
        }
      }
    }
  }
}
