function Ajax(url, method) {
	if(url.length == 0) {
		throw "Invalid URL";	
	}
	
	this.url           = url;
	this.CallBack      = undefined;
	this.OpenPost      = OpenPost;
	this.OpenGet       = OpenGet;
	this.connection    = undefined;
	this.Send          = Send;
	this.SetConnection = SetConnection;
	
	this.SetConnection();
	
	if(method == "post") {
		this.OpenPost();	
	}
	
	else {
		this.OpenGet();	
	}
}

function Send(data) {
	if(!this.CallBack) {
		throw("You must create a callback function before you can send data.");	
	}
	
	if(!this.connection) {
		throw("Not connected");	
	}
	
	this.connection.onreadystatechange = this.CallBack;
	
	this.connection.send(data);
}

function SetConnection() {
	try {
		if(window.XMLHttpRequest) {
			this.connection = new XMLHttpRequest();
		}
		
		else if(window.ActiveXObject) {
			this.connection = new ActiveXObject("Microsoft.XMLHTTP");
		}
		
		else {
			throw("Error Creating XMLHttpRequest Object: The object could not be found.");
		}
	} catch(e) {
		throw(e);
	}
}

function OpenPost() {
	if(this.connection == undefined) {
		throw("You must first create the connection object.");	
	}
	
	var connection = this.connection;
	
	connection.open("POST", this.url, true);
	connection.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}

function OpenGet() {
	if(this.connection == undefined) {
		throw("You must first create the connection object.");	
	}
	
	this.connection.open("GET", this.url, true);
}
