	function resetform(){
		var controls = getElementsByClass("form-field-error");
		for (var i = 0; i < controls.length; i++){
			controls[i].className = "form-field";
		}

		controls = getElementsByClass("form-label-error");
		for (var i = 0; i < controls.length; i++){
			controls[i].className = "form-label";
		}
		
		controls = getElementsByClass("form-label-required");
		for (var i = 0; i < controls.length; i++){
			controls[i].src = "/images/join/required.gif";
		}

		controls = getElementsByClass("error-message");
		for (var i = 0; i < controls.length; i++){
			controls[i].style.display = 'none';
		}	
	}
	

	function validate(formName){
	
		//to clear the form for new validation check
		resetform();

		var isValid = true;

		// get all the textboxes, and dropdown boxes
		var objForm = document.getElementById(formName);
		var controls = getElementsByTagNames('input,select,textarea', objForm);
		var groupChecked = '';

		for (var i = 0; i < controls.length; i++){
			// set required on form eg. <textarea required="true"
			
			if (controls[i].id != "" && controls[i].getAttribute('required') == "true"){
				
					var group = controls[i].getAttribute('group');
					var rule = controls[i].getAttribute('rule');
					var maxlength = controls[i].getAttribute('maxlength');					
					var value = controls[i].value;
					var id = controls[i].id;
					var compare = controls[i].getAttribute('compare');
					
					var valid = false;
					var re = null;
					var re2= null;
					
					var confirmValid = true;
			
					
					if (controls[i].type == "radio"){

						var radiobuttonarray = document.getElementsByName(controls[i].name);

						var checkselected = false;
						if (radiobuttonarray){
							for (var n = 0; n <  radiobuttonarray.length; n++){
								if (radiobuttonarray[n].checked){
									checkselected = true;
								}
							}
						}

						if (checkselected){
							valid = true;
						}	
						
					
					}	
					
					if (controls[i].type == "checkbox"){
						// <input type="checkbox" name="choice"   choice required
						//one checkbox required to validate
						
						var checkboxarray = document.getElementsByName(controls[i].name);
						
						var checkboxselected = false;
						
						var j = 0;
						if (checkboxarray){
							for (j = 0; j < checkboxarray.length; j++){
								
								if (checkboxarray[j].checked){
									checkboxselected = true;

								}
							}
						}
						
						
						if (checkboxselected){

							valid = true;
						}						
					
					}
					
					if (group){
						//    for use with multiple groups need...
						//     if 'group' attribute is a substring of 'groupChecked' ignore.
						
						// get all elements with 'group' atttribute that has the same value by looping through all controls and checking group value.
						//if equal group value,  place within an array.
						var groupattributearray = document.getElementsByName(controls[i].group);
						var groupselected = false;
					
						// loop through at array. Check to see if one of them has been selected / filled in / etc,.;
						var j = 0;
						if (groupattributearray){
							for (j = 0; j < groupattributearray.length; j++){
								
								if (groupattributearray[j].checked){
									groupselected = true;
								}
							}
						}
												
						
						// if none has been selected, return false and activate group error.
						//if something has been selected, return true so that it does not activate  **GROUP ERRORS**

						if (groupselected){
							valid = true;
						}
						
						//      add 'group' value to 'groupChecked'
						//     groupChecked = groupChecked + ',' + group;

					}
					
											
										
					// want to trim spaces for textbox and textarea entry
					if (controls[i].type == "text" || controls[i].type == "textarea"){
			           	value = value.replace( /^\s+/g, "" );// strip leading
           				value = value.replace( /\s+$/g, "" );// strip trailing
					}

									
					// figure which regular expression to use
					// set rule on form eg. <textarea rule="notempty"
					if (rule){
						switch(rule){
							case "notempty": 		// Something must be entered
								re = new RegExp(/.+/);
								valid = re.test(value);
								break;
							case "notemptytxt": 		// Something must be entered can not be empty
								re = new RegExp(/.+/);
								re2 = new RegExp(/^[a-z ]*$/i);
								valid = ( re.test(value) && re2.test(value) );
								break;
							case "notemptynum" :			// Only numbers (allow decimal) can not be empty
								re = new RegExp(/^[\d\.]*$/);
								re2 = new RegExp(/^[\d\.]*$/);
								valid = ( re.test(value) && re2.test(value) );
								break;
							case "txt" : 			// Text only allowed and can be empty
								re = new RegExp(/^[a-z ]*$/i);
								valid = re.test(value);
								break;
							case "num" :			// Only numbers (allow decimal) and can be empty
								re = new RegExp(/^[\d\.]*$/);
								valid = re.test(value);
								break;
							case "int" :			// Integers only
								re = new RegExp(/^\d*$/);
								valid = re.test(value);
								break;		
							case "email" :			// Something valid-ish for an email
								re = new RegExp(/^[a-z\d\.\-_]+@[a-z\d\.\-_]{2,}\.[a-z]{2,10}$/i);
								valid = re.test(value);
								break;
							case "alphanum" :		// Alpha-numeric characters
								re = new RegExp(/^[\w ]*$/i);
								valid = re.test(value);
								break;
							case "curr" :			// Allows currency values eg. 202.23
								re = new RegExp(/^\d*,?\.?\d{0,2}$/i);
								valid = re.test(value);
								break;
							case "greaterthan" :
								re = new RegExp(/.+/);
								if(re.test(value) && re.test(compare)){
									valid = (value-0) > (compare-0);
								}
								break;
							case "lessthan" :
								re = new RegExp(/.+/);
								if(re.test(value) && re.test(compare)){
									valid = (value-0) < (compare-0);
								}				
								break;
							case "greaterequalthan" :
								re = new RegExp(/.+/);								
								valid = false;
								if(re.test(value) && re.test(compare)){
									valid = ((value-0) >= (compare-0));
								}					
								break;
							case "lessequalthan" :
								re = new RegExp(/.+/);
								if(re.test(value) && re.test(compare)){
									valid = ((value-0) <= (compare-0));
								}							
								break;
							case "zero" :
								re = new RegExp(/.+/);
								if(re.test(value)){
									valid = ((value-0) == 0);
								}							
								break;
							case "notnegative" :
								re = new RegExp(/.+/);
								if(re.test(value)){
									valid = ((value-0) >= 0);
								}							
								break;
							case "notnegativenotzero" :
								re = new RegExp(/.+/);
								if(re.test(value)){
									valid = ((value-0) > 0);
								}								
								break;
								
							
							default :
								// nothing here yet

						}											
					}
					
					if (maxlength && controls[i].type != "checkbox" && controls[i].type != "radio") {
						var length = parseInt(maxlength);

						if (value && value.length <= length){
							valid = true;
						} else {
							valid = false;
						}
					}
															
					// passwords have confirmaton textboxes as default
					// so we need to check for confirmation
					if (valid && controls[i].id.indexOf("-confirm") > -1){
						var confirmId = controls[i].id.replace("-confirm", "");
						var confirmText = document.getElementById(confirmId);
						if (confirmText &&
						    confirmText.value == controls[i].value){
							valid = true;
						} else {
							valid = false;
							group = confirmId;
							confirmValid = false;
						}
					}

					if (!valid){


						// if it's part of a group activate the group errors and everything in it.

						// **GROUP ERRORS**
						//first half of 'if' not used yet
						if (group){

							/*  Not Used Yet
							var groupElement = document.getElementById("group-" +group);

							if (groupElement){
							var groupControls = getElementsByTagNames('input,select', groupElement);
									for (var j = 0; j < groupControls.length; j++){
										groupControls[j].className = "form-field-error";
																				
										// try and see if there are individual labels
										
										showErrorLabels(groupControls[j].id);
									}									
							}
							*/
							
							// show the confirm error if there are any													
							
							if (!confirmValid){
								
								var inputConfirm = document.getElementById(group + '-confirm');
								if (inputConfirm){
									inputConfirm.className = "form-field-error";
								}
								showErrorSet(group + '-confirm');	
														
							} else {
								// show the group error if there are any
								showErrorLabels(group);
								showErrorSet(group);							
							}
							
						
						} else {

							// if it's not part of a group just activate the group and the associated errors
							controls[i].className = "form-field-error";
							showErrorSet(controls[i].id);																	
						}
						
						if (!valid){	
							isValid = false;
						}						
					}
					
									
			}
		}

		if (isValid){

			return true;
			
		} else {			

			return false;
			
		}
		
	}
	
	function showErrorLabels(id){
		var errorLabel = document.getElementById( 'form-label-' + id);
		if (errorLabel) errorLabel.className = 'form-label-error';
		var errorRequired = document.getElementById( 'form-label-required-' + id);
		if (errorRequired) errorRequired.src = '/images/join/error-required.gif';
	}
	
	function showErrorSet(id){
		var errorMessage = document.getElementById( 'error-message-' + id);
		if (errorMessage) errorMessage.style.display = 'block';
		var errorDescription = document.getElementById( 'error-description-' + id);
		if (errorDescription) errorDescription.style.display = 'block';
		var errorLabel = document.getElementById( 'form-label-' + id);
		if (errorLabel) errorLabel.className = 'form-label-error';
		var errorRequired = document.getElementById( 'form-label-required-' + id);
		if (errorRequired) errorRequired.src = '/images/join/error-required.gif';
	}