// JavaScript Document
//<![CDATA[
// ]]>

var myForm = {

    // Utilizzare una variabile per fare riferimento al file SWF incorporato.
    

	start: function(){
		
		if ($('myForm')) myForm.send();
		if ($$('.formInfo')) myForm.initForm();

	},
	
	initForm: function()
	{

		var list = new Array;
		
		var myInput = $$('.formInfo label input');
		var myTextarea = $$('.formInfo label textarea');
		var mySelect = $$('.formInfo label select');
		
		var list = list.concat(myInput, myTextarea, mySelect)
		
		list.each(function(element) {
			
			var fx = new Fx.Styles(element, {duration:300, wait:false});
			
			element.addEvent('focus', function(){
				fx.start({
							'background-color': '#0089C9',
							'color': '#FFFFFF'
				});
				//element.setStyle('background-color', '#e1a721');	
			})

			element.addEvent('blur', function(){
				fx.start({
							'background-color': '#FFFFFF',
							'color': '#000000'
				});
			})			
				
		});
		// loop through all anchor tags
	},
	
	/* Meetodo per Spedire la FORM con Ajax */
	send: function(){

		$('myForm').addEvent('submit', function(e) {
			/**
			 * Prevent the submit event
			**/
			new Event(e).stop();
			/**
			 * This empties the log and shows the spinning indicator
			**/
			var log = $('risposta').empty().addClass('loading');
			log.setStyle('display','block');
			log.setStyle('top', $('myForm').getTop());
			log.setStyle('left', window.getWidth()/2 - (log.getStyle('width').toInt()/2));			
			/**
			 * send takes care of encoding and returns the Ajax instance.
			 * onComplete removes the spinner from the log.
			 */
			this.send({
				update: log,
				onComplete: function() {

					log.setStyle('left', window.getWidth()/2 - (log.getStyle('width').toInt()/2));
					
					log.removeClass('loading');
					log.addEvent('click', function()
						{
							this.setStyle('display','none');
							
							if ($('emailSpedita')) {
								
								$('nome').setProperty('value', '');
								$('azienda').setProperty('value', '');
								$('email').setProperty('value', '');
								$('telefono').setProperty('value', '');
								$('messaggio').setProperty('value', '');
								$('autorizzo').checked = false;
								
							}
							
						}
					);
				}
			});
		});		
	}	// Fine Send()	

}

///////////////////////////////////////////////////////

window.addEvent('load', myForm.start);
//]]>