function validateInput(frm, mask){

	//Count the number of form elements
	var FrmLen = frm.elements.length;
 
	//Get the validation mask string
	var maskarr = mask;
	
	//Loop through all the form elements
	for (var i = 0; i < FrmLen; i++)
	{
		//obtain the validation mask character
		maskarr = mask.substring(i,i+1)

		//Initialise local variables
		var valdate = 1;
		var valtext = 1;
		var valnum = 1;
		var valtelenum = 1;
		var valemail = 1;

	//Test field against validation mask character
	if (maskarr == "d")
	{
		valdate = validateDate(frm.elements[i].value);
	}
	if (maskarr == "t")
	{
		valtext = validateText(frm.elements[i].value);
		
	}
	if (maskarr == "n")
	{
		valnum = validateNum(frm.elements[i].value);
	}
	if (maskarr == "p")
	{
		valtelenum = validateTeleNum(frm.elements[i].value);
	}
	if (maskarr == "e")
	{
		valemail = validateEmail(frm.elements[i].value);
	
	}

	//If the validation fails prompt the user
	if (! valdate)
	{
		alert("The date you have entered is invalid");
		putFocus(frm.elements[i]);
		return false;
	}
	if (! valtext)
	{
		alert("You forgot to fill out the information where the cursor is now flashing");
		putFocus(frm.elements[i]);
		return false;
	}
	if (! valnum)
	{
		alert("Please enter a valid number");
		putFocus(frm.elements[i]);
		return false;
	}
	if (! valtelenum)
	{
		alert("Please enter a valid telephone or extension number");
		putFocus(frm.elements[i]);
		return false;
	}
	if (! valemail)
	{
		alert("The Email address you have entered is invalid. Please correct the email address at the flashing cursor");
		putFocus(frm.elements[i]);
		return false;
	}
	}
	return true;
}

//Date validation function
function validateDate(s)
{
	//Test for a string
	if (s.length > 0)
	{
		//Create an array to split the date into (dd/mm/yy)
		strarr = new Array ()

		//Use own split function as JScript does not include JavaScripts split function
		own_split(strarr, s, "/");
		
		//3 array elements means month,day and year
		if (strarr.length == 3)
		{
			//Test the value of each element falls in an acceptable range
			for (var i = 0; i < strarr.length; i++)
			{
				if ((strarr[1] < 0) || (strarr[1] >31)){
					return false;
				}
				if ((strarr[0] < 0) || (strarr[0] >12)){
					return false;
				}
				if ((strarr[2] <= 1899) || (strarr[2] > 2099)){
					return false;
				}
			}
			return true;
		}
		return false;
	}
	return false;
}

//Text validation function
function validateText(s)
{
	//test for a string
	if (s.length > 0)
	{
		return true;
	}
	return false;
}

//Number validation function
function validateNum(s)
{
	//Test to see if the value converts to a number
	if (parseInt(s) > 0)
	{
		return true;
	}
	return false;
}

//Telephone Number validation function
function validateTeleNum(s)
{
	//Test for a string
	if (s.length > 0)
	{
		for (i = 0;  i < s.length;  i++)
 		{
		    	ch = s.charAt(i);
			if(! own_instring(ch))
			{
			return false;
			}
		}
		return true;
	}
	return false;
}

//E-Mail address validation function
function validateEmail(s)
{
	//Test for a string
	if (s.length > 0)
	{
		// Return false if e-mail field does not contain a '@' and '.' .
		if (s.indexOf ('@',0) == -1 || s.indexOf ('.',0) == -1)
      			{
			return false;
			}
		return true;
	}
	return false;
}

//In string function to test for valid substring, accomodates JavaScripts lack of VBScripts InStr() function
function own_instring(c)
{
	var checkOK = "0123456789-+-. ()\t\r\n\f";
	var ret  = false;

  		for (j = 0;  j < checkOK.length;  j++)
		{
      			if (c != checkOK.charAt(j))
			{
			continue;
			}
			else
			{
			ret = true;
			break;
			}
		}
	return ret;
}

//String split function to accomodate JScripts lack of JavaScripts split function
function own_split(arr, str, delim)
{
	//Initialise local variables
	var pos = 0;
	var num = 0;
	var start = 0;
	
	//Loop while there are characters in the string
	while (pos < str.length)
	{
		//Loop while there are delimiters in the string
		while((str.substring (pos, pos+1) != delim) && (pos < str.length))
		{
		pos++;
		}
		//Add the new characters to the output array
		arr[num] = str.substring(start,pos);
		num++;
		start = pos+1;
		pos++;
	}
}

function putFocus(elementStr)
   {
   elementStr.value="";
   elementStr.focus();
   }
