<!-- //<%
/*	FunctionLibrary. Code by Ian Hodger. @Software PLC
 	Version History:	  Created 24/11/2000.
The following functions are defined

isNumber(Value)=boolean
isInteger(Value)=boolean
isCurrency(Value)=boolean
isPhoneNumber(Value)=boolean
isEmailAddress(Value)=boolean
isURL(Value)=boolean
isPostCode(Value)=boolean
isDate(Value)=boolean
isCreditCard(Value)=boolean
isCCDate(Value)=boolean
trim(Value)=string
removeQuotes(Value)=string
escapeQuotes(Value)=string
removeHTML(Value)=string

isURL has been changed to allow for forward slashes in the URL. /BG 12/4/01

	Code begins here
*/

function isNumber(Value)
{
	var result;
	if (Value == "") return false;
	Value = new Number(Value);
	result = isFinite(Value);
	return(result);
};
function isInteger(Value)
{
	//first check Value is a number
	var result,IntegerValue;
	Value = new Number(Value);
	result = isFinite(Value);
	if (!result) return(false);
	//calc Value mod 1, iff zero then Value is an integer
	IntegerValue = Value % 1;
	if (IntegerValue!=0) return(false);
	return(true);
};
function isCurrency(Value)
{
	var result,re;
	Value = new String(Value);
	//format=[currency symbol][any number of digits][a separator][upto two digits]
	re = /\d*\s?[,.]?\d?\d?/;
	result = re.test(Value);
	return(result);
};
function isPhoneNumber(Value)
{
	var result,re;
	Value = new String(Value);
	//format=[10+ digits, with or without separators after any or all digits]
	re = /(\d\s*){10}/;
	result = re.test(Value);
	return(result);
};
function isEmailAddress(Value)
{
	var strValue = new String(Value);
	//format=whitespace[one or more valid character][@][one or more valid character]series of([.][one or more valid character]) one of([.][ 2-4chars])whitespace
	var re = /^\s*[^\s,]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(\.([A-Za-z]){2,4})\s*$/;
	var bolResult = re.test(strValue);
	return(bolResult);
};


// isURL has been changed to allow for forward slashes in the URL
function isURL(Value)
{
	var result,re;
	Value = new String(Value);
	//format=[one or more valid character][.][one or more valid character][.][one or more valid character]
	re = /\S+\.\S+\.\S+/;
	result = re.test(Value);
	if (!result) return(false);
	//format=[illegal character set {}|[]\^<> ]
	re = /[{}\|\[\]\\\^<>]/;
	result = re.test(Value);
	if (result) return(false);

	//re = /^http/;
	//result = re.test(Value);
	//if (!result) return(false);

	return(true);
};
function isPostCode(value)
{
//1 or 2 letters, 0-9(once or twice) a letter?, some spaces... 0-9 and 2 a-z's case insensitive
	value=new String(value);
	if (value.match(/^[a-z]{1,2}[0-9]{1,2}[a-z]?\s*[0-9][a-z]{2}$/i))
		return true;
	return false;
};
function isDate(value)
{

	value = new String(value);
	if(value.match(/^\s*\d{1,2}[-.\/\\, ]\d{1,2}[-.\/\\, ](\d\d){1,2}\s*$/))
		return true;
//	var re=/^\s*\d{1,2}[-.\/\\, ]\d{1,2}[-.\/\\, ](\d\d){1,2}\s*$/;
//	if(re.test(Value)) return true;
	return false;
};
function trim(Value)
{
	Value = new String(Value);
	//while the first char of Value is a space, remove it and check again
	while (Value.charAt(0)==' ') Value = Value.substr(1);
	//while the last char is a space, remove it
	while (Value.charAt(Value.length-1)==' ') Value = Value.substr(0,Value.length-1);
	return(Value);
};
function removeQuotes(Value)
{
	var result,i;
	Value = new String(Value);
	result = '';
	//iterate string, check each char in turn, concatenate to result iff not a quote
	for (i=0;i<Value.length;i++) if (Value.charAt(i)!="'") result += Value.charAt(i);
	return(result);
};
function escapeQuotes(Value)
{
	var result,i,a,b;
	Value = new String(Value);
	result = '';
	//iterate string, check each char in turn, replace any substring of quotes with an escaped quote
	for (i=0;i<Value.length;i++)
	{
		a = Value.charAt(i);
		b = Value.charAt(i-1);
		//if current char is a quote and last char is not, then concatenate escaped quote to result
		if ((a=="'")&(b!="'")) result += "''";
		//if current char is not a quote, then concatenate to result
		if (a!="'") result += a;
		//last possible case is both current and previous chars are quotes, in which case do nothing
	};
	return(result);
};
function removeHTML(Value)
{
// These couple of lines have been added. If the function is going to be re-instated,
// remove the lines.
	var result;
	result = new String(Value);
/*
	var result,text,tag,goodHTML;
	Value = new String(Value);
	result = '';
	//define all tags considered OK, only lowercase variants required
	goodHTML = '<b></b><u></u><bold></bold><i></i><br>';
	//algorithm = Value is split into a series of text,tag pairs st
	// Value = text1+tag1+text2+tag2+.... where any text/tag string maybe empty
	// the result is constructed by ignoring all tags except those defined above
	while (Value.length>0)
	{
		//find text
		i = Value.indexOf('<');
		if (i<0) i=Value.length;
		text = Value.substr(0,i);
		Value = Value.substr(i);
		//find tag
		i = Value.indexOf('>');
		if (i<0) i=Value.length;
		tag = Value.substr(0,i+1);
		tag = tag.toLowerCase();
		Value = Value.substr(i+1);
		//add text to result
		result += text;
		//add tag to result iff OK
		if (goodHTML.indexOf(tag)>-1) result += tag;
	}
*/
	return(result);
};
function isCreditCard(Value)
{
	var re;
	//format=[13 or 16 digits, with or without separators after any or all digits]
	Value = new String(Value);
	re = /(\d\s*){13}/;
	if (re.test(Value)) return(true);
	re = /(\d\s*){16}/;
	if (re.test(Value)) return(true);
	return(false);
};
function isCCDate(Value)
{
	var re,result;
	//format= nn/nnnn where n=digit and /=separator from set [.,/]
	Value = new String(Value);
	result = false;
	re = /\d\d[-.\/\\, ]\d\d\d\d/;
	if (re.test(Value)) result = true;
	return(result);

};
/*	Code ends here		*/
//%> -->

