var ns = (document.layers)? true:false;
var ie = (document.all)? true:false;
var dhtml = (document.getElementById)? true:false;

var width;
var height;
var initialDocLength;

var MINHEIGHT = 450;
var MINWIDTH = 750;

var oldActiveBracketName = "";

width = GetWidth();
height = GetHeight();

window.onresize = moveBorder;

function GetHeight() {
	var height;
	if(ie) {
		height = document.body.offsetHeight - 16;
		if(document.body.offsetWidth < MINWIDTH - 7) {
			height = height - 16;
		}
		if(document.body.offsetHeight < initialDocLength + 20) { height = initialDocLength + 10; }
		if(height < MINHEIGHT) { height = MINHEIGHT; }
	} else if(ns) {
		height = window.innerHeight;
		if(((window.innerWidth + 16) < MINWIDTH - 7)) {
			height = height - 22;  /* this incorporates the horizontal scroll bar */
		}
		if(window.innerHeight < initialDocLength) { height = initialDocLength + 10; }
		if (height < MINHEIGHT) {
			height=MINHEIGHT;
		}
	} else if(dhtml) {
		height = window.innerHeight - 36;
		if(((window.innerWidth + 16) < MINWIDTH - 7)) {
			height = height - 36;  /* this incorporates the horizontal scroll bar */
		}
		if(window.innerHeight < initialDocLength) { height = initialDocLength + 10; }
		if (height < MINHEIGHT) {
			height=MINHEIGHT;
		}
	} else {
		height = document.body.offsetHeight -16;
		if(document.body.offsetWidth < MINWIDTH - 7) {
			height = height - 16;
		}
		if(document.body.offsetHeight < initialDocLength + 20) { height = initialDocLength + 10; }
		if(height < MINHEIGHT) { height = MINHEIGHT; }
	}
	return height;
}

function GetWidth() {
	var width;
	if(ie) {
		width = document.body.offsetWidth;
		if(width < MINWIDTH - 7) {
			width = MINWIDTH;
			height = height - 16;
		}
	} else if(ns) {
		width = window.innerWidth;
		if (width < MINWIDTH - 7) {
			width = MINWIDTH;
			height = height - 16;
		}
	} else if(dhtml) {
		width = window.innerWidth;
		if (width < MINWIDTH - 7) {
			width = MINWIDTH;
			height = height - 16;
		}
	} else {
		width = document.body.offsetWidth;
		if(width < MINWIDTH - 7) {
			width = MINWIDTH;
			height = height - 16;
		}
	}
	return width;
}

function moveBorder() {
	width = GetWidth();
	height = GetHeight();
	
	if(ie) {
		document.all.pageVisitBar.style.top = height + "px";
		document.all.pageVisitBar.style.left = width - 200 - 28 + "px";
	} else if(ns) {
		document.layers.pageVisitBar.top = height;
		document.layers.pageVisitBar.right = 200 - 28;
	} else if(dhtml) {
		document.getElementById('pageVisitBar').style.top = height + "px";
		document.getElementById('pageVisitBar').style.left = width - 200 - 28 + "px";
	} else {
		document.all.pageVisitBar.style.top = height;
		document.all.pageVisitBar.style.left = width - 200 - 28;
	}
}

function posLayer(y, vis, t, l, z) {
	(vis == 1) ? y.visibility = "visible" : y.visibility = "hidden";
	(y < 0) ? y.bottom = -1 * t : y.top = t;
	(l < 0) ? y.right = -1 * l : y.left = l;
	y.zIndex = z;
}

function openwin(url, width, height, name){

	open_win = window.open(url, name, "fullscreen=no,toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,directories=no,location=no,width="+width+",height="+height+",left=0,top=0");

	return false;

}

function swapUpdate(newText, newActive, latestUpdate) {
	var latestUpdateText = "Latest Update . . . ";
	var pastUpdateText = "Past Update . . . ";
	
	if(oldActiveBracketName == "") {
		oldActiveBracketName = newActive;
	}
	if(ie) {
		document.all.updateTextBox.innerHTML = newText;
		document.all[oldActiveBracketName].innerHTML = document.all[oldActiveBracketName].innerHTML.replace(/leftNavBarCur/g, 'leftNavBarInactive');
		document.all[newActive].innerHTML = document.all[newActive].innerHTML.replace(/leftNavBarInactive/g, 'leftNavBarCur');
		if(latestUpdate == 0) {
			document.all.updateLine.innerHTML = latestUpdateText;
		} else {
			document.all.updateLine.innerHTML = pastUpdateText;
		}		
	} else if(ns) {
		document.layers.updateTextBox.innerHTML = newText;
		document.layers[oldActiveBracketName].innerHTML = document.layers[oldActiveBracketName].innerHTML.replace(/leftNavBarCur/g, 'leftNavBarInactive');
		document.layers[newActive].innerHTML = document.layers[newActive].innerHTML.replace(/leftNavBarInactive/g, 'leftNavBarCur');
		if(latestUpdate == 0) {
			document.layers.updateLine.innerHTML = latestUpdateText;
		} else {
			document.layers.updateLine.innerHTML = pastUpdateText;
		}
	} else if(dhtml) {
		document.getElementById('updateTextBox').innerHTML = newText;
		document.getElementById(oldActiveBracketName).innerHTML = document.getElementById(oldActiveBracketName).innerHTML.replace(/leftNavBarCur/g, 'leftNavBarInactive');
		document.getElementById(newActive).innerHTML = document.getElementById(newActive).innerHTML.replace(/leftNavBarInactive/g, 'leftNavBarCur');
		if(latestUpdate == 0) {
			document.getElementById('updateLine').innerHTML = latestUpdateText;
		} else {
			document.getElementById('updateLine').innerHTML = pastUpdateText;
		}
	} else {
		document.all.updateTextBox.innerHTML = newText;
		document.all[oldActiveBracketName].innerHTML = document.all[oldActiveBracketName].innerHTML.replace(/leftNavBarCur/g, 'leftNavBarInactive');
		document.all[newActive].innerHTML = document.all[newActive].innerHTML.replace(/leftNavBarInactive/g, 'leftNavBarCur');
		if(latestUpdate == 0) {
			document.all.updateLine.innerHTML = latestUpdateText;
		} else {
			document.all.updateLine.innerHTML = pastUpdateText;
		}
	}
	swapActiveBracket(newActive.replace(/\s+|,/g, ''), oldActiveBracketName.replace(/\s+|,/g, ''));
	oldActiveBracketName = newActive;
}