jQuery(document).ready(function() {
    $("#cerca").click(
		function() {  
			if($("#cerca_campo").val().length<3)
				alert('Digitare almeno 2 caratteri per effetuare la ricerca');
			else
				location.replace('/ricerca/'+escape($("#cerca_campo").val())+'.html') ;			
			return false;
		});
	$('#cerca_campo').keyup(function(e) {
		if(e.keyCode == 13) {
			if($("#cerca_campo").val().length<3)
				alert('Digitare almeno 2 caratteri per effetuare la ricerca');
			else
				location.replace('/ricerca/'+escape($("#cerca_campo").val())+'.html') ;				
		}
		return false;
	});
		
	if($('#gallery').length > 0){
		$('#gallery a').lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.6,
			imageLoading: 'http://'+window.location.hostname+'/js/lightbox/images/lightbox-ico-loading.gif',
			imageBtnClose: 'http://'+window.location.hostname+'/js/lightbox/images/lightbox-btn-close.gif',
			imageBtnPrev: 'http://'+window.location.hostname+'/js/lightbox/images/lightbox-btn-prev.gif',
			imageBtnNext: 'http://'+window.location.hostname+'/js/lightbox/images/lightbox-btn-next.gif',
			containerResizeSpeed: 0,
			txtImage: 'Immagine',
			txtOf: 'di'
	   });
	}	

});

var feats = "top=50, left=50, width=540, height=480, status=no, menubar=no, toolbar=no, scrollbars=yes";
function popinfo(infowindow) {
	window.open(infowindow, "", feats);
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) != -1)
	return 1;
	else
	return 0;
	}
	function checkForm(form){
	if ( isEmail(form.email.value) == 0 ) {
	alert("Inserire un indirizzo e-mail valido")
	form.email.focus();
	return false}
}

function inva_email(){
	
	if($('#emailfrom').val() != '' && isEmail($('#emailfrom').val())){
		$.ajax({
		   type: "POST",
		   url: "/invia_email_info.html",
		   data: { emailto: $('#emailto').val(),
		           emailname: $('#emailname').val(),
				   emailfrom: $('#emailfrom').val(),
				   emailcontent: $('#emailcontent').val(),
				   captcha: $('#captcha').val()},
		   dataType: "html",
		   cache: false,
		   success: function(data, textStatus){
		   		alert(data.replace(/\n/g, '<br>'));
		   }	
     });
	} else {
		alert('inserisci una e-mail valida');
	}
		
	
	
	return false;
}

