/* new_user.js
   Simple form checking script
   Tomoya Konishi
*/

function checkForm() {
  $('sendBtn').disabled = true;

  if (!checkEmail()) {
  } else if (!checkPassword()) {
  } else if ($F('title1') == undefined && $F('title2') == undefined && $F('title3') == undefined && $F('title4') == undefined) {
	alert('Please input title');
  } else if ($F('first') == "") {
	alert('Please input First Name.');
  } else if ($F('last') == "") {
	alert('Please input Last Name.');
  } else if ($F('affiliation') == "") {
	alert('Please input Affiliation.');
  } else if ($F('zip') == "") {
	alert('Please input Zip code.');
  } else if ($F('address') == "") {
	alert('Please input Address.');
  } else if ($F('country') == "") {
	alert('Please input Country.');
  } else if ($F('phone') == "") {
	alert('Please input Phone number.');
  } else {
  	$('sendBtn').disabled = false;
	return true;
  }
  $('sendBtn').disabled = false;
  return false;
}

function checkPassword() {
  if ($F('password').length == "") {
	alert("Please input password.");
	return false;
  }
  if ($F('password').length < 6) {
	alert("Password must be at least 6 characters.");
	return false;
  }
  if ($F('password') != $F('password2')) {
	alert("Two passwords do not match.");
	return false;
  }
  return true;
}

function checkEmail() {
  var regex = /.+@.+\..+/;
  if (!$F('email').match(regex)) {
	alert("Please input valid E-mail address.");
	return false;
  }
  return true;
}

