/********************************************
<body onload="ajax_page('URL', 'POST', 'DIV_NAME', 'POST_DATA')">
POST_DATA is formatted the same as GET is in a URL

********************************************/

function ajax_init()
{
	   var ajax_object;
	   var msie_req_type = new Array(
			   'Msxml2.XMLHTTP.5.0',
			   'Msxml2.XMLHTTP.4.0',
			   'Msxml2.XMLHTTP.3.0',
			   'Msxml2.XMLHTTP',
			   'Microsoft.XMLHTTP'
	   );
	   for (var i = 0; i < msie_req_type.length; i++)
	   {
			   try
			   {
					   ajax_object = new ActiveXObject(msie_req_type[i]);
			   }
			   catch (e)
			   {
					   ajax_object = null;
			   }
	   }

	   if(!ajax_object && typeof XMLHttpRequest != 'undefined')
	   {
			   ajax_object = new XMLHttpRequest();
	   }
	   return ajax_object;
}

function findObj(objId)
{
	   var element = objId;
	   if (document.getElementById)
	   {
			   element = document.getElementById(objId);
	   }
	   else if (document.all)
	   {
			   element = document.all[objId];
	   }
	   else if (document.layers)
	   {
			   element = document.layers[objId];
	   }
	   return element;
}

function ajax_page(url, type, objId, post_data)
{
	   var xmlHttpReq = ajax_init();
	   var defType = 'GET';

	   // Make sure the type is defined
	   if(type != 'POST' && type != 'GET')
	   {
			   if ( type == 'get' )
			   {
					   var type = 'GET';
			   }
			   else if ( type == 'post' )
			   {
					   var type = 'POST';
			   }
			   else
			   {
					   var type = defType;
			   }
	   }

//	  // Fill the element with a loading message
	   findObj(objId).innerHTML = '<span class="gensmall">Loading...</span>';

	   // Open the request and set the header
	   xmlHttpReq.open(type, url, true);

	   // Change the element
	   xmlHttpReq.onreadystatechange = function()
	   {
			   if (xmlHttpReq.readyState == 4)
			   {
					   findObj(objId).innerHTML = xmlHttpReq.responseText;
			   }
	   }

	   // Send the post data
	   if(type == 'POST')
	   {
			   xmlHttpReq.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
			   xmlHttpReq.send(post_data);
	   }
	   else
	   {
			   xmlHttpReq.send(null);
	   }

	   delete xmlHttpReq;
}

function ajax_post(url, objId, post_data, submit)
{
	   var xmlHttpReq = ajax_init();
	   if(post_data)
	   {
			   var type = 'POST';
	   }
	   else
	   {
			   var type = 'GET';
	   }
	   xmlHttpReq.open(type, url, true);
	   xmlHttpReq.onreadystatechange = function()
	   {
			   if (xmlHttpReq.readyState == 4)
			   {
					   findObj(objId).innerHTML = xmlHttpReq.responseText;
					   submit.disabled = false;
			   }
	   }
	   if(type == 'POST')
	   {
			   xmlHttpReq.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
			   xmlHttpReq.send(post_data);
	   }
	   else
	   {
			   xmlHttpReq.send(null);
	   }
	   delete xmlHttpReq;
}

function ajax_page_s(url, objId)
{
	   var xmlHttpReq = ajax_init();
	   xmlHttpReq.open('GET', url, true);
	   xmlHttpReq.onreadystatechange = function()
	   {
			   if (xmlHttpReq.readyState == 4)
			   {
					   findObj(objId).innerHTML = xmlHttpReq.responseText;
			   }
	   }
	   xmlHttpReq.send(null);
	   delete xmlHttpReq;
}
function form_submit(span)
{
	ajax_page( document.forms.ajaxform.action,
	document.forms.ajaxform.method, span, 'field=' +
	escape(document.forms.ajaxform.field.value) );
	return false;
}