function checkLoginForm(){
	if (document.getElementById("login_name").value==""){
    alert("You need to enter a username.");
    document.getElementById("login_name").focus();
    return false; 
  }else if (document.getElementById("login_password").value==""){
    alert("You need to enter a password.");
    document.getElementById("login_password").focus();
    return false;
  }
}

function checkForgotForm(){
	if (document.getElementById("fp_username").value==""){
    alert("You need to enter a username.");
    document.getElementById("fp_username").focus();
    return false; 
  }else if (document.getElementById("fp_email").value==""){
    alert("You need to enter an email address.");
    document.getElementById("fp_email").focus();
    return false;
  }else if (echeck(document.getElementById("fp_email").value)==false){
    alert("The email entered is not a valid email address.");
    document.getElementById("fp_email").focus();
    return (false);
  }
}

function checkAnswerForm(){
	if (document.getElementById("fp_answer").value==""){
    alert("You need to enter an answer.");
    document.getElementById("fp_answer").focus();
    return false; 
  }
}

function checkChangePassword(){
	if (document.getElementById("pwd_current").value==""){
    alert("You need to enter your current password.");
    document.getElementById("pwd_current").focus();
    return false; 
  }else if (document.getElementById("pwd_new").value==""){
    alert("You need to enter a new password.");
    document.getElementById("pwd_new").focus();
    return false;
  }else if (document.getElementById("pwd_new").value.length<=5){
    alert("Your new password must be between 6 and 12 characters in length.");
    document.getElementById("pwd_new").focus();
    return (false);
  }else if (document.getElementById("pwd_new2").value==""){
    alert("You need to confirm your new password.");
    document.getElementById("pwd_new2").focus();
    return false;
  }else if (document.getElementById("pwd_new").value!=document.getElementById("pwd_new2").value){
    alert("Your confirmation password does not match your new password.");
    document.getElementById("pwd_new2").focus();
    return false;
  }
}

function submitSearchForm(loc_id){
  document.getElementById("loc_id").value=loc_id;
  document.getElementById("j_search_form").submit();
}

function checkRegDefault(){
  if (document.getElementById("reg_first_name").value==""){
    alert("You must enter a first name.");
    document.getElementById("reg_first_name").focus();
    return (false);
  }else if (document.getElementById("reg_last_name").value==""){
    alert("You must enter a last name.");
    document.getElementById("reg_last_name").focus();
    return (false);
   }else if (document.getElementById("reg_address_1").value==""){
    alert("You must enter the first line of your address.");
    document.getElementById("reg_address_1").focus();
    return (false);
  }else if (document.getElementById("reg_county").value==""){
    alert("You must select a county.");
    document.getElementById("reg_county").focus();
    return (false);
  }else if (document.getElementById("reg_postcode").value==""){
    alert("You must enter your postcode.");
    document.getElementById("reg_postcode").focus();
    return (false);
  }else if (document.getElementById("reg_telephone").value==""){
    alert("You must enter a telephone number.");
    document.getElementById("reg_telephone").focus();
    return (false);
  }else if (document.getElementById("reg_email").value==""){
    alert("You must enter your email address.");
    document.getElementById("reg_email").focus();
    return (false);
  }else if (echeck(document.getElementById("reg_email").value)==false){
    alert("The email entered is not a valid email address.");
    document.getElementById("reg_email").focus();
    return (false);
  }else if (document.getElementById("reg_username").value==""){
    alert("You must choose a username.");
    document.getElementById("reg_username").focus();
    return (false);
    }else if (document.getElementById("reg_username").value.length<=5){
    alert("Your username must be between 6 and 12 characters in length.");
    document.getElementById("reg_username").focus();
    return (false);
  }else if (document.getElementById("reg_password").value==""){
    alert("You must enter a password.");
    document.getElementById("reg_password").focus();
    return (false);
   }else if (document.getElementById("reg_password").value.length<=5){
    alert("Your password must be between 6 and 12 characters in length.");
    document.getElementById("reg_password").focus();
    return (false);
  }else if (document.getElementById("reg_password2").value==""){
    alert("You must retype your password.");
    document.getElementById("reg_password2").focus();
    return (false);
  }else if (document.getElementById("reg_password").value!=document.getElementById("reg_password2").value){
    alert("Your typed passwords do not match.");
    document.getElementById("reg_password2").focus();
    return (false);
  }else if (document.getElementById("reg_security_answer").value==""){
    alert("You must enter an answer to the security question.");
    document.getElementById("reg_security_answer").focus();
    return (false);
  }
}

function checkChangeDetails(){
  if (document.getElementById("reg_first_name").value==""){
    alert("You must enter a first name.");
    document.getElementById("reg_first_name").focus();
    return (false);
  }else if (document.getElementById("reg_last_name").value==""){
    alert("You must enter a last name.");
    document.getElementById("reg_last_name").focus();
    return (false);
   }else if (document.getElementById("reg_address_1").value==""){
    alert("You must enter the first line of your address.");
    document.getElementById("reg_address_1").focus();
    return (false);
  }else if (document.getElementById("reg_county").value==""){
    alert("You must select a county.");
    document.getElementById("reg_county").focus();
    return (false);
  }else if (document.getElementById("reg_postcode").value==""){
    alert("You must enter your postcode.");
    document.getElementById("reg_postcode").focus();
    return (false);
  }else if (document.getElementById("reg_email").value==""){
    alert("You must enter your email address.");
    document.getElementById("reg_email").focus();
    return (false);
  }else if (echeck(document.getElementById("reg_email").value)==false){
    alert("The email entered is not a valid email address.");
    document.getElementById("reg_email").focus();
    return (false);
  }
}


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;
  }else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
    return false;
  }else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
    return false;
  }else if (str.indexOf(at,(lat+1))!=-1){
    return false;
  }else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
    return false;
  }else if (str.indexOf(dot,(lat+2))==-1){
    return false;
  }else if (str.indexOf(" ")!=-1){
    return false;
  }else{
    return true;
  }	
}
