var banner = {
	init: function(){
		if (document.getElementById('close_banner')){
			var myCookie = Cookie.read('no_banner');
			var the_banner = $('banner');
			
			if(myCookie == 'true' || myCookie == true)
			{
				the_banner.setStyles({
					display: 'none'
				});
			}
			else
			{
				the_banner.set('morph', {
					duration: 500,
					transition: 'expo:Out',
					onComplete: function(){
						the_banner.setStyles({
							display: 'none'
						});
					}
				});
			}
			
			$('close_banner').addEvent('click', function(){
				var myCookie  = Cookie.write('no_banner', true, {duration: 1});
				the_banner.morph({
					opacity: [1, 0]
				});			
			});
			
		};
	}
}

var participants = {
	submit_participants: null,
	select_participants: null,
	value : null,
	init: function(){
		if (document.getElementById('box_participants')){
			
			participants.select_participants = $('select_participants');
			participants.submit_participants = $('submit_participants');
			
			participants.select_participants.addEvent('change', function(){
				participants.disableInputs();
			});
			
			participants.submit_participants.addEvent('click', function(){
				return participants.verify();
			});
		};
	},
	disableInputs: function(){
		participants.value = participants.select_participants.value;
		
		for(var i=0; i<=3; i++){
			if(i>0 && i<=participants.value)
			{
				$('name_' + i).disabled = null;
				$('surname_' + i).disabled = null;
			}
			else if(i>0 && i>participants.value)
			{
				$('name_' + i).value = "";
				$('surname_' + i).value = "";
				
				$('name_' + i).setProperty('disabled', 'true');
				$('surname_' + i).setProperty('disabled', 'true');
			}
		}
	},
	verify: function(){
		var errors = false;
		for(var i=1; i<=participants.value; i++){
			if($('name_' + i).value == "" || $('surname_' + i).value == ""){
				errors = true;
			};
		};
		
		if(errors)
		{
			alert('compilare tutti i campi');
			return false;
		}
		else
		{
			return true;
		}
	}
}

window.addEvent('domready', function(){
	//banner.init();
	participants.init();
});
