String.prototype.strip_tags = function()
{
  tags = this;
  stripped = tags.replace(/(<br\/?\s*>|<\/p>\s*<p>)/gi, '\n');
  stripped = tags.replace(/<\/?[^>]+>/gi, '');
  return stripped;
}


NMT_Form = {
  init: function(theForm)
  {
  
    theForm.addEvent('submit', function(e)
    {
      e.stop();
      if (checkForm()) 
      {
        this.submit();
      }
    }
.bindWithEvent(theForm));
    
    $$('#' + theForm.id + ' input, #' + theForm.id + ' textarea').each(function(el)
    {
      if (!el.id || el.hasClass('no-check')) 
        return;
      if (!(el.Label = $E('label[for=' + el.id + ']'))) 
        return;
      
      el.originalColour = el.getStyle('background-color');
      el.originalColour2 = el.getStyle('color');
      el.Label.originalColour = el.Label.getStyle('color');
      
      el.addEvents({
        focus: function()
        {
          //          this.fireEvent('markError');
        },
        blur: function()
        {
          if (this.value != '') 
          {
            this.fireEvent('unmarkError');
          }
        },
        markError: function()
        {
          switch (this.getProperty('type'))
          {
            case 'text':
            case '':
              this.setStyle('background-color', 'red');
              this.setStyle('color', 'white');
              break;
          }
          
          this.Label.setStyle('color', 'red');
        },
        unmarkError: function()
        {
          switch (this.getProperty('type'))
          {
            case 'text':
            case '':
              this.setStyle('background-color', this.originalColour);
              this.setStyle('color', this.originalColour2);
              break;
          }
          this.Label.setStyle('color', this.Label.originalColour);
        }
      });
    });
  },
  
  errors: [],
  focus: null,
  
  checkEmpty: function(el, msg)
  {
    if (!el) 
      return;
    
    if (el.value == '') 
    {
      this.errors.push(msg);
      el.fireEvent('markError');
      if (this.focus == null) 
      {
        this.focus = el;
      }
    }
  },
  
  checkRadio: function(el, msg)
  {
    if (!el) 
      return;
    
    if (!el.checked) 
    {
      this.errors.push(msg);
      el.fireEvent('markError');
      if (this.focus == null) 
      {
        this.focus = el;
      }
    }
  },
  
  end: function()
  {
    console.dir(this);
    
    if (this.focus == null) 
    {
      return true;
    }
    else 
    {
      $('error_msg').setStyle('display', 'block');
      this.focus.focus();
      this.focus = null;
      return false;
    }
  }
}



window.addEvent('domready', function()
{


  var Tips2 = new Tips($$('.tip'), {
    initialize: function()
    {
      this.fx = new Fx.Style(this.toolTip, 'opacity', {
        duration: 500,
        wait: false
      }).set(0);
    },
    onShow: function(toolTip)
    {
      this.fx.start(1);
    },
    onHide: function(toolTip)
    {
      this.fx.start(0);
    }
  })
});
