// JavaScript Document

<!--

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_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_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_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+' is required.\n'; }
  } 
  
  // Modified the standard dreamweaver script to call MM_ValidateSurvey to check survey fields
  // Darren Rollett, 28 September 2004
  
  // If error with required information the display error and return.
  // If no errors then check survey information.
  if (errors) {
  	alert('The following error(s) occurred:\n'+errors);
  }
  else
  {
	MM_ValidateSurvey();
	  
	// If we get an error set the local error variable to something meaningful.
	if (document.MM_returnValue) { errors = 'Missing volunteer information\n'; }
  }  
  document.MM_returnValue = (errors == '');
}

function MM_ValidateSurvey() {
// Validate Survey Required Information
// Author: Darren Rollett
// Date: 28 September 2004
// Copyright 2004 Room 108 Limited, All rights reserved.


	var errors=''; // Used to store error text
	var flagError = false; // Used to indicate if more information is required
	var objCheckBox, objPostalAddress, objPostCode, objTelephoneNumber; // variables to hold field objects

	// First we setup the basic text that will be displayed if information is missing
	errors = 'Thank you for expressing an interest in volunteering.\n\n';
	errors += 'In order to process your request we require the following information to be entered:\n\n';

	// Find all the objects that will be checked. If an object is missing an error is flagged	
	objCheckBox = MM_findObj('Survey');
	objPostalAddress = MM_findObj('Postal_address');
	objPostCode = MM_findObj('PostCode');
	objTelephoneNumber	= MM_findObj('Telephone_Number');
	
	// First check if objects exist if not flag a major error
	if ( objCheckBox &&  objPostalAddress && objPostCode && objTelephoneNumber) {
		// Check if we are checking or unchecking the Survey checkbox.
		if (objCheckBox.checked) {
			// Survey checkbox must have been checked so we now check each required field
			// This ensures we only prompt for information that is missing
			// If information is missing then we set the flagError variable to true this triggers the display of the error box
			if (objPostalAddress.value == "") {
				errors += 'Postal Address\n';
				flagError = true;
			}
			if (objPostCode.value == "") {
				errors += 'Postcode\n';
				flagError = true;
			}
			if (objTelephoneNumber.value == "") {
				errors += 'Contact Number\n';
				flagError = true;
			}
			// If the flagError is set to true i.e. There is missing information, then display the error box
			if (flagError) {
				errors += '\nThe information provided will only be used to contact you with regards to volunteering.\n';
				alert(errors);
			}
		}
	}
	else
	{
		// Something must be wrong with the form so ask visitor to contact webmaster
		errors = 'Unknown error with form please contact webmaster@batml.org.uk\n'
		flagError = true;
		alert(errors);
	}
	
	// This indicates to the form handler that an error has occured and the form should not be posted.
	document.MM_returnValue = flagError;
}

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;
}
//-->

