/*

Page Layout for div based Layout.  Redraws each sector of the page to fit with the content and the size of the window.

*/
var xIE4Up=false;
var xNN4=false;
var xOp5or6=false;
var xOp7=false;
var xVersion='3.14.1';

var xUA=navigator.userAgent.toLowerCase();

var xOriginalsSet = false;
var xcHeight = 0;
var xlHeight = 0;
var xrHeight = 0;

if( window.onload == null )
{
	window.onload = function()  
	{  
		initialize();
	}  
}

function initialize()
{
	xcHeight = xHeight("content");  
	xlHeight = xHeight("sidebar-left"); 
	xrHeight = xHeight("sidebar-right");	

	xAddEventListener(window, "resize", adjustLayout, false);  
	xAddEventListener(xGetElementById("content"), "resize", adjustLayout, false);  
	adjustLayout();  
}


function xWidth(e)
{

	if( !xGetElementById(e) )
	{
		return 0;
	}
	else
	{
		return xGetElementById(e).offsetWidth;
	}

}

function adjustLayout()  
{  

	xGetElementById("content").style.width = xClientWidth() - xWidth("sidebar-left") - xWidth("sidebar-right");
	xGetElementById("banner").style.width = xWidth("content") + xWidth("sidebar-left") + xWidth("sidebar-right");

	if( xGetElementById("footer") )
	{
		xGetElementById("footer").style.width = xWidth("banner")
	}

	var sHeight = xClientHeight() - (xHeight("banner") + xHeight("menu"))
	var cHeight = xHeight("content");  
	var lHeight = xHeight("sidebar-left");  
	var rHeight = xHeight("sidebar-right");  

	var maxHeight = 0;

	if( sHeight > Math.max(xcHeight, Math.max(xlHeight, xrHeight)) )
	{
		maxHeight = sHeight;
	}

	if( Math.max(cHeight, Math.max(lHeight, rHeight)) > maxHeight )
	{
		maxHeight = Math.max(cHeight, Math.max(lHeight, rHeight));
	}

	xHeight("content", maxHeight);  
	xHeight("sidebar-left", maxHeight);  
	xHeight("sidebar-right", maxHeight);  
 
	//if( xGetElementById("footer") ) 
	//{
	//	xGetElementById("footer").style.top = maxHeight + xGetElementById("banner").offsetHeight;
	//}
	//xShow("footer"); 
	
	if ( xWidth("banner") > 995)
		window.status = "> 1024x768 (" + (xWidth("banner") + ")");
	else
		if (xWidth("banner") == 995)
			window.status = "1024x768";
		else
			window.status = "<= 1024x768";
	
	//window.status = "Height: " + sHeight + " Width: " + xWidth("banner"); 
 
}

function xAddEventListener(e,eventType,eventListener,useCapture) 
{

	if(!(e=xGetElementById(e)))
		return;
  
	eventType=eventType.toLowerCase();
	
	if((!xIE4Up && !xOp7) && e==window) 
	{
		if(eventType=='resize') 
		{ 
			window.xPCW=xClientWidth(); 
			window.xPCH=xClientHeight(); 
			window.xREL=eventListener; 
			xResizeEvent(); 
			return; 
		}
		
		if(eventType=='scroll') 
		{
			window.xPSL=xScrollLeft();
			window.xPST=xScrollTop();
			window.xSEL=eventListener;
			xScrollEvent(); 
			return; 
		}
		
	}
	var eh='e.on'+eventType+'=eventListener';
	
	if(e.addEventListener) 
		e.addEventListener(eventType,eventListener,useCapture);
	else 
	{
		if(e.attachEvent) 
			e.attachEvent('on'+eventType,eventListener);
		else
		{
			if(e.captureEvents) 
			{
				if(useCapture||(eventType.indexOf('mousemove')!=-1)) 
				{
					e.captureEvents(eval('Event.'+eventType.toUpperCase())); 
				}
				eval(eh);
			}
			else 
				eval(eh);
		}
	}
}

function xClientHeight() 
{

  var h=0;

	if(xOp5or6) 
		h=window.innerHeight;
	else 
	{
		if(!window.opera && document.documentElement && document.documentElement.clientHeight)
			h=document.documentElement.clientHeight;
		else
		{ 
			if(document.body && document.body.clientHeight)
				h=document.body.clientHeight;
			else
			{
				if(xDef(window.innerWidth,window.innerHeight,document.width)) 
				{
					h=window.innerHeight;
					if(document.width>window.innerWidth) 
						h-=16;
				}
			}
		}
	}
	
  return h;
  
}

function xClientWidth() 
{

  var w=0;

	if(xOp5or6) 
		w=window.innerWidth;
	else 
	{
		if(!window.opera && document.documentElement && document.documentElement.clientWidth)
			w=document.documentElement.clientWidth;
		else 
		{
			if(document.body && document.body.clientWidth)
				w=document.body.clientWidth;
			else 
			{
				if(xDef(window.innerWidth,window.innerHeight,document.height)) 
				{
					w=window.innerWidth;
					if(document.height>window.innerHeight) 
						w-=16;
				}
			}
		}
	}
	
	return w;
  
}

function xDef() 
{
	for(var i=0; i<arguments.length; ++i)
	{
		if(typeof(arguments[i])=='undefined') 
			return false;
	}
	
	return true;
	
}

function xGetElementById(e) 
{
	if(typeof(e)!='string') 
		return e;
		
	if(document.getElementById) 
		e=document.getElementById(e);
	else
	{ 
		if(document.all) 
			e=document.all[e];
		else 
		{
			if(document.layers) 
				e=xLayer(e);
			else 
				e=null;
		}
	}	
	return e;
}

function xHeight(e,uH) 
{

	if(!(e=xGetElementById(e))) 
		return 0;

	if (xNum(uH)) 
	{
		if (uH<0) 
			uH = 0;
		else 
			uH=Math.round(uH);
	}
	else 
		uH=0;

	var css=xDef(e.style);

	if(css && xDef(e.offsetHeight) && xStr(e.style.height)) 
	{
		if(uH) 
			xSetCH(e, uH);
			
		uH=e.offsetHeight;
	}
	else if(css && xDef(e.style.pixelHeight)) {
	
		if(uH) 
			e.style.pixelHeight=uH;
			
		uH=e.style.pixelHeight;
	}
	else 
	if(xDef(e.clip) && xDef(e.clip.bottom)) 
	{
    
		if(uH) 
			e.clip.bottom=uH;
		
		uH=e.clip.bottom;
		
	}
	return uH;
}

function xNum(n) {

	return typeof(n)=='number';
	
}

function xResizeEvent() { 
  
	if (window.xREL) 
		setTimeout('xResizeEvent()', 250);
	
	var cw = xClientWidth()
	var ch = xClientHeight();
	
	if (window.xPCW != cw || window.xPCH != ch) 
	{ 
		window.xPCW = cw; 
		window.xPCH = ch; 
		if (window.xREL) 
			window.xREL(); 
	}

}

function xSetCH(ele,uH){

	var pt=0,pb=0,bt=0,bb=0;
  
	if(xDef(document.defaultView) && xDef(document.defaultView.getComputedStyle))
	{
		pt=xGetCS(ele,'padding-top');
		pb=xGetCS(ele,'padding-bottom');
		bt=xGetCS(ele,'border-top-width');
		bb=xGetCS(ele,'border-bottom-width');
	}
	else if(xDef(ele.currentStyle,document.compatMode))
	{
		if(document.compatMode=='CSS1Compat')
		{
			pt=parseInt(ele.currentStyle.paddingTop);
			pb=parseInt(ele.currentStyle.paddingBottom);
			bt=parseInt(ele.currentStyle.borderTopWidth);
			bb=parseInt(ele.currentStyle.borderBottomWidth);
		}
	}
	else if(xDef(ele.offsetHeight,ele.style.height))
	{ 
		ele.style.height=uH+'px';
		pt=ele.offsetHeight-uH;
	}
	
	if(isNaN(pt)) 
		pt=0; 
		
	if(isNaN(pb)) 
		pb=0; 
		
	if(isNaN(bt)) 
		bt=0; 
		
	if(isNaN(bb)) 
		bb=0;
		
	var cssH=uH-(pt+pb+bt+bb);
  
	if(isNaN(cssH)||cssH<0) 
		return;
	else 
		ele.style.height=cssH+'px';
		
}

function xShow(e) 
{
	if(!(e=xGetElementById(e))) 
		return;
		
	if(e.style && xDef(e.style.visibility)) 
		e.style.visibility='visible';
	else
	{
		if(xDef(e.visibility)) 
			e.visibility='show';
	}
	
}

function xStr(s) 
{
  return typeof(s)=='string';
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}


