/**
 * Generated by Apache Royale Compiler from org\apache\royale\jewel\beads\controls\datefield\DateFieldMaskedTextInput.as
 * org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput');

goog.require('goog.events.BrowserEvent');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.core.IBead');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor.
 *
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.9.4
 * @constructor
 * @implements {org.apache.royale.core.IBead}
 */
org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput = function() {
};


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput', org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput);


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput.prototype.org_apache_royale_jewel_beads_controls_datefield_DateFieldMaskedTextInput__strand;


/**
 * @private
 * @param {goog.events.BrowserEvent} event
 */
org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput.prototype.org_apache_royale_jewel_beads_controls_datefield_DateFieldMaskedTextInput_validateInput = function(event) {
  var /** @type {number} */ code = event.charCode;
  if (event.keyCode == 8 || event.keyCode == 46)
    return;
  if (event.keyCode == 9 || event.keyCode == 13)
    return;
  if (event.keyCode == 37 || event.keyCode == 39)
    return;
  var /** @type {string} */ key = String.fromCharCode(code);
  var /** @type {RegExp} */ regex = /[0-9]|\./;
  if (!regex.test(key)) {
    event["returnValue"] = false;
    if (org.apache.royale.utils.Language.closure(event.preventDefault, event, 'preventDefault'))
      event.preventDefault();
    return;
  }
  var /** @type {number} */ cursorStart = Number(event.target.selectionStart);
  var /** @type {number} */ cursorEnd = Number(event.target.selectionEnd);
  var /** @type {string} */ left = org.apache.royale.utils.Language.string(event.target.value.substring(0, cursorStart));
  var /** @type {string} */ right = org.apache.royale.utils.Language.string(event.target.value.substr(cursorEnd));
  var /** @type {string} */ complete = left + key + right;
  if (isNaN(parseFloat(complete))) {
    event["returnValue"] = false;
    if (org.apache.royale.utils.Language.closure(event.preventDefault, event, 'preventDefault'))
      event.preventDefault();
  }
};


/**
 * (TODO carlosrovira): this should take into account IFormatBead
 * @private
 * @param {goog.events.BrowserEvent} event
 */
org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput.prototype.org_apache_royale_jewel_beads_controls_datefield_DateFieldMaskedTextInput_dateInputMask = function(event) {
  if (event.keyCode < 47 || event.keyCode > 57) {
    event.preventDefault();
  }
  var /** @type {number} */ len = Number(event.target.value.length);
  if (len !== 1 || len !== 3) {
    if (event.keyCode == 47) {
      event.preventDefault();
    }
  }
  if (len === 2) {
    event.target.value += '/';
  }
  if (len === 5) {
    event.target.value += '/';
  }
};


org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput.prototype.set__strand = function(value) {
  this.org_apache_royale_jewel_beads_controls_datefield_DateFieldMaskedTextInput__strand = value;
  
  var /** @type {org.apache.royale.core.UIBase} */ host = this.org_apache_royale_jewel_beads_controls_datefield_DateFieldMaskedTextInput__strand;
  host.element.addEventListener("keypress", org.apache.royale.utils.Language.closure(this.org_apache_royale_jewel_beads_controls_datefield_DateFieldMaskedTextInput_dateInputMask, this, 'dateInputMask'), false);
};


Object.defineProperties(org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput.prototype, /** @lends {org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput.prototype.set__strand}}
);


/**
 * Metadata
 *
 * @type {Object.<string, Array.<Object>>}
 */
org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput.prototype.ROYALE_CLASS_INFO = { names: [{ name: 'DateFieldMaskedTextInput', qName: 'org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput', kind: 'class' }], interfaces: [org.apache.royale.core.IBead] };



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput'}
      };
    },
    methods: function () {
      return {
        'DateFieldMaskedTextInput': { type: '', declaredBy: 'org.apache.royale.jewel.beads.controls.datefield.DateFieldMaskedTextInput'}
      };
    }
  };
};