$(function() {

	
	$('form input').keypress(function(e) {
		var key = e.charCode ? e.charCode : e.keyCode ? e.keyCode : 0;

		if(key == 13) {
			// Really dumb fix for IE6, disable the back button on 
			// pressing enter and then submit the form.  Without the
			// disabled button it just submits the 'back' button :|
			$(this).find('button.back').attr('disabled', 'disabled');
			$(this).submit();
			return false;
		}
		else
			update_hereby();
		
		return true;
	});
	
	
	do_force = function() {
		if($(this).val() == '-1') {
			$('.row.other').slideDown(500, function() {
				$('.row.other input').focus();
			});
		}
		else {
			$('.row.other input').val('');
			$('.row.other').slideUp(250);
		}
	}

	update_hereby = function() {
		var hereby = $('#applicant_firstname').val() + ' ' + $('#applicant_surname').val();
		$('#hereby').html(hereby.length == 1 ? '_____' : hereby);
	}


	$('#force').change(do_force);
	
	if($('#force').val() == '-1') {
		$('.row.other').show();
		$('.row.other input').focus();
	}
	
	$('#applicant_firstname, #applicant_surname').keyup(update_hereby);
	update_hereby();

});