var section;
var popup;

browsver = navigator.appVersion.toLowerCase();
browsvernum = parseInt(navigator.appVersion);
browsname = navigator.appName;
browsagt = navigator.userAgent.toLowerCase();


function initpage() {
	theheader = document.getElementById("header");
	theleftcol = document.getElementById("leftcolumn");
	thebodycol1 = document.getElementById("bodycolumn1");
	thebodycol2 = document.getElementById("bodycolumn2");
	
	if (popup != true) {
		if (theheader.addEventListener) {
			theheader.addEventListener("mouseover", hideall, true);
		}
		else if (theheader.attachEvent) {
			theheader.attachEvent("onmouseover", hideall);
		}
		if (theleftcol.addEventListener) {
			theleftcol.addEventListener("mouseover", hideall, true);
		}
		else if (theleftcol.attachEvent) {
			theleftcol.attachEvent("onmouseover", hideall);
		}
		if (thebodycol1.addEventListener) {
			thebodycol1.addEventListener("mouseover", hideall, true);
		}
		else if (thebodycol1.attachEvent) {
			thebodycol1.attachEvent("onmouseover", hideall);
		}
		if (thebodycol2.addEventListener) {
			thebodycol2.addEventListener("mouseover", hideall, true);
		}
		else if (thebodycol2.attachEvent) {
			thebodycol2.attachEvent("onmouseover", hideall);
		}
	}
}


function resizecols() {
	if (popup != true) {
		col1 = document.getElementById('navigation');
		col2 = document.getElementById('bodycolumn1');
		col3 = document.getElementById('bodycolumn2');
		col4 = document.getElementById('bodycolumn3');

		htdiff1 = 23; // col1 top - col2 top
		htdiff2 = 20; // col1 padding-bottom
		htdiff3 = 5; // col2 margin-bottom (if col4)

		if (col4) {
			sizearr = new Array();
			sizearr.push(col2.offsetHeight);
			if (col3) {
				sizearr.push(col3.offsetHeight);
			}

			sizearr.sort(function(a,b){return b - a})
			col2.style.height = sizearr[0] + 'px';
			if (col3) {
				col3.style.height = sizearr[0] + 'px';
			}

			sizearr = new Array();
			sizearr.push(col1.offsetHeight + htdiff1);
			sizearr.push(col2.offsetHeight + col4.offsetHeight + htdiff3);

			sizearr.sort(function(a,b){return b - a})
			col1.style.height = ((sizearr[0] - htdiff1) - htdiff2) + 'px';
			col4.style.height = ((sizearr[0] - col2.offsetHeight) - htdiff3) + 'px';
		}
		else {
			sizearr = new Array();
			sizearr.push(col1.offsetHeight + htdiff1);
			sizearr.push(col2.offsetHeight);
			if (col3) {
				sizearr.push(col3.offsetHeight);
			}

			sizearr.sort(function(a,b){return b - a})
			col1.style.height = ((sizearr[0] - htdiff1) - htdiff2) + 'px';
			col2.style.height = sizearr[0] + 'px';
			if (col3) {
				col3.style.height = sizearr[0] + 'px';
			}
		}
	}
}


function resizeform() {
	if (popup != true) {
		col1 = document.getElementById('formframe');
		col2 = document.getElementById('formdummy');

		htdiff = 50; // extra padding around form
		sizearr = new Array();
		colht = col2.offsetHeight + htdiff;

		col1.style.height = colht + 'px';
	}
}


if(popup != true) {
	self.name = "mainwin";
	window.onload=function() {
		if (document.getElementById) {
			initpage();
			if (document.getElementById('formframe') && document.getElementById('formdummy')) {
				//resizeform();
			}
			resizecols();
		}
	}
}

function hideall() {
	showhide('null','null');
}

function showhide(thisel,thisnum) {
	if (thisel == "nav" || thisel == "null") {
		showhide('team','null');
		for (i=0; i<nav_arr.length; i++) {
			if (nav_arr[i] == thisnum) {
				document.getElementById("subnav" + nav_arr[i]).style.display = "block";
			}
			else {
				document.getElementById("subnav" + nav_arr[i]).style.display = "none";
			}
		}
	}
	if (thisel == "team" || thisel == "null") {
		for (i=0; i<teams_arr.length; i++) {
			thisnav = document.getElementById("subnav1_team" + teams_arr[i]);
			thismenu = document.getElementById("subnav2_team" + teams_arr[i]);
			if (teams_arr[i] == thisnum) {
				if (thisnav && thismenu) {
					thisnav.style.color = "#FFFFFF";
					thisnav.style.background = "url(http://athletics.bard.edu/images/bg_subnav_ro.jpg) no-repeat left center";
					thisnav.style.borderWidth = "0px 0px 0px 0px";
					thismenu.style.display = "block";
				}
			}
			else {
				if (thisnav && thismenu) {
					thisnav.style.color = "#333333";
					thisnav.style.background = "url(http://athletics.bard.edu/images/bg_subnav.gif) no-repeat left bottom";
					thisnav.style.borderWidth = "0px 1px 0px 0px";
					thismenu.style.display = "none";
				}
			}
		}
	}
}






var caltext = "calendartext";
var calshell = "calendar";

function createRequest() {
	var request = null;
	if (window.XMLHttpRequest) {
		request = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return request;
	if (request == null) {
		alert("Browser does not support HTTP Request.");
	}
}

function changecal(url) {
	document.getElementById(caltext).innerHTML = "<p style=\"text-decoration: blink;\"><b><i>Loading new dates...</i></b><br /><br /><br /></p>";
	request = createRequest();
	request.open("GET", url, true);
	request.setRequestHeader('Content-Type', 'text/xml');
	request.onreadystatechange = newcal;
	request.send(null);
}

function newcal() {
	caldiv = document.getElementById(calshell);
	if (request.readyState == 4) {
		response = request.responseText;
		caldiv.innerHTML = response;
	}
}





function popup(loc,win,atts) {
	thisatts = "location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=774,height=500" + "," + atts;
	window.open(loc,win,thisatts);
}

