// JavaScript Document

window.xhrs = Array();
window.xhrs_count = 0;

function xhrcomplete(text, type, tgt) {
	if (type = "html") {
		e = document.getElementById(tgt);
		e.innerHTML = text;
		window.calendar_loading = false; 
	}
}


function xhr(URL, nocache) {  // ненулевой второй параметр = NO CACHE

	if (nocache) nocache = "";
	else nocache = (URL.indexOf("?")==-1 ? "?" : "&") + "cachekiller="+Math.random()*1e11;

	function createRequestObject()
	{
		if (window.XMLHttpRequest) {
			try {
				return new XMLHttpRequest();
			} catch (e){}
		} else if (window.ActiveXObject) {
			try {
				return new ActiveXObject('Msxml2.XMLHTTP');
			} catch (e){}
			try {
				return new ActiveXObject('Microsoft.XMLHTTP');
			} catch (e){}
		}
		alert('Ваш браузер не поддерживает технологию AJAX');
		return null;
	}

	xhrobject = createRequestObject();
	
	
	if (xhrobject) {
	  xhrobject.open('GET', URL + nocache , true);
	  xhrobject.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	  if (!nocache) {
		  xhrobject.setRequestHeader('Cache-Control', 'cache');
	  }
	  xhrobject.send(null);
	  
	  xhrobject.onreadystatechange = function() {
		  if(xhrobject.readyState == 4) {
			 if (xhrobject.status == 404) alert('Ошибка 404 - Файла не существует');
			 else if(xhrobject.status == 403) alert('Ошибка 403 - Запрещено');
			 else if (xhrobject.status == 200) {
				xhrcomplete(xhrobject.responseText, xhrobject.getResponseHeader('ALPINE-type'), xhrobject.getResponseHeader('ALPINE-target') ); 
			 }
			 xhrobject.onreadystatechange = function() {}
		 	 delete xhrobject;
		  }
	  }
	}
	else alert('Ваш браузер не поддерживает технологию AJAX');
}

