/* Created by Rahul Banerjee '10 for the Chattertocks. rahul att brown dott edu */

function addOnload(func) { //let a function execute once the page has loaded
	if(window.addEventListener) window.addEventListener('load',func,true); //real browsers
	else if(window.attachEvent) window.attachEvent('onload',func); //stupid Internet Exploder
}

function ajax() { //create an AJAX variable (AJAX lets you fetch php/database data without reloading the page
	var http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) http_request.overrideMimeType('text/html');
	} else if (window.ActiveXObject) { // IE
		try {http_request = new ActiveXObject("Msxml2.XMLHTTP");}
		catch (e) {
			try {http_request = new ActiveXObject("Microsoft.XMLHTTP");}
			catch (e) {
				alert('Sorry, please update your browser in order to view the Chattertocks website.');
			}
		}
	}
	return http_request;
}

var url_pattern = /^(.+Chattertocks\/)(.+\.php)?.*$/;
var url_matches = document.URL.match(url_pattern);
var _ROOT = url_matches[1];
var _PAGE = url_matches[2] || 'home.php';
addOnload(makeNavmenuBold);
function makeNavmenuBold() {
	var topLinks = document.getElementById('navmenu').getElementsByTagName('a');
	for(var i=0; i<topLinks.length; i++) {
		if(topLinks[i].getAttribute('href').indexOf(_PAGE) > -1) topLinks[i].className = 'selected';
		if(i == 0 && _PAGE == 'home.php') topLinks[i].className = 'selected';
	}
	var bottomLinks = document.getElementById('bottom_container').getElementsByTagName('a');
	for(var j=0; j<bottomLinks.length; j++) {
		if(bottomLinks[j].getAttribute('href').indexOf(_PAGE) > -1) bottomLinks[j].className = 'selected';
		if(j == 0 && _PAGE == 'home.php') bottomLinks[j].className = 'selected';
	}
}