1function dateAdd(startDate, numDays, numMonths, numYears) 2{ 3 cleanDate = new Date(startDate); 4 var returnDate = new Date(cleanDate.getTime()); 5 var yearsToAdd = numYears; 6 7 var month = returnDate.getMonth() + numMonths; 8 if (month > 11) 9 { 10 yearsToAdd = Math.floor((month+1)/12); 11 month -= 12*yearsToAdd; 12 yearsToAdd += numYears; 13 } 14 returnDate.setMonth(month); 15 returnDate.setFullYear(returnDate.getFullYear() + yearsToAdd); 16 returnDate.setTime(returnDate.getTime()+60000*60*24*numDays); 17 18 // Get the month and year 19 var month = returnDate.getMonth() + 1; 20 var year = returnDate.getYear(); 21 22 // Get the day 23 var strTemp = returnDate.toString(); 24 var splitArray = strTemp.split(' '); 25 var day = splitArray[2]; 26 27 // Put together the date in formatted string format 28 var strStringDate = month + '/' + day + '/' + year; 29 30 return strStringDate; 31} 32 33function yearAdd(startDate, numYears) 34{ 35 return DateAdd(startDate, 0, 0, numYears); 36} 37 38function monthAdd(startDate, numMonths) 39{ 40 return DateAdd(startDate, 0, numMonths,0); 41} 42 43function dayAdd(startDate, numDays) 44{ 45 return DateAdd(startDate, numDays, 0, 0); 46} 47 48/* Takes two strings that represents dates, and returns a boolean 49 indicating whether or not the first date is after the second date. */ 50function isFirstDateEarlier(strDelimiter, strFirstDate, strSecondDate) 51{ 52 var month; 53 var day; 54 var year; 55 var splitArray; 56 57 // Get the first date 58 splitArray = strFirstDate.split(strDelimiter); 59 month = splitArray[0]; 60 day = splitArray[1]; 61 year = splitArray[2]; 62 var firstDate = new Date(year, month - 1, day) 63 64 // Get the second date 65 splitArray = strSecondDate.split(strDelimiter); 66 month = splitArray[0]; 67 day = splitArray[1]; 68 year = splitArray[2]; 69 var secondDate = new Date(year, month - 1, day) 70 71 if (firstDate < secondDate) 72 { 73 return true; 74 } 75 else 76 { 77 return false; 78 } 79} 80 81/* Takes two strings that represents dates, and returns a boolean 82 indicating whether or not the first date is after the second date. */ 83function isFirstDateEarlierEuropean(strDelimiter, strFirstDate, strSecondDate) 84{ 85 var month; 86 var day; 87 var year; 88 var splitArray; 89 90 // Get the first date 91 splitArray = strFirstDate.split(strDelimiter); 92 day = splitArray[0]; 93 month = splitArray[1]; 94 year = splitArray[2]; 95 var firstDate = new Date(year, month - 1, day) 96 97 // Get the second date 98 splitArray = strSecondDate.split(strDelimiter); 99 day = splitArray[0]; 100 month = splitArray[1]; 101 year = splitArray[2]; 102 var secondDate = new Date(year, month - 1, day) 103 104 if (firstDate < secondDate) 105 { 106 return true; 107 } 108 else 109 { 110 return false; 111 } 112} 113 114// Trim leading and trailing spaces 115function trim(lstr) 116{ 117 return ltrim(rtrim(stripLineFeed(lstr))); 118} 119 120function stripLineFeed(strText) 121{ 122 var strReturnText = strText; 123 var flgContinue = true; 124 125 // Only check if the string passed in has a length greater than zero 126 if (strReturnText.length > 0) 127 { 128 // Loop as long as the last character is either a line feed or a carriage return 129 while (flgContinue == true) 130 { 131 // If the last character is either a backspace or a line feed, strip it off 132 if (strReturnText.charAt(strReturnText.length - 1) == '\n' || strReturnText.charAt(strReturnText.length - 1) == '\r') 133 { 134 strReturnText = strReturnText.substr(0, strReturnText.length - 1); 135 } 136 else 137 { 138 // If the last character is not a carriage return or line feed, stop looping 139 flgContinue = false; 140 } 141 } 142 } 143 144 return strReturnText; 145} 146 147// This function trims all spaces from the left-hand side of a string. 148function ltrim(lstr) 149{ 150 if (lstr != "") 151 { 152 var strlen, cptr, lpflag, chk; 153 strlen = lstr.length; 154 cptr = 0; 155 lpflag = true; 156 157 do 158 { 159 chk = lstr.charAt(cptr); 160 if (chk != " ") 161 { 162 lpflag = false; 163 } 164 else 165 { 166 if (cptr == strlen) 167 { 168 lpflag = false; 169 } 170 else 171 { 172 cptr++; 173 } 174 } 175 } 176 177 while (lpflag == true) 178 if (cptr > 0) 179 {
180 lstr = lstr.substring(cptr,strlen); 181 } 182 } 183 184 return lstr; 185} 186 187// This function trims all spaces from the right-hand side of a string. 188function rtrim(lstr) 189{ 190 if (lstr != "") 191 { 192 var strlen, cptr, lpflag, chk; 193 strlen = lstr.length; 194 cptr = strlen; 195 lpflag = true; 196 197 do 198 { 199 chk=lstr.charAt(cptr-1); 200 if (chk != " ") 201 { 202 lpflag = false; 203 } 204 else 205 { 206 if (cptr == 0) 207 { 208 lpflag = false; 209 } 210 else 211 { 212 cptr--; 213 } 214 } 215 } 216 217 while (lpflag == true) 218 if (cptr < strlen) 219 { 220 lstr = lstr.substring(0, cptr); 221 } 222 } 223 224 return lstr; 225} 226 227// ****************************************************************** 228// This function accepts a string variable and verifies if it is a 229// proper date or not. It validates format matching mm.dd.yyyy, 230// mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month 231// has the proper number of days, based on which month it is. 232 233// The function returns true if a valid date, false if not. 234// ****************************************************************** 235/* 236function isDate(dateStr) { 237 238 var datePat = /^(\d{1,2})(\/|-|.)(\d{1,2})(\/|-|.)(\d{4})$/; 239 var matchArray = dateStr.match(datePat); // is the format ok? 240 241 if (matchArray == null) { 242 alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy."); 243 return false; 244 } 245
246 month = matchArray[1]; // parse date into variables 247 day = matchArray[3]; 248 year = matchArray[5]; 249 250 if (month < 1 || month > 12) { // check month range 251 alert("Month must be between 1 and 12."); 252 return false; 253 } 254 255 if (day < 1 || day > 31) { 256 alert("Day must be between 1 and 31."); 257 return false; 258 } 259 260 if ((month==4 || month==6 || month==9 || month==11) && day==31) { 261 alert("Month "+month+" doesn't have 31 days!") 262 return false; 263 } 264 265 if (month == 2) { // check for february 29th 266 var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); 267 if (day > 29 || (day==29 && !isleap)) { 268 alert("February " + year + " doesn't have " + day + " days!"); 269 return false; 270 } 271 } 272 return true; // date is valid 273} 274 275*/ 276// ****************************************************************** 277// This function accepts a string variable and verifies if it is a 278// proper European date or not. It validates format matching dd.mm.yyyy, 279// dd-mm-yyyy, or dd/mm/yyyy. Then it checks to make sure the month 280// has the proper number of days, based on which month it is. 281 282// The function returns true if a valid date, false if not. 283// ****************************************************************** 284function isDateEuropean(dateStr) { 285 286 var datePat = /^(\d{1,2})(\/|-|.)(\d{1,2})(\/|-|.)(\d{4})$/; 287 var matchArray = dateStr.match(datePat); // is the format ok? 288 289 if (matchArray == null) { 290 alert("Please enter date as either dd/mm/yyyy or dd-mm-yyyy."); 291 return false; 292 } 293 294 day = matchArray[1]; // parse date into variables
295 month = matchArray[3]; 296 year = matchArray[5]; 297 298 if (month < 1 || month > 12) { // check month range 299 alert("Month must be between 1 and 12."); 300 return false; 301 } 302 303 if (day < 1 || day > 31) { 304 alert("Day must be between 1 and 31."); 305 return false; 306 } 307 308 if ((month==4 || month==6 || month==9 || month==11) && day==31) { 309 alert("Month "+month+" doesn't have 31 days!") 310 return false; 311 } 312 313 if (month == 2) { // check for february 29th 314 var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)); 315 if (day > 29 || (day==29 && !isleap)) { 316 alert("February " + year + " doesn't have " + day + " days!"); 317 return false; 318 } 319 } 320 return true; // date is valid 321} 322 323 324/* Takes two strings that represents numbers, and returns a boolean 325 indicating whether or not the first number is larger than the second number */ 326function isFirstNumberLarger(strFirst, strSecond) 327{ 328 var lngFirst = parseFloat(strFirst); 329 var lngSecond = parseFloat(strSecond); 330 var flgReturnValue = false; 331 332 // If the first number is greater than the second number 333 if (lngFirst > lngSecond) 334 { 335 flgReturnValue = true; 336 } 337 338 return flgReturnValue; 339} 340 341 342/* The isNumeric function validates a string to determine whether or not it contains a numeric value. 343 Parameters: lstr - Contains string value to validate 344 Returns: true/false */ 345function isNumeric(lstr) 346{ 347 lstr = rtrim(lstr); 348 if (lstr != "") 349 { 350 //declare local variables 351 var strlen, curptr, setptr, chk, inloop, decflag, minusflag, iserror; 352 iserror = false; 353 decflag = false; 354 minusflag = false; 355 strlen = lstr.length; 356 curptr = 0; 357 chk; 358 // first check for space - . 359 inloop = true; 360 for (curptr = 0; curptr < strlen; curptr++) 361 { 362 chk = lstr.charAt(curptr); 363 if (chk >= "0" && chk <= "9") 364 { 365 break; 366 } 367 368 if (chk == "-") 369 { 370 minusflag = true; 371 break; 372 } 373 if (chk == ".") 374 { 375 decflag = true; 376 break; 377 } 378 if (chk != " ") 379 { 380 return false; 381 } 382 } 383 384 if (curptr >= strlen-1) 385 { 386 if (decflag || minusflag || chk == " ") 387 { 388 return false; 389 } 390 else 391 { 392 return true; 393 } 394 } 395 setptr = curptr + 1; 396 for (curptr = setptr; curptr < strlen; curptr++) 397 { 398 chk = lstr.charAt(curptr); 399 if (chk < "0" || chk > "9") 400 { 401 if (chk != ".") 402 { 403 return false; 404 } 405 else 406 { 407 if (decflag) 408 { 409 return false; 410 } 411 else 412 { 413 decflag = true; 414 } 415 } 416 } 417 } 418 return true; 419 } 420 return false; 421} 422 423// This routine takes a string parameter and return true/false, indicating whether or not the string represents 424// a valid hex color. The string can optionally have a # sign at the beginning of it. 425function isValidHexColor(strHexColor) 426{ 427 var arrHexValues; 428 var lngStartingPoint; 429 var strChar; 430 var i; 431 var j; 432 var flgValidCharacter; 433 var lngNumberOfCharacters; 434 435 // Initialize a string of all valid characters in a hex string 436 arrHexValues = new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"); 437 438 // The string must be either 6 or 7 characters long, depending on whether the # sign was use 439 if (strHexColor.length != 6 && strHexColor.length != 7) 440 { 441 return false; 442 } 443 444 // If the string is 7 characters long, the first character must be a # sign 445 if (strHexColor.length == 7 && strHexColor.charAt(0) != '#') 446 { 447 return false; 448 } 449 450 // Determine whether to start checking characters with the first or second character, 451 // depending on whether the first character is a pound sign 452 if (strHexColor.length == 7) 453 { 454 lngStartingPoint = 1; 455 lngNumberOfCharacters = 7; 456 } 457 else 458 { 459 lngStartingPoint = 0; 460 lngNumberOfCharacters = 6; 461 } 462 463 // Loop through each character of the string (other than the possible initial # sign), and check 464 // to see whether each character is a valid hex character. If not, return false. 465 for (i = lngStartingPoint; i < lngNumberOfCharacters; i++) 466 { 467 strChar = strHexColor.charAt(i); 468 strChar = strChar.toUpperCase(); 469 flgValidCharacter = false; 470 471 // After extracting the next character in the string, loop through the array of valid 472 // hex values to see if there's a match. 473 for (j = 0; j < arrHexValues.length; j++) 474 { 475 if (strChar == arrHexValues[j]) 476 { 477 flgValidCharacter = true; 478 } 479 } 480 481 // If the current character was not in the list of valid hex characters, the flag will be set to 482 // false. In that case, return false. 483 if (flgValidCharacter == false) 484 { 485 return false; 486 } 487 } 488 489 // At this point, all conditions have been checked, so it must be a valid hex color string. 490 return true; 491} 492 493// This function verifies that an email conforms to RFC 822 email address standard 494function isValidEmailAddress(strEmail) 495{ 496 if (strEmail == null || strEmail == "") 497 { 498 return false; 499 } 500 else 501 { 502 // Patterns 503 var emailPat=/^(.+)@(.+)$/ 504 var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
505 var validChars="\[^\\s" + specialChars + "\]" 506 var quotedUser="(\"[^\"]*\")" 507 var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/ 508 var atom=validChars + '+' 509 var word="(" + atom + "|" + quotedUser + ")" 510 var userPat=new RegExp("^" + word + "(\\." + word + ")*$") 511 var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$") 512 513 var matchArray = strEmail.match(emailPat) 514 if (matchArray == null) 515 { 516 return false; 517 } 518 519 var user = matchArray[1] 520 var domain = matchArray[2] 521 522 // See if "user" is valid 523 if (user.match(userPat) == null) 524 { 525 // user is not valid 526 return false; 527 } 528 529 var IPArray = domain.match(ipDomainPat) 530 if (IPArray!=null) 531 { 532 // this is an IP address 533 for (var i=1;i<=4;i++) 534 { 535 if (IPArray[i]>255) 536 { 537 return false; 538 } 539 } 540 } 541 542 // Domain is symbolic name 543 var domainArray = domain.match(domainPat) 544 if (domainArray == null) 545 { 546 return false; 547 } 548 549 // Now we need to break up the domain to get a count of how many atoms it consists of. 550 var atomPat = new RegExp(atom,"g") 551 var domArr = domain.match(atomPat) 552 var len = domArr.length 553 if (domArr[domArr.length-1].length < 2 || domArr[domArr.length-1].length > 4) 554 { 555 // the address must end in a two, three, or four letter word. 556 return false; 557 } 558 559 // Make sure there's a host name preceding the domain. 560 if (len < 2) 561 { 562 return false; 563 } 564 } 565 566 return true; 567} 568 569function isAlphaNumeric(strText) 570{ 571 // Check each letter to make sure it's a letter or a number 572 for (var i = 0; i < strText.length; i++) 573 { 574 if ((strText.charAt(i) < '0' || strText.charAt(i) > '9') && (strText.charAt(i) < 'a' || strText.charAt(i) > 'z') && (strText.charAt(i) < 'A' || strText.charAt(i) > 'Z')) 575 { 576 return false; 577 } 578 } 579 580 return true; 581} 582 583function isValidIPAddress(strIPAddress) 584{ 585 var VALID_FORMAT = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/; 586 if (VALID_FORMAT.test(strIPAddress)) 587 { 588 var strParts = strIPAddress.split("."); 589 if (parseInt(parseFloat(strParts[0])) == 0) { return false; } 590 for (var i = 0; i < strParts.length; i++) 591 { 592 if (parseInt(parseFloat(strParts[i])) > 255) { return false; } 593 } 594 595 return true; 596 } 597 else 598 { 599 return false; 600 } 601}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.