
function createHTMLEditor(strName, iWidth, iHeight, strToolbarSetName, strValue, strConfigFilename)
  {
    var oHtmlEditor = new FCKeditor(strName, iWidth, iHeight, strToolbarSetName, strValue);
    oHtmlEditor.BasePath = 'skin/fckeditor/';
    oHtmlEditor.Config['BaseHref'] = strHtmlEditorBaseHref;
    oHtmlEditor.Config['ImageBrowserURL'] = '../filemanager/browser/mcpuk/browser.html?Type=Image&Connector=' + strHtmlEditorBaseHref + strVirtualDirectory + oHtmlEditor.BasePath + 'editor/filemanager/browser/mcpuk/connectors/php/connector.php' ;
    if (strConfigFilename != null)
      oHtmlEditor.Config['CustomConfigurationsPath'] = '/' + oHtmlEditor.BasePath + strConfigFilename;
    oHtmlEditor.Create();
    return oHtmlEditor;
  }

function focusOnInput(oInput)
  {
    if (oInput && (oInput.type != 'hidden') && !oInput.disabled && (oInput.style.visibility != 'hidden') && (oInput.style.display != 'none'))
      oInput.focus();
  }

function getHTMLEditorContent(strEditorId)
  {
    if (document.frames(strEditorId + '___Frame').document.getElementById('eWysiwyg').style.display != 'none')
      strResult = document.frames(strEditorId + '___Frame').document.frames('eEditorArea').document.body.innerHTML;
    else if (document.frames(strEditorId + '___Frame').document.getElementById('eSource').style.display != 'none')
      strResult = document.frames(strEditorId + '___Frame').document.getElementById('eSourceField').value;
    else
      strResult = '';
    return strResult;
  }

function registerEventHandler(oNode, strEvent, funcHandler)
  {
    var funcOldHandler = (oNode[strEvent] ? oNode[strEvent] : function() {});
    oNode[strEvent] = function() { funcOldHandler(); funcHandler(); };
  }

// insertAdjacentHTML(), insertAdjacentText() and insertAdjacentElement()
// for Netscape 6/Mozilla by Thor Larholm thor@jscript.dk
// Usage: include this code segment at the beginning of your document
// before any other Javascript contents.

if(typeof HTMLElement!="undefined" && !HTMLElement.prototype.insertAdjacentElement)
  {
    HTMLElement.prototype.insertAdjacentElement = function(where,parsedNode)
      {
        switch (where)
          {
            case 'beforeBegin':
              this.parentNode.insertBefore(parsedNode,this)
              break;
            case 'afterBegin':
              this.insertBefore(parsedNode,this.firstChild);
              break;
            case 'beforeEnd':
              this.appendChild(parsedNode);
              break;
            case 'afterEnd':
              if (this.nextSibling)
                this.parentNode.insertBefore(parsedNode,this.nextSibling);
              else this.parentNode.appendChild(parsedNode);
              break;
          }
      }

    HTMLElement.prototype.insertAdjacentHTML = function(where,htmlStr)
      {
        var r = this.ownerDocument.createRange();
        r.setStartBefore(this);
        var parsedHTML = r.createContextualFragment(htmlStr);
        this.insertAdjacentElement(where,parsedHTML)
      }


    HTMLElement.prototype.insertAdjacentText = function(where,txtStr)
      {
        var parsedText = document.createTextNode(txtStr)
        this.insertAdjacentElement(where,parsedText)
      }
  }

function toggleDisplay(oElement, bDisplay)
  {
    if (bDisplay == undefined)
      bDisplay = !elementIsDisplayed(oElement);
    if (bDisplay)
      oElement.style.display = '';
    else
      oElement.style.display = 'none';
  }

function elementIsDisplayed(oElement)
  {
    return !(oElement.style.display == 'none');
  }

function computedStyle(oNode)
  {
    var oResult;
    if (oNode.currentStyle)
      oResult = oNode.currentStyle;
    else if (document.defaultView && document.defaultView.getComputedStyle)
      oResult = document.defaultView.getComputedStyle(oNode, '');
    else
      oResult = oNode.style;
    return oResult;
  }

function parentNodeOfType(oNode, strNodeType, bInclusive)
  {
    strNodeType = strNodeType.toLowerCase();
    if (!bInclusive && oNode)
      oNode = oNode.parentNode;
    while (oNode && (!oNode.nodeName || (oNode.nodeName.toLowerCase() != strNodeType)))
      oNode = oNode.parentNode;
    return oNode;
  }

function parentNodePositioned(oNode, bInclusive)
  {
    if (!bInclusive && oNode)
      oNode = oNode.parentNode;
    while (oNode && (oNode.parentNode))
      {
        oStyle = computedStyle(oNode);
        if ((oStyle.position == 'absolute') || (oStyle.position == 'relative'))
          break;
        oNode = oNode.parentNode;
      }
    return oNode;
  }

function nextSiblingOfClass(oNode, strClassName)
  {
    strClassName = strClassName.toLowerCase();
    if (oNode)
      oNode = oNode.nextSibling;
    while (oNode && (!oNode.className || (oNode.className.toLowerCase() != strClassName)))
      oNode = oNode.nextSibling;
    return oNode;
  }

function nextSiblingOfType(oNode, strNodeType)
  {
    strNodeType = strNodeType.toLowerCase();
    if (oNode)
      oNode = oNode.nextSibling;
    while (oNode && (!oNode.nodeName || (oNode.nodeName.toLowerCase() != strNodeType)))
      oNode = oNode.nextSibling;
    return oNode;
  }

function limitInputValueLength(oInput, iMaxCharacterCount, iMaxLineCount)
  {
    if ((iMaxCharacterCount != null) && (oInput.value.length > iMaxCharacterCount))
      oInput.value = oInput.value.substring(0, iMaxCharacterCount);
    if ((iMaxLineCount != null) && (iMaxLineCount > 0))
      {
        aLines = oInput.value.split('\n', iMaxLineCount + 1);
        if (aLines.length > iMaxLineCount)
          {
            aLines.pop();
            oInput.value = aLines.join('\n');
          }
      }
  }

function trim(strX)
  {
    var strResult = strX.replace(/^\s+/, '');
    strResult = strResult.replace(/\s+$/, '');
    return strResult;
  }

function getSelectValue(oSelect)
  {
    var strResult;
    if (oSelect.options.selectedIndex != null)
      strResult = oSelect.options[oSelect.selectedIndex].value;
    else
      strResult = null;
    return strResult;
  }

function setSelectValue(oSelect, strValue)
  {
    for (i = 0; i < oSelect.options.length; i++)
      {
        if (oSelect.options[i].value == strValue)
          {
            oSelect.options[i].selected = true;
            break;
          }
      }
  }

function getRadioValue(radio)
  {
    var strResult = null;
    if (radio == null)
      strResult = null;
    else if (radio.length == null)
      strResult = (radio.checked ? radio.value : null);
    else
      {
        for (var i = 0; i < radio.length; i++)
          if (radio[i].checked)
            strResult = radio[i].value;
      }
    return strResult;
  }

function enableRadio(radio, bEnabled)
  {
    if (radio != null)
      {
        if (radio.length == null)
          radio.disabled = !bEnabled;
        else
          {
            for (var i = 0; i < radio.length; i++)
              radio[i].disabled = !bEnabled;
          }
      }
  }

function checkAllCheckboxes(checkboxes, bChecked)
  {
    if (checkboxes)
      {
        if (checkboxes.length)
          for (var i = 0; i < checkboxes.length; i++)
            checkboxes[i].checked = bChecked;
        else
          checkboxes.checked = bChecked;
      }
  }

function countCheckboxes(checkboxes)
  {
    var iResult;
    if (checkboxes)
      {
        if (checkboxes.length)
          iResult = checkboxes.length;
        else
          iResult = 1;
      }
    else
      iResult = 0;
    return iResult;
  }

function regularizeSiblingHeight(oNode, strClassName)
  {
    var iHeight = 0;
    var aNodes = new Array(oNode);
    var oCurrentNode = oNode;
    while (oCurrentNode != null)
      {
        iHeight = Math.max(iHeight, oCurrentNode.offsetHeight);
        if (strClassName)
          oCurrentNode = nextSiblingOfClass(oCurrentNode, strClassName);
        else
          oCurrentNode = oCurrentNode.nextSibling;
      }
    oCurrentNode = oNode;
    while (oCurrentNode != null)
      {
        oCurrentNode.style.height = iHeight + 'px';
        if (strClassName)
          oCurrentNode = nextSiblingOfClass(oCurrentNode, strClassName);
        else
          oCurrentNode = oCurrentNode.nextSibling;
      }
  }

function findNodesOfTypeAndClass(strNodeType, strClassName)
  {
    strClassName = strClassName.toLowerCase();
    var aNodes = document.getElementsByTagName(strNodeType);
    var aResult = new Array();
    for (var i = 0; i < aNodes.length; i++)
      {
        if (aNodes[i].className.toLowerCase() == strClassName)
          aResult.push(aNodes[i]);
      }
    return aResult;
  }

function initIERowHighlighting()
  {
    if (document.all && document.getElementById)
      {
        var aListFormTables = findNodesOfTypeAndClass('table', 'listForm');

        for (var i = 0; i < aListFormTables.length; i++)
          {
            oTable = aListFormTables[i];
            oTbody = oTable.childNodes[0];
            strTbodyNodeName = oTbody.nodeName.toLowerCase();
            if (strTbodyNodeName == 'tr')
              oTbody = oTable;
            else if (strTbodyNodeName == 'thead')
              oTbody = nextSiblingOfType(oTbody, 'tbody');
            else if (strTbodyNodeName == 'form')
              oTbody = oTable;

            for (var j = 0; j < oTbody.childNodes.length; j++)
              {
                oNode = oTbody.childNodes[j];
                if (oNode.nodeName.toLowerCase() == 'tr')
                  {
                    var strOriginalClassName = oNode.className;
                    if (!strOriginalClassName)
                      strOriginalClassName = '';

                    oNode.onmouseover = function()
                      { this.className = 'mouseover'; }

                    eval("oNode.onmouseout = function() { this.className = this.className.replace('mouseover', '" + strOriginalClassName + "'); }");
                  }
              }
          }
      }
  }

