
var httpRequest = createHttpRequest();

var resultId = '';


function createHttpRequest() {

var httpRequest;

var browser = navigator.appName;

if (browser == "Microsoft Internet Explorer") {

httpRequest = new ActiveXObject("Microsoft.XMLHTTP");

} else {

httpRequest = new XMLHttpRequest();

}

return httpRequest;

}

function sendRequest(file, _resultId, getRequestProc) {

resultId = _resultId;

document.getElementById(resultId).innerHTML = '<center><img src=ajax/img/loading.gif></center>';//Подождите, идет загрузка...

httpRequest.open('get', file);

httpRequest.onreadystatechange = getRequestProc;

httpRequest.send(null);

}

function sendRequestTrue(file, _resultId, getRequestProc, _ajaxLoadElem, ajaxLoadPic) 
{
	resultId = _resultId;
	ajaxLoadElem = _ajaxLoadElem;	
	document.getElementById(ajaxLoadElem).innerHTML = '<center><img border="0" src='+ajaxLoadPic+'></center>';
	httpRequest.open('get', file);
	httpRequest.onreadystatechange = getRequestProc;
	httpRequest.send(null);
}

function getRequestTrue() 
{
	if (httpRequest.readyState == 4)
	{
		document.getElementById(ajaxLoadElem).innerHTML = '';
		document.getElementById(resultId).innerHTML = httpRequest.responseText;
	}
}

function sendPostRequest(url, params,_resultId, getRequestProc, _ajaxLoadElem, ajaxLoadPic) {

resultId = _resultId;
ajaxLoadElem = _ajaxLoadElem;

document.getElementById(ajaxLoadElem).innerHTML = '<img border="0" src='+ajaxLoadPic+'>';//Подождите, идет загрузка...

httpRequest.open("POST", url, true);

//Send the proper header information along with the request
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpRequest.setRequestHeader("Content-length", params.length);
httpRequest.setRequestHeader("Connection", "close");

httpRequest.onreadystatechange = getRequestProc;
httpRequest.send(params);

}

function sendRequestExt(file, _resultId, _image, getRequestProc) {

resultId = _resultId;
image=_image;

document.getElementById('flower').innerHTML = '<img src=ajax/img/'+image+'.gif>';//Подождите, идет загрузка...

httpRequest.open('get', file);

httpRequest.onreadystatechange = getRequestProc;



httpRequest.send(null);

}

function sendRequestx(file, _resultId, getRequestProc) {

resultId = _resultId;

document.getElementById('flower').innerHTML = '<img src=ajax/img/flower.gif>';//Подождите, идет загрузка...

httpRequest.open('get', file);

httpRequest.onreadystatechange = getRequestProc;

httpRequest.send(null);

}

function getRequest() {

if (httpRequest.readyState == 4) {

document.getElementById(resultId).innerHTML = httpRequest.responseText;
document.getElementById('flower').innerHTML = '';

}

}


function openmail(mess,page)
{
	if (mess) {mess.className='mess';}
	sendRequestTrue('ajax/getmodal.php?id='+page, 'modal', getRequestTrue, 'modal', 'ajax/img/circle.gif');
	document.getElementById('overlay').style.display='block';
	document.getElementById('overlaymodal').style.display='block';
}
function newmail(mess,page)
{
	if (mess) {mess.className='mess';}
	sendRequestTrue('ajax/sendmodal.php?id='+page, 'modal', getRequestTrue, 'modal', 'ajax/img/circle.gif');
	document.getElementById('overlay').style.display='block';
	document.getElementById('overlaymodal').style.display='block';
}
function closemail()
{
	document.getElementById('overlay').style.display='none';
	document.getElementById('overlaymodal').style.display='none';
}
function sent()
{
	notice("Сообщение отправлено","good");
}

function notice(mess,type)
{
	if (httpRequest.readyState != 1 && httpRequest.readyState != 2 && httpRequest.readyState != 3)
	{
		var notice=document.createElement('div');
		notice.className=type;
		notice.innerHTML=mess;
		closemail();
		n=document.getElementById('notice');
		n.appendChild(notice);
		setTimeout(function(){hide(notice,1);}, 3000);
	}
}
function hide(notice,i)
{
	notice.style.marginTop="-"+(i)+"px";
	if (i<(notice.clientHeight+5))
	{
		setTimeout(function(){hide(notice,(i+2));}, 20);
	} else 
	{
		document.getElementById('notice').removeChild(notice);
	}
}
function addnotice(obj)
{
}
