var xmlHttp

function getTargetField(link_type)
{
	xmlHttp=GetXmlHttpObject()
	if(xmlHttp==null)
	{
		alert ("Please download a browser that supports AJAX to propertly view this page.")
	}
	
	var url="ajax_link_target.php";
	url=url+"?link_type="+link_type;
	xmlHttp.onreadystatechange=stateChanged_field
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function refreshNewsroom(article_id)
{
	xmlHttp=GetXmlHttpObject()
	if(xmlHttp==null)
	{
		alert ("Please download a browser that supports AJAX to properly view this page.")
	}
	
	var url="ajax_newsroom_refresh.php";
	url=url+"?article_id="+article_id
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function showTech(category_id)
{ 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Please download a browser that supports AJAX to properly view this page.")
		return
	}
	
	var url="ajax_target.php"
	url=url+"?category_id="+category_id
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function doSearch(form_object)
{
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null)
	{
		alert ("Please download a browser that supports AJAX to properly view this page.")
		return
	}
	
	var url="ajax_target.php"
	url=url+getSearchString(form_object)
	xmlHttp.onreadystatechange=stateChanged
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function getSearchString(obj)
{
	var getstr = "?";
	for (i=0; i<obj.getElementsByTagName("input").length; i++)
	{
		if (obj.getElementsByTagName("input")[i].type == "text")
		{
			getstr += obj.getElementsByTagName("input")[i].name + "=" + 
				obj.getElementsByTagName("input")[i].value + "&";
		}
		if (obj.getElementsByTagName("input")[i].type == "checkbox")
		{
			if (obj.getElementsByTagName("input")[i].checked) {
				getstr += obj.getElementsByTagName("input")[i].name + "=" + 
					obj.getElementsByTagName("input")[i].value + "&";
			}
			else
			{
				getstr += obj.getElementsByTagName("input")[i].name + "=&";
			}
		}
		if (obj.getElementsByTagName("input")[i].type == "radio") {
           if (obj.getElementsByTagName("input")[i].checked)
			{
				getstr += obj.getElementsByTagName("input")[i].name + "=" + 
					obj.getElementsByTagName("input")[i].value + "&";
			}
		}
		if (obj.getElementsByTagName("input")[i].tagName == "SELECT")
		{
			var sel = obj.getElementsByTagName("input")[i];
			getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
		}
	}
	
	return(getstr)
}

function stateChanged()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("ajax_output").innerHTML=xmlHttp.responseText;
		target=null;
	} 
}

function stateChanged_field()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("link_field").innerHTML=xmlHttp.responseText;
		target=null;
	} 
}

function stateChanged_ordering()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById("ajax_ordering").innerHTML=xmlHttp.responseText;
	}
}

function stateChanged_variable(id)
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		document.getElementById(id).innerHTML=xmlHttp.responseText;
	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		//Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	
	return xmlHttp;
}