var pathname1 = document.location.pathname;
var pathname2 = pathname1.substring(pathname1.indexOf("/")+1,pathname1.length);
var ctxPath = "/" + pathname2.substring(0,pathname2.indexOf("/"));

function addToLib(image, id) {
	var url = ctxPath + "/addCitationToLib/" +id + ".html";
	var req = newXMLHttpRequest();
	req.onreadystatechange = getReadyStateHandlerForText(req, showSectionPopup);
	req.open("POST", url, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send("");
    image.className="pubmed-removefromlib";
 	image.title = "Remove this citation from My Library";
	image.onclick = function(){removeFromLib(this,id); return false;};
 	 
}

function removeFromLib(image, id) {
	var url = ctxPath + "/removeCitationFromLib/" +id + ".html";
	var req = newXMLHttpRequest();
	req.onreadystatechange = getReadyStateHandlerForText(req, updateContents);
	req.open("POST", url, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send("");
    image.className="pubmed-addtolib";
	image.title = "Add this citation to My Library";
	image.onclick = function(){addToLib(this,id);return false;};
}

function updateContents(){
	return true;
}
function showPopup(retVal){
	if(retVal.substring(0,4) == 'true')
	{		
		tb_show('Title', ctxPath +'/addanonyuserctntpopup.html?modal=true&height=490&width=650', false);		
	}
	return true;
}
