
/*
 * vyberie si tabulku z overview a nastavi jej onmouseover, onmouseout
 */
highlightTableRow = function()
{
//if (document.all&&document.getElementById) {
	tbody = document.getElementById('overview_list');
	for (i=0; i<tbody.childNodes.length; i++) {
		node = tbody.childNodes[i];
		if (node.nodeName=='TR') {
			node.onmouseover=function() {
				this.className+=" over";
			}
			node.onmouseout=function() {
				this.className=this.className.replace("over", "");
			}
			node.onclick=function() {
				if (this.cells[1].firstChild.href)
				{
					destination = this.cells[1].firstChild.href;
					location.href = destination;
				}
			}
		}
	}
//}	
}
/*
* kvoli tupemu euru
*/
function _change_currency(obj)
{
	try
	{
		obj.nextSibling.style.display="inline";
		obj.style.display="none";	
	}
	catch(err)
	{
	}
}

function change_currency(obj)
{
	try
	{
		obj.previousSibling.style.display="inline";
		obj.style.display="none";
	}
	catch(err)
	{
	}
	
}



/*
 * vypocita mesacnu splatku hypotekarneho uveru
 */
function hypocalc()
{
	el = document.getElementById('dlzka');
	doba = parseFloat(el.value);
	el = document.getElementById('urok');
	urok = parseFloat(el.value)/1200;
	el = document.getElementById('uver');
	kapital = parseFloat(el.value);
	el = document.getElementById('splatka');
	a = Math.round((kapital*urok)/(1-Math.pow(1/(1+urok), doba*12)));
	if (isNaN(a) || doba<=0 || urok<=0 || kapital<0)
		a = 0;
	el.value = a;
}



/*
 * skrolovanie obrazkov v galerii na detaile projektu/objektu
 */
var pos = 0;

function scrollForward(max, type)
{
    if (pos < max-3)
    {
        for (j=1; j<4; j++)
        {
            anchor = document.getElementById('odkaz'+j);
            anchor.href='uploads/'+type+'/'+photos_main[pos+j];
            anchor.firstChild.src='uploads/'+type+'/'+photos_thumb[pos+j];
        }
        pos++;
    }
}

function scrollBack(type)
{
    if (pos != 0)
    {
        for (j=1; j<4; j++)
        {
            anchor = document.getElementById('odkaz'+j);
            anchor.href='uploads/'+type+'/'+photos_main[(pos+3)-(5-j)];
            anchor.firstChild.src='uploads/'+type+'/'+photos_thumb[(pos+3)-(5-j)];
        }
        pos--;
    }
}

function change_img(type)
{
   video = document.getElementById('videogal');
   if (video)
   {
   	 video.style.display = 'none';
   }
   
   anchor = document.getElementById('main_obrazok');
   anchor.src=type.href;
   //anchor.alt=type.href;
   anchor.style.display = 'block';
}


/*
 * oznaci vsetky checkboxy pri typoch projektov v rozsirenom vyhladavani
 */
function SelectAllProjects()
{
	for (var i = 0; i < 7; i++)
	{
		ch = document.getElementById('projects'+i);
		ch.checked = true;
	}
	return false;
}

function SelectAllEstates()
{
	for (var i = 0; i < 11; i++)
	{
		ch = document.getElementById('projects'+i);
		ch.checked = true;
	}
	return false;
}

function SelectAllServices(max)
{
	for (var i = 0; i < max; i++)
	{
		ch = document.getElementById('projects'+i);
		ch.checked = true;
	}
	return false;
}



/*
 * odznaci vsetky checkboxy pri typoch projektov v rozsirenom vyhladavani
 */
function DeselectAllProjects()
{
	for (var i = 0; i < 7; i++)
	{
		ch = document.getElementById('projects'+i);
		ch.checked = false;
	}
	return false;
}

function DeselectAllEstates()
{
	for (var i = 0; i < 11; i++)
	{
		ch = document.getElementById('projects'+i);
		ch.checked = false;
	}
	return false;
}

function DeselectAllServices(max)
{
	for (var i = 0; i < max; i++)
	{
		ch = document.getElementById('projects'+i);
		ch.checked = false;
	}
	return false;
}



function ChangeCities(changeDistrict)
{
	if (changeDistrict)
	{
		sel = document.getElementById('districtSelect');
		if (sel.options[sel.selectedIndex].value != '')
        	xajax_getCities(sel.options[sel.selectedIndex].value, 0);
	}
	else
	{
		sel = document.getElementById('regionSelect');
		if (sel.options[sel.selectedIndex].value != '')
        	xajax_getCities(0, sel.options[sel.selectedIndex].value);
	}
}



function ChangeDistricts()
{
	sel = document.getElementById('regionSelect');
	if (sel.options[sel.selectedIndex].value != '')
        xajax_getDistricts(sel.options[sel.selectedIndex].value);    
    ChangeCities(false);
}



function getElementsByClassName(searchClass, node, tag)
{
	var classElements = new Array();
	if (node == null)
	{
		node = document;
	}
	if (tag == null)
	{
		tag = '*';
	}
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
	for (var i = 0, j = 0; i < elsLen; i++)
	{
		if (pattern.test(els[i].className))
		{
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}



function AddRegion()
{
	no_item = document.getElementById('items_regions_0');
	if (no_item.className.indexOf('hidden') < 0)
	{
		no_item.className+=' hidden';
	}
	
	sel = document.getElementById('regionSelect');
	if (sel.options[sel.selectedIndex].text != '')
	{
		if (document.getElementById('items_regions_'+sel.options[sel.selectedIndex].value) == null)
		{
			box = document.getElementById('box_regions');
			div = document.createElement('div');
			div.innerHTML = '<span>'+sel.options[sel.selectedIndex].text+'</span> <a href="" onclick="return DeleteRegion(\'items_regions_'+sel.options[sel.selectedIndex].value+'\')"></a><input type="hidden" name="region[]" value="'+sel.options[sel.selectedIndex].value+'" /><div class="clear"></div>';
			div.className = 'items';
			div.id = 'items_regions_'+sel.options[sel.selectedIndex].value;
			box.appendChild(div);
		}
	}
	return false;
}


function DeleteRegion(id)
{
	// zmaze danu polozku
	del_item = document.getElementById(id);
	if (del_item != null)
	{
		box = document.getElementById('box_regions');
		box.removeChild(del_item);
		
		// prida info ze nie je zvoleny ziaden region
		items = getElementsByClassName('items', box);
		if(items.length == 0)
		{
			no_item = document.getElementById('items_regions_0');
			no_item.className = no_item.className.replace('hidden', '');
		}
	}
	
	return false;
}



function AddDistrict()
{
	no_item = document.getElementById('items_districts_0');
	if (no_item.className.indexOf('hidden') < 0)
	{
		no_item.className+=' hidden';
	}
	
	sel = document.getElementById('districtSelect');
	if (sel.options[sel.selectedIndex].text != '')
	{
		if (document.getElementById('items_districts_'+sel.options[sel.selectedIndex].value) == null)
		{
			box = document.getElementById('box_districts');
			div = document.createElement('div');
			div.innerHTML = '<span>'+sel.options[sel.selectedIndex].text+'</span> <a href="" onclick="return DeleteDistrict(\'items_districts_'+sel.options[sel.selectedIndex].value+'\')"></a><input type="hidden" name="district[]" value="'+sel.options[sel.selectedIndex].value+'" /><div class="clear"></div>';
			div.className = 'items';
			div.id = 'items_districts_'+sel.options[sel.selectedIndex].value;
			box.appendChild(div);
		}
	}
	
	return false;
}


function DeleteDistrict(id)
{
	// zmaze danu polozku
	del_item = document.getElementById(id);
	if (del_item != null)
	{
		box = document.getElementById('box_districts');
		box.removeChild(del_item);
		
		// prida info ze nie je zvoleny ziaden okres
		items = getElementsByClassName('items', box);
		if(items.length == 0)
		{
			no_item = document.getElementById('items_districts_0');
			no_item.className = no_item.className.replace('hidden', '');
		}
	}
	return false;
}



function AddCity()
{
	no_item = document.getElementById('items_cities_0');
	if (no_item.className.indexOf('hidden') < 0)
	{
		no_item.className+=' hidden';
	}
	
	sel = document.getElementById('citySelect');
	if (sel.options[sel.selectedIndex].text != '')
	{
		if (document.getElementById('items_cities_'+sel.options[sel.selectedIndex].value) == null)
		{
			box = document.getElementById('box_cities');
			div = document.createElement('div');
			div.innerHTML = '<span>'+sel.options[sel.selectedIndex].text+'</span> <a href="" onclick="return DeleteCity(\'items_cities_'+sel.options[sel.selectedIndex].value+'\')"></a><input type="hidden" name="city[]" value="'+sel.options[sel.selectedIndex].value+'" /><div class="clear"></div>';
			div.className = 'items';
			div.id = 'items_cities_'+sel.options[sel.selectedIndex].value;
			box.appendChild(div);
		}
	}
	
	return false;
}


function DeleteCity(id)
{
	// zmaze danu polozku
	del_item = document.getElementById(id);
	if (del_item != null)
	{
		box = document.getElementById('box_cities');
		box.removeChild(del_item);
		
		// prida info ze nie je zvoleny ziaden okres
		items = getElementsByClassName('items', box);
		if(items.length == 0)
		{
			no_item = document.getElementById('items_cities_0');
			no_item.className = no_item.className.replace('hidden', '');
		}
	}
	return false;
}


function changeSpanCurrency(el, currency)
{
	var parent = el.parentNode;
	var childs = getElementsByClassName('price', parent);
	for (i = 0; i < childs.length; i++) {
		var classes = childs[i].className.split(' ');
		if (classes[1] == currency) childs[i].style.display = 'inline';
		else childs[i].style.display = 'none';
	}
	
	return true;
}

function showSKK(el)
{
	changeSpanCurrency(el, 'skk');
	return false;
}

function showEUR(el)
{
	changeSpanCurrency(el, 'eur');
	return false;
}


