function Class_Ajax(){

	var xmlhttp;

	this.ajax_url="http://muz-school.ru/index.php?action=ajax";	



	try {

		this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

	} catch (e) {

		try {

			this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

		} catch (E) {

			this.xmlhttp = false;

		}

	}

	if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {

		this.xmlhttp = new XMLHttpRequest();

	}

	

	this.post=function(req,func){

	    var req_str = this.ajax_url;

    	this.xmlhttp.open('POST', req_str, true);

		showLoader();		

	

		this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); 

    	this.xmlhttp.send(req);	//+"&n="+Math.random()

    	// Timeout 10 seconds

		var timeout = setTimeout(abort, 15000);

		// onreadystage function is replaced on timeout. It works better in IE.

		var timeoutonreadystage = setTimeout(onreadystatechange, 10);

		

		var self=this;

		function abort(){

			self.xmlhttp.abort();

			clearTimeout(timeoutonreadystage);

			hideLoader();

			handleError("Time over"); 

		}

		function onreadystatechange(){ 

			if(self.xmlhttp.readyState != 4) {

				timeoutonreadystage = setTimeout(onreadystatechange, 100);

				return;

			}

			clearTimeout(timeout);

			clearTimeout(timeoutonreadystage);

			hideLoader();
			
			if(self.xmlhttp.status == 200){ 

        		//if(self.xmlhttp.responseText.length>0){

  		    		func(self.xmlhttp.responseText);

        		//} 

    		}

		}

	}

	

	function handleError(message) {

  	  alert("Error: "+message)  

	}

	function showLoader(){

		//var holder=document.getElementById("kladr_content_holder");

		var holder=document.getElementsByTagName('BODY');

		if (holder && typeof holder[0]==="object"){

			var img=document.createElement('IMG');

			img.src="http://muz-school.ru/images/ajax-loader(2).gif";

			img.id="loader";

			img.style.position="absolute";

			img.style.top="20px";

			img.style.left="20px";

			holder[0].appendChild(img);			

		}

	}

	function hideLoader(){

		var img=document.getElementById("loader");

		if (img){

			img.parentNode.removeChild(img);

		}	

	}

}

