function RichEditor() {}

function put_docHtml(passedValue) 
{
    doc.innerHTML = passedValue;
    open();
}

var tEdit = null;
var selectedImage = null;
var selectedFlash = null;
var showTableBorders = true;
var bTableBarVisible = false;
var oldContent = '';

function open()
{
    document.body.attachEvent('onselectstart', checkSelection);
    window.attachEvent('onresize', setDocWidth);
    oldContent = doc.innerHTML;
    
    doc.attachEvent('ondragend', onMouseUp);
    doc.attachEvent('onkeyup', onKeyUp);
    doc.attachEvent('onmouseup', onMouseUp);
    doc.attachEvent('onpaste', onPaste);

    colTables = doc.getElementsByTagName('TABLE');
    for (var i = 0; i < colTables.length; i++)
        if (!colTables[i].border || colTables[i].border == '0')
        {
            colTables[i].borderColor = '#dcdcdc';
            colTables[i].border = '1';
            colTables[i].style.borderStyle = 'dashed';
        }

    if (tEdit == null)
    {
        tEdit = new tableEditor(doc);
    }
    for (i = 0 ; i < document.links.length ; i++)
    {
        var lnkHref = new String(document.links[i].href);
lnkHref = lnkHref.replace('/cms/editor/popup_editor/richedit.php', '');        if (lnkHref.charAt(0) == '#')
        {
            lnkHref = 'javascript:void(0);/*binneditortmplink*/' + lnkHref;
        }
        document.links[i].href = lnkHref;
    }
    doc.contentEditable = 'true';
    show();
}

function show()
{
    editor.style.unselectable = "on";
    editor.style.display = "block";
    setDocWidth();
    editor.style.visibility = "visible";
    doc.focus();
    reset();
}

function setDocWidth()
{
    doc.style.width = document.body.clientWidth;
}

function cancelEvent()
{
    window.event.cancelBubble = true;
    window.event.returnValue = false; 
}

function hover(on)
{
    var el = event.srcElement;

    if (el && !el.disabled && el.nodeName == "IMG" && el.className != "spacer") 
    {
        if (on)
        {
            el.setCapture();
            el.style.backgroundColor = "#c1d2ee";
            el.style.border = "#316ac5 1px solid";
        }
        else
        {
            el.releaseCapture();
            if (el.className != "checked")
            {
                el.className = null;
                el.style.backgroundColor = "#efefde";
                el.style.border = "1px solid #efefde";
                el.style.marginTop = 1;
                el.style.marginBottom = 1;
                el.style.marginLeft = 1;
                el.style.marginRight = 1;
                el.style.cursor = 'hand';
            }
            else
            {
                el.style.backgroundColor = "buttonhighlight";
            }
        }
    }
}

function press(on)
{
    var el = event.srcElement;

    if (el && !el.disabled && el.nodeName == "IMG" && el.className != "spacer") 
    {
        if (on)
        {
            el.style.border = "#316ac5 1px solid";
            el.style.marginTop = 2;
            el.style.marginBottom = 0;
            el.style.marginLeft = 2;
            el.style.marginRight = 0;
            el.style.backgroundColor = "buttonhighlight";
        }
        else if (el.className != "checked")
        {
            el.style.marginTop = 1;
            el.style.marginBottom = 1;
            el.style.marginLeft = 1;
            el.style.marginRight = 1;
            el.style.backgroundColor = "#c1d2ee";
        }
    }
}

function setChecked(el, bCheck)
{
    if (!el.disabled) 
    {
        if (bCheck)
        {
            el.className = "checked";
            el.style.border = "#316ac5 1px solid";
            el.style.marginTop = 2;
            el.style.marginBottom = 0;
            el.style.marginLeft = 2;
            el.style.marginRight = 0;
            el.style.backgroundColor = "buttonhighlight";
        }
        else 
        {
            el.className = null;
            el.style.border = "1px solid #efefde";
            el.style.backgroundColor = "#efefde";
            el.style.marginTop = 1;
            el.style.marginBottom = 1;
            el.style.marginLeft = 1;
            el.style.marginRight = 1;
            el.style.cursor = 'hand';
        }
    }
}

function setEnabled(el, bEnabled)
{
    el.disabled = !bEnabled;
    if (el.disabled)
    {
        el.releaseCapture();
        if (el.className != "checked")
        {
            el.className = null;
            el.style.backgroundColor = "#efefde";
            el.style.border = "1px solid #efefde";
            el.style.marginTop = 1;
            el.style.marginBottom = 1;
            el.style.marginLeft = 1;
            el.style.marginRight = 1;
            el.style.cursor = 'hand';
        }
        el.style.filter = "progid:DXImageTransform.Microsoft.BasicImage( Rotation=0,Mirror=0,Invert=0,XRay=0,Grayscale=1,Opacity=0.25)";
    }
    else
        el.style.filter = "";
}

function showTableBar(show)
{
    if (show && !bTableBarVisible)
        tablebar.style.display = "block";
    if (!show && bTableBarVisible)
        tablebar.style.display = "none";
    bTableBarVisible = show;
}

