//Created and developed by jj
//kamil.surowka@gmail.com

HttpRequest.prototype.xhttp = null;
function HttpRequest() {
	if (window.XMLHttpRequest){
		this.xhttp=new XMLHttpRequest();

	}else{
		this.xhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

};

HttpRequest.prototype.getDoc = function () {
	return this.xmlDoc;
};

HttpRequest.prototype.sendRequest = function (link,method,type) {
	this.xhttp.open(method,link,false);
	this.xhttp.setRequestHeader('HTTP_X_REQUESTED_WITH','XMLHttpRequest');
	this.xhttp.send("");
	if(type == undefined){
		this.actualDoc = this.xhttp.responseText;
	}else{
		this.actualDoc = this.xhttp.responseXML;
	}
	return this.actualDoc;
};

HttpRequest.prototype.sendRequestData = function (link,data,method,type) {
	this.xhttp.open(method,link,false);
	this.xhttp.send(data);
	if(type == undefined){
		this.actualDoc = this.xhttp.responseText;
	}else{
		this.actualDoc = this.xhttp.responseXML;
	}
	return this.actualDoc;
};

HttpRequest.prototype.close = function () {
	this.xhttp.abort();
	this.xhttp = null;
};

DjangoModelJSON.prototype.data = null;

function DjangoModelJSON(obj_type,query_str,fun) {
	if(fun != undefined){
		this.reqFun = fun;
	}
	this.obj_type = obj_type;
	this.query_str = query_str;
	this.ajax_get_object();
	
};
DjangoModelJSON.prototype.ajax_get_object = function (){
	
	$.getJSON("/ajax/object/?model="+this.obj_type+'&'+this.query_str,this.reqFun);
	
};
DjangoModelJSON.prototype.reqFun = function(data,textStatus) {

	this.data = data;
};

