
var AjaxRequestObject = {
	create : function Ajax_new_xml_http_request()
	{
		var A = null;

		try {
			A = new ActiveXObject("Msxml2.XMLHTTP");
		} catch( e ) {
			try {
				A = new ActiveXObject("Microsoft.XMLHTTP");
			} catch( oc ) {
				A=null;
			}
		}
		if( !A && typeof XMLHttpRequest != "undefined" ){
			A = new XMLHttpRequest();
		}
		return A;
	}
}

function Ajax( url , method , params , callback )
{
	this.url	= url;
	this.method	= ( method || "post" ).toUpperCase();
	if( this.method != "POST" && this.method != "GET" ) {
		this.method = "GET";
	}
	this.params		= params;
	this.callback	= callback;

	this.xml_req = AjaxRequestObject.create();

	if( ! this.xml_req ) alert( "Your browser does not support the XmlHttpRequest object!" );
}

Ajax.prototype.escape_paramstring = function( paramstring )
{
	var pieces		= paramstring.split("&");
	var newpieces	= new Array();
	for( var i = 0 ; i < pieces.length ; i++ ) {
		var param = pieces[i].split("=");
		newpieces[ newpieces.length ] = escape( param[0] ) + "=" + escape( param[1] );
	}
	return newpieces.join("&");
}

Ajax.prototype.go = function(async)
{
	if(typeof(async) == "undefined")
	{
		async = true;
	}

	this.xml_req.open( this.method , this.url , async );
	if( async ) {
		this.xml_req.onreadystatechange = this.onreadystatechange.bind(this);
	}

	if( this.method == "POST" ) {
			this.xml_req.setRequestHeader( "Content-Type" , "application/x-www-form-urlencoded" );
	}


	this.xml_req.send( this.escape_paramstring( this.params ) );
	if( ! async ) {
		return this.xml_req;
	}
}

Ajax.prototype.onreadystatechange = function()
{
	if( this.xml_req.readyState == 4 ) {
		this.callback( this.xml_req );
	}
}

if(!Function.prototype.bind) {
  Function.prototype.bind = function(object) {
    var __method = this;
    return function() {
      return __method.apply(object, arguments);
    }
  }
}
