﻿var UBQO; if (!UBQO) { UBQO = {}; }
if (!UBQO.Website) { UBQO.Website = {}; };
if (!UBQO.Website.Form) { UBQO.Website.Form = {}; };

UBQO.Website.Form.Clear = function(form) {
    $(':input', form)
     .not(':button, :submit, :reset, :hidden')
     .val('')
     .removeAttr('checked')
     .removeAttr('selected');
};

UBQO.Website.Form.Hide = function(form) {
    $(form).hide();
    $(form + 'Result').show();    
};

UBQO.Website.Form.Show = function(form) {
    $(form + 'Result').hide();
    $(form).show();
};

UBQO.Website.Form.Submit = function(form) {
    // Note conventions:
    // Submit button for form must have id of {FormName} + 'Submit'. e.g. RegisterFormSubmit
    // <div> that holds the resulting Html of the submit must have id of {FormName} + 'Result'. e.g. RegisterFormResult

    // Build the submit function and go!
    if ($(form).attr("method").toUpperCase() == "POST") {
        $(form + 'Submit').attr("disabled", 'disabled');
        $(form + 'Processing').show();
        UBQO.Website.Form.HttpPost(form, $(form).attr("action"), form + "Result");
    }
    return false;
};

UBQO.Website.Form.HttpPost = function(form, url, div) {
    $.ajax({
        type: "POST",
        url: url,
        data: $(form).serialize(),
        success: function(result) {
            $(form + 'Result').html(result);            
            $(form + 'Processing').hide();
            $(form + 'Submit').removeAttr("disabled");
        }
    });
    return false;
};
