﻿function AjaxObject(dest, parameters, method, handler) {
	this.dest = '' + dest;
	this.parameters = parameters;
	this.method = (method == 'POST') ? method : 'GET';
	this.handler = handler;

	try {
		this.xmlhttp = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch (e) {
		// browser doesn't support ajax. handle

		this.xmlhttp = false;
	}

	this.request = function() {
		this.xmlhttp.onreadystatechange = this.handler;

		if (this.method == 'POST') {
			this.xmlhttp.open(this.method, this.dest, true);
			this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			this.xmlhttp.setRequestHeader('Charset', 'UTF-8');
			this.xmlhttp.send(this.parameters);
		}
		else {
			this.path = (this.parameters) ? this.dest + this.parameters : this.dest;

			this.xmlhttp.open(this.method, this.path, true);
			this.xmlhttp.send(null);
		}
	};
}

