<!-- Hide code from non-js browsers
//Basic JS Functions for page validation
//getFullYear(date) :- gets the 4 digit year for a valid date
//getActualMonth(date) :- gets the month digit for a valid date and increments it by one ie January is 1
//getCalendarMonth(date) :- returns the month name for a valid date
//dateString(date) :- uses the 3 above to return a date string
//getRadioValue(radioObject) :- returns the value of the selected radio button
//getSelectValue(selectObject) :- returns the value of the selected checkbox
//twoPlaces(total) :- returns a number with two decimal places
//checkDateObj(fieldObj,millenium) :- checks validity of a field for a date and uses checkDate(fieldObj,millenium)
//  if the millenium parameter is set to TRUE then if a two digit date was used and when 1900 is added it is less than 1998 it adds 100
//  ie 00 --> 1900 is less than 1998 so add 100 ie 2000
//checkDate(fieldValue,millenium) :- checks a non empty value for date validity (for millenium parameter see above)
//calcddmmyy(fieldValue) :- takes a value and attempts to convert it and return values of dd,mm & yy
//CheckNum(str,startPos) :- returns the position within a string of the first non-number (used by calcddmmyy(fieldValue))
//removeSpaces(fieldValue):- removes spaces at the beginning and end of a field
//isEmail(emailFieldObj,noAlert):- validates an email field and if noAlert is TRUE then returns an error message
//isEmpty(s) :- Check whether string s is empty
//isWhitespace(s) :- Returns true if string s is empty or whitespace characters only.
//stripCharsNotInBag(s,bag) :- Removes all characters which do NOT appear in string bag from string s.
//stripCharsNotInBagTidy(s,bag) :- Removes all characters which do NOT appear in string bag from string s & removes leading & trailing spaces.
//stripCharsInBag (s, bag) :- Removes all characters which appear in string bag from string s.
//replaceString(oldS,newS,fullS) :- Replaces oldS with newS in the string fullS
//cleanUpText (fieldValue) :- Removes unacceptable characters and replaces tabs with 4 spaces, commas with single spaces, and returns with '|'


Date.prototype.getFullYear = getFullYear
Date.prototype.getActualMonth = getActualMonth
Date.prototype.getActualDay = getActualDay
Date.prototype.getCalendarMonth = getCalendarMonth

//These are the 'bags' of characters
var digits = "0123456789";
var lowercaseLetters = "abcdefghijklmnopqrstuvwxyz"
var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
var whitespace = " \t\n\r";
var decimalPointDelimiter = "."
var phoneNumberDelimiters = "()- ";
// characters which are allowed in UK phone numbers
var validUKPhoneChars = digits + phoneNumberDelimiters;
var validWorldPhoneChars = digits + phoneNumberDelimiters + "+";
// non-digit characters which are allowed in credit card numbers
var creditCardDelimiters = " "
var nameChars= lowercaseLetters + uppercaseLetters +" -"
var addressChars = nameChars+digits
var dateChars = digits + ".\\/- "

var textChars = nameChars + "-:,"+whitespace
var fileChars = lowercaseLetters + uppercaseLetters+digits+"-"

// CONSTANT STRING DECLARATIONS
// m is an abbreviation for "missing"
var mPrefix = "You did not enter a value into the "
var mSuffix = " field. We need this informnation to process your enquiry. Please enter it now."

// i is an abbreviation for "invalid"
var iEmail = "This field must be a valid email address (like foo@bar.com). Please reenter it now."
var iCreditCardPrefix = "This is not a valid "
var iCreditCardSuffix = " credit card number."

// p is an abbreviation for "prompt"
var pEntryPrompt = "Please enter a "
var pEmail = "valid email address (like foo@bar.com)."
var pCreditCard = "valid credit card number."


//End of constant definitions

function getFullYear(date)
{ 
	var n = date.getYear() 
	return n 
} 

function getActualMonth(date)

{ 
	var n = date.getMonth()
	n += 1 
	return n 
} 

function getActualDay(date)
{ 
	var n = date.getDay()
	n += 1 
	return n 
} 
        
function getCalendarMonth(date) 
{ 
	 var n = date.getMonth()
	 var moy = new Array(12)
	 moy[0] = "January" 
	 moy[1] = "February" 
	 moy[2] = "March" 
	 moy[3] = "April" 
	 moy[4] = "May" 
	 moy[5] = "June" 
	 moy[6] = "July" 
	 moy[7] = "August" 
	 moy[8] = "September" 
	 moy[9] = "October" 
	 moy[10] = "November" 
	 moy[11] = "December" 
	 return moy[n] 
} 

function dateString(date)
{

	//return (date.getDate()+" "+getCalendarMonth(date)+" "+ getFullYear(date))
	return (date.getDate()+" "+getCalendarMonth(date)+" "+ date.getYear())
}


function getRadioValue(radioObject)
{
	var value = ""
	for (var i=0; i<radioObject.length; i++)
	{
		if (radioObject[i].checked)
		{
			value = radioObject[i].value
			break
		}
	}
	return value
}

function getSelectValue(selectObject)
{
	
	return selectObject.options[selectObject.selectedIndex].value
}

function twoPlaces(total)
//Ensures that string versions of numbers show two decimal places
//ie for displaying costs in pounds
{
  var total_str;

  total = Math.round(total * 100) / 100;
  total_str = total + "";
  i = total_str.indexOf(".");
  l = total_str.length;
  if (i == -1)
    total_str += ".00";
  else if (i == l - 2)
    total_str += "0";
  else
    total_str = total_str.substring(0, i + 3);

  return total_str;
}

function checkDateObj(fieldObj,millenium)
{
if (isWhitespace(fieldObj.value)||isNaN(parseInt(fieldObj.value)))
	{
		fieldObj.focus();
		return false;
	}
fieldObj.value=stripCharsNotInBag(fieldObj.value, dateChars)
if (checkDate(fieldObj.value,millenium)) {
	return (calcDate);
	}
else {return false}
}


function checkDate(fieldValue,millenium)
{
	// Checks that the day mumber does not exceed the number of days in the month
	// also checking leap year dates (crudely!) and number of months
	// it also adds 100 if it is millenium is 'true' and the last 2 digits are less than 98
	if (fieldValue==""||isNaN(parseInt(fieldValue)))
	{
		return false
	}
	// This first call below translates a string eg 24/10/58 into dd,mm,yy
	if (calcddmmyy(fieldValue))
	{
		if (mm<0||mm>11)
			{
			alert("Please use a month number between 1 and 12")
			return false;
			}
		else if(((mm+1)==4||(mm+1)==6||(mm+1)==9||(mm+1)==11)&&dd>30)
			{
			alert("There are only 30 days in the month!")
			return false;
			}
			else if(((mm+1)==1||(mm+1)==3||(mm+1)==5||(mm+1)==7||(mm+1)==8||(mm+1)==10||(mm+1)==12)&&dd>31)
			{
			alert("There are only 31 days in the month!")
			return false;
			}
	
			else if((mm+1)==02)
		 	{
			if((Math.floor(yy/4)==yy/4))
				{
				if(dd>29)
					{
	            alert("Too many days in February\nEven for a leap year!")
	            return false


	         	}
	         }
				else
					{ 
	           	if (dd>28)
						{
							alert("Too many days in February")
							return false
	       			}
					}
			}
		
		if((yy>99&&yy<1898)||yy>2005)
			{
			alert("The year number is not acceptable")
			return false
			}
			if(yy<100){yy=yy+1900}
		//alert("yy="+yy)
		if(millenium&&yy<1998)
		{
			yy = yy+100
		}
		
		calcDate= new Date (yy,mm,dd);
		return (calcDate);
		}
	else {return false}
} 

function calcddmmyy(fieldValue)
// note that the these will be in line with normal conventions
// ie January = 0
{
	fieldValue=removeSpaces(fieldValue)
	//alert("fieldValue is >"+fieldValue+"<")
	startPos=0
	while(fieldValue.substr(startPos,1)=="0")
	{
		fieldValue=fieldValue.substring(1)
	}
	//alert("fieldValue is >"+fieldValue+"<")
	
	pos= CheckNum(fieldValue,startPos)
	
	//alert ("dd startPos"+startPos+" pos "+pos+"String is >"+(fieldValue.substring(startPos,pos))+"<")
	dd = parseInt(fieldValue.substring(startPos,pos))
	//alert ("startPos"+startPos)
	startPos=pos+1
	//alert ("startPos"+startPos)
	//alert("fieldValue.substr(startPos,1)=>"+(fieldValue.substr(startPos,1))+"<")
	
	//alert ("startPos"+startPos)
	
	pos = CheckNum(fieldValue,startPos)
	while(fieldValue.substr(startPos,1)=="0")
	{
	 startPos=startPos+1
	 //alert("zero")
	}
	

	//alert("fieldValue is >"+fieldValue+"<")
	//alert ("mm startPos"+startPos+" pos "+pos+"String is >"+(fieldValue.substring(startPos,pos))+"<")
	mm = parseInt((fieldValue.substring(startPos,pos)))-1
	startPos=pos+1
	yy = parseInt(fieldValue.substring(startPos))
	//alert (fieldValue+" dd ="+dd+", mm ="+mm +", yy ="+yy)
	if (isNaN(dd)||isNaN(mm)||isNaN(yy))
	{	return false
	}
	if (Math.floor(dd)!=dd||Math.floor(mm)!=mm||Math.floor(yy)!=yy)
	{	return false
	}
	return true
		
}


function CheckNum(str,startPos) {
// Returns the position in a string of the first non number 
// Used for parsing date strings
	 var ch=""
     for (var i=startPos; i < str.length; i++)
     {
     	ch = str.substring(i,i+1);
       	//alert (ch)
     	if (ch < "0" || ch > "9")
     	{
       		var nonNumericPos=i
			//alert("break")
			break
        } 
     }
     return nonNumericPos;
}
	 
function removeSpaces(fieldValue)
{
// removes spaces at the beginning and end of a field
// removing at end added 24/8/99
	while (fieldValue.substring(0,1)==" ")
	{
		fieldValue=fieldValue.substring(1)
	}
	//alert("-"+fieldValue.substring(fieldValue.length,fieldValue.length+1)+"-")
	if (fieldValue.length>0)
	{
		while (fieldValue.substring(fieldValue.length-1,fieldValue.length)==" ")
		{
			fieldValue=fieldValue.substring(0,fieldValue.length-1)
		}
	}
	return fieldValue
}

function isEmail(emailFieldObj,noAlert)
{
	s =emailFieldObj.value
	if (isWhitespace(s))
	{
		if(!(noAlert))
		{
			alert("The E-MAIL field is blank.\n\nPlease enter your e-mail address.")
			emailFieldObj.focus();
		}
		return false; 
	}
	
	if (s.indexOf ('@',0) == -1 ||s.indexOf ('.',0) == -1)
	{
		if(!noAlert)
		{
			alert("\nThe E-MAIL field requires a \"@\" and a \".\" be used.\n\nPlease re-enter your e-mail address.")
			emailFieldObj.select();
			emailFieldObj.focus();
		}
		return false;
	}
	else
	{
		return true;
	}
}


// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}



// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);

        if (whitespace.indexOf(c) == -1) return false;
    }
	//alert("Whitespace")
    // All characters are whitespace.
    return true;
}


// Removes all characters which do NOT appear in string bag 
// from string s.

function stripCharsNotInBag(s,bag)

{   var i;
    var returnString = "";

    // Search through string's characters one by one.
    // If character is 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 stripCharsNotInBagTidy(s,bag)

{
	returnString=stripCharsNotInBag(s,bag)
	returnString=removeSpaces(returnString)
	return returnString;
}

	
	
// Removes all characters which appear in string bag from string s.

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 replaceString(oldS,newS,fullS) {
// Replaces oldS with newS in the string fullS
   for (var i=0; i<fullS.length; i++) {
      if (fullS.substring(i,i+oldS.length) == oldS) {
         fullS = fullS.substring(0,i)+newS+fullS.substring(i+oldS.length,fullS.length)
      }
   }
   return fullS
}

function cleanUpText(fieldValue) {
//Removes unacceptable characters and replaces commas with single spaces, and returns with ';'
	fieldValue=removeSpaces(fieldValue)
	fieldValue=stripCharsNotInBag(fieldValue,textChars)
	fieldValue=replaceString("\,","  ",fieldValue)
	fieldValue=replaceString("\r","; ",fieldValue)
	fieldValue=replaceString("\n","; ",fieldValue)
	return fieldValue
}

//Functions to put up error messages

var mPrefix = "You did not enter a value into the "
var mSuffix = " field. We need that information to process you enquiry. Please enter it now."

// Notify user that required field theField is empty.
// String s describes expected contents of theField.value.
// Put focus in theField and return false.

function warnEmpty (theField, s)
{   theField.focus()
    alert(mPrefix + s + mSuffix)
    return false
}


// Notify user that contents of field theField are invalid.
// String s describes expected contents of theField.value.
// Put select theField, pu focus in it, and return false.

function warnInvalid (theField, s)
{   theField.focus()
    theField.select()
    alert(s)
    return false
}



// end hiding -->

