// checkRequiredFields
	function checkRequiredFields(formObj) {  
		var alert_message = ""; 

		// LOOP THROUGH FIELDS TO BE VALIDATED
		for (i = 0; i < formObj.requiredFields.length; i++) {
			if (formObj.requiredFields[i].value != "") {
				
				temp = formObj.requiredFields[i].value.split("|");
				fieldName 		= temp[0];
				isRequired		= temp[1];
				validationType	= temp[2];
				fieldTitle		= temp[3];
				if (temp.length > 4) {
					maxLength 	= temp[4];
					
					// CHECK MAX LENGTH
					if (!isEmpty(eval("formObj." + fieldName + ".value")) && eval("formObj." + fieldName + ".value").length > maxLength) {
						alert_message = alert_message + "   " + fieldTitle + " too long (max length " + maxLength + " chars)\n";
					}
				}
				
				if (fieldName == "evtBlurb") {
					if (!isEmpty(formObj.evtBlurb.value)) {
						if ((formObj.evtBlurb.value.length > 250) || (formObj.evtBlurb.value.length == 0)) {
							alert_message = alert_message + "   Blurb must not be empty and must be less than 250 characters long\n";
						}
					}
				}
				
				else if (fieldName == "jobDescription") {
					if (isRequired == "required" || isEmpty(formObj.jobDescription.value)) {
						if ((formObj.jobDescription.value.length > 500) || (formObj.jobDescription.value.length == 0)) {
							alert_message = alert_message + "   Description must not be empty and must be less than 500 characters long\n";
						}
					}
				}
				
				else if (fieldName == "opMarketing") {
					if (isRequired == "required" || isEmpty(formObj.opMarketing.value)) {
						if ((formObj.opMarketing.value.length > 5000) || (formObj.opMarketing.value.length == 0)) {
							alert_message = alert_message + "   Marketing must not be empty and must be less than 5000 characters long\n";
						}
					}
				}
				
				else if (fieldName == "opInvolvement") {
					if (isRequired == "required" || isEmpty(formObj.opInvolvement.value)) {
						if ((formObj.opInvolvement.value.length > 5000) || (formObj.opInvolvement.value.length == 0)) {
							alert_message = alert_message + "   Involvement in Industry must not be empty and must be less than 5000 characters long\n";
						}
					}
				}
				
				else if (fieldName == "opEnhancing") {
					if (isRequired == "required" || isEmpty(formObj.opEnhancing.value)) {
						if ((formObj.opEnhancing.value.length > 5000) || (formObj.opEnhancing.value.length == 0)) {
							alert_message = alert_message + "   Enhancing Consumer Experience must not be empty and must be less than 5000 characters long\n";
						}
					}
				}
				
				else if (fieldName == "opDevelopment") {
					if (isRequired == "required" || isEmpty(formObj.opDevelopment.value)) {
						if ((formObj.opDevelopment.value.length > 5000) || (formObj.opDevelopment.value.length == 0)) {
							alert_message = alert_message + "   Staff Development and Training must not be empty and must be less than 5000 characters long\n";
						}
					}
				}
				
				else if (fieldName == "spoCategory") {
					if(document.getElementById('spoGoldMajorPrizes').checked == true) {
						if(isEmpty(formObj.spoGoldMajorAmount.value)) {
							alert_message = alert_message + "   Please enter an amount for the Gold Major Prize donation\n";
						}
					}
					if(document.getElementById('spoSilverMajorPrizes').checked == true) {
						if(isEmpty(formObj.spoSilverMajorAmount.value)) {
							alert_message = alert_message + "   Please enter an amount for the Silver Major Prize donation\n";
						}
					}
					if(document.getElementById('spoPlasticCheque').checked == true) {
						if(isEmpty(formObj.spoPlasticChequeAmount.value)) {
							alert_message = alert_message + "   Please enter an amount for the Large Plastic Cheque donation\n";
						}
					}
					if(document.getElementById('spoDecorations').checked == true) {
						if(isEmpty(formObj.spoDecorationsAmount.value)) {
							alert_message = alert_message + "   Please enter an amount for the Decorations donation\n";
						}
					}
					if(document.getElementById('spoPhotographer').checked == true) {
						if(isEmpty(formObj.spoPhotographerAmount.value)) {
							alert_message = alert_message + "   Please enter an amount for the Photographer donation\n";
						}
					}
					if(document.getElementById('spoRafflePrizes').checked == true) {
						if(isEmpty(formObj.spoRafflePrizesAmount.value)) {
							alert_message = alert_message + "   Please enter an amount for the Raffle Prizes donation\n";
						}
					}
					if (isRequired == "required") {
						if (document.getElementsByName(fieldName).length > 0)
						{
							if (eval("!isRadioSelected(formObj." + fieldName + ")")) {
								alert_message = alert_message + "   " + fieldTitle + "\n";
							}
						}
					}	
				}
				
				
				// STREET ADDRESS
				else if (fieldName == "USRSTREETADDRESSONE") {
					
					if (isRequired == "required" 
						|| !isEmpty(formObj.USRSTREETADDRESSONE.value)
						|| !isEmpty(formObj.USRSTREETADDRESSONE.value)
						|| !isEmpty(formObj.USRSTREETCITY.value)
						|| !isEmpty(formObj.USRSTREETSTATITLE.value)
						|| !isEmpty(formObj.USRSTREETPOSTCODE.value)) {
						
							if (isEmpty(formObj.USRSTREETADDRESSONE.value)) {
								alert_message = alert_message + "   Street Address Line 1\n";
							}
							
							if (isEmpty(formObj.USRSTREETCITY.value)) {
								alert_message = alert_message + "   Street Address City / Suburb\n";
							}
							
							if (formObj.USRSTREETCTYREQUIRESTATE.value == "1") {
								if (isEmpty(formObj.USRSTREETSTATITLE.value)) {
									alert_message = alert_message + "   Street Address State\n";
								}
							}
							if (formObj.USRSTREETCTYREQUIREPOSTCODE.value == "1") {
								if (isEmpty(formObj.USRSTREETPOSTCODE.value)) {
									alert_message = alert_message + "   Street Address Postcode\n";
								}
							}
							
							/*if (isEmpty(formObj.USRSTREETCTYTITLE.value)) {
								alert_message = alert_message + "   Street Address Country\n";
							}*/
					}
				
				
				// POSTAL ADDRESS
				} else if (fieldName == "USRPOSTADDRESSONE") {
				
					if (isRequired == "required" 
						|| !isEmpty(formObj.USRPOSTADDRESSONE.value)
						|| !isEmpty(formObj.USRPOSTADDRESSTWO.value)
						|| !isEmpty(formObj.USRPOSTCITY.value)
						|| !isEmpty(formObj.USRPOSTSTATITLE.value)
						|| !isEmpty(formObj.USRPOSTPOSTCODE.value)) {
						
							if (isEmpty(formObj.USRPOSTADDRESSONE.value)) {
								alert_message = alert_message + "   Postal Address Line 1\n";
							}
							
							if (isEmpty(formObj.USRPOSTCITY.value)) {
								alert_message = alert_message + "   Postal Address City / Suburb\n";
							}
							
							if (formObj.USRPOSTCTYREQUIRESTATE.value == "1") {
								if (isEmpty(formObj.USRPOSTSTATITLE.value)) {
									alert_message = alert_message + "   Postal Address State\n";
								}
							}
							if (formObj.USRPOSTCTYREQUIREPOSTCODE.value == "1") {
								if (isEmpty(formObj.USRPOSTPOSTCODE.value)) {
									alert_message = alert_message + "   Postal Address Postcode\n";
								}
							}
							
							/*if (isEmpty(formObj.USRPOSTCTYTITLE.value)) {
								alert_message = alert_message + "   Postal Address Country\n";
							}*/
					}
				
				
				// OTHER ADDRESS
				} else if (fieldName == "ADDRESSONE") {
				
					if (isRequired == "required" 
						|| !isEmpty(formObj.ADDRESSONE.value)
						|| !isEmpty(formObj.ADDRESSTWO.value)
						|| !isEmpty(formObj.SUBTITLE.value)
						|| !isEmpty(formObj.STATITLE.value)
						|| !isEmpty(formObj.SUBPOSTCODE.value)) {
						
							if (isEmpty(formObj.ADDRESSONE.value)) {
								alert_message = alert_message + "   Address Line 1\n";
							}
							
							if (isEmpty(formObj.SUBTITLE.value)) {
								alert_message = alert_message + "   City / Suburb\n";
							}
							
							if (formObj.CTYREQUIRESTATE.value == "1") {
								if (isEmpty(formObj.STATITLE.value)) {
									alert_message = alert_message + "   State\n";
								}
							}
							if (formObj.CTYREQUIREPOSTCODE.value == "1") {
								if (isEmpty(formObj.SUBPOSTCODE.value)) {
									alert_message = alert_message + "   Postcode\n";
								}
							}
							
							if (isEmpty(formObj.CTYTITLE.value)) {
								alert_message = alert_message + "   Country\n";
							}
					}
				
				// Time (hh:mm:ss)
				} else if (validationType == "Time (hh:mm:ss)") {
					if (isRequired == "required" || !isEmpty(eval("formObj." + fieldName + ".value"))) {
						if (eval("!isValidTiming(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						}
					}
				
				
				// Time (hh:mm am/pm)
				} else if (validationType == "Time (hh:mm am/pm)") {
					if (isRequired == "required" || !isEmpty(eval("formObj." + fieldName + ".value"))) {
						if (eval("!isValidTime(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						}
					}
				
				
				// Date
				} else if (validationType == "date") {
					
					thisDate = "";
					if (eval("formObj." + fieldName)) {
						thisDate = eval("formObj." + fieldName + ".value");
					
					} else if (eval("formObj." + fieldName + "Day") && eval("formObj." + fieldName + "Month") && eval("formObj." + fieldName + "Year")) {
						thisDate = eval("formObj." + fieldName + "Day.value") + "/" + eval("formObj." + fieldName + "Month.value") + "/" + eval("formObj." + fieldName + "Year.value");
					}

					if (isRequired == "required" || (!isEmpty(thisDate) && thisDate != "//")) {
						if (!isValidDate(thisDate)) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						}
					}
				
				
				// year
				} else if (validationType == "year") {
					if (isRequired == "required" || !isEmpty(eval("formObj." + fieldName + ".value"))) {
						if (eval("!isValidYear(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						}
					}
				
				
				// select
				} else if (validationType == "select") {
					if (isRequired == "required") {
						if (eval("!isSelected(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						}
					}
					
					
				// Radio
				} else if (validationType == "Radio") {
					if (isRequired == "required") {
						if (document.getElementsByName(fieldName).length > 0)
						{
							if (eval("!isRadioSelected(formObj." + fieldName + ")")) {
								alert_message = alert_message + "   " + fieldTitle + "\n";
							}
						}
					}
					
					
				// Integer
				} else if (validationType == "Integer") {
					if (isRequired == "required" || !isEmpty(eval("formObj." + fieldName + ".value"))) {
						if (eval("!isInteger(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						
						} else {
						
							eval("thisFieldValue = parseInt(formObj." + fieldName + ".value)");
						
							// if have "Total Allowed" on integer field
							if (eval("formObj.totalAllowed_" + fieldName)) {
								eval("thisTotalAllowed = parseInt(formObj.totalAllowed_" + fieldName + ".value)");
							
								// check that not getting more than is available
								if (thisFieldValue > thisTotalAllowed) {
									alert_message = alert_message + "   " + fieldTitle + ": only " + thisTotalAllowed + " allowed\n";
								}
							}
							
							// if have "Allow Zero" on integer field
							if (eval("formObj.allowZero_" + fieldName)) {
								eval("thisAllowZero = formObj.allowZero_" + fieldName + ".value");
							
								// check that field is not zero
								if (thisAllowZero != 1 && thisFieldValue == 0) {
									if (isRequired == "required") {
										alert_message = alert_message + "   " + fieldTitle + ": zero not allowed\n";
									} else {
										alert_message = alert_message + "   " + fieldTitle + ": zero not allowed (leave blank if not wanted)\n";
									}
								}
							}
						}
					}
					
					
				// Decimal
				} else if (validationType == "Decimal") {
					if ((isRequired == "required" || !isEmpty(eval("formObj." + fieldName + ".value"))) && eval("formObj." + fieldName + ".style.display != 'none'")) {
						
						if (eval("!isDecimalNumber(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						} else {
						
							eval("thisFieldValue = parseFloat(formObj." + fieldName + ".value)");
						
							// if have "Allow Zero" on decimal field
							if (eval("formObj.allowZero_" + fieldName)) {
								eval("thisAllowZero = formObj.allowZero_" + fieldName + ".value");
							
								// check that field is not zero
								if (thisAllowZero != 1 && thisFieldValue == 0) {
									if (isRequired == "required") {
										alert_message = alert_message + "   " + fieldTitle + ": zero not allowed\n";
									} else {
										alert_message = alert_message + "   " + fieldTitle + ": zero not allowed (leave blank if not wanted)\n";
									}
								}
							}
							
							// if have "Allow Negative" on decimal field
							if (eval("formObj.allowNegative_" + fieldName)) {
								eval("thisAllowNegative = formObj.allowNegative_" + fieldName + ".value");
							
								// check that field is not zero
								if (thisAllowNegative != 1 && thisFieldValue < 0) {
									alert_message = alert_message + "   " + fieldTitle + ": negative numbers not allowed\n";
								}
							}
							
						}
					}
					
					
				// Email
				} else if (validationType == "Email") {
					if (isRequired == "required" || !isEmpty(eval("formObj." + fieldName + ".value"))) {
						if (eval("!isValidEmail(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						}
					}
					
					
				// URL	
				} else if (validationType == "URL") {
					if (isRequired == "required" || !isEmpty(eval("formObj." + fieldName + ".value"))) {
						if (eval("!isValidURL(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						}
					}
				
				// text
				} else if (validationType == "text") {
					if (isRequired == "required") {
						if (eval("isEmpty(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						}
					}
				
				// image file
				} else if (validationType == "imageFile") {
					if (isRequired == "required" || !isEmpty(eval("formObj." + fieldName + ".value"))) {
						if (eval("!isValidImageType(formObj." + fieldName + ".value)")) {
							alert_message = alert_message + "   " + fieldTitle + "\n";
						}
					}
				}
			}
		}
		
		
		// if merchandise has a quantity limit
		if (formObj.merchandiseFields) {
			if (formObj.merchandiseFields.length) {
				
				// loop through merchandise colours (ie quantity limit by colour)
				for (i=0; i < formObj.merchandiseFields.length; i++) {
					if (formObj.merchandiseFields[i].value != "") {
						
						temp = formObj.merchandiseFields[i].value.split("|");
						fieldName 			= temp[0];
						quantityAvailable	= parseInt(temp[1]);
						fieldTitle			= temp[2];
						
						quantityEntered = 0;
						
						// loop though merchandise sizes belonging to colour - get total number entered
						if (eval("formObj.merchandiseAvailable_" + fieldName + ".length")) {
							for (j=0; eval("j < formObj.merchandiseAvailable_" + fieldName + ".length"); j++) {
								if (eval("formObj.merchandiseAvailable_" + fieldName + "[j].value != ''")) {
									
									eval("sizeFieldName = formObj.merchandiseAvailable_" + fieldName + "[j].value");
									if (eval("isInteger(formObj." + sizeFieldName + ".value)")) {
										eval("quantityEntered = quantityEntered + parseInt(formObj." + sizeFieldName + ".value)");
									}
								}
							}
						}
						
						// check if number entered is more than what is available
						if (quantityEntered > quantityAvailable) {
							alert_message = alert_message + "   " + fieldTitle + " - Only " + quantityAvailable + " available\n";
						}
					}
				}
			}
		}
		
		return alert_message;
	}
	


// Returns "true" if "str" contains only alpha characters [a-z, A-Z] (no whitespace etc.).
	function isAlpha(strValue) {
		return (! strValue.search (/^([a-zA-Z]+)$/));
	}

// isDecimalNumber
	function isDecimalNumber (passedVal) {
		if(passedVal == "") {
			return false;
		}
			
		for (z=0; z<passedVal.length; z++) {
			if (passedVal.charAt(z) == ".") {
			}
			else if (passedVal.charAt(z) == "-" && z == 0) {
			}
			else if (passedVal.charAt(z) < "0") {
				return false;
			}
			else if (passedVal.charAt(z) > "9") {
				return false;
			}
		}
		return true;
	}

	
// isEmpty
	function isEmpty (strValue) {
		return (! strValue.replace (/^(\s*)/, "", strValue));
	}
	
	
// isInteger
	function isInteger (passedVal) {
		if(passedVal == "") {
			return false;
		}
		
		trimmedVal =  passedVal.replace(/\s+/g,''); //remove whitespace
			
		for (z=0; z<trimmedVal.length; z++) {
			if (trimmedVal.charAt(z) < "0") {
				return false;
			}
			else if (trimmedVal.charAt(z) > "9") {
				return false;
			}
		}
		return true;
	}
	
	
// isRadioSelected
	function isRadioSelected (radioObject) {
		eventOption = -1;
		
		
		if (radioObject[0]) {			
			for ( z=0; z < radioObject.length; z++) {
				if (radioObject[z].checked) {
					eventOption = z;
				}
			}
		} 
		else {
			if (radioObject.checked) { eventOption = 1; }
		}
			
		if(eventOption == -1) {
			return false;
		} else {
			return true;
		}
	}
	
	
// isSelected
	function isSelected (strValue) {
		if (strValue == "0" || strValue == "")
			return false;
		else
			return true;
	}
	
	
// getUsrAge
	function getUsrAge(usrDOB, ageCutoffDate) {  
		var usrAge = ""; 
	
		if (isValidDate(usrDOB) && isValidDate(ageCutoffDate)) {
			
			tempArray 	= usrDOB.split("/");
			dobDay		= tempArray[0];
			dobMonth	= tempArray[1] - 1;
			dobYear		= tempArray[2];
			
			var thisDOB	= new Date(dobYear, dobMonth, dobDay);
			
			tempArray 	= ageCutoffDate.split("/");
			dobDay		= tempArray[0];
			dobMonth	= tempArray[1] - 1;
			dobYear		= tempArray[2];
			
			var thisAgeCutoffDate	= new Date(dobYear, dobMonth, dobDay);
			
			usrAge	= thisAgeCutoffDate.getFullYear() - thisDOB.getFullYear();
			
			if (thisDOB.getMonth() > thisAgeCutoffDate.getMonth()) {
				usrAge = usrAge - 1;
			
			} else if ((thisDOB.getMonth() == thisAgeCutoffDate.getMonth()) && (thisDOB.getDate() > thisAgeCutoffDate.getDate())) {
				usrAge = usrAge - 1;
			}
		}
		
		return usrAge;
	}
	
	
	
	
// getRadioCheckboxValue
	function getRadioCheckboxValue (radioObject) {
		thisValue = "";
		
		eventOption = -1;
	
		if (radioObject[0]) {			
			for ( z=0; z < radioObject.length; z++) {
				if (radioObject[z].checked) {
					if (thisValue == "")
						thisValue = radioObject[z].value;
					else
						thisValue = thisValue + "|" + radioObject[z].value;
				}
			}
		} 
		else {
			if (radioObject.checked) { thisValue = radioObject.value }
		}
			
		return thisValue;
	}
	
// Return "true" if "monthnum" and "yearnum" constitute a valid credit card date.
//
// Created (16 Oct 2000) Raymond Woo
// Modified (24 May 2001) Raymond Woo -- optimised code for checking : 2 digits only for month/year each
	function isValidCCDate(monthnum, yearnum) {
		var now = new Date();
		var futureexpiry = (now.getYear() + 10); // within x years
		// Must be 2 digits each
		if ((! /^\d{2}$/.test(monthnum)) || (! /^\d{2}$/.test(yearnum))) return false;
		// Cannot have expired and must be within x years.
		if (monthnum > 12 || monthnum < 1) return false;
		if (yearnum > (futureexpiry%100) || yearnum < (now.getYear()%100)) return false;
		if (yearnum == (now.getYear()%100) && monthnum <= now.getMonth()) return false; 
		return true;
	}
	
	
// Return "true" if "numbertocheck" is a valid credit card number, as defined by the Luhn algorithm.
//
// Created (16 Oct 2000) Raymond Woo
// Modified (24 May 2001) Raymond Woo -- optimised code for checking : 16-19 digits only
// Modified (20 Aug 2001) Raymond Woo -- doh, AMEX is 15 digits. have now dropped the lowerbound to 5, in case of proprietry cards
	function isValidCCNumber(numbertocheck) {
		var weight = 1;
		var checktotal = 0;
		//Characters can only be (5 to 19) digits.
		if (! /^\d{5,19}$/.test(numbertocheck)) return false;
		//LUHN check.
		if (numbertocheck.length % 2 == 0) {weight = 2}  
		else {weight = 1}
		for (i=0; i <= numbertocheck.length-1; i++) 
		{
			digit = numbertocheck.substring(i, i+1);
			val = digit * weight;
			if (val > 9) {val = val - 9}
			checktotal = checktotal + val;
			weight = (weight == 2) ? 1 : 2;
		}
		if (checktotal %10 == 0) {return true}  
		else {return false}
	}
	
	
	// Returns an error message if there is an error with the credit card, returns null otherwise.
	// This requires the isValidCCNumber and isValidCCDate javascript functions.
	// Input:	numbertocheck = the credit card number - digits ONLY, no spaces
	//			monthnum, yearnum = the expiry month and year (2-digit year)
	//			cardtype = one of "VISA", "MAST","BANK", "DINE", "AMEX", "JCB", "PROP"
	// 
	// Created (24 May 2001) Raymond Woo
	
	function validateCCard (numbertocheck, monthnum, yearnum, cardtype) {
		var alert_message = ""; 
		
		if (!isValidCCDate(monthnum, yearnum)) {
			alert_message = alert_message + "   Expiry Date is not valid\n";
		}
		if (!isValidCCNumber(numbertocheck)) {
			alert_message = alert_message + "   Credit Card Number is not valid\n";
			return alert_message;
		}
		
		switch (cardtype) {
			case "VISA" :
				if (! /4\d+/.test(numbertocheck))
					alert_message = alert_message + "   Card number does not appear to be valid for a Visa\n";
				break;
			case "MAST" :
				if (! /5[12345]\d+/.test(numbertocheck))
					alert_message = alert_message + "   Card number does not appear to be valid for a Mastercard\n";
				break;
			case "BANK" :
				if ((! /56022[12345]\d+/.test(numbertocheck)) && (! /56105\d+/.test(numbertocheck)))
					alert_message = alert_message + "   Card number does not appear to be valid for a Bankcard\n";
				break;
			case "DINE" :
				if (! /3[0689]\d+/.test(numbertocheck))
					alert_message = alert_message + "   Card number does not appear to be valid for a Diners Club\n";
				break;
			case "AMEX" :
				if (! /3[47]\d+/.test(numbertocheck))
					alert_message = alert_message + "   Card number does not appear to be valid for an American Express\n";
				break;
			case "JCB" :
				if ((! /1800\d+/.test(numbertocheck)) && (! /2131\d*/.test(numbertocheck)) && (! /35(28|29|[345678])\d+/.test(numbertocheck)))
					alert_message = alert_message + "   Card number does not appear to be valid for a JCB\n";
				break;
			case "PROP" :
				if (! /5[078]\d+/.test(numbertocheck))
					alert_message = alert_message + "   Card number does not appear to be valid for a Proprietry Card\n";
				break;
			default : 
				alert_message = alert_message + "   Card Type is not valid\n";
		}

		return alert_message;
	}
	
	
// Checks the date input for a valid format.
// This code accepts the date formats: DD/MM/YYYY or DD-MM-YYYY
// To alter the format checked for, change the datePat (date pattern) -
//    d{2} requires 2 digits, d{1,2} requires either 1 or 2 digits etc.
//    \/|- requires / or - as a separator etc.
//
// Created (16 Oct 2000) Raymond Woo
	function isValidDate (strValue) {
		var datePat = /^(\d{2})(\/)(\d{2})\2(\d{4})$/; // Change this to check for a different format
		var matchArray = strValue.match(datePat); // is the format ok?
		if (matchArray == null) { return false;	}
		day = matchArray[1]; month = matchArray[3]; year = matchArray[4];
		if (month < 1 || month > 12) { return false; }
		if (day < 1 || day > 31) { return false; }
		if ((month==4 || month==6 || month==9 || month==11) && day==31) { return false; }
		if (month==2) {
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day>29 || (day==29 && !isleap)) { return false; }
		}
		return true;  // date is valid
	}
	
// isValidEmail
	function isValidEmail (emailStr) {
		
		var emailPat=/^(.+)@(.+)$/; 
		var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
		var validChars="\[^\\s" + specialChars + "\]"; 
		var quotedUser="(\"[^\"]*\")";
		var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
		var atom=validChars + '+'; 
		var word="(" + atom + "|" + quotedUser + ")";
		var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
		var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
		
		var matchArray=emailStr.match(emailPat)
		if (matchArray==null) {
			return false;
		}
				
		var user=matchArray[1];
		var domain=matchArray[2];
				
		if (user.match(userPat)==null) {
			return false;
		}
				
		var IPArray=domain.match(ipDomainPat)
		if (IPArray!=null) {
			for (var z=1;z<=4;z++) {
				if (IPArray[z]>255) {
					return false;
				}
			}
			return true;
		}
				
		var domainArray=domain.match(domainPat)
		if (domainArray==null) {
			return false;
		}
		
		var atomPat=new RegExp(atom,"g")
		var domArr=domain.match(atomPat)
		var len=domArr.length
		if (domArr[domArr.length-1].length<2 || 
			domArr[domArr.length-1].length>3) {
			return false;
		}
			
		if (len<2) {
			return false;
		}
		
		return true;
	}
	
	
// isValidImageType
	function isValidImageType (strValue) {
		var imageTypesArray = new Array();
		
		imageTypesArray[0] = "gif";
		imageTypesArray[1] = "jpg";
		imageTypesArray[2] = "jpeg";
		
		
		var stringArray = strValue.split(".");
		fileType = stringArray[stringArray.length - 1];
		
		for (z = 0; z < imageTypesArray.length; z++) {
			if(imageTypesArray[z].toLowerCase() == fileType.toLowerCase()) {
				return true;
			}
		}
		return false;
	}	
	
	
// Returns "true" if the "strValue" is in a valid 12 hour time format, eg. HH:MM or H:MM 
// P or PM or A or AM are optional at the end, and are case insensitive.
//
// Created (16 Oct 2000) Raymond Woo
// Modified (27 Nov 2000) Raymond Woo "AM" matching corrected. Doh.
	function isValidTime ( strValue ) {
		var objRegExp = /^(0{0,1}[1-9]|1[0-2]):[0-5]\d\s*([A]|[P])M*$/i;
		return objRegExp.test( strValue );
	}
	
	
// isValidTiming (h:mm:ss or m:ss)
	function isValidTiming( strValue ) {
		//var objRegExp = /^(0{0,1}[1-9]:|1[0-2]:|)[0-5][0-9]:[0-5][0-9]*$/i;
		var objRegExp = /^(0{0,1}[0-9]:|[0-9][0-9]:|)(0{0,1}[0-5]|)[0-9]:[0-5][0-9]*$/i;
		return objRegExp.test( strValue );
	}
	
	
// isValidURL
	function isValidURL (strValue) {
		
		// CHECK IF HAS VALID URL PREFIX
		var urlPrefixArray = new Array();
		urlPrefixArray[0] = "file";
		urlPrefixArray[1] = "ftp";
		urlPrefixArray[2] = "gopher";
		urlPrefixArray[3] = "http";
		urlPrefixArray[4] = "https";
		urlPrefixArray[5] = "telnet";
		urlPrefixArray[6] = "wais";
		urlPrefixArray[7] = "mailto";
		urlPrefixArray[8] = "news";
		
		
		// check URL is long enough
		if (strValue.length <= 7 ) {
			return false;
		}
		
		
		hasPrefix = false;
		stringAddress = "";
		var stringArray = strValue.split(":");
		stringPrefix = stringArray[0];
		
		
		if (stringArray.length >= 2) stringAddress = stringArray[1];
		
		
		var addressArray = stringAddress.split("//");
		if (addressArray.length >= 2) stringAddress = addressArray[1];
		
		var addressArray = stringAddress.split("/");
		stringAddress = addressArray[0];
		
		var addressArray = stringAddress.split("?");
		stringAddress = addressArray[0];
		
		for (z = 0; z < urlPrefixArray.length; z++) {
			if(urlPrefixArray[z] == stringPrefix) {
				hasPrefix = true;
			}
		}
		
		// IF NO VALID PREFIX - RETURN FALSE
		if (!hasPrefix) return false;
		
		
		// are regular expressions supported?
	    var supported = 0;
	    if (window.RegExp) {
	        var tempStr = "a";
	        var tempReg = new RegExp(tempStr);
	        if (tempReg.test(tempStr)) supported = 1;
	    }
		
		// check if right format
	    if (supported) {
			var r1 = new RegExp(/^[a-z0-9\-]+(\.[a-z0-9\-]+)*(\.[a-z]{2,3})+$/);
			
			return (r1.test(stringAddress));
			
	    } else {
			return true;
		}
	}
	
	
	// isValidYear
	function isValidYear ( strValue ) {
		var objRegExp = /^(\d{4})$/;
		var objRegExp2 = /^(\d{4})-(\d{4})$/;
		
		if (strValue.match( objRegExp )) {
			return true;
		} else if (strValue.match( objRegExp2 )) {
			return true;
		} else {
			return false;
		}
	}
	
	
// Eliminates everything apart from digits (0 through 9) from a string.
//
// Created (16 Oct 2000) Raymond Woo
	function reduceToDigits (strValue) {
		return (strValue.replace (/([^0-9])/g, "", strValue));
	}

	
	
// formCheckComplete	
	function formCheckComplete(formObj) { 	
						
		var alert_message = ""; 
	
		alert_message = alert_message + checkRequiredFields(formObj);

		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" + 
				   alert_message )
			return false;
		} else { 
			return true;
		}
	}
	
// formCheckUpdateRegistration
	function formCheckUpdateRegistration(formObj) {
		var alert_message = ""; 
		var passwordMessage = "";
		if (formObj.email.value != '' && formObj.email.value != formObj.cemail.value) {
			passwordMessage = "Your email fields must match\n";
		} else if (formObj.password.value != '' && formObj.password.value != formObj.cpass.value) {
			passwordMessage = passwordMessage+"Your password fields must match\n";
		}
		
		if (passwordMessage != '') {
			alert(passwordMessage);
			return false;
		}
		
		alert_message = alert_message + checkRequiredFields(formObj);
		
		if (alert_message) { 
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" + 
				   alert_message )
			return false;
		} else { 
			return true;
		}
	}
	
	function getItem(id)
	{
		return document.getElementById&&document.getElementById(id)? document.getElementById(id) : document.all&&document.all[id]? document.all[id] : null;
	}	
	