 Session.setDefault('referenceShowNew', false)
 Session.setDefault('referenceEditingId', null)
-
+Session.setDefault("referenceNewObj", null)
 
 Template.referencesTbl.helpers
 


    'typeahead:selected': (evt, tmpl, v) ->
        div = $(tmpl.find('div.selectedReference')).empty()
        Blaze.renderWithData(Template.referenceSingleSelectSelected, {referenceID:v._id}, div[0])
        $(evt.target).typeahead("val", "")

    'click .selectListRemove': (evt, tmpl) ->
        $(evt.currentTarget).parent().remove()

Template.referenceSingleSelect.rendered = ->
    Meteor.typeahead.inject()



        obj['monographAgent'] = [Session.get('monographAgent')]
        isValid = Reference.simpleSchema().namedContext().validate(obj)
        if isValid
            ref_id = Reference.insert(obj)
            Session.set("referenceShowNew", false)
            Session.set("referenceNewObj", ref_id)
        else
            errorDiv = share.createErrorDiv(Reference.simpleSchema().namedContext())
            $(tmpl.find("#errors")).html(errorDiv)
