function poll_toggle_results(id, action) {
    if ( id ) {
        div_results = $('poll_results_' + id);
        div_vote = $('poll_vote_' + id);
    }
    else {
        div_results = $('poll_results');
        div_vote = $('poll_vote');
    }
    if ( action == 'show' ) {
        div_results.style.display = "block";
        div_vote.style.display = "none";
    }
    else {
        div_results.style.display = "none";
        div_vote.style.display = "block";
    }
}

function poll_vote(id) {
    var target_url = '/pages/polls/ajax_poll.php';

    var form_name = 'poll_'+id;
    
    var form = $(form_name);
    
    if (supportsAjax()) {
        new Ajax (target_url, {method: 'post', postBody: $F(form), onComplete: poll_process_vote}).request();
        return true;
    }
    else {
        form.ajax.value = 0;
        form.action = target_url;
        form.method = 'POST';
        form.submit();
        return false;
    }
}

function poll_process_vote(results) {
    var json_results = eval( '(' + results + ')' );
    if ( json_results['error_msg'] ) {
        alert(json_results['error_msg']);
        return;
    }
    var poll_div = $('inline-poll_' + json_results['data']['id']);
    poll_div.innerHTML = json_results['template'];
		poll_div.parentNode.style.display = 'block';
    var clrgif = document.createElement('img');
    if ( json_results['dw_url'] ) {
        var dw_url = json_results['dw_url'];
    }
    else {
        var dw_url = 'http://dw.com.com/redir?ltype=&siteid=107&edid=107&ptid=6087&onid=10217&useract=141&destURL=http://dw.com.com/clear/c.gif';
    }
    clrgif.setAttribute('src', dw_url);
    document.body.appendChild(clrgif);   
    
}