// newcustomer
function formValidator(){
	// Make quick references to our fields
	var businessname = document.getElementById('businessname');
	var name = document.getElementById('name');
	var address = document.getElementById('address');
	var city = document.getElementById('city');
	var zip = document.getElementById('zip');
	var phone1 = document.getElementById('phone1');
	var email = document.getElementById('email');
	var yearest = document.getElementById('yearest');
	var numberemp = document.getElementById('numberemp');
	var description = document.getElementById('description');
	var verif_box = document.getElementById('verif_box');
	
	// Check each input in the order that it appears in the form!
	if(notEmpty(businessname, "Please type the name of your business")){
		if(notEmpty(name, "Please type your name")){
			if(notEmpty(address, "Please type your address")){
				if(notEmpty(city, "Please type your city")){
					if(notEmpty(zip, "Please type your zip code")){
						if(notEmpty(phone1, "Please type your phone number")){
							if(notEmpty(email, "Please type a valid e-mail address")){
							if(emailValidator(email, "Please type a valid e-mail address")){
								if(notEmpty(yearest, "Please tell us when the business was established")){
									if(notEmpty(numberemp, "How many people does this business employ?")){
										if(notEmpty(description, "Please provide a short description of the business")){
											if(notEmpty(verif_box, "Please type the image verification characters")){
												return true;
											}
										}
									}
								}
							}
							}
						}
					}
				}
			}
		}
	}
	return false;
}

function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus();
		return false;
	}
	return true;
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function lengthRestriction(elem, min, max){
	var uInput = elem.value;
	if(uInput.length >= min && uInput.length <= max){
		return true;
	}else{
		alert("Please enter between " +min+ " and " +max+ " characters");
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){
	var alphaExp = /^[a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isNumeric(elem, helperMsg){
	var numericExpression = /^[0-9]+$/;
	if(elem.value.match(numericExpression)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphanumeric(elem, helperMsg){
	var alphaExp = /^[0-9a-zA-Z]+$/;
	if(elem.value.match(alphaExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function madeSelection(elem, helperMsg){
	if(elem.value == "Please Choose"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function madeSelection2(elem, helperMsg){
	if(elem.value == "0"){
		alert(helperMsg);
		elem.focus();
		return false;
	}else{
		return true;
	}
}

function emailValidator(elem, helperMsg){
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function checkPassword(pw1, pw2, helperMsg) {
      if(pw1.value != pw2.value)
         { 
          alert(helperMsg);
          pw1.focus();
            return false;     
      }
      else{
      return true;
      }
}
