
function post_submit() {
    //$('#buglabel').text = 'Bug report successfully submitted'
}
function pre_submit(formData, jqForm, option) {
	// Validate form elements
	var form = jqForm[0]; 
    if (!form.email.value || !form.bugcomments.value) { 
        alert('Please provide an e-mail address and comments.'); 
        return false; 
    } 
    //$('#buglabel').text('Submitting...');
    //$('#bugreport-dialog').dialog('close');
}

function initDialog(){
	$("#bugreport").dialog({
	autoOpen: false,
    bgiframe: true,
    height: 350,
    width:350,
    modal: true,
    resizable: false,
    title: 'Report a bug',
    buttons: {
        'Submit report': function() {
            $('#bugreport-form').ajaxSubmit()
            $(this).dialog('close');
        },
        Cancel: function() {
            $(this).dialog('close');
            
        }
    }
	});
}

function initBugreport() {
        $('#report-a-bug').unbind('click').bind('click', function() {
            //$("#bugreport-form").show();
            $('#bugreport').dialog('open');
            initBugreport();
        });
}

$(document).ready(function() {
    var options = {
            //target: '#buglabelmsg',   // target element(s) to be updated with server response 
            type: 'post',
            clearForm: true,
            resetForm: true,
            beforeSubmit: pre_submit,
            success: post_submit
        };
    // bind form using 'ajaxForm'
    $('#bugreport-form').ajaxForm(options);
	initDialog();
	initBugreport();
});