<!--
/*
Explanation of Parameters:
	field : The field to be Validated withing the form.
	message : The message that is displayed to the user when validation fails.
	instance : The instance of validation that is to be used.

	Allowed Instances:
	1 : Validates the existence of any data value (Text or number)
	2 : Checks that a value is numeric.
	3 : Check that the value contains both a numbers AND Text (AplhaNumeric)
	4 : Checks that email addresses have an @ sign and a . (period). Invalid characters are also not permitted.
	5 : Validates a South African Cellular Number
	6 : Validates a South African Telephone Number.
	7 : Date format is checked for validity
	8 : Time format is checked for validity
	9 : Validates a Credit Card Number
	10 : Ensures a correct URL is entered
	11: A value in the DropDown Box must be selected
	12: Check that one Radio button is selected.
	13: Check that the checkbox is checked.
	14: Validates a South African ID Numbers
	15: Checks that a value is numeric and is larger than 0.
*/

function DoV(arrFields, arrInstances, arrMessages) {
	//This function runs through field name values given in array and does the required instance validation.
	//If the validation fails the message is displayed.

	for (var i=0; i<arrFields.length;i++) {
		//Loop through array values

		var Field = arrFields[i];
		var Instance = arrInstances[i];
		var Message = arrMessages[i];
		
//		alert('value= '+ Field + '\n' + 'inst= '+ Instance + '\n' + 'msg= '+ Message);

		//Switch between instances
		switch (Instance) {
			case 1: {
				if (Field.value=='') {
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
			case 2: {
				if ((Field.value=='') || (!isFinite(Field.value))) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
			case 3: {
				var checkstring = Field.value;
				var TestExp = /\d/;
				if (checkstring.search(TestExp)!==-1) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
			case 4: {
				var atposition = Field.value.indexOf('@');
				var ExpCheck = /[,"<>:;]|\]|\[|\(|\)|\\/g
				if ((Field.value=='')||
					(atposition==-1)||
					(Field.value.indexOf('.', atposition)==-1)||
					(Field.value.indexOf('@', atposition+1)!=-1)||
					(Field.value[Field.value.length-1]=='.')) {
					
					window.alert(Message);
					Field.focus();
					return false;
				};
				if (Field.value.search(ExpCheck)!=-1) {
					window.alert(Message);
					field.focus();
					return false;
				};
				break;
			};
			case 5: {
				if (Field.value=='') {
					window.alert(Message);
					Field.focus();
					return false;
				};
				var TempTel = Field.value;
				var test = /[ ()]|-/g;
				TempTel = TempTel.replace(test,'');
				if (!isFinite(TempTel)) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				if (TempTel.length <10) {
					window.alert(Message);
					field.focus();
					return false;
				};
				if ((TempTel.substring(0,3)!='083') && (TempTel.substring(0,3)!='082') && (TempTel.substring(0,3)!='072')){
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
			case 6: {
				if (Field.value=='') {
					window.alert(Message);
					Field.focus();
					return false;
				};
				var TempTel = Field.value;
				var test = /[ ()]|-/g;
				TempTel = TempTel.replace(test,'');
				if (!isFinite(TempTel)) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
			case 7: {
				if (Field.value=='') {
					window.alert(Message);
					Field.focus();
					return false;
				};
				var dArray = Field.value.split(" ");
				if (dArray.length < 3) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				dDay = dArray[0];
				dMonth = dArray[1];
				dYear = dArray[2];
				
				if ((dDay.length < 1)||(dMonth.length < 3)||(dYear.length < 4)) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				
				d = new Date(Field.value);
				if (!isFinite(d)) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				if (Field.value.indexOf('/')!=-1) {
					//Not Full date used
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;	
			};
			case 8: {
				if (Field.value.indexOf(':')==-1) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				
				var tArray = Field.value.split(":");
				tHrs = tArray[0];
				tMin = tArray[1];

				if ((tHrs.length>2)||(tHrs.length==0)||(!isFinite(tHrs))||(parseInt(tHrs)>23)) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				
				if ((tMin.length>2)||(tMin.length<2)||(!isFinite(tMin))||(parseInt(tMin)>59)) {
					window.alert(Message);
					Field.focus();
					return false;
				};

				break;
			};
			case 9: {
				var doubledigit = (Field.value.length % 2 == 1) ? false : true;
				var checkdigit = 0;
				var tempdigit=0;
				
				for (var i=0; i<field.value.length;i++) {
					tempdigit=eval(field.value.charAt(i));
					if (doubledigit) {
						tempdigit*=2;
						checkdigit+=(tempdigit%10);
						if ((tempdigit/10)>=1.0) {
							checkdigit++;
						}
						doubledigit=false;
					} else {
						checkdigit+=tempdigit;
						doubledigit=true;
					};
				};
				if ((checkdigit%10)!=0) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
			case 10: {
				if ((Field.value.length)<=7) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				if ((Field.value.substr(0,7)).toUpperCase()!='HTTP://') {
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};		
			case 11: {
				if (Field[Field.selectedIndex].value=='-1'){
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
			case 12: {
				var i;
				for (i=0; i<Field.length; i++) {
					if (Field[i].checked) {
						return true;
						break;
					};
				};
				window.alert(Message);
				return false;
				break;
			};
			case 13: {
				if ((Field.checked==false)) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
			case 14: {
				if ((Field.value.length)<13) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
			case 15: {
				if ((Field.value=='') || (!isFinite(Field.value)) || (Field.value<1)) {
					window.alert(Message);
					Field.focus();
					return false;
				};
				break;
			};
		};
	};
	return true;
};
//-->
