

$(document).ready(function(){
	if($('input.focused:first,textarea.focused:first').length == 1){
		$('input.focused:first,textarea.focused:first').focus();
	}
	
	 $('form.stdForm').submit(function(){
		if(!stdFormCheck(this)) return false;
		b = $(this).find('button.saveButton').attr('disabled', 'disabled');
		
		if($(b).val()) $(b).html($(b).val());
		
		$(this).find('button.loadIndicator').append('...');
	 });
	
});


function stdFormCheck(f){
	$(f).find('.needed').removeClass('wrong');
	$(f).find('.needed').each(function(){
		if($(this).val().match(/^\s*$/)) $(this).addClass('wrong');
	});	
	
	if($(f).find('.wrong').length){
		$(f).find('.wrong:first').focus();
		return false;
	}
	
	return true;	
	
}
