   var request = false;
   try {
     request = new XMLHttpRequest();
   } catch (trymicrosoft) {
     try {
       request = new ActiveXObject("Msxml2.XMLHTTP");
     } catch (othermicrosoft) {
       try {
         request = new ActiveXObject("Microsoft.XMLHTTP");
       } catch (failed) {
         request = false;
       }  
     }
   }

   if (!request) alert("Error initializing XMLHttpRequest!");


var AjaxOn = false;
function sendRequest(httpMethod,url,httpParams,async,callback,onerror,callbackArgsArray){
	if (AjaxOn==true) return false;
	AjaxOn=true;
	if (!document.getElementById("Loading")) {

	}
	toggle_center_block("Loading", 100, 71);
	var xmlHttpRequest=new (window.XMLHttpRequest||ActiveXObject)("Msxml2.XMLHTTP");
	if (!xmlHttpRequest) throw new Error("Ошибка создания объекта XMLHttpRequest")
	if (async) {
		var timeout = setTimeout( function(){ xmlHttpRequest.abort();}, 10000);
		xmlHttpRequest.onreadystatechange=registreCallbackFunction(xmlHttpRequest,callback,onerror,callbackArgsArray, timeout)
	}
	try{
		if(httpMethod=="get"){
			xmlHttpRequest.open("get",encodeURI(url+"?"+httpParams),async);
		       xmlHttpRequest.send(null);
		} else{
       		xmlHttpRequest.open("post", encodeURI(url+""), async);
	       	xmlHttpRequest.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		       xmlHttpRequest.send(httpParams);
		}
	} catch(e) {
		xmlHttpRequest.onreadystatechange=null;
		if (typeof onerror=="function") onerror.apply(xmlHttpRequest,callbackArgsArray);
		else throw new Error("Ошибка запроса XMLHttpRequest")
	}
	if (!async) {
		if (!xmlHttpRequest.status || xmlHttpRequest.status>=200 && xmlHttpRequest.status<300 || xmlHttpRequest.status == 304) {
			callback.apply(xmlHttpRequest,callbackArgsArray);
		} else {
			if (typeof onerror=="function") onerror.apply(xmlHttpRequest,callbackArgsArray); 
			else throw new Error("Ошибка запроса XMLHttpRequest")
		}
	}
}

function registreCallbackFunction(xmlHttpRequest,callback,onerror,callbackArgsArray, timeout){
	return function(){
		if(xmlHttpRequest.readyState == 4){
			AjaxOn=false;
			clearTimeout(timeout);
			xmlHttpRequest.onreadystatechange = null;	
			if(!xmlHttpRequest.status || xmlHttpRequest.status >= 200 && xmlHttpRequest.status < 300 || xmlHttpRequest.status == 304) {
				toggle_center_block("Loading", 220, 45);
				if (xmlHttpRequest.responseText) {
					if (xmlHttpRequest.responseText=="NOAUTORIZ") {document.location="/index.php?time="+escape('Авторизуйтесь заново, ваше сессия была закрыта из за неактивности на страницы более 10 минут'); return false;}
					callback.apply(xmlHttpRequest,callbackArgsArray);
				}
				else alert("Время ожидания запроса истекло, попробуйте еще раз");
			} else {
				if (typeof onerror == "function") {
					toggle_center_block("Loading", 100, 71);
					onerror.apply(xmlHttpRequest,callbackArgsArray);
				} else throw new Error("Ошибка запроса XMLHttpRequest")    
			}
		}
	};
}

function OnErrorAjax(typeAjax) {
	AjaxOn=false;
	alert("Ошибка загрузки Ajax модуля " + typeAjax);
}

function toggle_center_block(block_id, w, h) {
  f = document.getElementById(block_id);
 
  if (f.style.display == "block") {
    f.style.display = "none";
  } // прячем блок
  else {
    // Для начала узнаем размеры видимой области страницы
    var myWidth = 0, myHeight = 0;
    if (typeof(window.innerWidth) == 'number') {
      // для всего кроме MSIE
      myWidth = window.innerWidth;
      myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
      // IE6+
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
      // IE4
      myWidth = document.body.clientWidth;
      myHeight = document.body.clientHeight;
    }
 
    // Теперь уточняем, насколько страница прокручена вниз и вбок
    var scrOfX = 0, scrOfY = 0;
    if(typeof(window.pageYOffset) == 'number') {
      // Netscape и его родственники
      scrOfY = window.pageYOffset;
      scrOfX = window.pageXOffset;
    } else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
      // DOM
      scrOfY = document.body.scrollTop;
      scrOfX = document.body.scrollLeft;
    } else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
    // IE6
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
 
    // А теперь позиционируем наш блок
    f.style.top = String(Math.round((myHeight - h) / 2) + scrOfY) + 'px';
    f.style.left = String(Math.round((myWidth - w) / 2) + scrOfX) + 'px';
    f.style.width = w + ((3 + 1) * 2);
    f.style.height = h + ((3 + 1) * 2);
    f.style.display = "block";
  } // показываем блок
} // toggle_center_block 


