﻿/* Label Over Plugin - Used on Contact Us page */

jQuery.fn.labelOver = function (overClass) {
  return this.each(function () {
    var label = jQuery(this);
    var f = label.attr('for');
    if (f) {
      var input = jQuery('#' + f);

      this.hide = function () {
        label.css({ textIndent: -10000 })
      }

      this.show = function () {
        if (input.val() == '') label.css({ textIndent: 0 })
      }

      // handlers
      input.focus(this.hide);
      input.blur(this.show);
      label.addClass(overClass).click(function () { input.focus() });

      if (input.val() != '') this.hide();
    }
  })
}


// Numeric only control handler
jQuery.fn.ForceNumericOnly =
function () {
  return this.each(function () {
    $(this).keydown(function (e) {
      var key = e.charCode || e.keyCode || 0;
      // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
      return (
                key == 8 ||
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
    })
  })
};

// Bryan Watt modified
jQuery.fn.ForceNumericWithPeriod =
function () {
  return this.each(function () {
    $(this).keydown(function (e) {
      var key = e.charCode || e.keyCode || 0;
      // allow backspace, tab, delete, arrows, numbers and keypad numbers ONLY
      return (
                key == 110 ||
                key == 190 ||
                key == 8 ||
                key == 9 ||
                key == 46 ||
                (key >= 37 && key <= 40) ||
                (key >= 48 && key <= 57) ||
                (key >= 96 && key <= 105));
    })
  })
};
