
/*BOF FORM CONTATTI*/

//restituisco true in caso di errore
function validateFormElement(elem)
{
	if(elem.value=="")
	{
		errorOnFormElement(elem);
		return true;
	}
	else 
	{	
		Element.setStyle(elem,{'background':'#ffffff'});
		return false;
	}
}


function validateHiddenElement(element)
{
	if(validateFormElement(element))
	{
		errorOnFormElement('fieldset_dettagli_richiesta');
		errorOnFormElement('fieldset_dettagli_preventivo');
		return true;
	}
	else return false;



}

function validateCheckBoxElement(elem)
{
	if(elem.checked)
	{
		return false;
	}
	else
	{
		errorOnFormElement(elem.parentNode);	
		return true;
	}
}

function validateFormEmail(elem)
{
	var emailRegexp = RegExp('^[A-Za-z0-9._-]+[@]([A-Za-z0-9-]+[.])+([A-za-z]{2,4})$', 'i');
	
	if (emailRegexp.test(elem.value))
	{
		return false;
	}
	else
	{
		errorOnFormElement(elem);
		return true;
	}
}


function errorOnFormElement(elem)
{	
	Effect.Shake(elem);
	new Effect.Highlight(elem);
	Element.setStyle(elem,{'background':'#f8ed75'});	
}



function submitFormBike()
{
	var form = $('guestbooksign');
	
//inizio validazione
	var error_found = 0;
			
	if(validateFormElement(form.frm_nome)) error_found++;
	if(validateFormEmail(form.frm_email)) error_found++;
	if(validateFormElement(form.frm_misura_a)) error_found++;
	if(validateFormElement(form.frm_misura_b)) error_found++;
	if(validateCheckBoxElement(form.frm_privacy)) error_found++;
	
	//controllo almeno 1 checkbox
	var cheboxed = 0;
	if (form.frm_tipologia_a.checked) cheboxed++;
	if (form.frm_tipologia_b.checked) cheboxed++;	
	if (form.frm_tipologia_c.checked) cheboxed++;	
	if (form.frm_tipologia_d.checked) cheboxed++;
	if (form.frm_tipologia_e.checked) cheboxed++;	
	
	if(cheboxed == 0) 
	{
		error_found++;
		errorOnFormElement($('label_cheboxed'));
	}
	else Element.setStyle($('label_cheboxed'),{'background':''});

	//if(validateCheckBoxElement(form.frm_privacy_a)) error_found++;		
	
//fine validazione	

	if(error_found==0)
	{
		
		Effect.BlindUp('form_bike_all_fields');

		form.request({
		
		  onComplete: function()
		  { 	
			Effect.BlindDown('form_bike_thanks');
			Form.reset('guestbooksign');

			  return false; 
		   }

		});

/*
	document.forms['guestbooksign'].submit();		
*/	
	}	

	return false;
}


/*EOF FORM CONTATTI*/


//switcho le immagini
function attachSwitch()
{	
	var images = document.getElementsByTagName('img');
	
	//percorro tutte le immagini		
	for (var i=0; i<images.length; i++)
	{
		var image = images[i];
		var relAttribute = String(image.getAttribute('name'));
		//se hanno match over... associo funzioni di swap img
		if (relAttribute.toLowerCase().match('over'))
		{
			image.onmouseover = function(){
			if(this.className!="active")
				{
					this.src= this.src.replace('_off', '_on');
				}
			};
			image.onmouseout = function(){
			if(this.className!="active")
				{
					this.src= this.src.replace('_on', '_off');
				}
			};			
		}
		if(image.className == "active")
		{
			image.src= image.src.replace('_off', '_on');
		}
	}
}


function preloadIMG()
{	
	var images = document.getElementsByTagName('img');
	var immagini=new Array();	
	var cont = 0;
	//percorro tutte le immagini		
	for (var i=0; i<images.length; i++)
	{
		var image = images[i];
		var relAttribute = String(image.getAttribute('name'));
		//se hanno match over... associo funzioni di swap img
		if (relAttribute.toLowerCase().match('preload'))
		{
			immagini[cont]=new Image();
			immagini[cont].src=image.src;
		}

	}
}

function marginFloat()
{
	var images = $$('#contenuto img');
	var images_float_left = new Array();
	var images_float_right = new Array();
	for(var i=0;i<images.length;i++)
	{
		if (images[i].getStyle('float').match('left') || (images[i].readAttribute('align') != null && images[i].readAttribute('align').match('left')))
		{
			var img = images[i];
			img.style.marginRight = '10px';
		}
		else if (images[i].getStyle('float').match('right') || (images[i].readAttribute('align') != null && images[i].readAttribute('align').match('right')))
		{
			var img = images[i];
			img.style.marginLeft = '10px';
		}
	}
}

function attachF()
{
	marginFloat();
	preloadIMG();
	attachSwitch();

}		