window.addEvent('domready', function() {

    // Get all of the ajax forms.
    
    var forms = $$("form.ajax");
    
    forms.addEvent('submit', function(e) {
    
        //Prevents the default submit event from loading a new page.
        e.stop();
		
        //Empty the log and show the spinning indicator.
        var log = $(this.id + '_contents');
        
        //Set the options of the form's Request handler. 
        this.set('send', {onComplete: function(response) { 
            log.set('html', response);
        }});
        //Send the form.
        this.send();
    });

	
});

function ajaxSubmitForm(formName, value) {

    var form = $(formName);
    
    //Empty the log and show the spinning indicator.
    var log = $(form.id + '_contents');

    // Store the value.
    var valueField = $(form.id + '_value');
	
	if (valueField)
	{
		valueField.value = value;
	}
    
    //Set the options of the form's Request handler. 
    form.set('send', {onComplete: function(response) { 
        log.set('html', response);
    }});
    
    //Send the form.
    form.send();

}

function submitForm(formName, value)
{

    var form = $(formName);
    var valueField = $(form.id + '_value');

	var loader = form.getElement(".loading_overlay").setStyle("display", "block");
	
	if (valueField)
	{
		valueField.value = value;
	}
    
	form.submit();
	
	
}