// JavaScript Document

// cast vote

function castVote(path) {
	
	var responseID = 0;
	
	for(i=0;i<document.vote.responseID.length;i++) {
		if(document.vote.responseID[i].checked)	 {
			responseID = document.vote.responseID[i].value;
		}
	}

	if(responseID != 0) {
	
		var xmlHttp;
		try {
			// Firefox, Opera 8.0+, Safari
			xmlHttp=new XMLHttpRequest();
		}
		catch (e) {
			// Internet Explorer
			try {
				xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch (e) {
				try {
					xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch (e) {
					alert("Your browser does not support AJAX!");
					return false;
				}
			}
		}	

		var pollID = document.vote.pollID.value;
	
		xmlHttp.onreadystatechange=function() {
			
			var poll = document.getElementById("poll");
	
			if(xmlHttp.readyState==3) {	  
				poll.innerHTML = "<p style='text-align: center'>CASTING VOTE...</p>";			
			}	
	
		  
			if(xmlHttp.readyState==4) {
				if(xmlHttp.status==200) {  
					poll.innerHTML = xmlHttp.responseText;
				} else {
					poll.innerHTML = "<p style='text-align: center'><strong>ERROR: " + xmlHttp.status + "</strong><br />There was an error casting your vote.</p>";
				}			
			}	  
		}
		
		xmlHttp.open("GET", path + "/design/widgets/site/ip_ajax_poll.cfm?action=castVote&pollID=" + pollID + "&responseID=" + responseID, true);
		xmlHttp.send(null);
		
	}
	
}

// reset vote

function resetVote(pollID,path) {

	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}	

	xmlHttp.onreadystatechange=function() {
		
		var poll = document.getElementById("poll");

		if(xmlHttp.readyState==3) {	  
			poll.innerHTML = "<p style='text-align: center'>RESETTING VOTE...</p>";			
	  	}	

	  
		if(xmlHttp.readyState==4) {
			if(xmlHttp.status==200) {  
				poll.innerHTML = xmlHttp.responseText;
			} else {
				poll.innerHTML = "<p style='text-align: center'><strong>ERROR: " + xmlHttp.status + "</strong><br />There was an error resetting your vote.</p>";				
			}			
	  	}	  
	}
	
	xmlHttp.open("GET", path + "/design/widgets/site/ip_ajax_poll.cfm?action=resetVote&pollID=" + pollID, true);
	xmlHttp.send(null);
	
	setTimeout("Custom.init()", 1000);
	
}

// show poll results

function showPollResults(pollID,path) {

	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}	

	xmlHttp.onreadystatechange=function() {
		
		var poll = document.getElementById("poll");

		if(xmlHttp.readyState==3) {	  
			poll.innerHTML = "<p style='text-align: center'>GETTING POLL RESULTS...</p>";			
	  	}	

	  
		if(xmlHttp.readyState==4) {
			if(xmlHttp.status==200) {  
				poll.innerHTML = xmlHttp.responseText;
			} else {
				poll.innerHTML = "<p style='text-align: center'><strong>ERROR: " + xmlHttp.status + "</strong><br />There was an error getting the poll results.</p>";				
			}			
	  	}	  
	}
	
	xmlHttp.open("GET", path + "/design/widgets/site/ip_ajax_poll.cfm?action=showPollResults&pollID=" + pollID, true);
	xmlHttp.send(null);
	
}

// vote... bring up responses

function vote(pollID,path) {

	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	xmlHttp.onreadystatechange=function() {
		
		var poll = document.getElementById("poll");

		if(xmlHttp.readyState==3) {	  
			poll.innerHTML = "<p style='text-align: center'>GETTING POLL RESPONSES...</p>";			
	  	}	

	  
		if(xmlHttp.readyState==4) {
			if(xmlHttp.status==200) {  
				poll.innerHTML = xmlHttp.responseText;
			} else {
				poll.innerHTML = "<p style='text-align: center'><strong>ERROR: " + xmlHttp.status + "</strong><br />There was an error setting up the poll.</p>";				
			}			
	  	}	  
	}
	
	xmlHttp.open("GET", path + "/design/widgets/site/ip_ajax_poll.cfm?action=vote&pollID=" + pollID, true);
	xmlHttp.send(null);
	
	setTimeout("Custom.init()", 1000);
	
}
