	var req;
	var linkId;
	
	function postHit(id) {
		url = '_hit.php?postId=' + id;
		loadXMLDoc(url);
		if(req) {
			req.open("GET", url, true);
			req.send("");
		}
	}
	
	function vote(url, id) {
		linkId = id;
		ePleaseWait = document.getElementById('pleaseWait');
		if (!ePleaseWait.id) {
			alert('Veuillez attendre la fin du chargement de la page avant de voter.');
		} else {
			ePleaseWait.className = 'pleaseWait';
			loadXMLDoc(url);
			if(req) {
				req.onreadystatechange = processReqChange;
				req.open("GET", url, true);
				req.send("");
			}
			processReqChange();
		}
	}
	
	function processVote() {
		var vote = req.responseXML.getElementsByTagName("vote")[0];
		var msg = req.responseXML.getElementsByTagName("msg")[0];
		var status = msg.getAttribute('type');
		
		document.getElementById('pleaseWaitText').innerHTML = msg.getAttribute('details');

		if (status == 'error') {
			document.getElementById('pleaseWait').className = 'pleaseWaitError';
		} else {
			document.getElementById('pleaseWait').className = 'pleaseWaitSuccess';
		}

		localVoteUp = document.getElementById('voteup' + linkId);
		localVoteDown = document.getElementById('votedown' + linkId);

		if (localVoteUp.innerHTML != vote.getAttribute('voteup')) {
			localVoteUp.innerHTML = vote.getAttribute('voteup');
			localVoteUp.className = localVoteUp.className + ' updated';
		}
		if (localVoteDown.innerHTML != vote.getAttribute('votedown')) {
			localVoteDown.innerHTML = vote.getAttribute('votedown');
			localVoteDown.className = localVoteUp.className + ' updated';
		}

		window.setTimeout("document.getElementById('pleaseWait').className = 'pleaseWaitHidden'", 3000);
	}

	function loadXMLDoc(url) {
		req = false;
		// branch for native XMLHttpRequest object
		if(window.XMLHttpRequest) {
			try {
				req = new XMLHttpRequest();
			} catch(e) {
				req = false;
			} 
		// branch for IE/Windows ActiveX version
		} else if(window.ActiveXObject) {
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					req = false;
				}
			}
		}
	}
	
	function processReqChange() {
		// only if req shows "loaded"
		if (req.readyState == 4) {
			// only if "OK"
			if (req.status == 200) {
				processVote(linkId);
			} else {
				alert("There was a problem retrieving the XML data:\n" + req.statusText);
				return false;
			}
		}
		return false;
	}