PageRenderTime 74ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/include/js/general.js

https://bitbucket.org/pinaki/crm
JavaScript | 3952 lines | 3215 code | 528 blank | 209 comment | 958 complexity | 42b79f2abfdc6fd1e2bf726c01ecc5e2 MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, GPL-2.0, LGPL-3.0
  1. /*********************************************************************************
  2. ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
  3. * ("License"); You may not use this file except in compliance with the License
  4. * The Original Code is: vtiger CRM Open Source
  5. * The Initial Developer of the Original Code is vtiger.
  6. * Portions created by vtiger are Copyright (C) vtiger.
  7. * All Rights Reserved.
  8. ********************************************************************************/
  9. //Utility Functions
  10. var gValidationCall='';
  11. if (document.all)
  12. var browser_ie=true
  13. else if (document.layers)
  14. var browser_nn4=true
  15. else if (document.layers || (!document.all && document.getElementById))
  16. var browser_nn6=true
  17. var gBrowserAgent = navigator.userAgent.toLowerCase();
  18. function hideSelect()
  19. {
  20. var oselect_array = document.getElementsByTagName('SELECT');
  21. for(var i=0;i<oselect_array.length;i++)
  22. {
  23. oselect_array[i].style.display = 'none';
  24. }
  25. }
  26. function showSelect()
  27. {
  28. var oselect_array = document.getElementsByTagName('SELECT');
  29. for(var i=0;i<oselect_array.length;i++)
  30. {
  31. oselect_array[i].style.display = 'block';
  32. }
  33. }
  34. function getObj(n,d) {
  35. var p,i,x;
  36. if(!d) {
  37. d=document;
  38. }
  39. if(n != undefined) {
  40. if((p=n.indexOf("?"))>0&&parent.frames.length) {
  41. d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
  42. }
  43. }
  44. if(d.getElementById) {
  45. x=d.getElementById(n);
  46. // IE7 was returning form element with name = n (if there was multiple instance)
  47. // But not firefox, so we are making a double check
  48. if(x && x.id != n) x = false;
  49. }
  50. for(i=0;!x && i<d.forms.length;i++) {
  51. x=d.forms[i][n];
  52. }
  53. for(i=0; !x && d.layers && i<d.layers.length;i++) {
  54. x=getObj(n,d.layers[i].document);
  55. }
  56. if(!x && !(x=d[n]) && d.all) {
  57. x=d.all[n];
  58. }
  59. if(typeof x == 'string') {
  60. x=null;
  61. }
  62. return x;
  63. }
  64. function getOpenerObj(n) {
  65. return getObj(n,opener.document)
  66. }
  67. function findPosX(obj) {
  68. var curleft = 0;
  69. if (document.getElementById || document.all) {
  70. while (obj.offsetParent) {
  71. curleft += obj.offsetLeft
  72. obj = obj.offsetParent;
  73. }
  74. } else if (document.layers) {
  75. curleft += obj.x;
  76. }
  77. return curleft;
  78. }
  79. function findPosY(obj) {
  80. var curtop = 0;
  81. if (document.getElementById || document.all) {
  82. while (obj.offsetParent) {
  83. curtop += obj.offsetTop
  84. obj = obj.offsetParent;
  85. }
  86. } else if (document.layers) {
  87. curtop += obj.y;
  88. }
  89. return curtop;
  90. }
  91. function clearTextSelection() {
  92. if (browser_ie) document.selection.empty();
  93. else if (browser_nn4 || browser_nn6) window.getSelection().removeAllRanges();
  94. }
  95. // Setting cookies
  96. function set_cookie ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
  97. {
  98. var cookie_string = name + "=" + escape ( value );
  99. if (exp_y) //delete_cookie(name)
  100. {
  101. var expires = new Date ( exp_y, exp_m, exp_d );
  102. cookie_string += "; expires=" + expires.toGMTString();
  103. }
  104. if (path) cookie_string += "; path=" + escape ( path );
  105. if (domain) cookie_string += "; domain=" + escape ( domain );
  106. if (secure) cookie_string += "; secure";
  107. document.cookie = cookie_string;
  108. }
  109. // Retrieving cookies
  110. function get_cookie(cookie_name)
  111. {
  112. var results = document.cookie.match(cookie_name + '=(.*?)(;|$)');
  113. if (results) return (unescape(results[1]));
  114. else return null;
  115. }
  116. // Delete cookies
  117. function delete_cookie( cookie_name )
  118. {
  119. var cookie_date = new Date ( ); // current date & time
  120. cookie_date.setTime ( cookie_date.getTime() - 1 );
  121. document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
  122. }
  123. //End of Utility Functions
  124. function emptyCheck(fldName,fldLabel, fldType) {
  125. var currObj = getObj(fldName);
  126. if (fldType=="text") {
  127. if (currObj.value.replace(/^\s+/g, '').replace(/\s+$/g, '').length==0) {
  128. alert(fldLabel+alert_arr.CANNOT_BE_EMPTY)
  129. try {
  130. currObj.focus()
  131. } catch(error) {
  132. // Fix for IE: If element or its wrapper around it is hidden, setting focus will fail
  133. // So using the try { } catch(error) { }
  134. }
  135. return false
  136. }
  137. else{
  138. return true
  139. }
  140. } else if((fldType == "textarea")
  141. && (typeof(CKEDITOR)!=='undefined' && CKEDITOR.intances[fldName] !== 'undefined')) {
  142. var textObj = CKEDITOR.intances[fldName];
  143. var textValue = textObj.getData();
  144. if (trim(textValue) == '' || trim(textValue) == '<br>') {
  145. alert(fldLabel+alert_arr.CANNOT_BE_NONE);
  146. return false;
  147. } else{
  148. return true;
  149. }
  150. } else{
  151. if (trim(currObj.value) == '') {
  152. alert(fldLabel+alert_arr.CANNOT_BE_NONE)
  153. return false
  154. } else
  155. return true
  156. }
  157. }
  158. function patternValidate(fldName,fldLabel,type) {
  159. var currObj=getObj(fldName)
  160. if (type.toUpperCase()=="YAHOO") //Email ID validation
  161. {
  162. //yahoo Id validation
  163. var re=new RegExp(/^[a-z0-9]([a-z0-9_\-\.]*)@([y][a][h][o][o])(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/)
  164. }
  165. if (type.toUpperCase()=="EMAIL") //Email ID validation
  166. {
  167. /*changes made to fix -- ticket#3278 & ticket#3461
  168. var re=new RegExp(/^.+@.+\..+$/)*/
  169. //Changes made to fix tickets #4633, #5111 to accomodate all possible email formats
  170. var re=new RegExp(/^[a-zA-Z0-9]+([\_\-\.]*[a-zA-Z0-9]+[\_\-]?)*@[a-zA-Z0-9]+([\_\-]?[a-zA-Z0-9]+)*\.+([\-\_]?[a-zA-Z0-9])+(\.?[a-zA-Z0-9]+)*$/)
  171. }
  172. if (type.toUpperCase()=="DATE") {//DATE validation
  173. //YMD
  174. //var reg1 = /^\d{2}(\-|\/|\.)\d{1,2}\1\d{1,2}$/ //2 digit year
  175. //var re = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/ //4 digit year
  176. //MYD
  177. //var reg1 = /^\d{1,2}(\-|\/|\.)\d{2}\1\d{1,2}$/
  178. //var reg2 = /^\d{1,2}(\-|\/|\.)\d{4}\1\d{1,2}$/
  179. //DMY
  180. //var reg1 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{2}$/
  181. //var reg2 = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
  182. switch (userDateFormat) {
  183. case "yyyy-mm-dd" :
  184. var re = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/
  185. break;
  186. case "mm-dd-yyyy" :
  187. case "dd-mm-yyyy" :
  188. var re = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
  189. }
  190. }
  191. if (type.toUpperCase()=="TIME") {//TIME validation
  192. var re = /^\d{1,2}\:\d{1,2}$/
  193. }
  194. //Asha: Remove spaces on either side of a Email id before validating
  195. if (type.toUpperCase()=="EMAIL" || type.toUpperCase() == "DATE") currObj.value = trim(currObj.value);
  196. if (!re.test(currObj.value)) {
  197. alert(alert_arr.ENTER_VALID + fldLabel + " ("+type+")");
  198. try {
  199. currObj.focus()
  200. } catch(error) {
  201. // Fix for IE: If element or its wrapper around it is hidden, setting focus will fail
  202. // So using the try { } catch(error) { }
  203. }
  204. return false
  205. }
  206. else return true
  207. }
  208. function splitDateVal(dateval) {
  209. var datesep;
  210. var dateelements = new Array(3);
  211. if (dateval.indexOf("-")>=0) datesep="-"
  212. else if (dateval.indexOf(".")>=0) datesep="."
  213. else if (dateval.indexOf("/")>=0) datesep="/"
  214. switch (userDateFormat) {
  215. case "yyyy-mm-dd" :
  216. dateelements[0]=dateval.substr(dateval.lastIndexOf(datesep)+1,dateval.length) //dd
  217. dateelements[1]=dateval.substring(dateval.indexOf(datesep)+1,dateval.lastIndexOf(datesep)) //mm
  218. dateelements[2]=dateval.substring(0,dateval.indexOf(datesep)) //yyyyy
  219. break;
  220. case "mm-dd-yyyy" :
  221. dateelements[0]=dateval.substring(dateval.indexOf(datesep)+1,dateval.lastIndexOf(datesep))
  222. dateelements[1]=dateval.substring(0,dateval.indexOf(datesep))
  223. dateelements[2]=dateval.substr(dateval.lastIndexOf(datesep)+1,dateval.length)
  224. break;
  225. case "dd-mm-yyyy" :
  226. dateelements[0]=dateval.substring(0,dateval.indexOf(datesep))
  227. dateelements[1]=dateval.substring(dateval.indexOf(datesep)+1,dateval.lastIndexOf(datesep))
  228. dateelements[2]=dateval.substr(dateval.lastIndexOf(datesep)+1,dateval.length)
  229. }
  230. return dateelements;
  231. }
  232. function compareDates(date1,fldLabel1,date2,fldLabel2,type) {
  233. var ret=true
  234. switch (type) {
  235. case 'L' : if (date1>=date2) {//DATE1 VALUE LESS THAN DATE2
  236. alert(fldLabel1+ alert_arr.SHOULDBE_LESS +fldLabel2)
  237. ret=false
  238. }
  239. break;
  240. case 'LE' : if (date1>date2) {//DATE1 VALUE LESS THAN OR EQUAL TO DATE2
  241. alert(fldLabel1+alert_arr.SHOULDBE_LESS_EQUAL+fldLabel2)
  242. ret=false
  243. }
  244. break;
  245. case 'E' : if (date1!=date2) {//DATE1 VALUE EQUAL TO DATE
  246. alert(fldLabel1+alert_arr.SHOULDBE_EQUAL+fldLabel2)
  247. ret=false
  248. }
  249. break;
  250. case 'G' : if (date1<=date2) {//DATE1 VALUE GREATER THAN DATE2
  251. alert(fldLabel1+alert_arr.SHOULDBE_GREATER+fldLabel2)
  252. ret=false
  253. }
  254. break;
  255. case 'GE' : if (date1<date2) {//DATE1 VALUE GREATER THAN OR EQUAL TO DATE2
  256. alert(fldLabel1+alert_arr.SHOULDBE_GREATER_EQUAL+fldLabel2)
  257. ret=false
  258. }
  259. break;
  260. }
  261. if (ret==false) return false
  262. else return true
  263. }
  264. function dateTimeValidate(dateFldName,timeFldName,fldLabel,type) {
  265. if(patternValidate(dateFldName,fldLabel,"DATE")==false)
  266. return false;
  267. dateval=getObj(dateFldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  268. var dateelements=splitDateVal(dateval)
  269. dd=dateelements[0]
  270. mm=dateelements[1]
  271. yyyy=dateelements[2]
  272. if (dd<1 || dd>31 || mm<1 || mm>12 || yyyy<1 || yyyy<1000) {
  273. alert(alert_arr.ENTER_VALID+fldLabel)
  274. try { getObj(dateFldName).focus() } catch(error) { }
  275. return false
  276. }
  277. if ((mm==2) && (dd>29)) {//checking of no. of days in february month
  278. alert(alert_arr.ENTER_VALID+fldLabel)
  279. try { getObj(dateFldName).focus() } catch(error) { }
  280. return false
  281. }
  282. if ((mm==2) && (dd>28) && ((yyyy%4)!=0)) {//leap year checking
  283. alert(alert_arr.ENTER_VALID+fldLabel)
  284. try { getObj(dateFldName).focus() } catch(error) { }
  285. return false
  286. }
  287. switch (parseInt(mm)) {
  288. case 2 :
  289. case 4 :
  290. case 6 :
  291. case 9 :
  292. case 11 : if (dd>30) {
  293. alert(alert_arr.ENTER_VALID+fldLabel)
  294. try { getObj(dateFldName).focus() } catch(error) { }
  295. return false
  296. }
  297. }
  298. if (patternValidate(timeFldName,fldLabel,"TIME")==false)
  299. return false
  300. var timeval=getObj(timeFldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  301. var hourval=parseInt(timeval.substring(0,timeval.indexOf(":")))
  302. var minval=parseInt(timeval.substring(timeval.indexOf(":")+1,timeval.length))
  303. var currObj=getObj(timeFldName)
  304. if (hourval>23 || minval>59) {
  305. alert(alert_arr.ENTER_VALID+fldLabel)
  306. try { currObj.focus() } catch(error) { }
  307. return false
  308. }
  309. var currdate=new Date()
  310. var chkdate=new Date()
  311. chkdate.setYear(yyyy)
  312. chkdate.setMonth(mm-1)
  313. chkdate.setDate(dd)
  314. chkdate.setHours(hourval)
  315. chkdate.setMinutes(minval)
  316. if (type!="OTH") {
  317. if (!compareDates(chkdate,fldLabel,currdate,"current date & time",type)) {
  318. try { getObj(dateFldName).focus() } catch(error) { }
  319. return false
  320. } else return true;
  321. } else return true;
  322. }
  323. function dateTimeComparison(dateFldName1,timeFldName1,fldLabel1,dateFldName2,timeFldName2,fldLabel2,type) {
  324. var dateval1=getObj(dateFldName1).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  325. var dateval2=getObj(dateFldName2).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  326. var dateelements1=splitDateVal(dateval1)
  327. var dateelements2=splitDateVal(dateval2)
  328. dd1=dateelements1[0]
  329. mm1=dateelements1[1]
  330. yyyy1=dateelements1[2]
  331. dd2=dateelements2[0]
  332. mm2=dateelements2[1]
  333. yyyy2=dateelements2[2]
  334. var timeval1=getObj(timeFldName1).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  335. var timeval2=getObj(timeFldName2).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  336. var hh1=timeval1.substring(0,timeval1.indexOf(":"))
  337. var min1=timeval1.substring(timeval1.indexOf(":")+1,timeval1.length)
  338. var hh2=timeval2.substring(0,timeval2.indexOf(":"))
  339. var min2=timeval2.substring(timeval2.indexOf(":")+1,timeval2.length)
  340. var date1=new Date()
  341. var date2=new Date()
  342. date1.setYear(yyyy1)
  343. date1.setMonth(mm1-1)
  344. date1.setDate(dd1)
  345. date1.setHours(hh1)
  346. date1.setMinutes(min1)
  347. date2.setYear(yyyy2)
  348. date2.setMonth(mm2-1)
  349. date2.setDate(dd2)
  350. date2.setHours(hh2)
  351. date2.setMinutes(min2)
  352. if (type!="OTH") {
  353. if (!compareDates(date1,fldLabel1,date2,fldLabel2,type)) {
  354. try { getObj(dateFldName1).focus() } catch(error) { }
  355. return false
  356. } else return true;
  357. } else return true;
  358. }
  359. function dateValidate(fldName,fldLabel,type) {
  360. if(patternValidate(fldName,fldLabel,"DATE")==false)
  361. return false;
  362. dateval=getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  363. var dateelements=splitDateVal(dateval)
  364. dd=dateelements[0]
  365. mm=dateelements[1]
  366. yyyy=dateelements[2]
  367. if (dd<1 || dd>31 || mm<1 || mm>12 || yyyy<1 || yyyy<1000) {
  368. alert(alert_arr.ENTER_VALID+fldLabel)
  369. try { getObj(fldName).focus() } catch(error) { }
  370. return false
  371. }
  372. if ((mm==2) && (dd>29)) {//checking of no. of days in february month
  373. alert(alert_arr.ENTER_VALID+fldLabel)
  374. try { getObj(fldName).focus() } catch(error) { }
  375. return false
  376. }
  377. if ((mm==2) && (dd>28) && ((yyyy%4)!=0)) {//leap year checking
  378. alert(alert_arr.ENTER_VALID+fldLabel)
  379. try { getObj(fldName).focus() } catch(error) { }
  380. return false
  381. }
  382. switch (parseInt(mm)) {
  383. case 2 :
  384. case 4 :
  385. case 6 :
  386. case 9 :
  387. case 11 : if (dd>30) {
  388. alert(alert_arr.ENTER_VALID+fldLabel)
  389. try { getObj(fldName).focus() } catch(error) { }
  390. return false
  391. }
  392. }
  393. var currdate=new Date()
  394. var chkdate=new Date()
  395. chkdate.setYear(yyyy)
  396. chkdate.setMonth(mm-1)
  397. chkdate.setDate(dd)
  398. if (type!="OTH") {
  399. if (!compareDates(chkdate,fldLabel,currdate,"current date",type)) {
  400. try { getObj(fldName).focus() } catch(error) { }
  401. return false
  402. } else return true;
  403. } else return true;
  404. }
  405. function dateComparison(fldName1,fldLabel1,fldName2,fldLabel2,type) {
  406. var dateval1=getObj(fldName1).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  407. var dateval2=getObj(fldName2).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  408. var dateelements1=splitDateVal(dateval1)
  409. var dateelements2=splitDateVal(dateval2)
  410. dd1=dateelements1[0]
  411. mm1=dateelements1[1]
  412. yyyy1=dateelements1[2]
  413. dd2=dateelements2[0]
  414. mm2=dateelements2[1]
  415. yyyy2=dateelements2[2]
  416. var date1=new Date()
  417. var date2=new Date()
  418. date1.setYear(yyyy1)
  419. date1.setMonth(mm1-1)
  420. date1.setDate(dd1)
  421. date2.setYear(yyyy2)
  422. date2.setMonth(mm2-1)
  423. date2.setDate(dd2)
  424. if (type!="OTH") {
  425. if (!compareDates(date1,fldLabel1,date2,fldLabel2,type)) {
  426. try { getObj(fldName1).focus() } catch(error) { }
  427. return false
  428. } else return true;
  429. } else return true
  430. }
  431. function timeValidate(fldName,fldLabel,type) {
  432. if (patternValidate(fldName,fldLabel,"TIME")==false)
  433. return false
  434. var timeval=getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  435. var hourval=parseInt(timeval.substring(0,timeval.indexOf(":")))
  436. var minval=parseInt(timeval.substring(timeval.indexOf(":")+1,timeval.length))
  437. var currObj=getObj(fldName)
  438. if (hourval>23 || minval>59) {
  439. alert(alert_arr.ENTER_VALID+fldLabel)
  440. try { currObj.focus() } catch(error) { }
  441. return false
  442. }
  443. var currtime=new Date()
  444. var chktime=new Date()
  445. chktime.setHours(hourval)
  446. chktime.setMinutes(minval)
  447. if (type!="OTH") {
  448. if (!compareDates(chktime,fldLabel,currtime,"current time",type)) {
  449. try { getObj(fldName).focus() } catch(error) { }
  450. return false
  451. } else return true;
  452. } else return true
  453. }
  454. function timeComparison(fldName1,fldLabel1,fldName2,fldLabel2,type) {
  455. var timeval1=getObj(fldName1).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  456. var timeval2=getObj(fldName2).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  457. var hh1=timeval1.substring(0,timeval1.indexOf(":"))
  458. var min1=timeval1.substring(timeval1.indexOf(":")+1,timeval1.length)
  459. var hh2=timeval2.substring(0,timeval2.indexOf(":"))
  460. var min2=timeval2.substring(timeval2.indexOf(":")+1,timeval2.length)
  461. var time1=new Date()
  462. var time2=new Date()
  463. //added to fix the ticket #5028
  464. if(fldName1 == "time_end" && (getObj("due_date") && getObj("date_start")))
  465. {
  466. var due_date=getObj("due_date").value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  467. var start_date=getObj("date_start").value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  468. dateval1 = splitDateVal(due_date);
  469. dateval2 = splitDateVal(start_date);
  470. dd1 = dateval1[0];
  471. mm1 = dateval1[1];
  472. yyyy1 = dateval1[2];
  473. dd2 = dateval2[0];
  474. mm2 = dateval2[1];
  475. yyyy2 = dateval2[2];
  476. time1.setYear(yyyy1)
  477. time1.setMonth(mm1-1)
  478. time1.setDate(dd1)
  479. time2.setYear(yyyy2)
  480. time2.setMonth(mm2-1)
  481. time2.setDate(dd2)
  482. }
  483. //end
  484. time1.setHours(hh1)
  485. time1.setMinutes(min1)
  486. time2.setHours(hh2)
  487. time2.setMinutes(min2)
  488. if (type!="OTH") {
  489. if (!compareDates(time1,fldLabel1,time2,fldLabel2,type)) {
  490. try { getObj(fldName1).focus() } catch(error) { }
  491. return false
  492. } else return true;
  493. } else return true;
  494. }
  495. function numValidate(fldName,fldLabel,format,neg) {
  496. var val=getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  497. if (format!="any") {
  498. if (isNaN(val)) {
  499. var invalid=true
  500. } else {
  501. var format=format.split(",")
  502. var splitval=val.split(".")
  503. if (neg==true) {
  504. if (splitval[0].indexOf("-")>=0) {
  505. if (splitval[0].length-1>format[0])
  506. invalid=true
  507. } else {
  508. if (splitval[0].length>format[0])
  509. invalid=true
  510. }
  511. } else {
  512. if (val<0)
  513. invalid=true
  514. else if (format[0]==2 && splitval[0]==100 && (!splitval[1] || splitval[1]==0))
  515. invalid=false
  516. else if (splitval[0].length>format[0])
  517. invalid=true
  518. }
  519. if (splitval[1])
  520. if (splitval[1].length>format[1])
  521. invalid=true
  522. }
  523. if (invalid==true) {
  524. alert(alert_arr.INVALID+fldLabel)
  525. try { getObj(fldName).focus() } catch(error) { }
  526. return false
  527. } else return true
  528. } else {
  529. // changes made -- to fix the ticket#3272
  530. var splitval=val.split(".")
  531. var arr_len = splitval.length;
  532. var len = 0;
  533. if(fldName == "probability" || fldName == "commissionrate")
  534. {
  535. if(arr_len > 1)
  536. len = splitval[1].length;
  537. if(isNaN(val))
  538. {
  539. alert(alert_arr.INVALID+fldLabel)
  540. try { getObj(fldName).focus() } catch(error) { }
  541. return false
  542. }
  543. else if(splitval[0] > 100 || len > 3 || (splitval[0] >= 100 && splitval[1] > 0))
  544. {
  545. alert( fldLabel + alert_arr.EXCEEDS_MAX);
  546. return false;
  547. }
  548. }
  549. else if(splitval[0]>18446744073709551615)
  550. {
  551. alert( fldLabel + alert_arr.EXCEEDS_MAX);
  552. return false;
  553. }
  554. if (neg==true)
  555. var re=/^(-|)(\d)*(\.)?\d+(\.\d\d*)*$/
  556. else
  557. var re=/^(\d)*(\.)?\d+(\.\d\d*)*$/
  558. }
  559. //for precision check. ie.number must contains only one "."
  560. var dotcount=0;
  561. for (var i = 0; i < val.length; i++)
  562. {
  563. if (val.charAt(i) == ".")
  564. dotcount++;
  565. }
  566. if(dotcount>1)
  567. {
  568. alert(alert_arr.INVALID+fldLabel)
  569. try { getObj(fldName).focus() } catch(error) { }
  570. return false;
  571. }
  572. if (!re.test(val)) {
  573. alert(alert_arr.INVALID+fldLabel)
  574. try { getObj(fldName).focus() } catch(error) { }
  575. return false
  576. } else return true
  577. }
  578. function intValidate(fldName,fldLabel) {
  579. var val=getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  580. if (isNaN(val) || (val.indexOf(".")!=-1 && fldName != 'potential_amount' && fldName != 'list_price'))
  581. {
  582. alert(alert_arr.INVALID+fldLabel)
  583. try { getObj(fldName).focus() } catch(error) { }
  584. return false
  585. }
  586. else if((fldName != 'employees' || fldName != 'noofemployees') && (val < -2147483648 || val > 2147483647))
  587. {
  588. alert(fldLabel +alert_arr.OUT_OF_RANGE);
  589. return false;
  590. }
  591. else if((fldName == 'employees' || fldName != 'noofemployees') && (val < 0 || val > 2147483647))
  592. {
  593. alert(fldLabel +alert_arr.OUT_OF_RANGE);
  594. return false;
  595. }
  596. else
  597. {
  598. return true
  599. }
  600. }
  601. function numConstComp(fldName,fldLabel,type,constval) {
  602. var val=parseFloat(getObj(fldName).value.replace(/^\s+/g, '').replace(/\s+$/g, ''))
  603. constval=parseFloat(constval)
  604. var ret=true
  605. switch (type) {
  606. case "L" : if (val>=constval) {
  607. alert(fldLabel+alert_arr.SHOULDBE_LESS+constval)
  608. ret=false
  609. }
  610. break;
  611. case "LE" : if (val>constval) {
  612. alert(fldLabel+alert_arr.SHOULDBE_LESS_EQUAL+constval)
  613. ret=false
  614. }
  615. break;
  616. case "E" : if (val!=constval) {
  617. alert(fldLabel+alert_arr.SHOULDBE_EQUAL+constval)
  618. ret=false
  619. }
  620. break;
  621. case "NE" : if (val==constval) {
  622. alert(fldLabel+alert_arr.SHOULDNOTBE_EQUAL+constval)
  623. ret=false
  624. }
  625. break;
  626. case "G" : if (val<=constval) {
  627. alert(fldLabel+alert_arr.SHOULDBE_GREATER+constval)
  628. ret=false
  629. }
  630. break;
  631. case "GE" : if (val<constval) {
  632. alert(fldLabel+alert_arr.SHOULDBE_GREATER_EQUAL+constval)
  633. ret=false
  634. }
  635. break;
  636. }
  637. if (ret==false) {
  638. try { getObj(fldName).focus() } catch(error) { }
  639. return false
  640. } else return true;
  641. }
  642. /* To get only filename from a given complete file path */
  643. function getFileNameOnly(filename) {
  644. var onlyfilename = filename;
  645. // Normalize the path (to make sure we use the same path separator)
  646. var filename_normalized = filename.replace(/\\/g, '/');
  647. if(filename_normalized.lastIndexOf("/") != -1) {
  648. onlyfilename = filename_normalized.substring(filename_normalized.lastIndexOf("/") + 1);
  649. }
  650. return onlyfilename;
  651. }
  652. /* Function to validate the filename */
  653. function validateFilename(form_ele) {
  654. if (form_ele.value == '') return true;
  655. var value = getFileNameOnly(form_ele.value);
  656. // Color highlighting logic
  657. var err_bg_color = "#FFAA22";
  658. if (typeof(form_ele.bgcolor) == "undefined") {
  659. form_ele.bgcolor = form_ele.style.backgroundColor;
  660. }
  661. // Validation starts here
  662. var valid = true;
  663. /* Filename length is constrained to 255 at database level */
  664. if (value.length > 255) {
  665. alert(alert_arr.LBL_FILENAME_LENGTH_EXCEED_ERR);
  666. valid = false;
  667. }
  668. if (!valid) {
  669. form_ele.style.backgroundColor = err_bg_color;
  670. return false;
  671. }
  672. form_ele.style.backgroundColor = form_ele.bgcolor;
  673. form_ele.form[form_ele.name + '_hidden'].value = value;
  674. return true;
  675. }
  676. function formValidate(){
  677. return doformValidation('');
  678. }
  679. function massEditFormValidate(){
  680. return doformValidation('mass_edit');
  681. }
  682. function doformValidation(edit_type) {
  683. //Validation for Portal User
  684. if(gVTModule == 'Contacts' && gValidationCall != 'tabchange')
  685. {
  686. //if existing portal value = 0, portal checkbox = checked, ( email field is not available OR email is empty ) then we should not allow -- OR --
  687. //if existing portal value = 1, portal checkbox = checked, ( email field is available AND email is empty ) then we should not allow
  688. if(edit_type=='')
  689. {
  690. if(getObj('existing_portal') != null
  691. && ((getObj('existing_portal').value == 0 && getObj('portal').checked &&
  692. (getObj('email') == null || trim(getObj('email').value) == '')) ||
  693. (getObj('existing_portal').value == 1 && getObj('portal').checked &&
  694. getObj('email') != null && trim(getObj('email').value) == ''))) {
  695. alert(alert_arr.PORTAL_PROVIDE_EMAILID);
  696. return false;
  697. }
  698. }
  699. else
  700. {
  701. if(getObj('portal') != null && getObj('portal').checked && getObj('portal_mass_edit_check').checked && (getObj('email') == null || trim(getObj('email').value) == '' || getObj('email_mass_edit_check').checked==false))
  702. {
  703. alert(alert_arr.PORTAL_PROVIDE_EMAILID);
  704. return false;
  705. }
  706. if((getObj('email') != null && trim(getObj('email').value) == '' && getObj('email_mass_edit_check').checked) && !(getObj('portal').checked==false && getObj('portal_mass_edit_check').checked))
  707. {
  708. alert(alert_arr.EMAIL_CHECK_MSG);
  709. return false;
  710. }
  711. }
  712. }
  713. if(gVTModule == 'SalesOrder') {
  714. if(edit_type == 'mass_edit') {
  715. if (getObj('enable_recurring_mass_edit_check') != null
  716. && getObj('enable_recurring_mass_edit_check').checked
  717. && getObj('enable_recurring') != null) {
  718. if(getObj('enable_recurring').checked && (getObj('recurring_frequency') == null
  719. || trim(getObj('recurring_frequency').value) == '--None--' || getObj('recurring_frequency_mass_edit_check').checked==false)) {
  720. alert(alert_arr.RECURRING_FREQUENCY_NOT_PROVIDED);
  721. return false;
  722. }
  723. if(getObj('enable_recurring').checked == false && getObj('recurring_frequency_mass_edit_check').checked
  724. && getObj('recurring_frequency') != null && trim(getObj('recurring_frequency').value) != '--None--') {
  725. alert(alert_arr.RECURRING_FREQNECY_NOT_ENABLED);
  726. return false;
  727. }
  728. }
  729. } else if(getObj('enable_recurring') != null && getObj('enable_recurring').checked) {
  730. if(getObj('recurring_frequency') == null || getObj('recurring_frequency').value == '--None--') {
  731. alert(alert_arr.RECURRING_FREQUENCY_NOT_PROVIDED);
  732. return false;
  733. }
  734. var start_period = getObj('start_period');
  735. var end_period = getObj('end_period');
  736. if (trim(start_period.value) == '' || trim(end_period.value) == '') {
  737. alert(alert_arr.START_PERIOD_END_PERIOD_CANNOT_BE_EMPTY);
  738. return false;
  739. }
  740. }
  741. }
  742. for (var i=0; i<fieldname.length; i++) {
  743. if(edit_type == 'mass_edit') {
  744. if(fieldname[i]!='salutationtype')
  745. var obj = getObj(fieldname[i]+"_mass_edit_check");
  746. if(obj == null || obj.checked == false) continue;
  747. }
  748. if(getObj(fieldname[i]) != null)
  749. {
  750. var type=fielddatatype[i].split("~")
  751. if (type[1]=="M") {
  752. if (!emptyCheck(fieldname[i],fieldlabel[i],getObj(fieldname[i]).type))
  753. return false;
  754. }
  755. switch (type[0]) {
  756. case "O" : break;
  757. case "V" : break;
  758. case "C" : break;
  759. case "DT" :
  760. if (getObj(fieldname[i]) != null && getObj(fieldname[i]).value.replace(/^\s+/g, '').replace(/\s+$/g, '').length!=0)
  761. {
  762. if (type[1]=="M")
  763. if (!emptyCheck(fieldname[2],fieldlabel[i],getObj(type[2]).type))
  764. return false
  765. if(typeof(type[3])=="undefined") var currdatechk="OTH"
  766. else var currdatechk=type[3]
  767. if (!dateTimeValidate(fieldname[i],type[2],fieldlabel[i],currdatechk))
  768. return false
  769. if (type[4]) {
  770. if (!dateTimeComparison(fieldname[i],type[2],fieldlabel[i],type[5],type[6],type[4]))
  771. return false
  772. }
  773. }
  774. break;
  775. case "D" :
  776. if (getObj(fieldname[i]) != null && getObj(fieldname[i]).value.replace(/^\s+/g, '').replace(/\s+$/g, '').length!=0)
  777. {
  778. if(typeof(type[2])=="undefined") var currdatechk="OTH"
  779. else var currdatechk=type[2]
  780. if (!dateValidate(fieldname[i],fieldlabel[i],currdatechk))
  781. return false
  782. if (type[3]) {
  783. if(gVTModule == 'SalesOrder' && fieldname[i] == 'end_period'
  784. && (getObj('enable_recurring') == null || getObj('enable_recurring').checked == false)) {
  785. continue;
  786. }
  787. if (!dateComparison(fieldname[i],fieldlabel[i],type[4],type[5],type[3]))
  788. return false
  789. }
  790. }
  791. break;
  792. case "T" :
  793. if (getObj(fieldname[i]) != null && getObj(fieldname[i]).value.replace(/^\s+/g, '').replace(/\s+$/g, '').length!=0)
  794. {
  795. if(typeof(type[2])=="undefined") var currtimechk="OTH"
  796. else var currtimechk=type[2]
  797. if (!timeValidate(fieldname[i],fieldlabel[i],currtimechk))
  798. return false
  799. if (type[3]) {
  800. if (!timeComparison(fieldname[i],fieldlabel[i],type[4],type[5],type[3]))
  801. return false
  802. }
  803. }
  804. break;
  805. case "I" :
  806. if (getObj(fieldname[i]) != null && getObj(fieldname[i]).value.replace(/^\s+/g, '').replace(/\s+$/g, '').length!=0)
  807. {
  808. if (getObj(fieldname[i]).value.length!=0)
  809. {
  810. if (!intValidate(fieldname[i],fieldlabel[i]))
  811. return false
  812. if (type[2]) {
  813. if (!numConstComp(fieldname[i],fieldlabel[i],type[2],type[3]))
  814. return false
  815. }
  816. }
  817. }
  818. break;
  819. case "N" :
  820. case "NN" :
  821. if (getObj(fieldname[i]) != null && getObj(fieldname[i]).value.replace(/^\s+/g, '').replace(/\s+$/g, '').length!=0)
  822. {
  823. if (getObj(fieldname[i]).value.length!=0)
  824. {
  825. if (typeof(type[2])=="undefined") var numformat="any"
  826. else var numformat=type[2]
  827. if(type[0]=="NN")
  828. {
  829. if (!numValidate(fieldname[i],fieldlabel[i],numformat,true))
  830. return false
  831. }
  832. else if (!numValidate(fieldname[i],fieldlabel[i],numformat))
  833. return false
  834. if (type[3]) {
  835. if (!numConstComp(fieldname[i],fieldlabel[i],type[3],type[4]))
  836. return false
  837. }
  838. }
  839. }
  840. break;
  841. case "E" :
  842. if (getObj(fieldname[i]) != null && getObj(fieldname[i]).value.replace(/^\s+/g, '').replace(/\s+$/g, '').length!=0)
  843. {
  844. if (getObj(fieldname[i]).value.length!=0)
  845. {
  846. var etype = "EMAIL"
  847. if(fieldname[i] == "yahooid" || fieldname[i] == "yahoo_id")
  848. {
  849. etype = "YAHOO";
  850. }
  851. if (!patternValidate(fieldname[i],fieldlabel[i],etype))
  852. return false;
  853. }
  854. }
  855. break;
  856. }
  857. //start Birth day date validation
  858. if(fieldname[i] == "birthday" && getObj(fieldname[i]).value.replace(/^\s+/g, '').replace(/\s+$/g, '').length!=0 )
  859. {
  860. var now =new Date()
  861. var currtimechk="OTH"
  862. var datelabel = fieldlabel[i]
  863. var datefield = fieldname[i]
  864. var datevalue =getObj(datefield).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  865. if (!dateValidate(fieldname[i],fieldlabel[i],currdatechk))
  866. {
  867. try { getObj(datefield).focus() } catch(error) { }
  868. return false
  869. }
  870. else
  871. {
  872. datearr=splitDateVal(datevalue);
  873. dd=datearr[0]
  874. mm=datearr[1]
  875. yyyy=datearr[2]
  876. var datecheck = new Date()
  877. datecheck.setYear(yyyy)
  878. datecheck.setMonth(mm-1)
  879. datecheck.setDate(dd)
  880. if (!compareDates(datecheck,datelabel,now,"Current Date","L"))
  881. {
  882. try { getObj(datefield).focus() } catch(error) { }
  883. return false
  884. }
  885. }
  886. }
  887. //End Birth day
  888. }
  889. }
  890. if(gVTModule == 'Contacts')
  891. {
  892. if(getObj('imagename'))
  893. {
  894. if(getObj('imagename').value != '')
  895. {
  896. var image_arr = new Array();
  897. image_arr = (getObj('imagename').value).split(".");
  898. var image_arr_last_index = image_arr.length - 1;
  899. if(image_arr_last_index < 0) {
  900. alert(alert_arr.LBL_WRONG_IMAGE_TYPE);
  901. return false;
  902. }
  903. var image_ext = image_arr[image_arr_last_index].toLowerCase();
  904. if(image_ext == "jpeg" || image_ext == "png" || image_ext == "jpg" || image_ext == "pjpeg" || image_ext == "x-png" || image_ext == "gif")
  905. {
  906. return true;
  907. }
  908. else
  909. {
  910. alert(alert_arr.LBL_WRONG_IMAGE_TYPE);
  911. return false;
  912. }
  913. }
  914. }
  915. }
  916. //added to check Start Date & Time,if Activity Status is Planned.//start
  917. for (var j=0; j<fieldname.length; j++)
  918. {
  919. if(getObj(fieldname[j]) != null)
  920. {
  921. if(fieldname[j] == "date_start" || fieldname[j] == "task_date_start" )
  922. {
  923. var datelabel = fieldlabel[j]
  924. var datefield = fieldname[j]
  925. var startdatevalue = getObj(datefield).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  926. }
  927. if(fieldname[j] == "time_start" || fieldname[j] == "task_time_start")
  928. {
  929. var timelabel = fieldlabel[j]
  930. var timefield = fieldname[j]
  931. var timeval=getObj(timefield).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  932. }
  933. if(fieldname[j] == "eventstatus" || fieldname[j] == "taskstatus")
  934. {
  935. var statusvalue = getObj(fieldname[j]).value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  936. var statuslabel = fieldlabel[j++]
  937. }
  938. }
  939. }
  940. if(statusvalue == "Planned")
  941. {
  942. var dateelements=splitDateVal(startdatevalue)
  943. var hourval=parseInt(timeval.substring(0,timeval.indexOf(":")))
  944. var minval=parseInt(timeval.substring(timeval.indexOf(":")+1,timeval.length))
  945. dd=dateelements[0]
  946. mm=dateelements[1]
  947. yyyy=dateelements[2]
  948. var chkdate=new Date()
  949. chkdate.setYear(yyyy)
  950. chkdate.setMonth(mm-1)
  951. chkdate.setDate(dd)
  952. chkdate.setMinutes(minval)
  953. chkdate.setHours(hourval)
  954. if(!comparestartdate(chkdate)) return false;
  955. }//end
  956. // We need to enforce fileupload for internal type
  957. if(gVTModule == 'Documents') {
  958. if(getObj('filelocationtype').value == 'I') {
  959. if(getObj('filename_hidden').value == '') {
  960. alert(alert_arr.LBL_PLEASE_SELECT_FILE_TO_UPLOAD);
  961. return false;
  962. }
  963. }
  964. }
  965. return true
  966. }
  967. function clearId(fldName) {
  968. var currObj=getObj(fldName)
  969. currObj.value=""
  970. }
  971. function comparestartdate(chkdate)
  972. {
  973. var datObj = [];
  974. var ajxdate = "test";
  975. var url = "module=Calendar&action=CalendarAjax&file=CalendarCommon&fieldval="+ajxdate
  976. var currdate = new Date();
  977. new Ajax.Request(
  978. 'index.php',
  979. {
  980. queue: {position: 'end', scope: 'command'},
  981. method: 'post',
  982. postBody:url,
  983. onComplete: function(response)
  984. {
  985. datObj = eval(response.responseText);
  986. currdate.setFullYear(datObj[0].YEAR)
  987. currdate.setMonth(datObj[0].MONTH-1)
  988. currdate.setDate(datObj[0].DAY)
  989. currdate.setHours(datObj[0].HOUR)
  990. currdate.setMinutes(datObj[0].MINUTE)
  991. }
  992. }
  993. );
  994. return compareDates(chkdate,alert_arr.START_DATE_TIME,currdate,alert_arr.DATE_SHOULDNOT_PAST,"GE");
  995. }
  996. function showCalc(fldName) {
  997. var currObj=getObj(fldName)
  998. openPopUp("calcWin",currObj,"/crm/Calc.do?currFld="+fldName,"Calc",170,220,"menubar=no,toolbar=no,location=no,status=no,scrollbars=no,resizable=yes")
  999. }
  1000. function showLookUp(fldName,fldId,fldLabel,searchmodule,hostName,serverPort,username) {
  1001. var currObj=getObj(fldName)
  1002. //var fldValue=currObj.value.replace(/^\s+/g, '').replace(/\s+$/g, '')
  1003. //need to pass the name of the system in which the server is running so that even when the search is invoked from another system, the url will remain the same
  1004. openPopUp("lookUpWin",currObj,"/crm/Search.do?searchmodule="+searchmodule+"&fldName="+fldName+"&fldId="+fldId+"&fldLabel="+fldLabel+"&fldValue=&user="+username,"LookUp",500,400,"menubar=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable=yes")
  1005. }
  1006. function openPopUp(winInst,currObj,baseURL,winName,width,height,features) {
  1007. var left=parseInt(findPosX(currObj))
  1008. var top=parseInt(findPosY(currObj))
  1009. if (window.navigator.appName!="Opera") top+=parseInt(currObj.offsetHeight)
  1010. else top+=(parseInt(currObj.offsetHeight)*2)+10
  1011. if (browser_ie) {
  1012. top+=window.screenTop-document.body.scrollTop
  1013. left-=document.body.scrollLeft
  1014. if (top+height+30>window.screen.height)
  1015. top=findPosY(currObj)+window.screenTop-height-30 //30 is a constant to avoid positioning issue
  1016. if (left+width>window.screen.width)
  1017. left=findPosX(currObj)+window.screenLeft-width
  1018. } else if (browser_nn4 || browser_nn6) {
  1019. top+=(scrY-pgeY)
  1020. left+=(scrX-pgeX)
  1021. if (top+height+30>window.screen.height)
  1022. top=findPosY(currObj)+(scrY-pgeY)-height-30
  1023. if (left+width>window.screen.width)
  1024. left=findPosX(currObj)+(scrX-pgeX)-width
  1025. }
  1026. features="width="+width+",height="+height+",top="+top+",left="+left+";"+features
  1027. eval(winInst+'=window.open("'+baseURL+'","'+winName+'","'+features+'")')
  1028. }
  1029. var scrX=0,scrY=0,pgeX=0,pgeY=0;
  1030. if (browser_nn4 || browser_nn6) {
  1031. document.addEventListener("click",popUpListener,true)
  1032. }
  1033. function popUpListener(ev) {
  1034. if (browser_nn4 || browser_nn6) {
  1035. scrX=ev.screenX
  1036. scrY=ev.screenY
  1037. pgeX=ev.pageX
  1038. pgeY=ev.pageY
  1039. }
  1040. }
  1041. function toggleSelect(state,relCheckName) {
  1042. if (getObj(relCheckName)) {
  1043. if (typeof(getObj(relCheckName).length)=="undefined") {
  1044. getObj(relCheckName).checked=state
  1045. } else {
  1046. for (var i=0;i<getObj(relCheckName).length;i++)
  1047. getObj(relCheckName)[i].checked=state
  1048. }
  1049. }
  1050. }
  1051. function toggleSelectAll(relCheckName,selectAllName) {
  1052. if (typeof(getObj(relCheckName).length)=="undefined") {
  1053. getObj(selectAllName).checked=getObj(relCheckName).checked
  1054. } else {
  1055. var atleastOneFalse=false;
  1056. for (var i=0;i<getObj(relCheckName).length;i++) {
  1057. if (getObj(relCheckName)[i].checked==false) {
  1058. atleastOneFalse=true
  1059. break;
  1060. }
  1061. }
  1062. getObj(selectAllName).checked=!atleastOneFalse
  1063. }
  1064. }
  1065. //added for show/hide 10July
  1066. function expandCont(bn)
  1067. {
  1068. var leftTab = document.getElementById(bn);
  1069. leftTab.style.display = (leftTab.style.display == "block")?"none":"block";
  1070. img = document.getElementById("img_"+bn);
  1071. img.src=(img.src.indexOf("images/toggle1.gif")!=-1)?"themes/images/toggle2.gif":"themes/images/toggle1.gif";
  1072. set_cookie_gen(bn,leftTab.style.display)
  1073. }
  1074. function setExpandCollapse_gen()
  1075. {
  1076. var x = leftpanelistarray.length;
  1077. for (i = 0 ; i < x ; i++)
  1078. {
  1079. var listObj=getObj(leftpanelistarray[i])
  1080. var tgImageObj=getObj("img_"+leftpanelistarray[i])
  1081. var status = get_cookie_gen(leftpanelistarray[i])
  1082. if (status == "block") {
  1083. listObj.style.display="block";
  1084. tgImageObj.src="themes/images/toggle2.gif";
  1085. } else if(status == "none") {
  1086. listObj.style.display="none";
  1087. tgImageObj.src="themes/images/toggle1.gif";
  1088. }
  1089. }
  1090. }
  1091. function toggleDiv(id) {
  1092. var listTableObj=getObj(id)
  1093. if (listTableObj.style.display=="block")
  1094. {
  1095. listTableObj.style.display="none"
  1096. }else{
  1097. listTableObj.style.display="block"
  1098. }
  1099. //set_cookie(id,listTableObj.style.display)
  1100. }
  1101. //Setting cookies
  1102. function set_cookie_gen ( name, value, exp_y, exp_m, exp_d, path, domain, secure )
  1103. {
  1104. var cookie_string = name + "=" + escape ( value );
  1105. if ( exp_y )
  1106. {
  1107. var expires = new Date ( exp_y, exp_m, exp_d );
  1108. cookie_string += "; expires=" + expires.toGMTString();
  1109. }
  1110. if ( path )
  1111. cookie_string += "; path=" + escape ( path );
  1112. if ( domain )
  1113. cookie_string += "; domain=" + escape ( domain );
  1114. if ( secure )
  1115. cookie_string += "; secure";
  1116. document.cookie = cookie_string;
  1117. }
  1118. // Retrieving cookies
  1119. function get_cookie_gen ( cookie_name )
  1120. {
  1121. var results = document.cookie.match ( cookie_name + '=(.*?)(;|$)' );
  1122. if ( results )
  1123. return ( unescape ( results[1] ) );
  1124. else
  1125. return null;
  1126. }
  1127. // Delete cookies
  1128. function delete_cookie_gen ( cookie_name )
  1129. {
  1130. var cookie_date = new Date ( ); // current date & time
  1131. cookie_date.setTime ( cookie_date.getTime() - 1 );
  1132. document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
  1133. }
  1134. //end added for show/hide 10July
  1135. /** This is Javascript Function which is used to toogle between
  1136. * assigntype user and group/team select options while assigning owner to entity.
  1137. */
  1138. function toggleAssignType(currType)
  1139. {
  1140. if (currType=="U")
  1141. {
  1142. getObj("assign_user").style.display="block"
  1143. getObj("assign_team").style.display="none"
  1144. }
  1145. else
  1146. {
  1147. getObj("assign_user").style.display="none"
  1148. getObj("assign_team").style.display="block"
  1149. }
  1150. }
  1151. //to display type of address for google map
  1152. function showLocateMapMenu()
  1153. {
  1154. getObj("dropDownMenu").style.display="block"
  1155. getObj("dropDownMenu").style.left=findPosX(getObj("locateMap"))
  1156. getObj("dropDownMenu").style.top=findPosY(getObj("locateMap"))+getObj("locateMap").offsetHeight
  1157. }
  1158. function hideLocateMapMenu(ev)
  1159. {
  1160. if (browser_ie)
  1161. currElement=window.event.srcElement
  1162. else if (browser_nn4 || browser_nn6)
  1163. currElement=ev.target
  1164. if (currElement.id!="locateMap")
  1165. if (getObj("dropDownMenu").style.display=="block")
  1166. getObj("dropDownMenu").style.display="none"
  1167. }
  1168. /*
  1169. * javascript function to display the div tag
  1170. * @param divId :: div tag ID
  1171. */
  1172. function show(divId)
  1173. {
  1174. if(getObj(divId))
  1175. {
  1176. var id = document.getElementById(divId);
  1177. id.style.display = 'inline';
  1178. }
  1179. }
  1180. /*
  1181. * javascript function to display the div tag
  1182. * @param divId :: div tag ID
  1183. */
  1184. function showBlock(divId)
  1185. {
  1186. var id = document.getElementById(divId);
  1187. id.style.display = 'block';
  1188. }
  1189. /*
  1190. * javascript function to hide the div tag
  1191. * @param divId :: div tag ID
  1192. */
  1193. function hide(divId)
  1194. {
  1195. var id = document.getElementById(divId);
  1196. id.style.display = 'none';
  1197. }
  1198. function fnhide(divId)
  1199. {
  1200. var id = document.getElementById(divId);
  1201. id.style.display = 'none';
  1202. }
  1203. function fnLoadValues(obj1,obj2,SelTab,unSelTab,moduletype,module){
  1204. var oform = document.forms['EditView'];
  1205. oform.action.value='Save';
  1206. //global variable to check the validation calling function to avoid validating when tab change
  1207. gValidationCall = 'tabchange';
  1208. /*var tabName1 = document.getElementById(obj1);
  1209. var tabName2 = document.getElementById(obj2);
  1210. var tagName1 = document.getElementById(SelTab);
  1211. var tagName2 = document.getElementById(unSelTab);
  1212. if(tabName1.className == "dvtUnSelectedCell")
  1213. tabName1.className = "dvtSelectedCell";
  1214. if(tabName2.className == "dvtSelectedCell")
  1215. tabName2.className = "dvtUnSelectedCell";
  1216. tagName1.style.display='block';
  1217. tagName2.style.display='none';*/
  1218. gValidationCall = 'tabchange';
  1219. // if((moduletype == 'inventory' && validateInventory(module)) ||(moduletype == 'normal') && formValidate())
  1220. // if(formValidate())
  1221. // {
  1222. var tabName1 = document.getElementById(obj1);
  1223. var tabName2 = document.getElementById(obj2);
  1224. var tagName1 = document.getElementById(SelTab);
  1225. var tagName2 = document.getElementById(unSelTab);
  1226. if(tabName1.className == "dvtUnSelectedCell")
  1227. tabName1.className = "dvtSelectedCell";
  1228. if(tabName2.className == "dvtSelectedCell")
  1229. tabName2.className = "dvtUnSelectedCell";
  1230. tagName1.style.display='block';
  1231. tagName2.style.display='none';
  1232. // }
  1233. gValidationCall = '';
  1234. }
  1235. function fnCopy(source,design){
  1236. document.getElementById(source).value=document.getElementById(design).value;
  1237. document.getElementById(source).disabled=true;
  1238. }
  1239. function fnClear(source){
  1240. document.getElementById(source).value=" ";
  1241. document.getElementById(source).disabled=false;
  1242. }
  1243. function fnCpy(){
  1244. var tagName=document.getElementById("cpy");
  1245. if(tagName.checked==true){
  1246. fnCopy("shipaddress","address");
  1247. fnCopy("shippobox","pobox");
  1248. fnCopy("shipcity","city");
  1249. fnCopy("shipcode","code");
  1250. fnCopy("shipstate","state");
  1251. fnCopy("shipcountry","country");
  1252. }
  1253. else{
  1254. fnClear("shipaddress");
  1255. fnClear("shippobox");
  1256. fnClear("shipcity");
  1257. fnClear("shipcode");
  1258. fnClear("shipstate");
  1259. fnClear("shipcountry");
  1260. }
  1261. }
  1262. function fnDown(obj){
  1263. var tagName = document.getElementById(obj);
  1264. var tabName = document.getElementById("one");
  1265. if(tagName.style.display == 'none'){
  1266. tagName.style.display = 'block';
  1267. tabName.style.display = 'block';
  1268. }
  1269. else{
  1270. tabName.style.display = 'none';
  1271. tagName.style.display = 'none';
  1272. }
  1273. }
  1274. /*
  1275. * javascript function to add field rows
  1276. * @param option_values :: List of Field names
  1277. */
  1278. var count = 0;
  1279. var rowCnt = 1;
  1280. function fnAddSrch(){
  1281. var tableName = document.getElementById('adSrc');
  1282. var prev = tableName.rows.length;
  1283. var count = prev;
  1284. var row = tableName.insertRow(prev);
  1285. if(count%2)
  1286. row.className = "dvtCellLabel";
  1287. else
  1288. row.className = "dvtCellInfo";
  1289. var fieldObject = document.getElementById("Fields0");
  1290. var conditionObject = document.getElementById("Condition0");
  1291. var searchValueObject = document.getElementById("Srch_value0");
  1292. var columnone = document.createElement('td');
  1293. var colone = fieldObject.cloneNode(true);
  1294. colone.setAttribute('id','Fields'+count);
  1295. colone.setAttribute('name','Fields'+count);
  1296. colone.setAttribute('value','');
  1297. colone.onchange = function() {
  1298. updatefOptions(colone, 'Condition'+count);
  1299. }
  1300. columnone.appendChild(colone);
  1301. row.appendChild(columnone);
  1302. var columntwo = document.createElement('td');
  1303. var coltwo = conditionObject.cloneNode(true);
  1304. coltwo.setAttribute('id','Condition'+count);
  1305. coltwo.setAttribute('name','Condition'+count);
  1306. coltwo.setAttribute('value','');
  1307. columntwo.appendChild(coltwo);
  1308. row.appendChild(columntwo);
  1309. var columnthree = document.createElement('td');
  1310. var colthree = searchValueObject.cloneNode(true);
  1311. colthree.setAttribute('id','Srch_value'+count);
  1312. colthree.setAttribute('name','Srch_value'+count);
  1313. colthree.setAttribute('value','');
  1314. colthree.value = '';
  1315. columnthree.appendChild(colthree);
  1316. row.appendChild(columnthree);
  1317. updatefOptions(colone, 'Condition'+count);
  1318. }
  1319. function totalnoofrows()
  1320. {
  1321. var tableName = document.getElementById('adSrc');
  1322. document.basicSearch.search_cnt.value = tableName.rows.length;
  1323. }
  1324. /*
  1325. * javascript function to delete field rows in advance search
  1326. * @param void :: void
  1327. */
  1328. function delRow()
  1329. {
  1330. var tableName = document.getElementById('adSrc');
  1331. var prev = tableName.rows.length;
  1332. if(prev > 1)
  1333. document.getElementById('adSrc').deleteRow(prev-1);
  1334. }
  1335. function fnVis(obj){
  1336. var profTag = document.getElementById("prof");
  1337. var moreTag = document.getElementById("more");
  1338. var addrTag = document.getElementById("addr");
  1339. if(obj == 'prof'){
  1340. document.getElementById('mnuTab').style.display = 'block';
  1341. document.getElementById('mnuTab1').style.display = 'none';
  1342. document.getElementById('mnuTab2').style.display = 'none';
  1343. profTag.className = 'dvtSelectedCell';
  1344. moreTag.className = 'dvtUnSelectedCell';
  1345. addrTag.className = 'dvtUnSelectedCell';
  1346. }
  1347. else if(obj == 'more'){
  1348. document.getElementById('mnuTab1').style.display = 'block';
  1349. document.getElementById('mnuTab').style.display = 'none';
  1350. document.getElementById('mnuTab2').style.display = 'none';
  1351. moreTag.className = 'dvtSelectedCell';
  1352. profTag.className = 'dvtUnSelectedCell';
  1353. addrTag.className = 'dvtUnSelectedCell';
  1354. }
  1355. else if(obj == 'addr'){
  1356. document.getElementById('mnuTab2').style.display = 'block';
  1357. document.getElementById('mnuTab').style.display = 'none';
  1358. document.getElementById('mnuTab1').style.display = 'none';
  1359. addrTag.className = 'dvtSelectedCell';
  1360. profTag.className = 'dvtUnSelectedCell';
  1361. moreTag.className = 'dvtUnSelectedCell';
  1362. }
  1363. }
  1364. function fnvsh(obj,Lay){
  1365. var tagName = document.getElementById(Lay);
  1366. var leftSide = findPosX(obj);
  1367. var topSide = findPosY(obj);
  1368. tagName.style.left= leftSide + 175 + 'px';
  1369. tagName.style.top= topSide + 'px';
  1370. tagName.style.visibility = 'visible';
  1371. }
  1372. function fnvshobj(obj,Lay){
  1373. var tagName = document.getElementById(Lay);
  1374. var leftSide = findPosX(obj);
  1375. var topSide = findPosY(obj);
  1376. var maxW = tagName.style.width;
  1377. var widthM = maxW.substring(0,maxW.length-2);
  1378. if(Lay == 'editdiv')
  1379. {
  1380. leftSide = leftSide - 225;
  1381. topSide = topSide - 125;
  1382. }else if(Lay == 'transferdiv')
  1383. {
  1384. leftSide = leftSide - 10;
  1385. topSide = topSide;
  1386. }
  1387. var IE = document.all?true:false;
  1388. if(IE)
  1389. {
  1390. if($("repposition1"))
  1391. {
  1392. if(topSide > 1200)
  1393. {
  1394. topSide = topSide-250;
  1395. }
  1396. }
  1397. }
  1398. var getVal = eval(leftSide) + eval(widthM);
  1399. if(getVal > document.body.clientWidth ){
  1400. leftSide = eval(leftSide) - eval(widthM);
  1401. tagName.style.left = leftSide + 34 + 'px';
  1402. }
  1403. else
  1404. tagName.style.left= leftSide + 'px';
  1405. tagName.style.top= topSide + 'px';
  1406. tagName.style.display = 'block';
  1407. tagName.style.visibility = "visible";
  1408. }
  1409. function posLay(obj,Lay){
  1410. var tagName = document.getElementById(Lay);
  1411. var leftSide = findPosX(obj);
  1412. var topSide = findPosY(obj);
  1413. var maxW = tagName.style.width;
  1414. var widthM = maxW.substring(0,maxW.length-2);
  1415. var getVal = eval(leftSide) + eval(widthM);
  1416. if(getVal > document.body.clientWidth ){
  1417. leftSide = eval(leftSide) - eval(widthM);
  1418. tagName.style.left = leftSide + 'px';
  1419. }
  1420. else
  1421. tagName.style.left= leftSide + 'px';
  1422. tagName.style.top= topSide + 'px';
  1423. }
  1424. function fninvsh(Lay){
  1425. var tagName = document.getElementById(Lay);
  1426. tagName.style.visibility = 'hidden';
  1427. tagName.style.display = 'none';
  1428. }
  1429. function fnvshNrm(Lay){
  1430. var tagName = document.getElementById(Lay);
  1431. tagName.style.visibility = 'visible';
  1432. tagName.style.display = 'block';
  1433. }
  1434. function cancelForm(frm)
  1435. {
  1436. window.history.back();
  1437. }
  1438. function trim(str)
  1439. {
  1440. var s = str.replace(/\s+$/,'');
  1441. s = s.replace(/^\s+/,'');
  1442. return s;
  1443. }
  1444. function clear_form(form)
  1445. {
  1446. for (j = 0; j < form.elements.length; j++)
  1447. {
  1448. if (form.elements[j].type == 'text' || form.elements[j].type == 'select-one')
  1449. {
  1450. form.elements[j].value = '';
  1451. }
  1452. }
  1453. }
  1454. function ActivateCheckBox()
  1455. {
  1456. var map = document.getElementById("saved_map_checkbox");
  1457. var source = document.getElementById("saved_source");
  1458. if(map.checked == true)
  1459. {
  1460. source.disabled = false;
  1461. }
  1462. else
  1463. {
  1464. source.disabled = true;
  1465. }
  1466. }
  1467. //wipe for Convert Lead
  1468. function fnSlide2(obj,inner)
  1469. {
  1470. var buff = document.getElementById(obj).height;
  1471. closeLimit = buff.substring(0,buff.length);
  1472. menu_max = eval(closeLimit);
  1473. var tagName = document.getElementById(inner);
  1474. document.getElementById(obj).style.height=0 + "px"; menu_i=0;
  1475. if (tagName.style.display == 'none')
  1476. fnexpanLay2(obj,inner);
  1477. else
  1478. fncloseLay2(obj,inner);
  1479. }
  1480. function fnexpanLay2(obj,inner)
  1481. {
  1482. // document.getElementById(obj).style.display = 'run-in';
  1483. var setText = eval(closeLimit) - 1;
  1484. if (menu_i<=eval(closeLimit))
  1485. {
  1486. if (menu_i>setText){document.getElementById(inner).style.display='block';}
  1487. document.getElementById(obj).style.height=menu_i + "px";
  1488. setTimeout(function() { fnexpanLay2(obj,inner); },5);
  1489. menu_i=menu_i+5;
  1490. }
  1491. }
  1492. function fncloseLay2(obj,inner)
  1493. {
  1494. if (menu_max >= eval(openLimit))
  1495. {
  1496. if (menu_max<eval(closeLimit)){document.getElementById(inner).style.display='none';}
  1497. document.getElementById(obj).style.height=menu_max +"px";
  1498. setTimeout(function() { fncloseLay2(obj,inner); }, 5);
  1499. menu_max = menu_max -5;
  1500. }
  1501. }
  1502. function addOnloadEvent(fnc){
  1503. if ( typeof window.addEventListener != "undefined" )
  1504. window.addEventListener( "load", fnc, false );
  1505. else if ( typeof window.attachEvent != "undefined" ) {
  1506. window.attachEvent( "onload", fnc );
  1507. }
  1508. else {
  1509. if ( window.onload != null ) {
  1510. var oldOnload = window.onload;
  1511. window.onload = function ( e ) {
  1512. oldOnload( e );
  1513. window[fnc]();
  1514. };
  1515. }
  1516. else
  1517. window.onload = fnc;
  1518. }
  1519. }
  1520. function InternalMailer(record_id,field_id,field_name,par_module,type) {
  1521. var url;
  1522. switch(type) {
  1523. case 'record_id':
  1524. url = 'index.php?module=Emails&action=EmailsAjax&internal_mailer=true&type='+type+'&field_id='+field_id+'&rec_id='+record_id+'&fieldname='+field_name+'&file=EditView&par_module='+par_module;//query string field_id added for listview-compose email issue
  1525. break;
  1526. case 'email_addy':
  1527. url = 'index.php?module=Emails&action=EmailsAjax&internal_mailer=true&type='+type+'&email_addy='+record_id+'&file=EditView';
  1528. break;
  1529. }
  1530. var opts = "menubar=no,toolbar=no,location=no,status=no,resizable=yes,scrollbars=yes";
  1531. openPopUp('xComposeEmail',this,url,'createemailWin',830,662,opts);
  1532. }
  1533. function fnHide_Event(obj){
  1534. document.getElementById(obj).style.visibility = 'hidden';
  1535. }
  1536. function ReplyCompose(id,mode)
  1537. {
  1538. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&record='+id+'&reply=true';
  1539. openPopUp('xComposeEmail',this,url,'createemailWin',820,689,'menubar=no,toolbar=no,location=no,status=no,resizable=no,scrollbars=yes');
  1540. }
  1541. function OpenCompose(id,mode)
  1542. {
  1543. switch(mode)
  1544. {
  1545. case 'edit':
  1546. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&record='+id;
  1547. break;
  1548. case 'create':
  1549. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView';
  1550. break;
  1551. case 'forward':
  1552. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&record='+id+'&forward=true';
  1553. break;
  1554. case 'Invoice':
  1555. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&attachment='+mode+'_'+id+'.pdf';
  1556. break;
  1557. case 'PurchaseOrder':
  1558. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&attachment='+mode+'_'+id+'.pdf';
  1559. break;
  1560. case 'SalesOrder':
  1561. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&attachment='+mode+'_'+id+'.pdf';
  1562. break;
  1563. case 'Quote':
  1564. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&attachment='+mode+'_'+id+'.pdf';
  1565. break;
  1566. case 'Documents':
  1567. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&attachment='+id+'';
  1568. break;
  1569. case 'print':
  1570. url = 'index.php?module=Emails&action=EmailsAjax&file=PrintEmail&record='+id+'&print=true';
  1571. }
  1572. openPopUp('xComposeEmail',this,url,'createemailWin',820,689,'menubar=no,toolbar=no,location=no,status=no,resizable=no,scrollbars=yes');
  1573. }
  1574. //crm-now: added multilang support for PDF attachments to quotes, oreders and invoices
  1575. function OpenComposePDF(id,mode,name)
  1576. {
  1577. switch(mode)
  1578. {
  1579. case 'Invoice':
  1580. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&attachment='+name+'_'+id+'.pdf';
  1581. break;
  1582. case 'PurchaseOrder':
  1583. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&attachment='+name+'_'+id+'.pdf';
  1584. break;
  1585. case 'SalesOrder':
  1586. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&attachment='+name+'_'+id+'.pdf';
  1587. break;
  1588. case 'Quote':
  1589. url = 'index.php?module=Emails&action=EmailsAjax&file=EditView&attachment='+name+'_'+id+'.pdf';
  1590. break;
  1591. }
  1592. openPopUp('xComposeEmail',this,url,'createemailWin',820,689,'menubar=no,toolbar=no,location=no,status=no,resizable=no,scrollbars=yes');
  1593. }
  1594. //Function added for Mass select in Popup - Philip
  1595. function SelectAll(mod,parmod)
  1596. {
  1597. if(document.selectall.selected_id != undefined)
  1598. {
  1599. x = document.selectall.selected_id.length;
  1600. var y=0;
  1601. if(parmod != 'Calendar')
  1602. {
  1603. var module = window.opener.document.getElementById('RLreturn_module').value
  1604. var entity_id = window.opener.document.getElementById('RLparent_id').value
  1605. var parenttab = window.opener.document.getElementById('parenttab').value
  1606. }
  1607. idstring = "";
  1608. namestr = "";
  1609. if ( x == undefined)
  1610. {
  1611. if (document.selectall.selected_id.checked)
  1612. {
  1613. idstring = document.selectall.selected_id.value;
  1614. if(parmod == 'Calendar')
  1615. namestr = document.getElementById('calendarCont'+idstring).innerHTML;
  1616. y=1;
  1617. }
  1618. else
  1619. {
  1620. alert(alert_arr.SELECT);
  1621. return false;
  1622. }
  1623. }
  1624. else
  1625. {
  1626. y=0;
  1627. for(i = 0; i < x ; i++)
  1628. {
  1629. if(document.selectall.selected_id[i].checked)
  1630. {
  1631. idstring = document.selectall.selected_id[i].value +";"+idstring;
  1632. if(parmod == 'Calendar')
  1633. {
  1634. idval = document.selectall.selected_id[i].value;
  1635. namestr = document.getElementById('calendarCont'+idval).innerHTML+"\n"+namestr;
  1636. }
  1637. y=y+1;
  1638. }
  1639. }
  1640. }
  1641. if (y != 0)
  1642. {
  1643. document.selectall.idlist.value=idstring;
  1644. }
  1645. else
  1646. {
  1647. alert(alert_arr.SELECT);
  1648. return false;
  1649. }
  1650. if(confirm(alert_arr.ADD_CONFIRMATION+y+alert_arr.RECORDS))
  1651. {
  1652. if(parmod == 'Calendar')
  1653. {
  1654. //this blcok has been modified to provide delete option for contact in Calendar
  1655. idval = window.opener.document.EditView.contactidlist.value;
  1656. if(idval != '')
  1657. {
  1658. var avalIds = new Array();
  1659. avalIds = idstring.split(';');
  1660. var selectedIds = new Array();
  1661. selectedIds = idval.split(';');
  1662. for(i=0; i < (avalIds.length-1); i++)
  1663. {
  1664. var rowFound=false;
  1665. for(k=0; k < selectedIds.length; k++)
  1666. {
  1667. if (selectedIds[k]==avalIds[i])
  1668. {
  1669. rowFound=true;
  1670. break;
  1671. }
  1672. }
  1673. if(rowFound != true)
  1674. {
  1675. idval = idval+';'+avalIds[i];
  1676. window.opener.document.EditView.contactidlist.value = idval;
  1677. var str=document.getElementById('calendarCont'+avalIds[i]).innerHTML;
  1678. window.opener.addOption(avalIds[i],str);
  1679. }
  1680. }
  1681. }
  1682. else
  1683. {
  1684. window.opener.document.EditView.contactidlist.value = idstring;
  1685. var temp = new Array();
  1686. temp = namestr.split('\n');
  1687. var tempids = new Array();
  1688. tempids = idstring.split(';');
  1689. for(k=0; k < temp.length; k++)
  1690. {
  1691. window.opener.addOption(tempids[k],temp[k]);
  1692. }
  1693. }
  1694. //end
  1695. }
  1696. else
  1697. {
  1698. opener.document.location.href="index.php?module="+module+"&parentid="+entity_id+"&action=updateRelations&destination_module="+mod+"&idlist="+idstring+"&parenttab="+parenttab;
  1699. }
  1700. self.close();
  1701. }
  1702. else
  1703. {
  1704. return false;
  1705. }
  1706. }
  1707. }
  1708. function ShowEmail(id)
  1709. {
  1710. url = 'index.php?module=Emails&action=EmailsAjax&file=DetailView&record='+id;
  1711. openPopUp('xComposeEmail',this,url,'createemailWin',820,695,'menubar=no,toolbar=no,location=no,status=no,resizable=no,scrollbars=yes');
  1712. }
  1713. var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
  1714. var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
  1715. var bMoz = (navigator.appName == 'Netscape');
  1716. function execJS(node) {
  1717. var st = node.getElementsByTagName('SCRIPT');
  1718. var strExec;
  1719. for(var i=0;i<st.length; i++) {
  1720. if (bSaf) {
  1721. strExec = st[i].innerHTML;
  1722. }
  1723. else if (bOpera) {
  1724. strExec = st[i].text;
  1725. }
  1726. else if (bMoz) {
  1727. strExec = st[i].textContent;
  1728. }
  1729. else {
  1730. strExec = st[i].text;
  1731. }
  1732. try {
  1733. eval(strExec);
  1734. } catch(e) {
  1735. alert(e);
  1736. }
  1737. }
  1738. }
  1739. //Function added for getting the Tab Selected Values (Standard/Advanced Filters) for Custom View - Ahmed
  1740. function fnLoadCvValues(obj1,obj2,SelTab,unSelTab){
  1741. var tabName1 = document.getElementById(obj1);
  1742. var tabName2 = document.getElementById(obj2);
  1743. var tagName1 = document.getElementById(SelTab);
  1744. var tagName2 = document.getElementById(unSelTab);
  1745. if(tabName1.className == "dvtUnSelectedCell")
  1746. tabName1.className = "dvtSelectedCell";
  1747. if(tabName2.className == "dvtSelectedCell")
  1748. tabName2.className = "dvtUnSelectedCell";
  1749. tagName1.style.display='block';
  1750. tagName2.style.display='none';
  1751. }
  1752. // Drop Dwon Menu
  1753. function fnDropDown(obj,Lay){
  1754. var tagName = document.getElementById(Lay);
  1755. var leftSide = findPosX(obj);
  1756. var topSide = findPosY(obj);
  1757. var maxW = tagName.style.width;
  1758. var widthM = maxW.substring(0,maxW.length-2);
  1759. var getVal = eval(leftSide) + eval(widthM);
  1760. if(getVal > document.body.clientWidth ){
  1761. leftSide = eval(leftSide) - eval(widthM);
  1762. tagName.style.left = leftSide + 34 + 'px';
  1763. }
  1764. else
  1765. tagName.style.left= leftSide + 'px';
  1766. tagName.style.top= topSide + 28 +'px';
  1767. tagName.style.display = 'block';
  1768. }
  1769. function fnShowDrop(obj){
  1770. document.getElementById(obj).style.display = 'block';
  1771. }
  1772. function fnHideDrop(obj){
  1773. document.getElementById(obj).style.display = 'none';
  1774. }
  1775. function getCalendarPopup(imageid,fieldid,dateformat)
  1776. {
  1777. Calendar.setup ({
  1778. inputField : fieldid, ifFormat : dateformat, showsTime : false, button : imageid, singleClick : true, step : 1
  1779. });
  1780. }
  1781. //Added to check duplicate account creation
  1782. function AjaxDuplicateValidate(module,fieldname,oform)
  1783. {
  1784. var fieldvalue = encodeURIComponent(trim(getObj(fieldname).value));
  1785. var recordid = getObj('record').value;
  1786. if(fieldvalue == '')
  1787. {
  1788. alert(alert_arr.ACCOUNTNAME_CANNOT_EMPTY);
  1789. return false;
  1790. }
  1791. VtigerJS_DialogBox.block();
  1792. var url = "module="+module+"&action="+module+"Ajax&file=Save&"+fieldname+"="+fieldvalue+"&dup_check=true&record="+recordid;
  1793. new Ajax.Request(
  1794. 'index.php',
  1795. {queue: {position: 'end', scope: 'command'},
  1796. method: 'post',
  1797. postBody:url,
  1798. onComplete: function(response) {
  1799. var str = response.responseText
  1800. if(str.indexOf('SUCCESS') > -1)
  1801. {
  1802. oform.submit();
  1803. }else
  1804. {
  1805. VtigerJS_DialogBox.unblock();
  1806. alert(str);
  1807. return false;
  1808. }
  1809. }
  1810. }
  1811. );
  1812. }
  1813. /**to get SelectContacts Popup
  1814. check->to check select options enable or disable
  1815. *type->to differentiate from task
  1816. *frmName->form name*/
  1817. function selectContact(check,type,frmName)
  1818. {
  1819. var record = document.getElementsByName("record")[0].value;
  1820. if($("single_accountid"))
  1821. {
  1822. var potential_id = '';
  1823. if($("potential_id"))
  1824. potential_id = frmName.potential_id.value;
  1825. account_id = frmName.account_id.value;
  1826. if(potential_id != '')
  1827. {
  1828. record_id = potential_id;
  1829. module_string = "&parent_module=Potentials";
  1830. }
  1831. else
  1832. {
  1833. record_id = account_id;
  1834. module_string = "&parent_module=Accounts";
  1835. }
  1836. if(record_id != '')
  1837. window.open("index.php?module=Contacts&action=Popup&html=Popup_picker&popuptype=specific&form=EditView"+module_string+"&relmod_id="+record_id,"test","width=640,height=602,resizable=0,scrollbars=0");
  1838. else
  1839. window.open("index.php?module=Contacts&action=Popup&html=Popup_picker&popuptype=specific&form=EditView","test","width=640,height=602,resizable=0,scrollbars=0");
  1840. }
  1841. else if(($("parentid")) && type != 'task')
  1842. {
  1843. if(getObj("parent_type")){
  1844. rel_parent_module = frmName.parent_type.value;
  1845. record_id = frmName.parent_id.value;
  1846. module = rel_parent_module.split("&");
  1847. if(record_id != '' && module[0] == "Leads")
  1848. {
  1849. alert(alert_arr.CANT_SELECT_CONTACTS);
  1850. }
  1851. else
  1852. {
  1853. if(check == 'true')
  1854. search_string = "&return_module=Calendar&select=enable&popuptype=detailview&form_submit=false";
  1855. else
  1856. search_string="&popuptype=specific";
  1857. if(record_id != '')
  1858. window.open("index.php?module=Contacts&action=Popup&html=Popup_picker&form=EditView"+search_string+"&relmod_id="+record_id+"&parent_module="+module[0],"test","width=640,height=602,resizable=0,scrollbars=0");
  1859. else
  1860. window.open("index.php?module=Contacts&action=Popup&html=Popup_picker&form=EditView"+search_string,"test","width=640,height=602,resizable=0,scrollbars=0");
  1861. }
  1862. }else{
  1863. window.open("index.php?module=Contacts&action=Popup&html=Popup_picker&return_module=Calendar&select=enable&popuptype=detailview&form=EditView&form_submit=false","test","width=640,height=602,resizable=0,scrollbars=0");
  1864. }
  1865. }
  1866. else if(($("contact_name")) && type == 'task')
  1867. {
  1868. var formName = frmName.name;
  1869. var task_recordid = '';
  1870. if(formName == 'EditView')
  1871. {
  1872. if($("parent_type"))
  1873. {
  1874. task_parent_module = frmName.parent_type.value;
  1875. task_recordid = frmName.parent_id.value;
  1876. task_module = task_parent_module.split("&");
  1877. popuptype="&popuptype=specific";
  1878. }
  1879. }
  1880. else
  1881. {
  1882. if($("task_parent_type"))
  1883. {
  1884. task_parent_module = frmName.task_parent_type.value;
  1885. task_recordid = frmName.task_parent_id.value;
  1886. task_module = task_parent_module.split("&");
  1887. popuptype="&popuptype=toDospecific";
  1888. }
  1889. }
  1890. if(task_recordid != '' && task_module[0] == "Leads" )
  1891. {
  1892. alert(alert_arr.CANT_SELECT_CONTACTS);
  1893. }
  1894. else
  1895. {
  1896. if(task_recordid != '')
  1897. window.open("index.php?module=Contacts&action=Popup&html=Popup_picker"+popuptype+"&form="+formName+"&task_relmod_id="+task_recordid+"&task_parent_module="+task_module[0],"test","width=640,height=602,resizable=0,scrollbars=0");
  1898. else
  1899. window.open("index.php?module=Contacts&action=Popup&html=Popup_picker&popuptype=specific&form="+formName,"test","width=640,height=602,resizable=0,scrollbars=0");
  1900. }
  1901. }
  1902. else
  1903. {
  1904. window.open("index.php?module=Contacts&action=Popup&html=Popup_picker&popuptype=specific&form=EditView&recordid="+record,"test","width=640,height=602,resizable=0,scrollbars=0");
  1905. }
  1906. }
  1907. //to get Select Potential Popup
  1908. function selectPotential()
  1909. {
  1910. // To support both B2B and B2C model
  1911. var record_id = '';
  1912. var parent_module = '';
  1913. var acc_element = document.EditView.account_id;
  1914. var cnt_element = document.EditView.contact_id;
  1915. if (acc_element != null) {
  1916. record_id= acc_element.value;
  1917. parent_module = 'Accounts';
  1918. } else if (cnt_element != null) {
  1919. record_id= cnt_element.value;
  1920. parent_module = 'Contacts';
  1921. }
  1922. if(record_id != '')
  1923. window.open("index.php?module=Potentials&action=Popup&html=Popup_picker&popuptype=specific_potential_account_address&form=EditView&relmod_id="+record_id+"&parent_module="+parent_module,"test","width=640,height=602,resizable=0,scrollbars=0");
  1924. else
  1925. window.open("index.php?module=Potentials&action=Popup&html=Popup_picker&popuptype=specific_potential_account_address&form=EditView","test","width=640,height=602,resizable=0,scrollbars=0");
  1926. }
  1927. //to select Quote Popup
  1928. function selectQuote()
  1929. {
  1930. // To support both B2B and B2C model
  1931. var record_id = '';
  1932. var parent_module = '';
  1933. var acc_element = document.EditView.account_id;
  1934. var cnt_element = document.EditView.contact_id;
  1935. if (acc_element != null) {
  1936. record_id= acc_element.value;
  1937. parent_module = 'Accounts';
  1938. } else if (cnt_element != null) {
  1939. record_id= cnt_element.value;
  1940. parent_module = 'Contacts';
  1941. }
  1942. if(record_id != '')
  1943. window.open("index.php?module=Quotes&action=Popup&html=Popup_picker&popuptype=specific&form=EditView&relmod_id="+record_id+"&parent_module="+parent_module,"test","width=640,height=602,resizable=0,scrollbars=0");
  1944. else
  1945. window.open("index.php?module=Quotes&action=Popup&html=Popup_picker&popuptype=specific&form=EditView","test","width=640,height=602,resizable=0,scrollbars=0");
  1946. }
  1947. //to get select SalesOrder Popup
  1948. function selectSalesOrder()
  1949. {
  1950. // To support both B2B and B2C model
  1951. var record_id = '';
  1952. var parent_module = '';
  1953. var acc_element = document.EditView.account_id;
  1954. var cnt_element = document.EditView.contact_id;
  1955. if (acc_element != null) {
  1956. record_id= acc_element.value;
  1957. parent_module = 'Accounts';
  1958. } else if (cnt_element != null) {
  1959. record_id= cnt_element.value;
  1960. parent_module = 'Contacts';
  1961. }
  1962. if(record_id != '')
  1963. window.open("index.php?module=SalesOrder&action=Popup&html=Popup_picker&popuptype=specific&form=EditView&relmod_id="+record_id+"&parent_module="+parent_module,"test","width=640,height=602,resizable=0,scrollbars=0");
  1964. else
  1965. window.open("index.php?module=SalesOrder&action=Popup&html=Popup_picker&popuptype=specific&form=EditView","test","width=640,height=602,resizable=0,scrollbars=0");
  1966. }
  1967. function checkEmailid(parent_module,emailid,yahooid)
  1968. {
  1969. var check = true;
  1970. if(emailid == '' && yahooid == '')
  1971. {
  1972. alert(alert_arr.LBL_THIS+parent_module+alert_arr.DOESNOT_HAVE_MAILIDS);
  1973. check=false;
  1974. }
  1975. return check;
  1976. }
  1977. function calQCduedatetime()
  1978. {
  1979. var datefmt = document.QcEditView.dateFormat.value;
  1980. var type = document.QcEditView.activitytype.value;
  1981. var dateval1=getObj('date_start').value.replace(/^\s+/g, '').replace(/\s+$/g, '');
  1982. var dateelements1=splitDateVal(dateval1);
  1983. dd1=parseInt(dateelements1[0],10);
  1984. mm1=dateelements1[1];
  1985. yyyy1=dateelements1[2];
  1986. var date1=new Date();
  1987. date1.setYear(yyyy1);
  1988. date1.setMonth(mm1-1,dd1+1);
  1989. var yy = date1.getFullYear();
  1990. var mm = date1.getMonth() + 1;
  1991. var dd = date1.getDate();
  1992. var date = document.QcEditView.date_start.value;
  1993. var starttime = document.QcEditView.time_start.value;
  1994. if (!timeValidate('time_start',' Start Date & Time','OTH'))
  1995. return false;
  1996. var timearr = starttime.split(":");
  1997. var hour = parseInt(timearr[0],10);
  1998. var min = parseInt(timearr[1],10);
  1999. dd = _2digit(dd);
  2000. mm = _2digit(mm);
  2001. var tempdate = yy+'-'+mm+'-'+dd;
  2002. if(datefmt == '%d-%m-%Y')
  2003. var tempdate = dd+'-'+mm+'-'+yy;
  2004. else if(datefmt == '%m-%d-%Y')
  2005. var tempdate = mm+'-'+dd+'-'+yy;
  2006. if(type == 'Meeting')
  2007. {
  2008. hour = hour + 1;
  2009. if(hour == 24)
  2010. {
  2011. hour = 0;
  2012. date = tempdate;
  2013. }
  2014. hour = _2digit(hour);
  2015. min = _2digit(min);
  2016. document.QcEditView.due_date.value = date;
  2017. document.QcEditView.time_end.value = hour+':'+min;
  2018. }
  2019. if(type == 'Call')
  2020. {
  2021. if(min >= 55)
  2022. {
  2023. min = min%55;
  2024. hour = hour + 1;
  2025. }else min = min + 5;
  2026. if(hour == 24)
  2027. {
  2028. hour = 0;
  2029. date = tempdate;
  2030. }
  2031. hour = _2digit(hour);
  2032. min = _2digit(min);
  2033. document.QcEditView.due_date.value = date;
  2034. document.QcEditView.time_end.value = hour+':'+min;
  2035. }
  2036. }
  2037. function _2digit( no ){
  2038. if(no < 10) return "0" + no;
  2039. else return "" + no;
  2040. }
  2041. function confirmdelete(url)
  2042. {
  2043. if(confirm(alert_arr.ARE_YOU_SURE))
  2044. {
  2045. document.location.href=url;
  2046. }
  2047. }
  2048. //function modified to apply the patch ref : Ticket #4065
  2049. function valid(c,type)
  2050. {
  2051. if(type == 'name')
  2052. {
  2053. return (((c >= 'a') && (c <= 'z')) ||((c >= 'A') && (c <= 'Z')) ||((c >= '0') && (c <= '9')) || (c == '.') || (c == '_') || (c == '-') || (c == '@') );
  2054. }
  2055. else if(type == 'namespace')
  2056. {
  2057. return (((c >= 'a') && (c <= 'z')) ||((c >= 'A') && (c <= 'Z')) ||((c >= '0') && (c <= '9')) || (c == '.')||(c==' ') || (c == '_') || (c == '-') );
  2058. }
  2059. }
  2060. //end
  2061. function CharValidation(s,type)
  2062. {
  2063. for (var i = 0; i < s.length; i++)
  2064. {
  2065. if (!valid(s.charAt(i),type))
  2066. {
  2067. return false;
  2068. }
  2069. }
  2070. return true;
  2071. }
  2072. /** Check Upload file is in specified format(extension).
  2073. * @param fldname -- name of the file field
  2074. * @param fldLabel -- Lable of the file field
  2075. * @param filter -- List of file extensions to allow. each extension must be seperated with a | sybmol.
  2076. * Example: upload_filter("imagename","Image", "jpg|gif|bmp|png")
  2077. * @returns true -- if the extension is IN specified extension.
  2078. * @returns false -- if the extension is NOT IN specified extension.
  2079. *
  2080. * NOTE: If this field is mandatory, please call emptyCheck() function before calling this function.
  2081. */
  2082. function upload_filter(fldName, filter)
  2083. {
  2084. var currObj=getObj(fldName)
  2085. if(currObj.value !="")
  2086. {
  2087. var file=currObj.value;
  2088. var type=file.split(".");
  2089. var valid_extn=filter.split("|");
  2090. if(valid_extn.indexOf(type[type.length-1]) == -1)
  2091. {
  2092. alert(alert_arr.PLS_SELECT_VALID_FILE+valid_extn)
  2093. try {
  2094. currObj.focus()
  2095. } catch(error) {
  2096. // Fix for IE: If element or its wrapper around it is hidden, setting focus will fail
  2097. // So using the try { } catch(error) { }
  2098. }
  2099. return false;
  2100. }
  2101. }
  2102. return true
  2103. }
  2104. function validateUrl(name)
  2105. {
  2106. var Url = getObj(name);
  2107. var wProtocol;
  2108. var oRegex = new Object();
  2109. oRegex.UriProtocol = new RegExp('');
  2110. oRegex.UriProtocol.compile( '^(((http|https|ftp|news):\/\/)|mailto:)', 'gi' );
  2111. oRegex.UrlOnChangeProtocol = new RegExp('') ;
  2112. oRegex.UrlOnChangeProtocol.compile( '^(http|https|ftp|news)://(?=.)', 'gi' );
  2113. wUrl = Url.value;
  2114. wProtocol=oRegex.UrlOnChangeProtocol.exec( wUrl ) ;
  2115. if ( wProtocol )
  2116. {
  2117. wUrl = wUrl.substr( wProtocol[0].length );
  2118. Url.value = wUrl;
  2119. }
  2120. }
  2121. function LTrim( value )
  2122. {
  2123. var re = /\s*((\S+\s*)*)/;
  2124. return value.replace(re, "$1");
  2125. }
  2126. function selectedRecords(module,category)
  2127. {
  2128. var allselectedboxes = document.getElementById("allselectedboxes");
  2129. var idstring = (allselectedboxes == null)? '' : allselectedboxes.value;
  2130. if(idstring != '')
  2131. window.location.href="index.php?module="+module+"&action=ExportRecords&parenttab="+category+"&idstring="+idstring;
  2132. else
  2133. window.location.href="index.php?module="+module+"&action=ExportRecords&parenttab="+category;
  2134. return false;
  2135. }
  2136. function record_export(module,category,exform,idstring)
  2137. {
  2138. var searchType = document.getElementsByName('search_type');
  2139. var exportData = document.getElementsByName('export_data');
  2140. for(i=0;i<2;i++){
  2141. if(searchType[i].checked == true)
  2142. var sel_type = searchType[i].value;
  2143. }
  2144. for(i=0;i<3;i++){
  2145. if(exportData[i].checked == true)
  2146. var exp_type = exportData[i].value;
  2147. }
  2148. new Ajax.Request(
  2149. 'index.php',
  2150. {queue: {position: 'end', scope: 'command'},
  2151. method: 'post',
  2152. postBody: "module="+module+"&action=ExportAjax&export_record=true&search_type="+sel_type+"&export_data="+exp_type+"&idstring="+idstring,
  2153. onComplete: function(response) {
  2154. if(response.responseText == 'NOT_SEARCH_WITHSEARCH_ALL')
  2155. {
  2156. $('not_search').style.display = 'block';
  2157. $('not_search').innerHTML="<font color='red'><b>"+alert_arr.LBL_NOTSEARCH_WITHSEARCH_ALL+" "+module+"</b></font>";
  2158. setTimeout(hideErrorMsg1,6000);
  2159. exform.submit();
  2160. }
  2161. else if(response.responseText == 'NOT_SEARCH_WITHSEARCH_CURRENTPAGE')
  2162. {
  2163. $('not_search').style.display = 'block';
  2164. $('not_search').innerHTML="<font color='red'><b>"+alert_arr.LBL_NOTSEARCH_WITHSEARCH_CURRENTPAGE+" "+module+"</b></font>";
  2165. setTimeout(hideErrorMsg1,7000);
  2166. exform.submit();
  2167. }
  2168. else if(response.responseText == 'NO_DATA_SELECTED')
  2169. {
  2170. $('not_search').style.display = 'block';
  2171. $('not_search').innerHTML="<font color='red'><b>"+alert_arr.LBL_NO_DATA_SELECTED+"</b></font>";
  2172. setTimeout(hideErrorMsg1,3000);
  2173. }
  2174. else if(response.responseText == 'SEARCH_WITHOUTSEARCH_ALL')
  2175. {
  2176. if(confirm(alert_arr.LBL_SEARCH_WITHOUTSEARCH_ALL))
  2177. {
  2178. exform.submit();
  2179. }
  2180. }
  2181. else if(response.responseText == 'SEARCH_WITHOUTSEARCH_CURRENTPAGE')
  2182. {
  2183. if(confirm(alert_arr.LBL_SEARCH_WITHOUTSEARCH_CURRENTPAGE))
  2184. {
  2185. exform.submit();
  2186. }
  2187. }
  2188. else
  2189. {
  2190. exform.submit();
  2191. }
  2192. }
  2193. }
  2194. );
  2195. }
  2196. function hideErrorMsg1()
  2197. {
  2198. $('not_search').style.display = 'none';
  2199. }
  2200. // Replace the % sign with %25 to make sure the AJAX url is going wel.
  2201. function escapeAll(tagValue)
  2202. {
  2203. //return escape(tagValue.replace(/%/g, '%25'));
  2204. if(default_charset.toLowerCase() == 'utf-8')
  2205. return encodeURIComponent(tagValue.replace(/%/g, '%25'));
  2206. else
  2207. return escape(tagValue.replace(/%/g, '%25'));
  2208. }
  2209. function removeHTMLFormatting(str) {
  2210. str = str.replace(/<([^<>]*)>/g, " ");
  2211. str = str.replace(/&nbsp;/g, " ");
  2212. return str;
  2213. }
  2214. function get_converted_html(str)
  2215. {
  2216. var temp = str.toLowerCase();
  2217. if(temp.indexOf('<') != '-1' || temp.indexOf('>') != '-1')
  2218. {
  2219. str = str.replace(/</g,'&lt;');
  2220. str = str.replace(/>/g,'&gt;');
  2221. }
  2222. if( temp.match(/(script).*(\/script)/))
  2223. {
  2224. str = str.replace(/&/g,'&amp;');
  2225. }
  2226. else if(temp.indexOf('&') != '-1')
  2227. {
  2228. str = str.replace(/&/g,'&amp;');
  2229. }
  2230. return str;
  2231. }
  2232. //To select the select all check box(if all the items are selected) when the form loads.
  2233. function default_togglestate(obj_id,elementId)
  2234. {
  2235. var all_state=true;
  2236. var groupElements = document.getElementsByName(obj_id);
  2237. for (var i=0;i<groupElements.length;i++) {
  2238. var state=groupElements[i].checked;
  2239. if (state == false)
  2240. {
  2241. all_state=false;
  2242. break;
  2243. }
  2244. }
  2245. if(typeof elementId=='undefined'){
  2246. elementId = 'selectall';
  2247. }
  2248. if(getObj(elementId)) {
  2249. getObj(elementId).checked=all_state;
  2250. }
  2251. }
  2252. //for select multiple check box in multiple pages for Campaigns related list:
  2253. function rel_check_object(sel_id,module)
  2254. {
  2255. var selected;
  2256. var select_global=new Array();
  2257. var cookie_val=get_cookie(module+"_all");
  2258. if(cookie_val == null)
  2259. selected=sel_id.value+";";
  2260. else
  2261. selected=trim(cookie_val);
  2262. select_global=selected.split(";");
  2263. var box_value=sel_id.checked;
  2264. var id= sel_id.value;
  2265. var duplicate=select_global.indexOf(id);
  2266. var size=select_global.length-1;
  2267. var result="";
  2268. if(box_value == true)
  2269. {
  2270. if(duplicate == "-1")
  2271. {
  2272. select_global[size]=id;
  2273. }
  2274. size=select_global.length-1;
  2275. var i=0;
  2276. for(i=0;i<=size;i++)
  2277. {
  2278. if(trim(select_global[i])!='')
  2279. result=select_global[i]+";"+result;
  2280. }
  2281. rel_default_togglestate(module);
  2282. }
  2283. else
  2284. {
  2285. if(duplicate != "-1")
  2286. select_global.splice(duplicate,1)
  2287. size=select_global.length-1;
  2288. var i=0;
  2289. for(i=size;i>=0;i--)
  2290. {
  2291. if(trim(select_global[i])!='')
  2292. result=select_global[i]+";"+result;
  2293. }
  2294. getObj(module+"_selectall").checked=false;
  2295. }
  2296. set_cookie(module+"_all",result);
  2297. }
  2298. //Function to select all the items in the current page for Campaigns related list:.
  2299. function rel_toggleSelect(state,relCheckName,module) {
  2300. var obj = document.getElementsByName(relCheckName);
  2301. if (obj) {
  2302. for (var i=0;i<obj.length;i++) {
  2303. obj[i].checked=state;
  2304. rel_check_object(obj[i],module);
  2305. }
  2306. }
  2307. }
  2308. //To select the select all check box(if all the items are selected) when the form loads for Campaigns related list:.
  2309. function rel_default_togglestate(module)
  2310. {
  2311. var all_state=true;
  2312. var groupElements = document.getElementsByName(module+"_selected_id");
  2313. if(typeof(groupElements) == 'undefined') return;
  2314. for (var i=0;i<groupElements.length;i++) {
  2315. var state=groupElements[i].checked;
  2316. if (state == false)
  2317. {
  2318. all_state=false;
  2319. break;
  2320. }
  2321. }
  2322. if(getObj(module+"_selectall")) {
  2323. getObj(module+"_selectall").checked=all_state;
  2324. }
  2325. }
  2326. //To clear all the checked items in all the pages for Campaigns related list:
  2327. function clear_checked_all(module)
  2328. {
  2329. var cookie_val=get_cookie(module+"_all");
  2330. if(cookie_val != null)
  2331. delete_cookie(module+"_all");
  2332. //Uncheck all the boxes in current page..
  2333. var obj = document.getElementsByName(module+"_selected_id");
  2334. if (obj) {
  2335. for (var i=0;i<obj.length;i++) {
  2336. obj[i].checked=false;
  2337. }
  2338. }
  2339. if(getObj(module+"_selectall")) {
  2340. getObj(module+"_selectall").checked=false;
  2341. }
  2342. }
  2343. //groupParentElementId is added as there are multiple groups in Documents listview.
  2344. function toggleSelect_ListView(state,relCheckName,groupParentElementId) {
  2345. var obj = document.getElementsByName(relCheckName);
  2346. if (obj) {
  2347. for (var i=0;i<obj.length;i++) {
  2348. obj[i].checked=state;
  2349. if(typeof(check_object) == 'function') {
  2350. // This function is defined in ListView.js (check for existence)
  2351. check_object(obj[i],groupParentElementId);
  2352. }
  2353. }
  2354. }
  2355. }
  2356. function gotourl(url)
  2357. {
  2358. document.location.href=url;
  2359. }
  2360. // Function to display the element with id given by showid and hide the element with id given by hideid
  2361. function toggleShowHide(showid, hideid)
  2362. {
  2363. var show_ele = document.getElementById(showid);
  2364. var hide_ele = document.getElementById(hideid);
  2365. if(show_ele != null)
  2366. show_ele.style.display = "inline";
  2367. if(hide_ele != null)
  2368. hide_ele.style.display = "none";
  2369. }
  2370. // Refactored APIs from DisplayFiels.tpl
  2371. function fnshowHide(currObj,txtObj) {
  2372. if(currObj.checked == true)
  2373. document.getElementById(txtObj).style.visibility = 'visible';
  2374. else
  2375. document.getElementById(txtObj).style.visibility = 'hidden';
  2376. }
  2377. function fntaxValidation(txtObj) {
  2378. if (!numValidate(txtObj,"Tax","any"))
  2379. document.getElementById(txtObj).value = 0;
  2380. }
  2381. function fnpriceValidation(txtObj) {
  2382. if (!numValidate(txtObj,"Price","any"))
  2383. document.getElementById(txtObj).value = 0;
  2384. }
  2385. function delimage(id) {
  2386. new Ajax.Request(
  2387. 'index.php',
  2388. {queue: {position: 'end', scope: 'command'},
  2389. method: 'post',
  2390. postBody: 'module=Contacts&action=ContactsAjax&file=DelImage&recordid='+id,
  2391. onComplete: function(response) {
  2392. if(response.responseText.indexOf("SUCCESS")>-1)
  2393. $("replaceimage").innerHTML=alert_arr.LBL_IMAGE_DELETED;
  2394. else
  2395. alert(alert_arr.ERROR_WHILE_EDITING);
  2396. }
  2397. }
  2398. );
  2399. }
  2400. function delUserImage(id) {
  2401. new Ajax.Request(
  2402. 'index.php',
  2403. {queue: {position: 'end', scope: 'command'},
  2404. method: 'post',
  2405. postBody: 'module=Users&action=UsersAjax&file=Save&deleteImage=true&recordid='+id,
  2406. onComplete: function(response) {
  2407. if(response.responseText.indexOf("SUCCESS")>-1)
  2408. $("replaceimage").innerHTML=alert_arr.LBL_IMAGE_DELETED;
  2409. else
  2410. alert(alert_arr.ERROR_WHILE_EDITING);
  2411. }
  2412. }
  2413. );
  2414. }
  2415. // Function to enable/disable related elements based on whether the current object is checked or not
  2416. function fnenableDisable(currObj,enableId) {
  2417. var disable_flag = true;
  2418. if(currObj.checked == true)
  2419. disable_flag = false;
  2420. document.getElementById('curname'+enableId).disabled = disable_flag;
  2421. document.getElementById('cur_reset'+enableId).disabled = disable_flag;
  2422. document.getElementById('base_currency'+enableId).disabled = disable_flag;
  2423. }
  2424. // Update current value with current value of base currency and the conversion rate
  2425. function updateCurrencyValue(currObj,txtObj,base_curid,conv_rate) {
  2426. var unit_price = $(base_curid).value;
  2427. //if(currObj.checked == true)
  2428. //{
  2429. document.getElementById(txtObj).value = unit_price * conv_rate;
  2430. //}
  2431. }
  2432. // Synchronize between Unit price and Base currency value.
  2433. function updateUnitPrice(from_cur_id, to_cur_id) {
  2434. var from_ele = document.getElementById(from_cur_id);
  2435. if (from_ele == null) return;
  2436. var to_ele = document.getElementById(to_cur_id);
  2437. if (to_ele == null) return;
  2438. to_ele.value = from_ele.value;
  2439. }
  2440. // Update hidden base currency value, everytime the base currency value is changed in multi-currency UI
  2441. function updateBaseCurrencyValue() {
  2442. var cur_list = document.getElementsByName('base_currency_input');
  2443. if (cur_list == null) return;
  2444. var base_currency_ele = document.getElementById('base_currency');
  2445. if (base_currency_ele == null) return;
  2446. for(var i=0; i<cur_list.length; i++) {
  2447. var cur_ele = cur_list[i];
  2448. if (cur_ele != null && cur_ele.checked == true)
  2449. base_currency_ele.value = cur_ele.value;
  2450. }
  2451. }
  2452. // END
  2453. /******************************************************************************/
  2454. /* Activity reminder Customization: Setup Callback */
  2455. function ActivityReminderProgressIndicator(show) {
  2456. if(show) $("status").style.display = "inline";
  2457. else $("status").style.display = "none";
  2458. }
  2459. function ActivityReminderSetupCallback(cbmodule, cbrecord) {
  2460. if(cbmodule && cbrecord) {
  2461. ActivityReminderProgressIndicator(true);
  2462. new Ajax.Request(
  2463. 'index.php',
  2464. {queue: {position: 'end', scope: 'command'},
  2465. method: 'post',
  2466. postBody:"module=Calendar&action=CalendarAjax&ajax=true&file=ActivityReminderSetupCallbackAjax&cbmodule="+
  2467. encodeURIComponent(cbmodule) + "&cbrecord=" + encodeURIComponent(cbrecord),
  2468. onComplete: function(response) {
  2469. $("ActivityReminder_callbacksetupdiv").innerHTML=response.responseText;
  2470. ActivityReminderProgressIndicator(false);
  2471. }});
  2472. }
  2473. }
  2474. function ActivityReminderSetupCallbackSave(form) {
  2475. var cbmodule = form.cbmodule.value;
  2476. var cbrecord = form.cbrecord.value;
  2477. var cbaction = form.cbaction.value;
  2478. var cbdate = form.cbdate.value;
  2479. var cbtime = form.cbhour.value + ":" + form.cbmin.value;
  2480. if(cbmodule && cbrecord) {
  2481. ActivityReminderProgressIndicator(true);
  2482. new Ajax.Request("index.php",
  2483. { queue:{position:"end", scope:"command"}, method:"post",
  2484. postBody:"module=Calendar&action=CalendarAjax&ajax=true&file=ActivityReminderSetupCallbackAjax" +
  2485. "&cbaction=" + encodeURIComponent(cbaction) +
  2486. "&cbmodule="+ encodeURIComponent(cbmodule) +
  2487. "&cbrecord=" + encodeURIComponent(cbrecord) +
  2488. "&cbdate=" + encodeURIComponent(cbdate) +
  2489. "&cbtime=" + encodeURIComponent(cbtime),
  2490. onComplete:function (response) {ActivityReminderSetupCallbackSaveProcess(response.responseText);}});
  2491. }
  2492. }
  2493. function ActivityReminderSetupCallbackSaveProcess(message) {
  2494. ActivityReminderProgressIndicator(false);
  2495. $('ActivityReminder_callbacksetupdiv_lay').style.display='none';
  2496. }
  2497. function ActivityReminderPostponeCallback(cbmodule, cbrecord, cbreminderid) {
  2498. if(cbmodule && cbrecord) {
  2499. ActivityReminderProgressIndicator(true);
  2500. new Ajax.Request("index.php",
  2501. { queue:{position:"end", scope:"command"}, method:"post",
  2502. postBody:"module=Calendar&action=CalendarAjax&ajax=true&file=ActivityReminderSetupCallbackAjax&cbaction=POSTPONE&cbmodule="+
  2503. encodeURIComponent(cbmodule) + "&cbrecord=" + encodeURIComponent(cbrecord) + "&cbreminderid=" + encodeURIComponent(cbreminderid),
  2504. onComplete:function (response) {ActivityReminderPostponeCallbackProcess(response.responseText);}});
  2505. }
  2506. }
  2507. function ActivityReminderPostponeCallbackProcess(message) {
  2508. ActivityReminderProgressIndicator(false);
  2509. }
  2510. function ActivityReminderRemovePopupDOM(id) {
  2511. if($(id)) $(id).remove();
  2512. }
  2513. /* END */
  2514. /* ActivityReminder Customization: Pool Callback */
  2515. var ActivityReminder_regcallback_timer;
  2516. var ActivityReminder_callback_delay = 40 * 1000; // Milli Seconds
  2517. var ActivityReminder_autohide = false; // If the popup should auto hide after callback_delay?
  2518. var ActivityReminder_popup_maxheight = 75;
  2519. var ActivityReminder_callback;
  2520. var ActivityReminder_timer;
  2521. var ActivityReminder_progressive_height = 2; // px
  2522. var ActivityReminder_popup_onscreen = 2 * 1000; // Milli Seconds (should be less than ActivityReminder_callback_delay)
  2523. var ActivityReminder_callback_win_uniqueids = new Object();
  2524. function ActivityReminderCallback() {
  2525. if(typeof(Ajax) == 'undefined') {
  2526. return;
  2527. }
  2528. if(ActivityReminder_regcallback_timer) {
  2529. window.clearTimeout(ActivityReminder_regcallback_timer);
  2530. ActivityReminder_regcallback_timer = null;
  2531. }
  2532. new Ajax.Request("index.php",
  2533. { queue:{position:"end", scope:"command"}, method:"post",
  2534. postBody:"module=Calendar&action=CalendarAjax&file=ActivityReminderCallbackAjax&ajax=true",
  2535. onComplete:function (response) {ActivityReminderCallbackProcess(response.responseText);}});
  2536. }
  2537. function ActivityReminderCallbackProcess(message) {
  2538. ActivityReminder_callback = document.getElementById("ActivityRemindercallback");
  2539. if(ActivityReminder_callback == null) return;
  2540. ActivityReminder_callback.style.display = 'block';
  2541. var winuniqueid = 'ActivityReminder_callback_win_' + (new Date()).getTime();
  2542. if(ActivityReminder_callback_win_uniqueids[winuniqueid]) {
  2543. winuniqueid += "-" + (new Date()).getTime();
  2544. }
  2545. ActivityReminder_callback_win_uniqueids[winuniqueid] = true;
  2546. var ActivityReminder_callback_win = document.createElement("span");
  2547. ActivityReminder_callback_win.id = winuniqueid;
  2548. ActivityReminder_callback.appendChild(ActivityReminder_callback_win);
  2549. $(ActivityReminder_callback_win).update(message);
  2550. ActivityReminder_callback_win.style.height = "0px";
  2551. ActivityReminder_callback_win.style.display = "";
  2552. var ActivityReminder_Newdelay_response_node = '_vtiger_activityreminder_callback_interval_';
  2553. if($(ActivityReminder_Newdelay_response_node)) {
  2554. var ActivityReminder_Newdelay_response_value = parseInt($(ActivityReminder_Newdelay_response_node).innerHTML);
  2555. if(ActivityReminder_Newdelay_response_value > 0) {
  2556. ActivityReminder_callback_delay = ActivityReminder_Newdelay_response_value;
  2557. }
  2558. // We don't need the no any longer, it will be sent from server for next Popup
  2559. $(ActivityReminder_Newdelay_response_node).remove();
  2560. }
  2561. if(message == '' || trim(message).indexOf('<script') == 0) {
  2562. // We got only new dealay value but no popup information, let us remove the callback win created
  2563. $(ActivityReminder_callback_win.id).remove();
  2564. ActivityReminder_callback_win = false;
  2565. message = '';
  2566. }
  2567. if(message != "") ActivityReminderCallbackRollout(ActivityReminder_popup_maxheight, ActivityReminder_callback_win);
  2568. else { ActivityReminderCallbackReset(0, ActivityReminder_callback_win); }
  2569. }
  2570. function ActivityReminderCallbackRollout(z, ActivityReminder_callback_win) {
  2571. ActivityReminder_callback_win = $(ActivityReminder_callback_win);
  2572. if (ActivityReminder_timer) { window.clearTimeout(ActivityReminder_timer); }
  2573. if (ActivityReminder_callback_win && parseInt(ActivityReminder_callback_win.style.height) < z) {
  2574. ActivityReminder_callback_win.style.height = parseInt(ActivityReminder_callback_win.style.height) + ActivityReminder_progressive_height + "px";
  2575. ActivityReminder_timer = setTimeout("ActivityReminderCallbackRollout(" + z + ",'" + ActivityReminder_callback_win.id + "')", 1);
  2576. } else {
  2577. ActivityReminder_callback_win.style.height = z + "px";
  2578. if(ActivityReminder_autohide) ActivityReminder_timer = setTimeout("ActivityReminderCallbackRollin(1,'" + ActivityReminder_callback_win.id + "')", ActivityReminder_popup_onscreen);
  2579. else ActivityReminderRegisterCallback(ActivityReminder_callback_delay);
  2580. }
  2581. }
  2582. function ActivityReminderCallbackRollin(z, ActivityReminder_callback_win) {
  2583. ActivityReminder_callback_win = $(ActivityReminder_callback_win);
  2584. if (ActivityReminder_timer) { window.clearTimeout(ActivityReminder_timer); }
  2585. if (parseInt(ActivityReminder_callback_win.style.height) > z) {
  2586. ActivityReminder_callback_win.style.height = parseInt(ActivityReminder_callback_win.style.height) - ActivityReminder_progressive_height + "px";
  2587. ActivityReminder_timer = setTimeout("ActivityReminderCallbackRollin(" + z + ",'" + ActivityReminder_callback_win.id + "')", 1);
  2588. } else {
  2589. ActivityReminderCallbackReset(z, ActivityReminder_callback_win);
  2590. }
  2591. }
  2592. function ActivityReminderCallbackReset(z, ActivityReminder_callback_win) {
  2593. ActivityReminder_callback_win = $(ActivityReminder_callback_win);
  2594. if(ActivityReminder_callback_win) {
  2595. ActivityReminder_callback_win.style.height = z + "px";
  2596. ActivityReminder_callback_win.style.display = "none";
  2597. }
  2598. if(ActivityReminder_timer) {
  2599. window.clearTimeout(ActivityReminder_timer);
  2600. ActivityReminder_timer = null;
  2601. }
  2602. ActivityReminderRegisterCallback(ActivityReminder_callback_delay);
  2603. }
  2604. function ActivityReminderRegisterCallback(timeout) {
  2605. if(timeout == null) timeout = 1;
  2606. if(ActivityReminder_regcallback_timer == null) {
  2607. ActivityReminder_regcallback_timer = setTimeout("ActivityReminderCallback()", timeout);
  2608. }
  2609. }
  2610. //added for finding duplicates
  2611. function movefields()
  2612. {
  2613. availListObj=getObj("availlist")
  2614. selectedColumnsObj=getObj("selectedCol")
  2615. for (i=0;i<selectedColumnsObj.length;i++)
  2616. {
  2617. selectedColumnsObj.options[i].selected=false
  2618. }
  2619. movefieldsStep1();
  2620. }
  2621. function movefieldsStep1()
  2622. {
  2623. availListObj=getObj("availlist")
  2624. selectedColumnsObj=getObj("selectedCol")
  2625. document.getElementById("selectedCol").style.width="164px";
  2626. var count=0;
  2627. for(i=0;i<availListObj.length;i++)
  2628. {
  2629. if (availListObj.options[i].selected==true)
  2630. {
  2631. count++;
  2632. }
  2633. }
  2634. var total_fields=count+selectedColumnsObj.length;
  2635. if (total_fields >4 )
  2636. {
  2637. alert(alert_arr.MAX_RECORDS)
  2638. return false
  2639. }
  2640. if (availListObj.options.selectedIndex > -1)
  2641. {
  2642. for (i=0;i<availListObj.length;i++)
  2643. {
  2644. if (availListObj.options[i].selected==true)
  2645. {
  2646. var rowFound=false;
  2647. for (j=0;j<selectedColumnsObj.length;j++)
  2648. {
  2649. selectedColumnsObj.options[j].value==availListObj.options[i].value;
  2650. if (selectedColumnsObj.options[j].value==availListObj.options[i].value)
  2651. {
  2652. var rowFound=true;
  2653. var existingObj=selectedColumnsObj.options[j];
  2654. break;
  2655. }
  2656. }
  2657. if (rowFound!=true)
  2658. {
  2659. var newColObj=document.createElement("OPTION")
  2660. newColObj.value=availListObj.options[i].value
  2661. if (browser_ie) newColObj.innerText=availListObj.options[i].innerText
  2662. else if (browser_nn4 || browser_nn6) newColObj.text=availListObj.options[i].text
  2663. selectedColumnsObj.appendChild(newColObj)
  2664. newColObj.selected=true
  2665. }
  2666. else
  2667. {
  2668. existingObj.selected=true
  2669. }
  2670. availListObj.options[i].selected=false
  2671. movefieldsStep1();
  2672. }
  2673. }
  2674. }
  2675. }
  2676. function selectedColClick(oSel)
  2677. {
  2678. if (oSel.selectedIndex == -1 || oSel.options[oSel.selectedIndex].disabled == true)
  2679. {
  2680. alert(alert_arr.NOT_ALLOWED_TO_EDIT);
  2681. oSel.options[oSel.selectedIndex].selected = false;
  2682. }
  2683. }
  2684. function delFields()
  2685. {
  2686. selectedColumnsObj=getObj("selectedCol");
  2687. selected_tab = $("dupmod").value;
  2688. if (selectedColumnsObj.options.selectedIndex > -1)
  2689. {
  2690. for (i=0;i < selectedColumnsObj.options.length;i++)
  2691. {
  2692. if(selectedColumnsObj.options[i].selected == true)
  2693. {
  2694. if(selected_tab == 4)
  2695. {
  2696. if(selectedColumnsObj.options[i].innerHTML == "Last Name")
  2697. {
  2698. alert(alert_arr.DEL_MANDATORY);
  2699. del = false;
  2700. return false;
  2701. }
  2702. else
  2703. del = true;
  2704. }
  2705. else if(selected_tab == 7)
  2706. {
  2707. if(selectedColumnsObj.options[i].innerHTML == "Last Name" || selectedColumnsObj.options[i].innerHTML == "Company")
  2708. {
  2709. alert(alert_arr.DEL_MANDATORY);
  2710. del = false;
  2711. return false;
  2712. }
  2713. else
  2714. del = true;
  2715. }
  2716. else if(selected_tab == 6)
  2717. {
  2718. if(selectedColumnsObj.options[i].innerHTML == "Account Name")
  2719. {
  2720. alert(alert_arr.DEL_MANDATORY);
  2721. del = false;
  2722. return false;
  2723. }
  2724. else
  2725. del = true;
  2726. }
  2727. else if(selected_tab == 14)
  2728. {
  2729. if(selectedColumnsObj.options[i].innerHTML == "Product Name")
  2730. {
  2731. alert(alert_arr.DEL_MANDATORY);
  2732. del = false;
  2733. return false;
  2734. }
  2735. else
  2736. del = true;
  2737. }
  2738. if(del == true)
  2739. {
  2740. selectedColumnsObj.remove(i);
  2741. delFields();
  2742. }
  2743. }
  2744. }
  2745. }
  2746. }
  2747. function moveFieldUp()
  2748. {
  2749. selectedColumnsObj=getObj("selectedCol")
  2750. var currpos=selectedColumnsObj.options.selectedIndex
  2751. var tempdisabled= false;
  2752. for (i=0;i<selectedColumnsObj.length;i++)
  2753. {
  2754. if(i != currpos)
  2755. selectedColumnsObj.options[i].selected=false
  2756. }
  2757. if (currpos>0)
  2758. {
  2759. var prevpos=selectedColumnsObj.options.selectedIndex-1
  2760. if (browser_ie)
  2761. {
  2762. temp=selectedColumnsObj.options[prevpos].innerText
  2763. tempdisabled = selectedColumnsObj.options[prevpos].disabled;
  2764. selectedColumnsObj.options[prevpos].innerText=selectedColumnsObj.options[currpos].innerText
  2765. selectedColumnsObj.options[prevpos].disabled = false;
  2766. selectedColumnsObj.options[currpos].innerText=temp
  2767. selectedColumnsObj.options[currpos].disabled = tempdisabled;
  2768. }
  2769. else if (browser_nn4 || browser_nn6)
  2770. {
  2771. temp=selectedColumnsObj.options[prevpos].text
  2772. tempdisabled = selectedColumnsObj.options[prevpos].disabled;
  2773. selectedColumnsObj.options[prevpos].text=selectedColumnsObj.options[currpos].text
  2774. selectedColumnsObj.options[prevpos].disabled = false;
  2775. selectedColumnsObj.options[currpos].text=temp
  2776. selectedColumnsObj.options[currpos].disabled = tempdisabled;
  2777. }
  2778. temp=selectedColumnsObj.options[prevpos].value
  2779. selectedColumnsObj.options[prevpos].value=selectedColumnsObj.options[currpos].value
  2780. selectedColumnsObj.options[currpos].value=temp
  2781. selectedColumnsObj.options[prevpos].selected=true
  2782. selectedColumnsObj.options[currpos].selected=false
  2783. }
  2784. }
  2785. function moveFieldDown()
  2786. {
  2787. selectedColumnsObj=getObj("selectedCol")
  2788. var currpos=selectedColumnsObj.options.selectedIndex
  2789. var tempdisabled= false;
  2790. for (i=0;i<selectedColumnsObj.length;i++)
  2791. {
  2792. if(i != currpos)
  2793. selectedColumnsObj.options[i].selected=false
  2794. }
  2795. if (currpos<selectedColumnsObj.options.length-1)
  2796. {
  2797. var nextpos=selectedColumnsObj.options.selectedIndex+1
  2798. if (browser_ie)
  2799. {
  2800. temp=selectedColumnsObj.options[nextpos].innerText
  2801. tempdisabled = selectedColumnsObj.options[nextpos].disabled;
  2802. selectedColumnsObj.options[nextpos].innerText=selectedColumnsObj.options[currpos].innerText
  2803. selectedColumnsObj.options[nextpos].disabled = false;
  2804. selectedColumnsObj.options[nextpos];
  2805. selectedColumnsObj.options[currpos].innerText=temp
  2806. selectedColumnsObj.options[currpos].disabled = tempdisabled;
  2807. }
  2808. else if (browser_nn4 || browser_nn6)
  2809. {
  2810. temp=selectedColumnsObj.options[nextpos].text
  2811. tempdisabled = selectedColumnsObj.options[nextpos].disabled;
  2812. selectedColumnsObj.options[nextpos].text=selectedColumnsObj.options[currpos].text
  2813. selectedColumnsObj.options[nextpos].disabled = false;
  2814. selectedColumnsObj.options[nextpos];
  2815. selectedColumnsObj.options[currpos].text=temp
  2816. selectedColumnsObj.options[currpos].disabled = tempdisabled;
  2817. }
  2818. temp=selectedColumnsObj.options[nextpos].value
  2819. selectedColumnsObj.options[nextpos].value=selectedColumnsObj.options[currpos].value
  2820. selectedColumnsObj.options[currpos].value=temp
  2821. selectedColumnsObj.options[nextpos].selected=true
  2822. selectedColumnsObj.options[currpos].selected=false
  2823. }
  2824. }
  2825. function lastImport(module,req_module)
  2826. {
  2827. var module_name= module;
  2828. var parent_tab= document.getElementById('parenttab').value;
  2829. if(module == '')
  2830. {
  2831. return false;
  2832. }
  2833. else
  2834. //alert("index.php?module="+module_name+"&action=lastImport&req_mod="+req_module+"&parenttab="+parent_tab);
  2835. window.open("index.php?module="+module_name+"&action=lastImport&req_mod="+req_module+"&parenttab="+parent_tab,"lastImport","width=750,height=602,menubar=no,toolbar=no,location=no,status=no,resizable=no,scrollbars=yes");
  2836. }
  2837. function merge_fields(selectedNames,module,parent_tab)
  2838. {
  2839. var select_options=document.getElementsByName(selectedNames);
  2840. var x= select_options.length;
  2841. var req_module=module;
  2842. var num_group=$("group_count").innerHTML;
  2843. var pass_url="";
  2844. var flag=0;
  2845. //var i=0;
  2846. var xx = 0;
  2847. for(i = 0; i < x ; i++)
  2848. {
  2849. if(select_options[i].checked)
  2850. {
  2851. pass_url = pass_url+select_options[i].value +","
  2852. xx++
  2853. }
  2854. }
  2855. var tmp = 0
  2856. if ( xx != 0)
  2857. {
  2858. if(xx > 3)
  2859. {
  2860. alert(alert_arr.MAX_THREE)
  2861. return false;
  2862. }
  2863. if(xx > 0)
  2864. {
  2865. for(j=0;j<num_group;j++)
  2866. {
  2867. flag = 0
  2868. var group_options=document.getElementsByName("group"+j);
  2869. for(i = 0; i < group_options.length ; i++)
  2870. {
  2871. if(group_options[i].checked)
  2872. {
  2873. flag++
  2874. }
  2875. }
  2876. if(flag > 0)
  2877. tmp++;
  2878. }
  2879. if (tmp > 1)
  2880. {
  2881. alert(alert_arr.SAME_GROUPS)
  2882. return false;
  2883. }
  2884. if(xx <2)
  2885. {
  2886. alert(alert_arr.ATLEAST_TWO)
  2887. return false;
  2888. }
  2889. }
  2890. window.open("index.php?module="+req_module+"&action=ProcessDuplicates&mergemode=mergefields&passurl="+pass_url+"&parenttab="+parent_tab,"Merge","width=750,height=602,menubar=no,toolbar=no,location=no,status=no,resizable=no,scrollbars=yes");
  2891. }
  2892. else
  2893. {
  2894. alert(alert_arr.ATLEAST_TWO);
  2895. return false;
  2896. }
  2897. }
  2898. function delete_fields(module)
  2899. {
  2900. var select_options=document.getElementsByName('del');
  2901. var x=select_options.length;
  2902. var xx=0;
  2903. url_rec="";
  2904. for(var i=0;i<x;i++)
  2905. {
  2906. if(select_options[i].checked)
  2907. {
  2908. url_rec=url_rec+select_options[i].value +","
  2909. xx++
  2910. }
  2911. }
  2912. if($("current_action"))
  2913. cur_action = $("current_action").innerHTML
  2914. if (xx == 0)
  2915. {
  2916. alert(alert_arr.SELECT);
  2917. return false;
  2918. }
  2919. var alert_str = alert_arr.DELETE + xx +alert_arr.RECORDS;
  2920. if(module=="Accounts")
  2921. alert_str = alert_arr.DELETE_ACCOUNT + xx +alert_arr.RECORDS;
  2922. if(confirm(alert_str))
  2923. {
  2924. $("status").style.display="inline";
  2925. new Ajax.Request(
  2926. 'index.php',
  2927. {queue: {position: 'end', scope: 'command'},
  2928. method: 'post',
  2929. postBody:"module="+module+"&action="+module+"Ajax&file=FindDuplicateRecords&del_rec=true&ajax=true&return_module="+module+"&idlist="+url_rec+"&current_action="+cur_action+"&"+dup_start,
  2930. onComplete: function(response) {
  2931. $("status").style.display="none";
  2932. $("duplicate_ajax").innerHTML= response.responseText;
  2933. }
  2934. }
  2935. );
  2936. }
  2937. else
  2938. return false;
  2939. }
  2940. function validate_merge(module)
  2941. {
  2942. var check_var=false;
  2943. var check_lead1=false;
  2944. var check_lead2=false;
  2945. var select_parent=document.getElementsByName('record');
  2946. var len = select_parent.length;
  2947. for(var i=0;i<len;i++)
  2948. {
  2949. if(select_parent[i].checked)
  2950. {
  2951. var check_parentvar=true;
  2952. }
  2953. }
  2954. if (check_parentvar!=true)
  2955. {
  2956. alert(alert_arr.Select_one_record_as_parent_record);
  2957. return false;
  2958. }
  2959. return true;
  2960. }
  2961. function select_All(fieldnames,cnt,module)
  2962. {
  2963. var new_arr = Array();
  2964. new_arr = fieldnames.split(",");
  2965. var len=new_arr.length;
  2966. for(i=0;i<len;i++)
  2967. {
  2968. var fld_names=new_arr[i]
  2969. var value=document.getElementsByName(fld_names)
  2970. var fld_len=document.getElementsByName(fld_names).length;
  2971. for(j=0;j<fld_len;j++)
  2972. {
  2973. value[cnt].checked='true'
  2974. // alert(value[j].checked)
  2975. }
  2976. }
  2977. }
  2978. function selectAllDel(state,checkedName)
  2979. {
  2980. var selectedOptions=document.getElementsByName(checkedName);
  2981. var length=document.getElementsByName(checkedName).length;
  2982. if(typeof(length) == 'undefined')
  2983. {
  2984. return false;
  2985. }
  2986. for(var i=0;i<length;i++)
  2987. {
  2988. selectedOptions[i].checked=state;
  2989. }
  2990. }
  2991. function selectDel(ThisName,CheckAllName)
  2992. {
  2993. var ThisNameOptions=document.getElementsByName(ThisName);
  2994. var CheckAllNameOptions=document.getElementsByName(CheckAllName);
  2995. var len1=document.getElementsByName(ThisName).length;
  2996. var flag = true;
  2997. if (typeof(document.getElementsByName(ThisName).length)=="undefined")
  2998. {
  2999. flag=true;
  3000. }
  3001. else
  3002. {
  3003. for (var j=0;j<len1;j++)
  3004. {
  3005. if (ThisNameOptions[j].checked==false)
  3006. {
  3007. flag=false
  3008. break;
  3009. }
  3010. }
  3011. }
  3012. CheckAllNameOptions[0].checked=flag
  3013. }
  3014. // Added for page navigation in duplicate-listview
  3015. var dup_start = "";
  3016. function getDuplicateListViewEntries_js(module,url)
  3017. {
  3018. dup_start = url;
  3019. $("status").style.display="block";
  3020. new Ajax.Request(
  3021. 'index.php',
  3022. {queue: {position: 'end', scope: 'command'},
  3023. method: 'post',
  3024. postBody:"module="+module+"&action="+module+"Ajax&file=FindDuplicateRecords&ajax=true&"+dup_start,
  3025. onComplete: function(response) {
  3026. $("status").style.display="none";
  3027. $("duplicate_ajax").innerHTML = response.responseText;
  3028. }
  3029. }
  3030. );
  3031. }
  3032. function getUnifiedSearchEntries_js(module,url){
  3033. var qryStr = document.getElementsByName('search_criteria')[0].value;
  3034. $("status").style.display="block";
  3035. var recordCount = document.getElementById(module+'RecordCount').value;
  3036. new Ajax.Request(
  3037. 'index.php',
  3038. {queue: {position: 'end', scope: 'command'},
  3039. method: 'post',
  3040. postBody:"module="+module+"&action="+module+"Ajax&file=UnifiedSearch&ajax=true&"+url+
  3041. '&query_string='+qryStr+'&search_onlyin='+encodeURIComponent('--USESELECTED--')+'&recordCount='+recordCount,
  3042. onComplete: function(response) {
  3043. $("status").style.display="none";
  3044. $('global_list_'+module).innerHTML = response.responseText;
  3045. }
  3046. }
  3047. );
  3048. }
  3049. /* End */
  3050. //Added after 5.0.4 for Documents Module
  3051. function positionDivToCenter(targetDiv)
  3052. {
  3053. //Gets the browser's viewport dimension
  3054. getViewPortDimension();
  3055. //Gets the Target DIV's width & height in pixels using parseInt function
  3056. divWidth =(parseInt(document.getElementById(targetDiv).style.width))/2;
  3057. divHeight=(parseInt(document.getElementById(targetDiv).style.height))/2;
  3058. //calculate horizontal and vertical locations relative to Viewport's dimensions
  3059. mx = parseInt(XX/2)-parseInt(divWidth);
  3060. my = parseInt(YY/3)-parseInt(divHeight);
  3061. //Prepare the DIV and show in the center of the screen.
  3062. document.getElementById(targetDiv).style.left=mx+"px";
  3063. document.getElementById(targetDiv).style.top=my+"px";
  3064. }
  3065. function getViewPortDimension()
  3066. {
  3067. if(!document.all)
  3068. {
  3069. XX = self.innerWidth;
  3070. YY = self.innerHeight;
  3071. }
  3072. else if(document.all)
  3073. {
  3074. XX = document.documentElement.clientWidth;
  3075. YY = document.documentElement.clientHeight;
  3076. }
  3077. }
  3078. function toggleTable(id) {
  3079. var listTableObj=getObj(id);
  3080. if(listTableObj.style.display=="none")
  3081. {
  3082. listTableObj.style.display="";
  3083. }
  3084. else
  3085. {
  3086. listTableObj.style.display="none";
  3087. }
  3088. //set_cookie(id,listTableObj.style.display)
  3089. }
  3090. function FileAdd(obj,Lay,return_action){
  3091. fnvshobj(obj,Lay);
  3092. window.frames['AddFile'].document.getElementById('divHeader').innerHTML="Add file";
  3093. window.frames['AddFile'].document.FileAdd.return_action.value=return_action;
  3094. positionDivToCenter(Lay);
  3095. }
  3096. function dldCntIncrease(fileid)
  3097. {
  3098. new Ajax.Request(
  3099. 'index.php',
  3100. {queue: {position: 'end', scope: 'command'},
  3101. method: 'post',
  3102. postBody: 'action=DocumentsAjax&mode=ajax&file=SaveFile&module=Documents&file_id='+fileid+"&act=updateDldCnt",
  3103. onComplete: function(response) {
  3104. }
  3105. }
  3106. );
  3107. }
  3108. //End Documents Module
  3109. //asterisk integration :: starts
  3110. /**
  3111. * this function accepts a node and puts it at the center of the screen
  3112. * @param object node - the dom object which you want to set in the center
  3113. */
  3114. function placeAtCenter(node){
  3115. var centerPixel = getViewPortCenter();
  3116. node.style.position = "absolute";
  3117. var point = getDimension(node);
  3118. var topvalue = (centerPixel.y - point.y/2) ;
  3119. var rightvalue = (centerPixel.x - point.x/2);
  3120. //to ensure that values will not be negative
  3121. if(topvalue<0) topvalue = 0;
  3122. if(rightvalue < 0) rightvalue = 0;
  3123. node.style.top = topvalue + "px";
  3124. node.style.right =rightvalue + "px";
  3125. }
  3126. /**
  3127. * this function gets the dimension of a node
  3128. * @param node - the node whose dimension you want
  3129. * @return height and width in array format
  3130. */
  3131. function getDimension(node){
  3132. var ht = node.offsetHeight;
  3133. var wdth = node.offsetWidth;
  3134. var nodeChildren = node.getElementsByTagName("*");
  3135. var noOfChildren = nodeChildren.length;
  3136. for(var index =0;index<noOfChildren;++index){
  3137. ht = Math.max(nodeChildren[index].offsetHeight, ht);
  3138. wdth = Math.max(nodeChildren[index].offsetWidth,wdth);
  3139. }
  3140. return {x: wdth,y: ht};
  3141. }
  3142. /**
  3143. * this function returns the center co-ordinates of the viewport as an array
  3144. */
  3145. function getViewPortCenter(){
  3146. var height;
  3147. var width;
  3148. if(typeof window.pageXOffset != "undefined"){
  3149. height = window.innerHeight/2;
  3150. width = window.innerWidth/2;
  3151. height +=window.pageYOffset;
  3152. width +=window.pageXOffset;
  3153. }else if(document.documentElement && typeof document.documentElement.scrollTop != "undefined"){
  3154. height = document.documentElement.clientHeight/2;
  3155. width = document.documentElement.clientWidth/2;
  3156. height += document.documentElement.scrollTop;
  3157. width += document.documentElement.scrollLeft;
  3158. }else if(document.body && typeof document.body.clientWidth != "undefined"){
  3159. height = window.screen.availHeight/2;
  3160. width = window.screen.availWidth/2;
  3161. height += document.body.clientHeight;
  3162. width += document.body.clientWidth;
  3163. }
  3164. return {x: width,y: height};
  3165. }
  3166. /**
  3167. * this function accepts a number and displays a div stating that there is an outgoing call
  3168. * then it calls the number
  3169. * @param number - the number to be called
  3170. */
  3171. function startCall(number, recordid){
  3172. div = document.getElementById('OutgoingCall').innerHTML;
  3173. outgoingPopup = _defPopup();
  3174. outgoingPopup.content = div;
  3175. outgoingPopup.displayPopup(outgoingPopup.content);
  3176. //var ASTERISK_DIV_TIMEOUT = 6000;
  3177. new Ajax.Request(
  3178. 'index.php',
  3179. { queue: {position: 'end', scope: 'command'},
  3180. method: 'post',
  3181. postBody: 'action=PBXManagerAjax&mode=ajax&file=StartCall&ajax=true&module=PBXManager&number='+encodeURIComponent(number)+'&recordid='+recordid,
  3182. onComplete: function(response) {
  3183. if(response.responseText == ''){
  3184. //successfully called
  3185. }else{
  3186. alert(response.responseText);
  3187. }
  3188. }
  3189. }
  3190. );
  3191. }
  3192. //asterisk integration :: ends
  3193. //added for tooltip manager
  3194. function ToolTipManager(){
  3195. var state = false;
  3196. /**
  3197. * this function creates the tooltip div and adds the information to it
  3198. * @param string text - the text to be added to the tooltip
  3199. */
  3200. function tip(node, text,id,fieldname){
  3201. state=true;
  3202. var divName = getDivId(id,fieldname);
  3203. var div = document.getElementById(divName)
  3204. if(!div){
  3205. div = document.createElement('div');
  3206. div.id = divName;
  3207. div.style.position = 'absolute';
  3208. if(typeof div.style.opacity == "string"){
  3209. div.style.opacity = 0.8;
  3210. }
  3211. div.className = "tooltipClass";
  3212. }
  3213. div.innerHTML = text;
  3214. document.body.appendChild(div);
  3215. div.style.display = "block";
  3216. positionTooltip(node, divName);
  3217. }
  3218. function getDivId(id,fieldname){
  3219. return '__VT_tooltip_'+id+'_'+fieldname;
  3220. }
  3221. function exists(id,fieldname){
  3222. return (typeof document.getElementById(getDivId(id,fieldname)) != 'undefined' &&
  3223. document.getElementById(getDivId(id,fieldname)) != null);
  3224. }
  3225. function show(node,id,fieldname){
  3226. var div = document.getElementById(getDivId(id,fieldname));
  3227. if(typeof div !='undefined' && div != null){
  3228. div.style.display = '';
  3229. positionTooltip(node, getDivId(id,fieldname));
  3230. }
  3231. }
  3232. /**
  3233. * this function removes the tooltip div
  3234. */
  3235. function unTip(nodelay,id,fieldname){
  3236. state=false;
  3237. var divName = getDivId(id,fieldname);
  3238. var div = document.getElementById(divName);
  3239. if(typeof div != 'undefined' && div != null ){
  3240. if(typeof nodelay != 'undefined' && nodelay != null){
  3241. div.style.display = "none";
  3242. }else{
  3243. setTimeout(function(){
  3244. if(!state){
  3245. div.style.display = "none";
  3246. }
  3247. }, 700);
  3248. }
  3249. }
  3250. }
  3251. /**
  3252. * this function is used to position the tooltip div
  3253. * @param string obj - the id of the element where the div has to appear
  3254. * @param object div - the div which contains the info
  3255. */
  3256. function positionTooltip(obj,div){
  3257. var tooltip = document.getElementById(div);
  3258. var leftSide = findPosX(obj);
  3259. var topSide = findPosY(obj);
  3260. var dimensions = getDimension(tooltip);
  3261. var widthM = dimensions.x;
  3262. var getVal = eval(leftSide) + eval(widthM);
  3263. var tooltipDimensions = getDimension(obj);
  3264. var tooltipWidth = tooltipDimensions.x;
  3265. if(getVal > document.body.clientWidth ){
  3266. leftSide = eval(leftSide) - eval(widthM);
  3267. }else{
  3268. leftSide = eval(leftSide) + (eval(tooltipWidth)/2);
  3269. }
  3270. if(leftSide < 0) {
  3271. leftSide = findPosX(obj) + tooltipWidth;
  3272. }
  3273. tooltip.style.left = leftSide + 'px';
  3274. var heightTooltip = dimensions.y;
  3275. var bottomSide = eval(topSide) + eval(heightTooltip);
  3276. if(bottomSide > document.body.clientHeight){
  3277. topSide = topSide - (bottomSide - document.body.clientHeight) - 10;
  3278. if(topSide < 0 ){
  3279. topSide = 10;
  3280. }
  3281. }else{
  3282. topSide = eval(topSide) - eval(heightTooltip)/2;
  3283. if(topSide<0){
  3284. topSide = 10;
  3285. }
  3286. }
  3287. tooltip.style.top= topSide + 'px';
  3288. }
  3289. return {tip:tip, untip:unTip,'exists': exists,'show': show,'getDivId':getDivId};
  3290. }
  3291. if(!tooltip){
  3292. var tooltip = ToolTipManager();
  3293. }
  3294. //tooltip manager changes end
  3295. function submitFormForActionWithConfirmation(formName, action, confirmationMsg) {
  3296. if (confirm(confirmationMsg)) {
  3297. return submitFormForAction(formName, action);
  3298. }
  3299. return false;
  3300. }
  3301. function submitFormForAction(formName, action) {
  3302. var form = document.forms[formName];
  3303. if (!form) return false;
  3304. form.action.value = action;
  3305. form.submit();
  3306. return true;
  3307. }
  3308. /** Javascript dialog box utility functions **/
  3309. VtigerJS_DialogBox = {
  3310. _olayer : function(toggle) {
  3311. var olayerid = "__vtigerjs_dialogbox_olayer__";
  3312. VtigerJS_DialogBox._removebyid(olayerid);
  3313. if(typeof(toggle) == 'undefined' || !toggle) return;
  3314. var olayer = document.getElementById(olayerid);
  3315. if(!olayer) {
  3316. olayer = document.createElement("div");
  3317. olayer.id = olayerid;
  3318. olayer.className = "small veil";
  3319. olayer.style.zIndex = (new Date()).getTime();
  3320. // In case zIndex goes to negative side!
  3321. if(olayer.style.zIndex < 0) olayer.style.zIndex *= -1;
  3322. if (browser_ie) {
  3323. olayer.style.height = document.body.offsetHeight + (document.body.scrollHeight - document.body.offsetHeight) + "px";
  3324. } else if (browser_nn4 || browser_nn6) { olayer.style.height = document.body.offsetHeight + "px"; }
  3325. olayer.style.width = "100%";
  3326. document.body.appendChild(olayer);
  3327. var closeimg = document.createElement("img");
  3328. closeimg.src = 'themes/images/close.gif';
  3329. closeimg.alt = 'X';
  3330. closeimg.style.right= '10px';
  3331. closeimg.style.top = '5px';
  3332. closeimg.style.position = 'absolute';
  3333. closeimg.style.cursor = 'pointer';
  3334. closeimg.onclick = VtigerJS_DialogBox.unblock;
  3335. olayer.appendChild(closeimg);
  3336. }
  3337. if(olayer) {
  3338. if(toggle) olayer.style.display = "block";
  3339. else olayer.style.display = "none";
  3340. }
  3341. return olayer;
  3342. },
  3343. _removebyid : function(id) {
  3344. if($(id)) $(id).remove();
  3345. },
  3346. unblock : function() {
  3347. VtigerJS_DialogBox._olayer(false);
  3348. },
  3349. block : function(opacity) {
  3350. if(typeof(opactiy)=='undefined') opacity = '0.3';
  3351. var olayernode = VtigerJS_DialogBox._olayer(true);
  3352. olayernode.style.opacity = opacity;
  3353. },
  3354. hideprogress : function() {
  3355. VtigerJS_DialogBox._olayer(false);
  3356. VtigerJS_DialogBox._removebyid('__vtigerjs_dialogbox_progress_id__');
  3357. },
  3358. progress : function(imgurl) {
  3359. VtigerJS_DialogBox._olayer(true);
  3360. if(typeof(imgurl) == 'undefined') imgurl = 'themes/images/plsWaitAnimated.gif';
  3361. var prgbxid = "__vtigerjs_dialogbox_progress_id__";
  3362. var prgnode = document.getElementById(prgbxid);
  3363. if(!prgnode) {
  3364. prgnode = document.createElement("div");
  3365. prgnode.id = prgbxid;
  3366. prgnode.className = 'veil_new';
  3367. prgnode.style.position = 'absolute';
  3368. prgnode.style.width = '100%';
  3369. prgnode.style.top = '0';
  3370. prgnode.style.left = '0';
  3371. prgnode.style.display = 'block';
  3372. document.body.appendChild(prgnode);
  3373. prgnode.innerHTML =
  3374. '<table border="5" cellpadding="0" cellspacing="0" align="center" style="vertical-align:middle;width:100%;height:100%;">' +
  3375. '<tr><td class="big" align="center"><img src="'+ imgurl + '"></td></tr></table>';
  3376. }
  3377. if(prgnode) prgnode.style.display = 'block';
  3378. },
  3379. hideconfirm : function() {
  3380. VtigerJS_DialogBox._olayer(false);
  3381. VtigerJS_DialogBox._removebyid('__vtigerjs_dialogbox_alert_boxid__');
  3382. },
  3383. confirm : function(msg, onyescode) {
  3384. VtigerJS_DialogBox._olayer(true);
  3385. var dlgbxid = "__vtigerjs_dialogbox_alert_boxid__";
  3386. var dlgbxnode = document.getElementById(dlgbxid);
  3387. if(!dlgbxnode) {
  3388. dlgbxnode = document.createElement("div");
  3389. dlgbxnode.style.display = 'none';
  3390. dlgbxnode.className = 'veil_new small';
  3391. dlgbxnode.id = dlgbxid;
  3392. dlgbxnode.innerHTML =
  3393. '<table cellspacing="0" cellpadding="18" border="0" class="options small">' +
  3394. '<tbody>' +
  3395. '<tr>' +
  3396. '<td nowrap="" align="center" style="color: rgb(255, 255, 255); font-size: 15px;">' +
  3397. '<b>'+ msg + '</b></td>' +
  3398. '</tr>' +
  3399. '<tr>' +
  3400. '<td align="center">' +
  3401. '<input type="button" style="text-transform: capitalize;" onclick="$(\''+ dlgbxid + '\').hide();VtigerJS_DialogBox._olayer(false);VtigerJS_DialogBox._confirm_handler();" value="'+ alert_arr.YES + '"/>' +
  3402. '<input type="button" style="text-transform: capitalize;" onclick="$(\''+ dlgbxid + '\').hide();VtigerJS_DialogBox._olayer(false)" value="' + alert_arr.NO + '"/>' +
  3403. '</td>'+
  3404. '</tr>' +
  3405. '</tbody>' +
  3406. '</table>';
  3407. document.body.appendChild(dlgbxnode);
  3408. }
  3409. if(typeof(onyescode) == 'undefined') onyescode = '';
  3410. dlgbxnode._onyescode = onyescode;
  3411. if(dlgbxnode) dlgbxnode.style.display = 'block';
  3412. },
  3413. _confirm_handler : function() {
  3414. var dlgbxid = "__vtigerjs_dialogbox_alert_boxid__";
  3415. var dlgbxnode = document.getElementById(dlgbxid);
  3416. if(dlgbxnode) {
  3417. if(typeof(dlgbxnode._onyescode) != 'undefined' && dlgbxnode._onyescode != '') {
  3418. eval(dlgbxnode._onyescode);
  3419. }
  3420. }
  3421. }
  3422. }