studentShown = 'f';
safe = 'y';

// On an onMouseDown event this function fires to stop a user accidently changing where they want to submit the form to.
// This is due to Firefox and IE focusing radio buttons when they're clicked but Safari doesn't focus radio buttons unless you tab to them.
function trap() {
    safe = 'n';
}

// On an onMouseUp event this function clears the safety as the user has completed the transaction with the button.
function safety(e) {
    safe = 'y';
    fmchange(e);
}

// If a user is using the keyboard to navigate the form the 'safe' flag will still be set, any instance where this is not the case would be alot less likely than a user accidently clicking on an option then deciding they don't want to select it and dragging their mouse off not knowing that the script has already been run.
function fmchange(e) {
    if (safe == 'y') {
        
        // Sets the form action to add the user to the list that is used for sending out newsletters.
        if ( e == 'subscribe') {
            document.getElementById('cfm').action = 'http://www.mooballmailer.com/form.php?form=46';
            
            // Checking if the extra fields for the student option are currently shown and hides them if they are, sets the tracking variable to false.
            if (studentShown == 't') {
                document.getElementById('fm-student-area').style.display = 'none';
                studentShown = 'f';
            }
        
        // Sets the form action to add the user to a list that doesn't receive newsletters.
        } else if (e == 'none') {
            document.getElementById('cfm').action = 'http://www.mooballmailer.com/form.php?form=45';
            
            // Checking if the extra fields for the student option are currently shown and hides them if they are, sets the tracking variable to false.
            if (studentShown == 't') {
                document.getElementById('fm-student-area').style.display = 'none';
                studentShown = 'f';
            }
            
        // Sets the form action to subscribe the user to the prospective students list which also receives newsletters, also shows the extra fields associated with prospective students and sets a variable which tracks whether these fields are shown or not to true.
        } else if (e == 'student') {
            document.getElementById('cfm').action = 'http://www.mooballmailer.com/form.php?form=47';
            document.getElementById('fm-student-area').style.display = 'block';
            studentShown = 't';
        } else if (e == 'leadership') 
        {
            document.getElementById('cfm').action = 'http://www.mooballmailer.com/form.php?form=68';

            document.getElementById('fm-student-area').style.display = 'block';
            studentShown = 't';
        }
    
    }
}

function check_form_action()
{
    var chk_array = ['chk-subscribe', 'chk-student', 'chk-leadership', 'chk-none'];
    var values = ['subscribe', 'student', 'leadership', 'none'];
    var cnt = 0;
    for(cnt = 0; cnt < chk_array.length; ++cnt)
    {
        element = document.getElementById(chk_array[cnt]);
        if(element.checked == true)
        {
            fmchange(values[cnt]);
            return true;
        }
    }
}

