if(typeof(Control) == "undefined")
  var Control = {};

  Control.Comment = Class.create();
  Object.extend(Control.Comment.prototype, {
    initialize: function(element, options) {
      //Elemento que controla activa el listado de artículos seleccionados

      this.element = $(element);

      this.options = $H({
        imgPath: '/img',
        urlRead: '',
        urlSubmit: ''
      }).merge(options || {}).toObject();
      this.createMessage();
    },
    
    createMessage: function() {
      var anchor = new Element('a', { name : 'secComment'});
      var form = new Element('form', { 
                            name : 'myCommentForm',
                            id : 'myCommentForm'
                      });
      var textarea = new Element('textarea', {
                            id: 'myComment',
                            name: 'myComment'
                      });
      var submit = new Element('input', {
                            name: 'myCommentSubmit',
                            id: 'myCommentSubmit',
                            type: 'button',
                            'class': 'submit',
                            value: 'Enviar comentario'
                      });
      var comentarios = new Element('ol', {
                            id: 'commentlist'
                      });
      submit.onclick = function() {
        if($F('myComment') == '') {
          alert('Olvidó escribir el comentario');
          return false;
        } else {
          new Ajax.Request(this.options.urlSubmit, { method: 'post', parameters: Form.serialize('myCommentForm'), onSuccess: function(transport) {
              $('myComment').value = '';
              this.bringMessages();
            }.bind(this)
          });
        }
      }.bind(this);
      this.element.appendChild(anchor);
      if(this.options.urlSubmit != '') {
        form.appendChild(textarea);
        var div = new Element('div', {id: 'myCommentDivSubmit'});
        div.appendChild(submit);
        form.appendChild(div);
        this.element.appendChild(form);
      }
      comentarios = this.element.appendChild(comentarios);
      //parameters:Form.serialize('myform')
      this.bringMessages();
    },
    
    bringMessages: function() {
      new Ajax.Updater($('commentlist'), this.options.urlRead, { asynchronous:true });
    }
  });