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 testo_jpg=trim(frm.testo_jpg.value);
	var nome=trim(frm.nome.value);
	var cognome=trim(frm.cognome.value);
	var mail=trim(frm.mail.value);
	
	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 (mail=="") {
		sMsg2 = sMsg2 + "Il campo Mail è obbligatorio\n";
	} else if (!email_reg_exp.test(mail)) {
		sMsg2 = sMsg2 + "Inserisci una Mail corretta!\n";
	}
	
	if (testo_jpg=="") {
		sMsg2 = sMsg2 + "Il campo Testo di controllo Antispam è obbligatorio\n";
	} else if (testo_jpg.length < 10) {
		sMsg2 = sMsg2 + "Il campo Testo di controllo Antispam deve essere di 10 caratteri\n";
	}

	if(frm.consenti.checked==false)
	{
		sMsg2 = sMsg2 + "Il consenso al trattamento dei dati personali è obbligatorio\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 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 (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.Mail.value == "")
		{
			sMsg2 = sMsg2 + " * Email\n";
		}
	}

	if(sMsg2!="")
	{
		sMsg2 = "ATTENZIONE!\nI seguenti 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 conta_caratteri(conta, mostra) {
	mostra.value="["+conta.value.length+"]";
}

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(frm.consenti.checked==false)
	{
		sMsg2 = sMsg2 + " * Consenso uso dati personali\n";
	}
	
	if(sMsg2!="")
	{
		sMsg2 = "I seguenti campi obbligatori non sono stati compilati:\n\n" + sMsg2 + "\n";
		alert(sMsg2);
	}
	else
	{
		frm.submit();
		return (true);
	}

}

function ControllaGBGruppi()
{
	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.nome_utente.value)=="")
	{
		sMsg2 = sMsg2 + " * Mi Chiamo\n";
	}
	smail=trim(frm.email_utente.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.testo.value)=="")
	{
		sMsg2 = sMsg2 + " * Messaggio\n";
	} else {
		var messaggio=trim(frm.testo.value);
		if (messaggio.length > 1000)
			sMsg2 = sMsg2 + " * Messaggio è superiore a 1000 caratteri!\n";
	}

	if(frm.consenti.checked==false)
	{
		sMsg2 = sMsg2 + " * Consenso uso dati personali\n";
	}
	
	if(sMsg2!="")
	{
		sMsg2 = "I seguenti campi obbligatori non sono stati 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) {
	var ua=navigator.userAgent.toLowerCase();
	var isKonq=(ua.indexOf('konqueror')!=-1);
	var isSafari=(ua.indexOf('webkit')!=-1);
	var isMac=(ua.indexOf('mac')!=-1);
	var buttonStr=isMac?'Command/Cmd':'CTRL';
	
	if (window.sidebar && window.sidebar.addPanel) { // Firefox
		alert('Per inserire la pagina tra i preferiti premi '+buttonStr+' + D.');
	} else if (window.external && (navigator.platform == 'Win32' || (window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ))) { // IE/Win
		window.external.AddFavorite(url_da_inserire, titolo_da_inserire);
	} else {
		if (isKonq)
			alert('Per inserire la pagina tra i preferiti premi CTRL + B.');
		else if (window.home || isSafari) // Firefox, Netscape, Safari, iCab, Opera
			alert('Per inserire la pagina tra i preferiti premi '+buttonStr+' + D.');
		else if (!window.print || isMac) // IE5/Mac and Safari 1.0
			alert('Per inserire la pagina tra i preferiti premi Command/Cmd + D.');    
		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 esci() {
	if (parent.parent.GB_hide)
		parent.parent.GB_hide();
	else
		history.back();
}

function stampa_pagina() {
	print();
}

function getPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	curleft += obj.x;
	return curleft;
} 

function getPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
	curtop += obj.y;
	return curtop;
}

function apriPopUp(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));
}

// per gestione banner
div_id="";
zone_id=new Array();
function hide_banner_div(zona_id) {	
	if (div_id) {
		elements=div_id.split(",");
		for (i=0; i<(elements.length-1); i++) {			
			if (zone_id.length>0 && zona_id!="")
				for (c=0; c<zone_id.length; c++)
					if (elements[i]==zone_id[c])
						zone_id.splice(c,1); 
			if (document.getElementById(elements[i])) document.getElementById(elements[i]).style.display="none";
		}
		if (zone_id.length>0 && document.getElementById(zona_id)) document.getElementById(zona_id).style.display="block";
	}
	div_id="";
}

//-->
