function clearFL(str) { reg = /^ | $/; while (reg.test(str)) { str = str.replace(reg, ""); } reg = /\'|\"/; while (reg.test(str)) { str = str.replace(reg, "`"); } return str; } function checkFields(elm, txt) { s = ""; err = ""; err1 = ""; f = 0; for (i = 0; i < elm.length; i++) { try { ag = false; el = document.form1[elm[i]]; type = ""; try { type = "" + el.type; } catch (e) { ag = true; } if (ag || (type == "undefined")) { try { type = el[0].type; } catch (e) {} } switch (type) { case "text" : val = (clearFL(el.value) == ""); reg = /\S{26}/; if (reg.test(el.value)) { err1 += txt[i] + "\n" f = el; } break; case "select-one" : val = (el.options[el.selectedIndex].value == 0); break; case "select-multiple" : j = 0; val = true; while ((j < el.options.length) && val) { val = !(el.options[j].selected && (el.options[j].value != 0)); j++; } break; case "checkbox" : j = 0; val = true; while ((j < el.length) && val) { val = !(el[j].checked && (el[j].value != 0)); j++; } break; case "radio" : j = 0; val = true; while ((j < el.length) && val) { val = !(el[j].checked && (el[j].value != 0)); j++; } break; case "textarea" : val = (clearFL(el.value) == ""); reg = /\S{26}/; if (reg.test(el.value)) { err1 += txt[i] + "\n" f = el; } break; } if (val) { err += txt[i] + "\n"; if (f == 0) f = el; } s += elm[i] + " = " + type + "," + typeof elm[i] + "\n"; } catch(e) {} } // alert(s); if (err != "") { alert("Следните полета са задължителни: \n" + err); try { f.focus(); }catch (e){} return false; } if (err1 != "") { alert("Следните полета имат думи по-големи от 25 символа: \n" + err1); f.focus(); return false; } return true; }