You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

528 lines
21 KiB

4 years ago
  1. //var imgPath = "/images/calendar.gif";
  2. var dateFormatType = 'yy-mm-dd';
  3. function ShowCalDefault(cal) {
  4. $(document).ready(function () {
  5. $(function () {
  6. $(cal).datepicker({
  7. changeMonth: true,
  8. changeYear: true,
  9. showOn: "both",
  10. //buttonImage: imgPath,
  11. //buttonImageOnly: true,
  12. dateFormat: dateFormatType,
  13. onClose: function () {
  14. this.focus();
  15. }
  16. });
  17. });
  18. });
  19. }
  20. function CalIDIssueDate(cal) {
  21. $(function () {
  22. $(cal).datepicker({
  23. changeMonth: true,
  24. changeYear: true,
  25. showOn: "both",
  26. //buttonImage: "/images/calendar.gif",
  27. //buttonImageOnly: true,
  28. //yearRange: "-90",
  29. //maxDate: "+0",
  30. //minDate: "-2Y",
  31. dateFormat: dateFormatType,
  32. maxDate: "+0Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  33. minDate: "-90Y",
  34. onClose: function (x, y) {
  35. this.focus();
  36. }
  37. });
  38. });
  39. }
  40. function VisaValidDateSend(cal) {
  41. $(function () {
  42. $(cal).datepicker({
  43. changeMonth: true,
  44. changeYear: true,
  45. showOn: "both",
  46. buttonImage: "/images/calendar.gif",
  47. buttonImageOnly: true,
  48. dateFormat: dateFormatType,
  49. //yearRange: "-60:-18", //18 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  50. maxDate: "+10Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  51. minDate: "+1"
  52. });
  53. });
  54. }
  55. function CalSenderDOB(cal) {
  56. $(function () {
  57. $(cal).datepicker({
  58. changeMonth: true,
  59. changeYear: true,
  60. showOn: "both",
  61. buttonImage: "/images/calendar.gif",
  62. buttonImageOnly: true,
  63. dateFormat: dateFormatType,
  64. yearRange: "-90:-16", //16 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  65. maxDate: "-16Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  66. minDate: "-90Y"
  67. //onClose: function (x, y) {
  68. // $("#txtSendMobile").focus();
  69. //}
  70. });
  71. });
  72. }
  73. function CalReceiverDOB(cal) {
  74. $(function () {
  75. $(cal).datepicker({
  76. changeMonth: true,
  77. changeYear: true,
  78. showOn: "both",
  79. //buttonImage: imgPath,
  80. //buttonImageOnly: true,
  81. dateFormat: dateFormatType,
  82. yearRange: "-90:-18", //18 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  83. maxDate: "-18Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  84. minDate: "-90Y",
  85. onClose: function (x, y) {
  86. $("#txtRecMobile").focus();
  87. }
  88. });
  89. });
  90. }
  91. function CalFromToday(cal) {
  92. $(function () {
  93. $(cal).datepicker({
  94. changeMonth: true,
  95. changeYear: true,
  96. showOn: "both", dateFormat: dateFormatType,
  97. //buttonImage: imgPath,
  98. //buttonImageOnly: true,
  99. maxDate: "+20Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  100. minDate: "+0",
  101. onClose: function (x, y) {
  102. $("#txtRecMobile").focus();
  103. }
  104. });
  105. });
  106. }
  107. function CalFromYesterdayToToday(cal) {
  108. $(function () {
  109. $(cal).datepicker({
  110. changeMonth: true,
  111. changeYear: true,
  112. showOn: "both", dateFormat: dateFormatType,
  113. //buttonImage: imgPath,
  114. //buttonImageOnly: true,
  115. yearRange: "-90:-18", //18 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  116. maxDate: "+0", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  117. minDate: "-1",
  118. onClose: function (x, y) {
  119. $("#txtRecMobile").focus();
  120. }
  121. });
  122. });
  123. }
  124. function CalUpToToday(cal) {
  125. $(function () {
  126. $(cal).datepicker({
  127. changeMonth: true,
  128. changeYear: true,
  129. showOn: "both", dateFormat: dateFormatType,
  130. // buttonImage: imgPath,
  131. //buttonImageOnly: true,
  132. // yearRange: "-90:-18", //18 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  133. maxDate: "+0", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  134. minDate: "-2Y",
  135. });
  136. });
  137. }
  138. function ExpiryDate(cal) {
  139. $(function () {
  140. $(cal).datepicker({
  141. changeMonth: true,
  142. changeYear: true,
  143. showOn: "both", dateFormat: dateFormatType,
  144. //buttonImage: "/images/calendar.gif",
  145. //buttonImageOnly: true,
  146. //yearRange: "-60:-18", //18 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  147. maxDate: "+10Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  148. minDate: "+6M",
  149. onClose: function () {
  150. this.focus();
  151. }
  152. });
  153. });
  154. }
  155. function AllowFutureDate(cal) {
  156. $(function () {
  157. $(cal).datepicker({
  158. changeMonth: true,
  159. changeYear: true,
  160. showOn: "both", dateFormat: dateFormatType,
  161. //buttonImage: "/images/calendar.gif",
  162. //buttonImageOnly: true,
  163. //yearRange: "-60:-18", //18 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  164. maxDate: "+10Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  165. minDate: "+0D",
  166. onClose: function () {
  167. this.focus();
  168. }
  169. });
  170. });
  171. }
  172. function VisaValidDate(cal) {
  173. $(function () {
  174. alert("Visa");
  175. $(cal).datepicker({
  176. changeMonth: true,
  177. changeYear: true,
  178. showOn: "both", dateFormat: dateFormatType,
  179. //buttonImage: imgPath,
  180. // buttonImageOnly: true,
  181. //yearRange: "-60:-18", //18 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  182. maxDate: "+10Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  183. minDate: "+1",
  184. onClose: function () {
  185. this.focus();
  186. }
  187. });
  188. });
  189. }
  190. function VisaValidDateRec(cal) {
  191. $(function () {
  192. $(cal).datepicker({
  193. changeMonth: true,
  194. changeYear: true,
  195. showOn: "both", dateFormat: dateFormatType,
  196. //buttonImage: imgPath,
  197. // buttonImageOnly: true,
  198. //yearRange: "-60:-18", //18 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  199. maxDate: "+10Y", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  200. minDate: "+1",
  201. onClose: function (x, y) {
  202. $("#txtRecMobile").focus();
  203. }
  204. });
  205. });
  206. }
  207. function ShowCalFromTo(calFrom, calTo, nom) {
  208. if (nom === null || nom === "" || nom === undefined) nom = 1;
  209. $(function () {
  210. $(calFrom).datepicker({
  211. //defaultDate: "+1w",
  212. changeMonth: true,
  213. changeYear: true,
  214. numberOfMonths: nom,
  215. showOn: "both", dateFormat: dateFormatType,
  216. //buttonImage: imgPath,
  217. // buttonImageOnly: true,
  218. onSelect: function (selectedDate) {
  219. $(calTo).datepicker("option", "minDate", selectedDate);
  220. }
  221. });
  222. $(calTo).datepicker({
  223. //defaultDate: "+1w",
  224. changeMonth: true,
  225. changeYear: true,
  226. numberOfMonths: nom,
  227. showOn: "both", dateFormat: dateFormatType,
  228. //buttonImage: imgPath,
  229. //buttonImageOnly: true,
  230. onSelect: function (selectedDate) {
  231. $(calFrom).datepicker("option", "maxDate", selectedDate);
  232. }
  233. });
  234. });
  235. }
  236. function CalSendB2BDoi(cal) {
  237. $(function () {
  238. $(cal).datepicker({
  239. changeMonth: true,
  240. changeYear: true,
  241. showOn: "both",
  242. dateFormat: dateFormatType,
  243. //buttonImage: imgPath,
  244. // buttonImageOnly: true,
  245. // yearRange: "-90:-18", //18 years or older up until 115yo (oldest person ever, can be sensibly set to something much smaller in most cases)
  246. maxDate: "+0", //Will only allow the selection of dates more than 18 years ago, useful if you need to restrict this
  247. minDate: "-90Y",
  248. onClose: function (x, y) {
  249. $("#txtRecMobile").focus();
  250. }
  251. });
  252. });
  253. }
  254. //@PRALHAD allow to select till today
  255. function CalTillToday(cal) {
  256. $(function () {
  257. $(cal).datepicker({
  258. changeMonth: true,
  259. changeYear: true,
  260. numberOfMonths: 1,
  261. showOn: "both",
  262. dateFormat: dateFormatType,
  263. maxDate: "+0",
  264. minDate: "-80Y",
  265. onSelect: function (selectedDate) {
  266. $(cal).datepicker("option", "minDate", selectedDate);
  267. }
  268. });
  269. });
  270. }
  271. function ShowCalFromToUpToToday(calFrom, calTo, nom) {
  272. if (nom === null || nom === "" || nom === undefined) nom = 1;
  273. $(function () {
  274. if (calFrom !== undefined && calFrom.length > 0) {
  275. $(calFrom).datepicker({
  276. //defaultDate: "+1w",
  277. changeMonth: true,
  278. changeYear: true,
  279. numberOfMonths: 1,
  280. showOn: "both",
  281. dateFormat: dateFormatType,
  282. //buttonImage: imgPath,
  283. // buttonImageOnly: true,
  284. maxDate: "+0",
  285. //minDate: "-2Y",
  286. onSelect: function (selectedDate) {
  287. $(calTo).datepicker("option", "minDate", selectedDate);
  288. }
  289. });
  290. var fromDateIdNameOnly = calFrom.split('#')[1];
  291. document.getElementById(fromDateIdNameOnly).setAttribute("onchange", "return DateValidation('" + fromDateIdNameOnly + "','t')");
  292. }
  293. if (calTo !== undefined && calTo.length > 0) {
  294. $(calTo).datepicker({
  295. //defaultDate: "+1w",
  296. changeMonth: true,
  297. changeYear: true,
  298. numberOfMonths: nom,
  299. showOn: "both",
  300. //buttonImage: imgPath,
  301. //buttonImageOnly: true,
  302. dateFormat: dateFormatType,
  303. maxDate: "+0",
  304. //minDate: "-2Y",
  305. onSelect: function (selectedDate) {
  306. $(calFrom).datepicker("option", "maxDate", selectedDate);
  307. }
  308. });
  309. var toDateIdNameOnly = calFrom.split('#')[1];
  310. if (calTo !== undefined && calTo.length > 0) {
  311. document.getElementById(toDateIdNameOnly).removeAttribute("onchange");
  312. toDateIdNameOnly = calTo.split("#")[1];
  313. document.getElementById(toDateIdNameOnly).setAttribute("onchange", "return DateValidation('" + toDateIdNameOnly + "','t','" + toDateIdNameOnly + "')");
  314. document.getElementById(toDateIdNameOnly).setAttribute("onchange", "return DateValidation('" + toDateIdNameOnly + "','t','" + toDateIdNameOnly + "')");
  315. }
  316. }
  317. });
  318. }
  319. function ShowCalFromToUpToTodayForInput(calFrom, calTo, nom) {
  320. if (nom === null || nom === "" || nom === undefined) nom = 1;
  321. $(function () {
  322. var fromDateIdNameOnly = calFrom.split('#')[1];
  323. var selectedDate = $(calFrom).val();
  324. if (selectedDate.length > 0) {
  325. $(calTo).datepicker("option", "minDate", selectedDate);
  326. document.getElementById(fromDateIdNameOnly).setAttribute("onchange", "return DateValidation('" + fromDateIdNameOnly + "','t')");
  327. }
  328. if (calTo !== undefined) {
  329. var toDate = $(calTo).val();
  330. if (toDate.length > 0) {
  331. $(calFrom).datepicker("option", "maxDate", toDate);
  332. }
  333. if (calTo !== undefined && calTo.length > 0) {
  334. document.getElementById(fromDateIdNameOnly).removeAttribute("onchange");
  335. toDateIdNameOnly = calTo.split("#")[1];
  336. document.getElementById(fromDateIdNameOnly).setAttribute("onchange", "return DateValidation('" + fromDateIdNameOnly + "','t','" + toDateIdNameOnly + "')");
  337. document.getElementById(toDateIdNameOnly).setAttribute("onchange", "return DateValidation('" + fromDateIdNameOnly + "','t','" + toDateIdNameOnly + "')");
  338. }
  339. }
  340. });
  341. }
  342. //// Input Date Validation
  343. function DateValidation(id, typeVal, compareId, compareTypeVal) {
  344. var firstDate = '';
  345. var firstId = id;
  346. var inputDate = document.getElementById(id).value;
  347. var dates = inputDate.split("-");
  348. if (id !== undefined && id.length > 0 && inputDate.length > 0) {
  349. if (dates.length === 3 && dates[0].length === 4 && dates[1].length <= 2 && dates[1] > 0 && dates[1] <= 12 && dates[2].length <= 2 && dates[2] > 0 && dates[2] <= 31) {
  350. var currentDate = new Date(Date.now()).toLocaleDateString();
  351. var currentDates = currentDate.split('/');
  352. if (dates[1] <= 9 && dates[1].length <= 1) {
  353. dates[1] = '0' + dates[1];
  354. }
  355. if (dates[2] <= 9 && dates[2].length <= 1) {
  356. dates[2] = '0' + dates[2];
  357. }
  358. if (currentDates[0] <= 9 && currentDates[0].length <= 1) {
  359. currentDates[0] = '0' + currentDates[0];
  360. }
  361. if (currentDates[1] <= 9 && currentDates[1].length <= 1) {
  362. currentDates[1] = '0' + currentDates[1];
  363. }
  364. inputDate = dates[0] + "-" + dates[1] + "-" + dates[2];
  365. currentDate = currentDates[2] + '-' + currentDates[0] + '-' + currentDates[1];
  366. if (typeVal === "dob") {
  367. CalSenderDOB("#" + id);
  368. var dobValidDate = currentDates[2] - 16 + '-' + currentDates[0] + '-' + currentDates[1];
  369. if (inputDate <= dobValidDate) {
  370. }
  371. else {
  372. SetValueById(id, '', '');
  373. alert("Date Of Birth Must Be At Least 16 Years Old.");
  374. return document.getElementById(id).focus();
  375. }
  376. }
  377. else if (typeVal === "t") {
  378. ShowCalFromToUpToToday("#" + id);
  379. var ValidDate = currentDates[2] - 2 + '-' + currentDates[0] + '-' + currentDates[1];
  380. if (inputDate < ValidDate) {
  381. SetValueById(id, '', '');
  382. return document.getElementById(id).focus();
  383. }
  384. if (inputDate > currentDate) {
  385. SetValueById(id, '', '');
  386. alert("You Cannot Input Future Date.");
  387. return document.getElementById(id).focus();
  388. }
  389. }
  390. else if (typeVal === "f") {
  391. AllowFutureDate("#" + id);
  392. if (inputDate < currentDate) {
  393. SetValueById(id, '', '');
  394. alert("You Cannot Input Past Date.");
  395. return document.getElementById(id).focus();
  396. }
  397. }
  398. else if (typeVal === "i") {
  399. CalTillToday("#" + id);
  400. if (inputDate > currentDate) {
  401. SetValueById(id, '', '');
  402. alert("You Cannot Input Future Date.");
  403. return document.getElementById(id).focus();
  404. }
  405. }
  406. firstDate = inputDate;
  407. $("#" + id).val(inputDate);
  408. }
  409. else {
  410. SetValueById(id, '');
  411. alert("Invalid Date Format ! Please Enter yyyy-mm-dd format");
  412. return document.getElementById(id).focus();
  413. }
  414. }
  415. if (compareId !== undefined && compareId.length > 0) {
  416. var compareDate = document.getElementById(compareId).value;
  417. if (compareDate.length > 0) {
  418. if (compareTypeVal !== undefined && compareTypeVal.length > 0) {
  419. typeVal = '';
  420. typeVal = compareTypeVal;
  421. }
  422. var dates = compareDate.split("-");
  423. if (dates.length == 3 && dates[0].length == 4 && dates[1].length <= 2 && dates[1] > 0 && dates[1] <= 12 && dates[2].length <= 2 && dates[2] > 0 && dates[2] <= 31) {
  424. var currentDate = new Date(Date.now()).toLocaleDateString();
  425. var currentDates = currentDate.split('/');
  426. if (dates[1] <= 9 && dates[1].length <= 1) {
  427. dates[1] = '0' + dates[1];
  428. }
  429. if (dates[2] <= 9 && dates[2].length <= 1) {
  430. dates[2] = '0' + dates[2];
  431. }
  432. if (currentDates[0] <= 9 && currentDates[0].length <= 1) {
  433. currentDates[0] = '0' + currentDates[0];
  434. }
  435. if (currentDates[1] <= 9 && currentDates[1].length <= 1) {
  436. currentDates[1] = '0' + currentDates[1];
  437. }
  438. compareDate = dates[0] + "-" + dates[1] + "-" + dates[2];
  439. currentDate = currentDates[2] + '-' + currentDates[0] + '-' + currentDates[1];
  440. if (typeVal === "t") {
  441. var ValidDate = currentDates[2] - 2 + '-' + currentDates[0] + '-' + currentDates[1];
  442. if (compareDate < ValidDate) {
  443. SetValueById(compareId, '', '');
  444. compareDate = '';
  445. document.getElementById(compareId).focus();
  446. }
  447. if (compareDate > currentDate) {
  448. SetValueById(compareId, '', '');
  449. compareDate = '';
  450. alert("You Cannot Input Future Date.");
  451. document.getElementById(compareId).focus();
  452. }
  453. }
  454. if (firstDate.length === 10) {
  455. if (firstDate > compareDate) {
  456. SetValueById(compareId, '');
  457. compareDate = '';
  458. alert("To Date Must Be Greater Or Equal To From Date");
  459. document.getElementById(id).focus();
  460. }
  461. }
  462. $("#" + compareId).val(compareDate);
  463. }
  464. else {
  465. SetValueById(compareId, '');
  466. alert("Invalid Date Format ! Please Enter yyyy-mm-dd format");
  467. return document.getElementById(compareId).focus();
  468. }
  469. }
  470. ShowCalFromToUpToTodayForInput("#" + id, "#" + compareId);
  471. }
  472. }
  473. function From(cal) {
  474. $(function () {
  475. $(cal).datepicker({
  476. changeMonth: true,
  477. changeYear: true,
  478. numberOfMonths: 1,
  479. showOn: "both",
  480. dateFormat: dateFormatType,
  481. maxDate: "+0",
  482. minDate: "-80Y",
  483. onSelect: function (selectedDate) {
  484. $('#to').datepicker("option", "minDate", selectedDate);
  485. }
  486. });
  487. });
  488. }
  489. function To(cal) {
  490. $(function () {
  491. $(cal).datepicker({
  492. changeMonth: true,
  493. changeYear: true,
  494. numberOfMonths: 1,
  495. showOn: "both",
  496. dateFormat: dateFormatType,
  497. maxDate: "+0",
  498. minDate: "-80Y",
  499. onSelect: function (selectedDate) {
  500. var fromDate = $('#from').val();
  501. $(cal).datepicker("option", "minDate", fromDate);
  502. }
  503. });
  504. });
  505. }