$(document).ready(function() {
	$('.answer').click(function() {
		if($(this).val() == 'n') {
			$(this).parent().parent().parent().find('.read').addClass('read-disabled');
			$(this).parent().parent().parent().find('.read').find('input').attr('disabled',true);
		} else {
			$(this).parent().parent().parent().find('.read').removeClass('read-disabled');
			$(this).parent().parent().parent().find('.read').find('input').attr('disabled',false);
		}
	});
	
	$('#editcontact').click(function() {
		$('#contact').hide();
		$('#contactform').show();
		$('#contactform input:eq(0)').focus();
		$(this).parent().hide();
		return false;
	});
	
	$('#savecontact').click(function() {
		// Gather data
		data = { 
					firstname : $('#recipient_firstname').val(),
					lastname : $('#recipient_lastname').val(),
					address : $('#recipient_address').val(),
					postalcode : $('#recipient_postalcode').val(),
					city : $('#recipient_city').val(),
					phone : $('#recipient_phone').val(),
					gsm : $('#recipient_gsm').val(),
					email : $('#recipient_email').val(),
					n : $('#n').val()
				}

		$.post('/seuranta/paivita/',data,function(result) {
			if(result == 'OK') {
				$('#contactform').hide();
				$('#savenotification').fadeIn();
			} else {
				alert('Yhteystietojen tallennuksessa tapahtui virhe, yritä uudelleen');
			}
		});
		
		return false;
	});
});
