// ***************************************************************************************************

	/* Replaces one substring with another */
	function strreplace(sString, sTarget, sReplace){
		var sTemp = sString;
		var a = 0;
		for(i = 0; i < sString.length; i++){
			a = sTemp.indexOf(sTarget);
			sTemp = sTemp.substring(0 , a) + sReplace + sTemp.substring((a + sTarget.length));
			if (a == -1){
				break;
			}
		}
		return sTemp;
	}
    
	/* Cuts leading and trailing whitespace characters from a string */
	function trim(sValue){
		while(sValue.substring(0, 1)==' '){
			sValue = sValue.substring(1, sValue.length);
		}
		while (sValue.substring(sValue.length-1, sValue.length) == ' '){
			sValue = sValue.substring(0, sValue.length - 1);
		}
		return sValue;
	}

// ****************************************************************************************************

	/* Validates whether field contains any input at all */
	function isFilled(oField){
		var sValue = trim(oField.value);
		return(sValue != "");
	}	/* Validates name - may include spaces, &s, special characters etc */

	/* Validates body text (EG in textarea) - most characters allowed, inc. line breaks & tabs */
	function isBodyText(oField){
		var sValue = trim(oField.value);
		var sRegex = /^([a-zA-Z0-9 _\.\-\n\t\u00c0-\u01ff!"'=\+\&\*£#%\[\]@;:\(\)\,\/])+$/;
		return(sRegex.test(sValue));
	}

	/* Validates text - most characters allowed, no line breaks or tabs */
	function isText(oField){
		var sValue = oField.value;
		var sRegex = /^([a-zA-Z0-9 _\.\-\u00c0-\u01ff!"'=\+\&\*£#%\[\]@;:\(\)\,\/])+$/;
		return(sRegex.test(sValue));
	}

	/* Validates alphanumeric text - no spaces allowed */
	function isAlphaNumeric(oField){
		var sValue = oField.value;
		var sRegex = /^[a-zA-Z0-9]+$/;
		return(sRegex.test(sValue));
	}

	
	/* Validates user name/password (must be between 6 & 10 characters long, must contain letters and numbers) */
	function isUsernamePassword(oField){
		var sValue = trim(oField.value);
        var sRegex = /^(?!^[0-9]*$)(?!^[a-zA-Z]*$)^([a-zA-Z0-9]{6,10})$/;
		return(sRegex.test(sValue));
	}
	
	function isName(oField){
		var sValue = trim(oField.value);
		var sRegex = /^([ \u00c0-\u01ffa-zA-Z\&'])+$/;
		return(sRegex.test(sValue));
	}

	/* Validates address line - may include numbers, spaces, &s, special characters etc */
	function isAddress(oField){
		var sValue = trim(oField.value);
		var sRegex = /^([ \-\,\.0-9a-zA-Z\&'])+$/;
		return(sRegex.test(sValue));
	}

	/* Validates telephone number - may include numbers, spaces, +, -, () */
	function isTel(oField){
		var sValue = trim(oField.value);
		var sRegex = /^[ 0-9\+\-\(\)\/]+$/;
		return(sRegex.test(sValue));
	}

	/* Validates UK postcode */
	function isPostcode(oField){
		var sValue = strreplace(trim(oField.value), " ", "");
		var sRegex = /^([A-PR-UWYZ]\d\d?\d[ABD-HJLNP-UW-Z]{2}|[A-PR-UWYZ][A-HK-Y]\d\d?\d[ABD-HJLNP-UW-Z]{2}|[A-PR-UWYZ]\d[A-HJKSTUW]\d[ABD-HJLNP-UW-Z]{2}|[A-PR-UWYZ][A-HK-Y]\d[A-HJKRSTUW]\d[ABD-HJLNP-UW-Z]{2}|GIR0AA)$/;
		return(sRegex.test(sValue));
	}
	
	/* Validates international postcode (very rough - simply validates alphanumeric) */
	function isPostcodeInternational(oField){
		var sValue = trim(oField.value);
		var sValue = strreplace(trim(sValue), " ", "");
		var sRegex = /^[0-9a-zA-Z]$/
		return(sRegex.test(sValue));
	}

	/* Validates URL (rough, fails querystrings) */
	function isURL(oField){
		var sValue = trim(oField.value);
		var sRegex  = /^(http:\/\/www.|https:\/\/www.|www.){1}([a-zA-Z0-9\-\/.]+)$/;
		return(sRegex.test(sValue));
	}

	/* Validates email address */
	function isEmail(oField){
		var sValue = trim(oField.value);
		var sRegex  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		return(sRegex.test(sValue));
	}

	/*	Validates ONLY FILE SUFFIX OF Gif/Jpeg filename  	*/
	function isImageFilename(oField){
		sValue = trim(oField.value);
		var sRegex = /(.gif|.jpg)$/;
		return(sRegex.test(sValue));
	}

	/* Validates positive or negative numeric value (leading zero not required) */
	function isNumeric(oField){
		var sValue = trim(oField.value);
		var sRegex = /^[-+]?([0-9]+)?([.][0-9]+)?$/;
		return(sRegex.test(sValue));
	}

	/* Validates positive or negative integer */
	function isInteger(oField){
		var sValue = trim(oField.value);
		var sRegex = /^(\+|-)?\d+$/;
		return(sRegex.test(sValue));
	}
	
	/* Validates positive or negative numeric value (leading zero not required) */
	function isNumericUnsigned(oField){
		var sValue = trim(oField.value);
		var sRegex = /^([0-9]+)?([.][0-9]+)?$/;
		return(sRegex.test(sValue));
	}

	/* Validates positive or negative integer */
	function isIntegerUnsigned(oField){
		var sValue = trim(oField.value);
		var sRegex = /^\d+$/;
		return(sRegex.test(sValue));
	}
