window.addEvent('domready', function() {
	$('myForm').addEvent('submit', function(e) {

		//Prevents the default submit event from loading a new page.
		e.stop();

		//Empty the log and show the spinning indicator.
		var log = $('log_res').empty().addClass('ajax-loading');

		//Set the options of the form's Request handler. 
		//("this" refers to the $('myForm') element).
		this.set('send', {onComplete: function(response) { 
			log.removeClass('ajax-loading');
			log.set('html', response);

			if (response == 'registration_ok') {
				log = $('log_res').empty().addClass('ajax-loading');
				myForm.reset();
				setTimeout("location.href = 'http://www.ecorikit.it/club/grazie';", 1);
			}
			else if (response == 'request_ok') {
				log = $('log_res').empty().addClass('ajax-loading');
				myForm.reset();
				setTimeout("location.href = 'http://www.ecorikit.it/grazie';", 1);
			}
			else if (response == 'survey_ok') {
				log = $('log_res').empty().addClass('ajax-loading');
				myForm.reset();
				setTimeout("location.href = 'http://www.ecorikit.it/club/conferma-valutazione';", 1);
			}
			else if (response == 'upload_ok') {
				log = $('log_res').empty().addClass('ajax-loading');
				myForm.reset();
				setTimeout("location.href = 'http://www.ecorikit.it/club/conferma-upload';", 1);
			};
		}});

		//Send the form.
		this.send();
	});
});

function showAnswer()
{
	var divstyle = new String();

	divstyle = document.getElementById("q_03").style.display;

	document.getElementById("q_03").style.display = "table-row";
}

function hideAnswer()
{
	var divstyle = new String();

	divstyle = document.getElementById("q_03").style.display;

	document.getElementById("q_03").style.display = "none";
}

/**
 * FancyUpload Showcase
 *
 * @license		MIT License
 * @author		Harald Kirschner <mail [at] digitarald [dot] de>
 * @copyright	Authors
 */

window.addEvent('domready', function() {

	/**
	 * Uploader instance
	 */
	var up = new FancyUpload3.Attach('file-list', '#attach-1, #attach-2', {
		path: '/js/uploader.swf',
		url: '/js/script.php',
		fileSizeMax: 5 * 1024 * 1024,
		fileListMax: 5,
		typeFilter: { 'Images (*.jpg, *.jpeg)': '*.jpg; *.jpeg' },
		
		verbose: true,
		
		onSelectFail: function(files) {
			files.each(function(file) {
				new Element('li', {
					'class': 'file-invalid',
					events: {
						click: function() {
							this.destroy();
						}
					}
				}).adopt(
					new Element('span', {html: file.validationErrorMessage || file.validationError})
				).inject(this.list, 'bottom');
			}, this);
			document.getElementById("button").style.display = "inline";
		},
		
		onFileSuccess: function(file) {
			new Element('input', {type: 'hidden', name: 'file[]', value: file.name}).inject(file.ui.element, 'top');
			file.ui.element.highlight('#e6efc2');
			document.getElementById("button").style.display = "inline";
		},

		onSelectSuccess: function(file) {
			document.getElementById("button").style.display = "none";
		},

		onFileError: function(file) {
			file.ui.cancel.set('html', 'Retry').removeEvents().addEvent('click', function() {
				file.requeue();
				return false;
			});
			
			new Element('span', {
				html: file.errorMessage,
				'class': 'file-error'
			}).inject(file.ui.cancel, 'after');
		},
		
		onFileRequeue: function(file) {
			file.ui.element.getElement('.file-error').destroy();
			
			file.ui.cancel.set('html', 'Cancel').removeEvents().addEvent('click', function() {
				file.remove();
				return false;
			});
			
			this.start();
		}
		
	});

});

