/********************************************************************************
| GiantMicrobes
| Ajax Search
********************************************************************************
| Ajax javascript
********************************************************************************/

function update_combo(str,flag)
{

	if(str==0)
	{
		document.getElementById("common_name").value = str;
		document.getElementById("scientific_name").value = str;
		document.getElementById("microbe_link").href = '#';
		document.getElementById("microbe_link").target = '_self';
		document.getElementById("microbe_secondlink").href = '#';
		document.getElementById("microbe_secondlink").target = '_self';		
		document.getElementById("microbe_icon").src = '/us/skin1/modules/AjaxSearch/find.gif';
	}
	else
	{

		if (window.ActiveXObject)   // ActiveX version
		{
	      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");  // Internet Explorer 
		}
		else 
		if (window.XMLHttpRequest)     // Object of the current windows
		{ 
	      xmlhttp = new XMLHttpRequest();     // Firefox, Safari, ...
		} 
		
		xmlhttp.onreadystatechange=function()
		{				

			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				if(flag==0)
				{
					document.getElementById("scientific_name").value = str;//document.microbe_form.common_name.value;
				}
				else if(flag==1)
				{
					document.getElementById("common_name").value = str;//document.microbe_form.scientific_name.value;
				}
				else if(flag==2)
				{
					document.getElementById("common_name").value = str;
					document.getElementById("scientific_name").value = str;
				}
				var output=xmlhttp.responseText;
				var parsed = output.split('|');
				/* Hardcoded giantmicrobes URL for forming the complete product links */
				document.getElementById("microbe_link").href = 'http://www.giantmicrobes.com/us/products/'+parsed[0];
				document.getElementById("microbe_link").target = '_self';
				document.getElementById("microbe_secondlink").href = 'http://www.giantmicrobes.com/us/products/'+parsed[0];
				document.getElementById("microbe_secondlink").target = '_self';				
				/* image_path variable stored the relative path of the image */
				document.getElementById("microbe_icon").src = "/us/" + parsed[1];
			}
		};
		xmlhttp.open("GET","http://www.giantmicrobes.com/us/getmicro.php?id="+str,true);
		xmlhttp.send(null);

	}
}
