//Js Include File
//Contains the standard functions, such as form validators
	document.onkeydown = function () {
	if(document.all){
		if(event.keyCode == 116){
			event.keyCode = 0;
			event.returnValue = false;
			event.cancelBubble = true;
			
			//reload the main page
			if(!top.name.length){
				if(top.frames.length){
					top.frames["main"].location.reload();
				}else{
					self.document.location.reload();
				}
			}else{
				self.document.location.reload();
			}
			
			return false;
		}
	}
  }

function isEmpty(value2check){

	if (value2check == "" || value2check == null){
		return true;
	}
	//nice bit of regexp!
	var nonSpaceCharacters = /\w/
	hasCharacters = nonSpaceCharacters.exec(value2check)
	if (hasCharacters == null){
		return true;
	}
		return false;
} //isEmpty
function isInteger(checkValue){
	if (isNaN(checkValue)){
		return false;
	}
	if (checkValue.indexOf('.') > -1){
		return false;
	}
	return true;
} //isInteger

function MM_swapImgRestore(){
  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 MM_swapImage(){
  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_findObj(n, d){
  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); return x;
}
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 coords(){
	this.x;
	this.y;
	this.width;
	this.heigth;
	this.calculate = function(){
		var intWidth = this.width;	
		var intHeight = this.height;
		if (navigator.appName=="Netscape")
		{
			intTopDiff=(screen.height/10);
			intXPos=(screen.width/2)-(intWidth/2);
			intYPos=((screen.height/2)-(intHeight/2))-intTopDiff;
	
		}
		else
		{
			intXPos=(screen.availWidth/2)-(intWidth/2);
			intYPos=(screen.availHeight/2)-(intHeight/2);
		}
			
		this.x=intXPos>0?intXPos:0;
		this.y=intYPos>0?intYPos:0;
	}
}

function openWindow(url,height,width,winObj){
	
	var objCoords = new coords();
	objCoords.width = width;
	objCoords.height = height;
	objCoords.calculate();
	
	var intXPos = objCoords.x;
	var intYPos = objCoords.y;

	strProperties="location=no,menubar=no,resizable=yes,status=no,toolbar=no,titlebar=no,";
	strProperties+="directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos;
	strProperties+=",screenY="+intYPos+",top="+intYPos+",width="+width+",height="+height;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
}

function openWindowWithMenu(url,height,width,winObj){
	var objCoords = new coords();
	objCoords.width = width;
	objCoords.height = height;
	objCoords.calculate();
	
	var intXPos = objCoords.x;
	var intYPos = objCoords.y;
	
	strProperties="location=no,menubar=yes,resizable=yes,status=no,toolbar=no,titlebar=no,";
	strProperties+="directories=no,scrollbars=yes,toolbar=0,screenX="+intXPos+",left="+intXPos;
	strProperties+=",screenY="+intYPos+",top="+intYPos+",width="+width+",height="+height;
	winObj=window.open(url,"" + winObj + "",strProperties);
	winObj.focus();
	
}
function setStatus(msg){
	status=msg;
	return true;
}
function validateDate(dateIn,monthIn,yearIn, strName){
	if (parseInt(yearIn, 10)  < 1753) {
		alert("You've entered a year earlier than 1753. Unfortunately we can only support dates after 1753, because this is when the Gregorian and Julian calendars were synchronized! Please re-enter a more recent date.")
		return false
	}

	if (dateIn.length==1){
		dateIn = "0" + dateIn
	}
	
	if (monthIn.length==1){
		monthIn = "0" + monthIn
	}

	var textStr = dateIn+"/"+monthIn+"/"+yearIn
	
	var chkDate=new Date()
	
	if(dateIn.indexOf("0") == 0){
		dateIn = dateIn.substring(1)
	}

	if(monthIn.indexOf("0") == 0){
		monthIn = monthIn.substring(1)
	}
	
	chkDate.setMonth((parseInt(monthIn)-1),(parseInt(dateIn)))
	chkDate.setFullYear(parseInt(yearIn))
	
	var chkMonthInt  = chkDate.getMonth()+1
	var chkMonthStr = chkMonthInt+"/"
	if (chkMonthStr.length == 2){
		chkMonthStr = "0"+chkMonthStr
	} 
	
	var chkDateInt = chkDate.getDate()
	var chkDateStr = chkDateInt+"/"
	if (chkDateStr.length == 2){
		chkDateStr = "0"+chkDateStr
	}

	var cmpDate=chkDateStr+chkMonthStr+(chkDate.getFullYear())
	
	if (cmpDate.length != 10){
		alert("You've entered a " + strName + " that does not exist or used an invalid date format.  Please use the dd/mm/yyyy format.");
		return false;
	}
	else {
		if (textStr!=cmpDate){
			alert("You've entered a " + strName + " that does not exist or used an invalid date format.  Please use the dd/mm/yyyy format.");
			return false;
		}
		else {
			if (cmpDate=="NaN/NaN/NaN"){
				alert("You've entered a " + strName + " that does not exist or used an invalid date format.  Please use the dd/mm/yyyy format.");
				return false;
			}
		}
	}
	return true;
}
function setValue(formName, formItem, value){
	objField = eval('document.' + formName + '.' + formItem)
	if (objField){
		for (i=0; i < objField.options.length; i++){
			if (objField.options[i].value == value){
				objField.options[i].selected = true	
			}
		}
	}
}

/* flipDisplay() & flipImage() added (copied from monster.dev) by Tom 09/02/04 */

	function createImage( s )
	{
		var objImage = new Image();
			objImage.src = s;
	
		return( objImage );
	}
	
	var agt = navigator.userAgent.toLowerCase();	
	var agt = navigator.userAgent.toLowerCase();
	var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
	            && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
	            && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
	
	function flipDisplay()
	{
	
		if(document.getElementById("displayTutor").style.display == "none"){
			document.getElementById("displayTutor").style.display = ""
		}else{
			document.getElementById("displayTutor").style.display = "none"
		}
		/*
		var arrRows = new Array("displayTutor");
		var objCurrentStyle;
		
		if ( !is_nav )
		{
			for ( var j=0; j<arrRows.length; j++ )
			{
				
				objCurrentStyle = document.getElementById(arrRows[j]).style;
				
				alert(objCurrentStyle)
				
				if ( objCurrentStyle.display == "" )
				{
					objCurrentStyle.display = "none"; //hide <tr> row
				}
				else
				{
					objCurrentStyle.display = ""; //display <tr> row
				}
			}
		}
		*/
		flipImage();
	}
	
	var imgExpand = createImage("/images/icons/plus.gif");
	var imgCollapse = createImage("/images/icons/minus.gif");
	
	function flipImage(){
		if (document.images["flip"].src.indexOf("plus") > 1){
			document.images["flip"].src = "/images/icons/minus.gif";
		}else{
			document.images["flip"].src = "/images/icons/plus.gif";
		}
	}

function textCounter(objField, intMaxChars){
	if (objField.value.length > intMaxChars){ 
		objField.value = objField.value.substring(0, intMaxChars);
		return false;
	}
	return true;	
}

// --- SWAPS HELP LINK AT TOP OF PAGE IF AVAILABLE

function toggle(obj){

	var objID = document.getElementById(obj);
	objID.style.display = (objID.style.display == "none")?"":"none";
		  
	var now = new Date();
	now.setTime(now.getTime() + 1000 * 60 * 60 * 24 * 365 * 5) 
	setCookie("helpdisplay",objID.style.display, now, "/");
	
	if(getText("HelpLink")=="Hide Help"){
		changeText("Show Help","HelpLink")
	} else {
		changeText("Hide Help","HelpLink")
	}
}		

function changeText(inText, inTarget) {
			
	  if (document.getElementById) {
		document.getElementById(inTarget).innerHTML = inText;
	  }
	  else if (document.all) {
		document.all[inTarget].innerHTML = inText;
	  }
}

function getText(inTarget) {
			
	  if (document.getElementById) {
		return document.getElementById(inTarget).innerHTML;
	  }
	  else if (document.all) {
		return document.all[inTarget].innerHTML
	  }
}

function setCookie(name, value, expires, path, domain, secure){
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "")
        //((domain) ? "; domain=" + domain : "") +
        //((secure) ? "; secure" : "");
}
function selectAction( field ){
	performAction(field.options[field.selectedIndex].value)
	field.selectedIndex = 0
}
//evalutates a passed string as javascript,
//mostly used with select lists n stuff
function performAction(inStr){
	if (inStr != "null"){
		eval(inStr);
	}
}