function validaricerca(){
		if($('key_cerca').value.length >= 3) return true;
		else{
			alert("La parola cercata &egrave; troppo corta");
			return false;
		}
}

function ricercaclick(v){
	if($('cercaautocompleta').style.display != 'none') return;	
	ricercabox(v);
}

function ricercabox(v){
	if(v.length >= 3){		
		var url = "/web/ricerca_ajax.php?key="+v;
		new Ajax.Request(url, {
		  method: 'get',
		  onSuccess: function(transport) {
			$('cercaautocompleta').innerHTML = transport.responseText;
			$('cercaautocompleta').show();
		  }
		});

	}else{
		$('cercaautocompleta').hide();
	}
}


document.onclick=check;
function check(e){
	var target = (e && e.target) || (event && event.srcElement);
	var obj = document.getElementById('cercaautocompleta');
	checkParent(target)?obj.style.display='none':null;
}
function checkParent(t){
	while(t.parentNode){
		if(t==document.getElementById('cercaautocompleta') || t==document.getElementById('key_cerca') ){
			return false
		}
			t=t.parentNode
		}
	return true
} 
function nl_iscriviti(){
		if($('nl_accetto').checked == true){
			var email = $('email_nl_box').value;
			if(email != ""){
				var url = '/web/action_varie.php?act=NL_REGISTRA&email='+email;
				new Ajax.Request(url, {
				  method: 'get',
				  onSuccess: function(transport){
						$('newsletter_box').innerHTML = transport.responseText;
				  }
				});
			}else{
				alert("Inserisci una email valida per registrarti.");	
			}
		}else{
			if(confirm("Se hai preso visione delle condizioni della Newsletter\nclicca su ok per continuare.")){
					$('nl_accetto').checked = true;
					nl_iscriviti();					
			}
		}
}

function callajax(div,url){
	 new Ajax.Request(url, {
					  method: 'post',
					  onSuccess: function(resp) {
							$(div).innerHTML = resp.responseText;
					  }
				});
}

function cambia_url_query(pagina,cosa,cosavalore,qstring){
	var newqstring=qstring.split('&');
	var url = "";
	var dato_val = ""
	for(i=0;i<newqstring.length;i++){
		dato_val=newqstring[i].split('=');
		if(dato_val[0]==cosa) continue;
		if(cosa == "idmarca" && dato_val[0] == 'pagina') continue;
		url += newqstring[i];
		url += '&';
	}
	url += cosa+'='+cosavalore;
	//alert(url);
	url = pagina+'?'+url;
	window.location = url;
}
function test(){ alert("OK");}

function banner_homepage(start,tot){
	var partida = start;
	var totale = tot;
	new Effect.toggle('bannerhomepage'+partida,'appear',{duration:0.5});
	prossimo = start+1;
	if(prossimo >= totale){ 
		prossimo = 1;
	}
	setTimeout('banner_homepage('+prossimo+','+tot+')',4000);
}

function add_preventivo_convariante(url){
	var radio = document.schedaprodottoform.idvariante;
	var variante;
	for(i=0;i<radio.length;i++){
			if(radio[i].checked == true) variante = radio[i].value;
	}
	//alert(variante);
	var vaia = url+"&idvariante="+variante;
	window.location = vaia;
	//alert(url);	
}

