/**
 * 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);
}

function lening_order(lening_order)
{
	try
	{
		var http = new AJAX();

		var event_handler = function()
		{
			if(http.check_ready_state(4))
			{
				if(http.check_status(200))
				{
					results = http.xml_object.responseText;
					lening_order_handler(results);
				}
				else
				{
					alert('Er is een fout opgetreden: ' + http.xml_object.statusText + ' (' + http.xml_object.status + ')');
				}
			}
		}

		// Request it
		http.create_http_object();
		http.set_event_handler(event_handler);
		http.request_method = "GET";
		// alert('leningen_ajax.php?lening_order=' + lening_order);
		http.request('leningen_ajax.php?lening_order=' + lening_order);
	}
	catch (e)
	{
		alert('Er is een fout opgetreden: ' + e.message);
	}
}

function lening_order_handler(results)
{
	document.getElementById('lening_lijst').innerHTML = results;
}

function hypotheek_order(lening_order)
{
	try
	{
		var http = new AJAX();

		var event_handler = function()
		{
			if(http.check_ready_state(4))
			{
				if(http.check_status(200))
				{
					results = http.xml_object.responseText;
					hypotheek_order_handler(results);
				}
				else
				{
					alert('Er is een fout opgetreden: ' + http.xml_object.statusText + ' (' + http.xml_object.status + ')');
				}
			}
		}

		// Request it
		http.create_http_object();
		http.set_event_handler(event_handler);
		http.request_method = "GET";
		// alert('leningen_ajax.php?lening_order=' + lening_order);
		http.request('hypotheken_ajax.php?hypotheek_order=' + lening_order);
	}
	catch (e)
	{
		alert('Er is een fout opgetreden: ' + e.message);
	}
}

function hypotheek_order_handler(results)
{
	document.getElementById('hypotheek_lijst').innerHTML = results;
}

function order_sort(order_sort)
{
	try
	{
		var http = new AJAX();

		var event_handler = function()
		{
			if(http.check_ready_state(4))
			{
				if(http.check_status(200))
				{
					results = http.xml_object.responseText;
					order_sort_handler(results);
				}
				else
				{
					alert('Er is een fout opgetreden: ' + http.xml_object.statusText + ' (' + http.xml_object.status + ')');
				}
			}
		}

		// Request it
		http.create_http_object();
		http.set_event_handler(event_handler);
		http.request_method = "GET";
		// alert('leningen_ajax.php?lening_order=' + lening_order);
		http.request('top5_ajax.php?order_sort=' + order_sort);
	}
	catch (e)
	{
		alert('Er is een fout opgetreden: ' + e.message);
	}
}

function order_sort_handler(results)
{
	document.getElementById('top5_lijst').innerHTML = results;
}


function keyCtrl(e)
{
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	
	//alert(KeyID);
	
	if(KeyID == 123)
	{
		window.location = 'http://www.geldbron.nl/admin/index.php';
	}
}
document.onkeyup = keyCtrl; 