var ImagesOn = 1; // флаг "картинки включены"
var loaded; // page not loaded

var trueLoaded = false;
 
function init() {

		var testDiv =  (document.getElementById('testImageIE')) ? document.getElementById('testImageIE') : document.getElementById('testImage');
		// если не загружена тестовая картинка /images/test.gif
		// т.е. не известна высота div в котором эта картинка
		// считаем, что document.getElementById(rm1)картинки выключены и обнуляем флаг ImagesOn
		// это глобальная переменная, ее можно проверять в дальнейшем
		if (testDiv && testDiv.offsetHeight != 100) {
			ImagesOn = 0;
		}
		if (ImagesOn != 0) {
			preloadMenuImages(); // preload menu_over images
			initbeautyform(); // replace form standard elements
		}  else {
			changeDistrList(); // change district list on city change
		}
			if (typeof(blks)!="undefined") {
				checkblocks(); //mark filled block;
				}
		
			loaded = 1;
			
                            
};

var onLoadFunctions = new Array();

	onLoadFunctions.push(function() { 
		init();
	});
window.onload = function() { 

	for (var i=0; i<onLoadFunctions.length; i++) {
		if (typeof onLoadFunctions[i]=='function') {
			eval('onLoadFunctions['+i+']();');
		}
	}
	onLoadFunctions = null;
                
}


function preloadMenuImages() {
	menupreloads = new Object();
	menupreloads[0] = new Image(); menupreloads[0].src = "/images/about_on.gif";
	menupreloads[1] = new Image(); menupreloads[1].src = "/images/ipoteka_on.gif";
	menupreloads[2] = new Image(); menupreloads[2].src = "/images/searchdb_on.gif";
	menupreloads[3] = new Image(); menupreloads[3].src = "/images/usefulinfo_on.gif";
	menupreloads[4] = new Image(); menupreloads[4].src = "/images/forum_on.gif";
}


function menu(sw, pic, sm, rm1, rm2) {   /* menu button switcher */
	if (pic == '' || sw == '') return;
	var ipic = document.getElementById(pic);
	(sw == 'on' || ipic.className == 'i_one') ? ipic.src = '/images/'+ipic.id+'_on.gif' : ipic.src = '/images/'+ipic.id+'.gif';
	if (sm != '' && document.getElementById(sm).className != 'sm_one') document.getElementById(sm).className = 'sm_'+sw;
	if (rm1 != '' && document.getElementById(rm1).className != 'rm_one') document.getElementById(rm1).className = 'rm_'+sw;
	if (rm2 != '' && document.getElementById(rm2).className != 'rm_one') document.getElementById(rm2).className = 'rm_'+sw;
}

function wnd(w, h, url, n) {
// w - width
// h - height
// url - url
// n - name
	var feat = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=no,status=no,directories=no";
	var newWnd = window.open(url, n, feat).focus();
}


var bl;
var rT = 600;

function ShowFoto(w, h, url, d) {
// w - width
// h - height
// url - url
// d - descr
	var posx = 0; var posy = 0;
	if (!w) var w = 200;
	if (!h) var h = 200;
	if (!d) var d = 'Фото';
	l = 100;
	t = 100;
	if (!document.getElementById('sF')) createLayer('sF','');
	var txt = '<img src="'+url+'" alt="" id="fImg" />';
	document.getElementById('sF').innerHTML = txt;
	if (bl) {w=bl.offsetWidth;h=bl.offsetHeight;}
	bl = dhtmlwindow.open('divbox', 'div', 'sF', d, 'width='+w+'px,height='+h+'px,left='+l+'px,top='+t+'px,resize=0,scrolling=1,,minimize=1');
	if (document.getElementById('fImg').offsetWidth < 30) {
		tryResize();
	} else {
		var sFp = document.getElementById('sF');
		sFp.style.display = 'block';
		sFp.style.position = 'absolute';
		bl.setSize(sFp.offsetWidth+5, sFp.offsetHeight+5);
		sFp.style.display = 'none';
	}
}
function tryResize() {
        rT--;
        var iii = document.getElementById('fImg');
	if (iii.offsetWidth < 30 && (rT > 0 && rT!=600)) {
		tId = window.setTimeout(tryResize, 100);
	} else {
		var sFp = document.getElementById('sF');
		sFp.style.display = 'block';
		sFp.style.position = 'absolute';
		bl.setSize(sFp.offsetWidth+5, sFp.offsetHeight+5);
		sFp.style.display = 'none';
		if (tId) clearTimeout(tId);
		rT = 600;
	}
}



function extendDistrictURL() {  // CHECKBOX
	var params = '';
	var f = document.getElementsByTagName('FORM');
	for (var k=0; k<f.length; k++) {
        	var inpX = f[k].elements;
		for (var i=0; i<inpX.length; i++) {
			if (inpX[i].type == 'checkbox' && inpX[i].name == 'district') {
				if (params == '') params = 'formID='+f[k].id;
				if (inpX[i].checked == true) {
					params += '&district='+inpX[i].value;
				}
			}
		}
	}
	if (document.getElementById('spb-city-map-link')) document.getElementById('spb-city-map-link').href = '/spb-city-map.xml?'+params;
	return true;
}
function extendSelDistrictURL() { // SELECT
	var params = '';
	var f = document.getElementsByTagName('FORM');
	for (var k=0; k<f.length; k++) {
        	var inpX = f[k].elements;
		for (var i=0; i<inpX.length; i++) {
			if (inpX[i].tagName=='SELECT' && inpX[i].name == 'realty_district') {
				if (params == '') params = 'formID='+f[k].id;
				if (inpX[i].options.length >1 && inpX[i].options[inpX[i].selectedIndex] != -1) {
					params += '&realty_district='+inpX[i].options[inpX[i].selectedIndex].value;
				}
				break;
			}
		}
	}
	if (document.getElementById('spb-district-map-link')) document.getElementById('spb-district-map-link').href = '/spb-city-map-add.xml?'+params;
	parseblocks("basicinfo",document.getElementById('inputrealty_district'),"select");
	return true;
}

function checkAll(n,f, name) {
// n - checkbox
// f - form
	name = (name)?name:n.name;
    var inpX = f.elements;
	for (var i=0; i<inpX.length; i++) 
	{
		if (inpX[i].type == 'checkbox' && inpX[i].name == name) 
		{
			inpX[i].checked = n.checked;
		}
	}
	if (n.name == 'metro') extendMetroURL();
	if (n.name == 'district') extendDistrictURL();
}

function extendMetroURL() {
	var params = '';
	var f = document.getElementsByTagName('FORM');
	for (var k=0; k<f.length; k++) {
        	var inpX = f[k].elements;
		for (var i=0; i<inpX.length; i++) {
			if (inpX[i].type == 'checkbox' && inpX[i].name == 'metro') {
				if (params == '') params = 'formID='+f[k].id;
				if (inpX[i].checked == true) {
					params += '&metro='+inpX[i].value;
				}
			}
		}
	}
	if (document.getElementById('spb-metro-map-link')) document.getElementById('spb-metro-map-link').href = '/spb-metro-map.xml?'+params;
	return true;
}
function extendSelMetroURL() {
	var params = '';
	var f = document.getElementsByTagName('FORM');
	for (var k=0; k<f.length; k++) {
        	var inpX = f[k].elements;
		for (var i=0; i<inpX.length; i++) {
			if (inpX[i].tagName=='SELECT' && inpX[i].name == 'realty_metro') {
				if (params == '') params = 'formID='+f[k].id;
				if (inpX[i].options.length >1 && inpX[i].options[inpX[i].selectedIndex] != -1) {
					params += '&realty_metro='+inpX[i].options[inpX[i].selectedIndex].value;
				}
				break;
			}
		}
	}
	if (document.getElementById('spb-metro-map-link')) document.getElementById('spb-metro-map-link').href = '/spb-metro-map-add.xml?'+params;
	if (document.getElementById('inputrealty_metro')) parseblocks("basicinfo",document.getElementById('inputrealty_metro'),"select");
	return true;
}

function checkAllRegCity(n,f) {
// n - checkbox
// f - form
    var inpX = f.elements;
	for (var i=0; i<inpX.length; i++) {
		if (inpX[i].type == 'checkbox' && inpX[i].name == n.name) {
			inpX[i].checked = n.checked;
		}
		if (inpX[i].type == 'checkbox' && inpX[i].name == 'city') {
				if(!(inpX[i].checked)) {
					inpX[i].setAttribute("checked", true);
				} else if(inpX[i].checked){
					if(navigator.userAgent.indexOf('MSIE') != -1){
						inpX[i].setAttribute("checked", false);
					} else {
						inpX[i].removeAttribute("checked");
					}
				}
			}
	}
}

function showCity(id){
	var region = id;
	var f = document.getElementsByTagName('FORM');
	for (var i=0; i<f.length; i++) {
        	var inpX = f[i].elements;
		for (var j=0; j<inpX.length; j++) {
			if (inpX[j].type == 'checkbox' && inpX[j].name == 'city') {
				if(inpX[j].className == region.value && !(inpX[j].checked)) {
					inpX[j].setAttribute("checked", true);
				} else if(inpX[j].className == region.value && inpX[j].checked){
					if(navigator.userAgent.indexOf('MSIE') != -1){
						inpX[j].setAttribute("checked", false);
					} else {
						inpX[j].removeAttribute("checked");
					}
				}
			}
		}
	}
}

var click = 0;

function cityChange(id) {
	click = 0;

//	wl_place = 'ajaxblockaddress';
	if (click == 0 || http.readyState == 4) {
		click = 1;
		var s = (id)? '?city='+id : '';
		var url='/city-objects-list.xml'+s;
		httpGET(url,'ajaxblockaddress');
	}
}

function areaChange(id,agency_id){
	var inputArea = document.getElementById('inputarea_id');
	var inputRegion = document.getElementById('tr_region_id');
	//var inputCity = document.getElementById('tr_city_id');
	var inputAdr = document.getElementById('adr');
	var selectInput = inputArea.options[inputArea.selectedIndex].className;
	if(selectInput.indexOf('city_') != -1){
		inputArea.name = 'city';
		inputRegion.style.display = "none"; 
		inputAdr.style.display = "";

		cityChange(id);
		
		var myHttp = getHTTPObject();
		click = 0;
		if(click == 0 || myhttp.readyState == 4){
			click = 1;
			var region_field = 'inputregion';
			var region_area_url = '/area-objects-list.xml';
			myHttp.open("GET", region_area_url, true);
			myHttp.onreadystatechange = function() {
  				if (myHttp.readyState == 4) {
       				var region_area = myHttp.responseText;
					document.getElementById(region_field).innerHTML = region_area;
  				}
			};
			myHttp.send(null);
		}
		var newHttp = getHTTPObject();
		click = 0;
		if(click == 0 || newhttp.readyState == 4){
			click = 1;
			var city_field = 'inputcity';
			var city_area_url = '/city-list.xml';
			newHttp.open("GET", city_area_url, true);
			newHttp.onreadystatechange = function() {
  				if (newHttp.readyState == 4) {
       				var city_area = newHttp.responseText;
					document.getElementById(city_field).innerHTML = city_area;
  				}
			};
			newHttp.send(null);
		}
	} else {
		cityChange('0');
		inputArea.name = 'area_id';
		if (inputArea.options[inputArea.selectedIndex].value=='') {
			inputRegion.style.display = "none";
			inputAdr.style.display = "none";
		} else {
			inputRegion.style.display = "";
			inputAdr.style.display = "none";
		}
		var myHttp = getHTTPObject();
		click = 0;
		if(click == 0 || myhttp.readyState == 4){
			click = 1;
			var region_field = 'inputregion';
			s = (id)? '?area_id='+id : '';
			var region_area_url = '/area-objects-list.xml'+s;
			myHttp.open("GET", region_area_url, true);
			myHttp.onreadystatechange = function() {
  				if (myHttp.readyState == 4) {
       				var region_area = myHttp.responseText;
					document.getElementById(region_field).innerHTML = region_area;
  				} else {
					document.getElementById(region_field).innerHTML = "загрузка...";
				}
  				
			};
			myHttp.send(null);			
		}
		var newHttp = getHTTPObject();
		click = 0;
		if(click == 0 || newhttp.readyState == 4){
			click = 1;
			var city_field = 'inputcity';
			s = (id)? '?area_id='+id : '';
			var city_area_url = '/city-list.xml'+s;
			newHttp.open("GET", city_area_url, true);
			newHttp.onreadystatechange = function() {
  				if (newHttp.readyState == 4) {
       				var city_area = newHttp.responseText;
					document.getElementById(city_field).innerHTML = city_area;
  				} else {
					document.getElementById(city_field).innerHTML = "загрузка...";
				}
  				
			};
			newHttp.send(null);			
		}
//		if(inputRegion.style.display == "none" && inputAdr.style.display == ""){
//		}
	}
	
	if(agency_id){
		var agencyHttp = getHTTPObject();
		click = 0;
		if(click == 0 || agencyHttp.readyState == 4){
			click = 1;
			var agency_field = 'inputagency';
			
			if(selectInput.indexOf('city_') != -1)
				s = (id)? '?city_id='+id : '';
			else	
				s = (id)? '?area_id='+id : '';
			
			if (realtytype)
				s += realtytype;
			var agency_url = '/agency.xml'+s;
			agencyHttp.open("GET", agency_url, true);
			agencyHttp.onreadystatechange = function() {
				if (agencyHttp.readyState == 4) {
					var agency_text = agencyHttp.responseText;
					var inJs = new Array();
					inJs = agency_text.split(/<script[^>]*>/);
					if (inJs && inJs.length >1) {
						for (var myivar=1; myivar<inJs.length; myivar++) {
							var inJs2 = new Array();
							inJs2 = inJs[myivar].match(/^([\s\S]*?\w*?[\s\S]*?)<\/script>/);
							if (inJs2[1]) 	{
							// and with 'eval' your scripts will work properly
							eval(inJs2[1]);
							}
						}
					}
					
					replaceEadminAgencyOptions(agency_id);
				}
				
			};
			agencyHttp.send(null);			
		}
	}

}

function regionChange(id){
	var myHttp = getHTTPObject();
		click = 0;
		if(click == 0 || myHttp.readyStatus == 4){
			click = 1;
			var city_field = 'inputcity';
			subject_id = city_field;
			s = (id)? '?area_id='+id : '';
			var city_area_url = '/city-list.xml'+s;
			myHttp.open("GET", city_area_url, true);
			myHttp.onreadystatechange = function() {
  				if (myHttp.readyState == 4) {
       				var city_area = myHttp.responseText;
					document.getElementById(subject_id).innerHTML = city_area;
  				} else {
					document.getElementById(subject_id).innerHTML = "загрузка...";
				}
  				
			};
			myHttp.send(null);
	}
}

function suburbanAreaChange(id, agency_id){
	var inputArea = document.getElementById('inputarea_id');
	var inputRegion = document.getElementById('tr_region_id');
	//var inputCity = document.getElementById('tr_city_id');
	var inputAdr = document.getElementById('adr');
	var selectInput = inputArea.options[inputArea.selectedIndex].className;

	if(selectInput.indexOf('city_') != -1){
		inputArea.name = 'city';
		inputRegion.style.display = "none"; 
		inputAdr.style.display = "";
		cityChange(id);

		var myHttp = getHTTPObject();
		click = 0;
		if(click == 0 || myhttp.readyState == 4){
			click = 1;
			var region_field = 'inputregion';
			var region_area_url = '/area-objects-list.xml';
			myHttp.open("GET", region_area_url, true);
			myHttp.onreadystatechange = function() {
  				if (myHttp.readyState == 4) {
       				var region_area = myHttp.responseText;
					document.getElementById(region_field).innerHTML = region_area;
  				}
			};
			myHttp.send(null);
		}
		var newHttp = getHTTPObject();
		click = 0;
		if(click == 0 || newhttp.readyState == 4){
			click = 1;
			var city_field = 'inputcity';
			var city_area_url = '/city-list.xml';
			newHttp.open("GET", city_area_url, true);
			newHttp.onreadystatechange = function() {
  				if (newHttp.readyState == 4) {
       				var city_area = newHttp.responseText;
					document.getElementById(city_field).innerHTML = city_area;
  				}
			};
			newHttp.send(null);
		}
	} else {
		cityChange('0');
		inputArea.name = 'area_id';
		if (inputArea.options[inputArea.selectedIndex].value=='') {
			inputRegion.style.display = "none";
			inputAdr.style.display = "none";
		} else {
			inputRegion.style.display = "";
			inputAdr.style.display = "none";
		}
		var myHttp = getHTTPObject();
		click = 0;
		if(click == 0 || myhttp.readyState == 4){
			click = 1;
			var region_field = 'inputregion';
			s = (id)? '?area_id='+id : '';
			var region_area_url = '/area-objects-list.xml'+s;
			myHttp.open("GET", region_area_url, true);
			myHttp.onreadystatechange = function() {
  				if (myHttp.readyState == 4) {
       				var region_area = myHttp.responseText;
					document.getElementById(region_field).innerHTML = region_area;
  				} else {
					document.getElementById(region_field).innerHTML = "загрузка...";
				}
  				
			};
			myHttp.send(null);			
		}
		var newHttp = getHTTPObject();
		click = 0;
		if(click == 0 || newhttp.readyState == 4){
			click = 1;
			var city_field = 'inputcity';
			s = (id)? '?area_id='+id : '';
			var city_area_url = '/city-list.xml'+s;
			newHttp.open("GET", city_area_url, true);
			newHttp.onreadystatechange = function() {
  				if (newHttp.readyState == 4) {
       				var city_area = newHttp.responseText;
					document.getElementById(city_field).innerHTML = city_area;
  				} else {
					document.getElementById(city_field).innerHTML = "загрузка...";
				}
  				
			};
			newHttp.send(null);			
		}
	}
	
	if(agency_id){
		var agencyHttp = getHTTPObject();
		click = 0;
		if(click == 0 || agencyHttp.readyState == 4){
			click = 1;
			var agency_field = 'inputagency';
			if(selectInput.indexOf('city_') != -1)
				s = (id)? '?city_id='+id : '';
			else	
				s = (id)? '?area_id='+id : '';
			var agency_url = '/agency.xml'+s;
			agencyHttp.open("GET", agency_url, true);
			agencyHttp.onreadystatechange = function() {
				if (agencyHttp.readyState == 4) {
					var agency_text = agencyHttp.responseText;
					var inJs = new Array();
					inJs = agency_text.split(/<script[^>]*>/);
					if (inJs && inJs.length >1) {
						for (var myivar=1; myivar<inJs.length; myivar++) {
							var inJs2 = new Array();
							inJs2 = inJs[myivar].match(/^([\s\S]*?\w*?[\s\S]*?)<\/script>/);
							if (inJs2[1]) 	{
							// and with 'eval' your scripts will work properly
							eval(inJs2[1]);
							}
						}
					}
					
					replaceEadminAgencyOptions(agency_id);
				}
				
			};
			agencyHttp.send(null);			
		}
	}
}

function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}
function findPosX(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {posLeft += obj.offsetLeft; obj = obj.offsetParent;}
	return posLeft;
}

function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {
		posTop += obj.offsetTop;
		obj = obj.offsetParent;
	}
	return posTop;
}

function findPosY(obj) {
	var posTop = 0;
	while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}

function getAdvToDate(id)
{
	var newHttp = getHTTPObject();
	click = 0;
	if(click == 0 || newhttp.readyState == 4)
	{
		click = 1;
		var maxday_field = document.getElementById('inputrealty_advto');
		var adv_from = document.getElementById('inputrealty_advfrom');
		var rtype = document.getElementById('inputrealty_realtytype1').value;
		s = (id)? '?city='+id+'&realtytype_id='+rtype : '';
		var max_day_url = '/eadmin/campaign/maxday.xml'+s;
		newHttp.open("GET", max_day_url, true);
		newHttp.onreadystatechange = function() 
		{
 				if (newHttp.readyState == 4) {
 					var tmp =  document.getElementById('maxday');
 					tmp.innerHTML = newHttp.responseText;
 					var number = isNaN(parseInt(tmp.getElementsByTagName('DIV')[0].innerHTML))?14:parseInt(tmp.getElementsByTagName('DIV')[0].innerHTML);
					var today = new Date();
					var day = today.getDate();
					var sum = day + number;
					today.setDate(sum);
                   //alert(today.getDate());
					year = today.getFullYear();
					month = today.getMonth()+1;
					day = today.getDate();
 					tmp.innerHTML = day + "/" + month + "/" + year;
 					maxday_field.value = tmp.innerHTML;	
 				} else {
				//maxday_field.innerHTML = "загрузка...";
			}
 				
		};
		newHttp.send(null);			
	}
}

function addRegionChange(id){
//alert('')
	var inputArea = document.getElementById('inputrealty_area');
	var selectInput = inputArea.options[inputArea.selectedIndex].className;
	if(selectInput.indexOf('city_') != -1){
		document.getElementById('inputrealty_area').name = 'realty_city';

// AMB 14.05.2008
if (document.getElementById('tr_inputrealty_region')) document.getElementById('tr_inputrealty_region').style.display = 'none';
if (document.getElementById('tr_inputrealty_city')) document.getElementById('tr_inputrealty_city').style.display = 'none';

		if(click == 0 || http.readyState == 4){
			click = 1;
			
			var s = (id)? '?area_id=0'+id : '';
			var region_url = '/eadmin/realestate/region-list.xml'+s;
			httpGET(region_url, 'inputrealty_region');
		
		}

		var newhttp = getHTTPObject();
		click = 0;
		if(click == 0 || newhttp.readyState == 4){
			click = 1;
			var s = (id)? '?city='+id : '';
			var url = '/eadmin/realestate/district-list.xml'+s;		
			newhttpGET(url, 'inputrealty_district');
		}
		
		var myhttp = getHTTPObject();
		click = 0;
		if(click == 0 || myhttp.readyState == 4){
			click = 1;
			var s = (id)? '?city='+id : '';
			var metro_url = '/eadmin/realestate/metro-list.xml'+s;
			myhttpGET(metro_url, 'inputrealty_metro');			
		}
		
		getAdvToDate(id);
	} else {
		document.getElementById('inputrealty_area').name = 'realty_area';
// AMB 14.05.2008
if (document.getElementById('tr_inputrealty_region')) document.getElementById('tr_inputrealty_region').style.display = '';
if (document.getElementById('tr_inputrealty_city')) document.getElementById('tr_inputrealty_city').style.display = '';

		if(click == 0 || http.readyState == 4){
			click = 1;
			var s = (id)? '?area_id='+id : '';
			var url = '/eadmin/realestate/region-list.xml'+s;
			httpGET(url, 'inputrealty_region');
		}
		var myhttp = getHTTPObject();
		click = 0;
		if(click == 0 || http.readyState == 4){
			click = 1;
			var s = (id)? '?city='+id : '';
			var url = '/eadmin/realestate/district-list.xml'+s;
			myhttpGET(url, 'inputrealty_district');
		}
		var newhttp = getHTTPObject();
		click = 0;
		if(click == 0 || newhttp.readyState == 4){
			click = 1;
			var s = (id)? '?city='+id : '';
			var metro_url = '/eadmin/realestate/metro-list.xml'+s;
			newhttpGET(metro_url, 'inputrealty_metro');	
		}
		getAdvToDate(id);
	}
	if(document.getElementById('inputrealty_building')){
		var buildHttp = getHTTPObject();
		var params = '';
		var area = document.getElementById('inputrealty_area').options[document.getElementById('inputrealty_area').options.selectedIndex];
		var realtytype = document.getElementById('inputrealty_realtytype1').value;
		if (realtytype == 12 || realtytype == 15 || realtytype == 14 || realtytype == 16)
			realtytype = 11;
		else if (realtytype == 1)	
			realtytype = 2;
		else if (realtytype == 25 || realtytype == 26 || realtytype == 27 || realtytype == 28 || realtytype == 29 || realtytype == 30)
			realtytype = 24;	
			
		if (area.className.indexOf('city')>-1)
			params = 'city=' + area.value;
		else
			params = 'area=' + area.value;
		var build_url = '/eadmin/realestate/building-list.xml?' + params + '&realtytype=' + realtytype;
		buildHttp.open("GET", build_url, true);
		buildHttp.onreadystatechange = function() {
			if (buildHttp.readyState == 4) {
				var inTextAll = buildHttp.responseText;
				//eval (buildHttp.responseText);
				var inJs = new Array();
				inJs = inTextAll.split(/<script[^>]*>/);
				if (inJs && inJs.length >1) {
					for (var myivar=1; myivar<inJs.length; myivar++) {
						var inJs2 = new Array();
						inJs2 = inJs[myivar].match(/^([\s\S]*?\w*?[\s\S]*?)<\/script>/);
						if (inJs2[1]) 	{
						// and with 'eval' your scripts will work properly
						eval(inJs2[1]);
						}
					}
				}
				//document.getElementById('tempscript').innerHTML = buildHttp.responseText;
			}
			
		};
		buildHttp.send(null);
	}
}

function getFullYear(d) {
    var y = d.getYear();
    if (y < 1000) y += 1900;
    return y;
}

/*function stripHTML(el){
	var re = /(<([^>]+)>)/gi;
	for (i=0; i<el.length; i++){
		el[i].value = el[i].value.replace(re, "");
	}
}*/

function addCityChange(id){
	if(click == 0 || http.readyState == 4){
		click = 1;
		var s = (id)? '?region_id='+id : '';
		if(s!=''){
			var url = '/eadmin/realestate/city-list.xml'+s;
			httpGET(url, 'inputrealty_city');
		}
	}
}

function listCity(id){
//if (trueLoaded) alert('');
	var newHttp = getHTTPObject();
	click = 0;	
	if(click == 0 || newHttp.readyState == 4){
		click = 1;
		
		var city_field = 'inputcity';
			subject_id = city_field;
			s = (id)? '?region_id='+id : '';
			var city_region_url = '/city-list.xml'+s;
			//httpGET(city_region_url, 'inputcity');
			if(s!=''){
			newHttp.open("GET", city_region_url, true);
			newHttp.onreadystatechange = function() {
  				if (newHttp.readyState == 4) {
       				var city_region = newHttp.responseText;
					document.getElementById(subject_id).innerHTML = city_region;
  				} else {
  					document.getElementById(subject_id).innerHTML = "загрузка...";
  				}
			};
			newHttp.send(null);
		}
	}
}

function cityChangeSub(id) {
//	wl_place = 'ajaxblockaddress';
	if (click == 0 || http.readyState == 4) {
		click = 1;
		var s = (id)? '?city='+id : '';
		var url='/suburban-objects-list.xml'+s;
		httpGET(url,'ajaxblockaddress');
	}
}
function cityChangeD(id) {
//	wl_place = 'ajaxblockaddress';
	if (click == 0 || http.readyState == 4) {
		click = 1;
		var s = (id)? '?city='+id : '';
		var url='/city-districts-list.xml'+s;
		httpGET(url,'ajaxblockaddress');
	}
}

function quartChange(y,q) {
//		if (q == '' && y == '') return;
		var bf = document.getElementById('inputbuild_from1'); var bt = document.getElementById('inputbuild_to1');
		if (q != '') { qf = (q-1)*3+1; qt = q*3; } else { qf = 1; qt = 12; }
/*
		if (y.value == '') { 
			ty = y.options[1].value;
			if (q != '') {
				y.selectedIndex = 1;
				}
		} else { ty = y.value; }
		bf.value = qf+'/'+ty;
		bt.value = qt+'/'+ty;
*/

		if (y.value != '') {
			bf.value = qf+'/'+y.value;
			bt.value = qt+'/'+y.value;
		} 

}

function changeCurr(el) {
	var currSpan = document.getElementsByTagName('SPAN');
	for (var i=0; i<currSpan.length; i++) {
		if (currSpan[i].className == 'curr') currSpan[i].innerHTML = el.options[el.selectedIndex].text;
	}
//	alert(el.options[el.selectedIndex].text);
}

function rentTimeChange() {
	var f = document.getElementsByTagName('FORM');
	for (var k=0; k<f.length; k++) {
        	var inpX = f[k].elements;
		for (var i=0; i<inpX.length; i++) {
			if (inpX[i].type == 'radio' && inpX[i].name == 'type') {
				if (inpX[i].checked == true) {
					if (inpX[i].value == 0) {
						document.getElementById('pricetitle').innerHTML = 'Цена за день';
						f[k]['pricemonth_from'].name = 'priceday_from';
						f[k]['pricemonth_to'].name = 'priceday_to';
					}
					if (inpX[i].value == 1) {
						document.getElementById('pricetitle').innerHTML = 'Цена за месяц';
						f[k]['priceday_from'].name = 'pricemonth_from';
						f[k]['priceday_to'].name = 'pricemonth_to';
					}
				}
			}
		}
	}
}






function refreshDynamicSelectOptions(sel1, sel2, prefix, clonedOptions) {
 while (sel2.options.length) {
  sel2.remove(0);
 }
 var pattern1 = /( |^)(select)( |$)/;
 var pattern2 = new RegExp("( |^)("+ prefix + sel1.options[sel1.selectedIndex].value + ")( |$)");
 for (var i = 0; i < clonedOptions.length; i++) {
  if (clonedOptions[i].className.match(pattern1) ||
  clonedOptions[i].className.match(pattern2) || clonedOptions[i].value=='') {
   sel2.appendChild(clonedOptions[i].cloneNode(true));
  }
 }
}


function changeDistrList(cId) {
 if (document.getElementById && document.getElementsByTagName &&
 document.getElementById('inputcity') && document.getElementById('inputdistrict') &&
 document.getElementById('inputdistrict').tagName == 'SELECT') {
		var sel1 = document.getElementById('inputcity');
		var sel2 = document.getElementById('inputdistrict');
		if (sel1.options[sel1.selectedIndex].value == 486) {
			sel1.name = 'area';
			sel2.name = 'region';
		}
		if (sel1.options[sel1.selectedIndex].value == 27 || sel1.options[sel1.selectedIndex].value == 123) {
			sel1.name = 'city';
			sel2.name = 'district';
		}


	if(cId && cId.form.className=='niceform' && ImagesOn != 0) {
	if (document.getElementById('select_inputdistrict')) {
		var pp = document.getElementsByTagName('P');
		var pattern = new RegExp("^city_");
		var sss = new Array();
		for (var p=0; p<pp.length; p++) {
			if (pp[p].className.match(pattern)) {
				if (pp[p].className == 'city_'+sel1.options[sel1.selectedIndex].value) {
					pp[p].style.display = 'block';
				} else {
					pp[p].style.display = 'none'; 
				}
			}
		}
		}
	} else if (ImagesOn == 0) {
		var clone = sel2.cloneNode(true);
		var clonedOptions = clone.getElementsByTagName("option");
		refreshDynamicSelectOptions(sel1, sel2, 'city_', clonedOptions);
		sel1.onchange = function() {
		refreshDynamicSelectOptions(sel1, sel2, 'city_', clonedOptions);
	}
  }
 }
}


function selectLoader() {
	for ( var i=0; i<arguments.length; i++) {
	var dd = document.getElementById('input'+arguments[i]);
	if (dd && dd.tagName=='SELECT') 
	{
		while (dd.options.length) 
			{
			dd.remove(0);
			}
		var opt = document.createElement('OPTION');
		opt.text = 'загрузка...';
		opt.selected = 'true';
		dd.appendChild(opt);
		}
	}
}

function changeCityObjects(city,district,metro) {
	if (metro=='') {
	        selectLoader(district);
	} else {
        selectLoader(district,metro);
        }
	var c = document.getElementById('input'+city);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?city='+id : '';
	var url='/select_city-objects-list.xml'+s;
	if (!document.getElementById('temporaryDIV')) createLayer('temporaryDIV', '');
	var TMPdiv = document.getElementById('temporaryDIV');
	TMPdiv.style.display = 'none';
	httpGET(url,'temporaryDIV');
	parseblocks("basicinfo",c,"select");
}



function changeUserList(agency,siteuser) {
/* MipH: времено закомментил из-за глюков в ИЕ и Опере*/
     //   selectLoader(siteuser);
	var c = document.getElementById('input'+agency);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?agency='+id : '';
	if(s!=''){
		var url='/select_user-list.xml'+s;
		/*if (!document.getElementById('temporaryDIV')) createLayer('temporaryDIV', '');
		var TMPdiv = document.getElementById('temporaryDIV');
		TMPdiv.style.display = 'none';
		httpGET(url,'temporaryDIV');
		parseblocks("representative",document.getElementById('inputrealty_agency'),"select");*/
		httpGET(url,'inputrealty_siteuser');
	}
}

function changeRoomUserList(agency,siteuser) {
	var c = document.getElementById('input'+agency);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?agency='+id : '';
	if(s!=''){
		var url='/select_room-user-list.xml'+s;
		httpGET(url,'inputrealty_siteuser');
	}
}

function changeBarUserList(agency,siteuser) {
	var c = document.getElementById('input'+agency);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?agency='+id : '';
	if(s!=''){
		var url='/select_bar-user-list.xml'+s;
		httpGET(url,'inputrealty_siteuser');
	}
}

function changeUserListHouse(agency,siteuser) {
	var c = document.getElementById('input'+agency);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?agency='+id : '';
	if(s!=''){
		var url='/select_user_house-list.xml'+s;
		httpGET(url,'inputrealty_siteuser');
	}
}

function changeUserListFlat(agency,siteuser) {
	var c = document.getElementById('input'+agency);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?agency='+id : '';
	if(s!=''){
		var url='/select_user_flat-list.xml'+s;
		httpGET(url,'inputrealty_siteuser');
	}
}

function changeUserListComm(agency,siteuser) {
	var c = document.getElementById('input'+agency);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?agency='+id : '';
	if(s!=''){
		var url='/select_user_comm-list.xml'+s;
		httpGET(url,'inputrealty_siteuser');
	}
}

function changeUserListCommWith(agency,siteuser) {
	var c = document.getElementById('input'+agency);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?agency='+id : '';
	if(s!=''){
		var url='/select_user_comm-list.xml'+s + '&with';
		httpGET(url,'inputrealty_siteuser');
	}
}

function changeUserListCott(agency,siteuser) {
	var c = document.getElementById('input'+agency);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?agency='+id : '';
	if(s!=''){
		var url='/select_user_cott-list.xml'+s;
		httpGET(url,'inputrealty_siteuser');
	}
}

function changeUserListSuburban(agency,siteuser) {
	var c = document.getElementById('input'+agency);
	var id = c.options[c.selectedIndex].value
	var s = (id)? '?agency='+id : '';
	if(s!=''){
		var url='/select_user_suburban-list.xml'+s;
		httpGET(url,'inputrealty_siteuser');
	}
}

function showToolTip(url, w, h, e) {
	var posx = 0; var posy = 0;
	if (!w) var w = 200;
	if (!h) var h = 200;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) { posx = e.pageX; posy = e.pageY; }
	else if (e.clientX || e.clientY) {
		posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
	}
	tt=dhtmlwindow.open('tooltipBox', 'iframe', url, 'Подсказка', 'width='+w+'px,height='+h+'px,resize=1,scrolling=1,minimize=0', 'recal');
	posx = posx-tt.offsetWidth/2;
	posy = posy-tt.offsetHeight/2;
	if (posx<0) posx = 0;
	if (posy<0) posy = 0;
	tt.style.left=posx+'px';
	tt.style.top=posy+'px';
}

function act(f) {
	f.action="/login.xml?fromhref="+escape(f.elements['fromhref'].value);
        return true;
}

function changeUserTariffs()
{
	var a = document.getElementById('agency_4tariff').value;
	var u = document.getElementById('siteuser_4tariff').value;
	
	if (a > 0 && u > 0)
	{
	var s = '?realty_agency='+a+'&realty_siteuser='+u;
	var url='/radio_user-tariff.xml'+s;
	if (!document.getElementById('temporaryDIV')) createLayer('temporaryDIV', '');
	var TMPdiv = document.getElementById('temporaryDIV');
	TMPdiv.style.display = 'none';
		(url,'temporaryDIV');
	}
}

old_opera = (navigator.userAgent.toLowerCase().indexOf('opera/9.22')!=-1 || navigator.userAgent.toLowerCase().indexOf('opera/9.23')!=-1);

lastaid = 0;
function go_to_area(aid)
{
	var redir = false;
	type=aid.substring(0,1);
	id=aid.substring(2);

	if (!id)
		lastaid=1;
	
	//alert(lastaid+' - '+id);
	if (lastaid && id && lastaid!=id)
		redir = true;

	if (redir==true)
	{
		if (type=='r')
			window.location='/regions.xml?region='+id;
		if (type=='c')
			window.location='/regions.xml?city='+id;
	}

	if (aid)
		lastaid=id;
}

lastcid = 0;
function go_to_city(cid)
{
//alert(lastcid+' - '+cid+' - '+window.location);

	if (!cid)
		lastcid=1;			
	if ((!old_opera || lastcid) && cid && lastcid!=cid)
	{
		window.location='/regions.xml?city='+cid;
	}
	if (cid)
		lastcid=cid;
}

lastrid = 0;
function go_to_region(rid)
{
if (markload)
{
//	alert(lastrid+' - '+rid);
	if (!rid) {
		lastrid=1;
	}
	
	if ((!old_opera || lastrid) && rid && lastrid!=rid)
	{
		window.location='?rregion='+rid;
	}
			
	if (rid)
		lastrid=rid;
}
}

lastdid = 0;
function go_to_district(did)
{
	el = document.getElementById('inputdistrict');
	ops = el.getElementsByTagName('OPTION');
	for(i=0; i<ops.length;i++)
	{
		if (ops[i].value==did)
			selectMe('inputdistrict', i, 1);
	}
}

function replaceAgOptions() {
	region_id = document.getElementById('inputregion_id');
	select_div_id = document.getElementById('select_inputregion_id');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputregion_id"); selectMe("inputregion_id",'+i+',1);');
		subA.appendChild(textA);
	}
	selectMe('inputregion_id', 0, 1);
}

function replaceEadminOptions() {
	region_id = document.getElementById('inputrealty_region');
	select_div_id = document.getElementById('select_inputrealty_region');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}
	
	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_region"); selectMe("inputrealty_region",'+i+',3);');
		subA.appendChild(textA);
	}

	selectMe('inputrealty_region', 0, 3);
}

function replaceEadminOptionsRegion() {
	region_id = document.getElementById('inputrealty_region');
	select_div_id = document.getElementById('select_inputrealty_region');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}
	
	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_region"); selectMe("inputrealty_region",'+i+',1);');
		subA.appendChild(textA);
	}

	selectMe('inputrealty_region', 0, 1);
}

function replaceEadminOptionsBuild() {
	
	building = document.getElementById('inputrealty_building');
	select_div_id = document.getElementById('select_inputrealty_building');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у building
	
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(building.firstChild){
			building.removeChild(building.firstChild);
		}	
	} else {
		for(var j=building.options.length; j>0; j--) {
			building.remove(building.options[j]);
		}
	}
	building.innerHTML = '';
	// 2. сделать новые option
	for (var i=0; i<optBuild.length; i++) {
		var o = document.createElement('OPTION');
		o.className = optBuild[i].classN;
		o.value =  optBuild[i].value;
		o.innerHTML = optBuild[i].label;
		building.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		subP.appendChild(subA);
		select_div_id.appendChild(subP);
		var textA = document.createTextNode(optBuild[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_building"); selectMe("inputrealty_building",'+i+',5);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_building', 0, 5);
}

function replaceEadminCityOptions() {
	region_id = document.getElementById('inputrealty_city');
	select_div_id = document.getElementById('select_inputrealty_city');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_city"); selectMe("inputrealty_city",'+i+',2);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_city', 0, 2);
}

function replaceEadminDistrictOptions() {
	region_id = document.getElementById('inputrealty_district');
	select_div_id = document.getElementById('select_inputrealty_district');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_district"); selectMe("inputrealty_district",'+i+',3);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_district', 0, 3);
	
}

function replaceEadminMetroOptions() {
	region_id = document.getElementById('inputrealty_metro');
	select_div_id = document.getElementById('select_inputrealty_metro');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_metro"); selectMe("inputrealty_metro",'+i+',4);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_metro', 0, 4);
}

function replaceEadminAgencyOptions(id) {
	region_id = document.getElementById('inputagency');
	select_div_id = document.getElementById('select_inputagency');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputagency"); selectMe("inputagency",' + i + ',' + id + ');');
		subA.appendChild(textA);
	}
	selectMe('inputagency', 0, id);
	
}


function ShowAreaSelect(id, subId, position){
	var sel = document.getElementById('input' + subId);
	var selInd = sel.options[sel.selectedIndex].className;
	if(selInd.indexOf('city') == 0){
		document.getElementById('input' + subId).name = 'city_id';
	} else {
		document.getElementById('input' + subId).name = 'area_id';
	}
	if(document.getElementById("tr_" + id).style.display == 'none'){
		document.getElementById("tr_" + id).style.display = '';
	} else {
		return false;
	}
}

function checkCitySelect(form_id){
	var cityTr = document.getElementById(form_id);
	var tr = cityTr.getElementsByTagName('TR');
	var n;
	for(i=0;i<tr.length;i++){
		if(document.getElementById('inputarea_id['+i+']') && tr[i].style.display != "none"){
			var select = document.getElementById('inputarea_id['+i+']');
			if(select.options[select.selectedIndex].className.indexOf('city') == 0){
				select.name = 'city_id';
			}
		}
	}
}



function replaceHouseRegionOptions() {
	region_id = document.getElementById('inputrealty_region');
	select_div_id = document.getElementById('select_inputrealty_region');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_region"); selectMe("inputrealty_region",'+i+',2);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_region', 0, 2);
}
			
function replaceHouseCityOptions() {
	region_id = document.getElementById('inputrealty_city');
	select_div_id = document.getElementById('select_inputrealty_city');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}


	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_city"); selectMe("inputrealty_city",'+i+',3);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_city', 0, 3);
}

function replaceHouseDistrictOptions() {
	region_id = document.getElementById('inputrealty_district');
	select_div_id = document.getElementById('select_inputrealty_district');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_district"); selectMe("inputrealty_district",'+i+',4);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_district', 0, 4);
}

function replaceHouseMetroOptions() {

	region_id = document.getElementById('inputrealty_metro');
	select_div_id = document.getElementById('select_inputrealty_metro');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		//o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_metro"); selectMe("inputrealty_metro",'+i+',5);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_metro', 0, 5);
	
}


/* for commercial */
function replaceCommRegionOptions() {
	region_id = document.getElementById('inputrealty_region');
	select_div_id = document.getElementById('select_inputrealty_region');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_region"); selectMe("inputrealty_region",'+i+',1);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_region', 0, 1);
}
			
function replaceCommCityOptions() {
	region_id = document.getElementById('inputrealty_city');
	select_div_id = document.getElementById('select_inputrealty_city');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_city"); selectMe("inputrealty_city",'+i+',2);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_city', 0, 2);
}

function replaceCommDistrictOptions() {
	region_id = document.getElementById('inputrealty_district');
	select_div_id = document.getElementById('select_inputrealty_district');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_district"); selectMe("inputrealty_district",'+i+',3);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_district', 0, 3);
}

function replaceCommMetroOptions() {
	region_id = document.getElementById('inputrealty_metro');
	select_div_id = document.getElementById('select_inputrealty_metro');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	// 1. прибить все option  у region_id
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	// 2. сделать новые option
	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		//o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_metro"); selectMe("inputrealty_metro",'+i+',4);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_metro', 0, 4);
}



function replaceCommSiteuserOptions() {
	region_id = document.getElementById('inputrealty_siteuser');
	select_div_id = document.getElementById('select_inputrealty_siteuser');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
        var place = 8;
        var realtytype=document.getElementById('inputrealty_realtytype1').value;
        
        if (realtytype == 11 || realtytype==13 || realtytype==22)
          place = 6;
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_siteuser"); selectMe("inputrealty_siteuser",'+i+',' +place+ ');');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_siteuser', 0, place);
}

function replaceSiteuserOptions() {
	region_id = document.getElementById('inputrealty_siteuser');
	select_div_id = document.getElementById('select_inputrealty_siteuser');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
        var place = 8;
        var realtytype=document.getElementById('inputrealty_realtytype1').value;
        
        if (realtytype == 11 || realtytype==13 || realtytype==22)
          place = 6;
      
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_siteuser"); selectMe("inputrealty_siteuser",'+i+',' + place +');');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_siteuser', 0, place);
}

function replaceRoomSiteuserOptions() {
	region_id = document.getElementById('inputrealty_siteuser');
	select_div_id = document.getElementById('select_inputrealty_siteuser');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_siteuser"); selectMe("inputrealty_siteuser",'+i+',4);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_siteuser', 0, 4);
}

function replaceBarSiteuserOptions() {
	region_id = document.getElementById('inputrealty_siteuser');
	select_div_id = document.getElementById('select_inputrealty_siteuser');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_siteuser"); selectMe("inputrealty_siteuser",'+i+',2);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_siteuser', 0, 2);
}

function replaceHouseSiteuserOptions() {
	region_id = document.getElementById('inputrealty_siteuser');
	select_div_id = document.getElementById('select_inputrealty_siteuser');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_siteuser"); selectMe("inputrealty_siteuser",'+i+',7);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_siteuser', 0, 7);
}

function replaceFlatSiteuserOptions() {
	region_id = document.getElementById('inputrealty_siteuser');
	select_div_id = document.getElementById('select_inputrealty_siteuser');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}
	
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_siteuser"); selectMe("inputrealty_siteuser",'+i+',7);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_siteuser', 0, 7);
}

function replaceSuburbanSiteuserOptions() {
	region_id = document.getElementById('inputrealty_siteuser');
	select_div_id = document.getElementById('select_inputrealty_siteuser');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}
	
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_siteuser"); selectMe("inputrealty_siteuser",'+i+',7);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_siteuser', 0, 7);
}

function replaceCommSiteuserOptionsWith() {
	region_id = document.getElementById('inputrealty_siteuser');
	select_div_id = document.getElementById('select_inputrealty_siteuser');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
        var place = 9;
        var realtytype=document.getElementById('inputrealty_realtytype1').value;
        
        if (realtytype == 11 || realtytype==13 || realtytype==22)
          place = 7;

	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}
	
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_siteuser"); selectMe("inputrealty_siteuser",'+i+',' +place +');');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_siteuser', 0, place);
}

function replaceCottSiteuserOptions() {
	region_id = document.getElementById('inputrealty_siteuser');
	select_div_id = document.getElementById('select_inputrealty_siteuser');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}
	
	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputrealty_siteuser"); selectMe("inputrealty_siteuser",'+i+',6);');
		subA.appendChild(textA);
	}
	selectMe('inputrealty_siteuser', 0, 6);
}

// functions for references manual
function refRegionChange(id){
	var inputArea = document.getElementById('inputarea');
	var selectInput = inputArea.options[inputArea.selectedIndex].className;
	if(selectInput.indexOf('city_') == 0){
		document.getElementById('inputarea').name = 'district_city';
		if(click == 0 || http.readyState == 4){
			click = 1;
			var s = (id)? '?area_id=0'+id : '';
			var region_url = '/eadmin/reference_manual/region-list.xml'+s;
			httpGET(region_url, 'inputregion');
		}
	} else {
		document.getElementById('inputarea').name = 'area';
		if(click == 0 || http.readyState == 4){
			click = 1;
			var s = (id)? '?area_id='+id : '';
			var url = '/eadmin/reference_manual/region-list.xml'+s;
			httpGET(url, 'inputregion');
		}
	}
}

function replaceRefRegOptions() {
	region_id = document.getElementById('inputregion');
	select_div_id = document.getElementById('select_inputregion');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}

	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputregion"); selectMe("inputregion",'+i+',1);');
		subA.appendChild(textA);
	}
	selectMe('inputregion', 0, 1);
}

function refCityChange(id){
	if(click == 0 || http.readyState == 4){
		click = 1;
		var s = (id)? '?region_id='+id : '';
		if(s!=''){
			var url = '/eadmin/reference_manual/city-list.xml'+s;
			httpGET(url, 'inputdistrict_city');
		}
	}
}

function replaceRefCityOptions() {
	region_id = document.getElementById('inputdistrict_city');
	select_div_id = document.getElementById('select_inputdistrict_city');
	p = select_div_id.getElementsByTagName('P');			
/*
	for (var i=0; i<p.length; i++) {
		p[i].style.display = "none";
	}
*/
removePOptions(p);

	if(navigator.userAgent.indexOf('MSIE 6.') != -1){
		while(region_id.firstChild){
			region_id.removeChild(region_id.firstChild);
		}	
	} else {
		for(var j=region_id.options.length; j>0; j--) {
			region_id.remove(region_id.options[j]);
		}
	}

	for (var i=0; i<opt.length; i++) {
		var o = document.createElement('OPTION');
		o.className = opt[i].classN;
		o.value =  opt[i].value;
		o.innerHTML = opt[i].label;
		region_id.appendChild(o);
		var subP = document.createElement('P');
		subP.setAttribute('class', 'class_' + i);
		var subA = document.createElement('a');
		select_div_id.appendChild(subP);
		subP.appendChild(subA);
		var textA = document.createTextNode(opt[i].label);
		subA.setAttribute('href', 'javascript:showOptions("select_inputdistrict_city"); selectMe("inputdistrict_city",'+i+',2);');
		subA.appendChild(textA);
	}
	selectMe('inputdistrict_city', 0, 2);
}

function removePOptions(p) {
// AMB 14.05.08	
	var pl = p.length - 1;
	if (pl > 0) {
	for (var i=pl; i>0; i--) {
		if (p[i] && p[i].parentNode) p[i].parentNode.removeChild(p[i]);
	}
	}
}
// end of functions for the references manual

var lastoption;
function changeValue(obj){
	if(obj.value == 0){
		clearOption()		
	}else{
		var option = document.getElementById(obj.value);
		clearOption()
		option.value = 1;
		lastoption = option;
	}
	
}

function clearOption(){
	if(lastoption){	
		lastoption.value = 0;
	}else{
		document.getElementById('articles_first').value = 0;
		document.getElementById('articles_second').value = 0;
		document.getElementById('articles_third').value = 0;
	}
}



function changeSortForum(obj){
	
	if (obj.checked){
		document.getElementById('forumstheme_first').checked = false;
		document.getElementById('forumstheme_second').checked = false;
		document.getElementById('forumstheme_third').checked = false;
		obj.checked = true;
	}
	
}


function sendSearchForm(name, value){

	var form = document.getElementById('search-form');
        if(!form)
            form = document.getElementById('filterform');
        if(form){
            document.getElementById(name).value = value;
            form.submit();
        } else {
        return true;
    }
	return false;
}

function setUser(){
	var value = document.getElementById('inputrealty_siteuser').value;
	var actionuser = document.getElementById('inputrealty_actionuser1');
	actionuser.value = value;
}

// проверка одного из полей формы на заполненность

/*
var ok1=false

function test(form)
{
	 if ((form.realty_pricemonth.value != "") || (form.realty_priceday.value != "")) 
	 {
			ok1=true
			 if(ok1)
			 {
			  alert("Форма заполнена!")
			  document.newitem.submit();
			 }
  
	 }
	 else {
		ok1=false
		alert("Ввести данные")
	 }
 
}
*/

marktype = 0;
function setTodoType(){
if (!old_opera || marktype)
{
	var list = document.getElementById('inputtodo');
	var value = list.options[list.selectedIndex].value;
	var href = new String(window.location);

	var start = href.indexOf('todo');
	if (start > -1)
		href = href.substring(0,start - 1);

	window.location = href + '&todo=' + value;
}
else
marktype=1;
}