fork download
  1. function validateText(sender)
  2. {
  3. if (sender.id.indexOf("MyValidator3") != -1)
  4. {
  5.  
  6. var oTextBox = document.getElementById(sender.attributes['controltovalidate'].value)
  7. //start with checking at the beginning of the string. you can have any words that start with an S but do not end in 'cript' followed by a < or : or >. you cannot have a < or >
  8. var oRegExp = /^(?:[^s^S^<^>]|[sS](?![Cc][Rr][Ii][Pp][Tt]\s*[<:>]))*$/ ;
  9. //test the expression.
  10. if (oTextBox != null && oRegExp.test(oTextBox.value)==false)
  11. {
  12. //here, the text has bad code, but we can only wipe the text out if we hit the cancel button, otherwise, we need to leave the validation error text for the user
  13. if (btnCancelHasFocus == true|| btnDeleteHasFocus == true)
  14. oTextBox.value = '';
  15. //return false for the rest of the validation process to work with it
  16. return false;
  17. }
  18. else
  19. {
  20. //now we need to check for the &# combination
  21. if (oTextBox != null )
  22. {
  23. var text = oTextBox.value;
  24. // Scrub Xml ensures that each character is W3C compliant.
  25. // This is a major performance hit. . .
  26. // #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
  27.  
  28. var validText;
  29. //-- If there are no special chars just return the original (99%)
  30. oRegExp = /[^\w\.@-]/;
  31. if (text != "" && oRegExp.test(oTextBox.value)== true)
  32. {
  33. for ( i = 0; i < text.length; i++)
  34. {
  35. c = text.substr(i, 1);
  36. var charInt = text.charCodeAt(i);
  37. if (charInt == 9 || charInt == 10 || charInt == 13 || (charInt >= 32 && charInt <= 55295) || (charInt >= 57344 && charInt <= 65533) || (charInt >= 65536 && charInt <= 1114111))
  38. {}
  39. else
  40. {
  41. validText = false;
  42. break;
  43. }
  44. }
  45. }
  46. else
  47. {
  48. validText = true;
  49. }
  50. if (text.search(/&#/) > -1 || validText == false)
  51. {
  52. if (btnCancelHasFocus == true|| btnDeleteHasFocus == true)
  53. oTextBox.value = '';
  54. //return false for the rest of the validation process to work with it
  55. return false;
  56. }
  57. else
  58. return true;
  59. }
  60. else
  61. return true;
  62.  
  63. }
  64. }
  65. else
  66. return true;
  67. }
  68.  
  69.  
  70. function validatePerformanceReviewComments(sender)
  71. {
  72. var isValid = true;
  73. /*this function validates 3 things...
  74. 1. script attacks
  75. 2. &# entries
  76. 3. text length of 1024***
  77. */
  78.  
  79. var oTextBox = document.all(sender.attributes['controltovalidate'].value);
  80. if (oTextBox != null)
  81. {
  82. var text = oTextBox.value;
  83.  
  84. //first check
  85. //start with checking at the beginning of the string. you can have any words that start with an S but do not end in 'cript' followed by a < or : or >. you cannot have a < or >
  86. var oRegExp = /^(?:[^s^S^<^>]|[sS](?![Cc][Rr][Ii][Pp][Tt]\s*[<:>]))*$/ ;
  87. if (oRegExp.test(oTextBox.value)==false)
  88. {
  89. //here, the text has bad code, but we can only wipe the text out if we hit the cancel button, otherwise, we need to leave the validation error text for the user
  90. if (btnCancelHasFocus == true|| btnDeleteHasFocus == true)
  91. oTextBox.value = '';
  92. isValid = false;
  93. }
  94.  
  95. //second check
  96. if (isValid == true)
  97. {
  98. //now we need to check for the &# combination
  99. if (text.search(/&#/) > -1)
  100. {
  101. if (btnCancelHasFocus == true|| btnDeleteHasFocus == true)
  102. oTextBox.value = '';
  103. isValid = false;
  104. }
  105. }
  106.  
  107. //third check
  108. if (isValid == true)
  109. {
  110. //now we need to check for the the length of the data
  111. if (text.length > 7000)
  112. {
  113. isValid = false;
  114. }
  115. }
  116. }
  117. return isValid
  118.  
  119. }
  120. function formatDate(oTextBox)
  121. {
  122. // Dates entered with periods as the delimiter (mm.dd.yy) pass the .Net date validator but aren't valid in the JScript Date object
  123. var dateEntered = oTextBox.value.replace(/\./g, "-");
  124. dateEntered = dateEntered.replace(/\-/g, "/"); // Convert dashes to slashes
  125. var yearEntered = dateEntered.split("/")[2];
  126. dateEntered = new Date(dateEntered)
  127. if (dateEntered.toDateString() != "NaN")
  128. {
  129. // If the year is entered as two digits and the calculated date is more than 80 years old, add 100 years to it
  130. var calculatedDate = new Date((dateEntered.getMonth() + 1) + "/" + dateEntered.getDate() + "/" + dateEntered.getFullYear());
  131. if (yearEntered.length == 2 && (new Date().getFullYear() - calculatedDate.getFullYear()) > 80)
  132. calculatedDate = new Date((dateEntered.getMonth() + 1) + "/" + dateEntered.getDate() + "/" + (dateEntered.getFullYear() + 100));
  133. oTextBox.value = (calculatedDate.getMonth() + 1) + "/" + calculatedDate.getDate() + "/" + calculatedDate.getFullYear();
  134. }
  135. }
  136.  
  137. function formatTime(sender)
  138. {
  139. var ctrlName;
  140. if (sender.id.indexOf("MyValidator1") == -1)
  141. {
  142. ctrlName = sender.id.replace("MyValidator2","TextBox1");
  143. }
  144. else
  145. {
  146. ctrlName = sender.id.replace("MyValidator1","TextBox1");
  147. }
  148. var ctrl = document.getElementById(ctrlName)
  149.  
  150. var arSpans = document.getElementsByTagName("span");
  151.  
  152. for (i=0;i<arSpans.length;i++)
  153. { // Find the MyValidator1 associated with oTextBox so we can shut off its display
  154. if (arSpans[i].controltovalidate == ctrl.id && arSpans[i].id.match(/MyValidator/gi))
  155. {
  156. var oValidator = arSpans[i];
  157. i = arSpans.length;
  158. }
  159. }
  160. var oValidator = sender
  161.  
  162. // Most of this code is copied from iVantage TimeInput.htc, so the behavior should be much the same...
  163. var text = ctrl.value;
  164. if (text == null || text == "")
  165. text = "";
  166. else
  167. {
  168. if (oValidator.attributes['pm_override'].value == "True")
  169. {
  170. text = text.trim()
  171. /*
  172. if the last character is a number then we add the 'pm', otherwise we do nothing
  173. becasue the user has given us the 'am' or 'pm'
  174.  
  175. if the entire text is numeric the we check for hours > 12
  176. if it is not then there is a ':' and we need to see if the characters to the left
  177. are > 12
  178. if either condition then we do NOT add PM
  179.  
  180. Also, if the time starts with 0 (05 for 24 hour time for example) then we add nothing to it
  181. */
  182. if (isDigit(text.substr(text.length - 1 ,1)))
  183. {
  184. if (isNaN(text))
  185. {
  186. pos = text.search(/:/i)
  187. if (text.substr(0,pos) <= 12 && text.substr(0,1) != 0)
  188. text += "pm"
  189. }
  190. else
  191. {
  192. if (parseInt(text) <= 12)
  193. text += "pm"
  194. }
  195. }
  196. text = text.trim() + "X"; // X is an end of input marker for the loop.
  197. }
  198. else
  199. {
  200. text = text.trim() + "X"; // X is an end of input marker for the loop.
  201. }
  202. }
  203. // Parse the time.
  204. var c = "", lastc, i;
  205. var h = null, m = null, s = null, ms = null, num = null;
  206. var hack = false;
  207.  
  208. if (text.substr(0, 1) == "0")
  209. {
  210. // We need a hack for 3 or 4 digit times that begin with 0 (i.e. 12 am).
  211. // Given the input 013 or 0013, our algorithm will interpret
  212. // it as 13--that is, 1 pm. What we do is change the 0
  213. // to a 1 (giving 113 or 1013) and then change it back.
  214. if (isDigit(text.substr(1, 1)) && isDigit(text.substr(2, 1)))
  215. {
  216. hack = true;
  217. text = "1" + text.substr(1);
  218. }
  219. }
  220.  
  221. for (i = 0; i < text.length; i++)
  222. {
  223. lastc = c;
  224. c = text.substr(i, 1);
  225. if (isDigit(c))
  226. {
  227. // Digit.
  228. if (num == null)
  229. num = parseInt(c);
  230. else if (num < 10000)
  231. num = num * 10 + parseInt(c);
  232. else
  233. break;
  234. }
  235. else
  236. {
  237. // Move num into h/m/s/ms.
  238. if (h == null)
  239. {
  240. if (num == null) break;
  241. if (num < 100)
  242. h = num;
  243. else
  244. {
  245. h = Math.floor(num / 100);
  246. m = num % 100;
  247. }
  248. num = null;
  249. if (h > 23 || m > 59) break;
  250. }
  251. else if (m == null)
  252. {
  253. if (num == null) break;
  254. if (num < 60) m = num;
  255. else break;
  256. num = null;
  257. }
  258. else if (s == null)
  259. {
  260. if (num == null) break;
  261. if (num < 60) s = num;
  262. else break;
  263. num = null;
  264. }
  265. else if (ms == null)
  266. {
  267. if (num == null) break;
  268. if (num < 1000) ms = num;
  269. else break;
  270. num = null;
  271. }
  272. else if (num != null)
  273. break;
  274.  
  275. if (c == ":")
  276. {
  277. // Preceding character must be digit and s must not be populated.
  278. if (!isDigit(lastc) || s != null) break;
  279. }
  280. else if (c == ".")
  281. {
  282. // ms separator. Preceding character must be a digit.
  283. if (!isDigit(lastc) || s == null || ms != null) break;
  284. }
  285. else if (c == " ")
  286. {
  287. // AM/PM separator. Preceding character must be a digit or space.
  288. if ((lastc != " " && !isDigit(lastc)) || h == null) break;
  289. if (m == null) m = 0;
  290. if (s == null) s = 0;
  291. if (ms == null) ms = 0;
  292. }
  293. else if (c == "a" || c == "A")
  294. {
  295. // Preceding character must be digit or space or period.
  296. if ((lastc != " " && lastc != "." && !isDigit(lastc)) || h == null || h > 12) break;
  297. if (h == 12) h = 0;
  298. if (m == null) m = 0;
  299. if (s == null) s = 0;
  300. if (ms == null) ms = 0;
  301. }
  302. else if (c == "p" || c == "P")
  303. {
  304. // Preceding character must be digit or space or period.
  305. if ((lastc != " " && lastc != "." && !isDigit(lastc)) || h == null || h == 0 || h > 12) break;
  306. if (h < 12) h += 12; // Convert to 24-hour format.
  307. if (m == null) m = 0;
  308. if (s == null) s = 0;
  309. if (ms == null) ms = 0;
  310. }
  311. else if (c == "m" || c == "M")
  312. {
  313. // Preceding character must be "a" or "p".
  314. if (lastc != "a" && lastc != "A" && lastc != "p" && lastc != "P") break;
  315. }
  316. else if (c == "X" && i == text.length - 1) { } // End of input.
  317. else break;
  318. }
  319. }
  320. if (i < text.length)
  321. {
  322. if (oValidator.style.display == 'None')
  323. {
  324. ctrl.style.color= "red"
  325. ctrl.style.fontWeight="bold";
  326. ctrl.title = "Invalid time";
  327. }
  328. return false;
  329. }
  330. else
  331. {
  332. if (oValidator.style.display == 'None')
  333. {
  334. ctrl.style.color= ""
  335. ctrl.style.fontWeight="";
  336. ctrl.title = "";
  337. }
  338.  
  339. if (text.length > 0)
  340. {
  341. if (hack && h == 1) h = 0;
  342. else if (hack && h == 10) h = 0;
  343. var time = new Date(1900, 0, 1, h, m, 0, 0); // drop secs and millisecs
  344. //this code is fired twice, some user settings have shown that the setting of the time
  345. //makes the second firing interpret the modified time as something else, we need to stop that second setting
  346. if (getCookieData("timeCookie") != '1') {
  347. setCookieData("timeCookie", '1');
  348. ctrl.value = time.toLocaleTimeString().replace(":00 "," "); //drop secs.
  349. } else {
  350. setCookieData("timeCookie", '0');
  351. }
  352. }
  353. return true;
  354. }
  355. }
  356.  
  357. function isDigit(c)
  358. {
  359. return (c >= "0" && c <= "9");
  360. }
  361.  
  362. function formatNumber(oTextBox, DecimalPlaces)
  363. {
  364. DecimalPlaces = parseInt(DecimalPlaces);
  365. var amount = oTextBox.value;
  366. if (amount != "")
  367. {
  368. amount -= 0;
  369. var scale= Math.pow(10,DecimalPlaces);
  370. if (! isNaN(amount))
  371. {
  372. amount = (Math.round(amount*scale))/scale + (1/scale/100) ;
  373. var sAmount = amount.toString();
  374. if (DecimalPlaces == 0)
  375. oTextBox.value = sAmount.substr(0,sAmount.indexOf('.') + DecimalPlaces);
  376. else
  377. oTextBox.value = sAmount.substr(0,sAmount.indexOf('.') + DecimalPlaces + 1);
  378. }
  379. }
  380. }
  381. function toggleNextRowDisplay(oImage,CourseCode)
  382. {
  383. if (event.srcElement.tagName.toLowerCase() == 'td')
  384. oImage = event.srcElement.firstChild;
  385. var sContractImageName = "contract.gif";
  386. var sExpandImageName = "expand.gif";
  387. var sImagePath = oImage.src.substring(0, oImage.src.lastIndexOf("/"));
  388. var sImageName = oImage.src.substr(oImage.src.lastIndexOf("/")+1);
  389. if (oImage.parentElement.parentElement.parentElement.parentElement.nextSibling.nextSibling.style.display=="none")
  390. {
  391. oImage.parentElement.parentElement.parentElement.parentElement.nextSibling.nextSibling.style.display = "";
  392. oImage.src = sImagePath + "/contract.gif";
  393. oImage.title = "Hide Details";
  394. oImage.parentElement.parentElement.parentElement.parentElement.nextSibling.firstChild.style.display = "none";
  395. }
  396. else
  397. {
  398. oImage.parentElement.parentElement.parentElement.parentElement.nextSibling.nextSibling.style.display = "none";
  399. oImage.src = sImagePath + "/expand.gif";
  400. oImage.title = "Show Details";
  401. oImage.parentElement.parentElement.parentElement.parentElement.nextSibling.firstChild.style.display = "";
  402.  
  403. }
  404. }
  405.  
  406. function getCookieData(name)
  407. {
  408. name = name.replace(/\=/g, "_");
  409. // alert("Getting cookie: " + name);
  410. var start = document.cookie.indexOf(name+"=");
  411. var len = start+name.length+1;
  412. if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
  413. if (start == -1) return null;
  414. var end = document.cookie.indexOf(";",len);
  415. if (end == -1) end = document.cookie.length;
  416. // alert("Cookie: " + unescape(document.cookie.substring(len,end)));
  417. return unescape(document.cookie.substring(len,end));
  418. }
  419.  
  420. function setCookieData(name, value, expires, path, domain, secure)
  421. {
  422. name = name.replace(/\=/g, "_");
  423. // alert("Setting cookie " + name + " to " + value);
  424. document.cookie = name + "=" +escape(value) +
  425. ( (expires) ? ";expires=" + expires.toGMTString() : "") +
  426. ( (path) ? ";path=" + path : "") +
  427. ( (domain) ? ";domain=" + domain : "") +
  428. ( (secure) ? ";secure" : "");
  429. }
  430.  
  431. String.prototype.trim = function () {
  432. return this.replace(/\s*/, '').replace(/\s*$/, '');
  433. }
  434.  
  435. String.prototype.escape = function () { return window.escape(this); }
  436.  
  437. String.prototype.unescape = function() { return window.unescape(this); }
  438.  
  439. function ShowHelp(appRoot, helpFileName)
  440. {
  441. window.open(appRoot + "/Help/" + helpFileName, 'Connect', 'menubar=no, toolbar=no, scrollbars=yes, resizable=yes');
  442. }
  443.  
  444. function DisplayCalendar(controlName)
  445. {
  446. var arSpans = document.getElementsByTagName("span");
  447.  
  448. for (i=0;i<arSpans.length;i++)
  449. { // Find any validators associated with controlName and hide them
  450. if (arSpans[i].controltovalidate == controlName && arSpans[i].id.match(/.*Validator/gi))
  451. {
  452. arSpans[i].style.display="none";
  453. }
  454. }
  455.  
  456. var windowOptions = 'height=180,width=235,left=200,top=150'
  457. var textBox = document.forms[0].elements[controlName]
  458.  
  459. var controlDate = new Date(textBox.value).toDateString();
  460. var TestControlDate = new Date(controlDate)
  461. if (TestControlDate.toDateString() == "NaN" || controlDate == "" || controlDate == "Invalid Date") {
  462. controlDate = "";
  463. textBox.value = "";
  464. }
  465.  
  466. var url = getPathRoot() + '/Common/ivDataEntryCalendar.aspx?ControlDate=' + controlDate + '&FormName=' + document.forms[0].name + '&ControlName=' + controlName;
  467. var DateWindow=window.open(url,'ivDataEntryDate',windowOptions);
  468. DateWindow.focus();
  469. }
  470.  
  471. function getPathRoot()
  472. {
  473. var s = location.pathname;
  474. if (s.substr(0, 1) != "/") s = "/" + s;
  475. var nPos = s.indexOf("/", 1);
  476. return (s.substr(0, nPos));
  477. }
  478.  
  479. function displayMessage(header,msg,code)
  480. {
  481. var windowOptions = 'height=450,width=450,left=200,top=150,resizable=yes,scrollbars=yes'
  482. var url = getPathRoot() + '/Common/ivDataEntryMessage.aspx?Header=' + header + '&Message=' + msg + '&Code=' + code;
  483. var MessageWindow=window.open(url,'Message',windowOptions);
  484. MessageWindow.focus();
  485. }
  486.  
  487. function formatAjaxDate(sender)
  488. {
  489. // Calls AJAX process to format date
  490. var dDateVal;
  491. var ctrlName;
  492. if (sender.id.indexOf("MyValidator1") == -1)
  493. {
  494. ctrlName = sender.id.replace("MyValidator2","TextBox1");
  495. }
  496. else
  497. {
  498. ctrlName = sender.id.replace("MyValidator1","TextBox1");
  499. }
  500. var ctrl = document.getElementById(ctrlName)
  501. if (ctrl.value == "")
  502. {
  503. return true
  504. }
  505.  
  506. var arSpans = document.getElementsByTagName("span");
  507. for (i=0;i<arSpans.length;i++)
  508. { // Find the DateExpressionValidator associated with TextBox so we can shut off its display if necessary
  509. if (arSpans[i].controltovalidate == ctrl.id && arSpans[i].id.match(/MyValidator/gi))
  510. {
  511. var oValidator = arSpans[i];
  512. i = arSpans.length;
  513. }
  514. }
  515. var oValidator = sender
  516. dDateVal = runAJAXProcess("/Common/AjaxFunctions.aspx?Func=FormatDate&sDate=" + ctrl.value)
  517. if (dDateVal != "INVALID")
  518. {
  519. ctrl.value = dDateVal;
  520.  
  521. if (oValidator.style.display == 'None')
  522. {
  523. ctrl.style.color = ""
  524. ctrl.style.fontWeight = "";
  525. ctrl.title = "";
  526. }
  527. return true;
  528. }
  529. else
  530. {
  531. if (oValidator.style.display == 'None')
  532. {
  533. ctrl.style.color = "red"
  534. ctrl.style.fontWeight = "bold";
  535. ctrl.title = "Invalid date";
  536. }
  537. return false;
  538. }
  539. }
  540.  
  541. function runAJAXProcess(url)
  542. {
  543. g_req = createXMLHTTPConduit();
  544. var url = getPathRoot() + url;
  545. if(g_req != null)
  546. {
  547. g_req.open("GET", url, false); // 'false' means call it synchronously -- wait for the ASP page to finish
  548. g_req.send(null);
  549. if (g_req.status == 200)
  550. {
  551. return g_req.responseText;
  552. }
  553. else if (g_req.status == 500)
  554. {
  555. // Internal Server Error -- show entire contents of error in a pop-up
  556. var errorText = "<span style='font-family: arial; font-size: x-small; font-weight: bold;'>Error encountered by runAJAXProcess<br><span style='font-size: small'>" + url + "</span></span><br><br>"
  557. errorText += g_req.responseText;
  558. var errorWin;
  559. // Create a new window and display the error
  560. errorWin = window.open('', 'errorWin');
  561. errorWin.document.body.innerHTML = errorText;
  562. errorWin.focus();
  563. }
  564. }
  565. }
  566.  
  567. function createXMLHTTPConduit()
  568. {
  569. //This function creates an XMLHTTP object to be used in AJAX-type operations
  570. var oXMLHTTP;
  571. try
  572. {
  573. oXMLHTTP = new ActiveXObject("Msxml2.XMLHTTP");
  574. }
  575. catch(e)
  576. {
  577. try
  578. {
  579. oXMLHTTP = new ActiveXObject("Microsoft.XMLHTTP");
  580. }
  581. catch(oc)
  582. {
  583. oXMLHTTP = null;
  584. }
  585. }
  586.  
  587. if(!oXMLHTTP && typeof XMLHttpRequest != "undefined")
  588. {
  589. oXMLHTTP = new XMLHttpRequest();
  590. }
  591. return oXMLHTTP;
  592. }
Success #stdin #stdout 0.37s 213888KB
stdin
Standard input is empty
stdout
Standard output is empty