
function giveFeedback(url) {

	var feedback = $('#feedback');
	var lang = $('BODY').hasClass('finnish') ? 'fi' : 'en';

	/* If the URL matches against active navigation item,
	   the default recipient is overwritten.
	   Note: e.g. /wiping matches also with all its subpages. */
	var recipient = 'info' + '@' + 'suominen.fi';
	var custom_recipients = [
		['/wiping', 'nonwovens' + '@' + 'suominen.fi,info' + '@' + 'codi.nl'],
		['/pyyhinta', 'nonwovens' + '@' + 'suominen.fi,info' + '@' + 'codi.nl'],
		['/packaging', 'flexibles' + '@' + 'suominen.fi'],
		['/joustopakkaukset', 'flexibles' + '@' + 'suominen.fi']
	];

	for (var i = 0; i < custom_recipients.length; i++) {
		var href = custom_recipients[i][0];
		var r = custom_recipients[i][1];
		if ($('#sidebar .active A[href=' + href + ']').length > 0) {
			recipient = r;
		}
	}
		
	feedback.load(url || '/feedback', function() {
		feedback.show();
		
		var bar = feedback.find('.bar')
		var status = feedback.find('.status');
		
		feedback.find('form').submit(function() {
			bar.show();
			
			$.post(url || '/feedback', {
				ngform_fid: this.ngform_fid.value,
				ngf_signature: this.ngf_signature.value,
				q0: this.q0.value,
				q1: this.q1.value,
				q2: this.q2.value,
				q3: this.q3.value,
				q4: this.q4.checked ? 1 : 0,
				recipient: recipient
			}, function(response) {
				bar.fadeOut('slow');
				
				if(response.toLowerCase().indexOf('form') == -1) {
					if (lang == 'fi') status.text("Ole hyvä ja täytä kaikki vaaditut kentät.");
					else status.text("Please fill all the required fields and check that the content is correct.");
				}
				else {
					if (lang == 'fi') status.text("Kiitos palautteesta.");
					else status.text("Thank you for your feedback.");
				}
			});
			
			return(false);
		});
		
		feedback.find('.cancel').click(function() {
			feedback.hide().empty();
		});
	});
}