var modificato; // 1. checkNull // 2. CtrlCap // 3. CtrlNum // 4. CtrlMail // 5. findObj // 6. disabilita // 7. setDefault // 8. disabilita2 // 9. disabilita3 // 10. disabilitacampo // 11. ctrlFormatoData // 12. lunghezza_x // 13. ctrlDataMinoreUgualeDi // 14. Trim // 15. ctrlFile // 16. ctrlURL // 17. ctrlEmail // 18. my_rollover // 19. get_confirm_on_form // 20. checked // 21. Ritorna indice di un elemento del form // 22. lunghezza_campo: Controlla la lunghezza massima di un Campo // 23. ctrlFormatoDataOra // 24. lunghezza_campo_min: Controlla la lunghezza minima di un Campo // 25. checkNullBlob Controllo Campo Blob obbligatorio // 26. calcHeight Calcola l'altezza di un iframe, 18/02/2019 PB // 26. calcHeight_old Calcola l'altezza di un iframe // 26bis. calcHeight Calcola l'altezza di un iframe con nome iframe parametrizzato // 27. CtrlNum_7_2 (Field, FieldName) controlla un numero con al massimo 7 interi+2 decimali // 28. Controlla che il numero specificato sia un intero // 29. Formattazione numero // 30. CtrlNum_2_1 (Field, FieldName) controlla un numero con al massimo 2 interi+1 decimali // 31. CtrlNum_9_2 (Field, FieldName) controlla un numero con al massimo 9 interi+2 decimali // 31bis. CtrlNum_9_2_s (Field, FieldName) controlla un numero con al massimo 9 interi+2 decimali, con segno // 32. ctrlEmail2 // 33. ctrlDataMaggioreDi // 33. bis ctrlDataMinoreDi // 34. getCheckedValue // 35. CtrlNum_3_2 (Field, FieldName) controlla un numero con al massimo 3 interi+2 decimali // 36. CtrlPercentuale_3_2 controlla validità di percentuale formata da 3 interi e due decimali // 37. fe (fieldName) “form element”. Evita problemi di mancato riferimento durante la copia di una form in un’altra // 38. CtrlCap(Field, Label) Aggiunge un controllo su CAP. Il CAP di uno stato estero è più lungo di 5 cifre // 39. Controlla che l'anno immesso sia compreso tra quello corrente e il 1900 // 40. CtrlInt (Field, FieldName) controlla validità di un numero intero senza virgola o punto // 41. CtrlNum_2_3 (Field, FieldName) controlla un numero con al massimo 2 interi+1 decimali //_______________________________________________________________________________________ //_______________________________________________________________________________________ //_______________________________________________________________________________________ //1. La funzione controlla l'obbligatorietà di un campo // Controlla che nel campo field ci sia un valore. //_______________________________________________________________________________________ function checkNull( field , fieldName) { selected = 0; fieldIsNull = 0; if ( field.type == "text" || field.type == "password" || field.type == "textarea" ) { field.value = trim(field.value); if ( field.value == "" ) fieldIsNull = 1; } else if ( field.type == "select-one" ) { if ( field.selectedIndex <= 0) fieldIsNull = 1; } else if ( field.type == "select-multiple" ) { fieldIsNull = 1; for ( i = 0; i < field.length; i++ ) if ( field.options[i].selected ) fieldIsNull = 0; } else if ( field.type == "undefined" || field.type == "checkbox" || field.type == "radio" ) { fieldIsNull = 1; for ( i = 0; i < field.length; i++ ) if ( field[i].checked ) fieldIsNull = 0; } if ( fieldIsNull ) { if ( typeof fieldName == "undefined" ) alert( " Deve essere impostato." ); else alert("Il campo <" + fieldName + "> deve essere impostato." ); if ( field.type == "text" || field.type == "textarea" || field.type == "password" || field.type == "select-one" || field.type == "select-multiple" ) field.focus(); //field.select(); return false; } return true; } //_______________________________________________________________________________________ // 2. Controlla che il CAP sia di 5 cifre //_______________________________________________________________________________________ function CtrlCap(Field, Label) { var ValidChar = "0123456789"; var OK = true; if (Field.value.length < 5){ alert("Il campo <" + Label + "> deve essere formato da 5 cifre.") Field.focus(); return false; } for (var i = 0; i < Field.value.length; i++) { var ch = Field.value.charAt(i) for (j = 0; j < ValidChar.length; j++) if (ch == ValidChar.charAt(j)) break; if (j == ValidChar.length) { OK = false; break; } } if (!OK) { alert("Il campo <" + Label + "> puo' contenere solo numeri!") Field.focus(); return false; } return true; } //_______________________________________________________________________________________ // 3. Controlla che i valori siano tutte cifre //_______________________________________________________________________________________ function CtrlNum(Field, Label) { var ValidChar = " 0123456789.,"; var OK = true; for (var i = 0; i < Field.value.length; i++) { var ch = Field.value.charAt(i) for (j = 0; j < ValidChar.length; j++) if (ch == ValidChar.charAt(j)) break; if (j == ValidChar.length) { OK = false; break; } } if (!OK) { alert("Il campo <" + Label + "> puo' contenere solo numeri!") Field.focus(); return false; } return true; } //_______________________________________________________________________________________ // 4. Controlla la presenza di @ nella stringa //_______________________________________________________________________________________ function CtrlMail(Field, Label) { if(Trim(Field.value) != "") { if (Field.value.indexOf('@', 0) == -1) { alert("Il campo <" + Label + "> non e' un indirizzo di E-Mail valido!"); Field.focus(); return false; } } return true; } //_______________________________________________________________________________________ // 5. funzione per ritrovare un oggetto mediante il nome indipendentemente dalla sua // posizione nella gerarchia della pagina //_______________________________________________________________________________________ function findObj(theObj, theDoc) { var p, i, foundObj; if(!theDoc) theDoc = document; if( (p = theObj.indexOf("?")) > 0 && parent.frames.length) { theDoc = parent.frames[theObj.substring(p+1)].document; theObj = theObj.substring(0,p); } if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj]; for (i=0; !foundObj && i < theDoc.forms.length; i++) foundObj = theDoc.forms[i][theObj]; for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) foundObj = findObj(theObj,theDoc.layers[i].document); if(!foundObj && document.getElementByName) foundObj = document.getElementByName(theObj); return foundObj; } //_______________________________________________________________________________________ // 6. La funzione disabilita il campo hide1 se l'opzione selezionata nel campo // nameSelect supera il valore MaxOption //_______________________________________________________________________________________ function disabilita(nameSelect, maxOption, hide1) { var obj, obj2Hide1, max; obj = findObj(nameSelect); obj2Hide1 = findObj(hide1); max = maxOption; if ((obj.value)> max){ obj2Hide1.disabled=""; } else{ obj2Hide1.disabled="disabled"; } } //_______________________________________________________________________________________ // 7. La funzione assegna l'unico valore presente, come default // (nameSelect e' una combobox) //_______________________________________________________________________________________ function setDefault(nameSelect) { var obj; obj = findObj(nameSelect); if (obj.length == 2) obj.selectedIndex=1; } //_______________________________________________________________________________________ // 8. La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue //_______________________________________________________________________________________ function disabilita2(field1, RefValue, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; if ((f1.value)== rval){ f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } //_______________________________________________________________________________________ // 9. La funzione disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue (utile per i pulsanti) //_______________________________________________________________________________________ function disabilita3(field1, RefValue, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval= RefValue; if ((f1.value)== rval){ f2.disabled=""; } else{ f2.disabled="disabled"; } } //_______________________________________________________________________________________ // 10. La funzione svuota e disabilita il campo field2 se l'opzione selezionata nel campo // field1 non e' uguale al valore RefValue //_______________________________________________________________________________________ function disabilitacampo(field1, RefValue1, RefValue2, field2) { var f1, rval, f2; f1= findObj(field1); f2= findObj(field2); rval1= RefValue1; rval2= RefValue2; if (((f1.value)== rval1) || ((f1.value)== rval2)){ f2.disabled=""; } else{ f2.value=""; f2.disabled="disabled"; } } //_______________________________________________________________________________________ //11. Verifica il formato di una data, nel senso che controlla: // - la correttezza del formato in termini gg-mm-aaaa // - la correzza dei mesi,giorni e anno // Ritorna true se la data è corretta e significativa, ritorna false altrimenti //_______________________________________________________________________________________ function ctrlFormatoData(Field, Label) { if (Field.value == '') return true; // se la data è obbligatoria sarà chiamata prima la isNull e quindi qui il controllo non va fatto errore = 0; corretta =/^\d?\d[ /.-]\d?\d[ /.-]\d\d\d\d$/.test(Field.value); if (!corretta) { errore = 1; // errore sul formato della data } else { dataInp = Field.value; if (dataInp.charAt(1) == ' ' || dataInp.charAt(1) == '/' || dataInp.charAt(1) == '-' || dataInp.charAt(1) == '.') dataInp = '0' + dataInp if (dataInp.charAt(4) == ' ' || dataInp.charAt(4) == '/' || dataInp.charAt(4) == '-' || dataInp.charAt(4) == '.') dataInp = dataInp.substring(0,3) + '0' + dataInp.substring(3,9) if (dataInp.charAt(2) != dataInp.charAt(5)) errore = 2 else { giorno = dataInp.substring(0, 2) mese = dataInp.substring(3, 5) anno = dataInp.substring(6, 10) if (mese > 0 && mese < 13 && giorno > 0 && giorno < 32) { if (mese == 11 || mese == 4 || mese == 6 || mese == 9) { if (giorno > 30) errore = 2 } if (mese == 2) { //resto = anno % 4; resto = 1; if (((anno % 4 == 0) && (anno % 100 != 0)) || (anno % 400 == 0)) { // se è un anno bisestile imposto resto a zero altrimenti lo lascio a uno resto = 0; } if (resto == 0 && giorno > 29) errore = 2 else { if (resto != 0 && giorno > 28) errore = 2 } } } else errore = 2 } } if (errore!= 0) { if (errore == 1) { msg = "Il valore del campo <"+Label+"> non contiene un formato valido di data.\n"; msg = msg + "Immettere la data nel formato gg-mm-aaaa."; } else { msg = "Il valore del campo <"+Label+"> non contiene una data valida.\nImmettere la data"; msg = msg + " nel formato gg-mm-aaaa."; } alert(msg); Field.focus(); return false; } else { Field.value = dataInp; return true; } } //_______________________________________________________________________________________ // 12. La funzione controlla la lunghezza massima (a_value) per un campo a_field di tipo textarea // e fornisce il messaggio di errore con il nome del campo (a_text) //_______________________________________________________________________________________ function lunghezza_x(a_field, a_value, a_text) { var v_field; v_field= findObj(a_field); if (v_field.value.length>a_value) { alert('La lunghezza del campo <'+a_text+'> supera '+a_value+'.'); v_field.focus(); v_field.select(); return false; } else return true; } //_______________________________________________________________________________________ // 13. Confronto tra date //_______________________________________________________________________________________ function ctrlDataMinoreUgualeDi(Field1, Field2,Label1, Label2) { if ((Field1.value == '') || (Field2.value == '')) return true; dataInp1 = Field1.value dataInp2 = Field2.value giorno1 = dataInp1.substring(0, 2) mese1 = dataInp1.substring(3, 5) anno1 = dataInp1.substring(6, 10) giorno2 = dataInp2.substring(0, 2) mese2 = dataInp2.substring(3, 5) anno2 = dataInp2.substring(6, 10) if (anno1 < anno2) return true; else if (anno1 == anno2) // Anni uguali: controllo sui mesi if (mese1 < mese2) return true; else if (mese1 == mese2) // Anni e mesi uguali: controllo sui giorni if (giorno1 <= giorno2) return true; msg = "La data specificata nel campo <"+ Label1 +"> non puo' essere posteriore a <"+Label2+">"; alert(msg); Field1.focus(); return false; } //_______________________________________________________________________________________ // 14. CONTROLLA CHE IL VALORE IN INPUT SIA DI TIPO STRING // alert('nella funzione'); //_______________________________________________________________________________________ function Trim(StrToTrim) { if (typeof StrToTrim != "string") { return StrToTrim; } // CATTURA IL PRIMO CARATTERE DELLA STRINGA // PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO var StrBlank = StrToTrim.substring(0, 1); // ELIMINA LO SPAZIO VUOTO DALLA PRIMA POSIZIONE DELLA STRINGA //alert('primo while'); while (StrBlank == " ") { StrToTrim = StrToTrim.substring(1, StrToTrim.length); StrBlank = StrToTrim.substring(0, 1); } // CATTURA L'ULTIMO CARATTERE DELLA STRINGA // PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO StrBlank = StrToTrim.substring(StrToTrim.length - 1, StrToTrim.length); // ELIMINA LO SPAZIO VUOTO DALL'ULTIMA POSIZIONE DELLA STRINGA //alert('secondo while'); while (StrBlank == " ") { StrToTrim = StrToTrim.substring(0, StrToTrim.length-1); StrBlank = StrToTrim.substring(StrToTrim.length-1, StrToTrim.length); } // ELIMINA POTENZIALI SPAZI VUOTI MULTIPLI // ALL'INIZIO ED ALLA FINE DI UNA STRINGA //alert('terzo while'); //while (StrToTrim.indexOf("") != -1) //{ //alert('nel terzo while'); //StrToTrim = StrToTrim.substring(0, StrToTrim.indexOf("")); //StrToTrim += StrToTrim.substring(StrToTrim.indexOf("") + 1, StrToTrim.length); //} // RESTITUISCE IL VALORE FINALE SENZA SPAZI VUOTI DI CONTORNO //alert('prima di uscire dalla funzione'); return StrToTrim; } //__________________________________________________________________________________ // 15. Verifica che l'estensione di un file sia ammessa rispetto alla tipologia file // contenuta in TipoFile //_________________________________________________________________________________ function ctrlFile(Field, Label, TipoFile){ var estensioniImmaginiAmmesse = new Array("gif", "jpg", "bmp", "jpeg", "pjpeg","png"); var estensioniVideoAmmesse = new Array("avi", "asf", "wmv", "mpg", "mpeg"); var estensioniAudioAmmesse = new Array("wav", "mp3", "wma", "midi", "au"); var estensioniTestoAmmesse = new Array("doc", "xls", "pps", "ppt", "pdf", "zip","rar", "html", "htm", "rtf", "txt"); //var estensioniTestoAmmesse = new Array("doc", "xls", "ppt", "pdf", "html", "txt", "rar"); if (Field.value == " ") return true; var estensione = Field.value.substring(Field.value.lastIndexOf(".") + 1); estensioneNonAmmessa = true; if (TipoFile == "Immagine") {for ( i = 0 ; i < estensioniImmaginiAmmesse.length ; i++) { if ( estensioniImmaginiAmmesse[i] == estensione.toLowerCase()) { estensioneNonAmmessa = false; break; } } } if (TipoFile == "Audio") {for ( i = 0 ; i < estensioniAudioAmmesse.length ; i++) { if ( estensioniAudioAmmesse[i] == estensione.toLowerCase()) { estensioneNonAmmessa = false; break; } } } if (TipoFile == "Video") {for ( i = 0 ; i < estensioniVideoAmmesse.length ; i++) { if ( estensioniVideoAmmesse[i] == estensione.toLowerCase()) { estensioneNonAmmessa = false; break; } } } if (TipoFile == "Testo") {for ( i = 0 ; i < estensioniTestoAmmesse.length ; i++) { if ( estensioniTestoAmmesse[i] == estensione.toLowerCase()) { estensioneNonAmmessa = false; break; } } } if ( estensioneNonAmmessa ) { alert("Formato file non ammesso per il campo <" + Label +">."); Field.focus(); //Field.select(); return false; } return true; } //__________________________________________________________________________________ // 16. Verifica che un URL sia sintatticamente corretto, // o meglio che almeno inizi con http:// //__________________________________________________________________________________ function ctrlURL(Field, Label){ var url = /\w+:\/\/\w+/; if (!Field.value.match(url)) { alert("Il campo <" + Label + "> non contiene un URL sintatticamente corretto." ); Field.focus(); return false; } return true; } //__________________________________________________________________________________ // 17. Verifica correttezza sintattica indirizzo eMail //__________________________________________________________________________________ function crtlEmail (Field, Label) { /* The following variable tells the rest of the function whether or not to verify that the address ends in a two-letter country or well-known TLD. 1 means check it, 0 means don't. */ Field.value=Trim(Field.value); var checkTLD=1; /* The following is the list of known TLDs that an e-mail address must end with. */ var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/; /* The following pattern is used to check if the entered e-mail address fits the user@domain format. It also is used to separate the username from the domain. */ var emailPat=/^(.+)@(.+)$/; /* The following string represents the pattern for matching all special characters. We don't want to allow special characters in the address. These characters include ( ) < > @ , ; : \ " . [ ] */ var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]"; /* The following string represents the range of characters allowed in a username or domainname. It really states which chars aren't allowed.*/ var validChars="\[^\\s" + specialChars + "\]"; /* The following pattern applies if the "user" is a quoted string (in which case, there are no rules about which characters are allowed and which aren't; anything goes). E.g. "jiminy cricket"@disney.com is a legal e-mail address. */ var quotedUser="(\"[^\"]*\")"; /* The following pattern applies for domains that are IP addresses, rather than symbolic names. E.g. joe@[123.124.233.4] is a legal e-mail address. NOTE: The square brackets are required. */ var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/; /* The following string represents an atom (basically a series of non-special characters.) */ var atom=validChars + '+'; /* The following string represents one word in the typical username. For example, in john.doe@somewhere.com, john and doe are words. Basically, a word is either an atom or quoted string. */ var word="(" + atom + "|" + quotedUser + ")"; // The following pattern describes the structure of the user var userPat=new RegExp("^" + word + "(\\." + word + ")*$"); /* The following pattern describes the structure of a normal symbolic domain, as opposed to ipDomainPat, shown above. */ var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$"); /* Finally, let's start trying to figure out if the supplied address is valid. */ /* Begin with the coarse pattern to simply break up user@domain into different pieces that are easy to analyze. */ var matchArray=Field.value.match(emailPat); if (matchArray==null) { /* Too many/few @'s or something; basically, this address doesn't even fit the general mould of a valid e-mail address. */ alert("Il campo <" + Label + "> contiene un indirizzo di Mail sintatticamente non corretto.(Controllare @ e .)"); Field.focus(); return false; } var user=matchArray[1]; var domain=matchArray[2]; // Start by checking that only basic ASCII characters are in the strings (0-127). for (i=0; i127) { alert("Nel campo <" + Label +"> il nome utente contiene caratteri non validi!"); Field.focus(); return false; } } for (i=0; i127) { alert("Nel campo <" + Label +"> il nome del dominio contiene caratteri non validi!"); Field.focus(); return false; } } // See if "user" is valid if (user.match(userPat)==null) { // user is not valid alert("Nel campo <" + Label +"> il nome utente non sembra essere un nome valido!"); Field.focus(); return false; } /* if the e-mail address is at an IP address (as opposed to a symbolic host name) make sure the IP address is valid. */ var IPArray=domain.match(ipDomainPat); if (IPArray!=null) { // this is an IP address for (var i=1;i<=4;i++) { if (IPArray[i]>255) { alert("Nel campo <" + Label +"> l'indirizzo IP non e' valido!"); Field.focus(); return false; } } return true; } // Domain is symbolic name. Check if it's valid. var atomPat=new RegExp("^" + atom + "$"); var domArr=domain.split("."); var len=domArr.length; for (i=0;i il nome del dominio sembra non essere valido!"); Field.focus(); return false; } } /* domain name seems valid, but now make sure that it ends in a known top-level domain (like com, edu, gov) or a two-letter word, representing country (uk, nl), and that there's a hostname preceding the domain or country. */ if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) { alert("L'indirizzo del campo <" + Label +"> deve terminare con un dominio conosciuto (o con le due lettere della Nazione)!"); Field.focus(); return false; } // Make sure there's a host name preceding the domain. if (len<2) { alert("Nel campo <" + Label +"> manca il nome dell'host!"); Field.focus(); return false; } // If we've gotten this far, everything's valid! return true; } //__________________________________________________________________________________ // 18. Visualizza il rollover su la riga 'idRiga' //__________________________________________________________________________________ // function my_rollover(idGif,idRiga) { eval('document.punto'+idRiga+'.src="/apulie/img/remark'+idGif+'.gif"'); } //__________________________________________________________________________________ // 19. Visualizza messaggio di conferma su richiesta cancellazione Record (FORM) //__________________________________________________________________________________ function get_confirm_on_form(messaggio) { return confirm(messaggio); } //__________________________________________________________________________________ // 20. Ritorna la stringa corrispondente ai campi checked in una check box // fm: nome form // parVal: conterrà la stringa valore // p_qty: indice del checkbox //_______________________________________________________________________________ function checked(fm,p_qty) { var i; var stringa; for (i=0;i<=(fm.length - 1);i++) { if (fm.elements[i].name) { if (!fm.elements[i].name.lastIndexOf(p_qty)) { if (fm.elements[i].checked) stringa +=fm.elements[i].value+","; } } } return stringa; } //__________________________________________________________________________________ // 21. Ritorna indice di un elemento del form //_______________________________________________________________________________ function get_index(p_name) { var i; for (i=1; ia_value) { alert('La lunghezza del campo <'+a_text+'> supera '+a_value+' caratteri.'); a_field.focus(); a_field.select(); return false; } else return true; } //_______________________________________________________________________________________ //23. Verifica il formato di una data/ora, nel senso che controlla: // - la correttezza del formato in termini gg-mm-aaaa hh:mi // - la correzza dei mesi, giorni, anno, ore e minuti // Ritorna true se la data/ora è corretta e significativa, ritorna false altrimenti //_______________________________________________________________________________________ function ctrlFormatoDataOra(Field, Label) { if (Field.value == '') return true; // se la data è obbligatoria sarà chiamata prima la isNull e quindi qui il controllo non va fatto errore = 0; corretta =/^\d\d[ /.-]\d\d[ /.-]\d\d\d\d[ /.-](\d{2})([ /.-:])(\d{2})([ap]m)?$/.test(Field.value); if (!corretta) { errore = 1; // errore sul formato della data } else { dataInp = Field.value; if (dataInp.charAt(1) == ' ' || dataInp.charAt(1) == '/' || dataInp.charAt(1) == '-' || dataInp.charAt(1) == '.') dataInp = '0' + dataInp if (dataInp.charAt(4) == ' ' || dataInp.charAt(4) == '/' || dataInp.charAt(4) == '-' || dataInp.charAt(4) == '.') dataInp = dataInp.substring(0,3) + '0' + dataInp.substring(3,9) if (dataInp.charAt(2) != dataInp.charAt(5)) errore = 2 else { giorno = dataInp.substring(0, 2) mese = dataInp.substring(3, 5) anno = dataInp.substring(6, 10) if (anno <= 1000) { errore = 3 } if (errore == 0 && mese > 0 && mese < 13 && giorno > 0 && giorno < 32) { if (mese == 11 || mese == 4 || mese == 6 || mese == 9) { if (giorno > 30) errore = 2 } if (mese == 2) { //resto = anno % 4; resto = 1; if (((anno % 4 == 0) && (anno % 100 != 0)) || (anno % 400 == 0)) { // se è un anno bisestile imposto resto a zero altrimenti lo lascio a uno resto = 0; } if (resto == 0 && giorno > 29) errore = 2 else { if (resto != 0 && giorno > 28) errore = 2 } } } else { if (errore == 0) errore = 2 } } } if (errore!= 0) { if (errore == 1) { msg = "Il valore del campo <"+Label+"> non contiene un formato valido di data.\n"; msg = msg + "Immettere la data nel formato gg-mm-aaaa hh:mi."; } else if (errore == 3) { msg = "Il valore di anno nel campo <"+Label+"> non e' valido.\n"; } else { msg = "Il valore del campo <"+Label+"> non contiene una data valida.\nImmettere la data"; msg = msg + " nel formato gg-mm-aaaa hh:mi."; } alert(msg); Field.focus(); return false; } else { //*** INIZIO Controllo orario *** dataInput = Field.value; orario = dataInput.substring(11); errore = 0; //alert(orario); // regular expression to match required time format re = /^(\d{1,2})([ /.-:])(\d{1,2})([ap]m)?$/; if (orario != '') { if (regs = orario.match(re)) { // 24-hour time format if (regs[1] > 23) { errore = 1; } if (regs[3] > 59) { errore = 2; } } else { errore = 3; } } if (errore > 0) { if (errore == 1) { msg = "Il valore delle ore nel campo <"+Label+"> non e' valido.\n"; msg = msg + "Immettere il valore orario nel formato hh:mi."; } if (errore == 2) { msg = "Il valore dei minuti nel campo <"+Label+"> non e' valido.\n"; msg = msg + "Immettere il valore orario nel formato hh:mi."; } if (errore == 3) { msg = "Il valore del campo <"+Label+"> non contiene un orario valido.\n"; msg = msg + "Immettere il valore orario nel formato hh:mi."; } alert(msg); Field.focus(); return false; } //*** FINE Controllo orario *** return true; } } //_______________________________________________________________________________________ // 24. La funzione controlla la lunghezza minima (a_value) per un campo a_field di tipo textarea // e fornisce il messaggio di errore con il nome del campo (a_text) //_______________________________________________________________________________________ function lunghezza_campo_min(a_field, a_value, a_text) { if (a_field.value.length minore di '+a_value+' caratteri.'); a_field.focus(); a_field.select(); return false; } else return true; } //_______________________________________________________________________________________ //25. La funzione controlla l'obbligatorietà di un campo BLOB // Controlla che nel campo field ci sia un valore. //_______________________________________________________________________________________ function checkNullBlob( field , fieldName) { if ( field.value == "" ) { alert("Il campo <" + fieldName + "> deve essere impostato." ); return false; } return true; } //_______________________________________________________________________________________ //26. La funzione calcola l'altezza di un iframe (FrameCentrale) // //_______________________________________________________________________________________ function calcHeight() { //find the height of the internal page var the_height = document.getElementById('FrameCentrale').contentWindow.document.body.scrollHeight; //change the height of the iframe if ( Math.round(the_height*1.1) < 3000) {document.getElementById('FrameCentrale').height=3000;} else {document.getElementById('FrameCentrale').height=document.getElementById('FrameCentrale').contentWindow.document.body.offsetHeight + 'px';} } function calcHeight_old() { //find the height of the internal page var the_height = document.getElementById('FrameCentrale').contentWindow. document.body.scrollHeight; //change the height of the iframe document.getElementById('FrameCentrale').height=Math.round(the_height*1.1); } //_______________________________________________________________________________________ //26bis. La funzione calcola l'altezza di un iframe (a_iframe) // //_______________________________________________________________________________________ function calcHeight2(a_iframe) { //find the height of the internal page var the_height= document.getElementById(a_iframe).contentWindow. document.body.scrollHeight; //change the height of the iframe document.getElementById(a_iframe).height=Math.round(the_height*1.1); } //_______________________________________________________________________________________ //27. La funzione controlla validità di un numero con al massimo 7 interi+2 decimali //_______________________________________________________________________________________ function CtrlNum_7_2 (Field, FieldName) { s = Field.value; if (s.length > 12) {alert("Il campo <" + FieldName + "> contiene un numero di caratteri superiore al massimo consentito."); Field.focus(); Field.select(); return false;} if (Field.value.search(/\+/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '+'."); Field.focus(); Field.select(); return false; } if (Field.value.search(/\-/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '-'."); Field.focus(); Field.select(); return false; } if (!isNaN(s)) {if (parseFloat(s) > Number("9999999.99")) {alert("Il campo <" + FieldName + "> contiene un valore maggiore di 9.999.999,99."); Field.focus(); Field.select(); return false;} else {return true;} } if (s.match(/^[0-9](\.)?(\d{1,3})?(\.)?(\d{1,3})?(\,\d{1,2})?$/)) {return true;} else {alert("Il campo <" + FieldName + "> non numerico o non nel formato corretto (7 interi + 2 decimali)."); Field.focus(); Field.select(); return false;} } //_______________________________________________________________________________________ // 28. La funzione controlla validità di un numero intero (non segnato) //_______________________________________________________________________________________ function CtrlNum_Int(Field, Label) { if (Field.value.search(/\+/) != -1) {alert("Il campo <" + Label + "> non puo' contenere il carattere '+'."); Field.focus(); Field.select(); return false; } if (Field.value.search(/\-/) != -1) {alert("Il campo <" + Label + "> non puo' contenere il carattere '-'."); Field.focus(); Field.select(); return false; } var s = parseInt(Field.value, "10"); if (isNaN(s)) {alert("Il campo <" + Label + "> puo' contenere solo numeri interi."); Field.focus(); Field.select(); return false;} else {return true;} } //_______________________________________________________________________________________ // 29. Formattazione numero //_______________________________________________________________________________________ function Formatta_Numero(Field) { var str = Field.value + ''; x = str.split(','); x1 = x[0]; x2 = x.length > 1 ? ',' + x[1] : ''; var rgx = /(\d+)(\d{3})/; while (rgx.test(x1)) x1 = x1.replace(rgx, '$1' + '.' + '$2'); return x1 + x2; } //_______________________________________________________________________________________ //30. La funzione controlla validità di un numero con al massimo 2 interi+1 decimali //_______________________________________________________________________________________ function CtrlNum_2_1 (Field, FieldName) { s = Field.value; if (s.length > 4) {alert("Il campo <" + FieldName + "> contiene un numero di caratteri superiore al massimo consentito."); Field.focus(); Field.select(); return false;} if (Field.value.search(/\+/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '+'."); Field.focus(); Field.select(); return false; } if (Field.value.search(/\-/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '-'."); Field.focus(); Field.select(); return false; } if (!isNaN(s)) {if (parseFloat(s) > Number("99.9")) {alert("Il campo <" + FieldName + "> contiene un valore maggiore di 99,9."); Field.focus(); Field.select(); return false;} else {return true;} } if (s.match(/^(\d{1,2})?(\,\d{1,1})?$/)) {return true;} else {alert("Il campo <" + FieldName + "> non numerico o non nel formato corretto (2 interi + 1 decimale)."); Field.focus(); Field.select(); return false;} } //_______________________________________________________________________________________ //31. La funzione controlla validità di un numero con al massimo 9 interi+2 decimali //_______________________________________________________________________________________ function CtrlNum_9_2 (Field, FieldName) { s = Field.value; if (s.length > 14) {alert("Il campo <" + FieldName + "> contiene un numero di caratteri superiore al massimo consentito."); Field.focus(); Field.select(); return false;} if (Field.value.search(/\+/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '+'."); Field.focus(); Field.select(); return false; } if (Field.value.search(/\-/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '-'."); Field.focus(); Field.select(); return false; } if (!isNaN(s)) {if (parseFloat(s) > Number("999999999.99")) {alert("Il campo <" + FieldName + "> contiene un valore maggiore di 999.999.999,99."); Field.focus(); Field.select(); return false;} else {return true;} } if (s.match(/^(\d{1,3})(\.)?(\d{1,3})?(\.)?(\d{1,3})?(\,\d{1,2})?$/)) {return true;} else {alert("Il campo <" + FieldName + "> non numerico o non nel formato corretto (9 interi + 2 decimali)."); Field.focus(); Field.select(); return false;} } //_______________________________________________________________________________________ //31bis. La funzione controlla validità di un numero con al massimo 9 interi+2 decimali, con segno //_______________________________________________________________________________________ function CtrlNum_9_2_s (Field, FieldName) { v = ""; s = ""; if (Field.value.count < 2) { s = Field.value; } else { v = Field.value.substring(0, 1); if (v == "-") { s = Field.value.substring(1); } else { s = Field.value; } } if (s.length > 14) {alert("Il campo <" + FieldName + "> contiene un numero di caratteri superiore al massimo consentito."); Field.focus(); Field.select(); return false;} if (s.search(/\+/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '+'."); Field.focus(); Field.select(); return false; } if (s.search(/\-/) != -1) {alert("Il campo <" + FieldName + "> puo' contenere il carattere '-' solo all'inizio."); Field.focus(); Field.select(); return false; } if (!isNaN(s)) {if ( parseFloat(s) > Number("999999999.99")) {alert("Il campo <" + FieldName + "> contiene un valore maggiore di 999.999.999,99 o minore di -999.999.999,99"); Field.focus(); Field.select(); return false;} else {return true;} } if (s.match(/^(\d{1,3})(\.)?(\d{1,3})?(\.)?(\d{1,3})?(\,\d{1,2})?$/)) {return true;} else {alert("Il campo <" + FieldName + "> non numerico o non nel formato corretto (9 interi + 2 decimali)."); Field.focus(); Field.select(); return false;} } //___________________________________________ //32. Controllo sitattico indirizzo mail //___________________________________________ function ctrlEmail2(Field, Label) { stringa = Field.value; Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/; if (Filtro.test(stringa)) return true; else { alert("Il campo <" + Label + "> contiene un indirizzo di Mail sintatticamente non corretto."); Field.select(); Field.focus(); return false; } } //_______________________________________________________________________________________ // 33. Confronto tra date //_______________________________________________________________________________________ function ctrlDataMaggioreDi(Field1, Field2,Label1, Label2) { if ((Field1.value == '') || (Field2.value == '')) return true; dataInp1 = Field1.value dataInp2 = Field2.value giorno1 = dataInp1.substring(0, 2) mese1 = dataInp1.substring(3, 5) anno1 = dataInp1.substring(6, 10) giorno2 = dataInp2.substring(0, 2) mese2 = dataInp2.substring(3, 5) anno2 = dataInp2.substring(6, 10) if (anno1 > anno2) return true; else if (anno1 == anno2) // Anni uguali: controllo sui mesi if (mese1 > mese2) return true; else if (mese1 == mese2) // Anni e mesi uguali: controllo sui giorni if (giorno1 > giorno2) return true; msg = "<"+ Label1 +"> deve contenere una data posteriore a <"+Label2+">"; alert(msg); Field1.select(); Field1.focus(); return false; } //_______________________________________________________________________________________ // 33. bis Confronto tra date //_______________________________________________________________________________________ function ctrlDataMinoreDi(Field1, Field2,Label1, Label2) { if ((Field1.value == '') || (Field2.value == '')) return true; dataInp1 = Field1.value dataInp2 = Field2.value giorno1 = dataInp1.substring(0, 2) mese1 = dataInp1.substring(3, 5) anno1 = dataInp1.substring(6, 10) giorno2 = dataInp2.substring(0, 2) mese2 = dataInp2.substring(3, 5) anno2 = dataInp2.substring(6, 10) if (anno1 < anno2) return true; else if (anno1 == anno2) // Anni uguali: controllo sui mesi if (mese1 < mese2) return true; else if (mese1 == mese2) // Anni e mesi uguali: controllo sui giorni if (giorno1 < giorno2) return true; msg = "<"+ Label1 +"> deve essere antecedente a <"+Label2+">"; alert(msg); Field1.select(); Field1.focus(); return false; } //_______________________________________________________________________________________ // 34. return the value of the radio button that is checked // return an empty string if none are checked, or // there are no radio buttons //_______________________________________________________________________________________ function getCheckedValue(radioObj) { if(!radioObj) return ""; var radioLength = radioObj.length; if(radioLength == undefined) if(radioObj.checked) return radioObj.value; else return ""; for(var i = 0; i < radioLength; i++) { if(radioObj[i].checked) { return radioObj[i].value; } } return ""; } // function trim(stringa){ while (stringa.substring(0,1) == ' '){ stringa = stringa.substring(1, stringa.length); } while (stringa.substring(stringa.length-1, stringa.length) == ' ') { stringa = stringa.substring(0,stringa.length-1); } return stringa; } //_______________________________________________________________________________________ //35. La funzione controlla validità di un numero con al massimo 3 interi+2 decimali senza + - e . //_______________________________________________________________________________________ function CtrlNum_3_2 (Field, FieldName) { s = Field.value; if (s.length > 6) {alert("Il campo <" + FieldName + "> contiene un numero di caratteri superiore al massimo consentito."); Field.focus(); Field.select(); return false;} if (Field.value.search(/\+/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '+'"); Field.focus(); Field.select(); return false; } if (Field.value.search(/\-/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '-'"); Field.focus(); Field.select(); return false; } if (Field.value.search(/\./) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '.'"); Field.focus(); Field.select(); return false; } if (!isNaN(s)) {if (parseFloat(s) > Number("999.99")) {alert("Il campo <" + FieldName + "> contiene un valore maggiore di 999,99."); Field.focus(); Field.select(); return false;} else {return true;} } if (s.match(/^(\d{1,3})?(\,\d{1,2})?$/)) {return true;} else {alert("Il campo <" + FieldName + "> non numerico o non nel formato corretto (3 interi + 2 decimali)."); Field.focus(); Field.select(); return false;} } //_______________________________________________________________________________________ //36. La funzione controlla validità di una percentuale formata da 3 numeri interi e da due decimali //_______________________________________________________________________________________ function CtrlPercentuale_3_2 (Field, FieldName) { s = Field.value; if (s.length > 6) {alert("Il campo <" + FieldName + "> contiene un numero di caratteri superiore al massimo consentito."); Field.focus(); Field.select(); return false;} if (Field.value.search(/\+/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '+'."); Field.focus(); Field.select(); return false; } if (Field.value.search(/\-/) != -1) {alert("Il campo <" + FieldName + "> non puo' contenere il carattere '-'."); Field.focus(); Field.select(); return false; } if (!isNaN(s)) v = s.replace(",","."); {if (parseFloat(v) > Number("100.00")) {alert("Il campo <" + FieldName + "> contiene un valore maggiore di 100,00."); Field.focus(); Field.select(); return false;} else {return true;} } if (s.match(/^(\d{1,3})?(\,\d{1,2})?$/)) {return true;} else {alert("Il campo <" + FieldName + "> non numerico o non nel formato corretto (3 interi + 2 decimali separati da una virgola)."); Field.focus(); Field.select(); return false;} } //_______________________________________________________________________________________ //37. “fe” è acronimo di “form element”. Utilizza gli elementi di una form, // a partire dal nome della stessa. Evita problemi di mancato riferimento durante la copia di una form in un’altra. //_______________________________________________________________________________________ function fe (fieldName) { return document.forms[0].elements[document.title+".DEFAULT."+fieldName+".01"]; } //_______________________________________________________________________________________ //38. Aggiunge un controllo di lunghezza del CAP esattamente a 5 cifre. //Il CAP di uno stato estero è più lungo di 5 cifre, pertanto non si può imporre, a livello di form, una restrizione sulla lunghezza //_______________________________________________________________________________________ function CtrlCap(Field, Label) { var ValidChar = "0123456789"; var OK = true; if (Field.value.length != 5) { alert("Il campo <" + Label + "> deve essere formato esattamente da 5 cifre.") Field.focus(); return false; } for (var i = 0; i < Field.value.length; i++) { var ch = Field.value.charAt(i) for (j = 0; j < ValidChar.length; j++) if (ch == ValidChar.charAt(j)) break; if (j == ValidChar.length) { OK = false; break; } } if (!OK) { alert("Il campo <" + Label + "> puo' contenere solo numeri!") Field.focus(); return false; } return true; } //_______________________________________________________________________________________ // 39. Controlla che l'anno immesso sia compreso tra quello corrente e il 1900 //_______________________________________________________________________________________ function CtrlAnno(Field, Label) { var ValidChar = " 0123456789.,"; var OK = true; var data_corrente = new Date(); anno_corrente = data_corrente.getFullYear(); for (var i = 0; i < Field.value.length; i++) { var ch = Field.value.charAt(i) for (j = 0; j < ValidChar.length; j++) if (ch == ValidChar.charAt(j)) break; if (j == ValidChar.length) { OK = false; break; } } if (!OK) { alert("Il campo <" + Label + "> puo' contenere solo numeri!") Field.focus(); return false; } if (Field.value>anno_corrente || Field.value<1900) { alert("Il campo <" + Label + "> contiente un valore non valido!") Field.focus(); return false; } return true; } //_______________________________________________________________________________________ // 40. La funzione controlla validità di un numero intero senza virgola o punto //_______________________________________________________________________________________ function CtrlInt(Field, Label) { if (Field.value.search(/\+/) != -1) {alert("Il campo <" + Label + "> non puo' contenere il carattere '+'."); Field.focus(); Field.select(); return false; } if (Field.value.search(/\-/) != -1) {alert("Il campo <" + Label + "> non puo' contenere il carattere '-'."); Field.focus(); Field.select(); return false; } if (isNaN(Field.value) || Field.value % 1!=0) {alert("Il campo <" + Label + "> puo' contenere solo numeri interi."); Field.focus(); Field.select(); return false;} else {return true;} } //__________________________________________________________ //41. Codice per resize iframe //__________________________________________________________ document.addEventListener('DOMContentLoaded', function() { parent.postMessage({ width: document.documentElement.scrollWidth, height: document.documentElement.scrollHeight }, '*'); }, false);