﻿function ChannelObject()
{
    this.name = new String();
    this.topic = new String();
    this.rawtopic = new String();
    this.version = new String();
    this.hashlink = new String();
    this.language = 10;
    this.users = 0;
}

ChannelObject.prototype.populate = function(n, t, v, h, l, u)
{
    this.name = n;
    this.topic = t;
    this.rawtopic = t;
    this.version = v;
    this.hashlink = "arlnk://F5fPZROCs4iuoc9Jm55Z" + h;
    this.language = l;
    this.users = u;
}

ChannelObject.prototype.drawTopic = function()
{
    str_split = this.topic.split("");
    str = new String();
    spans = 0;
    bold_on = false;
    underline_on = false;
    italic_on = false;

    for (x = 0; x < str_split.length; x++) // text effects
    {
        if (str_split[x] == "\x03") // forecolor
        {
            code = str_split[x + 1] + str_split[x + 2];
            code = ColorCodeToSpanString(code, false);

            if (code != null)
            {
                str += code;
                x += 2;
                spans++;
                continue;
            }
        }

        if (str_split[x] == "\x05") // backcolor
        {
            code = str_split[x + 1] + str_split[x + 2];
            code = ColorCodeToSpanString(code, true);

            if (code != null)
            {
                str += code;
                x += 2;
                spans++;
                continue;
            }
        }

        if (str_split[x] == "\x06") // bold
        {
            bold_on = !bold_on;
            spans++;
            str += bold_on ? "<span style=\"font-weight: bold;\">" : "<span style=\"font-weight: normal;\">";
            continue;
        }

        if (str_split[x] == "\x07") // underline
        {
            underline_on = !underline_on;
            spans++;
            str += underline_on ? "<span style=\"text-decoration: underline;\">" : "<span style=\"text-decoration: none;\">";
            continue;
        }

        if (str_split[x] == "\x09") // italic
        {
            italic_on = !italic_on;
            spans++;
            str += italic_on ? "<span style=\"font-style: italic;\">" : "<span style=\"font-style: normal;\">";
            continue;
        }

        str += (str_split[x] == " " ? " " : str_split[x]);
    }

    str = PopulateEmoticons(str); // emoticons

    if (spans > 0)
        for (x = 0; x < spans; x++)
            str += "</span>";

    this.topic = str;
}

ChannelObject.prototype.languageCode2String = function()
{
    switch (this.language)
    {
        case 11:
           return "Arabic";
        case 12:
           return "Chinese";
        case 14:
           return "Czech";
        case 15:
           return "Danish";
        case 16:
           return "Dutch";
        case 10:
           return "English";
        case 27:
           return "Finnish";
        case 28:
           return "French";
        case 29:
           return "German";
        case 30:
           return "Italian";
        case 17:
           return "Japanese";
        case 19:
           return "Kirghiz";
        case 20:
           return "Polish";
        case 21:
           return "Portuguese";
        case 31:
           return "Russian";
        case 22:
           return "Slovak";
        case 23:
           return "Spanish";
        case 25:
           return "Swedish";
        case 26:
           return "Turkish";
        default:
           return "English";
    }
}
