function xmlhttpPost(strURL,input_form,output_div)
{
	temp=document.getElementById(output_div);
	if (! temp )
	{
		alert('ERROR: \"'+output_div+'\" element not found!');
		return(0);
	}

	var xmlHttpReq = false;
	var self = this;
	// Mozilla/Safari
	if (window.XMLHttpRequest)
	{
		self.xmlHttpReq = new XMLHttpRequest();
	}
	// IE
	else if (window.ActiveXObject)
	{
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}

	if (! self.xmlHttpReq)
	{
		alert ('Unfortunatelly you browser does not support asynchronous loading.');
		return false;
	}

	self.xmlHttpReq.open('POST', strURL, true);
	self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = function()
	{
		if (self.xmlHttpReq.readyState == 4)
		{
			updatepage(output_div , self.xmlHttpReq.responseText);

                        javatest=document.getElementById('java_backend');

/*                        if ( javatest && navigator.appName != 'Netscape' )
                        {
                                eval (javatest.innerHTML);
                        } */
		}
		if (self.xmlHttpReq.readyState == 1)
		{
			updatepage(output_div , '<font color=grey>.. Searching ..</font>');
		}
	}

	self.xmlHttpReq.send( getquerystring( input_form ) );
}

function getquerystring (input_form)
{
	if (! input_form )
	{
		return("");
	}
	var first=0;
	var head="";
	var qstring="";
	var theForm = document.forms[input_form];
	if (! theForm )
	{
		alert('ERROR: \"'+input_form+'\" form not found!');
		return(0);
	}
	for(i=0; i<theForm.elements.length; i++)
	{
		if(first>0)
		{
			head="&";
		} else
		{
			head="";
		}

		if(theForm.elements[i].type == "text" || theForm.elements[i].type == "hidden" || theForm.elements[i].type == "textarea" || theForm.elements[i].type == "button")
		{
			qstring += head + theForm.elements[i].name + '=' + escape(theForm.elements[i].value);
			first++;
		}
		else if(theForm.elements[i].type == "checkbox")
		{
			if(theForm.elements[i].checked)
			{
				qstring += head + theForm.elements[i].name+ "=on";
				first++;
			}
		}
		else if(theForm.elements[i].type == "select-one")
		{
			qstring += head + theForm.elements[i].name + "=" + escape(theForm.elements[i].options[theForm.elements[i].selectedIndex].value);
			first++;
		}
	}
	return qstring;
}

// notice: this fixes IE innerHTML bug and 
// also helps to register new forms inside new div.innerHTML
function updatepage (output_div,str)
{
	container=document.getElementById(output_div);
	if ( container )
	{
		sub=document.getElementById('ajax_sub_'+output_div);
		if ( sub )
		{
			container.removeChild(sub);
		}
		var newdiv = document.createElement('div');
		newdiv.id = 'ajax_sub_'+output_div;
		newdiv.innerHTML = unescape(str);
		container.appendChild(newdiv);

	}else
	{
		alert('ERROR: \"'+output_div+'\" element not found!');
	}
}
