function build_http_query(names,data) {
	var string = names[0] + "=" + data[0];
	var i;
	for (i = 1; i < names.length; i++) {
		string += "&" + names[i] + "=" + data[i];
	}
	return string;
}
var share = document.getElementsByClassName("sharebuttons");
var i;
for (i = 0; i < share.length; i++) {
	var buttons = share[i].getElementsByTagName("a");
	var index;
	for (i = 0; i < buttons.length; i++) {
		buttons[i].addEventListener("click",function() {
			o_contentShare(this.name);
		});
	}
}
function o_contentShare(service) {
	console.log("Sharing Content of " + window.location.href + " with Opolytics Sharebuttons 1.0 on " + service);
	var xhr = new XMLHttpRequest();
	var searchfor = "/";
	xhr.open("POST",window.location.href.substr(0,window.location.href.indexOf(searchfor) + searchfor.length) + "opolytics/sharebuttons/sharetracker.php");
	xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	var data = {"service":service,"site":window.location.href};
	var params = build_http_query(Object.keys(data),Object.values(data));
	xhr.addEventListener("load",function() {
		console.log("Opolytics Share Buttons Tracker returned: " + this.responseText);
	});
	xhr.send(params);
}