<!--
try{
document.onclick = showID;
}catch(e){error=1;}
window.onerror=handlerFunction;
function handlerFunction(description, page, line) {
	error = "Caught error... \n\nDescription : "+description+" \nPage : "+page+" \nLine : "+line;
	//alert(error);
	return true;
}
function showID(){
	//try{blur();}catch(e){error=0;}
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function returnArrtib(element, attrib){
	for (i=0;i<element.attributes.length;i++) {
		if(element.attributes[i].name == attrib){return element.attributes[i].value; break;}
	}
}

function checkInput(element, type){
	var defaultvalue=''
	if (element.defaultValue) {
	 defaultvalue=element.defaultValue;
	}
	if(type == "blur" || type=="focus"){
		if(element.value == "") {element.value = defaultvalue;
		} else if (element.value==defaultvalue)
		{
			element.value = ""
		}
	}else{
		if(element.value == element.style.initialvalue){element.value = "";}
	}
}

function clearMissedFields(theForm){
	//This function checks all fields for initial values and removes them before submitting.
	for(x=0;x<theForm.elements.length;x++){
		if(theForm.elements[x].value == returnArrtib(theForm.elements[x], "initialvalue")){
			theForm.elements[x].value = "";
		}
	}
}


function formHandler(theForm){
	//The form object is passed this function (called theForm)
	//set error status variable
	formError = false;
	//loop through form elements array
	for(x=0;x<theForm.elements.length;x++){
		//check if field is mandatory
		attribs = "";
		if(theForm.elements[x].style.mandatory == "true"){
			//switch to detect form object type
			switch(theForm.elements[x].type){
				//any text object
				case 'text':
					//if value is blank
					if(theForm.elements[x].value == "" || theForm.elements[x].value == theForm.elements[x].style.initialvalue){
						alert("Please complete the "+theForm.elements[x].style.fullname+" field.");
						//set form error to prevent form submit
						formError = theForm.elements[x];
						break;
					}
					//if type = email run email check function
					if(theForm.elements[x].style.fieldtype == "email" && !varifyEmail(theForm.elements[x].value)){
						alert("The email address does not appear to be valid.");
						//set form error to prevent form submit
						formError = theForm.elements[x];
						break;
					}
					//if type = number run numeric regualr expression function
					if(theForm.elements[x].style.fieldtype == "number" && !varifyNumber(theForm.elements[x].value)){
						alert("The "+theForm.elements[x].fullName+" field must only contain numbers and spaces.");
						//set form error to prevent form submit
						formError = theForm.elements[x];
						break;
					}
				break;
				//any text-area
				case "textarea":
					if(theForm.elements[x].value == ""  || theForm.elements[x].value == theForm.elements[x].style.initialvalue){
						alert("Please complete the "+theForm.elements[x].style.fullname+" field.");
						//set form error to prevent form submit
						formError = theForm.elements[x];
						break;
					}
				break;
				//any select drop-down
				case "select-one":
					if(theForm.elements[x].options[theForm.elements[x].selectedIndex].value == ""){
						alert("Please select an option from the "+theForm.elements[x].style.fullname+" menu.");
						//set form error to prevent form submit
						formError = theForm.elements[x];
						break;
					}
				break;
			}
		//if form error, break the from loop
		if(formError){break}
		}
	}
	//if no errors, submit
	if(!formError){
		clearMissedFields(theForm);
		theForm.submit();
	}else{
		formError.focus();
	}
}

function varifyEmail(string){
	//set error status variable.
	varified = false;
	//check string for @ sign after 1 character
	if(string.indexOf("@") >= 1){
		//if found, split string into array using the @ sign
		emailArray = string.split("@");
		//check 2nd array index for full-stop after 1 character, and set varified var as true (varified!)
		if(emailArray[1].indexOf(".") >= 1 && emailArray[1].indexOf(".") < emailArray[1].length-1){varified = true;}
	}
	return varified;
}

function varifyNumber(string){
	//set regular expression - 0 to9 and space
	numericExp = RegExp("[0-9 ]");
	//loop through each character of the string
	for(x=0;x<string.length;x++){
		//if a char is found that is not in the regular expression, return false (stops function at this point)
		if(!numericExp.test(string.substr(x,1))){
			return(false);
			break;
		}
	}
	//if no errors, returns true
	return(true);
}

function formElementFocus(formID, elementID){
	theForm = MM_findObj(formID);
	theElement = eval("theForm."+elementID);
	theElement.focus();
}

function checkUserType(){
	userTypeDiv = new Array('pupilLogin','teacherLogin');
	radioBtn = MM_findObj("createUserForm").userType
	for(x=0;x<radioBtn.length;x++){
		MM_findObj(userTypeDiv[x]).style.display = "none";
		if(radioBtn[x].checked){
			MM_findObj(userTypeDiv[x]).style.display = "block";
		}
	}
}
function checkLoginInput(form){
	formError = 0;
	radioBtn = form.userType;
	if(radioBtn[0].checked && formError == 0){
		firstname = form.firstname.value;
		if(firstname == ""){alert("Please enter your first name.");formError = 1;}
		if(firstname.length > 0 && firstname.length < 2 && formError == 0){alert("Please enter a name with a minimum of 2 characters.");formError = 1;}
	}
	if(radioBtn[1].checked || formError == 0){form.submit();}
}
-->