function conta_caratteri(conta, mostra) {
	mostra.value="["+conta.value.length+"]:";
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") return inputString;
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
	
   while (ch == " ") { // Check for spaces at the beginning of the string
	  retValue = retValue.substring(1, retValue.length);
	  ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length - 1, retValue.length);
	
   while (ch == " ") { // Check for spaces at the end of the string
	  retValue = retValue.substring(0, retValue.length - 1);
	  ch = retValue.substring(retValue.length - 1, retValue.length);
   }
	
	// Note that there are two spaces in the string - look for multiple spaces within the string
   while (retValue.indexOf("  ") != -1) {
		// Again, there are two spaces in each of the strings
	  retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length);
   }
   return retValue; // Return the trimmed string back to the user
}

function ControllaIscr()
{
	frm = document.forms['MyForm'];
	sMsg2 = "";
	email_reg_exp=/^([a-zA-Z0-9_\.\-\&])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	var nick=trim(frm.nick.value);
	var nome=trim(frm.nome.value);
	var cognome=trim(frm.cognome.value);
	var cellulare=trim(frm.cellulare.value);
	var indirizzo=trim(frm.indirizzo.value);
	var localita=trim(frm.localita.value);
	var provincia=trim(frm.provincia.options[frm.provincia.selectedIndex].value);
	var mail=trim(frm.mail.value);
	
	if (nick=="") {
		sMsg2 = sMsg2 + "Il campo Nick è obbligatorio\n";
	} else if (nick.length < 5) {
		sMsg2 = sMsg2 + "Il campo Nick deve essere di almeno 5 caratteri\n";
	}
	
	if (nome=="") {
		sMsg2 = sMsg2 + "Il campo Nome è obbligatorio\n";
	} else if (nome.length < 2) {
		sMsg2 = sMsg2 + "Il campo Nome deve essere di almeno 2 caratteri\n";
	}

	if (cognome=="") {
		sMsg2 = sMsg2 + "Il campo Cognome è obbligatorio\n";
	} else if (cognome.length < 2) {
		sMsg2 = sMsg2 + "Il campo Cognome deve essere di almeno 2 caratteri\n";
	}

	if (indirizzo=="") {
		sMsg2 = sMsg2 + "Il campo Indirizzo è obbligatorio\n";
	} else if (indirizzo.length < 5) {
		sMsg2 = sMsg2 + "Il campo Indirizzo deve essere di almeno 5 caratteri\n";
	}

	if (localita=="") {
		sMsg2 = sMsg2 + "Il campo Località è obbligatorio\n";
	} else if (localita.length < 2) {
		sMsg2 = sMsg2 + "Il campo Località deve essere di almeno 2 caratteri\n";
	}

	if (provincia=="") {
		sMsg2 = sMsg2 + "Devi selezionare una Provincia\n";
	} 
	
	if (mail=="") {
		sMsg2 = sMsg2 + "Il campo Mail è obbligatorio\n";
	} else if (!email_reg_exp.test(mail)) {
		sMsg2 = sMsg2 + "Inserisci una Mail corretta!\n";
	}
	
	if (sMsg2) {
		alert(sMsg2);
		return false;
	} else {
		frm.submit();
		return true;
	}

}

function ControllaModIscr()
{
	frm = document.forms['MyForm'];
	sMsg2 = "";
	email_reg_exp=/^([a-zA-Z0-9_\.\-\&])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	var pwd=trim(frm.pwd.value);
	var nome=trim(frm.nome.value);
	var cognome=trim(frm.cognome.value);
	var cellulare=trim(frm.cellulare.value);
	var indirizzo=trim(frm.indirizzo.value);
	var localita=trim(frm.localita.value);
	var provincia=trim(frm.provincia.options[frm.provincia.selectedIndex].value);
	var mail=trim(frm.mail.value);
	
	if (pwd=="") {
		sMsg2 = sMsg2 + "Il campo Password è obbligatorio\n";
	} else if (pwd.length < 5) {
		sMsg2 = sMsg2 + "Il campo Password deve essere di almeno 5 caratteri\n";
	}
	
	if (nome=="") {
		sMsg2 = sMsg2 + "Il campo Nome è obbligatorio\n";
	} else if (nome.length < 2) {
		sMsg2 = sMsg2 + "Il campo Nome deve essere di almeno 2 caratteri\n";
	}

	if (cognome=="") {
		sMsg2 = sMsg2 + "Il campo Cognome è obbligatorio\n";
	} else if (cognome.length < 2) {
		sMsg2 = sMsg2 + "Il campo Cognome deve essere di almeno 2 caratteri\n";
	}

	if (indirizzo=="") {
		sMsg2 = sMsg2 + "Il campo Indirizzo è obbligatorio\n";
	} else if (indirizzo.length < 5) {
		sMsg2 = sMsg2 + "Il campo Indirizzo deve essere di almeno 5 caratteri\n";
	}

	if (localita=="") {
		sMsg2 = sMsg2 + "Il campo Località è obbligatorio\n";
	} else if (localita.length < 2) {
		sMsg2 = sMsg2 + "Il campo Località deve essere di almeno 2 caratteri\n";
	}

	if (provincia=="") {
		sMsg2 = sMsg2 + "Devi selezionare una Provincia\n";
	} 
	
	if (mail=="") {
		sMsg2 = sMsg2 + "Il campo Mail è obbligatorio\n";
	} else if (!email_reg_exp.test(mail)) {
		sMsg2 = sMsg2 + "Inserisci una Mail corretta!\n";
	}
	
	if (sMsg2) {
		alert(sMsg2);
		return false;
	} else {
		frm.submit();
		return true;
	}

}

function ControllaMod(n)
{

	frm = document.forms['MyForm'];
	sMsg2 = "";

if (n == "LogPas")
{
	if(frm.Nick.value == "")
	{
		sMsg2 = sMsg2 + " * Nick\n";
	}
	if(frm.Password.value == "")
	{
		sMsg2 = sMsg2 + " * Password\n";
	}
}
else
{
	if(frm.DNick.value == "")
	{
		sMsg2 = sMsg2 + " * Nick\n";
	}
	if(frm.Mail.value == "")
	{
		sMsg2 = sMsg2 + " * Email\n";
	}
}

	if(sMsg2!="")
	{
		sMsg2 = "ATTENZIONE!\nSeguenti campi è obbligatori non sono stati compilati\n\n" + sMsg2 + "\n";
		alert(sMsg2);
	}
	else
	{
		frm.AZIONE.value = n

		frm.submit();
		return (true);
	}
}
function ControllaGrp() {
	frm = document.forms['MyForm'];
	
	sMsg = "";

	if(frm.GruppoCorrente.value == frm.gruppo.options[frm.gruppo.selectedIndex].value)
	{
		sMsg = sMsg + " * Appartieni già a questo gruppo\n";
	}

	if(frm.gruppo.options[frm.gruppo.selectedIndex].value == "")
	{
		sMsg = sMsg + " * Seleziona un gruppo\n";
	}
	
	if(sMsg!="")
	{
		sMsg = "ATTENZIONE!\n\n" + sMsg + "\n";
		alert(sMsg);
	}
	else
	{
		frm.submit();
		return (true);
	}
}

function ControllaGB()
{
	frm = document.forms['MyForm'];
	sMsg2 = "";
	email_reg_exp=/^([a-zA-Z0-9_\.\-\&])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if(trim(frm.MiChiamo.value)=="")
	{
		sMsg2 = sMsg2 + " * Mi Chiamo\n";
	}
	smail=trim(frm.MiaMail.value);
	if(smail=="")
	{
		sMsg2 = sMsg2 + " * E-Mail\n";
	} else if (!email_reg_exp.test(smail)) {
		sMsg2 = sMsg2 + " * E-Mail (inserisci una Mail corretta!)\n";
	}

	if(trim(frm.Messaggio.value)=="")
	{
		sMsg2 = sMsg2 + " * Messaggio\n";
	} else {
		var messaggio=trim(frm.Messaggio.value);
		if (messaggio.length > 1000)
			sMsg2 = sMsg2 + " * Messaggio è superiore a 1000 caratteri!\n";
	}

	if(trim(frm.testo_jpg.value)=="")
	{
		sMsg2 = sMsg2 + " * Codice di controllo\n";
	}
	

	
	if(sMsg2!="")
	{
		sMsg2 = "I seguenti campi obbligatori non sono stati correttamente compilati:\n\n" + sMsg2 + "\n";
		alert(sMsg2);
	}
	else
	{
		frm.submit();
		return (true);
	}

}

function ControllaMexFor()
{
	frm = document.forms['MyForm'];
	sMsg2 = "";
	//controlla mail valida
	stringamail=frm.Email.value;
	chiocciolina=parseInt(stringamail.indexOf("@"));
	puntino=parseInt(stringamail.lastIndexOf("."));
	if(chiocciolina<2 || (puntino<(chiocciolina+4)))
	{	
		sMsg2 = sMsg2 + " * Devi inserire un indirizzo E-mail valido" + "\n";
	}
	if(frm.Nome.value=="")
	{
		sMsg2 = sMsg2 + " * Nome\n";
	}
	if(frm.Soggetto.value=="")
	{
		sMsg2 = sMsg2 + " * Soggetto\n";
	}
	if(frm.Messaggio.value=="")
	{
		sMsg2 = sMsg2 + " * Messaggio\n";
	}
	if(sMsg2!="")
	{
		sMsg2 = "I seguenti campi obbligatori non sono stati compilati:\n\n" + sMsg2 + "\n";
		alert(sMsg2);
	}
	else
	{
		frm.submit();
		return (true);
	}

}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function addBookmark(url_da_inserire, titolo_da_inserire) {
	if ( window.sidebar && window.sidebar.addPanel ) {
		window.sidebar.addPanel(titolo_da_inserire, url_da_inserire,'');
	} else if ( window.external && ( navigator.platform == 'Win32' || ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) {
		window.external.AddFavorite(url_da_inserire, titolo_da_inserire);
	} else {
		alert('Per inserire la pagina tra i preferiti, segui le istruzioni del tuo browser!');
	}
}

function setHomepage(url, nome_sito) {    
    if(document.all)
    {
        document.body.style.behavior='url(#default#homepage)';
        document.body.setHomePage(url);
    }
    else
        alert('Attenzione! Questa funzione è valida solo per Internet Explorer. Per inserire "' + nome_sito + '" come Pagina Iniziale, segui le istruzioni del tuo browser.');
}

function openPopUp(pagina,wi,he,sc) {
	if (wi) { width=wi; } else { width=570; }
	if (he) { height=he; } else { height=350; }
	if (!sc) sc='yes';
	finestrella = window.open(pagina, '_blank', 'scrollbars=' + sc + ',resizable=no, status=no, width=' + width + ',height=' + height + ',top=' + ((screen.height/2) - (height/2)) + ',left=' + ((screen.width/2) - width/2));
}

function segnala_sito() {
	sMsg2="";
	frm=document.form_ss;
	nome_mittente=trim(frm.nome_mittente.value);
	email_mittente=trim(frm.email_mittente.value);
	nome_destinatario=trim(frm.nome_destinatario.value);
	email_destinatario=trim(frm.email_destinatario.value);
	email_reg_exp=/^([a-zA-Z0-9_\.\-\&])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;

	if (nome_mittente=="") {
		sMsg2 = sMsg2 + "Il campo Nome Mittente è obbligatorio\n";
	}
	
	if (email_mittente=="") {
		sMsg2 = sMsg2 + "Il campo Mail Mittente è obbligatorio\n";
	} else if (!email_reg_exp.test(email_mittente)) {
		sMsg2 = sMsg2 + "Inserisci una Mail Mittente corretta!\n";
	}
	
	if (nome_destinatario=="") {
		sMsg2 = sMsg2 + "Il campo Nome Destinatario è obbligatorio\n";
	}
	
	if (email_destinatario=="") {
		sMsg2 = sMsg2 + "Il campo Mail Destinatario è obbligatorio\n";
	} else if (!email_reg_exp.test(email_destinatario)) {
		sMsg2 = sMsg2 + "Inserisci una Mail Destinatario corretta!\n";
	}
	
	if (sMsg2) {
		alert('Attenzione!\n'+sMsg2);
		return false;
	} else {
		return true;
	}

}
//-->