// DEA 20090714 gFilesRefPath is set in filesref.wssi
//alert('gFilesRefPath = ' + gFilesRefPath);

      var counter = 0;
      var serial = 0;
      function addAttachment() {
        var cont = document.getElementById('attachmentContainer');
        if(cont){
          var inputs = cont.getElementsByTagName('INPUT');
          for(var i=0; i<inputs.length; i++) {
            if(inputs[i].type == 'file') {
              if(inputs[i].value=='') return;
            }
          }

          var div = document.createElement('DIV');
          div.id = 'attach'+serial;

          var input = document.createElement('INPUT');
          input.name='attachment';
          input.type='file';
          input.className='FieldText';
          input.size=35;
          input.onchange = function () {
            addAttachment();
          }

          var img = document.createElement('IMG');
          img.src = gFilesRefPath+'iconoptionsreset.gif';
          img.style.display = counter<1 ? 'none' : '';
          img.border = 0;
          img.onclick = function () {
            dropAttachment(div.id);
            return false;
          }

          div.appendChild(input);
          div.appendChild(document.createTextNode(' '));
          div.appendChild(img);
          cont.appendChild(div);

          var imgs = cont.getElementsByTagName('IMG');
          for(var i=0; i<imgs.length; i++) {
            imgs[i].style.display = counter<1 ? 'none' : '';
          }

          counter++;
          serial++;
        }
      }
      function dropAttachment(id) {
        if(counter==1)
          return;

        var inputContainer = document.getElementById(''+id);
        if(inputContainer) {
          inputContainer.parentNode.removeChild(inputContainer);
          counter--;
        }

        var cont = document.getElementById('attachmentContainer');
        var imgs = cont.getElementsByTagName('IMG');
        for(var i=0; i<imgs.length; i++) {
          imgs[i].style.display = counter<2 ? 'none' : '';
        }
      }
      function hReset() {
    HTMLArea.changeView("Body_SHADOW","hide");
    HTMLAreaList["Body_SHADOW"]._externalControll = document.getElementById('SendHTML');
      }
      
    function activateEditor() {
        var config = new HTMLArea.Config();
        config.width = '100%';
        config.height = '280px';
        config.toolbar = ['underline', 'italic', 'bold', 'insertorderedlist','insertunorderedlist','redo','undo',];
        itEditor = new HTMLArea('Body', config);
        formElement = document.getElementById('SendHTMLrt');
        formElement2 = document.getElementById('SendHTML');
        var modeGenerate = true;
        if (!formElement || formElement.type.toUpperCase()!='CHECKBOX' || formElement.tagName.toUpperCase()!='INPUT' || !formElement.checked) modeGenerate = false;
        try { itEditor.generate(modeGenerate); }catch(e) {}
        if(formElement && formElement.tagName.toUpperCase()=='INPUT' && formElement.type.toUpperCase()=='CHECKBOX' && formElement.checked) {
            formElement2.disabled=true;
            formElement.name='SendHTML';
            formElement.id='SendHTML';
            setTimeout(function() {
                //HTMLArea.changeView('Body_SHADOW', 'hide');
                //HTMLArea.changeView('Body_SHADOW', 'show');
                HTMLArea.updateView('Body_SHADOW');
                HTMLAreaList["Body_SHADOW"]._externalControll = formElement;
            }, 10);
        }
    }
