//alert('validate.js loaded') function IsFilled(sBuffer, sMessage) { if (sBuffer == "") { if (sMessage != "") { alert(sMessage); } return false; } return true; } // Returns true if character c is a letter or digit. function isLetterOrDigit (c) { return (isLetter(c) || isDigit(c)) } // comprova si el camp passat com a parāmetre te un format de data vālid (dd/mm/aaaa) function checkDate(dateField) { if (isWhitespace(dateField.value)) return true; var pieces = dateField.value.split("/"); var date = new Date(Date.parse(pieces[1]+"/"+pieces[0]+"/"+pieces[2])); if (isNaN(date)) { // alert("Format de data no vālid. Ha de ser dd/mm/aaaa."); dateField.value = ""; return false; } var d = date.getDate(); if (d < 10) d = new String("0" + d); var m = date.getMonth()+1; if (m < 10) m = new String("0" + m); if (date.getFullYear() > 1980) { var y = new String(date.getFullYear()); } else { var y = new String(date.getFullYear() + 100); } dateField.value = d + "/" + m + "/" + y; return true; } // Check whether string s is empty. function isEmpty(s) { return ((s == null) || (s.length == 0)) } var defaultEmptyOK = false // whitespace characters var whitespace = " \t\n\r"; // Returns true if string s is empty or // whitespace characters only. function isWhitespace(s) { var i; // Is s empty? if (isEmpty(s)) return true; // Search through string's characters one by one // until we find a non-whitespace character. // When we do, return false; if we don't, return true. for (i = 0; i < s.length; i++) { // Check that current character isn't whitespace. var c = s.charAt(i); if (whitespace.indexOf(c) == -1) return false; } // All characters are whitespace. return true; } // Returns true if character c is a digit // (0 .. 9). function isDigit (c) { return ((c >= "0") && (c <= "9")) } // isInteger (STRING s [, BOOLEAN emptyOK]) // // Returns true if all characters in string s are numbers. // // Accepts non-signed integers only. Does not accept floating // point, exponential notation, etc. // // We don't use parseInt because that would accept a string // with trailing non-numeric characters. // // By default, returns defaultEmptyOK if s is empty. // There is an optional second argument called emptyOK. // emptyOK is used to override for a single function call // the default behavior which is specified globally by // defaultEmptyOK. // If emptyOK is false (or any value other than true), // the function will return false if s is empty. // If emptyOK is true, the function will return true if s is empty. // // EXAMPLE FUNCTION CALL: RESULT: // isInteger ("5") true // isInteger ("") defaultEmptyOK // isInteger ("-5") false // isInteger ("", true) true // isInteger ("", false) false // isInteger ("5", false) true function isInteger (s) { var i; if (isEmpty(s)) if (isInteger.arguments.length == 1) return defaultEmptyOK; else return (isInteger.arguments[1] == true); // Search through string's characters one by one // until we find a non-numeric character. // When we do, return false; if we don't, return true. for (i = 0; i < s.length; i++) { // Check that current character is number. var c = s.charAt(i); if (!isDigit(c)) return false; } // All characters are numbers. return true; } // isSignedInteger (STRING s [, BOOLEAN emptyOK]) // // Returns true if all characters are numbers; // first character is allowed to be + or - as well. // // Does not accept floating point, exponential notation, etc. // // We don't use parseInt because that would accept a string // with trailing non-numeric characters. // // For explanation of optional argument emptyOK, // see comments of function isInteger. // // EXAMPLE FUNCTION CALL: RESULT: // isSignedInteger ("5") true // isSignedInteger ("") defaultEmptyOK // isSignedInteger ("-5") true // isSignedInteger ("+5") true // isSignedInteger ("", false) false // isSignedInteger ("", true) true function isSignedInteger (s) { if (isEmpty(s)) if (isSignedInteger.arguments.length == 1) return defaultEmptyOK; else return (isSignedInteger.arguments[1] == true); else { var startPos = 0; var secondArg = defaultEmptyOK; if (isSignedInteger.arguments.length > 1) secondArg = isSignedInteger.arguments[1]; // skip leading + or - if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") ) startPos = 1; return (isInteger(s.substring(startPos, s.length), secondArg)) } } // isNonnegativeInteger (STRING s [, BOOLEAN emptyOK]) // // Returns true if string s is an integer >= 0. // // For explanation of optional argument emptyOK, // see comments of function isInteger. function isNonnegativeInteger (s) { var secondArg = defaultEmptyOK; if (isNonnegativeInteger.arguments.length > 1) secondArg = isNonnegativeInteger.arguments[1]; // The next line is a bit byzantine. What it means is: // a) s must be a signed integer, AND // b) one of the following must be true: // i) s is empty and we are supposed to return true for // empty strings // ii) this is a number >= 0 return (isSignedInteger(s, secondArg) && ( (isEmpty(s) && secondArg) || (parseInt (s,10) >= 0) ) ); } // isEmail (STRING s [, BOOLEAN emptyOK]) // // Email address must be of form a@b.c -- in other words: // * there must be at least one character before the @ // * there must be at least one character before and after the . // * the characters @ and . are both required // // For explanation of optional argument emptyOK, // see comments of function isInteger. function isEmail (s) { if (isEmpty(s)) if (isEmail.arguments.length == 1) return defaultEmptyOK; else return (isEmail.arguments[1] == true); // is s whitespace? if (isWhitespace(s)) return false; // there must be >= 1 character before @, so we // start looking at character position 1 // (i.e. second character) var i = 1; var sLength = s.length; // look for @ while ((i < sLength) && (s.charAt(i) != "@")) { i++ } if ((i >= sLength) || (s.charAt(i) != "@")) return false; else i += 2; // look for . while ((i < sLength) && (s.charAt(i) != ".")) { i++ } // there must be at least one character after the . if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false; else return true; } // Buscar paraules clau function CrearURL(sPag,sFormul) { var sFrase; var i; var sTemp; var sTemp2; var sOld; var sDif_Cero; sOld=" " sTemp2="" sTemp=eval('document.'+sFormul+'.txtBuscar.value;') if (sTemp!="") { sDif_Cero=false; for (i=0; i