function submitSnap()
{
	var element=document.getElementById("snapId");
	var id=element.value;
	if(id.match(/[^\s]/)==null)
	{
		alert("Please enter a SwissProt Id.");
		return;
	}
	element=document.getElementById("snapMutant");
	var mutant=element.value;
	if(mutant.match(/[^\s]/)==null)
	{
		alert("Please enter a mutant.");
		return;
	}
	var url="snpfun_search.test.php?id=" + id + "&mutant=" + mutant;
	var img=document.createElement("img");
	img.setAttribute("src", "processing.gif");
	var container=document.getElementById("snapResults");
	removeChildren(container);
	container.appendChild(img);
	jQuery.get(url, function(data) { submitSnapCb(data) });
}

function submitSnapCb(data)
{
	var json=eval("(" + data + ")");
	var container=document.getElementById("snapResults");
	removeChildren(container);
	if(json.mutants[0]!=undefined)
	{
		var table=document.createElement("table");
		var row=document.createElement("tr");
		var cell=document.createElement("td");
		cell.setAttribute("class", "snapResults");
		cell.appendChild(document.createTextNode("Mutation"));
		row.appendChild(cell);
		cell=document.createElement("td");
		cell.setAttribute("class", "snapResults");
		cell.appendChild(document.createTextNode("Prediction"));
		cell.setAttribute("class", "snapResults");
		row.appendChild(cell);
		cell=document.createElement("td");
		cell.setAttribute("class", "snapResults");
		cell.appendChild(document.createTextNode("Reliability"));
		row.appendChild(cell);
		cell=document.createElement("td");
		cell.setAttribute("class", "snapResults");
		cell.appendChild(document.createTextNode("Expected Accuracy"));
		row.appendChild(cell);
		cell=document.createElement("td");
		cell.setAttribute("class", "snapResults");
		cell.appendChild(document.createTextNode("Function"));
		row.appendChild(cell);
		table.appendChild(row);
		var mutants=json.mutants;
		var i=0;
		while(i<mutants.length)
		{
			row=document.createElement("tr");
			cell=document.createElement("td");
			cell.setAttribute("class", "snapResults");
			cell.appendChild(document.createTextNode(mutants[i].mutant));
			row.appendChild(cell);
			cell=document.createElement("td");
			cell.setAttribute("class", "snapResults");
			cell.appendChild(document.createTextNode(mutants[i].prediction));
			row.appendChild(cell);
			cell=document.createElement("td");
			cell.setAttribute("class", "snapResults");
			cell.appendChild(document.createTextNode(mutants[i].reliability));
			row.appendChild(cell);
			cell=document.createElement("td");
			cell.setAttribute("class", "snapResults");
			cell.appendChild(document.createTextNode(mutants[i].accuracy));
			row.appendChild(cell);
			cell=document.createElement("td");
			cell.setAttribute("class", "snapResults");
			var funcs=mutants[i].func;
			var j=0;
			while(j<funcs.length)
			{
				var link=document.createElement("a");
				link.setAttribute("href", "http://spock.genes.nig.ac.jp/~pmd/cgi-bin/PMD/PMDentry.pl.cgi?" + funcs[j].accession);
				link.setAttribute("target", "_blank");
				link.appendChild(document.createTextNode(funcs[j].func));
				cell.appendChild(link);
				cell.appendChild(document.createTextNode(" "));
				j++;
			}
			row.appendChild(cell);
			table.appendChild(row);
			i++;
		}
		container.appendChild(table);
	}
	else
	{
		container.appendChild(document.createTextNode("No matches found."));
	}
}

function removeChildren(element)
{
	while(element.firstChild!=undefined)
	{
		element.removeChild(element.firstChild);
	}
}
