function checkFreeMapsForm() {
    var requiredFields = ['payerFirstName','payerLastName','payerStreet1','payerCityName','payerStateOrProvince','payerPostalCode','payerCountry','payer'];
    var alertMessage = '';
    
    for (var i=0; i<requiredFields.length; i++) {
        if ($('#' + requiredFields[i]).val() == '') {
            alertMessage = alertMessage + '<li>' + $('#' + requiredFields[i]).attr('title') + '</li>';            
        }
    }
    
    if (alertMessage != '') {
        alertMessage = '<h1>Oops!</h1><p>You must fill out the following fields before you can continue\:<ul>' + alertMessage + '</ul></p>';
        //console.log(alertMessage);
        displayFormErrorDialog(alertMessage);
        return false;
    } else {
        return true;
    }
}

function displaySharePopup() {
    $('#sharePopup').dialog({
        autoOpen: false,
        bgiframe: true,
        draggable: true,
        resizable: false,
        modal: false,
        width: 675
    });
    
    $('#sharePopup').dialog('open');
}

function displayFormErrorDialog(msg) {
    if ($('#formErrorDialog').length == 0) {
        $('<div id="formErrorDialog" style="text-align\:left; display\:none;"></div>').appendTo('body');
        
        $('#formErrorDialog').dialog({
            title: 'Error with your form submission',
            autoOpen: false,
            bgiframe: true,
            draggable: false,
            resizable: false,
            width: 450,
            buttons: { 
                'Ok': function() {
                    $(this).dialog('close');
                }
            }
        });
    }
    
    $('#formErrorDialog').html(msg);
    $('#formErrorDialog').dialog('open'); 
}

function submitShareForm() {
    var alertMessage = '';
    
    if ($('#fullName').val() == '') {
        alertMessage += 'You must enter a name.<br/>';
    }
    if ($('#story').val() == '') {
        alertMessage += 'You must enter a story.<br/>';
    }
    
    if (alertMessage != '') {
        $('#sharePopupError').css('color', 'red').css('font-weight', 'bold').html(alertMessage).show();
    } else {
        $.post('/nationalparks/includes/share-story-code.cfm', $('#shareForm').serialize());
        $('#sharePopup').html('<h4>Thank you!</h4><p>Your story will be added to our collection of Yosemite memories.</p><div></div>').dialog('option', 'buttons', { "Close": function() { $(this).dialog("close"); } });
    }
}