/// begin disable right click for images ////

/*
Disable right click script II (on images)- By Dynamicdrive.com
For full source, Terms of service, and 100s DTHML scripts
Visit http://www.dynamicdrive.com
*/

var clickmessage="Right click is disabled on images"

function disableclick(e) {
if (document.all) {
if (event.button==2||event.button==3) {
if (event.srcElement.tagName=="IMG"){
alert(clickmessage);
return false;
}
}
}
else if (document.layers) {
if (e.which == 3) {
alert(clickmessage);
return false;
}
}
else if (document.getElementById){
if (e.which==3&&e.target.tagName=="IMG"){
alert(clickmessage)
return false
}
}
}

function associateimages(){
for(i=0;i<document.images.length;i++)
document.images[i].onmousedown=disableclick;
}

if (document.all)
document.onmousedown=disableclick
else if (document.getElementById)
document.onmouseup=disableclick
else if (document.layers)
associateimages()

/// end disable right click for images ////

/// open new window ///
function openWin (fileName, windowName) { window.open(fileName,windowName,',,,,,,,,'); } 

////check Past Pupils form /////////
function checkYears() {

if ((document.pastpupilsform.FirstName.value == "") || (document.pastpupilsform.Email.value == "") || (document.pastpupilsform.Surname.value == "") || (document.pastpupilsform.YearLeft.selectedIndex == 0) || (document.pastpupilsform.YearJoined.selectedIndex == 0)) {
		alert('Please enter your First Name, Surname, Email and the years you joined and left.');
		return false;
	}
	else {
	return true;
}	

//validate email address
var emailFilter=/^.+@.+\..{2,3}$/;
if (!(emailFilter.test(document.pastpupilsform.Email.value))) { 
		alert('Please enter a valid email address');
		return false;
}	
//make sure year they left is later than year they joined
if ((document.pastpupilsform.YearLeft.selectedIndex < document.pastpupilsform.YearJoined.selectedIndex)) {
		alert('Please make sure the year you left is not earlier than the year you joined.');
		return false;
}

	else {
	return true;
}
}

///////check search field//////////
function checkSearch() {
	if ((document.pastpupils.searchfield.value == " ") || (document.pastpupils.searchfield.value == "Enter Surname Only")) {
		alert('Please enter a Surname');
			   return false;
	}
	else {
		return true;
	}
}
///////// form field highlight colour /////////
var highlightcolor="#EAE0CC"

var ns6=document.getElementById&&!document.all
var previous='#EAE0CC'
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}

function checkSearchField() {
	if (document.pastpupils.searchfield.value == "") {
	document.pastpupils.searchfield.value = "Enter Surname Only";
	document.pastpupils.searchfield.style.backgroundColor = "#EAE0CC";
	}

}

///////////////// text field counter
function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

 ///////// Side Menu Mouse Over Functions ///////////
 	var isIE4 = false;
	function CheckBrowser() 
	{ if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.charAt(0) >= 4) { isIE4 = true; }}
	function mOvr(src,clrOver)
	{ if (!src.contains(event.fromElement)) { src.style.cursor = 'hand'; src.bgColor = clrOver; src.children.tags('A')[0].style.color = '#333333';}}
	function mOut(src,clrIn) 
	{ if (!src.contains(event.toElement)) { src.style.cursor = 'default'; src.bgColor = clrIn;  src.children.tags('A')[0].style.color = '#333333';}}
	function mClk(src) 
	{ if(event.srcElement.tagName=='TD'){src.children.tags('A')[0].click();} }
	function mOvrTop(src,clrOver)
	{ if (!src.contains(event.fromElement)) { src.style.cursor = 'hand'; src.bgColor = clrOver;}}
	function mOutTop(src,clrIn) 
	{ if (!src.contains(event.toElement)) { src.style.cursor = 'default'; src.bgColor = clrIn;}}
 
 ///////// Macromedia Scripts /////////

///////// Macromedia Scripts /////////
 
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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 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_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_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_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' \n'; }
  } if (errors) alert('The following information is required:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

///////// form field highlight colour /////////
var highlightcolor="#FFFFFF"

var ns6=document.getElementById&&!document.all
var previous=''
var eventobj

//Regular expression to highlight only form elements
var intended=/INPUT|TEXTAREA|SELECT|OPTION/

//Function to check whether element clicked is form element
function checkel(which){
if (which.style&&intended.test(which.tagName)){
if (ns6&&eventobj.nodeType==3)
eventobj=eventobj.parentNode.parentNode
return true
}
else
return false
}

//Function to highlight form element
function highlight(e){
eventobj=ns6? e.target : event.srcElement
if (previous!=''){
if (checkel(previous))
previous.style.backgroundColor=''
previous=eventobj
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
}
else{
if (checkel(eventobj))
eventobj.style.backgroundColor=highlightcolor
previous=eventobj
}
}


///////// status bar note /////////
//var note = "Coolmine Community School | Creideamh Beo";
//function statusbar()
//{
//  defaultStatus = note.substr()
//}
//statusbar();


///////// clear default form value /////////
function clearDefault(el) {
  if (el.defaultValue==el.value) el.value = ""
} 

function checkSearchField() {
	if (document.searchform.searchfield.value == "") {
	document.searchform.searchfield.style.backgroundColor = "#D9DDE1";
	document.searchform.searchfield.value = "Enter Search Words";
	}

}

function checkSearchField2() {
	if (document.pastpupils.searchfield2.value == "") {
	document.pastpupils.searchfield2.style.backgroundColor = "#EAE0CC";
	document.pastpupils.searchfield2.value = "Enter Surname Only";
	}

}


//////////// Flash Search Field ////////////////
function checkData()
{
	if((document.searchform.searchfield.value.length == 0) || (document.searchform.searchfield.value == "Enter Search Words"))
	{
		flash("searchfield");
		document.searchform.searchfield.value = '';
		return false;
	}
	return true;
}

function checkData2()
{
	if((document.pastpupils.searchfield2.value.length == 0) || (document.pastpupils.searchfield2.value == "Enter Surname Only"))
	{
		flash("searchfield2");
		document.pastpupils.searchfield2.value = '';
		return false;
	}
	return true;
}

///////////flash field function/////////
$ = function(el){ return document.getElementById(el); }
var flashTimer = null;
var flashState = flashCount = 0;

function flash(el)
{
	if(flashState == 1)
	{
		$(el).style.backgroundColor = "#FFFFFF";
		flashState = 0;
	}
	else
	{
		$(el).style.backgroundColor = "#666666";	
		flashState = 1;
	}
	
	if(flashCount == 5)
	{
		$(el).focus();
		clearTimeout(flashTimer);
		flashCount = flashState = 0;
	}
	else
	{
		flashTimer = setTimeout("flash('"+el+"')",50);
		flashCount++;
	}
	
}

///////// random number function /////////
function randomNumber(limit){
  return Math.floor(Math.random()*limit);
}