window.onerror = function(){return true;}

function sameheight(addHeight)
{

 if (window.innerHeight > (document.getElementById('footer').offsetTop + document.getElementById('footer').clientHeight)){
 	
		if (window.innerHeight > (document.getElementById('middleContent').offsetTop + document.getElementById('middleContent').clientHeight)){
		
		theFooterHeight = document.getElementById('footer').clientHeight;
		var item = document.getElementById('middleContent');
			
		theHeight = (parseInt(window.innerHeight) - parseInt(document.getElementById('footer').offsetTop) - parseInt(document.getElementById('footer').clientHeight));
		
		theHeight = (parseInt(theHeight) + parseInt(item.offsetTop) + parseInt(item.clientHeight)) + 'px';
		
		item.style.height = theHeight;
	}
	
	document.getElementById('footer').setAttribute('style','margin-top:'+(parseInt(window.innerHeight) - parseInt(document.getElementById('footer').offsetTop) - parseInt(document.getElementById('footer').clientHeight)+20)+'px');
}
 
 var theLeftHeight = document.getElementById('leftContent').style.height ? document.getElementById('leftContent').style.height.replace('px','') : document.getElementById('leftContent').offsetHeight;
 var theContentHeight = document.getElementById('middleContent').style.height ? document.getElementById('middleContent').style.height.replace('px','') : document.getElementById('middleContent').offsetHeight;

 var theRightHeight = 0;
 if (document.getElementById('rightContent')){
 	theRightHeight = document.getElementById('rightContent').style.height ? document.getElementById('rightContent').style.height.replace('px','') : document.getElementById('rightContent').offsetHeight;
 	var theBoxes = document.getElementById('rightContent').getElementsByTagName('div');
 	var theLastBox = null;
 	for (var i=0;i<theBoxes.length;i++){
 		if (theBoxes[i].getAttribute('class') == 'box'){
 			theLastBox = theBoxes[i];
 		}
 	}
 	if (theLastBox){
 		theLastBox.setAttribute('style','border-bottom:0px');
 	}
 	
 }

 var maxheight = Math.max(theLeftHeight,theContentHeight,theRightHeight);
 document.getElementById('leftContent').style.height = (maxheight + addHeight) + 'px';
 document.getElementById('middleContent').style.height = (maxheight + addHeight) + 'px';
 if (document.getElementById('rightContent')){
 	document.getElementById('rightContent').style.height = (maxheight + addHeight) + 'px';
 }
 window.defaultContentHeight = maxheight + addHeight;
 
 


}


if(document.all)
{
 window.attachEvent('onload',function() {sameheight(0);initFormObservers();});
}
else
{
 window.addEventListener('load',function() {sameheight(0);initFormObservers();},false);
} 

function resetContentHeightForPowermail()
{
	setTimeout(function()
	{
		var tempHeight = window.defaultContentHeight;
		$$('.powermail_mandatory_js').each(function(dom)
		{
			tempHeight += dom.offsetHeight;										
		});
		tempHeight += 'px';
		$('leftContent').style.height = tempHeight;
		$('middleContent').style.height = tempHeight;
		if($('rightContent'))$('rightContent').style.height = tempHeight;
	},1);
}

function initFormObservers()
{
	$A($$('.tx_powermail_pi1_form')).each(function(form)
	{
		$A(form.elements).each(function(elm)
		{
			Event.observe(elm,'blur',resetContentHeightForPowermail);
			Event.observe(elm,'focus',resetContentHeightForPowermail);
			Event.observe(elm,'click',resetContentHeightForPowermail);
		});
	});
}