$(function(){
	// Stuff for the front end employee add form
	// Start by adding the "add more" button
	$('.reimbursements.add_employee div.submit').append('<span class="add"> or <input type="button" class="add_employee" value="Add another employee"></span>')
	$('.reimbursements.add_employee input.add_employee').click(function(){
		var counter = $('.reimbursements.add_employee form fieldset.employee').size();
		// clone the fieldset
		var clone = $($('.reimbursements.add_employee form fieldset.employee')[0]).clone()
		// update the name and values of the cloned elements
		clone.find('input, textarea, select').each(function(){
			this.name = this.name.replace('[0]', '['+counter+']');
			this.value = '';
		});
		// and finally, stick 'em back in the DOM
		$('div.more').append(clone);
		// one more thing; if we've reached the limit of adds, get rid of the add button
		if (counter+1 >= $('#ReimbursementMaxAdd').attr('value')) {
			$('input.add_employee').attr('disabled', 'disabled');
		}
	});
});
