/*
 * contact.js
 * js de la section formations (inscription à)
 * simon - egzakt.com
 * 2009-03-04
 */


// Afficher un participant
function addAttendee(num,hide_remove) {
	var attendee_id = 'attendee_'+num;
	$('#attendeedefault').clone().appendTo('#attendees');
	$('#attendees').children('.attendee:last').attr('id',attendee_id);
	
	$('#'+attendee_id+' .num').html(num);
	
	// Changement des id
	$('#'+attendee_id+' #first_name').attr('id','first_name_'+num).attr('name','first_name_'+num);
	$('#'+attendee_id+' #last_name').attr('id','last_name_'+num).attr('name','last_name_'+num);
	$('#'+attendee_id+' #code').attr('id','code_'+num).attr('name','code_'+num);
	
	$('#'+attendee_id).show();
	$('#attendees').show();
	
	$('.btn_add').hide();
	$('#'+attendee_id+' .btn_add').show().click(function () { addAttendee(++attendee_num); return true; });
	
	$('#'+attendee_id+' .btn_remove').click(function () { removeAttendee(attendee_id); return true; })
	
	if (num == 1) {
		$('#'+attendee_id+' .btn_remove').hide();
	} else if (num > 1) {
		// Cacher seulement le premier.
		$('.btn_remove').each(function() {
			if ($(this).parent().parent().attr('id') != 'attendee_1')
				$(this).show();
		});
	}

}

function removeAttendee(attendee_id) {
		
	if ($('#attendees').children('.attendee').length > 1) {
		$('#'+attendee_id).remove();
		$('#attendees .attendee:last .btn_add').show();
	}
}

function fillAttendee(num,first_name,last_name,code) {
	var attendee_id = 'attendee_'+num;
	$('#'+attendee_id+' #first_name_'+num).val(first_name);
	$('#'+attendee_id+' #last_name_'+num).val(last_name);
	$('#'+attendee_id+' #code_'+num).val(code);
}

var attendee_num = 0;

function document_ready_training() {
	addAttendee(++attendee_num,true);
	$('#finscription').submit(function() {
		return sendform('submitinscription');
	})
}
