// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

function validate_places_needed(){
	places_needed = 0;
	
	if(!isNaN($('registration_places').value))
		places_needed += parseInt($('registration_places').value);
		
	if(!isNaN($('registration_tables').value))
		places_needed += parseInt($('registration_tables').value);
		
	if(places_needed > 0)
	{
		current_attendees = $$('.attendee').length
		if(current_attendees > places_needed)
		{	
			too_many = current_attendees - places_needed;
			start_at = (current_attendees - too_many);
			
			for(i=start_at; i <= current_attendees; i++){
				$$('.attendee').last().remove();
			}
			
		}
		else if(current_attendees < places_needed)
		{
			missing = places_needed - current_attendees;
			new Ajax.Request('/inscriptions/add_attendees?missing='+missing, {asynchronous:true, evalScripts:true, method:'post', parameters:Form.serializeElements([$$("input[name=authenticity_token]").first()])}); return false;
		}
	}
	else
	{
		alert("Vous devez entrer un nombre de places et/ou un nombre de tables");
	}
}


/******************************************************************************
 ADDON POUR SCAL
******************************************************************************/

function announcement_scroll(direction){
	
	var index_to_show = 0
	
	if(direction > 0){
		index_to_show = announcement_counter + direction + 1;
		index_to_hide = announcement_counter
	}else{
		index_to_show = announcement_counter + direction
		index_to_hide = announcement_counter + 1
	}
	
	if(index_to_show >= 0 && index_to_show <= $$(".announcement").length-1){
		$('announcement_'+index_to_hide).hide();
		$('announcement_'+index_to_show).show();
		
		announcement_counter += direction;
	}
}