
var xmlHttp
var currentobj
var voteobj
var votedisptype

//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 EnvoiRequete(scriptURL,id)
 {
 var xhr_object = null;
 

xhr_object=GetXmlHttpObject()
 // On ouvre la requete vers la page désirée
 xhr_object.open("GET", scriptURL, true);
 
 xhr_object.onreadystatechange = function(){
 if ( xhr_object.readyState == 4 )
 {
 	
 // j'affiche dans la DIV spécifiées le contenu retourné par le fichier
 //id Du div affichant le compte des participants
 document.getElementById('votes'+id).innerHTML = xhr_object.responseText;
 //id du div affichant le lien annule - le réinitialise à vide
 document.getElementById('voteid'+id).innerHTML='';
 
 }
 }
 // dans le cas du get
 xhr_object.send(null);

 }
 
 
 function EnvoiRequete2(scriptURL,id)
 {
 var xhr_object = null;
 

xhr_object=GetXmlHttpObject()
 // On ouvre la requete vers la page désirée
 xhr_object.open("GET", scriptURL, true);
 
 xhr_object.onreadystatechange = function(){
 if ( xhr_object.readyState == 4 )
 {
 	
 // j'affiche dans la DIV spécifiées le contenu retourné par le fichier
 //id Du div affichant le compte des participants
 document.getElementById('listename').innerHTML = xhr_object.responseText;

 
 }
 }
 // dans le cas du get
 xhr_object.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 voteno = xmlHttp.responseText;

switch (votedisptype) {
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,userID,baseURL) {
	votedisptype = 'bar';
	currentobj = voteID;
	var scripturl = baseURL+"/voteinterface.php?type=vote&uid="+userID+"&pid="+articleID+"&auth="+Math.random();
	AJAXrequest(scripturl);
	scripturl = baseURL+"/displayname.php?pid="+articleID;
	EnvoiRequete2(scripturl,articleID);  
}

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

	EnvoiRequete(scripturl,articleID);    
	scripturl = baseURL+"/displayname.php?pid="+articleID;

	EnvoiRequete2(scripturl,articleID);    

	
}


