
function setOnclick ( node ) {
	node.onclick = function(){ showdetails(node) };
	}

function showdetails (node) { 
	var chars = node.firstChild.data; 
	var clang = node.lang;
	var panel = document.getElementById('panel');
	panel.style.display = 'block';
	var replacement = document.createElement('div');
	var str = document.createElement('div');
	str.appendChild(document.createTextNode(chars));
	str.className='ex';
	str.lang = clang;
	str.id = 'title';
	replacement.appendChild(str);
	
	panel.replaceChild(replacement, panel.firstChild);
	
	var uri = '/rishida/tools/analysestring/getnames.php?list='+encodeURIComponent(chars); // escaped so IE works
	httpRequest('GET', uri, true, displaypanel);
	}

function displaypanel () {  
	if (request.readyState == 4 && request.status == 200) { 
		var dbResponse = request.responseXML;
		var nodename; var newnode;
		var chardata = dbResponse.getElementsByTagName('p');
		var panellocation = document.getElementById('panel').firstChild;
		var clnode; 
		
		copyNodes(dbResponse.getElementsByTagName('body')[0], panellocation); // workaround for IE
		
		//for (var i=0; i<chardata.length; i++) { 
			//copyNodes(chardata[i], panellocation);
			//clnode = chardata[i].cloneNode(true);
			//panellocation.appendChild(clnode);
			//}
		}
	}

function copyNodes (ajaxnode, copiednode) { 
	for (var node=ajaxnode.firstChild; node != null; node = node.nextSibling) {
		if (node.nodeType == 3){ //text
			copiednode.appendChild(document.createTextNode(node.data));
			}
		if (node.nodeType == 1){ //element
			var subnode = document.createElement(node.nodeName);
			var attlist = node.attributes;
			if (attlist != null) {
				for (var i=0; i<attlist.length; i++){ 
					subnode.setAttribute(attlist[i].name, attlist[i].value);
					}
				}
			copiednode.appendChild(subnode);
			copyNodes(node, subnode);
			}
		}
	}

	
function initialise () {
	var examples = document.getElementsByTagName('span'); 
	total = examples.length;
	for (i=0;i<total;i++) { 
		if (examples[i].className == 'ex' ) {
			setOnclick(examples[i]);
			}
		}
	}




window.onload = function() { initialise(); };