<!-- Hide

// Function to determine if a field contains chars
function Valid_Required(TheForm, TheField, MinLength, MaxLength)
	{
	var IsValid = false;
	Util_WhiteSpaceTrim(TheField);
	IsValid = ((TheField.value.length >= MinLength) && (TheField.value.length <= MaxLength));
	return(IsValid);
	}

// Function to determine if a field contains chars
function Valid_RequiredBoth(TheForm, TheField, TheFieldMatchedName, MaxLength)
	{
	var Count, TheFieldMatched, TheIsValid = false;
	Util_WhiteSpaceTrim(TheField);

	// Find the matching field
	for (Count = 0; Count < TheForm.elements.length; Count++)
		{
		TheFieldMatched = TheForm.elements[Count];
		if (TheFieldMatched.name == TheFieldMatchedName)
			{
			Util_WhiteSpaceTrim(TheFieldMatched);
			TheIsValid = (((TheField.value.length > 0) && (TheField.value.length <= MaxLength))
					|| ((TheFieldMatched.value.length > 0) && (TheFieldMatched.value.length <= MaxLength)));
			Count = TheForm.elements.length;
			}
		}
	return(TheIsValid);
	}

// Function to determine if two fields are equal
function Valid_RequiredMatch(TheForm, TheField, TheFieldMatchedName, MaxLength)
	{
	var Count, TheFieldMatched, TheIsValid = false;
	Util_WhiteSpaceTrim(TheField);

	// Find the matching field
	for (Count = 0; Count < TheForm.elements.length; Count++)
		{
		TheFieldMatched = TheForm.elements[Count];
		if (TheFieldMatched.name == TheFieldMatchedName)
			{
			Util_WhiteSpaceTrim(TheFieldMatched);
			TheIsValid = (TheField.value == TheFieldMatched.value)
				&& (((TheField.value.length > 0) && (TheField.value.length <= MaxLength))
					|| ((TheFieldMatched.value.length > 0) && (TheFieldMatched.value.length <= MaxLength)));
			Count = TheForm.elements.length;
			}
		}
	return(TheIsValid);
	}

// Function to determine if two fields are not equal
function Valid_NotMatch(TheForm, TheField, TheFieldMatchedName, MaxLength)
	{
	var Count, TheFieldMatched, TheIsValid = false;
	Util_WhiteSpaceTrim(TheField);

	// Find the matching field
	for (Count = 0; Count < TheForm.elements.length; Count++)
		{
		TheFieldMatched = TheForm.elements[Count];
		if (TheFieldMatched.name == TheFieldMatchedName)
			{
			Util_WhiteSpaceTrim(TheFieldMatched);
			TheIsValid = (TheField.value != TheFieldMatched.value);
			Count = TheForm.elements.length;
			}
		}
	return(TheIsValid);
	}

// Rountine to limit the max length of a field
function Valid_TextLimit(TheForm, TheField, TheDisplay, MaxLength)
	{
	if (TheField.value.length > MaxLength)
		TheField.value = TheField.value.substr(0, MaxLength);
	TheDisplay = document.all ? document.all[TheDisplay] : document.getElementById(TheDisplay);
	TheDisplay.innerText = MaxLength - TheField.value.length;
	}

// Function to determine if a field contains a number
function Valid_Number(TheForm, TheField)
	{
	var Test, IsValid = false;
	Util_WhiteSpaceRemove(TheField);
	IsValid = ! isNaN(TheField.value);
	return(IsValid);
	}

function Valid_Dollar(TheForm, TheField)
	{
	var Test, IsValid = false;
	Util_WhiteSpaceRemove(TheField);
	IsValid = ! isNaN(TheField.value);
	if (IsValid)
		TheField.value = formatDec(TheField.value, 2);
	return(IsValid);
	}

// Function to determine if a field contains a number
function Valid_Postcode(TheForm, TheField)
	{
	var Test, IsValid = false;
	Util_WhiteSpaceRemove(TheField);
	Test = TheField.value.match(/^[1234567(08)]\d{3}$/g);
	IsValid = (Test != null) && (Test.length);
	return(IsValid);
	}

// Function to determine if a field contains an Email
function Valid_Email(TheForm, TheField)
	{
	var Test, IsValid = false;
	Util_WhiteSpaceTrim(TheField);
	Test = TheField.value.match(/\S+@([-\w]+\.)+\w+/g);
	IsValid = (Test != null) && (Test.length);
	return(IsValid);
	}

// Function to determine if a field contains an URL
function Valid_URL(TheForm, TheField)
	{
	var Test, IsValid = false;
	Util_WhiteSpaceTrim(TheField);
	Test = TheField.value.match(/([-\w]+\.)+\w+\S*/g);
	IsValid = (Test != null) && (Test.length);
	return(IsValid);
	}

// Function to determine if a date is valid
function Valid_Date(TheForm, TheField)
	{
	var TheDay, TheMonth, TheYear;
	var TestDate;
	var IsValid = false;
	TestDate = TheField.value.split("/");
	TheDay = TestDate[0];
	if (TheDay == "08")
		TheDay = "8";
	else if (TheDay == "09")
		TheDay = "9";
	TheMonth = TestDate[1];
	if (TheMonth == "08")
		TheMonth = "8";
	else if (TheMonth == "09")
		TheMonth = "9";
	TheYear = TestDate[2];
	if (!isNaN(TheDay) && !isNaN(TheMonth) && !isNaN(TheYear))
		{
		TestDate = new Date(TheYear, TheMonth - 1, TheDay, 0, 0, 0);
		IsValid = ((parseInt(TheDay) == parseInt(TheDay)) && (parseInt(TheMonth) == TestDate.getMonth() + 1) && (parseInt(TheYear) == TestDate.getFullYear()))
		if (IsValid)
			TheField.value = leftPad(TestDate.getDate(), "0", 2) + "/" + leftPad(TestDate.getMonth()+1, "0", 2) + "/" + TestDate.getFullYear();
		}
	return (IsValid);
	}

// Function to determine if a time is valid
function Valid_Time(TheForm, TheField)
	{
	var TheHours, TheMinutes;
	var TestTime;
	var IsValid = false;
	TestTime = TheField.value.split(":");
	TheHours = TestTime[0];
	if (TheHours == "08")
		TheHours = "8";
	else if (TheHours == "09")
		TheHours = "9";
	TheMinutes = TestTime[1];
	if (TheMinutes == "08")
		TheMinutes = "8";
	else if (TheMinutes == "09")
		TheMinutes = "9";
	if (!isNaN(TheHours) && !isNaN(TheMinutes))
		{
		TheHours = parseInt(TheHours);
		TheMinutes = parseInt(TheMinutes);
		IsValid = ((TheHours >= 0) && (TheHours < 24) && (TheMinutes >= 0) && (TheMinutes < 60))
		if (IsValid)
			TheField.value = leftPad(TheHours, "0", 2) + ":" + leftPad(TheMinutes, "0", 2);
		}
	return (IsValid);
	}

// Function to determine if a date triplet is valid
function Valid_Date_triple(TheForm, TheDay, TheMonth, TheYear)
	{
	var TestDate;
	var IsValid = false;
	if (!isNaN(TheDay) && !isNaN(TheMonth) && !isNaN(TheYear))
		{
		TestDate = new Date(TheYear, TheMonth, TheDay, 0, 0, 0);
		IsValid = ((parseInt(TheDay) == TestDate.getDate()) && (parseInt(TheMonth) == TestDate.getMonth()) && (parseInt(TheYear) == TestDate.getYear()))
		}
	return (IsValid);
	}

// Function to determine if an image is valid
function Valid_Image(TheForm, TheField, TheWidth, TheHeight)
	{
	var TestImage;
	var IsValid = true;
	if (TheField.value != "")
		{
		TestImage = new Image();
		TestImage.src = TheField.value;
		if (TheWidth && TheHeight)
			IsValid = (TestImage.width == TheWidth) && (TestImage.height == TheHeight);
		else
			IsValid = true;
		}
	return (IsValid);
	}

// Function to determine if a selection field has 
function Valid_Selection(TheForm, TheField)
	{
	var Test, IsValid = false;
	Util_WhiteSpaceTrim(TheField);
	Test = TheField.value.match(/([-\w]+\.)+\w+\S*/g);
	IsValid = (Test != null) && (Test.length);
	IsValid = (TheField.selectedIndex != 0);
	return(IsValid);
	}

// Function to determine if a field contains a number
function Valid_Password(TheForm, TheField)
	{
	var Test, IsValid = false;
	Util_WhiteSpaceRemove(TheField);
	// Check for non-alphanumeric
	Test = TheField.value.match(/\W/g);
	IsValid = (Test == null);
	// Check for uppercase
	if (IsValid)
		{
		Test = TheField.value.match(/[A-Z]/g);
		IsValid = (Test != null) && (Test.length);
		}
	// Check for lowercase
	if (IsValid)
		{
		Test = TheField.value.match(/[a-z]/g);
		IsValid = (Test != null) && (Test.length);
		}
	// Check for numeric
	if (IsValid)
		{
		Test = TheField.value.match(/[0-9]/g);
		IsValid = (Test != null) && (Test.length);
		}
	return(IsValid);
	}

// Rountine to check the validation of all fields in a form
var WindowValidation;
function Validate_Form(TheForm, FormValidation, TheRelativePath)
	{
	var Count, TheField, TheValidation, IsValid;
	var TheErrorMessage = "", FirstFault = null;
	for (Count = 0; Count < TheForm.elements.length; Count++)
		{
		TheField = TheForm.elements[Count];
		TheValidation = FormValidation[TheField.name];
		if (TheValidation)
			{
			if (TheField.value.length == 0)
				{
				if (TheValidation.required)
					{
					TheErrorMessage += "The " + TheValidation.fieldname + " is required.;";
					if (FirstFault == null) FirstFault = TheField;
					}
				}
			else
				{
				IsValid = TheValidation.verify(TheForm, TheField, TheValidation.min, TheValidation.max);
				if (! IsValid)
					{
					if (TheValidation.verify == Valid_RequiredMatch)
						TheErrorMessage += "The " + TheValidation.fieldname + " & " + TheValidation.fieldnamematched + " must match.;";
					else if (TheValidation.verify == Valid_NotMatch)
						TheErrorMessage += "The " + TheValidation.fieldname + " & " + TheValidation.fieldnamematched + " must not match.;";
					else
						TheErrorMessage += "The " + TheValidation.fieldname + " is not valid.;";
					if (FirstFault == null) FirstFault = TheField;
					}
				}
			}
		}
	if (TheErrorMessage != "")
		{
		var ThePopupLocation;
		ThePopupLocation = TheRelativePath + "Global/Error/Error.html";
		//alert("ThePopupLocation=" + ThePopupLocation);
		var TheWindowParams = "toolbar=no,location=no,menubar=no,scrollbars=yes,status=no,statusbar=no,resizable=yes,title=no,titlebar=no,width=400,height=300";
		TheWindowParams += ",left=" + ((screen.Width - 400) / 2)
			+ ",top=" + ((screen.Height - 300) / 2);
		FirstFault.focus();
		ThePopupLocation += "?FormName=" + TheForm.name;
		document.all.ValidationError.value = TheErrorMessage;
		if (WindowValidation && !WindowValidation.closed)
			WindowValidation.location = ThePopupLocation;
		else
			{
			WindowValidation = window.open(ThePopupLocation,"ModalPopup",TheWindowParams);
			}
//alert("WindowValidation.document.all.TheTitle=" + WindowValidation.document.all.TheTitle);
//alert("WindowValidation.document.all.TheTitle.innerHTML =" + WindowValidation.document.all.TheTitle.innerHTML);
//		WindowValidation.document.all.TheTitle.innerHTML = "Error";
//		WindowValidation.document.all.TheContent.innerHTML = TheErrorMessage;
		WindowValidation.focus();
		}

	// Return whether the validation was successful
	return(TheErrorMessage == "");
	}

// Function to left pad a string with a character
function leftPad(TheString, TheFill, TheWidth)
	{
	var Count, ThePad = "";

	TheString = new String(TheString);
	for (Count = 0; Count < (TheWidth - TheString.length); Count++)
		ThePad += TheFill;
	TheString = ThePad + TheString;
	return(TheString);
	}

// Function to remove whitespace from a string
function Util_WhiteSpaceRemove(TheField)
	{
	TheField.value = TheField.value.replace(/\s+/g, '');
	return(TheField.value);
	}

// Function to trim whitespace from a string
function Util_WhiteSpaceTrim(TheField)
	{
	TheField.value = TheField.value.replace(/^\s+|\s+$/g, '');
	return(TheField.value);
	}

// End hide -->
