// JavaScript Document
function echeck(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 checkNewTopic() {

  var problem;
  problem = 'No';

  if (!document.getElementById("tTitle").value.length) {
    alert ('You must provide a title.');
    problem = 'Yes';
    return false;
  }

  if (!document.getElementById("tText").value.length) {
    alert ('You must actually type something.');
    problem = 'Yes';
    return false;
  }

  if (problem == 'Yes') {
    problem = 'No';
  	return false;
  } else {
    problem = 'No';
  	return true;
  }

}

function checkProfile() {

  var problem;
  problem = 'No';

  if (!document.getElementById("tNameFirst").value.length) {
    alert ('You must provide your first name.');
    problem = 'Yes';
  }
  
  if (!document.getElementById("tNameLast").value.length) {
    alert ('You must provide your last name.');
    problem = 'Yes';
  }

  if (problem == 'Yes') {
    problem = 'No';
  	return false;
  } else {
    problem = 'No';
  	return true;
  }

}

function checkEmail () {

  var problem;
  problem = 'No';

  if (echeck(document.accountEmail.tEmail.value)==false){
    document.accountEmail.tEmail.focus();
    alert ('There was an error with your email address.');
    problem = 'Yes';
  }

  if (!document.getElementById("tUsername").value.length) {
    alert ('Your username can not be blank.');
    problem = 'Yes';
  }  

  if (problem == 'Yes') {
    problem = 'No';
  	return false;
  } else {
    problem = 'No';
  	return true;
  }

}

function checkPwd() {

  var problem;
  problem = 'No';


  if (!document.getElementById("tPassword").value.length) {
    alert ('Your password can not be blank.');
    problem = 'Yes';
  }
  
  if (document.accountInfo.tPassword.value != document.accountInfo.tPassword2.value) {
    document.accountInfo.tPassword.focus();
    alert ('Your passwords are not the same. Please try again.'); 
    problem = 'Yes'; 
  }

  if (problem == 'No') {
    problem = 'No';
  	return true;
  } else {
    problem = 'No';
  	return false;
  }

}