<!--

// *** The following form validation script written by Chas Wilder, Clock Ltd, Watford, UK ++44(0)1923 224409 ***

// FUNCTION CALL
// valForm function called by 'onSubmit="return valForm(.....)' within form tag, see below for definition of contents of brackets.
// The valForm function submits in sets of three for each form field you want to validate; fNameName, fNameLabel and fNameType.
// fNameName is the name of the form element you wish to validate, this is submitted as a string enclosed in single quotes ('title' in sample below)
// fNameLabel is a string that is used in the alert, usually the label you have give the form element that is displayed on the web page ('your title' in sample below)
// fNameType is an integer that tells the script what type of data you are validating, see definitions below sample.
// sample: valForm('title','your title',5,'name','your full name',3,'email','email address',1,'phone','telephone number',2)

// fNameType DEFINITIONS
// 0:string, 1:email, 2:phone/fax, 3:name, 4:integer, 5:select list , 6:number with decimal (see comments for each plugin function above)
// (fNameType 5 will throw an alert if the select list is left in its default state, effectively the top item selected. Use only when you want to the user to select another value)
// Any form fields not included in the call to valForm will not be validated, select lists with no null value, check boxes, radio buttons and optional fields shouldn't be validated.

// Any redundant plugin functions and comments not surrounded by ***  *** maybe removed as desired

// VALIDATION PLUGIN FUNCTIONS
// validate for existance of a text string
function ValType0(fName,fLabel){
  elm=eval("document.form."+fName);
  if(elm.value==""){
    alert('Please enter your \''+fLabel+'\'');
    eval("document.form."+fName+".focus()");
    return true;
  }
return false;
}

// validate for an email address than contains valid characters
function ValType1(fName,fLabel){
  elm=eval("document.form."+fName);
  if(elm.value.indexOf("@")!="-1" && elm.value.indexOf(".")!="-1" && elm.value.indexOf(" ")=="-1" && elm.value!=""){
    return false;
  }
alert('Please enter a valid '+fLabel);
eval("document.form."+fName+".focus()");
return true;
}

// validate for a phone or fax number, allows numbers, spaces, hyphens, plus symbol and brackets only
function ValType2(fName,fLabel){
  var str=eval("document.form."+fName+".value");
  if (str==""){
    alert('Please enter your '+fLabel);
    eval("document.form."+fName+".focus()");
    return true;
  }
  for (var i=0; i<str.length; i++){
    var ch=str.substring(i,i+1);
      if ((ch<"0" || "9"<ch) && ch!=' ' && ch!='-' && ch!='+' && ch!='(' && ch!=')'){
        alert('The '+fLabel+' that you entered contains invalid characters.\nPlease only use the following: 0 to 9, -, +, (, ) and spaces');
        eval("document.form."+fName+".focus()");
        return true;
      }
  }
return false;
}

// validate for a full name (forename or initial and lastname, separated by a space)
function ValType3(fName,fLabel){
  str=eval("document.form."+fName+".value");
  if(str==""){
    alert('Please enter your '+fLabel);
    eval("document.form."+fName+".focus()");
    return true;
    }else if(str.indexOf(" ")==-1){
      alert('Please enter your '+fLabel+' with a space separating the forename/initial and lastname');
      eval("document.form."+fName+".focus()");
      return true;
  }
return false;
}

// validate for an integer, will only allow purely numerical values (no decimal point)
function ValType4(fName,fLabel){
  var str=eval("document.form."+fName+".value");
  if (str==""){
    alert('Please complete \''+fLabel+'\'');
    eval("document.form."+fName+".focus()");
    return true;
  }
  for (var i=0; i<str.length; i++){
    var ch=str.substring(i,i+1);
      if ((ch<"0" || "9"<ch)){
        alert('The field \''+fLabel+'\' can only contain whole numbers');
        eval("document.form."+fName+".focus()");
        return true;
      }
  }
return false;
}

// Validate for an integer, but only if a value is supplied. ie field is optional,
// but if a value has been entered, it must be a number
function ValType7(fName,fLabel){
  var str=eval("document.form."+fName+".value");
  if (str != ""){
	  for (var i=0; i<str.length; i++){
		var ch=str.substring(i,i+1);
		  if ((ch<"0" || "9"<ch)){
			alert('The field \''+fLabel+'\' can only contain whole numbers');
			eval("document.form."+fName+".focus()");
			return true;
		  }
	  }
	}
return false;
}

// validate for a select list having other than top value selected
function ValType5(fName,fLabel){
  selIndx=eval("document.form."+fName+".selectedIndex");
  if(selIndx==0){
    alert('Please enter \''+fLabel+'\'');
    eval("document.form."+fName+".focus()");
    return true;
  }
return false;
}

// validate for a number with or without decimal point (allows numerals and one decimal point only)
function ValType6(fName,fLabel){
  var str=eval("document.form."+fName+".value");
  if (str==""){
    alert('Please complete \''+fLabel+'\'');
    eval("document.form."+fName+".focus()");
    return true;
  }
  var point=0;
  for (var i=0; i<str.length; i++){
    var ch=str.substring(i,i+1);
    if(ch=='.' && point ==0){
      point=1;
      }else{
        alert('You can only enter a value with one decimal point in \''+fLabel+'\'');
        eval("document.form."+fName+".focus()");
        return true;
    }
    if ((ch<"0" || "9"<ch)&& ch!='.'){
      alert('The field \''+fLabel+'\' contains invalid characters\nPlease only use the numerals: 0 to 9 and a decimal point');
      eval("document.form."+fName+".focus()");
      return true;
    }
  }
return false;
}

// MAIN FUNCTION CALLED ON FORM SUBMIT
// Parse submitted form elements, alert comment and fNameType, submit to valiadation plugin function according to fNameType
function valForm(){
  args=valForm.arguments;
  for(i=0;i<(args.length);i=i+3){
    if(eval("ValType"+args[i+2]+"('"+args[i]+"','"+args[i+1]+"')")){
      return false;
    }
  }
return true;
}

//-->
