function prepareYtePoem(xmlPoem) {
	
	var linearray=xmlPoem.getElementsByTagName("line");
	var ytePoem = document.getElementById("ytepoem");
		
	var yteContent = document.createElement("div");
	yteContent.setAttribute("id", "yteContent");
	ytePoem.appendChild(yteContent);
		
	for (e=0;e<linearray.length;e++) {
		
		try {
			line=xmlPoem.getElementsByTagName("line")[e].childNodes[0].nodeValue;
		}
		catch(err) {
			line = null;
		}
			
		if (line != null ) {
			var newLine = document.createElement("p");
			var newLineTerms = document.createElement("div");
			var lineNode = document.createTextNode(line);

			var linePlus=line.replace(/\s+/g,"+");
			newLineTerms.setAttribute("id", 'lineterm'+e);
			newLine.appendChild(lineNode);
			idLine = newLineTerms.getAttribute("id");
				
			originalPoem.appendChild(newLine);
			yteContent.appendChild(newLineTerms);
		
			requestYte(linePlus, idLine);
		}
	}
}

function requestYte (line, idLine) {

	var hostname = 'http://api.search.yahoo.com/';
	var path = 'ContentAnalysisService/V1/termExtraction?appid=tHT5qsXV34FNwpel1Di0GCA5qdaqojOPQAxKZViFp5QL.TXeehD8Uu1LQ1JeF6s-&context=' + line;
	var url = 'http://www.dudeyjon.com/digipoem/restapiproxy.php?hostname=' + encodeURIComponent(hostname) + '&api_path=' + encodeURIComponent(path);
	var method = "POST";
	var asyncRequest = "true";
	var callback = loadYteXML;
	var xmlDoc = xmlRequest(url, method, asyncRequest, callback);

	function loadYteXML(request)
	{	
		// IE Code
		if (window.ActiveXObject)
		{
			var response = request.responseXML;
			xmlDocYte=new ActiveXObject("Microsoft.XMLDOM");
			xmlDocYte.async=false;
			xmlDocYte.load(response);
			getTerm(xmlDocYte);
		}
	
		// Firefox Code
		else if (document.implementation&&document.implementation.createDocument)
		{
			var response = request.responseXML;
			var xmlDocYte = document.createElement("div");
			xmlDocYte.innerHTML = response;
			getTerm(response);
		}
	
		// Error Code
		else
		{
			alert('Your browser cannot handle this script');
		}
	}
	
	function getTerm(xmlDocYte)
	{
		var results=xmlDocYte.getElementsByTagName("Result");
		for (i=0;i<results.length;i++)
		{
			var terms=xmlDocYte.getElementsByTagName("Result")[i].childNodes[0];
			
			var ytePoem = document.getElementById(idLine);
			var newTerm = document.createElement("p");
			var termNode = document.createTextNode(terms.nodeValue);
			newTerm.appendChild(termNode);
			
			ytePoem.appendChild(newTerm);
		}
	}

	function populateTerms(term)
	{
		var newTerm = document.createElement("p");
		var newLine = document.getElementById(idLine);
		var termNode = document.createTextNode(term);
		newTerm.appendChild(termNode);
	}


}