var pollTarget;
var pollName;

// See http://malsup.com/jquery/form/#code-samples
jQuery(function() {
    // bind to the form's submit event
    $('.pollform').submit(function() {
        pollTarget = '#'  + jQuery(this).parent().attr('id');
		pollName = jQuery(this).find("#poll_name").val();  // name of this poll
        var options = {
                target:        pollTarget,   // target element(s) to be updated with server response
                success:       showPollResponse,  // post-submit callback
                dataType:   'html'
        };
        // inside event callbacks 'this' is the DOM element so we first
        // wrap it in a jQuery object and then invoke ajaxSubmit
        $(this).ajaxSubmit(options);

        // !!! Important !!!
        // always return false to prevent standard browser submit and page navigation
        return false;
    });
});

//post-submit callback
function showPollResponse(responseText, statusText)  {
    // for normal html responses, the first argument to the success callback
    // is the XMLHttpRequest object's responseText property

    // if the ajaxSubmit method was passed an Options Object with the dataType
    // property set to 'xml' then the first argument to the success callback
    // is the XMLHttpRequest object's responseXML property

    // if the ajaxSubmit method was passed an Options Object with the dataType
    // property set to 'json' then the first argument to the success callback
    // is the json data object returned by the server
    //jQuery(pollTarget).html(responseText);

    jQuery(pollTarget).load('/ajax/poll/' + pollName + '.html');
    //alert('status: ' + statusText + '\n\nresponseText: \n' + responseText +
    //    '\n\nThe output div should have already been updated with the responseText.');
}
