//# Name                Validate.js
//# Version             69.50 Multi-Language
//# Modified            02/11/2004 17:26
//# Copyright Rocktime Ltd/Kieron Matthews 2000 - 2004.
//# Not to be used in whole or part without written permission from Rocktime.


//################################################################################
//	Start js
//################################################################################

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Call this routine to run
// Validation Field, FriendlyName, Tests, Options
//
// Field includes the name of the form
//
// FriendlyName is the name that will appear in the error message box
//
// Tests can be:
// "W" Capitalise words
// "S" Capitalise sentenses
// "U" Capitalise all
// "L" Lowercase all
// "A>4" Text greater than or equal to 4 characters, 0 = not blank
// "A<20" Test less than or equal to 20
// "A1,20" Text greater than or equal to 1 character and less than or equal to 20, 0 in min = not blank
// "N" Must be a number
// "NN>1" Number greater than and NOT equal to 1
// "NN<1000" Number less than and NOT equal to 1000
// "N>>1" Number greater than or equal to 1
// "N<<1000" Number less than or equal to 1000
// "N5,500" Number greater than or equal to 5, less than or equal to 500
// "D" UK date field
// "DB" UK date field or Blank
// "DT" UK date and time
// "DTB" UK date and time or Blank
// "C" (Clock) Time hh:mm(:ss)
// "CB" (Clock) Time hh:mm(:ss) or Blank
// "H" Web URL
// "E" Email address
// "EB" Email address or Blank
// "T" Telephone number
// "O" Select Option Drop Box (0 = not selected)
// "F" Allow form to only submit once
// "P" Password function used to compare two passwords
// "B3" Tick boxes, at least 3 need to be ticked
// "BM3" Tick boxes, no more than 3 need to be ticked
// "BR1,3" Tick boxes, Less than 3 and more than 1 need to be ticked
// "BB" Make sure a radio button has been selected
// "R" Checks for SQL Unique Identifier
// "X" Stops submit (test mode)
// "" Makes empty function
//
// Combinations can be used, so Tests could be "EA5,255" = Email address greater than or equal to 5  characters, less than or equal to 255
// For checkboxes use Validation "myForm,mycheckbox1,mycheckbox2,mycheckbox3,etc", "My text box", "A3,30E", 0
//
// Options are 0,1,2 or 3 where:
// 0 Only one field to test
// 1 First field to test
// 2 Middle field
// 3 Last field
//
// eg. Validation "myForm.myField", "My text box", "A3,30", 0
//
// You must remember to add the line onSubmit='return validate();' to the form
//
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript test Password Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	var GlobalStatus = true;
	var GlobalErrors = "";
	var GlobalErrorTarget = null;


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Set Error
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


	function alertValidate(amessage){

		if (GlobalStatus){
			GlobalErrors = amessage;
		}
		else {
			if (amessage != "") {
				GlobalErrors = GlobalErrors + "\n" + amessage;
			}
		}
		GlobalStatus = false;

	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Set Error
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function SetFocus(field){

		if (GlobalErrorTarget == null) {
			GlobalErrorTarget = field;
		}
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript test Password Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	var FirstPasswordfield = "";
	var FirstPasswordfName = "";

	function testPassword(tmpfield, fName) {

	  	if ( FirstPasswordfName == "" ) {
			FirstPasswordfield = tmpfield;
			FirstPasswordfName = fName;
	 	}
	  	else {
	  		if ( FirstPasswordfield.value != tmpfield.value ) {
//	  			alertValidate(FirstPasswordfName + ' must be the same as ' + fName + '.\nPlease enter both fields again!');
	  			alertValidate(ValidateMessagePassword(FirstPasswordfName, fName));
				SetFocus(FirstPasswordfield);
				FirstPasswordfName = "";
				return (false);
	  		}
//			FirstPasswordfield = "";
			FirstPasswordfName = "";
			tmpfield.value = "";
	  	}

		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript test Date Time Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function testDateTime(tmpfield, fName, timeBlank) {

		var tmpDate = '';
	  	var tmpTime = '';
	  	var tmpFlag = false;
	  	if ( tmpfield.value.length == 0 && timeBlank == true ) {
				return (true);
	  	}
	  	if ( tmpfield.value.length < 10 || tmpfield.value.length > 23 ) {
//				alertValidate(fName + ' is not a valid timestamp\nPlease enter in the format DD/MM/YY(YY) hh:mm(:ss(.ms)) (AM/PM) 12 or 24 hour');
				alertValidate(ValidateMessageTimeStamp(fName));
				SetFocus(tmpfield);
				return (false);
	  	}
	  	for (i = 0; i < tmpfield.value.length; i++ ) {;
	  		if ( tmpfield.value.charAt(i) == ' ' && tmpFlag == false ) {
	  			tmpFlag = true;
	  		}
	  		if ( tmpFlag == false ) {
	  			tmpDate += tmpfield.value.charAt(i);
	  		}
	  		else {
	  			tmpTime += tmpfield.value.charAt(i);
	  		}
	  	}
		tmpTime = tmpTime.replace(' ','');

	 	tmpfield.value = tmpDate;
		if ( !testDate(tmpfield,fName,false) ) {
			tmpfield.value = tmpDate + ' ' + tmpTime;
			return (false);
		}
	 	tmpDate = tmpfield.value;
	 	tmpfield.value = tmpTime;
		if ( !testTime(tmpfield,fName,false) ) {
			tmpfield.value = tmpDate + ' ' + tmpTime;
			return (false);
		}
	 	tmpTime = tmpfield.value;
		tmpfield.value = tmpDate + ' ' + tmpTime;
		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Test Time Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function testTime(tmpfield, fName, timeBlank) {
		var checkOK = '0123456789amAPMp. ';
	  	var allValid = true;
		var chValid = false;
		var separatorFound = 0;
		var timeH = '00';
		var timeM = '00';
		var timeS = '00';
		var timeMS = '000';
		var PMFlag = false;
		if ( tmpfield.value == '' && timeBlank == true ) {
			return (true);
		}
		if ( tmpfield.value == '' && timeBlank == false ) {
//			alertValidate(fName + ' is not a valid time\nPlease enter in the format hh:mm(:ss(.ms)) 12 or 24 hour!');
			alertValidate(ValidateMessageTimeSS(fName));
			SetFocus(tmpfield);
			return (false);
		}
		else {
			if ( tmpfield.value.length < 3 ) {
//				alertValidate(fName + ' is not a valid time\nPlease enter in the format hh:mm(:ss(.ms)) 12 or 24 hour!');
				alertValidate(ValidateMessageTimeSS(fName));
				SetFocus(tmpfield);
	    		return (false);
			}
			for (i = 0; i < tmpfield.value.length; i++) {
				k = tmpfield.value.charAt(i);
				chValid = false;
				for (j = 0;  j < checkOK.length;  j++) {
					if (k == checkOK.charAt(j)) { // check character against allowed characters
						chValid = true;
						if (k=='a' || k=='A' || k=='p' || k=='P' || k=='m' || k=='M' || k==' '){
							if (k=='p' || k=='P'){
								PMFlag = true;
							}
						}
						else {
							if ( separatorFound == 0 ) {
								timeH += k;
							}
							else if ( separatorFound == 1 ) {
								timeM += k;
							}
							else if ( separatorFound == 2 ) {
								timeS += k;
							}
							else if ( separatorFound == 3 ) {
								timeMS += k;
							}
						}
						break;
					}
					if (((k == ':') && (separatorFound < 3))||((k == '.') && (separatorFound == 3))) { // check character against separator
						chValid = true;
						separatorFound++;
						break;
					}
				}
				if (!chValid) {
					allValid = false;
//					alertValidate(fName + ' is not a valid time\nPlease enter in the format hh:mm(:ss(.ms)) 12 or 24 hour!');
					alertValidate(ValidateMessageTimeSS(fName));
					SetFocus(tmpfield);
	    			return (false);
				}
			}
			timeH = timeH.substr(timeH.length - 2, 2);
			timeM = timeM.substr(timeM.length - 2, 2);
			timeS = timeS.substr(timeS.length - 2, 2);
			timeMS = timeMS.substr(timeMS.length - 3, 3);
			if ( parseInt(timeH) <= 11 && parseInt(timeH) >= 0 && PMFlag == true){
				timeH = String(parseInt(timeH) + 12);
			}

			if ( parseInt(timeH) > 23 || parseInt(timeH) < 0 || parseInt(timeM) > 59 || parseInt(timeM) < 0 || parseInt(timeS) > 59 || parseInt(timeS) < 0 ) {
//				alertValidate(fName + ' is not a valid time\nPlease enter in the format hh:mm(:ss(.ms)) 12 or 24 hour!');
				alertValidate(ValidateMessageTimeSS(fName));
				SetFocus(tmpfield);
	    		return (false);
			}
			if (timeMS = '000') {
				tmpfield.value = timeH + ':' + timeM + ':' + timeS
			}
			else {
				tmpfield.value = timeH + ':' + timeM + ':' + timeS + '.' + timeMS;
			}
		}
		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript testDropBox Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function testDropBox(tmpfield, fName) {
		if (tmpfield.value == 'ERROR!') {
//			alertValidate('Please select an item from the ' + fName + ' list.');
			alertValidate(ValidateMessageList(fName));
			SetFocus(tmpfield);
	    	return (false);
		}
		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Capitalise All Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function upperCase(tmpfield) {
		var wordString = tmpfield.value;
		var newWordString = '';
		if ( wordString.length > 0 ) {
			newWordString = wordString.toUpperCase();
			tmpfield.value = newWordString;
		}
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Lowercase All Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function lowerCase(tmpfield) {
		var wordString = tmpfield.value;
		var newWordString = '';
		if ( wordString.length > 0 ) {
			newWordString = wordString.toLowerCase();
			tmpfield.value = newWordString;
		}
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Capitalise Sentence Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function capSentence(tmpfield) {
		var wordString = tmpfield.value;
		var newWordString = '';
	 	var pos = 0;
	 	var foundSpace = true;
	 	var foundDot = true;
		if ( wordString.length > 0 ) {
			while ( pos < wordString.length ) {
	 			if (((64 < wordString.charCodeAt(pos) && wordString.charCodeAt(pos) < 91) || (96 < wordString.charCodeAt(pos) && wordString.charCodeAt(pos) < 123)) && foundDot == true  && foundSpace == true ) {
	 				newWordString = newWordString + wordString.charAt(pos).toUpperCase();
	 				foundSpace = false;
	 				foundDot = false;
	 			}
	 			else {
	 				newWordString = newWordString + wordString.charAt(pos);
	 			}
	 			if ( 32 == wordString.charCodeAt(pos) && foundDot == true) {
	 				foundSpace = true;
	 			}
	 			else {
	 				foundDot = false;
	 			}
	 			if ( 46 == wordString.charCodeAt(pos) | 33 == wordString.charCodeAt(pos) | 63 == wordString.charCodeAt(pos) | 58 == wordString.charCodeAt(pos) ) {
	 				foundDot = true;
	 			}
				pos++;
			}
			tmpfield.value = newWordString;
		}
	}



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Capitalise Word Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function capWord(tmpfield) {
		var wordString = tmpfield.value;
		var newWordString = '';
	 	var pos = 0;
	 	var foundSpace = true;
		if ( wordString.length > 0 ) {
			while ( pos < wordString.length ) {
	 			if (((64 < wordString.charCodeAt(pos) && wordString.charCodeAt(pos) < 91) || (96 < wordString.charCodeAt(pos) && wordString.charCodeAt(pos) < 123)) && foundSpace == true ) {
	 				newWordString = newWordString + wordString.charAt(pos).toUpperCase();
	 				foundSpace = false;
	 			}
	 			else {
	 				newWordString = newWordString + wordString.charAt(pos);
	 			}
	 			if ( 32 == wordString.charCodeAt(pos) ) {
	 				foundSpace = true;
	 			}
				pos++;
			}
			tmpfield.value = newWordString;
		}
	}



//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript testTel Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function testTel(tmpfield, fName, TelBlankFlag) {
		var checkOK = '0123456789-+() ';
	  	var allValid = true;
		var chValid = false;
		if ( TelBlankFlag == false ) {
			if ( tmpfield.value == null || tmpfield.value == '' ) {
				allValid = false;
//				alertValidate(fName + ' is not a valid telephone number');
				alertValidate(ValidateMessageTel(fName));
				SetFocus(tmpfield);
				return (false);
			}
		}
		for (i = 0; i < tmpfield.value.length; i++) {
			k = tmpfield.value.charAt(i);
			chValid = false;
			for (j = 0;  j < checkOK.length;  j++) {
				if (k == checkOK.charAt(j)) { // check character against allowed characters
					chValid = true;
					break;
				}
			}
			if (!chValid) {
				allValid = false;
//				alertValidate(fName + ' is not a valid telephone number');
				alertValidate(ValidateMessageTel(fName));
				SetFocus(tmpfield);
	    		return (false);
			}
			checkOK = '0123456789-() ';
		}
		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript IsNumber? Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


	function isNum(xnum, xtmpfield, xfName) {
		return(isABNum(xnum, xtmpfield, xfName, 'D'));
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript IsAnyBaseNumber? Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


	function isABNum(num, tmpfield, fName, tmpType) {

		var checkOK;
	  	var allValid = true;
		var chValid = false;
		var negFlag = false;
		var decFlag = false;

		tmpType = tmpType.toUpperCase();
		num = num.toUpperCase();

		switch(tmpType) {
			case "D" :
				checkOK = '0123456789.,';
				break;
			case "B" :
				checkOK = '01';
				break;
			case "H" :
				checkOK = '0123456789ABCDEF';
				break;
			case "O" :
				checkOK = '01234567';
				break;
			default :
				checkOK = '0123456789.';
				break;
		}

		if ( num == null ) {
			return (false);
		}

		l = num.charAt(0);
		if ( l == '-' ) {
			num = num.slice(1, num.length);
		}

		for (i = 0; i < num.length; i++) {
			k = num.charAt(i);
			if ( (k == '.' || k == ",") && decFlag == true ) {
				if ( fName != "" ) {
//					alertValidate(fName + ' is not a valid number');
					alertValidate(ValidateMessageNum(fName));
				}
				if ( tmpfield != "" ) {
					SetFocus(tmpfield);
					tmpfield.select();
				}
	    		return (false);
			}

			if ( k == '.' && decFlag == false ) {
				decFlag = true;
			}

			chValid = false;
			for (j = 0;  j < checkOK.length;  j++) {
				if (k == checkOK.charAt(j)) { // check character against allowed characters
					chValid = true;
					break;
				}
			}
			if (!chValid) {
				allValid = false;
				if ( fName != "" ) {
//					alertValidate(fName + ' is not a valid number');
					alertValidate(ValidateMessageNum(fName));
				}
				if ( tmpfield != "" ) {
					SetFocus(tmpfield);
					tmpfield.select();
				}
	    		return (false);
			}
		}
		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Text Test Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function testTextLen(tmpfield,name,min,max) {
	  	var allValid = true;
		var errorMsg = '';
		if (min != 'na') {
  			if (min == 0 && tmpfield.value.length == 0) {
//				errorMsg = name + ' cannot be left blank.';
				errorMsg = ValidateMessageCharBlank(name);;
				allValid = false;
			}
			if (tmpfield.value.length < min && min != 0) {
				if (min > 1 ) {
//	  				errorMsg = name + ' must be a minimum length of ' + min + ' characters.';
	  				errorMsg = ValidateMessageCharMin(name, min, true);
	  			}
	  			else {
//	  				errorMsg = name + ' must be a minimum length of ' + min + ' character.';
	  				errorMsg = ValidateMessageCharMin(name, min, false);
	  			}
				allValid = false;
			}
	  	}
		if (max != 'na') {
			if (tmpfield.value.length > max) {
	  			if (max > 1 ) {
//	  				errorMsg = name + ' must be a maximum length of ' + max + ' characters.';
	  				errorMsg = ValidateMessageCharMax(name, max, true);
	  			}
	  			else {
//	  				errorMsg = name + ' must be a maximum length of ' + max + ' character.';
	  				errorMsg = ValidateMessageCharMax(name, max, false);
	  			}
				allValid = false;
			}
		}
	  	if (!allValid) {
	    	alertValidate(errorMsg);
	    	SetFocus(tmpfield);
	    	return (false);
	  	}
		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Date Test Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function isDNum(num) {
		var checkOK = '0123456789';
	  	var allValid = true;
		var chValid = false;
		if ( num == null ) {
			return (false);
		}
			for (i = 0; i < num.length; i++) {
				k = num.charAt(i);
				chValid = false;
				for (j = 0;  j < checkOK.length;  j++) {
					if (k == checkOK.charAt(j)) { // check character against allowed characters
						chValid = true;
						break;
					}
				}
				if (!chValid) {
					allValid = false;
				}
			}
		if (!allValid)
	  	{
	    	return (false);
	  	}
		return(true);
	}


	function testDate(tmpfield,name,blank) {
		var allValid = true;
		var allDashFlag = false;
		var D,M,Y,B1,B2,MaxD;
		var blankErrorMsg = '';
//		if ( blank == true ) {
//			blankErrorMsg = ' or leave blank';
//		}
//		var errorMsg = name + ' does not conform to UK date standard.\nPlease input date as DD/MM/YY(YY)' + blankErrorMsg + '.';
		var errorMsg = ValidateMessageDate(name, blank);
		var tDate = tmpfield.value;
		if  ( tDate.length == 0 && blank == true ) {
			return(true);
		}
		if	( tDate.length < 6 || tDate.length > 10 ) {
			alertValidate(errorMsg);
			SetFocus(tmpfield);
			return(false);
		}
		else {// Day

				for (i = 0; i < tDate.length; i++) {
					if (tDate.charAt(i) == '/' || tDate.charAt(i) == '-' || tDate.charAt(i) == '.' || tDate.charAt(i) == '\\') {
						allDashFlag = true;
						break;
					}
				}

				if (allDashFlag == false){
						tDate = tDate.substring(0,2) + "/" + tDate.substring(2,4) + "/" + tDate.substring(4,tDate.length);
				}

				for (i = 0; i < tDate.length; i++) {
					if (tDate.charAt(i) == '/' || tDate.charAt(i) == '-' || tDate.charAt(i) == '.' || tDate.charAt(i) == '\\') {
						D = tDate.substring(0,i);
						tDate = tDate.substring(i+1,tDate.length);
						break;
					}
				}
				for (i = 0; i < tDate.length; i++) {
				if (tDate.charAt(i) == '/' || tDate.charAt(i) == '-' || tDate.charAt(i) == '.' || tDate.charAt(i) == '\\') {
						M = tDate.substring(0,i);
						tDate = tDate.substring(i+1,tDate.length);
						break;
					}
				}

				if (tDate.length == 2){
					if (tDate > 20){
						tDate = "19" + tDate;
					}
					else {
						tDate = "20" + tDate;
					}
				}

				if (M == 2){
					MaxD = 28;
					if ((tDate%4) == 0){
						MaxD = 29;
					}
					if ((tDate%100) == 0 && (tDate%400) != 0){
						MaxD = 28;
					}
				}
				else {
					if (M == 4 || M == 6 || M == 9 || M == 11){
						MaxD = 30;
					}
					else {
						MaxD = 31;
					}
				}

				if ( isDNum(D) ) {
					if ( D > MaxD || D < 1) {
//						alertValidate(D + ' is not a valid day for ' + name + '\nPlease input date as DD/MM/YY(YY)' + blankErrorMsg);
						alertValidate(ValidateMessageDateDay(name, D, blank));
						SetFocus(tmpfield);
						return(false);
					}
				}
				else {
					if ( D == null ){
//						alertValidate('Not a valid day for ' + name + '\nPlease input date as DD/MM/YY(YY)' + blankErrorMsg);
						alertValidate(ValidateMessageDateDay(name, '', blank));
					}
					else {
//						alertValidate(D + ' is not a valid day for ' + name + '\nPlease input date as DD/MM/YY(YY)' + blankErrorMsg);
						alertValidate(ValidateMessageDateDay(name, D, blank));
	 				}
					SetFocus(tmpfield);
					return(false);
				}
				if ( isDNum(D) && D.length == 1) {
					D = '0' + D;
				}
				// Month
				if ( isDNum(M) ) {
					if ( M > 12 || M < 1) {
//						alertValidate(M + ' is not a valid month for ' + name + '\nPlease input date as DD/MM/YY(YY)' + blankErrorMsg);
						alertValidate(ValidateMessageDateMonth(name, M, blank));
						SetFocus(tmpfield);
						return(false);
					}
				}
				else {
					if ( M == null ) {
//						alertValidate('Not a valid month for ' + name + '\nPlease input date as DD/MM/YY(YY)' + blankErrorMsg);
						alertValidate(ValidateMessageDateMonth(name, '', blank));
					}
					else {
//						alertValidate(M + ' is not a valid month for ' + name + '\nPlease input date as DD/MM/YY(YY)' + blankErrorMsg);
						alertValidate(ValidateMessageDateMonth(name, M, blank));
	 				}
					SetFocus(tmpfield);
					return(false);
				}
				if ( isDNum(M) && M.length == 1) {
					M = '0' + M;
				}
				// Year
				if ( isDNum(tDate) && tDate.length == 4) {
					allValid = true;
				}
				else {
					if ( Y == null ) {
//						alertValidate('Not a valid year for ' + name + '\nPlease input date as DD/MM/YY(YY)' + blankErrorMsg);
						alertValidate(ValidateMessageDateMonth(name, '', blank));
					}
					else {
//						alertValidate(tDate + ' is not a valid year for ' + name + '\nPlease input date as DD/MM/YY(YY)' + blankErrorMsg);
						alertValidate(ValidateMessageDateMonth(name, tDate, blank));
	 				}
					SetFocus(tmpfield);
					return(false);
				}
		}
		tmpfield.value = D + '/' + M + '/' + tDate
		return(allValid);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript URL Test Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function testURL(tmpfield,name,blank) {
		var TEs = tmpfield.value;
		var allValid = false;
		var blankErrorMsg = '';
//		if ( blank == true ) {
//			blankErrorMsg = ' or leave blank';
//		}
		if  (((TEs.length == 0) || (TEs == 'http://')) && (blank == true)) {
			return(true);
		}
		for (j = 0;  j < TEs.length;  j++) {
			ch = TEs.charAt(j);
			if (ch == '.') {
				allValid = true;
				break;
			}
		}
		if (!allValid)
		{
//			alertValidate(name + ' is not a valid url.\nPlease input a valid url' + blankErrorMsg) + '.';
			alertValidate(ValidateMessageURL(name, blank));
			SetFocus(tmpfield);
			return (false);
		}
		if (allValid) {
			lowerCase(tmpfield);
//			tmpfield.value = tmpfield.value.replace('http://', '');
		}
		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Email Test Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function testEmail(tmpfield,name,blank) {
		var TEs = tmpfield.value;
		var allValid = false;
		var atFlag = false;
		var blankErrorMsg = '';
//		if ( blank == true ) {
//			blankErrorMsg = ' or leave blank';
//		}
		if  ( TEs.length == 0 && blank == true ) {
			return(true);
		}
		for (j = 0;  j < TEs.length;  j++) {
			ch = TEs.charAt(j);
			if (ch == '@' && atFlag == false) {
				atFlag = true;
			}
			if (ch == '.' && atFlag == true) {
				allValid = true;
				break;
			}
		}
		if (!allValid)
		{
//			alertValidate(name + ' is not a valid email address.\nPlease input a valid email address' + blankErrorMsg) + '.';
			alertValidate(ValidateMessageEmail(name, blank));
			SetFocus(tmpfield);
			return (false);
		}
		if (allValid) {lowerCase(tmpfield);}
		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Number Test Routine
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function testNum(tmpfield,name,min,max,tmpType,neflag) {

		var checkStr = tmpfield.value;
	  	var allValid = true;
		var errorMsg = '';
	  	//check for number
	  	if (!isABNum(checkStr, tmpfield, name, tmpType)) {
	    	return (false);
		}
		if (neflag == false) {
			if (allValid && min != 'na') {
				if (tmpfield.value < min) {
//		  			errorMsg = name + ' must be a minimum value of ' + min + '.';
		  			errorMsg = ValidateMessageNumMin(name, min);
					allValid = false;
				}
		  	}
			if (allValid && max != 'na') {
				if (tmpfield.value > max) {
//		  			errorMsg = name + ' must be a maximum value of ' + max + '.';
		  			errorMsg = ValidateMessageNumMax(name, max);
					allValid = false;
				}
			}
		}
		else {
			if (allValid && min != 'na') {
				if (tmpfield.value <= min) {
//		  			errorMsg = name + ' must be greater than a value of ' + min + '.';
		  			errorMsg = ValidateMessageNumGreater(name, min);
					allValid = false;
				}
		  	}
			if (allValid && max != 'na') {
				if (tmpfield.value >= max) {
//		  			errorMsg = name + ' must be less than a value of ' + max + '.';
		  			errorMsg = ValidateMessageNumLess(name, max);
					allValid = false;
				}
			}
		}
		if (!allValid)
	  	{
	    	alertValidate(errorMsg);
	    	SetFocus(tmpfield);
			return(false);
	  	}
		return(true);
	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Base N To Decimal Converter
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function baseN2Dec(value,inBase) {

		var strValue;
		var i;
		var x;
		var y;
		var tmpType;

		strValue = value.toString().toUpperCase();

		switch(inBase) {
			case 10 :
				tmpType = 'D';
				break;
			case 2 :
				tmpType = 'B';
				break;
			case 16 :
				tmpType = 'H';
				break;
			case 8 :
				tmpType = 'O';
				break;
			default :
				tmpType = 'D';
				break;
		}

		if ( isABNum(strValue, "", "", tmpType) ) {
			for (i=strValue.length()-1; i=0; i--) {
				x = strValue.charCodeAt(i);
				if ( x >= 65 ) {
					x = x - 55;
				}
				else {
					x = x - 48;
				}
				y = y + ( x * (inBase ^ (strValue.length() - 1)));
			}
		}
		else {
			return "NaN";
		}

		return y;

	}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// JavaScript Test For Unique Identifier
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

	function testUID(strUID, tmpField, tmpName) {

		var strTest;

		if ( strUID.length() != 36 ) {
			return (false);
		}
		if ( strUID.charAt(9) != "-" || strUID.charAt(14) != "-" || strUID.charAt(19) != "-" || strUID.charAt(24) != "-" ) {
			if ( tmpName != "" ) {
//				alertValidate(tmpName + " is not a valid UID.");
				alertValidate(ValidateMessageUID(tmpName));
			}
			if ( tmpField != "" ) {
				SetFocus(tmpfield);
			}
			return (false);
		}

		strTest = strUID.subStr(0,8)
		if ( !isABNum(strTest, "", "", "H") ) {
			if ( tmpName != "" ) {
//				alertValidate(tmpName + " is not a valid UID.");
				alertValidate(ValidateMessageUID(tmpName));
			}
			if ( tmpField != "" ) {
				SetFocus(tmpfield);
			}
			return (false);
		}
		strTest = strUID.subStr(10,4)
		if ( !isABNum(strTest, "", "", "H") ) {
			if ( tmpName != "" ) {
//				alertValidate(tmpName + " is not a valid UID.");
				alertValidate(ValidateMessageUID(tmpName));
			}
			if ( tmpField != "" ) {
				SetFocus(tmpfield);
			}
			return (false);
		}
		strTest = strUID.subStr(15,4)
		if ( !isABNum(strTest, "", "", "H") ) {
			if ( tmpName != "" ) {
//				alertValidate(tmpName + " is not a valid UID.");
				alertValidate(ValidateMessageUID(tmpName));
			}
			if ( tmpField != "" ) {
				SetFocus(tmpfield);
			}
			return (false);
		}
		strTest = strUID.subStr(20,4)
		if ( !isABNum(strTest, "", "", "H") ) {
			if ( tmpName != "" ) {
//				alertValidate(tmpName + " is not a valid UID.");
				alertValidate(ValidateMessageUID(tmpName));
			}
			if ( tmpField != "" ) {
				SetFocus(tmpfield);
			}
			return (false);
		}
		strTest = strUID.subStr(25,12)
		if ( !isABNum(strTest, "", "", "H") ) {
			if ( tmpName != "" ) {
//				alertValidate(tmpName + " is not a valid UID.");
				alertValidate(ValidateMessageUID(tmpName));
			}
			if ( tmpField != "" ) {
				SetFocus(tmpfield);
			}
			return (false);
		}

		return (true);

	}

//################################################################################
//	End JavaScript Routines
//################################################################################


