﻿var _tRef = '';

function savePolling(ref) {
    var val = "";
    var opt = document.getElementsByName("optPolling" + ref);
    for (var i=0;i<=opt.length-1;i++) {
        if (opt[i].checked == true) {
            val = opt[i].value;  
        }
    }
    if (val == "") {
        alert("Silahkan pilih dahulu salah satu pilihan yang tersedia");
    } else {
        _tRef = ref;
        document.getElementById("divPolInd" + ref).style.display = "";
        document.getElementById("divPolOk" + ref).style.display = "none";
        WCFSignUp.JSON_insertPolling(ref, val, savePollingOnComplete, savePollingOnError);
    }
}

function savePollingOnComplete(result) {
    if (result!='') {
        window.location = _rootPath + 'webForm/webForm/A2Z/quiz.aspx';
    } else {
        document.getElementById("divPolInd" + _tRef).style.display = "none";
        document.getElementById("divPolOk" + _tRef).style.display = "none";
        alert(result);
    }
}

function savePollingOnError(result) {
    document.getElementById("divPolInd" + _tRef).style.display = "none";
    document.getElementById("divPolOk" + _tRef).style.display = "none";
    alert(result);
}
