/**
* Keeps track of the number of submits performed by forms
* on the page.
*/
var num_submits = 0;

/**
 * Reset the number of submits so the user can re-submit if they
 * go back in their browser history.
 *
 */
window.onbeforeunload = function() {
    num_submits = 0;
};

function toggle(element_name) {
    link_id = element_name + '_link';
    target_id = element_name + '_target';
    if(document.getElementById(target_id).style.display == 'block') {
        hide(link_id, target_id);
    }
    else {
        show(link_id, target_id);
    }
}

function process_form_submission(form) {
    return is_first_submit();
}

function submit_address_form() {
    document.getElementById("address_form").submit()
}

/**
 * Increments the number of form submissions then returns
 * true if the last submission was the first, false otherwisse.
 *
 * @return a boolean value
 *
 */
function is_first_submit() {
    num_submits++;
    return num_submits == 1;
}

function connect(link) {
  window.location.href = link
  return true;
}
