function checkID (id) {	
	if (id.value!="") {
		var pattern = /[^0-9A-Za-z]/
		if (id.value.match(pattern)){
			alert("User ID must contain only letters and numbers.");
			id.focus();
			id.select();
			return false;
		}
		else if (id.value.length <3) {
			alert("User ID must be at least 3 characters long.");
			id.focus();
			id.select();
			return false;
		}
		else {
			return true;
		}
	}
	else {
		return true;
	}
}

function checkPassword (pword) {	
	if (pword.value !="") {
		var pattern = /[^a-zA-Z0-9]/
		if (pword.value.match(pattern)) {
			alert("Password must contain only letters and numbers.");
			pword.focus();
			pword.select();
			return false;
		}
		else if (pword.value.length < 6) {
			alert("Password must be at least 6 characters long.");
			pword.focus();
			pword.select();
			return false;
		}
		else {
			return true;
		}
	}
	else {
		return true;
	}
}

function myphoneCheck (phoneStr) {
  if (phoneStr.value!="") {
    if (!(phoneCheck(phoneStr.value))) {	
		alert("Please fill in a valid phone number using the format ###-###-####.");
		phoneStr.focus();
		phoneStr.select();
		return false;
	}
	else {
		return true;
	} 
  }
  else {
  	return true;
  }	 
}

function checkZip(Zipstr) {
	if (Zipstr.value!="") {
		var pattern = /[0-9]{5}/;

			// See if number is valid 
		if ((Zipstr.value.match(pattern)==null) || (Zipstr.value=="00000")) {
			alert("Please fill in a valid zip code using the format #####.");
			Zipstr.focus();
			Zipstr.select();
			return false;
		}
		else {
			return true;
		}
	}
	else {
		return true;
	}
}

function myemailCheck (emailStr) {
  if (emailStr.value!="") {
	if (!(emailCheck(emailStr.value))) {	
		alert("Please fill in a valid email address.\nExample: person@somewhere.com");
		emailStr.focus();
		emailStr.select();
		return false;
	}
	else {
		return true;
	}
  }
  else {
	return true;
  }	 
}

function confirmPassword (pword1, pword2) {
	if (pword1.value=="" || pword2.value=="") {
		alert("Please fill in a password.");
		if (pword1.value=="") {
			pword1.focus();
			pword1.select();
		}
		else {
			pword2.focus();
			pword2.select();
		}
		return false;
	}
	else if (pword1.value != pword2.value) {
		alert("Password entered incorrectly.  Please try again.");
		pword1.focus();
		pword1.select();
		return false;
	}
	else {
		return true;
	}
}

function mydateCheck (dateStr, today) {
  if (dateStr.value !="") {
    if (!(compareDates(dateStr.value, today))) {
		alert("Please fill in a valid date using the format mm/dd/yyyy.\nYou may not enter a future date.");
		dateStr.focus();
		dateStr.select();
		return false;
	}
	
	if (!(dateCheck(dateStr.value, today))) {	
		alert("Please fill in a valid date using the format mm/dd/yyyy.");
		dateStr.focus();
		dateStr.select();
		return false;
	}
	else {
		return true;
	}
  }
  else {
  	return true;
  }	 
}

function checkDates(a, b) {
	if (a.value!="" && b.value=="") {
		alert("Please fill in a start and an end date.");
		b.focus();
		return false;
	}
	
	if (a.value=="" && b.value!="") {
		alert("Please fill in a start and an end date.");
		a.focus();
		return false;
	}
	
	if (a.value!="" && b.value!="") {
		if (!(compareDates(a.value, b.value))) {
			alert("You must enter sequential dates.");
			b.focus();
			return false;
		}
	}
}

function checkDesc(desc) {
	var pattern = /^\s{1,300}$/;
	if (desc.value!="") {
		if (desc.value.length>300) {
			alert("Please limit your description to 300 characters.");
			desc.focus();
			return false;
		}
		else if (desc.value.match(pattern)) {
			alert("Please fill in a description of your injury.");
			desc.focus();
			desc.select();
			return false;
		}
		else {
			return true;
		}
	}
	else {
		return true;
	}
}

function checkSpaces(string) {
	var pattern = /^\s{1,300}$/;
	if (string.value!="") {
		if (string.value.match(pattern)) {
			alert("Please fill in this textbox with the required information.");
			string.focus();
			string.select();
			return false;
		}
		else {
			return true;
		}
	}
	else {
		return true;
	}
}

function validateZIP(field) {
	if (field.value !="") {
		var valid = "0123456789-";
		var hyphencount = 0;
		var msg = "The zip code you entered is invalid.  Please correct the following error(s):\n"
		var error
		var errorTemp = false;
		var errorHyphen = false;
		
		if (field.value.length!=5 && field.value.length!=10) {
			msg = msg + "\tEnter a 5 digit or 5 digit+4 zip code.\n";
			error = true;
		}
		//alert(field.value.length);
		for (var i=0; i < field.value.length; i++) {
			temp = "" + field.value.substring(i, i+1);
			//alert(temp);
			if (temp == "-") hyphencount++;
			if (valid.indexOf(temp) == "-1") {
				errorTemp = true;
			}
			
			if ((hyphencount > 1) || ((field.value.length==10) && ""+field.value.charAt(5)!="-")) {
				errorHyphen = true;
			}
		}
			
			if (errorTemp==true) {
				msg = msg + "\tInvalid characters in your zip code.\n";
				error = true;
			}
			
			if (errorHyphen==true) {
				msg = msg + "\tThe hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.\n";
				error = true;
			}
			
			if (error) {
				msg = msg + "Please try again."
				alert(msg)
				field.focus();
				field.select();
				return false;
			}
			else {
				return true;
			}
	}
	else {
		return true;
	}
}
