var g_tnuid = '';
var g_taxon = '';
var g_pub_id = '';
var g_element_ID = '';

function prepareTreatment(tnuid, taxon, pub_id, elementID) {
	var urlTreatment = 'http://hymfiles.biosci.ohio-state.edu/scripts/OJ_Break.pl?action=getTreatments&pub_list=' + pub_id + '&callback=handlePrepareTreatment';
	//var urlTreatment = 'http://hymfiles.biosci.ohio-state.edu/scripts/OJ_Break.pl?action=getTreatment&lsid=urn:lsid:biosci.ohio-state.edu:osuc_concepts:' + tnuid + '&pub_id=' + pub_id + '&elementID=' + elementID + '&callback=handlePrepareTreatment';
	
	g_tnuid = tnuid;
	g_taxon = taxon;
	g_pub_id = pub_id;
	g_element_ID = elementID;
	
	// Create a new script object (JSON-style query)
	aObj = new JSONscriptRequest(urlTreatment);
	// Build the script tag
	aObj.buildScriptTag();
	// Execute (add) the script tag
	aObj.addScriptTag();
}

function handlePrepareTreatment(jData) {
	if (jData == null) {
		// Parse problem so return
		return;
	}
	
	// Prepare treatments
	for (var pubCount = 0; pubCount < jData.length; pubCount++) {
		var pub = jData[pubCount];
		var tnuids = pub.tnuids;
		
		for (var tnuidCount = 0; tnuidCount < tnuids.length; tnuidCount++) {
			// Check if annotation is present
			if (tnuids[tnuidCount] == g_tnuid) {
				document.getElementById(g_element_ID).innerHTML += ' Plazi Digital Archive: <a href="http://plazi2.cs.umb.edu/GgServer/search?resultFormat=html&taxonomicName.isNomenclature=taxonomicName.isNomenclature&taxonomicName.exactMatch=taxonomicName.exactMatch&taxonomicName.LSID=urn:lsid:biosci.ohio-state.edu:osuc_concepts:' + g_tnuid + '&MODS.ModsDocID=' + g_pub_id + '&indexName=0" target="_new"><img src="http://atbi.biosci.ohio-state.edu/HymOnline/plazi_logo.png" title="View formatted treatment from Plazi" border="0"></a>';
			}
		}
	}
}

