var iContentMinHeight = 358;
var iPaginationDefaultPosTop = 516;

//START: Fix IE 6 Text Selection Bug
if (window.createPopup && document.compatMode && document.compatMode=="CSS1Compat")
{
	document.onreadystatechange = function fixIE6AbsPos() {
		if( !document.body ) { return; }
		document.body.style.height = document.documentElement.scrollHeight + 'px';
	}
}
//END: Fix IE 6 Text Selection Bug

function BrowserDetection()
{
	var sUserAgent = navigator.userAgent.toLowerCase();

	this.isIE = (sUserAgent.indexOf('msie') != -1);
	this.isSafari = (sUserAgent.indexOf('safari') != - 1);
	this.isMozilla = (sUserAgent.indexOf('gecko') != -1 && this.isSafari == false);
}

var oBrowser = new BrowserDetection();

function openMicrosite(location, width, height, name, toolbar, scrollbars, status, resizable, otherAttrib)
{
	//openMicrosite object properties
	this.location=(location != null) ? location:'#';
	this.width=(width != null) ? width:'790';
	this.height=(height != null) ? height:'564';
	this.name=(name != null) ? name:'microsite';
	this.toolbar=(toolbar != null) ? toolbar:'0';
	this.scrollbars=(scrollbars != null) ? scrollbars:'0';
	this.status=(status != null) ? status:'0';
	this.resizable=(resizable != null) ? resizable:'no';
	this.otherAttrib=(otherAttrib != null) ? otherAttrib:'';
	this.screenWidth=screen.width;
	this.screenHeight=screen.height;
	this.leftPos=(this.screenWidth/2)-(this.width/2);
	this.topPos=(this.screenHeight/2)-(this.height/2);

	//open method opens a window in the center of the screen
	this.open=function()
	{
		this.name = window.open(this.location, this.name, 'toolbar='+this.toolbar+',status='+this.status+',scrollbars='+this.scrollbars+',resizable='+this.resizable+','+this.otherAttrib+',left='+this.leftPos+',top='+this.topPos+',height='+this.height+',width='+this.width);
	}
}

function initMicrosite(sUrl)
{
	var iMicrositeWidth = 790;
	var iMicrositeHeight = 564;

	//other sizes for Safari needed
	if (oBrowser.isSafari) {
		iMicrositeWidth = 788;
		iMicrositeHeight = 563;
	}

	var oMicrositeWin = new openMicrosite(sUrl, iMicrositeWidth, iMicrositeHeight,'microsite');
	oMicrositeWin.open();
}

function getPos(id)
{
	var obj = document.getElementById(id);
	var pos = {left:0, top:0};

	if(typeof obj.offsetLeft != 'undefined') {

		while (obj) {
			pos.left += obj.offsetLeft;
			pos.top += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else {
		pos.left = obj.left;
		pos.top = obj.top;
	}

	return pos;
}

function setObjectHeight(id, height)
{
	var obj = document.getElementById(id);
	obj.style.height = height + "px";
}

function getObjectHeight(id)
{
	var obj = document.getElementById(id);
	var iObjectHeight = 0;
	iObjectHeight = obj.offsetHeight;
	return parseInt(iObjectHeight);
}

function positionPageTools()
{
	var iContentHeight = getObjectHeight('content');
	var iPaginationHeight = getObjectHeight('pagination-zone');
	var iPageToolsZoneHeight = getObjectHeight('page-tools-zone');
	
	var iContextHeight = iContentHeight + iPaginationHeight - iPageToolsZoneHeight;
	setObjectHeight('context', iContextHeight);
}

function init()
{
	var oContent = document.getElementById('content');

	//set content min-height for Mozilla
	if (oBrowser.isMozilla) {
		oContent.style.minHeight = iContentMinHeight + "px";
		oContent.style.height = "auto";
	}

	//if a scroll bar exists, set content height to "auto" for Safari
	if(oBrowser.isSafari)
	{
		if(getPos('end-of-content').top > iPaginationDefaultPosTop-1) {
			oContent.style.height = "auto";
		}
	}

	positionPageTools();
}
var pop = null;

function popdown() {
  if (pop && !pop.closed) pop.close();
}

function popup(obj,w,h) {
  var url = (obj.getAttribute) ? obj.getAttribute('href') : obj.href;
  if (!url) return true;
  w = (w) ? w += 1 : 150;  // 150px*150px is the default size
  h = (h) ? h += 1 : 150;
  var args = 'width='+w+',height='+h+',resizable';
  popdown();
  pop = window.open(url,'',args);
  return (pop) ? false : true;
}

window.onunload = popdown;
window.onfocus = popdown;