var xmlHttp;

function GetSelectedItem(poll) {
    chosen = "";
    len = poll.length;

    for (i = 0; i <len; i++) {
        if (poll[i].checked) {
            chosen = poll[i].value;
        }
    }

    if (chosen == "") {
        alert("No Option Chosen");
    } else {
        return chosen;
    }
}

var q_id;


function Save(poll, question_id, submit_poll){
    GetSelectedItem(poll);
    xmlHttp=GetXmlHttpObject();
    if (xmlHttp==null){
        alert ("Browser does not support HTTP Request");
        return;
    }
    
    q_id = question_id;

    var url = '?action='+submit_poll+'&option='+chosen+'&question_id='+question_id;
    xmlHttp.onreadystatechange=stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
}

function stateChanged(){ 
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
        document.getElementById("txtHint_"+q_id).innerHTML=xmlHttp.responseText;
    }
}

function GetXmlHttpObject(){
    var xmlHttp=null;
    try{
        // Firefox, Opera 8.0+, Safari
        xmlHttp=new XMLHttpRequest();
    }catch (e){
        //Internet Explorer
        try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e){
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}