//<script language="javascript">
	function ValidateCCNumberBox(sTitle, oInput)
	{
		// Purpose:	Simple validation of Credit card number
		// Version:	1.4.148
		// Comments: Supports VISA and MasterCard.
		//				If value is empty, will return true
		var sCCNumber;
		var lCCNumberLength = 0;
		var lSum = 0;
		var regEx;
		var bOddEven;
		var i;
		var lDigit;
		
		if (oInput && oInput.value)
		{
			sCCNumber = oInput.value;
			
			if (sCCNumber.length = 0)
			{
				return true;
			}
			else
			{
				// Remove all non-numeric chars
				regEx = new RegExp(/\D*/g);
				sCCNumber = sCCNumber.replace(regEx, "");
				lCCNumberLength = sCCNumber.length;
			
				// check for length
				if (lCCNumberLength < 14)
				{
					alert(sTitle + ' does not have enough digits. Please check the number and try again');
					oInput.focus();
					oInput.select();
					return false;				
				}
				if (lCCNumberLength > 16)
				{
					alert(sTitle + ' has too many digits. Please check the number and try again');
					oInput.focus();
					oInput.select();
					return false;				
				}

				// Check Mod10
				var bOddEven = lCCNumberLength & 1;

				for (var i = 0; i < lCCNumberLength; i++) 
				{
					var lDigit = parseInt(sCCNumber.charAt(i));
					if (!((i & 1) ^ bOddEven)) 
					{
						lDigit *= 2;
						if (lDigit > 9)
						lDigit -= 9;
					}
					lSum += lDigit;
				}
				if (lSum % 10 == 0)
				{
					return true;
				}
				else
				{
					alert(sTitle + ' is not a valid credit card number. Please check the number and try again');
					oInput.focus();
					oInput.select();
					return false;
				}
			}
		}
	}

	function ValidateSelect(sTitle, oSelect)
	{
		return ValidateSelectBox(sTitle, oSelect);
	}

	function ValidateSelectBox(sTitle, oSelect)
	{
		// Purpose:	Check a select to make sure that an item is selected.
		// Version:	1.0.107
		// Comments:	Checks the value to see if it has been set
								
		if (oSelect)
		{	
			if (oSelect.value == '')
			{
				alert('Please select a ' + sTitle + '.');
				oSelect.focus();
				return false;
			}
		}
		return true;				
	}

	function txtBox_OnFocus()
	{
		// Purpose:	Selects the text inside of a textbox ready to be overtyped
		// Version:	1.0.107
		// Date:	16-Oct-2002
		// Author:	daniel
		// Comments:	
		//			Call this from the OnFocus event of Password Input controls
		//			to facilitate easier user input when using the keyboard.
		//			TODO: Make this a behaviour (for IE)	
		try
		{
			if (event.srcElement)
			{
				event.srcElement.select();
			}
		}
		catch(e)
		{
			//
		}
	}

	function ValidatePasswordBoxes(sName, oTextBox1, oTextBox2)
	{
		// Purpose:	Validate Password boxes
		// Version:	1.0.107
		// Date:	08-Nov-2002
		// Author:	daniel
		// Comments:
		//			Checks the password and confirm password text boxes to ensure that they
		//			match and returns true if OK, displays an alert and return false if not.
		if (oTextBox1)
		{
			if (oTextBox2)
			{
				if (oTextBox1.value == oTextBox2.value)
				{
					// no worries
				}
				else
				{
					alert(sName + 's do not match.');
					oTextBox1.select();
					return false;
				}
			}
		}
		
		return true;
	}
		
	function ValidateNoSpacesInBox(sName, oTextBox)
	{
		// Purpose:	Checks for spaces in textbox
		// Version:	1.0.107
		// Date:	08-Nov-2002
		// Author:	daniel
		// Comments:

		try
		{

			if (oTextBox)
			{
				if (oTextBox.value.search(/\s/g) >= 0)
				{
					alert(sName + ' cannot contain any spaces.');
					oTextBox.select();
					return false;
				}
			}

			return true;
		}
		catch(e)
		{
			return true;
		}	
	}
		
	function ValidateEmailBox(sName, oTextBox)
	{
		// Purpose:	Validate An Email TextBox
		// Version:	1.0.107
		// Date:	07-Nov-2002
		// Author:	daniel
		// Comments:
		//			Ensure that the textbox is not empty and that 
		//			the email address uses correct syntax.
		var sTemp = '';
	
		try
		{
			if (oTextBox)
			{
				if (ValidateTextBox(sName, oTextBox))
				{
					if (ValidateNoSpacesInBox(sName, oTextBox))
					{
						// email address must have at least one at sign (@) and one fullstop(.)
						sTemp = oTextBox.value;
					
						if ((sTemp.search(/\@/g) < 0) || (sTemp.search(/\./g) < 0))
						{
							alert('Please enter a valid ' + sName);
							oTextBox.select();
							return false;
						}
					}
					else
					{
						return false;
					}
				}
				else
				{
					return false;
				}
			}
			else
			{
				//throw oTextBox.id + ' does not exist.'
			}

			return true;
		}
		catch(e)
		{
			return true;
		}
	}
	
	function ValidateTextBox(sName, oTextBox)
	{
		// Purpose:	Validate A TextBox
		// Version:	1.0.107
		// Date:	07-Nov-2002
		// Author:	daniel
		// Comments:
		//			Ensure that the textbox is not empty
		var sTemp = '';

		try
		{
		
			// No validation takes place if TextBox is not found
			if (oTextBox)
			{		
				sTemp = oTextBox.value.replace(/\s/g, '');
		
				if(sTemp.length == 0)
				{
					alert(sName + ' cannot be blank.');
					oTextBox.select();
					return false;
				}
			}
			else
			{
				//throw oTextBox.id + ' does not exist.'
			}

			return true;
		}
		catch(e)
		{
			return true;
		}
	}

	// Validate box has given minimum and maximum length constraints
	function kxValidateBoxLength(sName, oTextBox, iMinLen, iMaxLen)
	{
		try 
		{
			if (sName)
			{
				var bError = false;
				var sTxt = oTextBox.value;
				if (iMinLen != null) if (sTxt.length < iMinLen) bError = true;
				if (iMaxLen != null) if (sTxt.length > iMaxLen) bError = true;
				if (bError)
				{
					var sAlert = sName + " must have a";
					if (iMinLen != null) 
					{
						sAlert = sAlert + " minimum length of " + iMinLen;
						if (iMaxLen != null) sAlert = sAlert + " and a";
					}
					if (iMaxLen != null)
					{
						sAlert = sAlert + " maximum length of " + iMaxLen;
					}
					alert(sAlert);
					oTextBox.select();
					return false;
				}
			}
		}
		catch(e) { }
		return true;
	}

	// Validate format is {12345678-1234-1234-1234-1234567890ab} where characters may be 1-9, a-f, A-F
	function kxValidateGUID(sGuid)
	{
		try
		{
			if (sGuid.length != 38) return false;
			if (sGuid.charAt(0) != '{' && sGuid.charAt(37) != '}') return false;
			if (sGuid.charAt(9) != '-' && sGuid.charAt(14) != '-' && sGuid.charAt(19) != '-' && sGuid.charAt(24) != '-') return false;
			sGuid = sGuid.replace(/[a-fA-F0-9]/g, '');
			if (sGuid == "{----}") return true;
			return false;
		}
		catch(e) { return false; }
	}

//</script>
