function getHTTPRequestObject(){
    var xmlHttpRequest;
    if (typeof ActiveXObject != 'undefined') {
        xmlHttpRequest = new ActiveXObject('Microsoft.XMLHTTP');
    } else if (typeof XMLHttpRequest != 'undefined') {
            xmlHttpRequest = new XMLHttpRequest();
           } else {
                xmlHttpRequest = false;
              }
    return xmlHttpRequest;
}


var ajaxRequest = getHTTPRequestObject();
ajaxRequest.onreadystatechange=onReadyStateChange;

if (ajaxRequest==false){
    alert('Ваш браузер не поддерживает технологию AJAX. Для удобной навигации по сайту используйте AJAX-совместимый браузер (IE от 6.0, Firefox 1.5.x и др.)')
}

function onReadyStateChange(){
    if (ajaxRequest.readyState==4){
	if (ajaxRequest.status==200){
	    var res = ajaxRequest.responseText.split('|');
	    current_x=parseInt(res[3]);
	    current_y=parseInt(res[2]);
	    total_x=parseInt(res[0]);
	    total_y=parseInt(res[1]);
	    hx=parseInt(res[4]);
	    hy=parseInt(res[5]);
	    pics_base_url=res[6];
	    current_scale=new_scale;
	    cacheImages();
	    for (i=1; i<=rows_y; i++){
		for (j=1; j<=rows_x; j++){
		    getElement('map'+i+'x'+j).src=pics_base_url+'image'+(current_y+i-1)+'x'+(current_x+j-1)+'.jpg';
		}
	    }
	    scaleUpdate();
	    fixhouse();
	}else alert('Ошибка при запросе данных с сервера. Обратитесь к администратору сайта. Подробности: status='+ajaxRequest.status);
	ajaxRequest.abort();
    }
}

function mapReDraw(){
    ajaxRequest.open('GET','/map.html?middle_x='+middle_x+'&middle_y='+middle_y+'&scale='+current_scale+'&new_scale='+new_scale+'&ajax=true&house='+houseId);
    ajaxRequest.onreadystatechange=onReadyStateChange;
    ajaxRequest.send(null);
    return false;
}

function getElement(id){
    return document.getElementById(id);
}

function scaleUpdate(){
    if (current_scale == 150) getElement("moreBtn").style.display = 'none'; else getElement("moreBtn").style.display = '';
    if (current_scale == 10) getElement("lessBtn").style.display = 'none';  else getElement("lessBtn").style.display = '';
    getElement('scale').innerHTML=current_scale+' %';
}

