
function getxmlhttp ()
{
	var xmlhttp = false;

	try //Check if the browser is IE
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");//If its a modern IE...
	}
	catch (e) //if not check if older xmlhttp will work...
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E)//Non-IE browser
		{
			xmlhttp = false;
		}
	}

	//check if the javascript xmlhttp will work instead
	if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}


//the AJAX bit
function processajax (serverPage, obj, getOrPost, str){

	//Get an XMLHttpRequest object for use.
	xmlhttp = getxmlhttp ();
	if(getOrPost == "get")
	{
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{
				obj.innerHTML = xmlhttp.responseText;
//				begintimer();
			}
		}
		xmlhttp.send(null);
	}
	else
	{
		xmlhttp.open("POST", serverPage, true);
		xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
		xmlhttp.onreadystatechange = function()
		{
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{
				obj.innerHTML = xmlhttp.responseText;
//				begintimer();
			}
		}
		xmlhttp.send(str);
	}
}	


//Functions to submit a form.
var aok;
function getformvalues (fobj)
{
	var str = "";
	var val;
	
	//Run through a list of all objects contained within the form.
	for(var i = 0; i < fobj.elements.length; i++)
	{
		str += fobj.elements[i].name + "=" + escape(fobj.elements[i].value) + "&";
	}
	return str;
}


function submitform(theform, serverPage, objID, getOrPost)
{
	var file = serverPage;
	if(getOrPost == 'post')
	{
		var str = getformvalues(theform);
	}
	obj = document.getElementById(objID);
	processajax(serverPage, obj, getOrPost, str);
}

