		//Validates the ILL request form
		function validate_form() {
			//Check for nonempty fields
			var validationError = false;
			
			//First the author field
			var authorError = "authorError";
  			if (document.ILL.author.value == "" ){
  				showError( document.ILL.author, authorError, "Please type in the author", "true" );
  				validationError = true;
  			}
  			else {
  				showError( document.ILL.author, authorError, "", null );
  			}
  			
  			//The title field
  			var titleError = "titleError";
  			if ( document.ILL.title.value == ""){
  				showError( document.ILL.title, titleError, "Please type in the title", "true" );
  				validationError = true;
  			}
  			else {
  				showError( document.ILL.title, titleError, "", null );
  			}
  			
  			//The patron field
  			var patronError = "patronError";
  			if ( document.ILL.patron.value == ""){
  				showError( document.ILL.patron, patronError, "Please enter your name", "true" );
  				validationError = true;
  			}
  			else {
  				showError( document.ILL.patron, patronError, null, null );
  			}
  			
  			//The card number field
  			var cardNumError = "cardnumError";
  			if( document.ILL.cardnum.value == "") {
    			showError( document.ILL.cardnum, cardNumError, "Please enter your library card number", "true" );
    			validationError = true;
  			}
  			else {
  				showError( document.ILL.cardnum, cardNumError, null, null );
  			}
  			
  			//If the phone numbers are not blank, check that they are valid.
  			var phoneNumError = "phoneErrorAM";
  			var errorMsg="Please enter a valid phone number";
  			if ( document.ILL.phoneam != null && document.ILL.phoneam.value != "" ){
  				if ( checkInternationalPhone(document.ILL.phoneam.value) == false ){
  					showError( document.ILL.phoneam, phoneNumError, errorMsg, "true" );
  					validationError = true;
  				}
  				else {
  					showError( document.ILL.phoneam, phoneNumError, null, null );
  				}
  			}
  			else {
  				showError( document.ILL.phoneam, phoneNumError, null, null );
  			}
  			phoneNumError="phoneErrorPM";
  			if ( document.ILL.phonePM != null && document.ILL.phonePM.value != "" ){
  				if ( checkInternationalPhone(document.ILL.phonePM.value) == false ){
  					showError( document.ILL.phonePM, phoneNumError, errorMsg, "true" );
  					validationError = true;
  				}
  				else {
  					showError( document.ILL.phonePM, phoneNumError, null, null );
  				}
  			}
  			else {
  				showError( document.ILL.phonePM, phoneNumError, null, null );
  			}
  			
  			//If the email field is not blank, check that it is valid.
  			errorMsg = "Please enter a valid email address";
  			var emailError = "emailError";
  			if ( document.ILL.emailaddress != null && document.ILL.emailaddress.value != "" ){
  				var emailValid = echeck( document.ILL.emailaddress.value );
  				if ( emailValid == false ){
  					showError( document.ILL.emailaddress, emailError, errorMsg, "true" );
  					validationError = true;
  				}
  				else {
  					showError( document.ILL.emailaddress, emailError, null, null );
  				}
  			}
  			return !validationError; 
		};
		
		
				//Validates the Volunteer form
		function validate_volunteer_form() {
			//Check for nonempty fields
			var validationError = false;
			
			//First the name of the volunteer
			var volunteerError = "nameError";
  			if (document.Volunteer.nameField.value == "" ){
  				showError( document.Volunteer.nameField, volunteerError, "Please type in your name", "true" );
  				validationError = true;
  			}
  			else {
  				showError( document.Volunteer.nameField, volunteerError, "", null );
  			}
  			
  			//The telephone and email fields cannot BOTH be blank
  			var telephoneError = "telephoneError";
  			var emailError = "emailError";
  			var contactErrorMsg = "Please fill in either a telephone number or an email address";
  			if ( document.Volunteer.emailField.value == "" && document.Volunteer.telephoneField.value == ""){
  				showError( document.Volunteer.emailField, emailError, contactErrorMsg, "true" );
  				showError( document.Volunteer.telephoneField, telephoneError, contactErrorMsg, "true" );
  				validationError = true;
  			}
  			else {
  				showError( document.Volunteer.emailField, emailError, "", null );
  				showError( document.Volunteer.telephoneField, telephoneError, "", null );
  			}
  					
  			//If the phone numbers are not blank, check that they are valid.
  			var phoneNumError = "telephoneError";
  			var errorMsg="Please enter a valid phone number";
  			if ( document.Volunteer.telephoneField != null && document.Volunteer.telephoneField.value != "" ){
  				if ( checkInternationalPhone(document.Volunteer.telephoneField.value) == false ){
  					showError( document.Volunteer.telephoneField, phoneNumError, errorMsg, "true" );
  					validationError = true;
  				}
  				else {
  					showError( document.Volunteer.telephoneField, phoneNumError, null, null );
  				}
  			}
  			
  			
  			
  			//If the email field is not blank, check that it is valid.
  			errorMsg = "Please enter a valid email address";
  			var emailError = "emailError";
  			if ( document.Volunteer.emailaddress != null && document.Volunteer.emailaddress.value != "" ){
  				var emailValid = echeck( document.Volunteer.emailaddress.value );
  				if ( emailValid == false ){
  					showError( document.Volunteer.emailaddress, emailError, errorMsg, "true" );
  					validationError = true;
  				}
  				else {
  					showError( document.Volunteer.emailaddress, emailError, null, null );
  				}
  			}
  			return !validationError; 
		};
		
		//Sets or clears error indicators on the field depending on
		//the boolean value inError.
		function showError( field, messageField, message, inError ){
			var msgField = document.getElementById( messageField );
			msgField.innerHTML=message;
  			if ( inError ){
  				field.setAttribute( "style", "background-color: yellow" );
  			}
  			else {
  				field.setAttribute( "style", "background-color: white" );
  			}
		
		}
		
		//Makes sure the user only enters valid characters for the phone
		//number
		function validatePhone(xxxxx) {
	 		var maintainplus = '';
 			var numval = xxxxx.value
 			if ( numval.charAt(0)=='+' ){ var maintainplus = '+';}
 			curphonevar = numval.replace(/[\\A-Za-z!"£$%^&*+_={};:'@#~,.¦\/<>?|`¬\]\[]/g,'');
 			xxxxx.value = maintainplus + curphonevar;
 			var maintainplus = '';
 			xxxxx.focus;
		}
		
	
		//------------------------------------------------------------------------------------
		//   Phone Validation
		//------------------------------------------------------------------------------------

		// Declaring required variables
		var digits = "0123456789";
		// non-digit characters which are allowed in phone numbers
		var phoneNumberDelimiters = "()- ";
		// characters which are allowed in international phone numbers
		// (a leading + is OK)
		var validWorldPhoneChars = phoneNumberDelimiters + "+";
		// Minimum no of digits in an international phone no.
		var minDigitsInIPhoneNumber = 7;

		function isInteger(s){   
			var i;
    		for (i = 0; i < s.length; i++){   
        		// Check that current character is number.
        		var c = s.charAt(i);
        		if (((c < "0") || (c > "9"))) return false;
    		}
    		// All characters are numbers.
    		return true;
		}

		function stripCharsInBag(s, bag){   
			var i;
    		var returnString = "";
    		// Search through string's characters one by one.
    		// If character is not in bag, append to returnString.
    		for (i = 0; i < s.length; i++){   
        		// Check that current character isn't whitespace.
        		var c = s.charAt(i);
        		if (bag.indexOf(c) == -1) returnString += c;
    		}
    		return returnString;
		}

		function checkInternationalPhone(strPhone){
			s=stripCharsInBag(strPhone,validWorldPhoneChars);
			return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
		}

		//-----------------------------------------------------------------
		//              Email Validation
		//-----------------------------------------------------------------
		function echeck(str) {

			var at="@"
			var dot="."
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
		   		return false
			}

			if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   		return false
			}

			if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    	return false
			}

		 	if (str.indexOf(at,(lat+1))!=-1){
		    	return false
		 	}

		 	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    	return false
		 	}

		 	if (str.indexOf(dot,(lat+2))==-1){
		    	return false
		 	}
		
		 	if (str.indexOf(" ")!=-1){
		    	return false
		 	}

 		 	return true					
		}



	