// JavaScript Document

function emcheck(str) {
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
       return false
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
      alert("Your email address is invalid.")
       return false
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
      alert("Your email address is invalid.")
        return false
    }
    if (str.indexOf(at,(lat+1))!=-1){
      alert("Your email address is invalid.")
      return false
    }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
      alert("Your email address is invalid.")
      return false
    }
    if (str.indexOf(dot,(lat+2))==-1){
      alert("Your email address is invalid.")
      return false
    }
    if (str.indexOf(" ")!=-1){
      alert("Your email address is invalid.")
      return false
    }        
}

function checkSignupForm () {

  var problem;
  problem = 'No';

  if (!document.getElementById("fName").value.length) {
    alert ('You must provide your first name.');
    problem = 'Yes';
  }  

  if (!document.getElementById("lName").value.length) {
    alert ('You must provide your last name.');
    problem = 'Yes';
  } 

  if (emcheck(document.signupForm.email.value)==false){
    document.signupForm.email.focus();
    alert ('There was an error with your email address.');
    problem = 'Yes';
  }

  if (!document.getElementById("uName").value.length) {
    alert ('You must create a username.');
    problem = 'Yes';
  } 

  if (document.getElementById("school").value == 0) {
    alert ('You must select a school.');
    problem = 'Yes';
  } 

  if (!document.getElementById("terms").checked) {
    alert ('Please agree to the Terms and Conditions.');
    problem = 'Yes';
  } 

  if (problem == 'Yes') {
    problem = 'No';
  	return false;
  } else {
    problem = 'No';
  	return true;
  }

}

function checkSignupConfirm () {

  var problem;
  problem = 'No';

  if (!document.getElementById("tPassword").value.length) {
    alert ('Your password can not be blank.');
    problem = 'Yes';
  }
  
  if (document.signupConfirm.tPassword.value != document.signupConfirm.tPassword2.value) {
    document.signupConfirm.focus();
    alert ('Your passwords are not the same. Please try again.'); 
    problem = 'Yes'; 
  }
  
  if (problem == 'Yes') {
    problem = 'No';
  	return false;
  } else {
    problem = 'No';
  	return true;
  }

}
