function vote_set(vote) {
    var page      = URLNAME;
    var hfunction = 'set';
    var sendVars = "function=" + hfunction + "&page=" + URLNAME + "&vote=" + vote;
    vote_ajax_handler(sendVars, vote_set_cb);
}
function vote_change(vote) {
    var page      = URLNAME;
    var hfunction = 'change';
    var sendVars = "function=" + hfunction + "&page=" + page + "&vote=" + vote;
    vote_ajax_handler(sendVars, vote_change_cb);
}
function vote_set_cb(responseData) {
    var votedata = eval("(" + responseData + ")");
    if (votedata.votestatus == "ok") {
       vote_dom_mod(votedata);
    } else if (votedata.votestatus == "login") {
        alert('You need to be logged in to do that!');
    }
}
function vote_change_cb(responseData) {
    var votedata = eval("(" + responseData + ")");
    if (votedata.votestatus == "ok") {
        vote_dom_mod(votedata);
    } else if (votedata.votestatus == "login") {
        alert('You need to be logged in to do that!');
    }
}
function vote_dom_mod(votedata) {
    if (votedata.vote == -1) {
        document.getElementById('votedownlink').className = "downstate";
        document.getElementById('voteuplink').className = "";
        document.getElementById('voteuplink').onclick = function() {vote_change(1); return false;};
        document.getElementById('votedownlink').onclick = function() {return false;};
    } else {
        document.getElementById('voteuplink').className = "downstate";
        document.getElementById('votedownlink').className = "";
        document.getElementById('voteuplink').onclick = function() {return false;};
        document.getElementById('votedownlink').onclick = function() {vote_change(-1); return false;};
    }
    if (votedata.score > 0) {
        var newscore = "+" + votedata.score;
    } else {
        var newscore = votedata.score;
    }
    document.getElementById('score').innerHTML = newscore;
    if (Effect) {
        Effect.Pulsate("score");
    }
}
function vote_ajax_handler(sendVars, voteCb) {
    var handlerUrl = "/system/vote/handler.php";
    if (!f) {
        http.open("POST", handlerUrl, true);
        http.onreadystatechange = function() {
            if (http.readyState == 4) {
                if(http.status == 200){
                    voteCb(http.responseText);
                    f = false;
                }
            }
        };
        http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        http.setRequestHeader('Accept','text/plain');
        http.send(sendVars);
        f = true;
    }
}