
// isEmpty
	function isEmpty (strValue) {
		return (! strValue.replace (/^(\s*)/, "", strValue));
	}

// 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 i=1;i<=4;i++) {
				if (IPArray[i]>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>4) {
			return false;
		}
	
		if (len<2) {
			return false;
		}

		return true;
	}

	function isValidCurrency(strValue)  {
		var objRegExp = /(^\${0,1}\d{1,3}(,{0,1}\d{3})*(\.\d{2})*$)|(^\(\${0,1}\d{1,3}(,{0,1}\d{3})*(\.\d{2}\))*$)/;
		return objRegExp.test( strValue );
	}

// isValidDate
	function isValidDate (strValue) {
		var datePat = /^(\d{2})(\/|-)(\d{2})\2(\d{4})$/;
		var matchArray = strValue.match(datePat); 
		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;
	}

// reduceToDigits
	function reduceToDigits (strValue) {
		return (strValue.replace (/([^0-9])/g, "", strValue));
	}
	 


//check contact form
	function checkContactFormComplete(formObj) {  

		var alert_message = "";

		if (isEmpty(formObj.usrName.value)) {
			alert_message = alert_message + "   Your Name\n";
		}

		if (!isValidEmail(formObj.usrEmail.value)) {
			alert_message = alert_message + "   Valid Email Address\n";
		}
		
		if (alert_message) {
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else {
			return true;
		}
	}
	 

// Checks that a form is completed before allowing it to be submitted.
	function checkComplete(formObj) {  

		var alert_message = ""; // string to hold error messages

		//----------------------------------------------------------------
		// Check Textfield is not empty - requres javascript function isEmpty
		if (isEmpty(formObj.myTextField.value)) {
			alert_message = alert_message + "   Some Text\n";
		}

		// Check Valid Email - requires javascript function isValidEmail
		if (!isValidEmail(formObj.myEmailField.value)) {
			alert_message = alert_message + "   Valid Email Address\n";
		}
		
		// Check for a Numeric value
		if (isNaN(parseFloat(formObj.myNumberField.value))) {
			alert_message = alert_message + "   Valid Number\n";
		}
		
		// Radio Buttons - must select one
		if (!formObj.myRadioButton[0].checked &&
			!formObj.myRadioButton[1].checked) {
			alert_message = alert_message + "   At Least One Radio Button\n";
		}
		
		// Check Boxes - must select certain number eg. 1
		var boxesChecked = 0;
		var mustCheckBoxes = 1;
		for (i = 0; i < formObj.myCheckBox.length; i++) {
			if (formObj.myCheckBox[i].checked == true) {
				boxesChecked = boxesChecked + 1;
			}
		}
		if (boxesChecked != mustCheckBoxes) {
			alert_message = alert_message + "   X Number of Check Boxes\n";
		}
		
		// Selection drop-down list - select something except the first value [0] "select an option please:"
		if (formObj.myDropDown.selectedIndex == 0) {
			alert_message = alert_message + "   Select an option\n";
		}

		//----------------------------------------------------------------
		// Pop up alert message and don't submit form if error occured
		if (alert_message) { // if there was error, alert_message will not be empty
			alert ("Your form is incomplete.\n" +
				   "You must supply the following information:\n" +
					alert_message);
			return false;
		} else { // no alert_message, so proceed
			return true;
		}
	}