var CurrentActiveBlock = null;
var CurrentState = 1;

function openBlock(id)
{
	if (document.getElementById)
	{
		var srcBlock = document.getElementById(id);	
		if (srcBlock)
		{
			if (CurrentActiveBlock)
			{
				CurrentActiveBlock.className = CurrentActiveBlock.className.replace(' active_d','');
			}
	
			if (srcBlock !== CurrentActiveBlock)
			{
				srcBlock.className = srcBlock.className.replace(' active_d','') + ' active_d';
				CurrentActiveBlock = srcBlock;
			}
			else
			{
				CurrentActiveBlock = null;
			}
			return false;
		}
	}
	return true;
}

function $(id)
{
    return document.getElementById(id);
}

var UnitStates = [];
function AddUnit(state, id)
{
	UnitStates[id] = state;
}

function ShowRentUnit()
{
	ShowUnitByState(2);
}

function ShowSaleUnit()
{
	ShowUnitByState(1);
}

function HideRentUnit()
{
	HideUnitByState(2);
}

function HideSaleUnit()
{
	HideUnitByState(1);
}

function ShowUnitByState(state)
{
	CurrentState = CurrentState | state;
	for (id in UnitStates)
	{		
		if (UnitStates[id] & CurrentState)
		{
			$('unit' + id).style.display = "block";
		}
		else
		{
			// $('unit' + id).style.display = "none";
		}			
	}
}

function HideUnitByState(state)
{
	CurrentState = CurrentState & ~state;
	for (id in UnitStates)
	{		
		if (! (UnitStates[id] & CurrentState))
		{
			$('unit' + id).style.display = "none";
		}
	}
}

function InArray(arr, item)
{
	for (var i = 0; i < arr.length; i++)
	{
		if (arr[i] == item)
		{
			return true;
		}
	}
	return false;
}
