function GetXmlHttpObject () {
	var oXmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		oXmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			oXmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				oXmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				alert("Your browser does not support AJAX!");
				oXmlHttp=null;
			}
		}
	}
	return ( oXmlHttp );
}

function post_form_via_ajax_from_element ( tApplicationName, tEvent, tElementName, tURL, oForm, oAJAXLoadingImage, tAJAXLoadingImage, oCallBack ) {
	var oXmlRequest=GetXmlHttpObject();
	
	if ( oXmlRequest ) {
		oXmlRequest.onreadystatechange=function() {
			if ( oXmlRequest.readyState == 4 ) {
				eval(oXmlRequest.responseText);
				delete oXmlRequest;
				oAJAXLoadingImage.innerHTML='&nbsp;';
			}
		}
		oAJAXLoadingImage.innerHTML='<img src="' + tAJAXLoadingImage + '" />';
		oXmlRequest.open("POST",tURL,true);
		oXmlRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		oXmlRequest.send('APP=' + tApplicationName + '&AJAX_EVENT=' + tEvent + '&AJAX_ELEMENT=' + tElementName + '&' + form_data_to_query_string(oForm));
	}
}

function post_form_via_ajax ( tApplicationName, tURL, oForm, oCallBack ) {
	var oXmlRequest=GetXmlHttpObject();
	
	if ( oXmlRequest ) {
		oXmlRequest.onreadystatechange=function() {
			if ( oXmlRequest.readyState == 4 ) {
				eval(oXmlRequest.responseText);
				delete oXmlRequest;
			}
		}
		oXmlRequest.open("POST",tURL,true);
		oXmlRequest.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		oXmlRequest.send('APP=' + tApplicationName + '&AJAX_EVENT=post_form&' + form_data_to_query_string(oForm));
	}
}

function form_data_to_query_string ( oForm ) {
	var oElement, tReturn="", i;

	for ( i=0; i < oForm.elements.length; i ++ ) {
		oElement=oForm.elements[i];
		switch ( oElement.type ) {
			// button
			case 'checkbox':
				if ( oElement.checked )
					tReturn += oElement.name + '=true' + '&';
				else
					tReturn += oElement.name + '=false' + '&';
				break;
			case 'text':
			case 'select-one':
			case 'hidden':
			case 'password':
			case 'textarea':
				tReturn += oElement.name + '=' + escape(oElement.value) + '&';
				break;
		}
	}

	return ( tReturn );
}
