﻿function IsValidForm() {
    if (!IsValidField(jQuery('#RegForm .Name'), "Name")) {
        return false;
    }
    else if (!IsValidField(jQuery('#RegForm .Password'), "Password")) {
       return false;
    }
    else if (!IsValidField(jQuery('#RegForm .EmailAddress'), "Email")) {
        return false;
    }
    else if (!IsValidField(jQuery('#RegForm .Locality'), "Location")) {
        return false;
    }
    else {
        var checkbox = jQuery('#RegForm .HasAgreedToTerms input:checkbox');
        var domCheckbox = checkbox[0];
        if (!domCheckbox.checked) {
            alert("You must agree to the terms and conditions to register.");
            return false;
        }
    }
}

function IsValidField(frmElem, fieldName) {
    if (frmElem.val() == "") {
        alert(fieldName + " is a required field.");
        frmElem.css({ 'background-color': '#eef5a2' });
        frmElem.focus();
        return false;
    }
    else {
        return true;
    }
}

function OnblurHandler(fieldName) {
    jQuery('#RegForm .' + fieldName).css({ 'background-color': '#ffffff' });
}

