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.

557 lines
21 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 ShowCalFromToUpToTodayForInput(calFrom, calTo, nom) {
  348. if (nom === null || nom === "" || nom === undefined) nom = 1;
  349. $(function () {
  350. var fromDateIdNameOnly = calFrom.split('#')[1];
  351. var selectedDate = $(calFrom).val();
  352. if (selectedDate.length > 0) {
  353. $(calTo).datepicker("option", "minDate", selectedDate);
  354. document.getElementById(fromDateIdNameOnly).setAttribute("onchange", "return DateValidation('" + fromDateIdNameOnly + "','t')");
  355. }
  356. if (calTo !== undefined) {
  357. var toDate = $(calTo).val();
  358. if (toDate.length > 0) {
  359. $(calFrom).datepicker("option", "maxDate", toDate);
  360. }
  361. if (calTo !== undefined && calTo.length > 0) {
  362. document.getElementById(fromDateIdNameOnly).removeAttribute("onchange");
  363. toDateIdNameOnly = calTo.split("#")[1];
  364. document.getElementById(fromDateIdNameOnly).setAttribute("onchange", "return DateValidation('" + fromDateIdNameOnly + "','t','" + toDateIdNameOnly + "')");
  365. document.getElementById(toDateIdNameOnly).setAttribute("onchange", "return DateValidation('" + fromDateIdNameOnly + "','t','" + toDateIdNameOnly + "')");
  366. }
  367. }
  368. });
  369. }
  370. //// Input Date Validation
  371. function DateValidation(id, typeVal, compareId, compareTypeVal) {
  372. var firstDate = '';
  373. var firstId = id;
  374. var inputDate = document.getElementById(id).value;
  375. var dates = inputDate.split("-");
  376. if (id !== undefined && id.length > 0 && inputDate.length > 0) {
  377. 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) {
  378. var currentDate = new Date(Date.now()).toLocaleDateString();
  379. var currentDates = currentDate.split('/');
  380. if (dates[1] <= 9 && dates[1].length <= 1) {
  381. dates[1] = '0' + dates[1];
  382. }
  383. if (dates[2] <= 9 && dates[2].length <= 1) {
  384. dates[2] = '0' + dates[2];
  385. }
  386. if (currentDates[0] <= 9 && currentDates[0].length <= 1) {
  387. currentDates[0] = '0' + currentDates[0];
  388. }
  389. if (currentDates[1] <= 9 && currentDates[1].length <= 1) {
  390. currentDates[1] = '0' + currentDates[1];
  391. }
  392. inputDate = dates[0] + "-" + dates[1] + "-" + dates[2];
  393. currentDate = currentDates[2] + '-' + currentDates[0] + '-' + currentDates[1];
  394. if (typeVal === "dob") {
  395. CalSenderDOB("#" + id);
  396. var dobValidDate = currentDates[2] - 16 + '-' + currentDates[0] + '-' + currentDates[1];
  397. if (inputDate <= dobValidDate) {
  398. }
  399. else {
  400. SetValueById(id, '', '');
  401. alert("Date Of Birth Must Be At Least 16 Years Old.");
  402. return document.getElementById(id).focus();
  403. }
  404. }
  405. else if (typeVal === "t") {
  406. ShowCalFromToUpToToday("#" + id);
  407. var ValidDate = currentDates[2] - 2 + '-' + currentDates[0] + '-' + currentDates[1];
  408. if (inputDate < ValidDate) {
  409. SetValueById(id, '', '');
  410. return document.getElementById(id).focus();
  411. }
  412. if (inputDate > currentDate) {
  413. SetValueById(id, '', '');
  414. alert("You Cannot Input Future Date.");
  415. return document.getElementById(id).focus();
  416. }
  417. }
  418. else if (typeVal === "f") {
  419. AllowFutureDate("#" + id);
  420. if (inputDate < currentDate) {
  421. SetValueById(id, '', '');
  422. alert("You Cannot Input Past Date.");
  423. return document.getElementById(id).focus();
  424. }
  425. }
  426. else if (typeVal === "i") {
  427. CalTillToday("#" + id);
  428. if (inputDate > currentDate) {
  429. SetValueById(id, '', '');
  430. alert("You Cannot Input Future Date.");
  431. return document.getElementById(id).focus();
  432. }
  433. }
  434. firstDate = inputDate;
  435. $("#" + id).val(inputDate);
  436. }
  437. else {
  438. SetValueById(id, '');
  439. alert("Invalid Date Format ! Please Enter yyyy-mm-dd format");
  440. return document.getElementById(id).focus();
  441. }
  442. }
  443. if (compareId !== undefined && compareId.length > 0) {
  444. var compareDate = document.getElementById(compareId).value;
  445. if (compareDate.length > 0) {
  446. if (compareTypeVal !== undefined && compareTypeVal.length > 0) {
  447. typeVal = '';
  448. typeVal = compareTypeVal;
  449. }
  450. var dates = compareDate.split("-");
  451. 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) {
  452. var currentDate = new Date(Date.now()).toLocaleDateString();
  453. var currentDates = currentDate.split('/');
  454. if (dates[1] <= 9 && dates[1].length <= 1) {
  455. dates[1] = '0' + dates[1];
  456. }
  457. if (dates[2] <= 9 && dates[2].length <= 1) {
  458. dates[2] = '0' + dates[2];
  459. }
  460. if (currentDates[0] <= 9 && currentDates[0].length <= 1) {
  461. currentDates[0] = '0' + currentDates[0];
  462. }
  463. if (currentDates[1] <= 9 && currentDates[1].length <= 1) {
  464. currentDates[1] = '0' + currentDates[1];
  465. }
  466. compareDate = dates[0] + "-" + dates[1] + "-" + dates[2];
  467. currentDate = currentDates[2] + '-' + currentDates[0] + '-' + currentDates[1];
  468. if (typeVal === "t") {
  469. var ValidDate = currentDates[2] - 2 + '-' + currentDates[0] + '-' + currentDates[1];
  470. if (compareDate < ValidDate) {
  471. SetValueById(compareId, '', '');
  472. compareDate = '';
  473. document.getElementById(compareId).focus();
  474. }
  475. if (compareDate > currentDate) {
  476. SetValueById(compareId, '', '');
  477. compareDate = '';
  478. alert("You Cannot Input Future Date.");
  479. document.getElementById(compareId).focus();
  480. }
  481. }
  482. if (firstDate.length === 10) {
  483. if (firstDate > compareDate) {
  484. SetValueById(compareId, '');
  485. compareDate = '';
  486. alert("To Date Must Be Greater Or Equal To From Date");
  487. document.getElementById(id).focus();
  488. }
  489. }
  490. $("#" + compareId).val(compareDate);
  491. }
  492. else {
  493. SetValueById(compareId, '');
  494. alert("Invalid Date Format ! Please Enter yyyy-mm-dd format");
  495. return document.getElementById(compareId).focus();
  496. }
  497. }
  498. ShowCalFromToUpToTodayForInput("#" + id, "#" + compareId);
  499. }
  500. }
  501. function From(cal) {
  502. $(function () {
  503. $(cal).datepicker({
  504. changeMonth: true,
  505. changeYear: true,
  506. numberOfMonths: 1,
  507. showOn: "both",
  508. dateFormat: dateFormatType,
  509. maxDate: "+0",
  510. minDate: "-80Y",
  511. onSelect: function (selectedDate) {
  512. $('#to').datepicker("option", "minDate", selectedDate);
  513. }
  514. });
  515. });
  516. }
  517. function To(cal) {
  518. $(function () {
  519. $(cal).datepicker({
  520. changeMonth: true,
  521. changeYear: true,
  522. numberOfMonths: 1,
  523. showOn: "both",
  524. dateFormat: dateFormatType,
  525. maxDate: "+0",
  526. minDate: "-80Y",
  527. onSelect: function (selectedDate) {
  528. var fromDate = $('#from').val();
  529. $(cal).datepicker("option", "minDate", fromDate);
  530. }
  531. });
  532. });
  533. }