// ajax_common_post.js
var debug_mode = false;
function debug(text) { if( debug_mode ) { alert("RSD: " + text); } }

function create_xmlhttp_object()
{
	debug("create_xmlhttp_object called.");
	var xmlhttp_object
	try	{ xmlhttp_object = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch( e )
	{
		try			{ xmlhttp_object = new ActiveXObject("Microsoft.XMLHTTP"); }
		catch( oc )	{ xmlhttp_object = null; }
	}
	if( !xmlhttp_object && typeof XMLHttpRequest != "undefined" )	{ xmlhttp_object = new XMLHttpRequest(); }
	if( !xmlhttp_object )											{ debug( "create_xmlhttp_object error." ); }
	return xmlhttp_object;
}

function post_form()
{
	var a = post_form.arguments;
	var url	= a[0];
	var paramstring = a[2];

	var x = create_xmlhttp_object();
	x.open("POST", url);
	x.onreadystatechange = function()
	{
		if( x.readyState != 4 ) { return; }

		debug( "received " + x.responseText );

		var status	= x.responseText.charAt(0);
		var data	= x.responseText.substring(2);

		if( status == "-" ) { alert("Error: " + data ); }
		else    			{ a[1]( data ); }
	}
	x.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	x.send(paramstring);

	debug( "post_form url = " + url );
	debug( "post_form waiting.." );
}
