﻿var minheight = 0;
//controls how many blocks count as the template height
//horizontal1 = banner
//horizontal2 = menu
//horizontal3 = footer
//horizontalContent = bodycopy (everything in the content area)
var tplBlocks = 3;
function usersize()
{
    //return;
  if(in_motion){ return; }
  in_motion = true;
  menu = document.getElementById("menu_ads");
  body = document.getElementById("bodycopy");
  left = document.getElementById("bottom_left");
  right = document.getElementById("bottom_right");
  wrapper = document.getElementById("leftwrapper");
  contentContainer = document.getElementById("container");
  if((left!=null) && (right!=null))
  {
    menu.style.height = "auto";
    newheight = checknewheight(Math.max((getBrowserHeight() - getTplHeight()), menu.offsetHeight));
    menu.style.height = body.style.height = (newheight + "px");
    newheight = checknewheight(contentContainer.offsetHeight - getFullPageHeight() -40);//-40 for padding
    
    right.style.height = newheight + "px";
//    if(wrapper!=null)
//    {
//      wrapper.style.height = "auto";
//      wrapper.style.height = newheight + "px";
//    }
//    search = document.getElementById("searchagain");
//    if( (search != null) && (search.style.display == "block") )
//    {
//      newheight = newheight - 44;
//    }    
//    left.style.height = newheight + "px";
    if( wrapper.offsetHeight > left.offsetHeight)
    { left.style.height = (newheight - 44)+ "px"; }
    else
    { left.style.height = newheight + "px"; }
  }
  else
  {
    if( (menu!=null) && (body!=null) ){
      newheight = getBrowserHeight() - getTplHeight();
      menu.style.height = body.style.height = "auto"; 
      if( (body.offsetHeight < newheight) && (menu.offsetHeight < newheight) )
      { menu.style.height = body.style.height = newheight + "px"; }
      else { menu.style.height = body.style.height = (max(menu, body)-1) + "px";}
    }
  }
  in_motion = false;
  return;
}
function max(a, b)
{
    maxheight = a.offsetHeight;
    if (maxheight < b.offsetHeight)
        { maxheight = b.offsetHeight; }
    return maxheight;
}
function getFullPageHeight()
{
    var panel = new Array();
    height = 0;
    flag = true;
    i = 1;
    while(flag)
    {
        panel[i] = document.getElementById("horizontal" + i);
        if (panel[i] ==  null){ flag = false; break; }
        height += panel[i].offsetHeight;
        //height += actual_height;
        i++;
    }
    return height+1;
}
function getTplHeight()
{
    height = 0;
    for(var i = 1; i <= tplBlocks; i++)
        { height += document.getElementById("horizontal" + i).offsetHeight; }
    return height+1;
}
function getStaticContentHeight()
{
    var panel = new Array();
    height = 0;
    flag = true;
    i = 4;
    while(flag)
    {
        panel[i] = document.getElementById("horizontal" + i);
        if (panel[i] ==  null){ flag = false; break; }
        height += panel[i].offsetHeight;
        i++;
    }
    return height+1;
}
function getBrowserWidth()
{
    var myWidth = 0;

//Non-IE
    if( typeof( window.innerWidth ) == 'number' )
    { myWidth = window.innerWidth; }
//IE 6+ in 'standards compliant mode'
    else if( document.documentElement && document.documentElement.clientWidth )
    { myWidth = document.documentElement.clientWidth; }
//IE 4 compatible
    else if( document.body && document.body.clientWidth )
    { myWidth = document.body.clientWidth; }
    return myWidth;
}

function getBrowserHeight()
{
    var myHeight = 0;

//Non-IE
    if( typeof( window.innerWidth ) == 'number' )
    { myHeight = window.innerHeight; }
//IE 6+ in 'standards compliant mode'
    else if( document.documentElement && document.documentElement.clientHeight )
    { myHeight = document.documentElement.clientHeight; }
//IE 4 compatible
    else if( document.body && document.body.clientHeight )
    {myHeight = document.body.clientHeight; }
    minheight = getminheight();
    if (myHeight < minheight)
    { myHeight = minheight; }
    return myHeight;
}
function productlistheight()
{
    pnew = document.getElementById("plistnew");
    pold = document.getElementById("plistold");
    pold.style.maxHeight = (555+(100 - pnew.offsetHeight) )+"px";
}
function checknewheight(newheight)
{
    if(newheight <= 0)
    { return 0; }
    else
    { return newheight; }
}
function getminheight()
{
    if(minheight == 0)
    {
        minheight = 500;
        displayHeight = (getTplHeight() + getStaticContentHeight()) + 50;
        if(minheight < displayHeight)
        { minheight = displayHeight; }
    }
    return minheight
}