/**
 * Used to manage tags
*/

function PriceSettingTool(handlerUrl) {
	this.url = handlerUrl;
}

PriceSettingTool.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);
}

PriceSettingTool.prototype.completeSet = 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("Successfully set price: "+response.split('\n')[1]);
			else
				alert("Setting price failed: \n"+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);
    }
}

PriceSettingTool.prototype.setPrice = function(artifactid, type, price) {
	var str = 'id='+artifactid+'&type='+type+'&price='+price;
	this.post(this.url, str, PriceSettingTool.prototype.completeSet);
}
