/*
net.READY_STATE_UNINITIALIZED=0;
net.READY_STATE_LOADING=1;
net.READY_STATE_LOADED=2;
net.READY_STATE_INTERACTIVE=3;
net.READY_STATE_COMPLETE=4;
*/

ContentLoader = function(component,url,method){
	this.component = component;
	this.url = url;
	this.method = "GET";//method;
	this.transport = this.getTransport();
}

ContentLoader.prototype = {
	
	getTransport: function(){
		var transport;
		if(window.XMLHttpRequest)
			transport = new XMLHttpRequest();
		else if(window.ActiveXObject){
			try{transport=new ActiveXObject('Msxml.XMLHTTP');}
			catch(err){
				transport = new ActiveXObject('Microsoft.XMLHTTP');
			}
		}
		return transport;
	},
	
	sendRequest: function(requestParams){
		if(this.transport.readyState != 1){
			var qs = this.getRequestString(requestParams);
			this.url += "?"+qs;
			this.transport.open(this.method,this.url,true);
			this.transport.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
			var oThis = this;
			this.transport.onreadystatechange = function(){
				oThis.handleAjaxResponse();
			}
			this.transport.send(null);
		}else{
			alert("Request is busy!");
		}
	},
	
	getRequestString: function(params){
		var alr = false;
		var str = "";
		for(var i in params){
			if(alr)
				str += "&";
			str += i + "=" + params[i];
			alr = true;
		}
		return str;
	},
	
	handleAjaxResponse: function(){
		if(this.transport.readyState == 4){
			if(this.isSuccess()){
				this.component.handleAjaxResponse(this.transport);
			}else{}
		}
	},
	
	isSuccess: function(){
		return this.transport.status == 0 || (this.transport.status >= 200 && this.transport.status < 300);
	}
}