
function getHTTPRequestObject() {
	var xmlHttpRequest;
	/*@cc_on
	@if (@_jscript_version >= 5)
	try {
		xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (exception1) {
		try {
			xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (exception2) {
			xmlHttpRequest = false;
		}
	}
	@else
		xmlhttpRequest = false;
	@end @*/
	
	if (!xmlHttpRequest && typeof XMLHttpRequest != 'undefined') {
		try {
			xmlHttpRequest = new XMLHttpRequest();
		} catch (exception) {
			xmlHttpRequest = false;
		}
	}
	return xmlHttpRequest;
}
 
var httpRequester = getHTTPRequestObject(); /* Когда страница загрузилась, создаем xml http объект */

var couldProcess = false;
var id;
var curr_id = 0;;
var too_hot = false;

function displayMessageBody(serverSideURL, id) {
	
	this.id = id;
	
	document.getElementById(id).innerHTML += '<div class="wait" id="wait' + id + '"><h2>Подождите</h2>	<div style="background-color: #ccc; width: 89px; height: 30px; overflow: visible !important; overflow:hidden; margin: 0 auto;">	<img style="filter:expression(fixPNG(this))" src="./images/wait_animated.gif" style="margin: 0 !important; margin: -10px -33px -10px -29px; " alt="Заружается..." /></div></div>';
	
	idToDisplay = id;
	if (!couldProcess && httpRequester) {
		
		httpRequester.open("GET", serverSideURL + '?id=' + escape(id), true);
		httpRequester.onreadystatechange = processResponse;
		couldProcess = true;
		httpRequester.send(null);
	}

}

function displayHotMessage(serverSideURL, id) {
	alert();
	idToDisplay = id;
	this.id = 'hot';
	
	if (!couldProcess && httpRequester) {
		
		httpRequester.open("GET", serverSideURL + '?id=' + escape(id), true);
		httpRequester.onreadystatechange = processResponse;
		couldProcess = true;
		httpRequester.send(null);
	}
	too_hot = true;
}

function changeImage(dir) {
	
	this.id = 'ajax_foto_dnya';
	idToDisplay = this.curr_id + dir;
	
	if (!couldProcess && httpRequester){
		
		httpRequester.open("GET", serverSideURL + '?id=' + escape(idToDisplay), true);
		httpRequester.onreadystatechange = processResponse;
		couldProcess = true;
		httpRequester.send(null);
	}
	
}

function changeReadToday(dir, num) {
	
	//alert('ajax_read' + num);
	this.curr_id = parseInt(document.getElementById('ajax_read' + num).getElementsByTagName('div')[0].id);
	this.id = 'ajax_read' + num;
	
	idToDisplay = parseInt(this.curr_id) + parseInt(dir)*5 + Math.round(Math.random()*200);
	if(isNaN(idToDisplay) || isNaN(this.curr_id)) idToDisplay = Math.round(Math.random()*1500);
	var cat_id;
	if		(num == 1) cat_id = 19;
	else if	(num == 2) cat_id = 26;
	else if	(num == 3) cat_id = 27;
	
	if (!couldProcess && httpRequester){
		httpRequester.open("GET", '/ajax/read_today.php' + '?id=' + escape(idToDisplay) + "&cat_id=" + escape(cat_id) + "&num=" + escape(num), true);
		httpRequester.onreadystatechange = processResponse;
		couldProcess = true;
		httpRequester.send(null);
	}
	
}

function displayHot(serverSideURL) {
	this.id = 'hot';
	
	idToDisplay = Math.round(Math.random()*10);
	if (!couldProcess && httpRequester) {
		
		httpRequester.open("GET", serverSideURL + '?id=' + escape(idToDisplay), true);
		httpRequester.onreadystatechange = processResponse;
		couldProcess = true;
		httpRequester.send(null);
	}
	
}

function processResponse() {
	
	if ( httpRequester.readyState == 4 ) {
		var value = httpRequester.responseText; //анализируем ответ сервера
		
		document.getElementById(id).innerHTML = value; //выбираем значение текущее сообщение
		couldProcess = false;
	}
	else {		
	}
}

function fixPNG(element)
{
	//Если браузер IE версии 5.5-6
	if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
		var src;
		
		if (element.tagName == 'IMG') {
			if (/\.png$/.test(element.src)) {
				src = element.src;
				element.src = "images/spacer.gif";
			}
		} else {
			src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
			if (src){
				src = src[1];
				element.runtimeStyle.backgroundImage="none";
			}
		}
		if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
	}
}