var CurrentScaleCallout;
var CurrentScaleFlag = false;
var ScP_Content,ScP_PageBase,ScP_ContentTop,ScP_ContentBase;

/* Set up parameters to scale the page content up to the size of
   the window.
   Parameters:
      - The ID of the main content DIV to resize
      - The ID of the SPAN marker for the top of the content
      - The ID of the SPAN marker for the bottom of the page
      - The ID of the SPAN marker for the bottom of the content (can be an array)
*/
function ScalePageSetup(content,pbase,ctop,cbase)
{
   ScP_Content = content;
   ScP_PageBase = pbase;
   ScP_ContentTop = ctop;
//   if (cbase.length && cbase.length>0)
      ScP_ContentBase = cbase
//   else
//      ScP_ContentBase = new Array(cbase);
}

function ScP_getObj(id)
{
   return document.getElementById(id);
}

function CheckScalePage()
{
   if (CurrentScaleFlag)
   {
      if (CurrentScaleCallout)
         cancelTimeout(CurrentScaleCallout);
      CurrentScaleCallout = setTimeout("CheckScalePage()",10);
      return;
   }
   CurrentScaleFlag = true;
   var mcc,ctt,ctb,pgb;
   if (!document.getElementById)
   {
      CurrentScaleFlag = false;
      return;
   }
   mcc = ScP_getObj(ScP_Content);
   ctt = ScP_getObj(ScP_ContentTop);
//   ctb = ScP_getObj(ScP_Content_Base);
//   smb = ScP_getObj('sidemenu_base');
   pgb = document.getElementById(ScP_PageBase);
   if (document.body && mcc && pgb && pgb.offsetTop)
   {
      var obtm = 0;
      for (var i=0;i<ScP_ContentBase.length;i++)
      {
         var ob=ScP_getObj(ScP_ContentBase[i]);
         if (ob && ob.offsetTop && ob.offsetTop>obtm)
            obtm = ob.offsetTop;
      }
      var wih = (window.innerHeight?window.innerHeight:document.body.clientHeight);
//      alert( wih+'/'+pgb.offsetTop+'/'+ScP_ContentBase+'/'+obtm+'/'+ctt.offsetTop);
      
      mcc.style.height="auto";
      var otop = ctt.offsetTop;
      var rwh = (wih-pgb.offsetTop) + (obtm-otop); // Amount needed plus current size;
//      window.status = (wih-pgb.offsetTop)+'/'+rwh;
//      window.status = wih+'/'+pgb.offsetTop+'/'+(obtm-otop)+(wih-pgb.offsetTop>0?' - Resizing by '+(wih-pgb.offsetTop):'');
      if (wih-pgb.offsetTop>0)
         mcc.style.height=rwh+"px";
      else
         mcc.style.height="";
   }
   CurrentScaleFlag = false;
}

