function controllaData(frm,gg,mm,aa,nome){
	if (document.forms[frm][aa].value.length == 1 ||
		document.forms[frm][aa].value.length == 3 ) {
		alert(nome + " errata. Inserire un valore corretto per	l'anno")
		return false
	}	
	if (document.forms[frm][aa].value.length == 2 ){
		if (document.forms[frm][aa].value < 30 ) {
			anno = "20" + document.forms[frm][aa].value
			document.forms[frm][aa].value = anno
		} else {
			anno = "19" + document.forms[frm][aa].value
			document.forms[frm][aa].value = anno
		}
	}	
	if (document.forms[frm][aa].value < 1800 && document.forms[frm][aa].value != "" ) {
		alert("L'anno del campo " + nome + " inserita è fuori dal range	consentito")
		return false
	}	
	
	if (document.forms[frm][mm].value > 12 ) {
		alert(nome + " errata. Inserire un valore corretto per il mese")
		return false
	}	
	if (document.forms[frm][mm].value == "2" ||  document.forms[frm][mm].value	== "02" ) {
		if ((document.forms[frm][aa].value % 4 ) == 0 ){
			if (document.forms[frm][gg].value > 29 ) {
				alert(nome + " errata. Inserire un valore corretto per il giorno")
				return false
			}
		} else if (document.forms[frm][gg].value > 28 ) {
			alert(nome + " errata. Inserire un valore corretto per il giorno")
			return false
		}
	} else if (document.forms[frm][mm].value == "04" || 
				document.forms[frm][mm].value == "4" || 
				document.forms[frm][mm].value == "06" || 
				document.forms[frm][mm].value == "6"  || 
				document.forms[frm][mm].value == "09" || 
				document.forms[frm][mm].value == "9"  || 
				document.forms[frm][mm].value == "11") {
		if (document.forms[frm][gg].value > 30 ) {
			alert(nome +" errata. Inserire un valore corretto per il giorno")
			return false
		}
	} else {
		if (document.forms[frm][gg].value > 31 ) {
			alert(nome +" errata. Inserire un valore corretto per il giorno")
			return false
		}
	}	
	return true
}

// mostra riquadro di anteprima
function anteprima(textarea,w,h) {
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;	
	//var inf = document.form.testo.value;
	var inf = document.getElementById(textarea).value;
	inf = inf.split(/\n/).join("<br />");
	var win = window.open(", ", "popup", "width="+w+",height="+h+",top="+TopPosition+",left="+LeftPosition+",scrollbars=yes");
	win.document.open();	
	win.document.writeln("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
	win.document.writeln("<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>");
	win.document.writeln("<head><title>Anteprima</title>");	
	win.document.writeln("<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' />");
	win.document.writeln("<link href='inc/style.css' rel='stylesheet' type='text/css' />");
	win.document.writeln("</head><body>");
	win.document.writeln("<div style='text-align:right; margin-bottom:20px;'><a href='javascript:window.close()'>Chiudi</A></div>");
	win.document.writeln("" + inf + "");
	win.document.writeln('</body></html>');
	win.document.close();
}

// controllo email: restituisce true o false
function controllaEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}

// controllo form
function controllaForm(){
	str = "";
	// controllo per un input type=text
	if (document.getElementById(nome).value == "") str = str + "Inserire il nome\n";	
	// controllo per un input type=password
	if (document.getElementById(password).value != document.getElementById(password2).value) str = str + "La password di conferma non è corretta\n";
	// controllo per un input type=text numerico
	if (isNaN(document.getElementById(anno).value) || document.getElementById(anno).value == "") str = str + "Inserire l\'anno\n";
	// invia messaggio di avvertimento
	if (str != "") {
		alert (str);
		return false;
	}
	return true;
}
function controllaMail(EmailAddr){
 Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
 if (Filtro.test(EmailAddr))
    return true;
 else
    return false;
}

function toggle(obj,tipo) {
	var el = document.getElementById(obj);
	if (!tipo) {
		if ( el.style.display != 'none' ) {
			el.style.display = 'none';
		}	else {
			el.style.display = 'block';
		}
	} else if (tipo == 'mostra') { el.style.display = 'block';
	} else if (tipo == 'nascondi') { el.style.display = 'none'; }
}

//popup
var win = null;
function popup(mypage,w,h){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	h = h + 10;
	w = w + 10;
	settings =
	'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+'no'+',resizable'
	winName = 'winName'+w+h;
	window.open(mypage,winName,settings);
}

