var nickList = new NickList();

function sendMessage() {
    var textInput = document.getElementById("message");
    var text = textInput.value;
    if (text !== "") {
        window.document.topic.SetVariable("data", text);
        window.document.topic.TCallLabel("\/", "send");
        textInput.value = "";
    }
}

function topicInit() {
    window.document.topic.SetVariable("host", getHostName());
    window.document.topic.SetVariable("port", 32899);
    window.document.topic.TCallLabel("\/", "connect");
}

function topicData(data) {
    if (data.indexOf(">") !== -1) {
        nickList.update(data);
    }
    else {
        document.getElementById("output").innerHTML += data + "<br \/>";
        document.getElementById("output").scrollTop = 99999999;
        setTitle(data);
    }
}

function topicConnected(yes) {
    if (yes) {
        document.getElementById("output").innerHTML += "Welcome to " + channel + "<br \/>";
        window.document.topic.SetVariable("data", channel + ">" + nick);
        window.document.topic.TCallLabel("\/", "send");
    }
    else {
        document.getElementById("output").innerHTML += "Connection failed<br \/>";
    }
}

function topicClosed() {
    document.getElementById("output").innerHTML += "Connection closed<br \/>";
}