function BOB_checkLengthItem(campo, lunghezza, nome, formo) {
	
	var sValue;	
	if (formo == null) {formo = "bob_formo"}	
	sValue = document.forms[formo].elements[campo].value;
	if (sValue.length > lunghezza) {
		alert ("La lunghezza del campo '" + nome + "' dev'essere minore di " + lunghezza + " caratteri.\n\nTu ne hai digitati " + sValue.length);
		document.forms[formo].elements[campo].focus();
		return false
	} else {
		return true
	}
}

function BOB_checkForm(lingua, formo) {
	
	var i, sName;	
	if (formo == null) {formo = "bob_formo"}	
	for (i=0;i < document.forms[formo].length; i++) {
		
		sName = document.forms[formo].elements[i].name;
		if (sName == "") {sName = document.forms[formo].elements[i].id;}
		
		if ((sName.charAt(0) != "_") && (sName.indexOf("___Config") < 0)) {
			//alert("sName: " + sName)
			
			if (document.forms[formo].elements[i].value == "") {			
				if (lingua == "ita") alert ("Il campo  [ " + sName + " ]  è obbligatorio!")
				else if (lingua == "spa") alert ("Todas las casillas son obligatorias!")
				else if (lingua == "ing") alert ("Please compile the [ " + sName + " ]  obligatory field!")
				else if (lingua == "ted") alert ("Alle Einträge sind obligatorisch!")
				else if (lingua == "fra") alert ("Tous les champs sont obligatoires!")
				else if (lingua == "por") alert ("Please compile the [ " + sName + " ]  obligatory field!")
				else alert ("...");
				
				document.forms[formo].elements[i].focus();
				
				break
			} else {
				if (((sName == "email") || (sName == "email_mittente") || (sName == "email_destinatario") || (sName == "e-mail"))
				 && (((document.forms[formo].elements[i].value).indexOf("@")==-1)
				 || ((document.forms[formo].elements[i].value).indexOf(".")==-1))
				 ) {
					if (lingua == "ita") alert ("L'email inserita non è valida!")
					else if (lingua == "spa") alert ("La dirección e-mail no es correcta!")
					else if (lingua == "ing") alert ("Please insert a valid e-mail address!")
					else if (lingua == "ted") alert ("Please insert a valid e-mail address!")
					else if (lingua == "fra") alert ("Please insert a valid e-mail address!")
					else if (lingua == "por") alert ("Please insert a valid e-mail address!")
					else alert ("...");
					
					document.forms[formo].elements[i].focus();
					
					break
				}
			}
		}
	}

	if (i == document.forms[formo].length) {
		return true
	} else {
		return false
	}
}


function BOB_submit(lingua, formo) {
	if (formo == null) {formo = "bob_formo"}
	if (BOB_checkForm(lingua, formo)) {
		document.forms[formo].submit();
	}
}

function BOB_saveformo(tabella, lingua) {
	testo = "?";
	if (lingua == "ita") {testo = "Sei sicuro di voler aggiornare questi dati della tabella '" + tabella + "'?"}

	if (confirm(testo)) {
		if (BOB_checkForm(lingua)) {
			document.bob_formo.submit()
		}
	}
}

function BOB_delart(tabella, lingua) {
	testo1 = "?";
	testo2 = "!";
	if (lingua == "ita") {
		testo1 = "Sei sicuro di voler eliminare questi dati della tabella '" + tabella + "'?"
		testo2 = "Nessun" + tabella + " selezionata!"
	}

	if (confirm(testo1)) {
		if (document.bob_formo._ID.value == "") {
			alert (testo2);
		} else {
			document.bob_formo._Cosa.value = "Del";
			document.bob_formo.submit()
		}
	}
}

function BOB_openBrWindow(theURL,winName,features) {
  mywin = window.open(theURL,winName,features);
  mywin.focus();
}

function BOB_setDiesis() {

	t = document.bob_formo.link_cartella.value;
	switch(t) {	
	case "#":
		document.bob_formo.link.value = "top"
	break;
	}
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.,";
	var IsNumber=(sText.length > 0);
	var Char;
	
	for (i = 0; i < sText.length && IsNumber == true; i++) {
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {IsNumber = false;}
	}
	if (IsNumber) {
		var nv = sText.split(",");	
		if (nv.length > 2) {IsNumber = false;}
		var np = sText.split(".");	
		if (np.length > 2) {IsNumber = false;}
		var pp = sText.indexOf(".");
		var pv = sText.indexOf(",");
		if ((pp > -1) && (pv >-1) && ((pv < (pp + 4)) || (pv > (pp + 4)) || (pp > pv))) {IsNumber = false;}
	}
	
	return IsNumber;
}

function BOB_anteprimaNewsletter(id) {
	BOB_openBrWindow('newsletter_preview.asp?ID=' + id,'prvwin','resizable=yes,scrollbars=yes,top=0,left=0,width=800,height=700');
}

function BOB_inviaNewsletter(test) {
	if (confirm("ATTENZIONE: verrà spedita l'ultima versione registrata della mailing list. Le modifiche inserite prima di aver premuto il pulsante AGGIORNA verranno cancellate. Sei sicuro di voler spedire questa mail?")) {
		//if (BOB_checkForm('ita')) {
			document.bob_formo.action = "newsletter_send.asp?test=" + test;
			document.bob_formo.submit()
		//}
	}
}
