function orkut(oId) {
    objeto      = window.document.getElementById(oId);
    valor       = objeto.value;
    comprimento = valor.length;
    novovalor   = "";

    if(comprimento == 0)
        retornaAlertaVazio();

    for(i = 0; i < comprimento; i++) {
        novovalor += formataAleatorio(valor.charAt(i));
    }

    if(novovalor.length > 1024) {
        if(confirm("O texto esta muito longo para um scrap, deseja prosseguir assim?"))
            adicionaTexto('result', novovalor);
    }
    else
        adicionaTexto('result', novovalor);

    div = window.document.getElementById("no");
    div.innerHTML = novovalor.length + " caracteres";
}



function adicionaTexto(oId, valor) {
    objeto = window.document.getElementById(oId);
    objeto.value = valor;
}



function retornaAlertaVazio() {
    alert("Você precisa digitar algo!");
    return false;
}



function formataAleatorio(valor) {
    if(valor == " ")
        return valor;

    aleatorio = Math.round(Math.random() * 17) + 1;

    switch(aleatorio) {
        case 1:
            valor = "[aqua]" + valor + "[/aqua]";
            return valor;
        case 2:
            valor = "[blue]" + valor + "[/blue]";
            return valor;
        case 3:
            valor = "[fuchsia]" + valor + "[/fuchsia]";
            return valor;
        case 4:
            valor = "[gold]" + valor + "[/gold]";
            return valor;
        case 5:
            valor = "[gray]" + valor + "[/gray]";
            return valor;
        case 6:
            valor = "[green]" + valor + "[/green]";
            return valor;
        case 7:
            valor = "[lime]" + valor + "[/lime]";
            return valor;
        case 8:
            valor = "[maroon]" + valor + "[/maroon]";
            return valor;
        case 9:
            valor = "[navy]" + valor + "[/navy]";
            return valor;
        case 10:
            valor = "[olive]" + valor + "[/olive]";
            return valor;
        case 11:
            valor = "[orange]" + valor + "[/orange]";
            return valor;
        case 12:
            valor = "[pink]" + valor + "[/pink]";
            return valor;
        case 13:
            valor = "[purple]" + valor + "[/purple]";
            return valor;
        case 14:
            valor = "[red]" + valor + "[/red]";
            return valor;
        case 15:
            valor = "[silver]" + valor + "[/silver]";
            return valor;
        case 16:
            valor = "[teal]" + valor + "[/teal]";
            return valor;
        case 17:
            valor = "[violet]" + valor + "[/violet]";
            return valor;
        case 18:
            valor = "[yellow]" + valor + "[/yellow]";
            return valor;
        default:
            return valor;
    }
}
function previewScrap(oSource) {
    objSource  = window.document.getElementById(oSource);

    nwProp = "top=0,left=0,toolbar=no,status=no,resizable=yes,location=no,width=420,height=420";
    objDestiny = window.open("", "Ver", nwProp);

    objDestiny.document.write('<html>');
    objDestiny.document.write('  <head>');
    objDestiny.document.write('      <title>Ver Recado | Orkut.etc.br</title>');
    objDestiny.document.write('      <style>body{font-family:courier new;font-size:10pt;}</style>');
    objDestiny.document.write('  </head>');
    objDestiny.document.write('  <body>');

    sourceValue = objSource.value.toString();
    finalValue  = sourceValue;

    finalValue = encodeHTMLTags(finalValue);
    finalValue = replaceSmilies(finalValue);
    finalValue = replaceColorTags(finalValue);
    finalValue = replaceFormatTags(finalValue);
    finalValue = replaceLinks(finalValue);

    finalValue = finalValue.replace(/\n/gm, "<br>");

    objDestiny.document.write(finalValue);

    objDestiny.document.write('<br><br><br><a href="#" onClick="javascript=window.close();">Fechar</a>');

    objDestiny.document.write('  </body>');
    objDestiny.document.write('</html>');
}

function encodeHTMLTags(value) {
    value = value.replace(/</gm, "&lt;");
    value = value.replace(/>/gm, "&gt;");
    return value;
}

function replaceSmilies(value) {
    value = value.replace(/(\[:X\])/gim,   '<img src="img/angry.gif">');
    value = value.replace(/(\[:D\])/gim,   '<img src="img/bigsmile.gif">');
    value = value.replace(/(\[\/\)\])/gim, '<img src="img/confuse.gif">');
    value = value.replace(/(\[8\)\])/gim,  '<img src="img/cool.gif">');
    value = value.replace(/(\[:P\])/gim,   '<img src="img/funny.gif">');
    value = value.replace(/(\[:\(\])/gim,  '<img src="img/sad.gif">');
    value = value.replace(/(\[:\)\])/gim,  '<img src="img/smile.gif">');
    value = value.replace(/(\[:o\])/gim,   '<img src="img/surprise.gif">');
    value = value.replace(/(\[;\)\])/gim,  '<img src="img/wink.gif">');
    return value;
}

function replaceColorTags(value) {
    value = value.replace(/(\[(aqua|blue|fuchsia|gold|gray|green|lime|maroon|navy|olive|orange|pink|purple|red|silver|teal|violet|yellow)\])/gim, '<span style="color:$2;">');
    value = value.replace(/(\[\/(aqua|blue|fuchsia|gold|gray|green|lime|maroon|navy|olive|orange|pink|purple|red|silver|teal|violet|yellow)\])/gim, '</span>');
    return value;
}

function replaceFormatTags(value) {
    value = value.replace(/(\[(b|u|i)\])/gim, "<$2>");
    value = value.replace(/(\[\/(b|u|i)\])/gim, "</$2>");
    return value;
}

function replaceLinks(value) {
    value = value.replace(/(\[link=(.*)\](.*)\[\/link\])/gim, '<a href="$2">$3</a>');
    return value;
}