   objects = require('../relaxng/objects')
 
   class TextorumValidator
-    constructor: (@validationOutputSelector, @editor) ->
+    constructor: (@validationOutputSelector, @editor, alternateStart) ->
       schema = @editor.plugins.textorum.schema
       if schema.schemaXML
         @schema = schema.schemaXML

      @validatorAttributes = new RNGParser()
      @validatorAttributes.process(@schema, false)

      @editor.addCommand 'validateWithAttributes', @validateWithAttributes, this
      @editor.addCommand 'validateWithoutAttributes', @validateWithoutAttributes, this
      @editor.addButton 'txt_validate_attrs', {cmd: 'validateWithAttributes', title: 'Full Validation'}
      @editor.addButton 'txt_validate_noattrs', {cmd: 'validateWithoutAttributes', title: 'Validation (Ignoring Attributes)'}

    validatePartialOpportunistic: (node, skipAttributes = false, descend = false) ->
      if skipAttributes
        validator = @validatorNoAttributes
      else

        unless res instanceof na
          possiblePatterns.push define
      index = possiblePatterns.length
      if not index
        return na
      res = na
      while index--
        res = possiblePatterns[index].childDeriv(node, descend)
        unless res instanceof na
          return res
      return res

    validateFullEditor: (skipAttributes = false, opportunistic = false) ->
      docdom = (new window.DOMParser()).parseFromString(@editor.getContent(), "text/xml")

      if skipAttributes
        if opportunistic
          res = @validatePartialOpportunisticResult docdom.documentElement, true
        else
          @validatorNoAttributes.getObjects().setSkipAttributes true
          res = @validationNoAttributesStart.childDeriv(docdom.documentElement, true)
      else
        if opportunistic
          res = @validatePartialOpportunisticResult docdom.documentElement, false
        else
          @validatorAttributes.getObjects().setSkipAttributes false
          res = @validationAttributesStart.childDeriv(docdom.documentElement, true)
      if res instanceof objects.Empty
        $(@validationOutputSelector).html('<b>No errors detected</b>')
      else
