/**
 * Used to manage tags
*/

function Sharing2Tool(handlerUrl) {
	this.url = handlerUrl;
}

Sharing2Tool.prototype.post = function(url, parameterString, callback) {
    if (window.XMLHttpRequest) {
	   	xmlReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		xmlReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	//alert(url+"?"+parameterString);
	xmlReq.persistenceTool = this;
	xmlReq.open("POST",url,true); 
	xmlReq.onreadystatechange = callback;
	xmlReq.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
	xmlReq.send(parameterString);
}

Sharing2Tool.prototype.completeShare2 = function() {
    if (xmlReq.readyState == 4) {
        if (xmlReq.status == 200) {
		    var response = xmlReq.responseText;
		    var status = (response.split("\n")[0]);
		    if (status == "success" || status == "success")
				alert("The item is now "+response.split('\n')[1]);
			else
				alert("Failed: "+response.split('\n')[1]);
		} else {
			alert("The website is having some problems ... the code returned is "+xmlReq.status);
		}
    } else {
		//alert("received file with status "+xmlReq.readyState);
    }
}

Sharing2Tool.prototype.setShared2 = function(artifactid, type, username, command) {
	var str = 'id='+artifactid+'&type='+type+'&user='+username+'&command='+command;
	this.post(this.url, str, Sharing2Tool.prototype.completeShare2);
}
