function ajaxFormSubmit(form, response_container_id)
{	
	$(form).ajaxSubmit({
		beforeSubmit: function(form_data, form_object, options)
		{
			var height = $('#' + response_container_id).height();

			$('#' + response_container_id).html('Please wait...');
			$('#' + response_container_id).height(height);
			return true; 
		},
	
		error: function(XMLHttpRequest, textStatus, errorThrown){ 
			alert('There was an error submitting the information: ' + textStatus);
		},
		
		success: function(response){			
			$('#' + response_container_id).html(response); 
		}
	});
}

function ajaxRequest(url, response_container_id, data, interim_html)
{
	var height = $('#' + response_container_id).height();

	if(interim_html == undefined) interim_html = 'Please wait...';
	
	$('#' + response_container_id).html(interim_html);
	$('#' + response_container_id).css('minHeight', $('#' + response_container_id).height());

	$.post(url, data, function(response) {
		$('#' + response_container_id).html(response); 
	});
}

function update_background()
{
	max_proportional_size($('#background'), $(window).width(), $('#main_page_table').height(), 1.502);	
	$('#background_container').css('top', ($('#main_page_table').height() - $('#background').height()) / 2);
}

function main_scale()
{
	size($('#main_panel_content'), undefined, $(window).height() - $('#footer').height(), undefined, 600);
	
	$('#bottom_vignette').css('top', $('#footer').offset().top - 75);
	
	update_background();

	if($(window).width() < parseInt($('#main_page_table').css('min-width')))
	{
		$('#main_page_table').width(parseInt($('#main_page_table').css('min-width')));
		$('#footer_table').width(parseInt($('#main_page_table').css('min-width')));		
	}
	else if($(window).width() > parseInt($('#main_page_table').css('max-width')))
	{
		$('#main_page_table').width(parseInt($('#main_page_table').css('max-width')));
		$('#footer_table').width(parseInt($('#main_page_table').css('max-width')));		
	}
	else
	{
		$('#main_page_table').width($(window).width());
		$('#footer_table').width($(window).width());		
	}
}

function max_proportional_size(element, max_width, max_height, aspect_ratio)
{
	var width = max_width;
	var height = max_width / aspect_ratio;

	if(height > max_height)
	{
		height = max_height;
		width = max_height * aspect_ratio;
	}
	
	element.width(width);
	element.height(height);
}

function size(element, width, height, min_width, min_height, max_width, max_height)
{
	if(width != undefined)
	{
		if(min_width != undefined && width < min_width)
		{
			width = min_width;
		}
		else if(max_width != undefined && width > max_width)
		{
			width = max_width;
		}

		element.width(width);
	}

	if(height != undefined)
	{
		if(min_height != undefined && height < min_height)
		{
			height = min_height;
		}
		else if(max_height != undefined && height > max_height)
		{
			height = max_height;
		}

		element.height(height);
	}	
}

function stop_default(event) 
{
	if(event && event.preventDefault)
	{
		event.preventDefault();
	}
	else if(window.event && window.event.returnValue)
	{
		window.eventReturnValue = false;
	}
}

