
function AjaxPost(cgi,id,date,stop,timeout) {
//cgi - серверный скрипт типа http://server/cgi-bin/test.cgi
//id - метка контейнера id
//date - данные
//stop - фраза в тексте ответа сервера, по которой прекращается setTimeout
//timeout - интервал. Если не указан, то 3000 мсек
//alert('cgi='+cgi+' id='+id+' date='+date+' stop'+stop);
//alert('id='+id);
if (window.XMLHttpRequest) {
	req = new XMLHttpRequest();
	req.onreadystatechange = function(){
		if (req.readyState == 4) {
		var text=req.responseText;
		var j=text.indexOf(':');
		var id=text.substring(0,j);
		if(!id){id='info'}
var txt=text.substring(j+1,text.length);

txt=unescape(txt);
//
		document.getElementById(id).innerHTML=txt;
	//******* demon *************
		if(stop){
			if(!timeout){timeout=3000}
			if(text.indexOf(stop)>=0){
					alert('В файле найдена конечная строка ('+stop+')\nскрипт ajaxpost.js закончил работу');
					return;
					}
				setTimeout(
					function(){
						var r=Math.round(Math.random() * (100));
						AjaxPost(cgi,id,date+'&'+r,stop,timeout);
					},timeout);
		}
	//*******************************
		}
	};
	req.open("POST", cgi, true);
	req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	req.send('id='+id+'&'+date);
//	req.open("GET", cgi+'?id='+id+'&'+date, true);
//	req.send(null);

    } else if (window.ActiveXObject) {
	alert('window.ActiveXObject');
	req = new ActiveXObject("Microsoft.XMLHTTP");
	if (req) {
	req.onreadystatechange = Req;
	req.open("POST", cgi, true);
	req.setRequestHeader ("Content-Type", "application/x-www-form-urlencoded");
	req.send('id='+id+'&'+date);
        }
    }
}


