// If the length of the element's string is 0 then display helper message
function isEmpty(elem, helperMsg){
    if(elem.value.length == 0){
        alert(helperMsg);
        elem.focus(); // set the focus to this input
        return true;
    }
    return false;
}

function lengthRestriction(elem, min, max){
    var uInput = elem.value;
    if(uInput.length >= min && uInput.length <= max){
        return true;
    }else{
        alert("Username should be between between " +min+ " and " +max+ " characters.");
        elem.focus();
        return false;
    }
}

function emailValidator(elem, helperMsg){
    var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
    if(elem.value.match(emailExp)){
        return true;
    }else{
        alert(helperMsg);
        elem.focus();
        return false;
    }
}

function SubmitForm() {
      if( ! document.getElementById('tcaccept').checked ) {
          alert( "You must indicate acceptance of Taggzilla's terms of service before registering." );
      } else {
        document.JoinForm.submit();
      }
}

/*
 * Do laborious, irritating javascript form processing.
 */
function SubmitForm2() {
      if( ! document.getElementById('tcaccept').checked ) {
          alert( "You must indicate acceptance of Taggzilla's terms of service before registering." );
      } else {
        document.JoinStage2.submit();
      }
}

// RJH 
// Not really form validation, but I'm putting it here anyway.
function toggle(obj) {
    var el = document.getElementById(obj);
    el.style.display = (el.style.display != 'none' ? 'none' : '' );
}

function toggleVis(obj) {
    if (obj.style.visibility=="hidden"){
        obj.style.visibility="visible";
    } else {
        obj.style.visibility="hidden";
    }
}

// RJH
// Check that password and password verification match
function verifyPass() {
    var frm =  document.forms["JoinStage2"];
    if( frm.password1.value != frm.password2.value ) {
        document.getElementById('explainBlock').value = "Passwords do not match";
    } else {
        document.getElementById('explainBlock').value = "(OK)";
    }
}


