var showLoginOnLoad = false;

function setTall() {
	if ( document.getElementById ) {
		// the divs array contains references to each column's div element.  
		// Replace 'center' 'right' and 'left' with your own.  
		// Or remove the last one entirely if you've got 2 columns.  Or add another if you've got 4!
		var divs = new Array( 
			new Array( 
				new Array( document.getElementById('content'), document.getElementById('lhs') ),
				new Array( document.getElementById('content'), document.getElementById('lhsMiddle') )
			)
		);
		
		for (var i = 0; i < divs.length; i++) {
			// Let's determine the maximum height out of all columns specified
			var maxHeight = 0;
			for (var j = 0; j < divs[i][0].length; j++) {
				if (divs[i][0][j].offsetHeight > maxHeight) {
					maxHeight = divs[i][0][j].offsetHeight;
				}
			}

			// Let's set all columns to that maximum height
			for (var j = 0; j < divs[i][0].length; j++) {
				divs[i][divs[i].length-1][j].style.height = maxHeight + 'px';
				if (divs[i][0][j].offsetHeight > maxHeight) {
					divs[i][divs[i].length-1][j].style.height = ( parseInt(divs[i][divs[i].length-1][j].style.height) - (divs[i][0][j].offsetHeight - maxHeight)) + 'px';
				}
			}
		}
	}
}


function correctPNGBackground( divId, imgURL ) // correctly handle PNG transparency in Win IE 5.5 , 6 & 7.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
	{
		var div = document.getElementById( divId );
		div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+imgURL+"', sizingMethod='image')";
		div.style.background = '';
	}
}

function showTerms(){
	window.open( '/popup/terms', 'mywindow', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, width=509, height=500');
}

function initLogin() {
	correctPNGBackground( 'loginPopupBg', '/custom/images/login-bg.png' );
	document.getElementById( 'loginPopup' ).style.display = '';
	loginBox = 
			new YAHOO.widget.Panel("loginPopup",  
											{ width:"297px", 
											  height:"178px", 
											  fixedcenter:true, 
											  close:false, 
											  draggable:false, 
											  modal:true,
											  visible:false,
											  underlay:"none",
											  effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.5} 
											} 
										);

	loginBox.render(document.body);
	if( showLoginOnLoad )
		loginBox.show();
}

YAHOO.util.Event.addListener(window, "load", initLogin);

function hideLogin() {
	if( typeof loginBox != "undefined" )
		loginBox.hide();
}

function showLogin() {
	if( typeof loginBox != "undefined" )
		loginBox.show();
	else
		showLoginOnLoad = true
}

function checkLoginForm() {
	// ensure we have username and password
	var validate = new validateForm();
	validate.checkText( 'clientLogin_username', 'Email' );	
	validate.checkText( 'clientLogin_password', 'Password' );
	if( validate.numberOfErrors() > 0 ) {
		validate.displayErrors();
		// we have errors
		return false;
	}
	
	return true;
}