Advertisement
Guest User

CM JS

a guest
Oct 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Key validation */
  2. function isValidChar(e, rgex) {
  3.     var evt = (e) ? e : window.event;
  4.     var key = (evt.keyCode) ? evt.keyCode : evt.which;
  5.  
  6.     if (key != null) {
  7.         key = String.fromCharCode(parseInt(key));
  8.         var rx = new RegExp(rgex);
  9.         return rx.test(key);
  10.     }
  11.     return true;
  12. }
  13.  
  14. function testForValidCharacters(input, rgex) {
  15.     var rx = new RegExp(rgex);
  16.  
  17.    
  18.     var currentValue = $(input).val();
  19.  
  20.     if (currentValue != "") {
  21.         if (!rx.test(currentValue)) {
  22.             $(input).val("");
  23.             $(input).change();
  24.         }
  25.         }
  26.  
  27.    
  28.    
  29.  
  30. }
  31.  
  32. function isEmptyFloatValue(val) {
  33.     return (val === undefined || val == null || val.length <= 0 ) ? "0" : val.replace(/\,/g, "");
  34.  
  35. }
  36.  
  37. /* end - Key validation */
  38.  
  39. /* confirm dialog for delete */
  40. function confirmDialog(e, a, message) {
  41.     e = $.event.fix(e);
  42.  
  43.     e.preventDefault();
  44.  
  45.     bootbox.confirm('Are you sure you want to ' + message + ' this record(s)', function (result) {
  46.  
  47.         if (result == true) {
  48.             window.location.href = a.href;
  49.         }
  50.     });
  51. }
  52. /* end - confirm dialog for delete */
  53.  
  54. /* accept numeric values and one period only */
  55. function amtOnly(elementRef) {
  56.     var keyCodeEntered = (event.which) ? event.which : (window.event.keyCode) ? window.event.keyCode : -1;
  57.  
  58.     if ((keyCodeEntered >= 48) && (keyCodeEntered <= 57)) {
  59.         return true;
  60.     }
  61.     else if (keyCodeEntered == 46) {
  62.         if ((elementRef.value) && (elementRef.value.indexOf('.') >= 0))
  63.             return false;
  64.         else
  65.             return true;
  66.     }
  67.  
  68.     return false;
  69. }
  70. /* end: accept numeric values and one period only */
  71.  
  72. /* accept numeric values only */
  73. function numericOnly(elementRef) {
  74.     var keyCodeEntered = (event.which) ? event.which : (window.event.keyCode) ? window.event.keyCode : -1;
  75.  
  76.     if ((keyCodeEntered >= 48) && (keyCodeEntered <= 57)) {
  77.         return true;
  78.     }
  79.  
  80.     return false;
  81. }
  82. /* end: accept numeric values only */
  83.  
  84.  
  85. //jQuery functions
  86. if (window.jQuery) {
  87.     /* All onload functions */
  88.     $(document).ready(function () {
  89.  
  90.         // On keypress
  91.         //        $(".wholenum").keypress(function () { return isValidChar(event, '[0-9]'); })
  92.         $(document.body).on('keypress', '.wholenum', function () { return isValidChar(event, '[0-9]'); });
  93.  
  94.         $(".currency").keypress(function () { return isValidChar(event, '[0-9.]'); })
  95.         $(".currency2").keypress(function () { return isValidChar(event, '[0-9.-]'); })
  96.         $(".currency3").keypress(function () { return isValidChar(event, '[0-9.]'); })
  97.        // $(".nospec0").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9]'); })
  98.         $(".nospec1").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9@,/&-]'); })
  99.         $(".nospec2").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9@,/]'); })
  100.         $(".nospec3").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9-]'); })
  101.         $(".nospec4").keypress(function () { return isValidChar(event, '[ a-zA-Z@,/-]'); })
  102.         $(".nospec5").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9/-]'); })
  103.         $(".nospec6").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9,/-]'); })
  104.         $(".nospec7").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9.-]'); })
  105.         $(".nospec8").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9._@]'); })
  106.         $(".nospec9").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9.,/-]'); })
  107.         $(".nospec10").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9.,/@-]'); })
  108.         //$(".nospecName").keypress(function () { return isValidChar(event, '[ a-zA-Z0-9\u00F1\u00D1!@#$%^&*();,.\'-]'); })
  109.         //$(".nospecEmail").keypress(function () { return isValidChar(event, '[^ ,:;"\'/]'); })
  110.         $(".seqno").keypress(function () { return isValidChar(event, '[0-9]'); })
  111.         // On focus
  112.         $(".currency").focus(function () { $(this).select(); })
  113.         $(".currency2").focus(function () { $(this).select(); })
  114.         $(".currency3").focus(function () { $(this).select(); })
  115.         $(".searcher").focus(function () { SrchBxFocus(this); })
  116.         // On blur or lose focus        
  117.         $(".currency").blur(function () { $(this).val(Currencify($(this).val())); })
  118.         $(".currency2").blur(function () { $(this).val(Currencify($(this).val())); })
  119.         $(".currency3").blur(function () { $(this).val(Currencify(noBelowZeroBalance($(this).val()))); })
  120.         $(".shortdate").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
  121.         $(".noForwardDate1521").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
  122.         $(".noForwardDate1900").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
  123.         $(".noForwardDate").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
  124.         $(".noCurrentForwardDate").blur(function () { $(this).val(PadDate($(this).val())); $(this).change(); })
  125.         $(".searcher").blur(function () { SrchBxBlur(this); })
  126.  
  127.  
  128.         $(".currencySelect").focus(function () { return $(this).val($(this).val().replace(/\,/g, "")); $(this).change(); })
  129.         $(".currencyDefaultValue").blur(function () { $(this).val(Currencify(isEmptyFloatValue($(this).val()))); $(this).change(); });
  130.         //$(".required").change(function () { markAsRequried($(this), $(this).val()); });
  131.         //$(".required").change(function () { toggleRequired($(this), $(this).val() == ""); });
  132.         $(document.body).on('change', '.required', function () { toggleRequired($(this), $(this).val() == ""); });
  133.         $(document.body).on('click', '.requiredRadio', function () { toggleRequired($(this), false); });
  134.         $(document.body).on('keypress', '.nospecName', function () { return isValidChar(event, '[ a-zA-Z0-9\u00F1\u00D1!@#$%^&*()\\\\;,.\'-]'); });
  135.  
  136.         $(document.body).on('change', '.nospecName', function () { testForValidCharacters(this, '^[ a-zA-Z0-9\u00F1\u00D1!@#$%^&*()\\\\;,.\'-]*$'); });
  137.         $(document.body).on('change', '.nospec0', function () { testForValidCharacters(this, '^[ a-zA-Z0-9]*$'); });
  138.         $(document.body).on('keypress', '.nospec0', function () { return isValidChar(event, '[ a-zA-Z0-9]'); });
  139.         $(document.body).on('change', '.wholenum', function () { testForValidCharacters(this, '^[0-9]*$'); });
  140.  
  141.         $(document.body).on('keypress', '.nospecEmail', function () { return isValidChar(event, '[^ ,:;"\'/]'); });
  142.         $(document.body).on('keypress', '.nospecWebsite', function () { return isValidChar(event, '[a-zA-Z0-9-_/\\\\.]'); });
  143.         $(document.body).on('change', '.nospecWebsite', function () { testForValidCharacters(this, '^[a-zA-Z0-9-_/\\\\.]*$'); });
  144.  
  145.         $(".shortdate").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
  146.         $(".noForwardDate1521").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
  147.         $(".noForwardDate1900").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
  148.         $(".noCurrentForwardDate").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
  149.         $(".noForwardDate").mask("99/99/9999", { placeholder: "mm/dd/yyyy" });
  150.         //others  
  151.  
  152. //        var s = $(".stickyDiv");
  153. //        var pos = s.position();
  154. //        $(window).scroll(function () {
  155. //            var windowpos = $(window).scrollTop();
  156. //            //                s.html("Distance from top:" + pos.top + "<br />Scroll position: " + windowpos);
  157. //            if (windowpos >= pos.top) {
  158. //                s.addClass("stick");
  159. //            } else {
  160. //                s.removeClass("stick");
  161. //            }
  162. //        });                    
  163.     })
  164.     /* end - All onload functions */
  165.  
  166.    
  167.  
  168.     /* Datepicker & date formatter */
  169.     //date formatter
  170.     function PadDate(d) {
  171.         var vDt = new Date(d);
  172.         var ds = d.split("/");
  173.         var dy = ds[2];
  174.         var mm = vDt.getMonth() + 1;
  175.         var dd = vDt.getDate();
  176.         var yyyy = vDt.getFullYear();
  177.         if ((ds.length == 3) && (dd <= 31) && (mm <= 12)) {
  178.             //goto closest year
  179.             if (dy.length < 4) {
  180.                 if (yyyy < 1940) { yyyy = yyyy + 100; }
  181.             }
  182.             //end
  183.             if (mm < 10) { mm = '0' + mm; }
  184.             if (dd < 10) { dd = '0' + dd; }
  185.             var xdate = mm + '/' + dd + '/' + yyyy;
  186.             return xdate
  187.         }
  188.         else { return ""; }
  189.     }  
  190.  
  191.     /* Number validators & formatters */
  192.     function isValidNumba(c) { return !isNaN(parseFloat(c)) && isFinite(c) }
  193.     function AmtListener(d) {
  194.         d += "";
  195.         x = d.split(".");
  196.         x1 = x[0];
  197.         x2 = x.length > 1 ? "." + x[1] : "";
  198.         var c = /(\d+)(\d{3})/;
  199.         while (c.test(x1)) {
  200.             x1 = x1.replace(c, "$1,$2")
  201.         }
  202.         return x1 + x2
  203.     }
  204.  
  205.     function Currencify(d) {
  206.         var e = d.replace(/\,/g, "");
  207.         if (isValidNumba(e)) {
  208.             var c = parseFloat(e);
  209.             nStr = c.toFixed(2);
  210.             return AmtListener(nStr);
  211.         }
  212.         else { return ""; }
  213.     }
  214.     /* end - Number validators & formatters */
  215.  
  216.     //check jquery-ui
  217.     if ($.ui) {
  218.         //datepicker
  219.         $(function () {
  220.             $(".shortdate").datepicker({
  221.                 showAnim: "",
  222.                 changeMonth: true,
  223.                 changeYear: true,              
  224.                 minDate: new Date(1900, 1, 1),
  225.                 yearRange: '1901:+75',
  226.                 dateFormat: "mm/dd/yy",
  227.                 onChangeMonthYear: function (year, month, day) {
  228.                     yearRange: '1901:+0',
  229.                 $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
  230.                 }
  231.             });
  232.             /*  var vdisabled = $(".shortdate").attr('disabled');
  233.             if (vdisabled == 'disabled') {
  234.             $(".shortdate").datepicker('disable');
  235.             }
  236.             else {
  237.             $(".shortdate").datepicker('enable');
  238.             } */
  239.  
  240.            
  241.         });
  242.          $(function () {
  243.             $(".noForwardDate1521").datepicker({
  244.                 showAnim: "",
  245.                 changeMonth: true,
  246.                 changeYear: true,
  247.                 yearRange: '1521:+0',
  248.                 dateFormat: "mm/dd/yy",
  249.                 maxDate: '0',
  250.                 minDate: new Date(1521, 1 - 1, 1),
  251.                 onChangeMonthYear: function (year, month, day) {
  252.                     yearRange: '1521:+0',
  253.                 $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
  254.                 }
  255.             });
  256.         });
  257.  
  258.         $(function () {
  259.             $(".noForwardDate1900").datepicker({
  260.                 showAnim: "",
  261.                 changeMonth: true,
  262.                 changeYear: true,
  263.                 yearRange: '1900:+0',
  264.                 dateFormat: "mm/dd/yy",
  265.                 maxDate: '0',
  266.                 minDate: new Date(1900, 1 - 1, 1),
  267.                 onChangeMonthYear: function (year, month, day) {
  268.                     yearRange: '1900:+0',
  269.                 $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
  270.                 }
  271.             });
  272.         });
  273.  
  274.         $(function () {
  275.             $(".noForwardDate").datepicker({
  276.                 showAnim: "",
  277.                 changeMonth: true,
  278.                 changeYear: true,
  279.                 yearRange: '1901:+0',
  280.                 dateFormat: "mm/dd/yy",
  281.                 maxDate: '0',
  282.                 minDate: new Date(1900, 1 - 1, 1),
  283.                 onChangeMonthYear: function (year, month, day) {
  284.                     yearRange: '1901:+0',
  285.                 $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
  286.                 }
  287.             });
  288.             /*  var vdisabled = $(".shortdate").attr('disabled');
  289.             if (vdisabled == 'disabled') {
  290.             $(".shortdate").datepicker('disable');
  291.             }
  292.             else {
  293.             $(".shortdate").datepicker('enable');
  294.             } */
  295.         });
  296.         /* end - Datepicker & date formatter */
  297.  
  298.         $(function () {
  299.             $(".noCurrentForwardDate").datepicker({
  300.                 showAnim: "",
  301.                 changeMonth: true,
  302.                 changeYear: true,
  303.                 yearRange: '1901:+0',
  304.                 dateFormat: "mm/dd/yy",
  305.                 maxDate: '-1',
  306.                 minDate: new Date(1900, 1 - 1, 1),
  307.                 onChangeMonthYear: function (year, month, day) {
  308.                     yearRange: '1901:+0',
  309.                 $(this).datepicker('setDate', new Date(year, month - 1, day.selectedDay));
  310.                 }
  311.             });
  312.         });
  313.  
  314.         $(function () {
  315.             $(".defaultToday").datepicker('setDate', new Date());
  316.             $(".defaultToday").change();
  317.         });
  318.        
  319.     }
  320.  
  321. }
  322.  
  323. /* Added by Sir Eric - 07142014 */
  324.  
  325. /* creation of alert message using pines notify */
  326. function showAlertMessage(message, type) {
  327.     new PNotify({
  328.         text: message,
  329.         type: type,
  330.         width: '1030px'
  331.     });
  332.  
  333. }
  334. /* end - creation of alert message using pines notify  */
  335.  
  336. function noBelowZeroBalance(d) {
  337.     var x = ((isValidNumba(d)) ? d : 0).toString();
  338.  
  339.     return ((parseFloat(x) >= 0) ? d : 0).toString();
  340. }
  341.  
  342. $(document).ready(function () {
  343.     var prm = Sys.WebForms.PageRequestManager.getInstance();    
  344.     prm.add_initializeRequest(InitializeRequest);
  345.     prm.add_endRequest(EndRequest);
  346.  
  347.     $(".shortdate").keypress(function () { return isValidChar(event, '[0-9/]'); })
  348.     $(".noForwardDate1521").keypress(function () { return isValidChar(event, '[0-9/]'); })
  349.     $(".noForwardDate1900").keypress(function () { return isValidChar(event, '[0-9/]'); })
  350.     $(".noForwardDate").keypress(function () { return isValidChar(event, '[0-9/]'); })
  351.  
  352.     $(".numericTextbox").keypress(function () { return isValidChar(event, '[0-9]'); })
  353.     $(".decimalTextbox").keypress(function () { return isValidChar(event, '[0-9.]'); })
  354.  
  355.     $(".shortdate").datepicker({});
  356.     $(".noForwardDate1521").datepicker({ maxDate: '0' });
  357.     $(".noForwardDate1900").datepicker({ maxDate: '0' });
  358.     $(".noForwardDate").datepicker({maxDate: '0'});
  359.     $(".noCurrentForwardDate").datepicker({maxDate: '-1'});
  360.    
  361. });
  362.  
  363. function InitializeRequest(sender, args) {
  364. }
  365.  
  366. function EndRequest(sender, args) {
  367.     $(".shortdate").keypress(function () { return isValidChar(event, '[0-9/]'); })
  368.     $(".noForwardDate1521").keypress(function () { return isValidChar(event, '[0-9/]'); })
  369.     $(".noForwardDate1900").keypress(function () { return isValidChar(event, '[0-9/]'); })
  370.     $(".noForwardDate").keypress(function () { return isValidChar(event, '[0-9/]'); })
  371.  
  372.     $(".numericTextbox").keypress(function () { return isValidChar(event, '[0-9]'); })
  373.     $(".decimalTextbox").keypress(function () { return isValidChar(event, '[0-9.]'); })
  374.  
  375.     $(".shortdate").datepicker({});
  376.     $(".noForwardDate1521").datepicker({ maxDate: '0' });
  377.     $(".noForwardDate1900").datepicker({ maxDate: '0' });
  378.  
  379.     $(".noForwardDate").datepicker({maxDate: '0'});
  380.     $(".noCurrentForwardDate").datepicker({maxDate: '-1'});
  381.  
  382.  
  383.    
  384. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement