function check_boxes(form, field, state) {
    for (i=0; i<form.length; i++){
		 if (form.elements[i].name == field)
		     form.elements[i].checked = state;
    }
}

function popupCartina(url){
  window.open(url,"popupcartina","location=no,width=600,height=400");
}

function popupfoto(imgURL){
  window.open(imgURL,"popupfoto","location=no,width=600,height=450");
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit)
	field.value = field.value.substring(0, maxlimit);
else
	 countfield.value = maxlimit - field.value.length;
}

function centerThumb(img, width, height){
	if (img.width)
			imgwidth = img.width;
	else
			imgwidth=width;
	if (img.height)
			imgheight=img.height;
	else
			imgheight=height;
	moveleft = Math.round((width - imgwidth) / 2);
	if (moveleft>0)
			img.style.marginLeft= moveleft + "px";
	movetop = Math.round((height - imgheight) / 2);
	if (movetop>0)
			img.style.marginTop= movetop + "px";
}

function toggleVisible(tagId){
	visibilityStatus = document.getElementById(tagId).style.display;
	if (visibilityStatus=='none')
		document.getElementById(tagId).style.display='block';
	else
		document.getElementById(tagId).style.display='none';
}

function switchText(node, tagId, showText, hideText){
	visibilityStatus = document.getElementById(tagId).style.display;
	if (visibilityStatus=='none')
		node.innerHTML = showText;
	else
		node.innerHTML = hideText;
	
}

function addToFavorites(url, title) {
	var sURL = window.location;
	var sText = title;

	try
	{	if (window.sidebar)
			window.sidebar.addPanel(sText, sURL, "");
		else if (window.external)
			window.external.AddFavorite(sURL, sText);
		else if (window.opera && window.print)
		{	var oA = document.createElement('a');
			oA.setAttribute('rel','sidebar');
			oA.setAttribute('href', sURL);
			oA.setAttribute('title', sText);
			oA.click();
		}
	}
	catch (e)
	{	
	}
}

function setAsHome(url){
	if (window.external){ //IE
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	}
		else alert("Spiacenti, il tuo browser non supporta questa funzione");
}

function clickCounter(counterID){
	counterImg = new Image;
	counterImg.src='/img2/blank.gif?counter=' + counterID + '&amp;ts=' + (new Date()).getTime();
}

function validateFormContatti(formObj){
	formObj.nome.value=formObj.nome.value.replace(/obbligatorio/, '');
	formObj.nome.value=formObj.nome.value.replace(/^\s+|\s+$/, '');
	formObj.telefono.value=formObj.telefono.value.replace(/obbligatorio tel. o email/, '');
	formObj.telefono.value=formObj.telefono.value.replace(/^\s+|\s+$/, '');
	formObj.email.value=formObj.email.value.replace(/obbligatorio tel. o email/, '');
	formObj.email.value=formObj.email.value.replace(/^\s+|\s+$/, '');
	errore ="";
	if (formObj.nome.value=="")
		errore = errore + " - e' obbligatorio indicare il nome\n";
	if (formObj.email.value=="" && formObj.telefono.value=="")
		errore = errore + " - e' obbligatorio indicare almeno uno tra email e telefono\n";
	if (formObj.email.value!="" && !/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(formObj.email.value))
		errore = errore + " - indirizzo email non valido\n";
	if (formObj.telefono.value!="" && !/^\d+$/.test(formObj.telefono.value))
		errore = errore + " - il telefono deve contenere solo caratteri numerici\n";

	if (errore!=""){
		errore = "Errori nei dati:\n" + errore;
		alert(errore);
		return false;
	}else{
		return true;
	}
}

function fotoplus(indice,operazione){
	var objOmbra = window.document.getElementById('popupOmbra_'+indice);
	var objImage = window.document.getElementById('popupImage_'+indice);
	var objImg = window.document.getElementById('img_'+indice);
	with(objImage.style){
		width=(objImg.width)+'px';
		height=(objImg.height)+'px';
		marginTop='-35px';
		marginLeft='-35px';
	}
	with(objOmbra.style){
		width=(objImg.width)+'px';
		height=(objImg.height)+'px';
		marginTop='-30px';
		marginLeft='-30px';
	}
	objImage.style.display=operazione;
	objOmbra.style.display=operazione;
}
