﻿function voteObject() {
    var JXHR;
    if (window.ActiveXObject) {
        if (_XML_ActiveX) {
            JXHR = new ActiveXObject(_XML_ActiveX);
        } else {
            var versions = ["MSXML2.XMLHTTP", "Microsoft.XMLHTTP", "Msxml2.XMLHTTP.7.0", "Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0"];
            for (var i = 0; i < versions.length; i++) {
                try {
                    JXHR = new ActiveXObject(versions[i]);
                    if (JXHR) {
                        var _XML_ActiveX = versions[i];
                        break;
                    }
                }
                catch (e) {
                }
            }
        }
    }
    if (!JXHR && typeof XMLHttpRequest != 'undefined') {
        try {
            JXHR = new XMLHttpRequest();
        } catch (e) {
            JXHR = false;
        }
    }
    return JXHR;
}

var httpvote = voteObject();
var voted = false;
var vbusy = false;
var vpId;

function votes() {
    if (!vbusy) {
        vbusy = true;
        var selection = getCheckedValue(document.forms[0].options);
        if (!voted && selection != "") {
            vpId = vpId + 1;
            voted = true;
            var urlz = "http://www.rugbyzone.com/votepoll.aspx?tmpInt=" + vpId + "&id=" + encodeURIComponent(selection)
            httpvote.open("GET", urlz, true);
            httpvote.onreadystatechange = voteresponse;
            vbusy = true;
            httpvote.send(null);
        } else {
            vbusy = false;
        }
    }
}

function voteresults(votepoll) {
    if (!vbusy) {
        vbusy = true;
        var urlz = "http://www.rugbyzone.com/votepoll.aspx?tmpInt=" + vpId + "&poll=" + encodeURIComponent(votepoll)
        httpvote.open("GET", urlz, true);
        httpvote.onreadystatechange = voteresponse;
        vbusy = true;
        httpvote.send(null);
    }
}

function voteresponse() {
    if (httpvote.readyState == 4) {
        if (httpvote.status == 200) {
            var tmptext = httpvote.responseText;
            if (document.getElementById("ctl00_VotePollControl1_vote")) { document.getElementById("ctl00_VotePollControl1_vote").innerHTML = tmptext; } else { document.getElementById("ctl00_VotePollControl1_votes").innerHTML = tmptext; }
        } else {

        }
        vbusy = false;
    }
}

function getCheckedValue(radioObj) {
    if (!radioObj)
        return "";
    var radioLength = radioObj.length;
    if (radioLength == undefined)
        if (radioObj.checked)
        return radioObj.value;
    else
        return "";
    for (var i = 0; i < radioLength; i++) {
        if (radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}