var net = new Object();
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;

//Constructor
net.ContentLoader = function (url,onload,onerror,method,params,contentType,container,statusContainer,returnType,async,extraParams){
	this.async = (async)? true : false;
    this.onload = onload;
    this.onerror = (onerror)? onerror : this.defaultError;
    this.defaultError;
    this.params = params;
    this.data;
    this.status;
    this.error = true;
    this.container = container;
    this.statusContainer = statusContainer;
    this.returnType = (returnType=='XML')? 'XML' : 'TEXT';
    this.extraParams = extraParams;
    this.loadXMLDoc(url,method,params,contentType);
}
net.ContentLoader.prototype.loadXMLDoc = function(url,method,params,contentType){
    if (!method){
        method = 'GET';
    }
    if (!contentType && method=='POST'){
        contentType = 'application/x-www-form-urlencoded';
    }
    if(window.XMLHttpRequest){
        this.req = new XMLHttpRequest();
    }else if(window.ActiveXObject){
        this.req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (this.req){
        try{
            var loader = this;
            this.req.onreadystatechange = function(){
                loader.onReadyState.call(loader);
            }
            this.req.open(method,url,this.async);
            
            if(contentType){
                this.req.setRequestHeader("Content-Type",contentType);
            }
            this.req.send(params);
            if(!this.async){
                loader.onReadyState.call(loader);
            }
        }catch (err){
            this.onerror.call(this);
        }
    }
}
net.ContentLoader.prototype.onReadyState = function(){
    var ready=this.req.readyState;
    if(ready == net.READY_STATE_COMPLETE){
        var httpStatus = this.req.status;
        if (httpStatus==200 || httpStatus==0){
        	this.status = '';
        	if (this.returnType=='TEXT'){
                this.data = this.req.responseText;
            }else{
                this.data = this.req.responseXML;
            }
            this.error = false;
            if(this.async){
                this.onload.call(this);
            }
        }else{
            this.onerror.call(this);
        }
    }else{
        this.status = 'Loading...';
        this.onload.call(this);
    }
}
net.ContentLoader.prototype.defaultError = function(){
        alert('Error loading data!');
}
function getResponse(){
    var oDiv = document.getElementById(this.container);
    var oDivS = document.getElementById(this.statusContainer);
    if(oDivS){
        oDivS.innerHTML = this.status;
    }
    if (oDiv && this.data){
        oDiv.innerHTML = this.data;
    }
}