// AJAX function for GC:Voting System (Gustavo Campos - www.guscampos.com)

var http = false;
	    
    if(navigator.appName == "Microsoft Internet Explorer") {
      http = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
      http = new XMLHttpRequest();
    }
    
	function prepare_vote(poll_id,poll_option_id) {		
		document.forms[''+poll_id+''].voted_option.value = poll_option_id;		
	}
	
	function do_vote(poll_id) {	

		var voted_option = document.forms[''+poll_id+''].voted_option.value;
		
		if(voted_option == '') {
			alert('Please select an option');
			return false;
		}
		
		document.forms[''+poll_id+''].voteBtn.value = 'Voting Now!';
		document.forms[''+poll_id+''].voteBtn.disabled = true;
		//do the ajax thing
		http.abort();
      	http.open("POST", 'vote.php?action=vote&poll_id='+poll_id+'&poll_option='+voted_option, true);
      	http.onreadystatechange=function() {
        	if(http.readyState == 4) {
          		document.getElementById('vote-form').innerHTML = http.responseText;
        	}
     	}

      	http.send(null); 
	}
	