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.

512 lines
19 KiB

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