﻿
var selectedValue = '';

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function checkIEVersion() {

    var version = getInternetExplorerVersion();

    if (version == 7)
        alert("Please use IE 8, FireFox or Chrome to get high on HighOnCoding!");     

}


function vote() {

    setSelectedPollChoice();
    updatePollStats();
}

function updatePollStats() {

    $.ajax(

    {
        type: "POST",
        dataType: "text/html",
        url: "/AjaxService.asmx/UpdatePollStatistics",
        data: "questionAndChoice=" + selectedValue,
        success: function(response) {

            loadPollStatistics();       

        }

    }

    );
   

}

function loadPollStatistics() {
    $(".pollWidgetClass").load("/Controls/PollStatPage.aspx");
}

function setSelectedPollChoice() {    
    
    var radioButtons = $(".radioButtonClass");

    jQuery.each(radioButtons, function() {

        if ($(this).attr("checked") == true) {

            selectedValue = $(this).val();
            return false;
        }

    });

    return ''; 
    

}