/*
	Square Circle Triangle
	Author: 	Ben Schwarz
	Purpose: 	AJAX without ajax; Make a call to the server for Json or XML, returned to your callback function without having to evaluate (eval();) it (fast!)
	Usage: 		new DataStore('myURL', 'myFunction');
				myFunction = function (response) {
					// Response from the server (JSON, usually)
				}
*/

DataStore = function (url, callback) {
	this._init(url, callback);
}
DataStore.prototype = {
	url: null,
	callback: null,
	
	// Init
	_init: function (url, callback) {
		this.url = url;
		this.callback = callback;
		
		if(callback) {
			this._request();
		} else {
			throw("No callback has been provided")
		}
	},
	// Make call
	_request: function () {
		var request_url = this.url + '&noCache=' + new Date().getTime();
		if(this.callback) {
			request_url += '&callback='+this.callback;
		}
		var script = document.createElement('script');
		script.setAttribute('src', request_url);
		script.setAttribute('type', 'text/javascript');
		
		// Append to DOM
		document.documentElement.getElementsByTagName('head')[0].appendChild(script);
	}
};
