"use strict";

vB_Text_Editor.prototype.insertgasida = function (e, gasida)
{
    var pdo = {
        'type' : 'insertgasida',
        'w' : 750,
        'h' : 500,
        'hash' : 'pgasida'
    };

    return this.gasida_ocw(pdo);
};

vB_Text_Editor.prototype.plain = function (e, txt)
{
    if (typeof txt === 'undefined')
    {
        txt = this.i_selected();
    }

    if (txt === '')
    {
        var d =
        {
            o : 'mwaextragasida_error',
            m : vbphrase.mwaextragasida_select_text
        };

        this.gasida_err(d);
    }
    else
    {
        this.insert_text(txt.replace(/\[flash=\"?([^\"\]]*)\"?\]width=[0-9]{0,4}\sheight=[0-9]{0,4}(\st=([0-1]))?\[\/flash\]/gi, '$1').replace(/\[[^\]]*\]/gi, ''));
    }
};

vB_Text_Editor.prototype.i_selected = function (b)
{
    var t = '';
    if (this.wysiwyg_mode)
    {
        t = this.get_selection();
    }
    else
    {
        t = this.get_selection();
    }
    return t || '';
};

vB_Text_Editor.prototype.i_contents = function ()
{
    var c = '';
    if (this.wysiwyg_mode)
    {
        c = this.get_editor_contents();
    }
    else
    {
        c = this.get_editor_contents();
    }
    return c || '';
};

vB_Text_Editor.prototype.gasida_err = function (d)
{
    if (vB_Text_Editor.prototype.perr == true)
    {
        return false;
    }

    var  o = YAHOO.util.Dom.get(d.o), timer = 1;

    vB_Text_Editor.prototype.perr = true;
    o.innerHTML = d.m;

    function blink()
    {
        if (o.style.backgroundColor !== '')
        {
            o.style.backgroundColor = '';
        }
        else
        {
            o.style.backgroundColor = 'lime';
        }

        if (timer < 10)
        {
            timer += 1;
            setTimeout(blink, 400);
        }
        else
        {
            o.style.display = 'none';
            vB_Text_Editor.prototype.perr = false;
        }
    }

    o.style.display = '';
    setTimeout(blink, 400);
};

vB_Text_Editor.prototype.gasida_ocw = function (pdo)
{
    var Pocw = [], base_tag = document.getElementsByTagName('base'), modal_prefix = '';

    if ((typeof Pocw[pdo.hash] !== 'undefined') && (Pocw[pdo.hash].closed === false))
    {
        Pocw[pdo.hash].focus();
    }
    else
    {
        // respect a <base> tag
        if (base_tag && base_tag[0] && base_tag[0].href)
        {
            modal_prefix = base_tag[0].href;
        }

        pdo.tp = (screen.height) ? ((screen.height - pdo.h) / 2) : 0;
        pdo.lp = (screen.width) ? ((screen.width - pdo.w) / 2) : 0;
        Pocw[pdo.hash] = document.open(modal_prefix + 'mwaextragasida.php?do=' + pdo.type, pdo.type, 'top=' + pdo.tp / 3 + ', left=' + pdo.lp + ', statusbar=no, menubar=no, toolbar=no, scrollbars=yes,resizable=yes, width=' + pdo.w + ', height=' + pdo.h);
    }

    this.editwin.hasfocus = true;
    return true;
};


