function sack(file) {
    this.xmlhttp = null;
    this.resetData = function() {
        this.method = "POST";
        this.queryStringSeparator = "?";
        this.argumentSeparator = "&";
        this.URLString = "";
        this.encodeURIString = true;
        this.execute = false;
        this.element = null;
        this.elementObj = null;
        this.requestFile = file;
        this.vars = new Object();
        this.responseStatus = new Array(2)
    };
    this.resetFunctions = function() {
        this.onLoading = function() {};
        this.onLoaded = function() {};
        this.onInteractive = function() {};
        this.onCompletion = function() {};
        this.onError = function() {};
        this.onFail = function() {}
    };
    this.reset = function() {
        this.resetFunctions();
        this.resetData()
    };
    this.createAJAX = function() {
        try {
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP")
        } catch(e1) {
            try {
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
            } catch(e2) {
                this.xmlhttp = null
            }
        }
        if (!this.xmlhttp) {
            if (typeof XMLHttpRequest != "undefined") {
                this.xmlhttp = new XMLHttpRequest()
            } else {
                this.failed = true
            }
        }
    };
    this.setVar = function(name, value) {
        this.vars[name] = Array(value, false)
    };
    this.encVar = function(name, value, returnvars) {
        if (true == returnvars) {
            return Array(encodeURIComponent(name), encodeURIComponent(value))
        } else {
            this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true)
        }
    };
    this.processURLString = function(string, encode) {
        encoded = encodeURIComponent(this.argumentSeparator);
        regexp = new RegExp(this.argumentSeparator + "|" + encoded);
        varArray = string.split(regexp);
        for (i = 0; i < varArray.length; i++) {
            urlVars = varArray[i].split("=");
            if (true == encode) {
                this.encVar(urlVars[0], urlVars[1])
            } else {
                this.setVar(urlVars[0], urlVars[1])
            }
        }
    };
    this.createURLString = function(urlstring) {
        if (this.encodeURIString && this.URLString.length) {
            this.processURLString(this.URLString, true)
        }
        if (urlstring) {
            if (this.URLString.length) {
                this.URLString += this.argumentSeparator + urlstring
            } else {
                this.URLString = urlstring
            }
        }
        this.setVar("rndval", new Date().getTime());
        urlstringtemp = new Array();
        for (key in this.vars) {
            if (false == this.vars[key][1] && true == this.encodeURIString) {
                encoded = this.encVar(key, this.vars[key][0], true);
                delete this.vars[key];
                this.vars[encoded[0]] = Array(encoded[1], true);
                key = encoded[0]
            }
            urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0]
        }
        if (urlstring) {
            this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator)
        } else {
            this.URLString += urlstringtemp.join(this.argumentSeparator)
        }
    };
    this.runResponse = function() {
        eval(this.response)
    };
    this.runAJAX = function(urlstring) {
        if (this.failed) {
            this.onFail()
        } else {
            this.createURLString(urlstring);
            if (this.element) {
                this.elementObj = document.getElementById(this.element)
            }
            if (this.xmlhttp) {
                var self = this;
                if (this.method == "GET") {
                    totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
                    this.xmlhttp.open(this.method, totalurlstring, true)
                } else {
                    this.xmlhttp.open(this.method, this.requestFile, true);
                    try {
                        this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
                    } catch(e) {}
                }
                this.xmlhttp.onreadystatechange = function() {
                    switch (self.xmlhttp.readyState) {
                    case 1:
                        self.onLoading();
                        break;
                    case 2:
                        self.onLoaded();
                        break;
                    case 3:
                        self.onInteractive();
                        break;
                    case 4:
                        self.response = self.xmlhttp.responseText;
                        self.responseXML = self.xmlhttp.responseXML;
                        self.responseStatus[0] = self.xmlhttp.status;
                        self.responseStatus[1] = self.xmlhttp.statusText;
                        if (self.execute) {
                            self.runResponse()
                        }
                        if (self.elementObj) {
                            elemNodeName = self.elementObj.nodeName;
                            elemNodeName.toLowerCase();
                            if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea") {
                                self.elementObj.value = self.response
                            } else {
                                self.elementObj.innerHTML = self.response
                            }
                        }
                        if (self.responseStatus[0] == "200") {
                            self.onCompletion()
                        } else {
                            self.onError()
                        }
                        self.URLString = "";
                        break
                    }
                };
                this.xmlhttp.send(this.URLString)
            }
        }
    };
    this.reset();
    this.createAJAX()
}
var serverSideFile = "jscript/poll.php";
var voteLeftImage = "images/kezdo/graph_left_1.gif";
var voteRightImage = "images/kezdo/graph_right_1.gif";
var voteCenterImage = "images/kezdo/graph_middle_1.gif";
var graphMaxWidth = 130;
var graphMinWidth = 15;
var pollScrollSpeed = 5;
var useCookiesToRememberCastedVotes = true;
var txt_totalVotes = "Total number of votes: ";
var ajaxObjects = new Array();
var pollVotes = new Array();
var pollVoteCounted = new Array();
var totalVotes = new Array();
var preloadedImages = new Array();
preloadedImages[0] = new Image();
preloadedImages[0].src = voteLeftImage;
preloadedImages[1] = new Image();
preloadedImages[1].src = voteRightImage;
preloadedImages[2] = new Image();
preloadedImages[2].src = voteCenterImage;
function Poller_Get_Cookie(C) {
    var D = document.cookie.indexOf(C + "=");
    var A = D + C.length + 1;
    if ((!D) && (C != document.cookie.substring(0, C.length))) {
        return null
    }
    if (D == -1) {
        return null
    }
    var B = document.cookie.indexOf(";", A);
    if (B == -1) {
        B = document.cookie.length
    }
    return unescape(document.cookie.substring(A, B))
}
function Poller_Set_Cookie(B, F, C, I, D, A) {
    C = C * 60 * 60 * 24 * 1000;
    var E = new Date();
    var G = new Date(E.getTime() + (C));
    var H = B + "=" + escape(F) + ((C) ? ";expires=" + G.toGMTString() : "") + ((I) ? ";path=" + I: "") + ((D) ? ";domain=" + D: "") + ((A) ? ";secure": "");
    document.cookie = H
}
function showVoteResults(N, J) {
    document.getElementById("poller_waitMessage" + N).style.display = "none";
    var C = ajaxObjects[J].response;
    C = C.replace(/\n/gi, "");
    var E = new RegExp("^.*?<pollerTitle>(.*?)<.*$", "gi");
    var S = C.replace(E, "$1");
    var G = document.getElementById("poller_results" + N);
    var M = document.createElement("P");
    M.className = "result_pollerTitle";
    M.innerHTML = S;
    G.appendChild(M);
    var B = C.split(/<option>/gi);
    pollVotes[N] = new Array();
    totalVotes[N] = 0;
    for (var A = 1; A < B.length; A++) {
        var H = B[A].split(/</gi);
        var O = false;
        for (var I = 0; I < H.length; I++) {
            if (H[I].substring(0, 1) != "/") {
                var T = H[I].replace(/^(.*?)>.*$/gi, "$1");
                var K = H[I].replace(/^.*?>(.*)$/gi, "$1");
                if (T.indexOf("optionText") >= 0) {
                    var D = document.createElement("p");
                    D.className = "result_pollerOption";
                    D.innerHTML = K;
                    G.appendChild(D)
                }
                if (T.indexOf("optionId") >= 0) {
                    O = K / 1
                }
                if (T.indexOf("votes") >= 0) {
                    var R = document.createElement("div");
                    R.className = "result_pollGraph";
                    G.appendChild(R);
                    var P = document.createElement("img");
                    P.src = voteLeftImage;
                    R.appendChild(P);
                    var F = document.createElement("div");
                    F.style.backgroundImage = "url('" + voteCenterImage + "')";
                    F.innerHTML = "0%";
                    F.id = "result_voteTxt" + O;
                    R.appendChild(F);
                    var Q = document.createElement("img");
                    Q.src = voteRightImage;
                    R.appendChild(Q);
                    pollVotes[N][O] = K;
                    totalVotes[N] = totalVotes[N] / 1 + K / 1
                }
            }
        }
    }
    var L = document.createElement("p");
    L.className = "result_totalVotes";
    L.innerHTML = txt_totalVotes + totalVotes[N];
    R.appendChild(L);
    setPercentageVotes(N);
    slideVotes(N, 0)
}
function setPercentageVotes(C) {
    for (var B in pollVotes[C]) {
        pollVotes[C][B] = Math.round((pollVotes[C][B] / totalVotes[C]) * 100)
    }
    var A = 0;
    for (var B in pollVotes[C]) {
        A = A + pollVotes[C][B] / 1
    }
    pollVotes[C][B] = pollVotes[C][B] + (100 - A)
}
function slideVotes(D, A) {
    A = A / 1 + 1;
    for (var C in pollVotes[D]) {
        if (pollVotes[D][C] >= A) {
            var B = document.getElementById("result_voteTxt" + C);
            B.innerHTML = A + "%";
            B.style.width = Math.max(graphMinWidth, Math.round(A / 100 * graphMaxWidth)) + "px"
        }
    }
    if (A < 100) {
        setTimeout('slideVotes("' + D + '","' + A + '")', pollScrollSpeed)
    }
}
function prepareForPollResults(A) {
    document.getElementById("poller_waitMessage" + A).style.display = "block";
    document.getElementById("poller_question" + A).style.display = "none"
}
function castMyVote(F, A) {
    var D = A.elements["vote[" + F + "]"];
    var C = false;
    for (var E = 0; E < D.length; E++) {
        if (D[E].checked) {
            C = D[E].value
        }
    }
    Poller_Set_Cookie("dhtmlgoodies_poller_" + F, "1", 6000000);
    if (C) {
        var B = ajaxObjects.length;
        ajaxObjects[B] = new sack();
        ajaxObjects[B].requestFile = serverSideFile + "?pollId=" + F + "&optionId=" + C;
        prepareForPollResults(F);
        ajaxObjects[B].onCompletion = function() {
            showVoteResults(F, B)
        };
        ajaxObjects[B].runAJAX()
    }
}
function displayResultsWithoutVoting(B) {
    var A = ajaxObjects.length;
    ajaxObjects[A] = new sack();
    ajaxObjects[A].requestFile = serverSideFile + "?pollId=" + B;
    prepareForPollResults(B);
    ajaxObjects[A].onCompletion = function() {
        showVoteResults(B, A)
    };
    ajaxObjects[A].runAJAX()
};