//VALIDATE MEMBERSHIP
function validate_submission(formObj) {
	warning = "";
	
	var sectionArray = new Array()
	sectionArray[0] = "distributor";
	sectionArray[1] = "prodeal";
	sectionArray[2] = "psia";
	sectionArray[3] = "retailer";
	sectionArray[4] = "admin";
	
	for (var i = 1; i <= 5; i++){
		var myPassword = formObj['password' + i].value;
		// checks if password field has value
		if(myPassword != undefined){
			
			// see if password and confirm fields match
			if(myPassword != formObj['confirm' + i].value){
				warning += "\n - Passwords for " + sectionArray[i-1]+ " don't match";
			}
		
			//checks for password length
			
			if (myPassword.length != 0 && myPassword.length < 5) {
    		    warning = "\n - Passwords must be at least 5 characters in length.";
			}
		
			// allow only letters, numbers, and underscores
			var illegalChars = /[\W_]/; 
			if (illegalChars.test(myPassword)){
    		    warning = "\n -  Passwords cannot contain spaces.";
			}	
		}
   	}
	
	//Checks for errors from above and decide whether to submit
	if (warning != "") {
        alert("ERROR:  The form cannot be submitted because\nthe following fields are incomplete or invalid:\n" + warning);
		return false;
	}else{
		return true;	
	}
} 