﻿// send and save the vote
function votePoll(id) {
    pollWaiting(1);
    CreateCallback(KEYwebRoot + "widgets/Poll/PollCallBack.aspx?vote=" + id, pollReload);
}

// update page control
function pollReload(response) {
    if (response == "reload") {
        location.reload();
    }
    else {
        var pollControl = document.getElementById("pollControl");
        var innerHtml = response.toString();
        var findText = "<div id=\"pollControl\">";

        var start = innerHtml.indexOf(findText, 0) + findText.length;
        var length = innerHtml.length - 20;

        pollControl.innerHTML = innerHtml.substring(start, length);
    }

    pollWaiting(0);
}

// show or hide the waiting image by the vote
function pollWaiting(state) {
    var waiting = document.getElementById("imgWaiting");

    waiting.style.visibility = (state == 0 ? "hidden" : "visible");
}