<!-- 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 || MaxLength == 0));
	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 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);
	}

// 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);
	Test = TheField.value.replace("$", "");
	IsValid = ! isNaN(Test);
	if (IsValid)
		TheField.value = "$" + formatDec(Test, 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(/^\w+@([-\w]+\.)+\w+$/g);
//	Test = TheField.value.match(/^[\w-_\.+]*[\w-_\.]\@([\w]+\\.)+[\w]+[\w]$/);
	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];
	TheMonth = TestDate[1];
	TheYear = TestDate[2];
	if (!isNaN(TheDay) && !isNaN(TheMonth) && !isNaN(TheYear))
		{
		TestDate = new Date(TheYear, TheMonth - 1, TheDay, 0, 0, 0);
		IsValid = ((parseInt("1" + TheDay) - 100 == TestDate.getDate()) && (parseInt("1" + TheMonth) - 100 == 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];
	TheMinutes = TestTime[1];
	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 a field in a form
function Validate_Field(TheForm, TheField, FormValidation)
	{
	var TheValidation, IsValid;
	var TheErrorMessage = "", FirstFault = null;
	TheValidation = FormValidation[TheField.name];
	if (TheValidation)
		{
		if (TheField.value.length == 0)
			{
			if (TheValidation.required)
				{
				TheErrorMessage += "The " + TheValidation.fieldname + " is required.\n";
				if (FirstFault == null) FirstFault = TheField;
				}
			}
		else
			{
			IsValid = TheValidation.verify(TheForm, TheField, TheValidation.min, TheValidation.max);
			if (! IsValid)
				{
				TheErrorMessage += "The " + TheValidation.fieldname + " is not valid.\n";
				if (FirstFault == null) FirstFault = TheField;
				}
			}
		}
	if (TheErrorMessage != "")
		{
		alert(TheErrorMessage);
		FirstFault.focus();
		}

	// Retrun whether the validation was successful
	return(TheErrorMessage == "");
	}

// Rountine to check the validation of all fields in a form
var WindowValidation;
function Validate_Form(TheEvent, TheForm, FormValidation)
	{
	var TheFormName = "";
	var Count, TheField, TheValidation, IsValid;
	var TheErrorMessage = "", FirstFault = null;
	TheField = TheForm.FormName;
	if (TheField)
		TheFormName = TheField.value;
	for (TheFieldName in FormValidation)
		{
		TheValidation = FormValidation[TheFieldName];
		TheField = document.getElementById(TheFormName + TheFieldName);
		if (TheField)
			{
			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 there is an error display it
	if (TheErrorMessage != "")
		{
		var TheDivError;
		TheDivError = document.getElementById("PanelErrorValidation");
		TheDivError.style["top"] = (TheEvent.clientY + 10) + "px";
		TheDivError.style["left"] = TheEvent.clientX + "px";
		TheDivError.style["display"] = "block";
		TheDivError = document.getElementById("PanelErrorIntroPlural");
		if (TheErrorMessage.indexOf(';', TheErrorMessage.indexOf(';') + 1) >= 0)
			TheDivError.innerHTML = "s were";
		else
			TheDivError.innerHTML = "&nbsp;was";
		TheDivError = document.getElementById("PanelErrorValidationContent");
		TheErrorMessage = "<li>" + TheErrorMessage.replace(";", "</li><li>") + "</li>";
		TheErrorMessage = TheErrorMessage.replace("<li></li>", "");
		TheDivError.innerHTML = "<ol>" + TheErrorMessage + "</ol>";
		}

	// Retrun whether the validation was successful
	return(TheErrorMessage == "");
	}

// Rountine to check the validation of all fields in a form
function Validate_Close()
	{
	var TheDivError;
	TheDivError = document.getElementById("PanelErrorValidation");
	TheDivError.style["display"] = "none";
	}

// Rountine to check the validation of all fields in a form
function Validate_Setup(TheForm, FormValidation)
	{
	var Count, TheField, TheValidation, IsValid;
	var TheErrorMessage = "", FirstFault = null;
	for (Count = 0; Count < TheForm.elements.length; Count++)
		{
		TheField = FormDiaryList.elements[Count];
		TheValidation = FormValidation[TheField.name];
		if (TheValidation)
			TheField.onblur = "Validate_Field(" + TheField + ", " + FormValidation + ");";
		}
	}

// Rountine to limit the max length of a field
function Validate_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;
	}

// Routine to set the preview of an image
function onChangeImage(TheImageNew, TheImageNewPreview, TheWidth, TheHeight)
	{
	var TheImageNewPreview;
	if (TheImageNew.value != "")
		{
		var TheNow = new Date();
		TheImageNewPreview = document.all(TheImageNewPreview);
		TheImageNewPreview.src = TheImageNew.value;
		setTimeout(function(){_setImageSize(TheImageNewPreview, TheWidth, TheHeight, TheNow)}, 500);
		}
	}

// Routine to set the size of an image after a couple of seconds - allows he browser to settle the image
function _setImageSize(TheImageNewPreview, TheWidth, TheHeight, TheNow )
	{
	var NewNow = new Date();
	TheWidth.value = TheImageNewPreview.width;
	TheHeight.value = TheImageNewPreview.height;
	}

// 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);
	}

// Function to format number into a decimal string
function formatDec(Value, Dec)
	{
	var StrOut;

	StrOut = leftPad(Math.round(Value * Math.pow(10, Dec)), "0", Dec+1);
	StrOut = StrOut.substring(0, StrOut.length - Dec)
		+ (Dec == 0 ? "" : ".") + StrOut.substring(StrOut.length - Dec);
	return (StrOut);
	}

// Rountine to check the deletion
function onDeleteConfirm()
	{
	return (confirm("Are you sure?"));
	}

// End hide -->
