
    url     = ABS_URI+'ajax/poll.php';
    choices = $$('#pollbody input');
    //btnvote = $$('#pollbody .vote');
    btnvote = $$('#pollbody .votebar button');
    ipadr   = IP;
    
    choices.each(function(obj){
        obj.onclick = function () {
            current = this.parentNode.parentNode.id;
            reset(current);
            this.parentNode.className = "selected";    
        }
    });
    
    btnvote.each( function(obj){
        obj.onclick = function(){
        pid = null;
        qid = null;
        choices.each(function(obj){
            if(obj.parentNode != null && obj.parentNode.parentNode != null){
                if(obj.checked){
                    pid = obj.parentNode.parentNode.id;
                    qid = obj.value;    
                }
            }
        });
            if ( (pid != null) && (qid != null) ){
                send(pid, qid);
            }else{
                return false;
            }
        }
    });
    
    function reset(current){
        choices.each(function(obj){
            if(obj.parentNode.parentNode != null){
                if (obj.parentNode.parentNode.id == current){
                    if(obj.parentNode.className == "selected"){
                        obj.parentNode.className = "";
                    }
                }
            }
        });
    }
    
    function send(pid, qid){
        pid = parseInt(pid.replace('p', ""));
        qid = parseInt(qid);
        url += '?pid='+pid+'&qid='+qid+'&ip='+ipadr;
        options = {
            method: 'get',
            
            onComplete: function (obj){
                
                switch(obj.responseText){
                    case "VOTED\n":
                        alert("U heeft reeds op deze POLL gestemd!");
                    break;
                }
                $('p'+pid).innerHTML = '<li class="link"><a href="poll/'+pid+'" class="pollresults">Klik hier om de resultaten te bekijken</a></li>';                
            }
        };
        new Ajax.Request(url, options);
        
    }
    
    
        


