function ajaxLoader(URL, destination, loading_id){
	this.request = false;
	this.destination = destination;
  	this.loading_id = loading_id;
	this.contentDiv = false;
  	this.loadingDiv = false;
	this.url = URL;
}

ajaxLoader.prototype.processStateChange = function(){
  if (this.request.readyState == 4)
  {
    if (this.request.status == 200)
    {
	    response = this.request.responseText;

    	if(this.loadingDiv)
    		this.loadingDiv.style.display = 'none';
		
	    this.contentDiv.innerHTML = response;
	    //извлекаем скрипт, если есть

	var script = this.contentDiv.getElementsByTagName('SCRIPT');
    	for(var i in script)
    	{
    		if(script[i].nodeName == 'SCRIPT')
	    	{
	    		eval(script[i].innerHTML);
	    	}
    	}

    } else {
		this.contentDiv.innerHTML = "Error: Status "+this.request.status;
    }
  }
}

ajaxLoader.prototype.loadModule = function (ext_get_param){

  if(!this.contentDiv)
  {
  	this.contentDiv = document.getElementById(this.destination);
  	this.contentDiv.style.display = 'block';
  }

  this.contentDiv.innerHTML = '';

  if(this.loading_id)
  	this.loadingDiv = document.getElementById(this.loading_id);
  
  if(this.loadingDiv)
  	this.loadingDiv.style.display = 'block';
  
  if(ext_get_param)
  	  this.url += '&'+ext_get_param;

  var obj = {global_obj : this};

  if (window.XMLHttpRequest)
  {
	this.request = new XMLHttpRequest();
	this.request.onreadystatechange = function () {obj.global_obj.processStateChange()};
	this.request.open("GET", this.url, true);
	this.request.send(null);
  } 
  else if (window.ActiveXObject)
  {
    this.request = new ActiveXObject("Microsoft.XMLHTTP");
    if (this.request) {
	this.request.onreadystatechange = function () {obj.global_obj.processStateChange()};
	this.request.open("GET", this.url, true);
	this.request.send();
    }
  }

return false;
}
