function TextLenIsCorrect(minlen, sText){ var leOfText = sText.length; minlen=minlen+1; if (leOfText == 0){ return true; } if (leOfText < minlen){ return false; } return true; } function isbnCorrect(field) { var isbn = field.value; var lunghezza = isbn.length; var checkisbn; if(lunghezza == 0 || isbn == "") return true; // test input --- checkisbn = isbn.substr((lunghezza - 1),1); if (isNaN(checkisbn)) { isbn = isbn.substr(0,(lunghezza - 1)) + "0"; lunghezza = isbn.length; } if ((lunghezza == 9) && (isbn.indexOf("-") == 4)) { isbn = isbn.substr(0,4) + isbn.substr(5,4); lunghezza = isbn.length; } if ((lunghezza == 8) && (isbn.indexOf("-") == 4)) { isbn = isbn.substr(0,4) + isbn.substr(5,3); lunghezza = isbn.length; } if ((lunghezza == 10) && (isbn.substr(0,2) == "88") && (isbn.indexOf("-") == (-1))) { isbn = isbn.substr(2,8); lunghezza = isbn.length; } // Fine test input --- if((!isNaN(isbn))&&(lunghezza>6)&&(lunghezza <=8)&&(isbn.indexOf("-") == (-1))) { if (lunghezza==7) { isbn=isbn+"0"; } var isbn1 = String(""); var isbn2 = String(""); isbn1 = isbn.substr(0,4); isbn2 = isbn.substr(4,4); isbn = isbn1+"-"+isbn2; field.value = isbn; return true; } if(lunghezza == 9) { if(isbn.indexOf("-") != 7) { return false; } else { var isbn1 = String(""); var isbn2 = String(""); isbn1 = isbn.substr(0,7); isbn2 = isbn.substr(8,8); var temp = isbn1+isbn2; if (!isNaN(temp)) { isbn1 = isbn.substr(0,4); isbn2 = isbn.substr(4,3)+isbn.substr(8,1); isbn = isbn1+"-"+isbn2; field.value = isbn; return true; } else { return false; } } } if((lunghezza == 10)&&(isbn.indexOf("-",0)==4)&&(isbn.indexOf("-",5)==8)) { var isbn1 = String(""); var isbn2 = String(""); var isbn3 = String(""); isbn1 = isbn.substr(0,4); isbn2 = isbn.substr(5,3); isbn3 = isbn.substr(9,1); isbn = isbn1+isbn2+isbn3; if (!isNaN(isbn)) { isbn = isbn1+"-"+isbn2+isbn3; field.value = isbn; return true; } } return false; } function chkForm() { //elenco dei campi del form di ricerca avanzata nel catalogo var autore=$('rcrccognome'); var titolo=$('rcrctitolo'); var collana=$('rcrccod_collana'); var tipo=$('rcrctipocontrib'); var contrib=$('rcrccognomecontrib'); var genere=$('rcrcmateria'); var isbn=$('rcrcisbn'); var temp=''; //elimino eventuali spazi ad inizio e fine autore.value = StripSpaces(autore.value); titolo.value = StripSpaces(titolo.value); //temp = StripSpaces(collana.value); tipo.value = StripSpaces(tipo.value); //contrib.value = StripSpaces(contrib.value); //genere.value = StripSpaces(genere.value); isbn.value = StripSpaces(isbn.value); var blank_var = " "; var tmp_var = "" var error=new Array(); if (!TextLenIsCorrect(1,autore.value)) { error=error.concat("Field author not valid."); } if (!TextLenIsCorrect(1,titolo.value)){ error=error.concat("Field title not valid."); } if (!TextLenIsCorrect(1,contrib.value)){ error=error.concat("Field contributor not valid."); } if (tipo.value) { if (contrib.value == "") { error=error.concat("Insert a contributor's surname."); } } if (!isbnCorrect(isbn)){ error=error.concat("Field isbn not valid."); } if ((tipo.value == "")&&(contrib.value == "")&&(genere.value == "")&&(isbn.value == "")&&(autore.value == "")&&(titolo.value == "")&&(collana.value == "")) { error=error.concat("At least one parameter required."); } // evitiamo lanci indesiderati tmp_var= autore.value; if (tmp_var.indexOf(blank_var) != -1) { error=error.concat("Field author not valid."); } tmp_var= titolo.value; if (tmp_var.indexOf(blank_var) != -1) { error=error.concat("Field title not valid."); } tmp_var= contrib.value; if (tmp_var.indexOf(blank_var) != -1) { error=error.concat("Field contributor not valid."); } if (error.length > 0) { var html=""; for(j=0; j < error.length; j++) { html+=error[j]+"
"; } $('search_frm_error').innerHTML=html; $('search_frm_error').display=''; return false; } // -- return true; } function StripSpaces(s) { while((s.indexOf(' ',0) == 0) && (s.length > 1)) { s = s.substring(1,s.length); } while((s.lastIndexOf(' ') == (s.length - 1) && (s.length > 1))) { s = s.substring(0,(s.length - 1)); } if((s.indexOf(' ',0) == 0) && (s.length == 1)) s = ''; return s; } function azzera() { self.location = "ricerca.jsp"; }