var request;
var dest;
var contentDiv;


function stat(n)
{
  switch (n) {
    case 0:
      return "<center><span align=center style='font-family: Tahoma; font-size: 15px; text-decoration: none; color: #666666;'><br><br><img src='i/ajax-loader.gif'><br><br>не инициализирован</span></center>";
    break;
 
    case 1:
      return "<center><span align=center style='font-family: Tahoma; font-size: 15px; text-decoration: none; color: #666666;'><br><br><img src='i/ajax-loader.gif'><br><br>загрузка</span></center>";
    break;

    case 2:
      return "<center><span align=center style='font-family: Tahoma; font-size: 15px; text-decoration: none; color: #666666;'><br><br><img src='i/ajax-loader.gif'><br><br>загружено</span></center>";
	break;

    case 3:
      return "<center><span align=center style='font-family: Tahoma; font-size: 15px; text-decoration: none; color: #666666;'><br><br><img src='i/ajax-loader.gif'><br><br>в процессе...</span></center>";
    break;
 
    case 4: 
      return "<center><span align=center style='font-family: Tahoma; font-size: 15px; text-decoration: none; color: #666666;'><br><br><img src='images/ajax-loader.gif'><br><br>готово</span></center>";
    break;
 
    default:
      return "<center><span align=center style='font-family: Tahoma; font-size: 15px; text-decoration: none; color: #666666;'><br><br>неизвестное состояние<br><br></span></center>";
  } 
}

function processStateChange(){
  contentDiv = document.getElementById(dest);
  contentDiv.innerHTML = stat(request.readyState);
  if (request.readyState == 4){
    if (request.status == 200){
		response = request.responseText;
		contentDiv.innerHTML = response;
    } else {
		contentDiv.innerHTML = "Ошибка загрузки: Статус "+request.status;
    }
  }
}

function loadHTML(url, destination, stat){
    dest = destination;
    request = null;
    if (window.XMLHttpRequest) {
        try {
            request = new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            request = new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){
            try {
                request = new ActiveXObject('Microsoft.XMLHTTP');
            } catch (e){}
        }
    }

    if (request) {
        request.onreadystatechange = processStateChange;
        request.open("GET", url, true);
        request.send(null);
    } else {
        alert("Ваш браузер не поддерживает JavaScript");
    }
}

function myAjax (URL, destination) {
	blockdiv(destination);
    contentDiv = document.getElementById(destination);
   	loadHTML(URL, destination, 1);
	window.scroll(0,0);
}


