filtro_spazi = /^\s*$/;
filtro_alfanum = /^[A-z0-9_]+$/;
filtro_digit = /^\d+$/;
filtro_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
filtro_float = /^\d+[\,\.]\d+$|^\d+$/;
filtro_data = /^[0-3][0-9][\/|\-][01][0-9][\/|\-][123][0-9][0-9][0-9]$/;
filtri = new Array(filtro_alfanum // 0
					, filtro_digit // 1
					, filtro_mail // 2
					, filtro_float // 3
					, filtro_data); // 4

function apriFinestra(url, nomeFinestra) {
	finestraFiglia = window.open(url, nomeFinestra, "toolbar=0,scrollbars=auto,status=0,resizable=1,width=200,height=200");
	finestraFiglia.focus();
}

function safeSubmit(theForm) {
	for(i = 0; i < document.links.length; i++) {
		document.links[i].href = "#";
	}
	for(i = 0; i < theForm.elements.length; i++) {
		if(theForm.elements[i].type == "button" || theForm.elements[i].type == "image" || theForm.elements[i].type == "submit") {
			theForm.elements[i].disabled = true;
		}
	}
	theForm.submit();
}

function valSelect(objSelect) {
	if(objSelect.selectedIndex >= 0)
		return objSelect.options[objSelect.selectedIndex].value;
	else
		return "";
}

function checkInput(oggetto, descrizione, indice_filtri, obbligatorio) {
	if(oggetto) {
		if(oggetto.type && /^select.*/i.test(oggetto.type)) {
			if(obbligatorio && filtro_spazi.test(valSelect(oggetto))) {
				alert("PREGO SELEZIONI IL CAMPO " + descrizione);
				oggetto.focus();
				return false;
			}
		} else {
			if(filtro_spazi.test(oggetto.value) && obbligatorio) {
				alert("PREGO COMPILI IL CAMPO "+descrizione);
				oggetto.focus();
				return false;
			} else if(indice_filtri >= 0 && oggetto.value != "" && !filtri[indice_filtri].test(oggetto.value)) {
				alert("ATTENZIONE, CAMPO " + descrizione + " NON VALIDO");
				oggetto.focus();
				return false;
			}
		}
		return true;
	} else
		return true;
}

function premutoInvio(e) {
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else
		keycode = e.which;
	if (keycode == 13)
		return true;
	else
		return false;
}

function full_screen() {
	if (typeof(screen.availWidth)!="undefined") {
		if(!navigator.userAgent || navigator.userAgent.toLowerCase().indexOf("msie") >= 0) {
			window.resizeTo(screen.availWidth + 8, screen.availHeight + 8);
			window.moveTo(-4, -4);
		} else {
			window.resizeTo(screen.availWidth, screen.availHeight);
			window.moveTo(0, 0);
		}
	}
}

function centerInScreen(w,h) {
	var wScreen, hScreen;
	if (typeof(screen.availWidth)!="undefined") {
		wScreen = screen.availWidth;
		hScreen = screen.availHeight;
	} else {
		wScreen = 1024;
		hScreen = 768;
	}
	resizeTo(w,h);
	moveTo((wScreen - w) / 2, (hScreen - h) / 2);
}

function strDecode(stringa) {
	stringa = stringa.replace(/&s;/g, '\\');
	stringa = stringa.replace(/&dq;/g, '"');
	stringa = stringa.replace(/&q;/g, "'");
	stringa = stringa.replace(/&l;/g, '<');
	stringa = stringa.replace(/&g;/g, '>');
	stringa = stringa.replace(/&p;/g, '.');
	stringa = stringa.replace(/&bs;/g, ' ');
	stringa = stringa.replace(/&a;/g, '&'); // sempre per ultimo
	return stringa;
}

function dateToInt(strData) {
	var objDataTemp = new Date(strData.substr(6,4), strData.substr(3,2) - 1, strData.substr(0,2));
	return objDataTemp.valueOf();
}

function cleanForm(ilform) {
	for(var i=0; elemento = ilform.elements[i]; i++) {
		if(elemento.type=="text") elemento.value = "";
		if(elemento.type=="select-one") elemento.selectedIndex = 0;
		if(elemento.type=="radio") if(elemento.value == "") elemento.checked = true;
	}
}

function TrasferisciValoriSelezionatiDueSelect(selectFrom, selectTo) {
	if(selectFrom.selectedIndex >= 0) {
		for(i = 0; i < selectFrom.length; i++) {
			if(selectFrom[i].selected) {
				selectTo[selectTo.length] = new Option(selectFrom[i].text, selectFrom[i].value);
				selectFrom[i--] = null;
			}
		}
	}
}

function selezionaTutteLeOption(objSelect) {
	for(i = 0; i < objSelect.length; i++)
		objSelect[i].selected = true;
}

function getAjaxData(parametri, cellaTarget) {
	var XMLHttpRequestObject = false;
	if (window.XMLHttpRequest)
		XMLHttpRequestObject = new XMLHttpRequest();
	else if (window.ActiveXObject)
		XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHttp");
	if(XMLHttpRequestObject) {
		XMLHttpRequestObject.open("GET", "ajax.php?" + parametri);
		XMLHttpRequestObject.onreadystatechange = function() {
			if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
				cellaTarget.innerHTML = XMLHttpRequestObject.responseText;
			}
		}
		XMLHttpRequestObject.send(null);
	}
}