/**
 * Find My Picture
 * De enige party foto zoekmachine in nederland!
 *
 * Gemaakt door Lucas van Dijk (http://www.lucasvd.nl)
 *
 * AJAX Class, gemaakt door Lucas van Dijk
 */

function AJAX()
{
	this.xml_object = null;
	this.request_method = "GET";
	this.post_values = new Array();
}

AJAX.prototype.create_http_object = function()
{
    var ActiveXTypes = [
        "Microsoft.XMLHTTP",
        "MSXML2.XMLHTTP.5.0",
        "MSXML2.XMLHTTP.4.0",
        "MSXML2.XMLHTTP.3.0",
        "MSXML2.XMLHTTP"
    ];

    for( var i = 0; i < ActiveXTypes.length; i++ )
    {
        try
        {
            this.xml_object = new ActiveXObject( ActiveXTypes[i] );
			return;
        }
        catch( e )
        { }
    }

    try
    {
        this.xml_object = new XMLHttpRequest();
		return;
    }
    catch( e )
    { }
	
    throw Error('Could not create XML Object');
}

AJAX.prototype.request = function(url)
{
	if(!this.xml_object)
	{
		throw Error('XML Object not defined');
	}

	this.request_method = this.request_method == "POST" ? "POST" : "GET";	

	this.xml_object.open(this.request_method, url, true);
	
	var post_string = '';
	if(this.request_method == "POST")
	{
		this.xml_object.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		
		for(var name in this.post_values)
		{
			post_string += name + "=" + escape(this.post_values[name]) + "&";
		}
	}

	this.xml_object.send(post_string);
}

AJAX.prototype.set_event_handler = function(event_handler)
{
	if(!this.xml_object)
	{
		throw Error('XML Object not initialized.');
	}

	if(typeof event_handler == "function")
	{
		this.xml_object.onreadystatechange = event_handler;
	}
}

AJAX.prototype.check_status = function(status)
{
	return this.xml_object.status == status;
}

AJAX.prototype.check_ready_state = function(ready_state)
{
	return this.xml_object.readyState == ready_state;
}

AJAX.prototype.json_decode = function(data)
{
	return eval(data);
}






