var newsid_pic = document.getElementById('newsid_pic');
if (newsid_pic) {
    var newsid_pic_big = new Image();
    newsid_pic_big.src = newsid_pic.getAttribute('rel');
    newsid_pic.onclick = function() {
	o_O.Effects.FadeTransparent.fadeOut(document.body, {stop: 8, speed: 20});
	var container = document.createElement('div');
	o_O.Effects.setOpacity(container, 0);
	container.id = 'thumbnailcontainer';
	document.body.appendChild(container);
	container.style.position = 'absolute';
	container.style.zIndex = 130;
	container.style.width = (o_O.Document.getDocumentSize()['width'] - 40)+'px';
	container.style.height = (o_O.Document.getDocumentSize()['height'] - 40)+'px';
	container.style.padding = '20px';
	container.style.textAlign = 'center';
	container.appendChild(newsid_pic_big);
	newsid_pic_big.style.cursor = 'hand';
	newsid_pic_big.style.cursor = 'pointer';
	newsid_pic_big.style.width = newsid_pic_big.width+'px';
	newsid_pic_big.style.height = newsid_pic_big.height+'px';
	newsid_pic_big.onclick = function() {
	    o_O.Effects.FadeTransparent.fadeIn(document.body);
	    document.body.removeChild(container);
	};
	container.style.top = (o_O.Window.top()+(container.offsetHeight/26))+'px';
	container.style.left = '0px';
	o_O.Effects.FadeTransparent.fadeIn(container, {speed: 20});
	return false;
    }
}

var estate_images = o_O.Document.getElementsByClassName('estate_image');
if (estate_images) {
    var img_array = [];
    for (var i in estate_images) {
	img_array[i] = new Image();
	img_array[i].src = estate_images[i].src.replace(/mini_square|medium/, 'big');
	estate_images[i].onclick = function(i) {
	    return function() {
		o_O.Effects.FadeTransparent.fadeOut(document.body, {stop: 8, speed: 20});
		var container = document.createElement('div');
		o_O.Effects.setOpacity(container, 0);
		container.id = 'thumbnailcontainer';
		document.body.appendChild(container);
		container.style.position = 'absolute';
		container.style.zIndex = 130;
		container.style.width = (o_O.Document.getDocumentSize()['width'] - 40)+'px';
		container.style.height = (o_O.Document.getDocumentSize()['height'] - 40)+'px';
		container.style.padding = '20px';
		container.style.textAlign = 'center';
		container.appendChild(img_array[i]);
		img_array[i].style.cursor = 'hand';
		img_array[i].style.cursor = 'pointer';
		img_array[i].style.width = img_array[i].width+'px';
		img_array[i].style.height = img_array[i].height+'px';
		img_array[i].onclick = function() {
		    o_O.Effects.FadeTransparent.fadeIn(document.body);
		    document.body.removeChild(container);
		};
		container.style.top = (o_O.Window.top()+(container.offsetHeight/26))+'px';
		container.style.left = '0px';
		o_O.Effects.FadeTransparent.fadeIn(container, {speed: 20});
		return false;
	    }
	}(i);
    }
}

var num_fields = o_O.Document.getElementsByClassName('num_field');
if (num_fields) {
    for (var i in num_fields) {
	num_fields[i].onkeypress = function(e) {
	    var evt = o_O.Event.get(e).which || o_O.Event.get(e).keyCode;
	    return (evt == 44 || evt == 46 || evt >= 48 && evt <= 57) ? true : false;
	};
    }
}
var help_tips = o_O.Document.getElementsByClassName('help_tip');
if (help_tips) {
    for (var i in help_tips) {
        help_tips[i].onmouseover = function() {
            o_O.Effects.showTip(this, this.getAttribute('rel'));
        };
        help_tips[i].onmouseout = function() {
            setTimeout(function(){o_O.Effects.closeTip();}, 50);
        };
    }
}
if (document.getElementById('captcha')) {
    document.getElementById('captcha').onclick = function() {
	this.src = this.src+'?_='+Math.random();
    };
}
var search_country = document.getElementById('search_country');
if (search_country) {
    search_country.onchange = function() {
	if (this.options[this.selectedIndex].value != '') {
	    o_O.AJAX.process({
		method: 'GET',
		url: '/json_regions.php?parent='+this.options[this.selectedIndex].value,
		onComplete: function(msg) {
		    var regions = eval(msg);
		    var search_region = document.getElementById('search_region');
		    if (regions.length > 0) {
			search_region.innerHTML = '';
			var o = document.createElement('option');
			o.value = '';
			o.text = 'Регион';
			try { search_region.add(o, null); } catch(e) { search_region.add(o); }
			for (var i in regions) {
			    var o = document.createElement('option');
			    o.value = regions[i]['obj_id'];
			    o.text = regions[i]['region_name'];
			    try { search_region.add(o, null); } catch(e) { search_region.add(o); }
			}
			search_region.onchange = function() {
			    var search_city = document.getElementById('search_city');
			    if (this.options[this.selectedIndex].value != '') {
				search_city.selectedIndex = 0;
			    }
			}
		    }
		}
	    });
	    o_O.AJAX.process({
		method: 'GET',
		url: '/json_cities.php?parent='+this.options[this.selectedIndex].value,
		onComplete: function(msg) {
		    var regions = eval(msg);
		    var search_city = document.getElementById('search_city');
		    if (regions.length > 0) {
			search_city.innerHTML = '';
			var o = document.createElement('option');
			o.value = '';
			o.text = 'Город';
			try { search_city.add(o, null); } catch(e) { search_city.add(o); }
			for (var i in regions) {
			    var o = document.createElement('option');
			    o.value = regions[i]['obj_id'];
			    o.text = regions[i]['region_name'];
			    try { search_city.add(o, null); } catch(e) { search_city.add(o); }
			}
			search_city.onchange = function() {
			    var search_region = document.getElementById('search_region');
			    if (this.options[this.selectedIndex].value != '') {
				search_region.selectedIndex = 0;
			    }
			}
		    }
		}
	    });
	} else {
	    var search_region = document.getElementById('search_region');
	    search_region.innerHTML = '';
	    var o = document.createElement('option');
	    o.value = '';
	    o.text = 'Регион';
	    try { search_region.add(o, null); } catch(e) { search_region.add(o); }
	    var o = document.createElement('option');
	    o.value = '';
	    o.text = ' ... выберите страну';
	    try { search_region.add(o, null); } catch(e) { search_region.add(o); }
	    var search_city = document.getElementById('search_city');
	    search_city.innerHTML = '';
	    var o = document.createElement('option');
	    o.value = '';
	    o.text = 'Город';
	    try { search_city.add(o, null); } catch(e) { search_city.add(o); }
	    var o = document.createElement('option');
	    o.value = '';
	    o.text = ' ... выберите страну';
	    try { search_city.add(o, null); } catch(e) { search_city.add(o); }
	}
    };
}
