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.

472 lines
18 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  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. debugger
  304. var firstDate = '';
  305. var checkDate = document.getElementById(id);
  306. if (checkDate === undefined || checkDate === null || checkDate === "" || checkDate.length < 10) {
  307. if (ContentPlaceHolderId.length >= 0) {
  308. id = ContentPlaceHolderId + id;
  309. }
  310. }
  311. var firstId = id;
  312. var inputDate = document.getElementById(id).value;
  313. var dates = inputDate.split("-");
  314. if (id !== undefined && id.length > 0 && inputDate.length > 0) {
  315. 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) {
  316. var currentDate = new Date(Date.now()).toLocaleDateString();
  317. console.log('Local date' + currentDate);
  318. var currentDates = currentDate.split('/');
  319. if (dates[1] <= 9 && dates[1].length <= 1) {
  320. dates[1] = '0' + dates[1];
  321. }
  322. if (dates[2] <= 9 && dates[2].length <= 1) {
  323. dates[2] = '0' + dates[2];
  324. }
  325. if (currentDates[0] <= 9 && currentDates[0].length <= 1) {
  326. currentDates[0] = '0' + currentDates[0];
  327. }
  328. if (currentDates[1] <= 9 && currentDates[1].length <= 1) {
  329. currentDates[1] = '0' + currentDates[1];
  330. }
  331. inputDate = dates[0] + "-" + dates[1] + "-" + dates[2];
  332. currentDate = currentDates[2] + '-' + currentDates[0] + '-' + currentDates[1];
  333. console.log('current date ' + currentDate + 'input date ' + inputDate);
  334. if (typeVal === "dob") {
  335. CalSenderDOB("#" + id);
  336. var dobValidDate = currentDates[2] - 16 + '-' + currentDates[0] + '-' + currentDates[1];
  337. var LastValidDate = currentDates[2] - 125 + '-' + currentDates[0] + '-' + currentDates[1];
  338. if (inputDate < LastValidDate) {
  339. SetValueById(id, '');
  340. alert("Invalid Date Format ! Date Can't be Earlier Then " + LastValidDate);
  341. return document.getElementById(id).focus();
  342. } else {
  343. if (inputDate <= dobValidDate) {
  344. console.log('valid');
  345. }
  346. else {
  347. SetValueById(id, '', '');
  348. alert("Date Of Birth Must Be At Least 16 Years Old.");
  349. return document.getElementById(id).focus();
  350. }
  351. }
  352. }
  353. else if (typeVal === "t") {
  354. ShowCalFromToUpToToday("#" + id);
  355. var ValidDate = currentDates[2] - 2 + '-' + currentDates[0] + '-' + currentDates[1];
  356. if (inputDate < ValidDate) {
  357. SetValueById(id, '', '');
  358. return document.getElementById(id).focus();
  359. }
  360. if (inputDate > currentDate) {
  361. SetValueById(id, '', '');
  362. alert("You Cannot Input Future Date.");
  363. return document.getElementById(id).focus();
  364. }
  365. }
  366. else if (typeVal === "f") {
  367. AllowFutureDate("#" + id);
  368. if (inputDate < currentDate) {
  369. SetValueById(id, '', '');
  370. alert("You Cannot Input Past Date.");
  371. return document.getElementById(id).focus();
  372. }
  373. }
  374. else if (typeVal === "i") {
  375. CalTillToday("#" + id);
  376. if (inputDate > currentDate) {
  377. SetValueById(id, '', '');
  378. alert("You Cannot Input Future Date.");
  379. return document.getElementById(id).focus();
  380. }
  381. }
  382. firstDate = inputDate;
  383. $("#" + id).val(inputDate);
  384. }
  385. else {
  386. SetValueById(id, '');
  387. alert("Invalid Date Format ! Please Enter yyyy-mm-dd format");
  388. return document.getElementById(id).focus();
  389. }
  390. }
  391. if (compareId !== undefined && compareId.length > 0) {
  392. var checkDatecompareId = document.getElementById(compareId);
  393. if (checkDatecompareId === undefined || checkDatecompareId === null || checkDatecompareId === "" || checkDatecompareId.length < 10) {
  394. if (ContentPlaceHolderId.length >= 0) {
  395. id = ContentPlaceHolderId + compareId;
  396. }
  397. }
  398. var compareDate = document.getElementById(compareId).value;
  399. if (compareDate.length > 0) {
  400. if (compareTypeVal !== undefined && compareTypeVal.length > 0) {
  401. typeVal = '';
  402. typeVal = compareTypeVal;
  403. }
  404. dates = compareDate.split("-");
  405. 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) {
  406. currentDate = new Date(Date.now()).toLocaleDateString();
  407. currentDates = currentDate.split('/');
  408. if (dates[1] <= 9 && dates[1].length <= 1) {
  409. dates[1] = '0' + dates[1];
  410. }
  411. if (dates[2] <= 9 && dates[2].length <= 1) {
  412. dates[2] = '0' + dates[2];
  413. }
  414. if (currentDates[0] <= 9 && currentDates[0].length <= 1) {
  415. currentDates[0] = '0' + currentDates[0];
  416. }
  417. if (currentDates[1] <= 9 && currentDates[1].length <= 1) {
  418. currentDates[1] = '0' + currentDates[1];
  419. }
  420. compareDate = dates[0] + "-" + dates[1] + "-" + dates[2];
  421. currentDate = currentDates[2] + '-' + currentDates[0] + '-' + currentDates[1];
  422. if (typeVal === "t") {
  423. ValidDate = currentDates[2] - 2 + '-' + currentDates[0] + '-' + currentDates[1];
  424. if (compareDate < ValidDate) {
  425. SetValueById(compareId, '', '');
  426. compareDate = '';
  427. document.getElementById(compareId).focus();
  428. }
  429. if (compareDate > currentDate) {
  430. SetValueById(compareId, '', '');
  431. compareDate = '';
  432. alert("You Cannot Input Future Date.");
  433. document.getElementById(compareId).focus();
  434. }
  435. }
  436. if (firstDate.length === 10) {
  437. if (firstDate > compareDate) {
  438. SetValueById(compareId, '');
  439. compareDate = '';
  440. alert("To Date Must Be Greater Or Equal To From Date");
  441. document.getElementById(id).focus();
  442. }
  443. }
  444. $("#" + compareId).val(compareDate);
  445. }
  446. else {
  447. SetValueById(compareId, '');
  448. alert("Invalid Date Format ! Please Enter yyyy-mm-dd format");
  449. return document.getElementById(compareId).focus();
  450. }
  451. }
  452. ShowCalFromToUpToTodayForInput("#" + id, "#" + compareId);
  453. }
  454. }