PageRenderTime 60ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/jssource/src_files/include/javascript/sugar_3.js

https://github.com/BarnetikKoop/SuiteCRM
JavaScript | 5060 lines | 4047 code | 498 blank | 515 comment | 1317 complexity | 69577f9e441f2729ec6387e2843ecb88 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. /*********************************************************************************
  2. * SugarCRM Community Edition is a customer relationship management program developed by
  3. * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
  4. * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
  5. * Copyright (C) 2011 - 2014 Salesagility Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU Affero General Public License version 3 as published by the
  9. * Free Software Foundation with the addition of the following permission added
  10. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  11. * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
  12. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  17. * details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License along with
  20. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  21. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  22. * 02110-1301 USA.
  23. *
  24. * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
  25. * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
  26. *
  27. * The interactive user interfaces in modified source and object code versions
  28. * of this program must display Appropriate Legal Notices, as required under
  29. * Section 5 of the GNU Affero General Public License version 3.
  30. *
  31. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  32. * these Appropriate Legal Notices must retain the display of the "Powered by
  33. * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
  34. * reasonably feasible for technical reasons, the Appropriate Legal Notices must
  35. * display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
  36. ********************************************************************************/
  37. /**
  38. * Namespace for Sugar Objects
  39. */
  40. if (typeof(SUGAR) == "undefined") {
  41. SUGAR = {
  42. /**
  43. * Creates a namespace if it doesn't exist and then returns it.
  44. *
  45. * Note: this implementation only creates a top-level namespace. Extend this function if
  46. * multi-level namespaces are needed.
  47. * @param ns
  48. */
  49. namespace: function(ns) {
  50. SUGAR[ns] = SUGAR[ns] || {};
  51. return ((typeof SUGAR[ns] === "object") && (SUGAR[ns] !== null)) ? SUGAR[ns] : false;
  52. },
  53. /**
  54. * Add properties of an object to target object.
  55. * @param target
  56. * @param obj
  57. */
  58. append: function(target, obj) {
  59. for (var prop in obj) {
  60. if (obj[prop] !== void 0) target[prop] = obj[prop];
  61. }
  62. return target;
  63. }
  64. };
  65. }
  66. // Namespaces
  67. SUGAR.namespace("themes");
  68. SUGAR.namespace("tour");
  69. /**
  70. * Namespace for Homepage
  71. */
  72. SUGAR.namespace("sugarHome");
  73. /**
  74. * Namespace for Subpanel Utils
  75. */
  76. SUGAR.namespace("subpanelUtils");
  77. /**
  78. * AJAX status class
  79. */
  80. SUGAR.namespace("ajaxStatusClass");
  81. /**
  82. * Tab selector utils
  83. */
  84. SUGAR.namespace("tabChooser");
  85. /**
  86. * General namespace for Sugar utils
  87. */
  88. SUGAR.namespace("utils");
  89. SUGAR.namespace("savedViews");
  90. /**
  91. * Dashlet utils
  92. */
  93. SUGAR.namespace("dashlets");
  94. SUGAR.namespace("unifiedSearchAdvanced");
  95. SUGAR.namespace("searchForm");
  96. SUGAR.namespace("language");
  97. SUGAR.namespace("Studio");
  98. SUGAR.namespace("contextMenu");
  99. SUGAR.namespace("config");
  100. var nameIndex = 0;
  101. var typeIndex = 1;
  102. var requiredIndex = 2;
  103. var msgIndex = 3;
  104. var jstypeIndex = 5;
  105. var minIndex = 10;
  106. var maxIndex = 11;
  107. var altMsgIndex = 15;
  108. var compareToIndex = 7;
  109. var arrIndex = 12;
  110. var operatorIndex = 13;
  111. var callbackIndex = 16;
  112. var allowblank = 8;
  113. var validate = new Array();
  114. var maxHours = 24;
  115. var requiredTxt = 'Missing Required Field:';
  116. var invalidTxt = 'Invalid Value:';
  117. var secondsSinceLoad = 0;
  118. var alertsTimeoutId;
  119. var inputsWithErrors = new Array();
  120. var tabsWithErrors = new Array();
  121. var lastSubmitTime = 0;
  122. var alertList = new Array();
  123. var oldStartsWith = '';
  124. /**
  125. * @deprecated
  126. *
  127. * As of Sugar version 6.2.3 (MSIE Version 9) this function is deprecated. The preferred method is to use the
  128. * user agent check supplied by YUI to check for IE:
  129. *
  130. * for checking if a browser is IE in general : if(YAHOO.env.ua.ie) {...}
  131. *
  132. * or for checking specific versions: if (YAHOO.env.ua.ie >= 5.5 && YAHOO.env.ua.ie < 9) {...}
  133. *
  134. */
  135. function isSupportedIE() {
  136. var userAgent = navigator.userAgent.toLowerCase() ;
  137. // IE Check supports ActiveX controls
  138. if (userAgent.indexOf("msie") != -1 && userAgent.indexOf("mac") == -1 && userAgent.indexOf("opera") == -1) {
  139. var version = navigator.appVersion.match(/MSIE (\d+\.\d+)/)[1] ;
  140. if(version >= 5.5 && version < 10) {
  141. return true;
  142. } else {
  143. return false;
  144. }
  145. }
  146. }
  147. function checkMinSupported(c, s) {
  148. var current = c.split(".");
  149. var supported = s.split(".");
  150. for (var i in supported) {
  151. if (current[i] && parseInt(current[i]) > parseInt(supported[i])) return true;
  152. else if (current[i] && parseInt(current[i]) < parseInt(supported[i])) return false;
  153. }
  154. return true;
  155. }
  156. function checkMaxSupported(c, s) {
  157. var current = c.split(".");
  158. var supported = s.split(".");
  159. for (var i in supported) {
  160. if (current[i] && parseInt(current[i]) > parseInt(supported[i])) return false;
  161. else if (current[i] && parseInt(current[i]) < parseInt(supported[i])) return true;
  162. }
  163. return true;
  164. }
  165. SUGAR.isSupportedBrowser = function(){
  166. var supportedBrowsers = {
  167. msie : {min:9, max:11}, // IE 9, 11
  168. safari : {min:534}, // Safari 5.1
  169. mozilla : {min:23.0}, // Firefox 23.0
  170. chrome : {min:29} // Chrome 29
  171. };
  172. var current = String($.browser.version);
  173. var supported;
  174. if ($.browser.msie || (!(window.ActiveXObject) && "ActiveXObject" in window)){ // Internet Explorer
  175. supported = supportedBrowsers['msie'];
  176. }
  177. else if ($.browser.mozilla) { // Firefox
  178. supported = supportedBrowsers['mozilla'];
  179. }
  180. else {
  181. $.browser.chrome = /chrome/.test(navigator.userAgent.toLowerCase());
  182. if($.browser.chrome){ // Chrome
  183. current = navigator.userAgent.match(/Chrome\/(.*?) /)[1];
  184. supported = supportedBrowsers['chrome'];
  185. }
  186. else if($.browser.safari){ // Safari
  187. supported = supportedBrowsers['safari'];
  188. }
  189. }
  190. if (current && supported)
  191. return checkMinSupported(current, String(supported.min)) && (!supported.max || checkMaxSupported(current, String(supported.max)));
  192. else
  193. return false;
  194. }
  195. SUGAR.isIECompatibilityMode = function(){
  196. var agentStr = navigator.userAgent;
  197. var mode = false;
  198. if (agentStr.indexOf("MSIE 7.0") > -1 &&
  199. (agentStr.indexOf("Trident/5.0") > -1 || // IE9 Compatibility View
  200. agentStr.indexOf("Trident/4.0") > -1 // IE8 Compatibility View
  201. )
  202. )
  203. {
  204. mode = true;
  205. }
  206. return mode;
  207. }
  208. SUGAR.isIE = isSupportedIE();
  209. var isSafari = (navigator.userAgent.toLowerCase().indexOf('safari')!=-1);
  210. // escapes regular expression characters
  211. RegExp.escape = function(text) { // http://simon.incutio.com/archive/2006/01/20/escape
  212. if (!arguments.callee.sRE) {
  213. var specials = ['/', '.', '*', '+', '?', '|','(', ')', '[', ']', '{', '}', '\\'];
  214. arguments.callee.sRE = new RegExp('(\\' + specials.join('|\\') + ')', 'g');
  215. }
  216. return text.replace(arguments.callee.sRE, '\\$1');
  217. }
  218. function addAlert(type, name,subtitle, description,time, redirect) {
  219. var addIndex = alertList.length;
  220. alertList[addIndex]= new Array();
  221. alertList[addIndex]['name'] = name;
  222. alertList[addIndex]['type'] = type;
  223. alertList[addIndex]['subtitle'] = subtitle;
  224. alertList[addIndex]['description'] = replaceHTMLChars(description.replace(/<br>/gi, "\n"));
  225. alertList[addIndex]['time'] = time;
  226. alertList[addIndex]['done'] = 0;
  227. alertList[addIndex]['redirect'] = redirect;
  228. }
  229. function checkAlerts() {
  230. secondsSinceLoad += 1;
  231. var mj = 0;
  232. var alertmsg = '';
  233. for(mj = 0 ; mj < alertList.length; mj++) {
  234. if(alertList[mj]['done'] == 0) {
  235. if(alertList[mj]['time'] < secondsSinceLoad && alertList[mj]['time'] > -1 ) {
  236. alertmsg = alertList[mj]['type'] + ":" + alertList[mj]['name'] + "\n" +alertList[mj]['subtitle']+ "\n"+ alertList[mj]['description'] + "\n\n";
  237. alertList[mj]['done'] = 1;
  238. if(alertList[mj]['redirect'] == '') {
  239. alert(alertmsg);
  240. }
  241. else if(confirm(alertmsg)) {
  242. window.location = alertList[mj]['redirect'];
  243. }
  244. }
  245. }
  246. }
  247. alertsTimeoutId = setTimeout("checkAlerts()", 1000);
  248. }
  249. function toggleDisplay(id) {
  250. if(this.document.getElementById(id).style.display == 'none') {
  251. this.document.getElementById(id).style.display = '';
  252. if(this.document.getElementById(id+"link") != undefined) {
  253. this.document.getElementById(id+"link").style.display = 'none';
  254. }
  255. if(this.document.getElementById(id+"_anchor") != undefined)
  256. this.document.getElementById(id+"_anchor").innerHTML='[ - ]';
  257. }
  258. else {
  259. this.document.getElementById(id).style.display = 'none';
  260. if(this.document.getElementById(id+"link") != undefined) {
  261. this.document.getElementById(id+"link").style.display = '';
  262. }
  263. if(this.document.getElementById(id+"_anchor") != undefined)
  264. this.document.getElementById(id+"_anchor").innerHTML='[+]';
  265. }
  266. }
  267. function checkAll(form, field, value) {
  268. for (i = 0; i < form.elements.length; i++) {
  269. if(form.elements[i].name == field)
  270. form.elements[i].checked = value;
  271. }
  272. }
  273. function replaceAll(text, src, rep) {
  274. offset = text.toLowerCase().indexOf(src.toLowerCase());
  275. while(offset != -1) {
  276. text = text.substring(0, offset) + rep + text.substring(offset + src.length ,text.length);
  277. offset = text.indexOf( src, offset + rep.length + 1);
  278. }
  279. return text;
  280. }
  281. function addForm(formname) {
  282. validate[formname] = new Array();
  283. }
  284. function addToValidate(formname, name, type, required, msg) {
  285. if(typeof validate[formname] == 'undefined') {
  286. addForm(formname);
  287. }
  288. validate[formname][validate[formname].length] = new Array(name, type,required, msg);
  289. }
  290. // Bug #47961 Callback validator definition
  291. function addToValidateCallback(formname, name, type, required, msg, callback)
  292. {
  293. addToValidate(formname, name, type, required, msg);
  294. var iIndex = validate[formname].length -1;
  295. validate[formname][iIndex][jstypeIndex] = 'callback';
  296. validate[formname][iIndex][callbackIndex] = callback;
  297. }
  298. function addToValidateRange(formname, name, type,required, msg,min,max) {
  299. addToValidate(formname, name, type,required, msg);
  300. validate[formname][validate[formname].length - 1][jstypeIndex] = 'range';
  301. validate[formname][validate[formname].length - 1][minIndex] = min;
  302. validate[formname][validate[formname].length - 1][maxIndex] = max;
  303. }
  304. function addToValidateIsValidDate(formname, name, type, required, msg) {
  305. addToValidate(formname, name, type, required, msg);
  306. validate[formname][validate[formname].length - 1][jstypeIndex] = 'date';
  307. }
  308. function addToValidateIsValidTime(formname, name, type, required, msg) {
  309. addToValidate(formname, name, type, required, msg);
  310. validate[formname][validate[formname].length - 1][jstypeIndex] = 'time';
  311. }
  312. function addToValidateDateBefore(formname, name, type, required, msg, compareTo) {
  313. addToValidate(formname, name, type,required, msg);
  314. validate[formname][validate[formname].length - 1][jstypeIndex] = 'isbefore';
  315. validate[formname][validate[formname].length - 1][compareToIndex] = compareTo;
  316. }
  317. function addToValidateDateBeforeAllowBlank(formname, name, type, required, msg, compareTo, allowBlank) {
  318. addToValidate(formname, name, type,required, msg);
  319. validate[formname][validate[formname].length - 1][jstypeIndex] = 'isbefore';
  320. validate[formname][validate[formname].length - 1][compareToIndex] = compareTo;
  321. validate[formname][validate[formname].length - 1][allowblank] = allowBlank;
  322. }
  323. function addToValidateBinaryDependency(formname, name, type, required, msg, compareTo) {
  324. addToValidate(formname, name, type, required, msg);
  325. validate[formname][validate[formname].length - 1][jstypeIndex] = 'binarydep';
  326. validate[formname][validate[formname].length - 1][compareToIndex] = compareTo;
  327. }
  328. function addToValidateComparison(formname, name, type, required, msg, compareTo) {
  329. addToValidate(formname, name, type, required, msg);
  330. validate[formname][validate[formname].length - 1][jstypeIndex] = 'comparison';
  331. validate[formname][validate[formname].length - 1][compareToIndex] = compareTo;
  332. }
  333. function addToValidateIsInArray(formname, name, type, required, msg, arr, operator) {
  334. addToValidate(formname, name, type, required, msg);
  335. validate[formname][validate[formname].length - 1][jstypeIndex] = 'in_array';
  336. validate[formname][validate[formname].length - 1][arrIndex] = arr;
  337. validate[formname][validate[formname].length - 1][operatorIndex] = operator;
  338. }
  339. function addToValidateVerified(formname, name, type, required, msg, arr, operator) {
  340. addToValidate(formname, name, type, required, msg);
  341. validate[formname][validate[formname].length - 1][jstypeIndex] = 'verified';
  342. }
  343. function addToValidateLessThan(formname, name, type, required, msg, max, max_field_msg) {
  344. addToValidate(formname, name, type, required, msg);
  345. validate[formname][validate[formname].length - 1][jstypeIndex] = 'less';
  346. validate[formname][validate[formname].length - 1][maxIndex] = max;
  347. validate[formname][validate[formname].length - 1][altMsgIndex] = max_field_msg;
  348. }
  349. function addToValidateMoreThan(formname, name, type, required, msg, min) {
  350. addToValidate(formname, name, type, required, msg);
  351. validate[formname][validate[formname].length - 1][jstypeIndex] = 'more';
  352. validate[formname][validate[formname].length - 1][minIndex] = min;
  353. }
  354. function removeFromValidate(formname, name) {
  355. for(i = 0; i < validate[formname].length; i++)
  356. {
  357. if(validate[formname][i][nameIndex] == name)
  358. {
  359. validate[formname].splice(i--,1); // We subtract 1 from i since the slice removed an element, and we'll skip over the next item we scan
  360. }
  361. }
  362. }
  363. function checkValidate(formname, name) {
  364. if(validate[formname]){
  365. for(i = 0; i < validate[formname].length; i++){
  366. if(validate[formname][i][nameIndex] == name){
  367. return true;
  368. }
  369. }
  370. }
  371. return false;
  372. }
  373. var formsWithFieldLogic=null;
  374. var formWithPrecision =null;
  375. function addToValidateFieldLogic(formId,minFieldId, maxFieldId, defaultFieldId, lenFieldId,type,msg){
  376. this.formId = document.getElementById(formId);
  377. this.min=document.getElementById(minFieldId);
  378. this.max= document.getElementById(maxFieldId);
  379. this._default= document.getElementById(defaultFieldId);
  380. this.len = document.getElementById(lenFieldId);
  381. this.msg = msg;
  382. this.type= type;
  383. }
  384. //@params: formid- Dom id of the form containing the precision and float fields
  385. // valudId- Dom id of the field containing a float whose precision is to be checked.
  386. // precisionId- Dom id of the field containing precision value.
  387. function addToValidatePrecision(formId, valueId, precisionId){
  388. this.form = document.getElementById(formId);
  389. this.float = document.getElementById(valueId);
  390. this.precision = document.getElementById(precisionId);
  391. }
  392. //function checkLength(value, referenceValue){
  393. // return value
  394. //}
  395. function isValidPrecision(value, precision){
  396. value = trim(value.toString());
  397. if(precision == '')
  398. return true;
  399. if(value == '')
  400. return true;
  401. //#27021
  402. if( (precision == "0") ){
  403. if (value.indexOf(dec_sep)== -1){
  404. return true;
  405. }else{
  406. return false;
  407. }
  408. }
  409. //#27021 end
  410. if(value.charAt(value.length-precision-1) == num_grp_sep){
  411. if(value.substr(value.indexOf(dec_sep), 1)==dec_sep){
  412. return false;
  413. }
  414. return true;
  415. }
  416. var actualPrecision = value.substr(value.indexOf(dec_sep)+1, value.length).length;
  417. return actualPrecision == precision;
  418. }
  419. function toDecimal(original, precision) {
  420. precision = (precision == null) ? 2 : precision;
  421. num = Math.pow(10, precision);
  422. temp = Math.round(original*num)/num;
  423. if((temp * 100) % 100 == 0)
  424. return temp + '.00';
  425. if((temp * 10) % 10 == 0)
  426. return temp + '0';
  427. return temp
  428. }
  429. function isInteger(s) {
  430. if(typeof num_grp_sep != 'undefined' && typeof dec_sep != 'undefined')
  431. {
  432. s = unformatNumberNoParse(s, num_grp_sep, dec_sep).toString();
  433. }
  434. return /^[+-]?[0-9]*$/.test(s) ;
  435. }
  436. function isDecimal(s) {
  437. if (typeof s == "string" && s == "") // bug# 46530, this is required in order to
  438. return true; // not check empty decimal fields
  439. if(typeof num_grp_sep != 'undefined' && typeof dec_sep != 'undefined')
  440. {
  441. s = unformatNumberNoParse(s, num_grp_sep, dec_sep).toString();
  442. }
  443. return /^[+-]?[0-9]*\.?[0-9]*$/.test(s) ;
  444. }
  445. function isNumeric(s) {
  446. return isDecimal(s);
  447. }
  448. if (typeof date_reg_positions != "object") var date_reg_positions = {'Y': 1,'m': 2,'d': 3};
  449. if (typeof date_reg_format != "string") var date_reg_format = '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})';
  450. function isDate(dtStr) {
  451. if(dtStr.length== 0) {
  452. return true;
  453. }
  454. // Check that we have numbers
  455. myregexp = new RegExp(date_reg_format)
  456. if(!myregexp.test(dtStr))
  457. return false
  458. m = '';
  459. d = '';
  460. y = '';
  461. var dateParts = dtStr.match(date_reg_format);
  462. for(key in date_reg_positions) {
  463. index = date_reg_positions[key];
  464. if(key == 'm') {
  465. m = dateParts[index];
  466. } else if(key == 'd') {
  467. d = dateParts[index];
  468. } else {
  469. y = dateParts[index];
  470. }
  471. }
  472. // Check that date is real
  473. var dd = new Date(y,m,0);
  474. // reject negative years
  475. if (y < 1)
  476. return false;
  477. // reject month less than 1 and greater than 12
  478. if (m > 12 || m < 1)
  479. return false;
  480. // reject days less than 1 or days not in month (e.g. February 30th)
  481. if (d < 1 || d > dd.getDate())
  482. return false;
  483. return true;
  484. }
  485. function getDateObject(dtStr) {
  486. if(dtStr.length== 0) {
  487. return true;
  488. }
  489. myregexp = new RegExp(date_reg_format)
  490. if(myregexp.exec(dtStr)) var dt = myregexp.exec(dtStr)
  491. else return false;
  492. var yr = dt[date_reg_positions['Y']];
  493. var mh = dt[date_reg_positions['m']];
  494. var dy = dt[date_reg_positions['d']];
  495. var dtar = dtStr.split(' ');
  496. var date1;
  497. if(typeof(dtar[1])!='undefined' && isTime(dtar[1])) {//if it is a timedate, we should make date1 to have time value
  498. var t1 = dtar[1].replace(/am/i,' AM');
  499. var t1 = t1.replace(/pm/i,' PM');
  500. //bug #37977: where time format 23.00 causes java script error
  501. t1=t1.replace(/\./, ':');
  502. date1 = new Date(mh+'/'+dy+'/'+yr+' '+t1);
  503. }
  504. else
  505. {
  506. date1 = new Date(mh+'/'+dy+'/'+yr);
  507. }
  508. if (isNaN(date1.valueOf())) {
  509. return null;
  510. }
  511. return date1;
  512. }
  513. function isBefore(value1, value2) {
  514. var d1 = getDateObject(value1);
  515. var d2 = getDateObject(value2);
  516. if(typeof(d2)=='boolean') {// if d2 is not set, we should let it pass, the d2 may not need to be set. the empty check should not be done here.
  517. return true;
  518. }
  519. return d2 >= d1;
  520. }
  521. function isValidEmail(emailStr) {
  522. if(emailStr.length== 0) {
  523. return true;
  524. }
  525. // cn: bug 7128, a period at the end of the string mangles checks. (switched to accept spaces and delimiters)
  526. var lastChar = emailStr.charAt(emailStr.length - 1);
  527. if(!lastChar.match(/[^\.]/i)) {
  528. return false;
  529. }
  530. //bug 40068, According to rules in page 6 of http://www.apps.ietf.org/rfc/rfc3696.html#sec-3,
  531. //first character of local part of an email address
  532. //should not be a period i.e. '.'
  533. var firstLocalChar=emailStr.charAt(0);
  534. if(firstLocalChar.match(/\./)){
  535. return false;
  536. }
  537. //bug 40068, According to rules in page 6 of http://www.apps.ietf.org/rfc/rfc3696.html#sec-3,
  538. //last character of local part of an email address
  539. //should not be a period i.e. '.'
  540. var pos=emailStr.lastIndexOf("@");
  541. var localPart = emailStr.substr(0, pos);
  542. var lastLocalChar=localPart.charAt(localPart.length - 1);
  543. if(lastLocalChar.match(/\./)){
  544. return false;
  545. }
  546. var reg = /@.*?;/g;
  547. var results;
  548. while ((results = reg.exec(emailStr)) != null) {
  549. var original = results[0];
  550. parsedResult = results[0].replace(';', '::;::');
  551. emailStr = emailStr.replace (original, parsedResult);
  552. }
  553. reg = /.@.*?,/g;
  554. while ((results = reg.exec(emailStr)) != null) {
  555. var original = results[0];
  556. //Check if we were using ; as a delimiter. If so, skip the commas
  557. if(original.indexOf("::;::") == -1) {
  558. var parsedResult = results[0].replace(',', '::;::');
  559. emailStr = emailStr.replace (original, parsedResult);
  560. }
  561. }
  562. // mfh: bug 15010 - more practical implementation of RFC 2822 from http://www.regular-expressions.info/email.html, modifed to accept CAPITAL LETTERS
  563. //if(!/[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/.test(emailStr))
  564. // return false
  565. //bug 40068, According to rules in page 6 of http://www.apps.ietf.org/rfc/rfc3696.html#sec-3,
  566. //allowed special characters ! # $ % & ' * + - / = ? ^ _ ` . { | } ~ in local part
  567. var emailArr = emailStr.split(/::;::/);
  568. for (var i = 0; i < emailArr.length; i++) {
  569. var emailAddress = emailArr[i];
  570. if (trim(emailAddress) != '') {
  571. if(!/^\s*[\w.%+\-&'#!\$\*=\?\^_`\{\}~\/]+@([A-Z0-9-]+\.)*[A-Z0-9-]+\.[\w-]{2,}\s*$/i.test(emailAddress) &&
  572. !/^.*<[A-Z0-9._%+\-&'#!\$\*=\?\^_`\{\}~]+?@([A-Z0-9-]+\.)*[A-Z0-9-]+\.[\w-]{2,}>\s*$/i.test(emailAddress)) {
  573. return false;
  574. } // if
  575. }
  576. } // for
  577. return true;
  578. }
  579. function isValidPhone(phoneStr) {
  580. if(phoneStr.length== 0) {
  581. return true;
  582. }
  583. if(!/^[0-9\-\(\)\s]+$/.test(phoneStr))
  584. return false
  585. return true
  586. }
  587. function isFloat(floatStr) {
  588. if(floatStr.length== 0) {
  589. return true;
  590. }
  591. if(!(typeof(num_grp_sep)=='undefined' || typeof(dec_sep)=='undefined')) {
  592. floatStr = unformatNumberNoParse(floatStr, num_grp_sep, dec_sep).toString();
  593. }
  594. return /^(-)?[0-9\.]+$/.test(floatStr);
  595. }
  596. function isDBName(str) {
  597. if(str.length== 0) {
  598. return true;
  599. }
  600. // must start with a letter
  601. if(!/^[a-zA-Z][a-zA-Z\_0-9]*$/.test(str))
  602. return false
  603. return true
  604. }
  605. var time_reg_format = "[0-9]{1,2}\:[0-9]{2}";
  606. function isTime(timeStr) {
  607. var timeRegex = time_reg_format;
  608. // eliminate the am/pm from the external time_reg_format
  609. timeRegex = timeRegex.replace(/[ ]*\([^)]*m\)/i, '');
  610. if(timeStr.length== 0){
  611. return true;
  612. }
  613. //we now support multiple time formats
  614. myregexp = new RegExp(timeRegex);
  615. if(!myregexp.test(timeStr)) {
  616. return false;
  617. }
  618. return true;
  619. }
  620. function inRange(value, min, max) {
  621. if (typeof num_grp_sep != 'undefined' && typeof dec_sep != 'undefined')
  622. value = unformatNumberNoParse(value, num_grp_sep, dec_sep).toString();
  623. var result = true;
  624. if (typeof min == 'number' && value < min)
  625. {
  626. result = false;
  627. }
  628. if (typeof max == 'number' && value > max)
  629. {
  630. result = false;
  631. }
  632. return result;
  633. }
  634. function bothExist(item1, item2) {
  635. if(typeof item1 == 'undefined') { return false; }
  636. if(typeof item2 == 'undefined') { return false; }
  637. if((item1 == '' && item2 != '') || (item1 != '' && item2 == '') ) { return false; }
  638. return true;
  639. }
  640. trim = YAHOO.lang.trim;
  641. function check_form(formname) {
  642. if (typeof(siw) != 'undefined' && siw
  643. && typeof(siw.selectingSomething) != 'undefined' && siw.selectingSomething)
  644. return false;
  645. return validate_form(formname, '');
  646. }
  647. function add_error_style(formname, input, txt, flash) {
  648. var raiseFlag = false;
  649. if (typeof flash == "undefined")
  650. flash = true;
  651. try {
  652. inputHandle = typeof input == "object" ? input : document.forms[formname][input];
  653. style = get_current_bgcolor(inputHandle);
  654. // strip off the colon at the end of the warning strings
  655. if ( txt.substring(txt.length-1) == ':' )
  656. txt = txt.substring(0,txt.length-1)
  657. // Bug 28249 - To help avoid duplicate messages for an element, strip off extra messages and
  658. // match on the field name itself
  659. requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
  660. invalidTxt = SUGAR.language.get('app_strings', 'ERR_INVALID_VALUE');
  661. nomatchTxt = SUGAR.language.get('app_strings', 'ERR_SQS_NO_MATCH_FIELD');
  662. matchTxt = txt.replace(requiredTxt,'').replace(invalidTxt,'').replace(nomatchTxt,'');
  663. YUI().use('node', function (Y) {
  664. Y.one(inputHandle).get('parentNode').get('children').each(function(node, index, nodeList){
  665. if(node.hasClass('validation-message') && node.get('text').search(matchTxt)){
  666. raiseFlag = true;
  667. }
  668. });
  669. });
  670. if(!raiseFlag) {
  671. errorTextNode = document.createElement('div');
  672. errorTextNode.className = 'required validation-message';
  673. errorTextNode.innerHTML = txt;
  674. if ( inputHandle.parentNode.className.indexOf('x-form-field-wrap') != -1 ) {
  675. inputHandle.parentNode.parentNode.appendChild(errorTextNode);
  676. }
  677. else {
  678. inputHandle.parentNode.appendChild(errorTextNode);
  679. }
  680. if (flash)
  681. inputHandle.style.backgroundColor = "#FF0000";
  682. inputsWithErrors.push(inputHandle);
  683. }
  684. if (flash)
  685. {
  686. // We only need to setup the flashy-flashy on the first entry, it loops through all fields automatically
  687. if ( inputsWithErrors.length == 1 ) {
  688. for(var wp = 1; wp <= 10; wp++) {
  689. window.setTimeout('fade_error_style(style, '+wp*10+')',1000+(wp*50));
  690. }
  691. }
  692. if(typeof (window[formname + "_tabs"]) != "undefined") {
  693. var tabView = window[formname + "_tabs"];
  694. var parentDiv = YAHOO.util.Dom.getAncestorByTagName(inputHandle, "div");
  695. if ( tabView.get ) {
  696. var tabs = tabView.get("tabs");
  697. for (var i in tabs) {
  698. if (tabs[i].get("contentEl") == parentDiv
  699. || YAHOO.util.Dom.isAncestor(tabs[i].get("contentEl"), inputHandle))
  700. {
  701. tabs[i].get("labelEl").style.color = "red";
  702. if ( inputsWithErrors.length == 1 )
  703. tabView.selectTab(i);
  704. }
  705. }
  706. }
  707. }
  708. window.setTimeout("inputsWithErrors[" + (inputsWithErrors.length - 1) + "].style.backgroundColor = '';", 2000);
  709. }
  710. } catch ( e ) {
  711. // Catch errors here so we don't allow an incomplete record through the javascript validation
  712. }
  713. }
  714. /**
  715. * removes all error messages for the current form
  716. */
  717. function clear_all_errors() {
  718. for(var wp = 0; wp < inputsWithErrors.length; wp++) {
  719. if(typeof(inputsWithErrors[wp]) !='undefined' && typeof inputsWithErrors[wp].parentNode != 'undefined' && inputsWithErrors[wp].parentNode != null) {
  720. if ( inputsWithErrors[wp].parentNode.className.indexOf('x-form-field-wrap') != -1 )
  721. {
  722. inputsWithErrors[wp].parentNode.parentNode.removeChild(inputsWithErrors[wp].parentNode.parentNode.lastChild);
  723. }
  724. else
  725. {
  726. inputsWithErrors[wp].parentNode.removeChild(inputsWithErrors[wp].parentNode.lastChild);
  727. }
  728. }
  729. }
  730. if (inputsWithErrors.length == 0) return;
  731. if ( YAHOO.util.Dom.getAncestorByTagName(inputsWithErrors[0], "form") ) {
  732. var formname = YAHOO.util.Dom.getAncestorByTagName(inputsWithErrors[0], "form").getAttribute("name");
  733. if(typeof (window[formname + "_tabs"]) != "undefined") {
  734. var tabView = window[formname + "_tabs"];
  735. if ( tabView.get ) {
  736. var tabs = tabView.get("tabs");
  737. for (var i in tabs) {
  738. if (typeof tabs[i] == "object")
  739. tabs[i].get("labelEl").style.color = "";
  740. }
  741. }
  742. }
  743. inputsWithErrors = new Array();
  744. }
  745. }
  746. function get_current_bgcolor(input) {
  747. if(input.currentStyle) {// ie
  748. style = input.currentStyle.backgroundColor;
  749. return style.substring(1,7);
  750. }
  751. else {// moz
  752. style = '';
  753. styleRGB = document.defaultView.getComputedStyle(input, '').getPropertyValue("background-color");
  754. comma = styleRGB.indexOf(',');
  755. style += dec2hex(styleRGB.substring(4, comma));
  756. commaPrevious = comma;
  757. comma = styleRGB.indexOf(',', commaPrevious+1);
  758. style += dec2hex(styleRGB.substring(commaPrevious+2, comma));
  759. style += dec2hex(styleRGB.substring(comma+2, styleRGB.lastIndexOf(')')));
  760. return style;
  761. }
  762. }
  763. function hex2dec(hex){return(parseInt(hex,16));}
  764. var hexDigit=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F");
  765. function dec2hex(dec){return(hexDigit[dec>>4]+hexDigit[dec&15]);}
  766. function fade_error_style(normalStyle, percent) {
  767. errorStyle = 'f10202';
  768. var r1 = hex2dec(errorStyle.slice(0,2));
  769. var g1 = hex2dec(errorStyle.slice(2,4));
  770. var b1 = hex2dec(errorStyle.slice(4,6));
  771. var r2 = hex2dec(normalStyle.slice(0,2));
  772. var g2 = hex2dec(normalStyle.slice(2,4));
  773. var b2 = hex2dec(normalStyle.slice(4,6));
  774. var pc = percent / 100;
  775. r= Math.floor(r1+(pc*(r2-r1)) + .5);
  776. g= Math.floor(g1+(pc*(g2-g1)) + .5);
  777. b= Math.floor(b1+(pc*(b2-b1)) + .5);
  778. for(var wp = 0; wp < inputsWithErrors.length; wp++) {
  779. inputsWithErrors[wp].style.backgroundColor = "#" + dec2hex(r) + dec2hex(g) + dec2hex(b);
  780. }
  781. }
  782. function isFieldTypeExceptFromEmptyCheck(fieldType)
  783. {
  784. var results = false;
  785. var exemptList = ['bool','file'];
  786. for(var i=0;i<exemptList.length;i++)
  787. {
  788. if(fieldType == exemptList[i])
  789. return true;
  790. }
  791. return results;
  792. }
  793. function validate_form(formname, startsWith){
  794. requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
  795. invalidTxt = SUGAR.language.get('app_strings', 'ERR_INVALID_VALUE');
  796. if ( typeof (formname) == 'undefined')
  797. {
  798. return false;
  799. }
  800. if ( typeof (validate[formname]) == 'undefined')
  801. {
  802. disableOnUnloadEditView(document.forms[formname]);
  803. return true;
  804. }
  805. var form = document.forms[formname];
  806. var isError = false;
  807. var errorMsg = "";
  808. var _date = new Date();
  809. if(_date.getTime() < (lastSubmitTime + 2000) && startsWith == oldStartsWith) { // ignore submits for the next 2 seconds
  810. return false;
  811. }
  812. lastSubmitTime = _date.getTime();
  813. oldStartsWith = startsWith;
  814. clear_all_errors(); // remove previous error messages
  815. inputsWithErrors = new Array();
  816. for(var i = 0; i < validate[formname].length; i++){
  817. if(validate[formname][i][nameIndex].indexOf(startsWith) == 0){
  818. if(typeof form[validate[formname][i][nameIndex]] != 'undefined' && typeof form[validate[formname][i][nameIndex]].value != 'undefined'){
  819. var bail = false;
  820. //If a field is not required and it is blank or is binarydependant, skip validation.
  821. //Example of binary dependant fields would be the hour/min/meridian dropdowns in a date time combo widget, which require further processing than a blank check
  822. if(!validate[formname][i][requiredIndex] && trim(form[validate[formname][i][nameIndex]].value) == '' && (typeof(validate[formname][i][jstypeIndex]) != 'undefined' && validate[formname][i][jstypeIndex] != 'binarydep'))
  823. {
  824. continue;
  825. }
  826. if(validate[formname][i][requiredIndex]
  827. && !isFieldTypeExceptFromEmptyCheck(validate[formname][i][typeIndex])
  828. ){
  829. if(typeof form[validate[formname][i][nameIndex]] == 'undefined' || trim(form[validate[formname][i][nameIndex]].value) == ""){
  830. add_error_style(formname, validate[formname][i][nameIndex], requiredTxt +' ' + validate[formname][i][msgIndex]);
  831. isError = true;
  832. }
  833. }
  834. if(!bail){
  835. switch(validate[formname][i][typeIndex]){
  836. case 'email':
  837. if(!isValidEmail(trim(form[validate[formname][i][nameIndex]].value))){
  838. isError = true;
  839. add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
  840. }
  841. break;
  842. case 'time':
  843. if( !isTime(trim(form[validate[formname][i][nameIndex]].value))){
  844. isError = true;
  845. add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
  846. } break;
  847. case 'date': if(!isDate(trim(form[validate[formname][i][nameIndex]].value))){
  848. isError = true;
  849. add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
  850. } break;
  851. case 'alpha':
  852. break;
  853. case 'DBName':
  854. if(!isDBName(trim(form[validate[formname][i][nameIndex]].value))){
  855. isError = true;
  856. add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
  857. }
  858. break;
  859. // Bug #49614 : Check value without trimming before
  860. case 'DBNameRaw':
  861. if(!isDBName(form[validate[formname][i][nameIndex]].value)){
  862. isError = true;
  863. add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
  864. }
  865. break;
  866. case 'alphanumeric':
  867. break;
  868. case 'file':
  869. var file_input = form[validate[formname][i][nameIndex] + '_file'];
  870. if( file_input && validate[formname][i][requiredIndex] && trim(file_input.value) == "" && !file_input.disabled ) {
  871. isError = true;
  872. add_error_style(formname, validate[formname][i][nameIndex], requiredTxt + " " + validate[formname][i][msgIndex]);
  873. }
  874. break;
  875. case 'int':
  876. if(!isInteger(trim(form[validate[formname][i][nameIndex]].value))){
  877. isError = true;
  878. add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
  879. }
  880. break;
  881. case 'decimal':
  882. if(!isDecimal(trim(form[validate[formname][i][nameIndex]].value))){
  883. isError = true;
  884. add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
  885. }
  886. break;
  887. case 'currency':
  888. case 'float':
  889. if(!isFloat(trim(form[validate[formname][i][nameIndex]].value))){
  890. isError = true;
  891. add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
  892. }
  893. break;
  894. case 'teamset_mass':
  895. var div_element_id = formname + '_' + form[validate[formname][i][nameIndex]].name + '_operation_div';
  896. var input_elements = YAHOO.util.Selector.query('input', document.getElementById(div_element_id));
  897. var primary_field_id = '';
  898. var validation_passed = false;
  899. var replace_selected = false;
  900. //Loop through the option elements (replace or add currently)
  901. for(t in input_elements) {
  902. if(input_elements[t].type && input_elements[t].type == 'radio' && input_elements[t].checked == true && input_elements[t].value == 'replace') {
  903. //Now find where the primary radio button is and if a value has been set
  904. var radio_elements = YAHOO.util.Selector.query('input[type=radio]', document.getElementById(formname + '_team_name_table'));
  905. for(var x = 0; x < radio_elements.length; x++) {
  906. if(radio_elements[x].name != 'team_name_type') {
  907. primary_field_id = 'team_name_collection_' + radio_elements[x].value;
  908. if(radio_elements[x].checked) {
  909. replace_selected = true;
  910. if(trim(document.forms[formname].elements[primary_field_id].value) != '') {
  911. validation_passed = true;
  912. break;
  913. }
  914. } else if(trim(document.forms[formname].elements[primary_field_id].value) != '') {
  915. replace_selected = true;
  916. }
  917. }
  918. }
  919. }
  920. }
  921. if(replace_selected && !validation_passed) {
  922. add_error_style(formname, primary_field_id, SUGAR.language.get('app_strings', 'ERR_NO_PRIMARY_TEAM_SPECIFIED'));
  923. isError = true;
  924. }
  925. break;
  926. case 'teamset':
  927. var table_element_id = formname + '_' + form[validate[formname][i][nameIndex]].name + '_table';
  928. if(document.getElementById(table_element_id)) {
  929. var input_elements = YAHOO.util.Selector.query('input[type=radio]', document.getElementById(table_element_id));
  930. var has_primary = false;
  931. var primary_field_id = form[validate[formname][i][nameIndex]].name + '_collection_0';
  932. for(t in input_elements) {
  933. primary_field_id = form[validate[formname][i][nameIndex]].name + '_collection_' + input_elements[t].value;
  934. if(input_elements[t].type && input_elements[t].type == 'radio' && input_elements[t].checked == true) {
  935. if(document.forms[formname].elements[primary_field_id].value != '') {
  936. has_primary = true;
  937. }
  938. break;
  939. }
  940. }
  941. if(!has_primary) {
  942. isError = true;
  943. var field_id = form[validate[formname][i][nameIndex]].name + '_collection_' + input_elements[0].value;
  944. add_error_style(formname, field_id, SUGAR.language.get('app_strings', 'ERR_NO_PRIMARY_TEAM_SPECIFIED'));
  945. }
  946. }
  947. break;
  948. case 'error':
  949. isError = true;
  950. add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex]);
  951. break;
  952. }
  953. if(typeof validate[formname][i][jstypeIndex] != 'undefined'/* && !isError*/){
  954. switch(validate[formname][i][jstypeIndex]){
  955. // Bug #47961 May be validation through callback is best way.
  956. case 'callback' :
  957. if (typeof validate[formname][i][callbackIndex] == 'function')
  958. {
  959. var result = validate[formname][i][callbackIndex](formname, validate[formname][i][nameIndex]);
  960. if (result == false)
  961. {
  962. isError = true;
  963. add_error_style(formname, validate[formname][i][nameIndex], requiredTxt + " " + validate[formname][i][msgIndex]);
  964. }
  965. }
  966. break;
  967. case 'range':
  968. if(!inRange(trim(form[validate[formname][i][nameIndex]].value), validate[formname][i][minIndex], validate[formname][i][maxIndex])){
  969. isError = true;
  970. var lbl_validate_range = SUGAR.language.get('app_strings', 'LBL_VALIDATE_RANGE');
  971. if (typeof validate[formname][i][minIndex] == 'number' && typeof validate[formname][i][maxIndex] == 'number')
  972. {
  973. add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + " value " + form[validate[formname][i][nameIndex]].value + " " + lbl_validate_range + " (" +validate[formname][i][minIndex] + " - " + validate[formname][i][maxIndex] + ")");
  974. }
  975. else if (typeof validate[formname][i][minIndex] == 'number')
  976. {
  977. add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + " " + SUGAR.language.get('app_strings', 'MSG_SHOULD_BE') + ' ' + validate[formname][i][minIndex] + ' ' + SUGAR.language.get('app_strings', 'MSG_OR_GREATER'));
  978. }
  979. else if (typeof validate[formname][i][maxIndex] == 'number')
  980. {
  981. add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + " " + SUGAR.language.get('app_strings', 'MSG_IS_MORE_THAN') + ' ' + validate[formname][i][maxIndex]);
  982. }
  983. }
  984. break;
  985. case 'isbefore':
  986. compareTo = form[validate[formname][i][compareToIndex]];
  987. if( typeof compareTo != 'undefined'){
  988. if(trim(compareTo.value) != '' || (validate[formname][i][allowblank] != 'true') ) {
  989. date2 = trim(compareTo.value);
  990. date1 = trim(form[validate[formname][i][nameIndex]].value);
  991. if(trim(date1).length != 0 && !isBefore(date1,date2)){
  992. isError = true;
  993. //jc:#12287 - adding translation for the is not before message
  994. add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] + "(" + date1 + ") " + SUGAR.language.get('app_strings', 'MSG_IS_NOT_BEFORE') + ' ' +date2);
  995. }
  996. }
  997. }
  998. break;
  999. case 'less':
  1000. value=unformatNumber(trim(form[validate[formname][i][nameIndex]].value), num_grp_sep, dec_sep);
  1001. maximum = parseFloat(validate[formname][i][maxIndex]);
  1002. if( typeof maximum != 'undefined'){
  1003. if(value>maximum) {
  1004. isError = true;
  1005. add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] +" " +SUGAR.language.get('app_strings', 'MSG_IS_MORE_THAN')+ ' ' + validate[formname][i][altMsgIndex]);
  1006. }
  1007. }
  1008. break;
  1009. case 'more':
  1010. value=unformatNumber(trim(form[validate[formname][i][nameIndex]].value), num_grp_sep, dec_sep);
  1011. minimum = parseFloat(validate[formname][i][minIndex]);
  1012. if( typeof minimum != 'undefined'){
  1013. if(value<minimum) {
  1014. isError = true;
  1015. add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex] +" " +SUGAR.language.get('app_strings', 'MSG_SHOULD_BE')+ ' ' + minimum + ' ' + SUGAR.language.get('app_strings', 'MSG_OR_GREATER'));
  1016. }
  1017. }
  1018. break;
  1019. case 'binarydep':
  1020. compareTo = form[validate[formname][i][compareToIndex]];
  1021. if( typeof compareTo != 'undefined') {
  1022. item1 = trim(form[validate[formname][i][nameIndex]].value);
  1023. item2 = trim(compareTo.value);
  1024. if(!bothExist(item1, item2)) {
  1025. isError = true;
  1026. add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex]);
  1027. }
  1028. }
  1029. break;
  1030. case 'comparison':
  1031. compareTo = form[validate[formname][i][compareToIndex]];
  1032. if( typeof compareTo != 'undefined') {
  1033. item1 = trim(form[validate[formname][i][nameIndex]].value);
  1034. item2 = trim(compareTo.value);
  1035. if(!bothExist(item1, item2) || item1 != item2) {
  1036. isError = true;
  1037. add_error_style(formname, validate[formname][i][nameIndex], validate[formname][i][msgIndex]);
  1038. }
  1039. }
  1040. break;
  1041. case 'in_array':
  1042. arr = eval(validate[formname][i][arrIndex]);
  1043. operator = validate[formname][i][operatorIndex];
  1044. item1 = trim(form[validate[formname][i][nameIndex]].value);
  1045. if (operator.charAt(0) == 'u') {
  1046. item1 = item1.toUpperCase();
  1047. operator = operator.substring(1);
  1048. } else if (operator.charAt(0) == 'l') {
  1049. item1 = item1.toLowerCase();
  1050. operator = operator.substring(1);
  1051. }
  1052. for(j = 0; j < arr.length; j++){
  1053. val = arr[j];
  1054. if((operator == "==" && val == item1) || (operator == "!=" && val != item1)){
  1055. isError = true;
  1056. add_error_style(formname, validate[formname][i][nameIndex], invalidTxt + " " + validate[formname][i][msgIndex]);
  1057. }
  1058. }
  1059. break;
  1060. case 'verified':
  1061. if(trim(form[validate[formname][i][nameIndex]].value) == 'false'){
  1062. //Fake an error so form does not submit
  1063. isError = true;
  1064. }
  1065. break;
  1066. }
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. /* nsingh: BUG#15102
  1073. Check min max default field logic.
  1074. Can work with float values as well, but as of 10/8/07 decimal values in MB and studio don't have min and max value constraints.*/
  1075. if(formsWithFieldLogic){
  1076. var invalidLogic=false;
  1077. if(formsWithFieldLogic.min && formsWithFieldLogic.max && formsWithFieldLogic._default) {
  1078. var showErrorsOn={min:{value:'min', show:false, obj:formsWithFieldLogic.min.value},
  1079. max:{value:'max',show:false, obj:formsWithFieldLogic.max.value},
  1080. _default:{value:'default',show:false, obj:formsWithFieldLogic._default.value},
  1081. len:{value:'len', show:false, obj:parseInt(formsWithFieldLogic.len.value,10)}};
  1082. var min = (formsWithFieldLogic.min.value !='') ? parseFloat(formsWithFieldLogic.min.value) : 'undef';
  1083. var max = (formsWithFieldLogic.max.value !='') ? parseFloat(formsWithFieldLogic.max.value) : 'undef';
  1084. var _default = (formsWithFieldLogic._default.value!='')? parseFloat(formsWithFieldLogic._default.value) : 'undef';
  1085. /*Check all lengths are <= max size.*/
  1086. for(var i in showErrorsOn){
  1087. if(showErrorsOn[i].value!='len' && showErrorsOn[i].obj.length > showErrorsOn.len.obj){
  1088. invalidLogic=true;
  1089. showErrorsOn[i].show=true;
  1090. showErrorsOn.len.show=true;
  1091. }
  1092. }
  1093. if(min!='undef' && max!='undef' && _default!='undef'){
  1094. if(!inRange(_default,min,max)){
  1095. invalidLogic=true;
  1096. showErrorsOn.min.show=true;
  1097. showErrorsOn.max.show=true;
  1098. showErrorsOn._default.show=true;
  1099. }
  1100. }
  1101. if(min!='undef' && max!= 'undef' && min > max){
  1102. invalidLogic = true;
  1103. showErrorsOn.min.show=true;
  1104. showErrorsOn.max.show=true;
  1105. }
  1106. if(min!='undef' && _default!='undef' && _default < min){
  1107. invalidLogic = true;
  1108. showErrorsOn.min.show=true;
  1109. showErrorsOn._default.show=true;
  1110. }
  1111. if(max!='undef' && _default !='undef' && _default>max){
  1112. invalidLogic = true;
  1113. showErrorsOn.max.show=true;
  1114. showErrorsOn._default.show=true;
  1115. }
  1116. if(invalidLogic){
  1117. isError=true;
  1118. for(var error in showErrorsOn)
  1119. if(showErrorsOn[error].show)
  1120. add_error_style(formname,showErrorsOn[error].value, formsWithFieldLogic.msg);
  1121. }
  1122. else if (!isError)
  1123. formsWithFieldLogic = null;
  1124. }
  1125. }
  1126. if(formWithPrecision){
  1127. if (!isValidPrecision(formWithPrecision.float.value, formWithPrecision.precision.value)){
  1128. isError = true;
  1129. add_error_style(formname, 'default', SUGAR.language.get('app_strings', 'ERR_COMPATIBLE_PRECISION_VALUE'));
  1130. }else if(!isError){
  1131. isError = false;
  1132. }
  1133. }
  1134. //END BUG# 15102
  1135. if (isError == true) {
  1136. var nw, ne, sw, se;
  1137. if (self.pageYOffset) // all except Explorer
  1138. {
  1139. nwX = self.pageXOffset;
  1140. seX = self.innerWidth;
  1141. nwY = self.pageYOffset;
  1142. seY = self.innerHeight;
  1143. }
  1144. else if (document.documentElement && document.documentElement.scrollTop) // Explorer 6 Strict
  1145. {
  1146. nwX = document.documentElement.scrollLeft;
  1147. seX = document.documentElement.clientWidth;
  1148. nwY = document.documentElement.scrollTop;
  1149. seY = document.documentElement.clientHeight;
  1150. }
  1151. else if (document.body) // all other Explorers
  1152. {
  1153. nwX = document.body.scrollLeft;
  1154. seX = document.body.clientWidth;
  1155. nwY = document.body.scrollTop;
  1156. seY = document.body.clientHeight;
  1157. }
  1158. var inView = true; // is there an error within viewport of browser
  1159. for(var wp = 0; wp < inputsWithErrors.length; wp++) {
  1160. var elementCoor = findElementPos(inputsWithErrors[wp]);
  1161. if(!(elementCoor.x >= nwX && elementCoor.y >= nwY &&
  1162. elementCoor.x <= seX+nwX && elementCoor.y <= seY+nwY)) { // if input is not within viewport, modify for SI bug 52497
  1163. inView = false;
  1164. scrollToTop = elementCoor.y - 75;
  1165. scrollToLeft = elementCoor.x - 75;
  1166. }
  1167. else { // on first input within viewport, don't scroll
  1168. break;
  1169. }
  1170. }
  1171. if(!inView) window.scrollTo(scrollToLeft,scrollToTop);
  1172. return false;
  1173. }
  1174. disableOnUnloadEditView(form);
  1175. return true;
  1176. }
  1177. /**
  1178. * This array is used to remember mark status of rows in browse mode
  1179. */
  1180. var marked_row = new Array;
  1181. /**
  1182. * Sets/unsets the pointer and marker in browse mode
  1183. *
  1184. * @param object the table row
  1185. * @param interger the row number
  1186. * @param string the action calling this script (over, out or click)
  1187. * @param string the default background color
  1188. * @param string the color to use for mouseover
  1189. * @param string the color to use for marking a row
  1190. *
  1191. * @return boolean whether pointer is set or not
  1192. */
  1193. function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor) {
  1194. var theCells = null;
  1195. // 1. Pointer and mark feature are disabled or the browser can't get the
  1196. // row -> exits
  1197. if ((thePointerColor == '' && theMarkColor == '')
  1198. || typeof(theRow.style) == 'undefined') {
  1199. return false;
  1200. }
  1201. // 2. Gets the current row and exits if the browser can't get it
  1202. if (typeof(document.getElementsByTagName) != 'undefined') {
  1203. theCells = theRow.getElementsByTagName('td');
  1204. }
  1205. else if (typeof(theRow.cells) != 'undefined') {
  1206. theCells = theRow.cells;
  1207. }
  1208. else {
  1209. return false;
  1210. }
  1211. // 3. Gets the current color...
  1212. var rowCellsCnt = theCells.length;
  1213. var domDetect = null;
  1214. var currentColor = null;
  1215. var newColor = nu

Large files files are truncated, but you can click here to view the full file