/// addLoadEvent, for queuing window.onload init functions
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		};
	};
};


//Insert Items after specified tag
function insertAfter(newElement, targetElement) {
	var parent = targetElement.parentNode;
	if (parent.lastChild == targetElement) {
		parent.appendChild(newElement);
	} else {
		parent.insertBefore(newElement, targetElement.nextSibling);
	}
}

function addClass(element, value) {
	if(!element.className) {
		element.className = value;
	} else {
		newClassName = element.className;
		newClassName+= " ";
		newClassName+= value;
		element.className = newClassName;
	}
}


//Opens Pop Up window
function popUpLinks() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		if (links[i].className == "popup") {
			links[i].onclick = function() {
			popUp(this.getAttribute("href"));
			return false; 
			};

		}
	}
}
addLoadEvent(popUpLinks);

//Popup window attributes
function popUp(winURL) {
	window.open(winURL, "popup", "width=860, height=670");
}

//Opens New window
function externalLinks() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		if (links[i].className == "newwindow") {
			links[i].target = "_blank";
		}
	}
}
addLoadEvent(externalLinks);


//Bookmark this page
function bookmarkLink() {
	if (!document.getElementsByTagName) return false;
	var links = document.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		if (links[i].className == "bookmark") {
			links[i].onclick = function() {
			bookmark(this.getAttribute("href"), this.getAttribute("title"));
			return false; 
			};

		}
	}
}
addLoadEvent(bookmarkLink);

function bookmark(url, description) { 
	var netscape="Netscape User's hit CTRL+D to add a bookmark to this site."
	if (navigator.appName=='Microsoft Internet Explorer') {
		window.external.AddFavorite(url, description);
	} else if (navigator.appName=='Netscape') {
		alert(netscape);
	}
}


//Add alternate colours to the rows
function altTables() {
	if (document.getElementById("timetable")) {
		var tables = document.getElementsByTagName("table");
		for (var i=0; i<tables.length; i++) {
			var odd = false;
			var rows = tables[i].getElementsByTagName("tr");
			for (var j=0; j<rows.length; j++) {
				if (odd == true) {
					addClass(rows[j],"odd");
					odd = false;
				} else {
					odd = true;
				}
			}
		}
	}
}
addLoadEvent(altTables);


/*font resizer*/
var min=8;
var max=18;
function increaseFontSize() {
   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=max) {
         s += 1;
      }
      p[i].style.fontSize = s+"px"
   }
}

function decreaseFontSize() {
   var p = document.getElementsByTagName('body');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s = 12;
      }
      if(s!=min) {
         s -= 1;
      }
      p[i].style.fontSize = s+"px"
   }   
}

function changeFontSize() {
    if(!document.getElementById("fontIncrease")) return false;
	if(!document.getElementById("fontDecrease")) return false;
	var buttonIncrease = document.getElementById("fontIncrease");
	var buttonDecrease = document.getElementById("fontDecrease");
	buttonIncrease.onclick = function() {
		increaseFontSize();
	 	 return false;	  
	}
	buttonDecrease.onclick = function() {
		decreaseFontSize();
		  return false;	  
	}
}
addLoadEvent(changeFontSize);


/*Print Button*/
function printButton() {
return false;
//	if(!document.getElementById("print")) return false;
//	var printbutton = document.getElementById("print");
//	printbutton.onclick = function() {
//		prePrint();
//		return false;
//	}
}
addLoadEvent(printButton);

function prePrint() {
	if (window.print) window.print();
	else if (VBS) printIt();
	else alert('This script does not work in your browser');
}

function backButton() {
	if(!document.getElementById("back")) return false;
	var backbutton = document.getElementById("back");
	backbutton.onclick = function() {
		history.back()
		return false;
	}
}
addLoadEvent(backButton);





//SHOW HIDE TOGGLE SCRIPT
function showSection(id) {
	var divs = document.getElementsByTagName("div");
	for (var i=0; i<divs.length; i++) {
		if (divs[i].className.indexOf("summary") == -1) continue;
		if (divs[i].getAttribute("id") != id) {
			divs[i].style.display = "none";
		} else {
			divs[i].style.display = "block";
		}
	}
}

//find id on click and send to showSection function
function showHideNav() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("option")) return false;
	var nav = document.getElementById("option");
	var links = nav.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		var sectionId = links[i].getAttribute("href").split("#")[1];
		if (!document.getElementById(sectionId)) continue;
		document.getElementById(sectionId).style.display = "none";
		links[i].destination = sectionId;
		links[i].onclick = function() {
			deactivate();
			this.style.backgroundPosition = "0px 0px";
			showSection(this.destination);
			return false;
		}
	}
}
addLoadEvent(showHideNav);

function deactivate() {
	var nav = document.getElementById("option");
	var links = nav.getElementsByTagName("a");
	for (var i=0; i<links.length; i++) {
		links[i].style.backgroundPosition = "0px -22px";
	}
}
	

//On load show the one specified section
function showStartSection() {
	if (!document.getElementById('publication')) return false;
	var publication = document.getElementById('publication');
	publication.style.backgroundPosition = "0px 0px";	
	publication.style.display = "block";	
}
addLoadEvent(showStartSection);


//Rollover Submit Buttons
function submitOver(form, element) {
	if (!document.getElementById(form)) return false;
	var emailupdates = document.getElementById(form);
	var button = emailupdates.getElementsByTagName(element);
	for (var i=0; i<button.length; i++) {	
		button[i].onmouseover = function() {
			this.style.backgroundPosition = "0px -13px";
		}
		button[i].onmouseout = function() {
			this.style.backgroundPosition = "0px 0px";
		}
	}
}


function targetForms() {
	submitOver("emailupdate","button");
	submitOver("request","button");
}
addLoadEvent(targetForms);


function TextFocus(ctrl, searchText)
{if (ctrl.value == searchText){ctrl.value=''}}
function TextBlur(ctrl, searchText)
{if (ctrl.value ==''){ctrl.value=searchText}}

function printMe(contentID){
  var javascript_version = 1.1;
  var lWinLeft = (screen.width - 750) / 2;
  var lWinTop = (screen.height - 500) / 2;
  var url = '../PrintMe.aspx?ContentID=' + contentID;
  oWindow = window.open(url, 'print', ('width=750,height=500,resizable=yes,scrollbars=yes,menubar=yes,status=yes,top=' + lWinTop + ',left=' + lWinLeft));
    if(javascript_version > 1.0 && navigator.appVersion.indexOf("MSIE 4") == -1){
      setTimeout('oWindow.focus();',250);}}