var ajax = new sack();
var updatewhat;
var last_id;
var showMessage = "";
var arrayOfClicks = new Array(100); 
function getPollDetail1_homepage(x)
{
	if(arrayOfClicks[x]==1){
		var obj = document.getElementById("p"+x);
		obj.innerHTML = "";
		arrayOfClicks[x] = 0;
	} else {
		//alert('_ajax_getDaysInMonth.php?month='+Month);
		ajax.requestFile = '/_ajax_calls/_getPollDetail1_homepage.php?id='+x;	
		ajax.onCompletion = createPollDetail1_homepage;	// Specify function that will be executed after file has been found
		updatewhat = "p"+x;
		ajax.runAJAX();		// Execute AJAX function
		arrayOfClicks[x] = 1;
	}
}
function createPollDetail1_homepage()
{
	var obj = document.getElementById(updatewhat);
	obj.innerHTML = ajax.response;
	//eval(ajax.response);	// Executing the response from Ajax as Javascript code	
}	

function getPollGraph_homepage(x,graphtype)
{
		ajax.requestFile = '/_ajax_calls/_getPollGraph'+graphtype+'_homepage.php?id='+x;	
		ajax.onCompletion = createPollGraph_homepage;	// Specify function that will be executed after file has been found
		updatewhat = "p"+x;
		ajax.runAJAX();		// Execute AJAX function
}

function getPollGraph_homepage_region(x,region)
{
		ajax.requestFile = '/_ajax_calls/_getPollGraph4_homepage.php?id='+x+'&r='+region;	
		ajax.onCompletion = createPollGraph_homepage;
		updatewhat = "p"+x;
		ajax.runAJAX();		// Execute AJAX function
}

function createPollGraph_homepage()
{
	var obj = document.getElementById(updatewhat);
	if(showMessage != "") {
		obj.innerHTML = showMessage + ajax.response;
		showMessage = "";
	} else {
		obj.innerHTML = ajax.response;
	}
}	

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function getVoteRadio(x) {
	//cycle through radio buttons and find the checked one.  we have to go through the ids... stupid browsers
	for(var i = 1;i<=8;i++) {
		//alert('looking for:'+'r'+x+'_'+i);
		var radioObj = document.getElementById('r'+x+'_'+i);
		if(radioObj!= null && radioObj.checked)
			return radioObj.value;
	}
	return "";
}


function do_vote_homepage(x)
{
	var c = getVoteRadio(x);
	if(c=="") {
		alert("You must first make a selection to vote on.");
		return;
	}
	ajax.requestFile = '/_ajax_calls/_vote.php?id='+x+'&c='+c;	
	ajax.onCompletion = createvoteoutput_homepage;
	updatewhat = "out"+x;
	last_id = x;
	ajax.runAJAX();
}

function createvoteoutput_homepage()
{
	var obj = document.getElementById(updatewhat);
	if(ajax.response=="success") {
		showMessage = "<br><b>Thanks for Voting!</b>";
		getPollGraph_homepage(last_id,1);
	} else {
		obj.innerHTML = ajax.response;
		//eval(ajax.response);
		checkFBLogin();  // then we call the face book js code again to have it parse and create the fb login button..
	}
}	

