$(document).ready(function(){   

	// last person
	$('.people-thumbs li:last').addClass('last');
	
	// forum
	$('.forum-table tr:even').addClass('even');
	$('.forum a.quote').click(function() {
		$('#message-reponse').val($(this).parents('.post-body').find('.post-content p').text().removeBlankLines());
	});
	$('#forum-modal-ok').dialog({ modal: true, autoOpen: false, close: function(event, ui) {
		$('#postForm').hide('slow', function () {
	        $(this).remove();
	    });
	}});
	$('#forum-modal-error').dialog({ modal: true, autoOpen: false })
	$('#postForm').submit(function() {
		if($('#message-reponse').val().trim().length > 0)
			$.ajax({
			  type: "POST",
			  async: false,
			  url: $(this).attr('action'),
			  data: "message="+$('#message-reponse').val(),
			  success: function(data) {
				$('#forum-modal-ok').dialog('open');
			  },
			  error: function(xhr, text, err) {
				$('#forum-modal-error').dialog('open');
			  }
			});
		else
			$('#forum-modal-error').dialog('open');
		return false;
	});
	
	// pagination
	$('.pager .dot').click(function() {
		return false;
	});
	
	// candidature
	$('#candidature').submit(function() {
		var pass = true;
		$(this).find(".required").css('border','1px solid #4B4B4D');
		$(this).find(".required").each(function(i) {
			if($(this).val() == '') {
				$(this).css('border','1px solid red');
				pass = false;
			}
		});
		return pass;
	});
});

String.prototype.stripHTML = function() { return this.replace(/<(?:.|\s)*?>/g, ""); };
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };
String.prototype.removeBlankLines = function() { return this.replace(/\n\n/g, "\n").replace(/\t\r\n/g, ''); };
