PageRenderTime 70ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/trunk/modules/PDFSettings/serverfiles/include/js/general.js

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