﻿
// Provides 'Agree to terms and conditions' logic to the submit 
// button of the RegisterJobSeeker page (same code as RegisterEmployer.js!)
$(function() {
    var $button = null;
    var $agreeContainer = null;
    var checkbox = null;

    var setButtonState = function() {
        // Set the disbaled attribute of the button with reference to the checkbox
        $button.attr("disabled", ($checkbox.attr("checked")) ? "" : "disabled");
    };


    // Create additional HTML amnd add it immediately after the submit button - note selection
    // by the css class of the standard forms submit button.
    $button = $("input.agreeTerms");                        // The existing submit button
    $agreeContainer = $("<div class='agree'></div>");       // Create a new <div> to hold our additional controls
    $button.after($agreeContainer);                         // Add the <div> container AFTER the submit button

    // Add the checkbox
    $checkbox = $("<input type='checkbox' checked='checked' name='chkAgreeTerms' />")
    .appendTo($agreeContainer)
    .click(function() {             // Bind to the onclick event and...
        setButtonState();           // set the button state accordingly
    });
    
    // Add the commentary
    $("<span>I agree to the terms and conditions of this web site</span>").appendTo($agreeContainer);
    
    // Set the initial state of the button
    setButtonState();
});
