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); } while (retValue.indexOf(" ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string retValue = retValue.substring(0, retValue.indexOf(" ")) + retValue.substring(retValue.indexOf(" ")+1, retValue.length); // Again, there are two spaces in each of the strings } return retValue; // Return the trimmed string back to the user } // Ends the "trim" function function replace(inputString, fromString, toString) { // Goes through the inputString and replaces every occurrence of fromString with toString inputString = trim(inputString); fromString = trim(fromString); toString = trim(toString); var temp = inputString; if (fromString == "") { return temp; } if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation) while (temp.indexOf(fromString) != -1) { var toTheLeft = temp.substring(0, temp.indexOf(fromString)); var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length); temp = toTheLeft + toString + toTheRight; } } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop var midStrings = new Array("~", "`", "_", "^", "#"); var midStringLen = 1; var midString = ""; // Find a string that doesn't exist in the inputString to be used // as an "inbetween" string while (midString == "") { for (var i=0; i < midStrings.length; i++) { var tempMidString = ""; for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; } if (fromString.indexOf(tempMidString) == -1) { midString = tempMidString; i = midStrings.length + 1; } } } // Keep on going until we build an "inbetween" string that doesn't exist // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string while (temp.indexOf(fromString) != -1) { var toTheLeft = temp.substring(0, temp.indexOf(fromString)); var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length); temp = toTheLeft + midString + toTheRight; } // Next, replace the "inbetween" string with the "toString" while (temp.indexOf(midString) != -1) { var toTheLeft = temp.substring(0, temp.indexOf(midString)); var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length); temp = toTheLeft + toString + toTheRight; } } // Ends the check to see if the string being replaced is part of the replacement string or not return temp; // Send the updated string back to the user } // Ends the "replaceSubstring" function function isValidChar(str,par_invalidChars){ var invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;"; var ok = true; if (par_invalidChars != "") { invalidChars = par_invalidChars } for (i=0; i -1) { ok = false } } return ok; } function isEmail(email) { invalidChars = " ~\'^\`\"*+=\\|][(){}$&!#%/:,;"; email = emailStr = trim(email); // Check for null if (email == "") { return false; } // Check for invalid characters as defined above for (i=0; i -1) { return false; } } lengthOfEmail = email.length; if ((email.charAt(lengthOfEmail - 1) == ".") || (email.charAt(lengthOfEmail - 2) == ".")) { return false; } Pos = email.indexOf("@",1); if (email.charAt(Pos + 1) == ".") { return false; } while ((Pos < lengthOfEmail) && ( Pos != -1)) { Pos = email.indexOf(".",Pos); if (email.charAt(Pos + 1) == ".") { return false; } if (Pos != -1) { Pos++; } } // There must be at least one @ symbol atPos = email.indexOf("@",1); if (atPos == -1) { return false; } // But only ONE @ symbol if (email.indexOf("@",atPos+1) != -1) { return false; } // Also check for at least one period after the @ symbol periodPos = email.indexOf(".",atPos); if (periodPos == -1) { return false; } if (periodPos+3 > email.length) { return false; } return true; } function CheckVeld(Veld, Language) { var bOk = true;; var Veldwaarde = Veld.value; var Veldnaam = Veld.id var Verplicht = Veldnaam.substring(Veldnaam.length - 2, Veldnaam.length -1) var Actie = Veldnaam.substring(Veldnaam.length - 1, Veldnaam.length) Veldnaam = Veldnaam.substring(0, Veldnaam.length - 2) var melding; var meldingleeg = "Veld mag niet leeg blijven"; var meldingnumeric = "Veld dient numerieke waarde te hebben"; var meldingemail = "Geen geldig emailadres"; var meldingalgemeen = "Geef geldige waarde voor '"; if (Language.toUpperCase() == 'EN') { meldingleeg = "Field should not be empty"; meldingnumeric = "Field should have a numeric value"; meldingemail = "No valid emailadress"; var meldingalgemeen = "Give valid value for '"; } if (Verplicht == 1 && Veldwaarde == "") { bOk = false; melding = meldingleeg; } else { if (Actie==1) { if (Number(Veldwaarde) != Veldwaarde) { bOk = false; melding = meldingnumeric; } } else if (Actie==2) { if (!isEmail(Veldwaarde)) { bOk = false; melding = meldingemail; } } } if (bOk == false) { alert (meldingalgemeen + Veldnaam + "'\n" + melding); Veld.focus(); } return bOk; } function CheckAndSubmit(language) { var controls = document.getElementsByTagName("input"); var bOk = true; for (var i = 0; i < controls.length; i++) { var control = controls.item(i); if(!CheckVeld(control,language)) { bOk = false; i = controls.length + 1; } } if (bOk) { controls = document.getElementsByTagName("textarea"); for (var i = 0; i < controls.length; i++) { var control = controls.item(i); if(!CheckVeld(control,language)) { bOk = false; i = controls.length + 1; } } } if (bOk) { window.document.all.frmMail.submit(); } }