function REUpdate(rename)
{
    if (document.getElementById('GM' + rename).value == 1)
        document.getElementById(rename).value = window.frames('IF' + rename).document.body.innerHTML;
    else
        document.getElementById(rename).value = window.frames('IF' + rename).document.body.innerText;     
}

function REStateChange (rename, dirname)
{
    var rt;
    var txt;

    if (document.getElementById('GM' + rename).value == 1)
    {
        rt = window.frames('IF' + rename);
        txt = rt.document.body.innerHTML;
        rt.document.body.innerHTML = '';
        rt.document.body.innerText = txt;
        document.getElementById('GM' + rename).value = 0;
        document.getElementById('STC' + rename).src = dirname + 'graphicsview.gif';
    }
    else
    {
        rt = window.frames('IF' + rename);
        txt = rt.document.body.innerText;
        rt.document.body.innerText = '';
        rt.document.body.innerHTML = txt;
        document.getElementById('GM' + rename).value = 1;
        document.getElementById('STC' + rename).src = dirname + 'htmlview.gif';
    }
}

function GetElementPosition(elem)
{
    var x,y,ofp;
    var ret = new Object;
    
    x = elem.offsetLeft;
    y = elem.offsetTop;

    ofp = elem.offsetParent;
    while (ofp != null)
    {
        x += ofp.offsetLeft;
        y += ofp.offsetTop;
        ofp = ofp.offsetParent;
    }
    
    Object.prototype.Left = x;
    Object.prototype.Top = y;
    return ret;
}

function GetRE (rename)
{
    var rt;
    rt = frames('IF' + rename);
    rt.focus();
    return rt;
}

function RESetBold(rename)
{
    GetRE(rename).document.execCommand('bold', false, '');
    REUpdate(rename);
}

function RESetItalic(rename)
{
    GetRE(rename).document.execCommand('italic', false, '');
    REUpdate(rename);
}

function RESetUnderline(rename)
{
    GetRE(rename).document.execCommand('underline', false, '');
    REUpdate(rename);
}

function REStrikeThrough(rename)
{
    GetRE(rename).document.execCommand('strikethrough', false, '');
    REUpdate(rename);
}

function RELeftAlign(rename)
{
    GetRE(rename).document.execCommand('justifyleft', false, '');
    REUpdate(rename);
}

function RERightAlign(rename)
{
    GetRE(rename).document.execCommand('justifyright', false, '');
    REUpdate(rename);
}

function RECenterAlign(rename)
{
    GetRE(rename).document.execCommand('justifycenter', false, '');
    REUpdate(rename);
}

function REJustify(rename)
{
    GetRE(rename).document.execCommand('justifyfull', false, '');
    REUpdate(rename);
}

function REInsertLine(rename)
{
    GetRE(rename).document.execCommand('inserthorizontalrule', false, '');
    REUpdate(rename);
}

function RETextColor(rename, img, cname)
{
    var obj = new Object();
    var ifct, ep;
    
    // pobranie kontenera dla wczytywanej strony
    ifct = document.all(cname);
    
    // wymiarowanie i pozycjonowanie kontenera 
    ep = GetElementPosition(img);
    ifct.style.left = ep.Left - 1;
    ifct.style.top = ep.Top + img.height + 1;

    ifct.style.display = 'inline';    
    Object.prototype.Container = ifct;
    Object.prototype.SetValue = RETextColorProc;
    Object.prototype.rename = rename;
    
    ep = GetRE(rename);
	var selection = ep.document.selection; 
	if (selection != null) ep = selection.createRange(); else ep = null;
    Object.prototype.rng = ep;

    // przekazanie obiektu do zainicjalizowania    
    ifct.contentWindow.Initialize(obj);
}

function RETextColorProc(Value)
{
    if (this.rng != null)
    {
        this.rng.select();
        GetRE(this.rename).document.execCommand('forecolor', false, Value);
        REUpdate(this.rename);
        this.Container.style.display = 'none';
    }
}

function REBkgrColor(rename, img, cname)
{
    var obj = new Object();
    var ifct, ep;
    
    // pobranie kontenera dla wczytywanej strony
    ifct = document.all(cname);
    
    // wymiarowanie i pozycjonowanie kontenera 
    ep = GetElementPosition(img);
    ifct.style.left = ep.Left - 1;
    ifct.style.top = ep.Top + img.height + 1;

    ifct.style.display = 'inline';    
    Object.prototype.Container = ifct;
    Object.prototype.SetValue = REBkgrColorProc;
    Object.prototype.rename = rename;
    
    ep = GetRE(rename);
	var selection = ep.document.selection; 
	if (selection != null) ep = selection.createRange(); else ep = null;
    Object.prototype.rng = ep;

    // przekazanie obiektu do zainicjalizowania    
    ifct.contentWindow.Initialize(obj);
}

function REBkgrColorProc(Value)
{
    if (this.rng != null)
    {
        this.rng.select();
        GetRE(this.rename).document.execCommand('backcolor', false, Value);
        REUpdate(this.rename);
        this.Container.style.display = 'none';
    }
}

function REFontSel(rename, img, cname)
{
    var obj = new Object();
    var ifct, ep;
    
    // pobranie kontenera dla wczytywanej strony
    ifct = document.all(cname);
    
    // wymiarowanie i pozycjonowanie kontenera 
    ep = GetElementPosition(img);
    ifct.style.left = ep.Left - 1;
    ifct.style.top = ep.Top + img.height + 1;

    ifct.style.display = 'inline';    
    Object.prototype.Container = ifct;
    Object.prototype.SetValue = REFontSelProc;
    Object.prototype.rename = rename;
    
    ep = GetRE(rename);
	var selection = ep.document.selection; 
	if (selection != null) ep = selection.createRange(); else ep = null;
    Object.prototype.rng = ep;

    // przekazanie obiektu do zainicjalizowania    
    ifct.contentWindow.Initialize(obj);
}

function REFontSelProc(Value)
{
    if (this.rng != null)
    {
        this.rng.select();
        GetRE(this.rename).document.execCommand('fontname', false, Value);
        REUpdate(this.rename);
        this.Container.style.display = 'none';
    }
}

function REFontSize(rename, img, cname)
{
    var obj = new Object();
    var ifct, ep;
    
    // pobranie kontenera dla wczytywanej strony
    ifct = document.all(cname);
    
    // wymiarowanie i pozycjonowanie kontenera 
    ep = GetElementPosition(img);
    ifct.style.left = ep.Left - 1;
    ifct.style.top = ep.Top + img.height + 1;

    ifct.style.display = 'inline';    
    Object.prototype.Container = ifct;
    Object.prototype.SetValue = REFontSizeProc;
    Object.prototype.rename = rename;
    
    ep = GetRE(rename);
	var selection = ep.document.selection; 
	if (selection != null) ep = selection.createRange(); else ep = null;
    Object.prototype.rng = ep;

    // przekazanie obiektu do zainicjalizowania    
    ifct.contentWindow.Initialize(obj);
}

function REFontSizeProc(Value)
{
    if (this.rng != null)
    {
        this.rng.select();
        GetRE(this.rename).document.execCommand('fontsize', false, Value);
        REUpdate(this.rename);
        this.Container.style.display = 'none';
    }
}


function RELink(rename)
{
    GetRE(rename).document.execCommand('createlink', true, '');
    REUpdate(rename);
}

function REListDot(rename)
{
    GetRE(rename).document.execCommand('insertunorderedlist', true, '');
    REUpdate(rename);
}

function REListNumber(rename)
{
    GetRE(rename).document.execCommand('insertorderedlist', true, '');
    REUpdate(rename);
}

function REIndent(rename)
{
    GetRE(rename).document.execCommand('indent', true, '');
    REUpdate(rename);
}

function REOutdent(rename)
{
    GetRE(rename).document.execCommand('outdent', true, '');
    REUpdate(rename);
}

