// Javascript for the signup page
function signupSubmit() {
    $(".error-msg").css ("display", "none");
    $("input[type=text]").removeClass ("invalid");
    var fields = ["name", "email", "store_name", "store_url"];
    for (var i = 0; i < fields.length; i++) {
        var elt = $("#" + fields[i]);
        var value = elt.val();
        if (fields[i] == "email" || fields[i] == "store_url" && value) value = value.toLowerCase();
        if (!value || value.length > 120 || 
            (fields[i] == "email" && !sf.data.TypeInfo.converter ("emailAddress") (value)) ||
            (fields[i] == "store_url" && !value.startsWith ("http://") && !value.startsWith ("https://"))) {
            elt.addClass ("invalid").focus();
            var errorPanel = $("#" + fields[i] + "-error").css ("display", "block");
            return  false;
        }
    }
    return true;
}

$(function () {
    $(".signup-submit").css ("display", "block");
    var dlg = new ModalDialog();
    $(".signup-note a").click (function () {
        dlg.show ($("#tos-modal"));        
    });
    $("#close-modal").click (function () { dlg.hide(); });
    $("#name").focus();
    var theForm = document.signupForm; // This seems to be the only way to refer to the form that works with IE
    theForm.onsubmit = signupSubmit;
    theForm.action = "thankyou.html";
})
