// Basic form checking routines
function JCheckLogin() {
  if (document.frmlogin.user.value=="") { alert("Please enter your username to login"); return; }
  if (document.frmlogin.password.value=="") { alert("Please enter your password to login"); return; }
  document.frmlogin.submit();
}
function JCheckRegister() {
  if (document.frmregister.name.value=="") { alert("Please enter your Name"); return; }
  if (document.frmregister.age.value=="") { alert("Please enter your Age"); return; }
  if (document.frmregister.email.value=="") { alert("Please enter your Email"); return; }
  if (document.frmregister.state.value=="") { alert("Please select the state you live in"); return; }
  if (document.frmregister.username.value=="") { alert("Please enter a Username"); return; }
  if (document.frmregister.password.value=="") { alert("Please enter a Password"); return; }

  if (document.frmregister.username.value.length<8) { alert("Your username has to be a minimum of 8 characters long"); return; }
  if (document.frmregister.password.value.length<8) { alert("Your password has to be a minimum of 8 characters long"); return; }
  if (!echeck(document.frmregister.email.value)) { alert("Please enter a correctly formatted email address"); return; }
  if ((parseInt(document.frmregister.age.value)<1) || (parseInt(document.frmregister.age.value)>125)) { alert("Please enter a numeric age"); return; }
  document.frmregister.submit();
}
function JCheckLPW() {
  if (document.frmlpw.email.value=="") { alert("Please enter the email address you registered with"); return; }
  if (!echeck(document.frmlpw.email.value)) { alert("Please enter a correctly formatted email address"); return; }
  document.frmlpw.submit();
}
function JCheckContact() {
  if (document.frmcontact.email.value=="") { alert("Please enter your email address to send replies to"); return; }
  if (document.frmcontact.qorc.value=="") { alert("Please enter a question or comment to send to us."); return; }
  if (document.frmcontact.name.value=="") { alert("Please enter your name"); return; }
  if (!echeck(document.frmcontact.email.value)) { alert("Please enter a correctly formatted email address"); return; }
  document.frmcontact.submit();
}
function JCheckReport() {
  if (document.frmreport.issue.value=="") { alert("In order to properly report an image, you must provide us a reason why you feel this image should be reviewed."); return; }
  document.frmreport.submit();
}

function JCheckAccount() {
  var Sname, Semail;
  Sname=document.frmaccount.name.value;
  Semail=document.frmaccount.email.value;
  if (Sname=="") { alert("You must have a name linked to your account"); return; }
  if (document.frmaccount.age.value=="") { alert("You must have an age linked to your account"); return; }
  if (Semail=="") { alert("You must have an email address linked to your account"); return; }
  if (document.frmaccount.password.value=="") { alert("You cannot have a blank password"); return; }

  if (document.frmaccount.password.value.length<8) { alert("Your new password has to be a minimum of 8 characters long"); return; }
  if (!echeck(document.frmaccount.email.value)) { alert("Please enter a correctly formatted email address"); return; }
  if ((parseInt(document.frmaccount.age.value)<1) || (parseInt(document.frmaccount.age.value)>125)) { alert("Please enter a numeric age"); return; }

  document.frmaccount.submit();
}

function JCheckGuide() {
  if (document.frmupload.mypic.value=="") { alert("Please select an image to upload to ikidsfishing.com"); return; }
  if (document.frmupload.agree.checked==false) { alert("After reading our guidelines, please check the box to confirm you have read and understood them."); return; }
  timer(); // call progress timer in other .js file
  document.frmupload.submit();
}

function JCheckUpload() {
  if (document.frmupload.name.value=="") { alert("Please enter a name for the people in the picture"); return; }
  if (document.frmupload.fishtype.value=="none") { alert("Please select the type of fish captured from the dropdown menu."); return; }
  document.frmupload.submit();
}

// template for checking
function JCheck() {
  if (document.frm.v.value=="") { alert(""); return; }
  document.frm.submit();
}

// DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
// Modified for spacing, alerts removed, semicolons added
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) { return false; }
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) { return false; }
  if (str.indexOf(at,(lat+1))!=-1) { return false; }
  if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) { return false; }
  if (str.indexOf(dot,(lat+2))==-1) { return false; }
  if (str.indexOf(" ")!=-1) { return false; }
  return true;
}