function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
addLoadEvent(initTabs);


// Tab menu functions by Jack Letourneau
// Modifications by Nick Momrik and Jason Carlin

function initTabs() {
	var tabList = cssQuery("li[class='tab']");
	for(i=0; i<tabList.length; i++){
		if(tabList[i].id.match(/\d/) == 1){
			switchOn(tabList[i]);
		}
	}
}

function switchOn(tab) {
	var tabName = tab.id;
	var tabGroup = (tabName).split(/-/)[0];
	var tabNum = (tabName).match(/\d/);
	switchAllOff(tabGroup);
	tab.className = 'selectedtab';
	document.getElementById(tabGroup+'-tabContents'+tabNum).className = 'tabselectedcontent';
}

function switchAllOff(tabGroup) {
	clearTop(tabGroup);
	clearContents(tabGroup);
}
function clearTop(tabGroup) {
	topRow = document.getElementById(tabGroup+'-tabs');
	tabArray = topRow.childNodes;
	for (var i=0; i<tabArray.length; i++) {
		tabArray[i].className = 'tab';
	}
}
function clearContents(tabGroup) {
	tabContents = document.getElementById(tabGroup+'-tabContents');
	contentsArray = tabContents.childNodes;
	for (var j=0; j<contentsArray.length; j++) {
		contentsArray[j].className = 'tabContent';
	}
}




// DYNAMIC COMMENT PREVIEW -- thanks to Mike Davidson and D. Keith Robinson

// live comment preview  - comment body
function ReloadTextDiv() {
	document.getElementById('TextDisplay').innerHTML = '<p>'+document.getElementById('text').value.replace(/(\r\n|\n)/g,'<br />').replace(/(<br \/>){2,}/gi,'<'+'/p><p>')+'<'+'/p>';
}

// live comment preview - author
function ReloadNameDiv() {
document.getElementById('NameDisplay').innerHTML = document.comments_form.author.value;
}

