/**
 * Is used to resize a couple of the style div's.
 */
var needsResize = !isIE7() && isIE();
var resizeBy = isIE6Plus() ? 65 : 48;
var extraResizeBy = isIE6Plus() ? 0 : 15;

function performCompatibilityChecks() {
	if (needsResize) {
		initAndResize();
		window.onresize = resize;
	}
}

function isIE() {
	return document.all;
}

function isIE6Plus() {
	return document.compatMode;
}

function isIE7() {
	return window.XMLHttpRequest;
}

function getHeight() {
  return document.body.clientHeight;
}

function getWidth() {
  return document.body.clientWidth;
}

function initAndResize() {
	resize();
}

function resize() {
  	if (!needsResize) return;
  	
  	var newWidth;
  	if (/popup=true|panels=true/.test(location.href) || window.isPopup || window.isPanels)
  		newWidth = getWidth();
  	else
  	{
  		if (window.navigationWidth)
  			newWidth = getWidth() - window.navigationWidth;
  		else
  			newWidth = getWidth() - 186;
  	}
  		
  	if (document.getElementById("menuHeader") && !isIE6Plus())
  		document.getElementById("menuHeader").style.height = 36;
  		
  	if (document.getElementById("leftMenu"))
		document.getElementById("leftMenu").style.height = getHeight() - resizeBy - 90;
  	
	if (document.getElementById("content"))
		document.getElementById("content").style.height = getHeight() - resizeBy;

	if (document.getElementById("centerHeader"))
		document.getElementById("centerHeader").style.width = newWidth;
	if (document.getElementById("content")) {
		document.getElementById("content").style.width = newWidth;
		document.getElementById("content").style.height = getHeight() - (resizeBy + extraResizeBy);
	}
	if (document.getElementById("iconbar"))
		document.getElementById("iconbar").style.width = newWidth;

	var sizeUnit = getWidth() / 10;
	var lblSize = sizeUnit * 2;
	var fldSize = sizeUnit * 3;
	
	// Resize Detail Forms
	var labels = getElementsByClass("fieldLabel");
	var fields = getElementsByClass("fieldField");

	map(labels, function (o) {
		if (hasClass(o, "columncount1"))
			o.style.width = lblSize * 2 + "px";
		else
			o.style.width = lblSize + "px";
		o.style.minWidth = o.style.width;
		o.style.maxWidth = o.style.width;
	});
	map(fields, function (o) {
		if (hasClass(o, "columncount1"))
			o.style.width = fldSize * 2 + "px";
		else {
			if (o.getAttribute('colspan') == 4) {
				o.style.width = (fldSize * 2 + lblSize) + "px";
			}
			else
				o.style.width = fldSize + "px";
		}
		o.style.minWidth = o.style.width;
		o.style.maxWidth = o.style.width;
	});
}