window.addEventListener ? window.addEventListener("load", procesarDocumento, false) : window.attachEvent("onload", procesarDocumento);

function procesarDocumento()
{
    if (!document.getElementById)
    {
        return;
    }

    var a = document.getElementsByTagName('*');
    for (i = 0; i < a.length; i++)
    {
        if (a[i].className != '')
        {
            while (buscarClase(a[i]))
            {
                redondear(a[i]);
            }
        }
    }
}

function buscarClase(o)
{
    var re = /\{rounded(-(top|bottom|none))?(-(left|right|none))? .+ [#a-zA-Z0-9]+\}/i;
    return re.test(o.className);
}

function redondear(o)
{
    var re = /\{rounded(-(top|bottom|none))?(-(left|right|none))? (.+) ([#a-zA-Z0-9]+)\}/i;
    var m = re.exec(o.className);
    var vertical = m[2];
    var horizontal = m[4];
    var fondo = m[5];
    var borde = m[6];

    o.className = o.className.replace(re, '');

    var top = (typeof vertical == 'undefined' || vertical == '' || vertical == 'top');
    var bottom = (typeof vertical == 'undefined' || vertical == '' || vertical == 'bottom');
    var left = (typeof horizontal == 'undefined' || horizontal == '' || horizontal == 'left');
    var right = (typeof horizontal == 'undefined' || horizontal == '' || horizontal == 'right');

    if (top)
    {
        var rtop = document.createElement('DIV');
        rtop.style.fontSize = '1px';
        rtop.style.height = '5px';
        rtop.style.lineHeight = '0px';
        rtop.style.display = 'block';
        rtop.style.margin = '0px';
        rtop.style.padding = '0px';

        var r1t = document.createElement('DIV');
        r1t.style.fontSize = '0px';
        r1t.style.height = '0px';
        r1t.style.display = 'block';
        r1t.style.borderBottom = '1px solid ' + borde;
        r1t.style.marginLeft = left ? '5px' : '0px';
        r1t.style.marginRight = right ? '5px' : '0px';
        r1t.style.marginTop = '0px';
        r1t.style.marginBottom = '0px';
        r1t.style.lineHeight = '0px';
        r1t.style.overflow = 'hidden';
    }

    if (bottom)
    {
        var rbot = document.createElement('DIV');
        rbot.style.fontSize = '1px';
        rbot.style.height = '5px';
        rbot.style.lineHeight = '0px';
        rbot.style.display = 'block';
        rbot.style.margin = '0px';
        rbot.style.padding = '0px';

        var r1b = document.createElement('DIV');
        r1b.style.fontSize = '0px';
        r1b.style.height = '0px';
        r1b.style.display = 'block';
        r1b.style.borderTop = '1px solid ' + borde;
        r1b.style.marginLeft = left ? '5px' : '0px';
        r1b.style.marginRight = right ? '5px' : '0px';
        r1b.style.marginTop = '0px';
        r1b.style.marginBottom = '0px';
        r1b.style.lineHeight = '0px';
        r1b.style.overflow = 'hidden';
    }

    var r2 = document.createElement('DIV');
    r2.style.fontSize = '0px';
    r2.style.height = '1px';
    r2.style.display = 'block';
    r2.style.borderLeft = (left ? '2' : '1') + 'px solid ' + borde;
    r2.style.borderRight = (right ? '2' : '1') + 'px solid ' + borde;
    r2.style.background = fondo;
    r2.style.backgroundPosition = '-4px 0px';
    r2.style.marginLeft = left ? '3px' : '0px';
    r2.style.marginRight = right ? '3px' : '0px';
    r2.style.marginTop = '0px';
    r2.style.marginBottom = '0px';
    r2.style.padding = '0px';
    r2.style.lineHeight = '0px';
    r2.style.overflow = 'hidden';

    var r3 = document.createElement('DIV');
    r3.style.fontSize = '0px';
    r3.style.height = '1px';
    r3.style.display = 'block';
    r3.style.borderLeft = '1px solid ' + borde;
    r3.style.borderRight = '1px solid ' + borde;
    r3.style.background = fondo;
    r3.style.backgroundPosition = '-2px -1px';
    r3.style.marginLeft = left ? '2px' : '0px';
    r3.style.marginRight = right ? '2px' : '0px';
    r3.style.marginTop = '0px';
    r3.style.marginBottom = '0px';
    r3.style.padding = '0px';
    r3.style.lineHeight = '0px';
    r3.style.overflow = 'hidden';

    var r4 = document.createElement('DIV');
    r4.style.fontSize = '0px';
    r4.style.height = '2px';
    r4.style.display = 'block';
    r4.style.borderLeft = '1px solid ' + borde;
    r4.style.borderRight = '1px solid ' + borde;
    r4.style.background = fondo;
    r4.style.backgroundPosition = '-1px -2px';
    r4.style.marginLeft = left ? '1px' : '0px';
    r4.style.marginRight = right ? '1px' : '0px';
    r4.style.marginTop = '0px';
    r4.style.marginBottom = '0px';
    r4.style.padding = '0px';
    r4.style.lineHeight = '0px';
    r4.style.overflow = 'hidden';

    if (top)
    {
        rtop.appendChild(r1t);
        rtop.appendChild(r2);
        rtop.appendChild(r3);
        rtop.appendChild(r4);
    }

    var rbody = document.createElement('DIV');
    rbody.style.borderLeft = '1px solid ' + borde;
    rbody.style.borderRight = '1px solid ' + borde;
    rbody.style.background = fondo;
    rbody.style.backgroundPosition = '0px -4px';

    o.parentNode.insertBefore(rbody, o);
    rbody.appendChild(o);

    if (bottom)
    {
        var delta = (rbody.firstChild.style.pixelHeight) ? rbody.firstChild.style.pixelHeight : parseInt(rbody.firstChild.offsetHeight);
        var d2 = delta + 7;
        var d3 = delta + 6;
        var d4 = delta + 4;
        var r2b = r2.cloneNode(false);
        r2b.style.backgroundPosition = '-4px -' + d2 + 'px';
        var r3b = r3.cloneNode(false);
        r3b.style.backgroundPosition = '-2px -' + d3 + 'px';
        var r4b = r4.cloneNode(false);
        r4b.style.backgroundPosition = '-1px -' + d4 + 'px';
        rbot.appendChild(r4b);
        rbot.appendChild(r3b);
        rbot.appendChild(r2b);
        rbot.appendChild(r1b);
    }
    if (top)
    {
        rbody.parentNode.insertBefore(rtop, rbody);
    }
    if (bottom)
    {
        if (rbody.nextSibling)
        {
            rbody.parentNode.insertBefore(rbot, rbody.nextSibling);
        }
        else
        {
            rbody.parentNode.appendChild(rbot);
        }
    }
}
