 //Resetta tutti i forms della pagina chiamante
function resettaForms(){
	var tuttiForms = document.forms;
	for(index=0; index < tuttiForms.length; index++) {
		document.forms[index].reset();
	}
}

//testa la data avente come parametri tre valori numerici; l'anno deve essere a 4 cifre
function checkData(gg, mm, aaaa) {
	//alert(gg + "," + mm + "," + aaaa);
	if (gg.length == 0 || mm.length == 0 || aaaa.length == 0) {
		alert('Compilare tutti i campi della data.');
		return false;
	} else if (isNaN(gg) || isNaN(mm) || isNaN(aaaa)) {
		alert('Immettere solo caratteri numerici per la data.');
		return false;
	} else if (gg.indexOf('.') > 0 || mm.indexOf('.') > 0 || aaaa.indexOf('.') > 0) {
		alert('Immettere solo cifre non decimali per la data.');
		return false;
	} else if (aaaa.length != 4) {
		alert('L\'anno deve essere di 4 cifre.');
		return false;	
	} else {
		if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10 || mm == 12) {
			if (gg < 1 || gg > 31) {
				alert('Il giorno deve essere compreso tra 1 e 31');
				return false;
			}
		} else if (mm == 4 || mm == 6 || mm == 9 || mm == 11) {
			if (gg < 1 || gg > 30) {
				alert('Il giorno deve essere compreso tra 1 e 30');
				return false;
			}			
		} else if (mm == 2 && aaaa % 4 == 0) {	//se č bisestile
				if (gg < 1 || gg > 29) {
					alert('Il giorno deve essere compreso tra 1 e 29');
					return false;
				}
		} else if (mm == 2 && aaaa % 4 > 0) {
				if (gg < 1 || gg > 28) {
					alert('Il giorno deve essere compreso tra 1 e 28');
					return false;
				}
		} else {
			alert('Immettere un  mese valido.');
			return false;
		}
	}
	//alert(gg+"/"+mm+"/"+aaaa+" data corretta");
}

//testa la correttezza dell'indirizzo e-mail
function CheckMail(email) {
	if (email.length > 0) {
		var objRegExp = new RegExp("^[a-z0-9._-]+\@[a-z0-9._-]+\.[a-z]{2,4}$", "gi");
		if (objRegExp.test(email) == false) {
			alert('Indirizzo e-mail non corretto.');
			return false;
		}
	} else if (email.length == 0) {
		alert('Inserisci un indirizzo e-mail.');
		return false;
	}
}
	
//testa che nel campo passato non ci sia una parola pių lunga di quanto consentito
function checkWordLength(testo, lungMax) {
	if (testo.length > 0) {
		var re = /\s/g;
		var splitTesto = testo.split(re);
		for (var i = 0; i < splitTesto.length; i++) {
			if (splitTesto[i].length > lungMax) {
				alert("Una o pių parole nel testo sono pių lunghe di " + lungMax + " caratteri\:\n\n" + splitTesto[i]);
				return false;
			}
		}
	} else if (testo.length == 0) {
		alert("Inserisci un testo");
	}
}

//Nasconde o mostra tag al volo(operazione = 'vedi' per mostrare, 'nascondi' per nascondere)
function vediNascondi(cheCosa, operazione) { 
	if (document.all) {  // creo le variabili per la sintassi di IE 
			documento="document.all"; 
			partA="[\""; 
			partB="\"]"; 
			visibilita=".style.display"; 
			nascosto="\"none\""; 
			visibile="\"block\""; 
	} 
	else if (document.layers){ //NN4 
			documento="document.layers"; 
			partA="[\""; 
			partB="\"]"; 
			visibilita=".display"; 
			nascosto="\"none\""; 
			visibile="\"block\""; 
	} 
	else if (document.getElementById) { // Opera e NN6 
			documento="document.getElementById"; 
			partA="(\""; 
			partB="\")"; 
			visibilita=".style.display"; 
			nascosto="\"none\""; 
			visibile="\"block\""; 
	}
	if (operazione == "nascondi") {
		eval(documento+partA+cheCosa+partB+visibilita+"="+nascosto+";");
	} else if (operazione == "vedi") {
		eval(documento+partA+cheCosa+partB+visibilita+"="+visibile+";");
	}
}
	
//Per l' anteprima finestra news nella pagina EditNews.asp
var newwindow;
function aprifinestraOld() {
	if (newwindow) newwindow.close();
	var LAR = document.aggnews.larghFin.value;
	var ALT = document.aggnews.altFin.value;
	var now = document.aggnews.datenews.value;
	var news = document.aggnews.messaggio.value;
	if (!ALT || !LAR) {
		alert('Inserire le dimensioni della finestra.');
		return false;
	}
	var daSx = (screen.availWidth - LAR)/2;
	var daSopra = (screen.availHeight - ALT)/2;
	//Define contents of page
	contents = '<html><head><title>toys</title><style>@import url(../front.css);</style></head>'+
	'<body link="#ff0000" vlink="#ff3333" alink="#ff0000" background="../gif/sfondolati.gif">'+
	'<table class="Comm" align="center" border="0" width="100%" height="100%" cellspacing="10" cellpadding="0"><tr>'+
	'<td valign="top" height="30" bgcolor="#0e0e0e"><p align="center"><font color="#ffff00"><b>News<br>'+now+
	'</b></font></p></td></tr><tr>'+
	'<td valign="top" bgcolor="#0e0e0e"><font color="#ffffff">'+news+
	'</font> </font></p></td></tr></table></body></html>'
	//Create new Window
	newwindow = window.open('','popup','top='+daSopra+',left='+daSx+',width='+LAR+',height='+ALT+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	newwindow.document.writeln(contents);
	newwindow.document.close();
	newwindow.focus();
}	

var newwin;
function apriFinestraNews(typeRE, news, LAR, now, foldCSS) {
	//if (newwin) newwin.close();
	if (!news) news = document.aggnews.messaggio.value;
	if (!LAR) LAR = parseInt(document.aggnews.larghFin.value);
	if (!now) now = document.aggnews.datenews.value;
	if (!foldCSS) {
		foldCSS = "";
	} else {
		foldCSS += "/";
	}
	if (typeRE == 1) {
		var news = news.replace(/\r\n+/g, "<br>");
	} else if (typeRE == 2) { 
		var news = news.replace(/[\r\n]|[\n]+/g, "<br>");
	}
	document.getElementById('divNews').style.width = LAR;
	document.getElementById('divNews').style.padding = "10px";
	document.getElementById('divNews').style.position = "absolute";
	document.getElementById('divNews').style.fontFamily = "verdana";
	document.getElementById('divNews').style.fontSize = "11px";
	document.getElementById('divNews').style.color = "#ffffff";
	document.getElementById('divNews').style.fontWeight = "normal";
	document.getElementById('divNews').style.textAlign = "justify";
	document.getElementById('divNews').style.backgroundColor = "#1c1c1c";
	document.getElementById('divNews').innerHTML = news;
	
	vediNascondi('divNews', 'vedi');
		LAR += 30;
	var ALT = document.getElementById('divNews').clientHeight + 60;
	vediNascondi('divNews', 'nascondi');
	
	if (!ALT || !LAR) {
		alert('Inserire le dimensioni della finestra.');
		return false;
	}
	var daSx = (screen.availWidth - LAR)/2;
	var daSopra = (screen.availHeight - ALT)/2;
	contents = '<html><head><title>Toys</title><link REL="stylesheet" HREF="'+foldCSS+'pzStyle.css" TYPE="text/css"></head>'+
	'<body link="#ff0000" vlink="#ff3333" alink="#ff0000" style="scrollbar-face-color: #1c1c1c;	scrollbar-highlight-color: #1c1c1c; scrollbar-3dlight-color: #1c1c1c; scrollbar-darkshadow-color: #1c1c1c; scrollbar-shadow-color: #1c1c1c; scrollbar-arrow-color: #FFFFFF; scrollbar-track-color: #1c1c1c;">'+
	'<div id="titolo" class="titoloFinNews">News '+now+'</div><div id="mah" class="testoFinNews">'+news+'</div></body></html>'
	newwin = window.open('','popup','top='+daSopra+',left='+daSx+',width='+LAR+',height='+ALT+',toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes');
	newwin.document.writeln(contents);
	newwin.document.close();
	newwin.focus();
}