function hideBox(boxId, olId)
{
	gEl(olId).style.display = 'none';
	gEl(boxId).style.display = 'none';
}
function showBox(boxId, olId)
{
	gEl(olId).style.height = document.body.offsetHeight + 'px';
	show(olId);
	show(boxId);
	center(boxId);
}
function showBox3(me)
{
	gEl('overlay3').style.height = document.body.offsetHeight + 'px';
	show('overlay3');
	show(me);
	center(me);
	return false;
}
function showBox4(me)
{
	gEl('overlay4').style.height = document.body.offsetHeight + 'px';
	show('overlay4');
	show(me);
	return false;
}
function hideBox3(me){
	hide(me);
	hide('overlay3');
	return false;
}
function hideBox4(me){
	hide(me);
	hide('overlay4');
	return false;
}
function show(element) { gEl(element).style.display = 'block'; }
function hide(element) { gEl(element).style.display = 'none'; }

function center(element)
{
	element = gEl(element);

	var my_width  = getWindowWidth();
	var my_height = getWindowHeight();

	element.style.position = 'absolute';
	element.style.zIndex   = 201;

	var scrollY = getScrollXY()[1];

	var elementDimensions = getDimensions(element);

	var setX = ( my_width  - elementDimensions.width  ) / 2;
	var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

	setX = ( setX < 0 ) ? 0 : setX;
	setY = ( setY < 0 ) ? 0 : setY;

	element.style.left = setX + "px";
	element.style.top  = setY + "px";

	element.style.display  = 'block';
}
function getDimensions (element) 
{	
	var display = element.style.display;
	if (display != 'none' && display != null) // Safari bug
		return { width: element.offsetWidth, height: element.offsetHeight};

	// All *Width and *Height properties give 0 on elements with display none,
	// so enable the element temporarily
	var els = element.style;
	var originalVisibility = els.visibility;
	var originalPosition = els.position;
	var originalDisplay = els.display;
	els.visibility = 'hidden';
	els.position = 'absolute';
	els.display = 'block';
	var originalWidth = element.clientWidth;
	var originalHeight = element.clientHeight;
	els.display = originalDisplay;
	els.position = originalPosition;
	els.visibility = originalVisibility;
	return {width: originalWidth, height: originalHeight};
}


function styleSelect(el)
{
	if (el.selectedIndex == 0)
		el.style.textAlign = 'center';
	else
		el.style.textAlign = 'left';
}

function ismaxlength(obj)
{
	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
	if (obj.getAttribute && obj.value.length>mlength)
	obj.value=obj.value.substring(0,mlength)
}
function gEl(id)
{
	return document.getElementById(id);
}
function doThing(who) 
{
	if (boardActive == '' && gEl(who).className == who+"on")
		boardActive = who;
	gEl(who).className = who+"on";
}
function doThing2(who) {
	if (who != boardActive)
		gEl(who).className = who+"normal";
}
		
var boardLinks = new Array();
var boardCalls = new Array();
var boardIds = new Array();

boardLinks[1] = 'health_care';
boardLinks[2] = 'economic_stimulus';
boardLinks[3] = 'education_and_retirement';
boardLinks[4] = 'commerce_program';
boardLinks[5] = 'about_us';

boardCalls[1] = '';
boardCalls[2] = '';
boardCalls[3] = '';
boardCalls[4] = '';
boardCalls[5] = '';

boardIds[1] = 'one';
boardIds[2] = 'two';
boardIds[3] = 'three';
boardIds[4] = 'four';
boardIds[5] = 'five';

var boardLoading = false;
var boardTab = 0;
var boardActive = '';
var boardScrollTo = '';
/* logged ajax nav */
function openBoard(id, clickEl)
{
	clickEl.blur();
	if (boardLoading || boardTab == id)
		return;
	gtPreload();
	boardLoading = true;
	boardActive = boardIds[id];
	dealType = '';
	processId = 1;
	processSrc = '';
	for (var i in boardIds)
	{
		if (i == id)
			doThing(boardIds[i]);
		else
			doThing2(boardIds[i]);
	}
	
	var req = 'isAjax=1&get=board&handler=' + boardLinks[id];
	boardTab = id;
	
	AjaxAfterLoadCall = (boardCalls[id] != '') ? boardCalls[id] : 'openBoardCallBack';

	AjaxRequestPost('ajax.php', req, 'null');
	
}

function openBoardCallBack(share)
{
	gEl('interior').innerHTML = AjaxRequestResult;
	boardLoading = false;	
}

function openBoardWithScroll(id, clickEl, scrollTo)
{
	clickEl.blur();
	if (boardLoading)
		return false;
	if (boardTab == id)
	{
		window.location.href = scrollTo;
		return;
	}
	else
	{
		gtPreload();
		boardLoading = true;
		boardActive = boardIds[id];
		dealType = '';
		processId = 1;
		processSrc = '';
		boardScrollTo = scrollTo;
		for (var i in boardIds)
		{
			if (i == id)
				doThing(boardIds[i]);
			else
				doThing2(boardIds[i]);
		}
		
		var req = 'isAjax=1&get=board&handler=' + boardLinks[id];
		boardTab = id;
		
		AjaxAfterLoadCall = (boardCalls[id] != '') ? boardCalls[id] : 'openBoardCallBackWithScroll';
	
		AjaxRequestPost('ajax.php', req, 'null');
	}
}

function openBoardCallBackWithScroll(share)
{
	gEl('interior').innerHTML = AjaxRequestResult;
	window.location.href = boardScrollTo; 
	boardLoading = false;	
}

var gtLTm = 0;
var gtLActive = false;
var gtFr = 1;
function gtPreload()
{
	getSize();
	preloadTime = new Date();
	document.getElementById("gtLoad").style.left = (myWidth / 2) + 'px';
	document.getElementById("gtLoad").style.top = ((myHeight / 2) + myScroll) + 'px';
	document.getElementById("gtLoad").style.visibility = "visible";	
	gtFr = 1;
	document.getElementById("gtSpin").src = '/images/zoom/zoom-spin-'+gtFr+'.png';  
	gtLTm = setInterval("gtPreloadA()", 100);
}

function gtPreloadA(from) {
	if (boardLoading != false) {
		document.getElementById("gtSpin").src = '/images/zoom/zoom-spin-'+gtFr+'.png';
		gtFr++;
		if (gtFr > 12) gtFr = 1;
	} else {
		gEl("gtLoad").style.visibility = "hidden";    
		clearInterval(gtLTm);
		gtLTm = 0;
	}
}

function gtPreloadInit()
{
	var inBody = document.getElementsByTagName("body").item(0);
	
	var inS = document.createElement("div");
	inS.setAttribute('id', 'gtLoad');
	inS.style.position = 'absolute';
	inS.style.left = '10px';
	inS.style.top = '10px';
	inS.style.visibility = 'hidden';
	inS.style.zIndex = '525';
	inBody.insertBefore(inS, inBody.firstChild);
	
	var inSpin = document.createElement("img");
	inSpin.setAttribute('id', 'gtSpin');
	inSpin.setAttribute('src', '/images/zoom/zoom-spin-1.png');
	inS.appendChild(inSpin);
}
addEvent(window, 'load', gtPreloadInit);


// this works for IE6 and 7, unlike findPos() from quirksmode
function getElementPos(container) {
	var offsetY = 0;
	var offsetX = 0;
	if (container.getBoundingClientRect) {
		var rect = container.getBoundingClientRect();
		offsetY = rect.top - 2;
		offsetX = rect.left - 2;
		var z = getScrollXY();
		offsetY += z[1];
		offsetX += z[0];
	} else {
		var parentElem = container;
		while (parentElem &&
		       parentElem != document.body &&
		       parentElem != document.documentElement) {
			offsetY += parentElem.offsetTop;
			offsetX += parentElem.offsetLeft;
			parentElem = parentElem.offsetParent;
		}
	}
	return [offsetX, offsetY];
}

function getElementWidth(target) 
{
	if (target.clientWidth) return target.clientWidth;
	else if (target.innerWidth) return target.innerWidth;
	else if (target.offsetWidth) return target.offsetWidth;
	else return 0;
}
function getElementHeight(target) {
	if (target.clientHeight) return target.clientHeight;
	else if (target.innerHeight) return target.innerHeight;
	else if (target.offsetHeight) return target.offsetHeight;
	else return 0;
}

function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}
function getWindowWidth() {
	if (window.innerWidth && window.innerWidth != 0)
		return window.innerWidth;
	if (document.documentElement.clientWidth && document.documentElement.clientWidth != 0)
		return document.documentElement.clientWidth;
	if (document.body.clientWidth && document.body.clientWidth != 0)
		return document.body.clientWidth;
	return 0;
}

function getWindowHeight() {
	if (window.innerHeight && window.innerHeight != 0)
		return window.innerHeight;
	if (document.documentElement.clientHeight && document.documentElement.clientHeight != 0)
		return document.documentElement.clientHeight;
	if (document.body.clientHeight && document.body.clientHeight != 0)
		return document.body.clientHeight;
	return 0;
}

function js_trim(_v)
{
	_v = _v.replace(/^\s+/, '');
	return _v.replace(/\s+$/, '');
}

function doDisplay(elId)
{
	if(gEl(elId).style.display == 'none' || gEl(elId).style.display == '')
		gEl(elId).style.display = 'block';
	else
		gEl(elId).style.display = 'none';
}
