
var xmlHttp
var currentobj
var voteobj
var votedisptype

/* added by Giles */
var baseURL = "/thevote/wp-content/plugins/vote-it-up";

//Javascript Function for JavaScript to communicate with Server-side scripts
function AJAXrequest(scriptURL) {
	xmlHttp=GetXmlHttpObject()
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 
	xmlHttp.onreadystatechange=voteChanged;
	xmlHttp.open("GET",scriptURL,true);
	xmlHttp.send(null);
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function voteChanged() 
{ 
if (xmlHttp.readyState==4)
{ 
	var votedisp = document.getElementById('voteid' + currentobj);
	var votenodisp = document.getElementById('votes' + currentobj);
	var vote_total_up = document.getElementById('vote_total_up_' + currentobj);
	var vote_total_down = document.getElementById('vote_total_down_' + currentobj);
	var votes_word_up = document.getElementById('votes_word_up_' + currentobj);
	var votes_word_down = document.getElementById('votes_word_down_' + currentobj);
	var vote_buttons = document.getElementById('votebuttons_' + currentobj);
	var voteno = xmlHttp.responseText;
	
	var vote_busy = document.getElementById('votebusy_' + currentobj);
	if (vote_busy) vote_busy.style.display = 'none';
	
	switch (votedisptype) {
	case 'diggstyle':
	var voteArray = voteno.split(',');
	vote_total_up.innerHTML = voteArray[0];
	votes_word_up.innerHTML = (voteArray[0]==1) ? 'Thumb Up' : 'thumbs Up';
	vote_total_down.innerHTML = voteArray[1];
	votes_word_down.innerHTML = (voteArray[1]==1) ? 'Thumb Down' : 'Thumbs Down';
	break;
	case 'bar':
	votenodisp.style.width = voteno;
	votedisp.innerHTML = '';
	break;
	case 'ticker':
	votenodisp.innerHTML = voteno;
	votedisp.innerHTML = '';
	votedisp.style.display = 'none';
	break;
}


//return xmlHttp.responseText;
//document.write(xmlHttp.responseText);
}
}

function vote_link_com(votelinkID,voteID,userID,baseURL) {
	//var votelinkdisp = document.getElementById(votelinkID);
	//based on <a style="cursor:default;" href="javascript:vote('<?php the_ID(); ?>','voterbox_<?php the_ID(); ?>', '<?php echo $user_ID; ?>', '<?php bloginfo('url') ?>');">Vote!</a>
	//votelinkdisp.innerHTML="<a style=\"cursor:default;\" href=\"javascript:vote('"+voteID+"','voterbox_"+voteID+"', '"+userID+"', '"+baseURL+"');\">Vote!</a>";
}

function vote_ticker(articleID,voteID,userID,baseURL) {
	votedisptype = 'ticker';
	currentobj = voteID;
	var scripturl = baseURL+"/voteinterface.php?type=vote&tid=total&uid="+userID+"&pid="+articleID+"&auth="+Math.random();
	AJAXrequest(scripturl);
}

function sink_ticker(articleID,voteID,userID,baseURL) {
	votedisptype = 'ticker';
	currentobj = voteID;
	var scripturl = baseURL+"/voteinterface.php?type=sink&tid=total&uid="+userID+"&pid="+articleID+"&auth="+Math.random();
	AJAXrequest(scripturl);
}

function vote(articleID,voteID,userID,baseURL,entryID) 
{
	var vote_buttons = document.getElementById('votebuttons_' + entryID);
	var vote_busy = document.getElementById('votebusy_' + entryID);
	if (vote_buttons) vote_buttons.style.display = 'none';
	if (vote_busy) vote_busy.style.display = 'block';
	
	votedisptype = 'diggstyle'; // bar';
	currentobj = voteID;
	var scripturl = baseURL+"/voteinterface.php?type=vote&uid="+userID+"&pid="+articleID+"&auth="+Math.random();
	AJAXrequest(scripturl);
}

function sink(articleID,voteID,userID,baseURL,entryID) 
{
	var vote_buttons = document.getElementById('votebuttons_' + entryID);
	var vote_busy = document.getElementById('votebusy_' + entryID);
	if (vote_buttons) vote_buttons.style.display = 'none';
	if (vote_busy) vote_busy.style.display = 'block';
	
	votedisptype = 'diggstyle'; // 'bar';
	currentobj = voteID;
	var scripturl = baseURL+"/voteinterface.php?type=sink&uid="+userID+"&pid="+articleID+"&auth="+Math.random();
	AJAXrequest(scripturl);
}

