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.

611 lines
23 KiB

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