// JavaScript Document

function init () {

	if (!document.getElementById) {

		for (i=0;i<document.styleSheets.length;i++) {

			document.styleSheets(i).disabled = true;

		}

	}

}



function showTab(show,hide) {

	hideContent = document.getElementById(hide);

	hiddenContentLink = document.getElementById(hide+'-link');

	showContent = document.getElementById(show);

	visibleContentLink = document.getElementById(show+'-link');

	hideContent.style.display = 'none';

	hiddenContentLink.className = '';

	showContent.style.display = 'block';

	visibleContentLink.className = 'active';

	visibleContentLink.blur();	

}

function hem(id,text) {

	if(id!="" || text!="") {

		id_a = id.split(".");

		str = "";

		for(i=0;i<id_a.length;i++) {

			str += String.fromCharCode(id_a[i]/5);

		}

		str2 = text == "" ? str : text;

		return "<a href=\"mailto:" + str + "\">" + str2 + "</a>";

	} else {

		return "";

	}

}

error_msg = " -- error: required field -- ";

function checkform(action,name) {

	var error=false;

	for(i=0;i<document.forms[name].length-2;i++) {

		if(document.forms[name].elements[i].getAttribute('rel')!="optional") {

			if(document.forms[name].elements[i].value=="" || document.forms[name].elements[i].value==error_msg) {

				document.forms[name].elements[i].style.border='solid #FF0000 1px';

				document.forms[name].elements[i].style.borderColor='#FF0000';

				if(document.forms[name].elements[i].type!="file" && document.forms[name].elements[i].type!="password" && action!='rec_form') {

					document.forms[name].elements[i].value=error_msg;

				} else if(document.forms[name].elements[i].type=="file"){

					alert ("The highlighted file field does not containt a path to your file.");

				} else if(document.forms[name].elements[i].type=="password"){

					alert ("The highlighted field is empty.");

				}

				error=true;

			} else if(document.forms[name].elements[i].id=="email") {

				mail_str = document.forms[name].elements[i].value;

				if(mail_str.indexOf(".", mail_str.indexOf("@")) < mail_str.indexOf("@") + 2

					|| mail_str.indexOf(".") < 1

					|| mail_str.indexOf(".") > mail_str.length-2

					|| mail_str.indexOf("@") < 1

					|| mail_str.indexOf("@") > mail_str.length-2)

					{

					error = true;

					document.forms[name].elements[i].style.borderColor='#FF0000';

					document.forms[name].elements[i].value="-- error: invalid email address --";

				}

				

			} else {

				document.forms[name].elements[i].style.borderColor='#C9D8D3';

				if(action=='rec_form') {

					document.forms[name].elements[i].style.border='solid #000000 0px';

				}

			}

		}

	}

	

	if(error) {

		alert("Please ensure that all highlighted fields are completed.");

		return false;

	}



}



function clear_error(field) {

	if(field.value==error_msg || field.value=='-- error: invalid email address --') {

		field.value="";

	}

}

function update_breadcrumbs(xml) {

   document.getElementById('breadcrumbs').innerHTML = xml;



}

function bio_change() {

	if(document.getElementById('bio_fr').style.display=='none' || document.getElementById('bio_fr').style.display=='') {

		document.getElementById('bio_en').style.display='none';

		document.getElementById('bio_fr').style.display='block';

		document.getElementById('bio_fe').innerHTML='<a onclick="bio_change()" href="#">English</a> | French'

	} else {

   		document.getElementById('bio_en').style.display='block';

		document.getElementById('bio_fr').style.display='none';

		document.getElementById('bio_fe').innerHTML='English | <a onclick="bio_change()" href="#">French</a>'

	}

}



/* This function comes from a post on hotscripts.com forums */

function reposition(){

	var el = document.getElementById("course_nav");


	var ScrollTop = document.body.scrollTop;

	if (ScrollTop == 0)

	{

		if (window.pageYOffset)

			ScrollTop = window.pageYOffset;

		else

			ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;

	}

	if(ScrollTop < 362)

		el.style.top = 362 - ScrollTop + "px";

	else

		el.style.top = "0px";

}





var lastElement = "";

function toggleElement(elementID) {
	currEl = document.getElementById(elementID);
	if (lastElement != "") {
		var elJustHidden = false;
		if (lastElement.style.display != "none") {
			lastElement.style.display = "none";
			elJustHidden = true;
		}
		if (lastElement.id != elementID) {
			currEl.style.display = "block";
		}
		else if (lastElement.style.display == "none" && !elJustHidden) {
			currEl.style.display = "block";
		}
	}
	else {
		currEl.style.display = "block";
	}

	lastElement = currEl;
}
