
$(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({
		social_tools: false,
		overlay_gallery: false
	});
});


/* AJAX ============================================================================================================ */
function AjaxLoader(url, place)
{
	if (window.ActiveXObject)
	{
		httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		httpRequest = new XMLHttpRequest();
	}
	
	if (!httpRequest)
		return false;
	
	httpRequest.open('GET', url);
	httpRequest.onreadystatechange = function () { AjaxResult(place); };
	httpRequest.send(null);
}

function AjaxResult(place)
{
	if (httpRequest.readyState == 4)
	{
		if(httpRequest.status == 200)
		{
			var oPlace = document.getElementById(place);
			if (oPlace)
			{
				oPlace.innerHTML = httpRequest.responseText;
				if (document.getElementById('AjaxMessageText') && document.getElementById('AjaxMessageText').value.length)
				{
					var tmp = document.getElementById('AjaxMessageText').value;
					document.getElementById('AjaxMessageText').id = '';
					alert(tmp);
				}
			}
			
			$(document).ready(function(){
				$('.mapclass').click(function(){
					ShowMap2($(this).attr('onmouseover'),'onclick');
				});
				$('.mapclass').mouseover(function(){
					ShowMap2($(this).attr('onmouseover'),'onmouseover');
				});
				$('.mapclass').mouseout(function(){
					ShowMap2($(this).attr('onmouseover'),'onmouseout');
				});
			});
			HpSearchSetSubcategory(false);
		}
	}
}

function HpSearchBoxChangeMap(region)
{
	var url = '/?cmd=hp-search-map&region='+region;
	AjaxLoader(url, 'HpSearchBoxMap');
}

var HpSearchLastCategory = 0;
function HpSearchSetSubcategory(clean)
{
	var category = document.getElementById('HpSearchCategory');
	
	if (!category)
		return;
	
	if (clean)
	{
		if (items = document.getElementsByTagName('INPUT'))
		{
			for (i = 0; i < items.length; i++)
			{
				if (items[i].rel == 'hpsearchsubcategory')
					items[i].checked = false;
			}
		}
	}
	
	if (HpSearchLastCategory)
	{
		if (oldDiv = document.getElementById('HpSearchSubcategory' + HpSearchLastCategory))
		{
			oldDiv.style.display = "none";
		}
	}
	
	if (div = document.getElementById('HpSearchSubcategory' + category.value))
		div.style.display = "";
	
	if (category.value == '1' || category.value == '2')
	{
		document.getElementById('HpSearchOwnership').style.display = "";
		
		if (category.value == '1')
			document.getElementById('HpSearchDisposition').style.display = "none";
		else
			document.getElementById('HpSearchDisposition').style.display = "";
	}
	else
	{
		document.getElementById('HpSearchOwnership').style.display = "none";
		document.getElementById('HpSearchDisposition').style.display = "none";
	}
	
	HpSearchLastCategory = category.value;
}


function ContackFormCheckbox(id, show)
{
	document.getElementById(id).style.display = show ? '' : 'none';
}


var lastBoxEstatixUserI = 1;
function BoxEstatixUser()
{
	var tmp = lastBoxEstatixUserI + 1;
	
	var first = document.getElementById('BoxEstatixUser1');
	var box = document.getElementById('BoxEstatixUser'+lastBoxEstatixUserI );
	var next = document.getElementById('BoxEstatixUser'+(lastBoxEstatixUserI + 1) );
	
	if (box && next)
	{
		box.style.display = 'none';
		next.style.display = '';
		lastBoxEstatixUserI = lastBoxEstatixUserI + 1;
	}
	else if (box && first)
	{
		box.style.display = 'none';
		first.style.display = '';
		lastBoxEstatixUserI = 1;
	}
}

var lastBoxEstatixPropertyI = 1;
function BoxEstatixProperty()
{
	var tmp = lastBoxEstatixPropertyI + 1;
	
	var first = document.getElementById('BoxEstatixProperty1');
	var box = document.getElementById('BoxEstatixProperty'+lastBoxEstatixPropertyI );
	var next = document.getElementById('BoxEstatixProperty'+(lastBoxEstatixPropertyI + 1) );
	
	if (box && next)
	{
		box.style.display = 'none';
		next.style.display = '';
		lastBoxEstatixPropertyI = lastBoxEstatixPropertyI + 1;
	}
	else if (box && first)
	{
		box.style.display = 'none';
		first.style.display = '';
		lastBoxEstatixPropertyI = 1;
	}
}
