function externalLinks() { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel") == "ext_link") 
     anchor.target = "_blank"; 
 } 
}



function messageAnswer(messageId, messageTitle, parentMessageInfo){
	document.getElementById('input_message').innerHTML = messageTitle + ": <br />" + parentMessageInfo;
	document.getElementById('parent_message_id').value = messageId;
	return true;
}

function sendForm(id){
	document.getElementById(id).submit();
	return false;
}

//JavaScript Document
function insertIntoField(field,what,rewrite,defaultValue){
  if ((rewrite=='true'&&field.value==defaultValue)||(rewrite=='false'&&field.value=='')) field.value=what;
}

function onclickChange(id,type){
  var element = document.getElementById(id);
  if (type=='radio') element.checked=true;
  else if (type=='field') element.focus();
}

function changeImage(source, width, height){
	var elem = document.getElementById('bigImageForChange');
	elem.src = source;
	return false;
}

function advertMainSearch(type){
	
	for (var i=0;i<3;i++){
		
		var elIt = document.getElementById("advert_main_item_"+i);
		var el = document.getElementById("advert_main_search_"+i);
		if (i == type) {
			el.style.display="block";
			elIt.className="active";
			document.getElementById("rubrika"+i).focus();
		}
		else {
			el.style.display="none";
			elIt.className="";
		}
		
	}
	
	return false;
}

/*
Funkce se pouziva u selectBoxu. 
Zobrazi ci schova what
*/
function onTypeChange(value,what,compare) {
		for (i in what){
			if (value == compare) { 
				if (window.innerHeight) { // mozilla + opera
					document.getElementById(what[i]).style.display = "table-row";
				} else { // explorer (nepodporuje v css hodnotu table-row)
					document.getElementById(what[i]).style.display = "block";
				}
			}
			else { 
				document.getElementById(what[i]).style.display = "none";
			}
		}
}

function showOrHideInTable(id,tr){
	var el = document.getElementById(id);
	
	var hide = 0;
	
	if (el.style.display=="table-row"||
			el.style.display=="block"||
			el.style.display=="table-cell") 
				hide=1;
	
	if (hide == 0){
		if (tr == 1){
			if (window.innerHeight) { // mozilla + opera
				el.style.display = "table-row";
			} else { // explorer (nepodporuje v css hodnotu table-row)
				el.style.display = "block";
			}
		}
		else {
			if (window.innerHeight) { // mozilla + opera
				el.style.display = "block";
			} else { // explorer (nepodporuje v css hodnotu table-row)
				el.style.display = "block";
			}
		}
	}
	else 
		el.style.display = "none";
	
}

/*
Hlaska pro odkliknuti
*/
function confirmDeleteUrlText(url, text) {
	if (confirm(text)) {
		window.location = url;
	}
}

function hideOrShow(id,type){
	
	if (type==undefined) type="inline";
	
	var show = document.getElementById(id);
	
	if (show == null) return;
	
	if (show.style.display=='none') show.style.display=type;
	else show.style.display="none";
}

function switchId(id,idh){
	hideOrShow(id);
	hideOrShow(idh);
	
	return false;
}
function insertData(select,idTo,suffix){
	var value = select[select.selectedIndex].value;
	var text = select[select.selectedIndex].text;
	
	if (suffix!=undefined) text += " "+suffix;
	
	var el = document.getElementById(idTo);

	if (el.innerHTML == ""){
		el.value = text;
	} else
		el.innerHTML = text;
}


function changeCities(idArea){
	$.ajax({
			url: 'include/cities.php?id='+idArea,
			type: 'GET',
			dataType: 'xml',
			timeout: 1000,
			error: function(){
				alert('Error loading XML document');
			},
			success: function(xml){
				$('#advert_cities_to_change').empty();
				$('#advert_cities_to_change1').empty();
				$('#advert_cities_to_change1').append("<option value=\"\"></option>");

				$(xml).find('city').each(function(){
					var name = $(this).attr("name");
					var id = $(this).attr("id");

					$('#advert_cities_to_change').append("<option value=\""+id+"\">"+name+"</option>");
					$('#advert_cities_to_change1').append("<option value=\""+id+"\">"+name+"</option>");
					});
			}
	});
}

/*
 * pridani odkazu k oblibenym
 */
function AddFavorite(linkObj,addUrl,addTitle)
{
  if (document.all && !window.opera)
  {
    window.external.AddFavorite(addUrl,addTitle);
    return false;
  }
  else if (window.opera && window.print)
  {
    linkObj.title = addTitle;
    return true;
  }
  else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))
  {
    if (window.confirm('Přidat oblíbenou stránku jako nový panel?'))
    {
      window.sidebar.addPanel(addTitle,addUrl,'');
      return false;
    }
  }
  window.alert('Po potvrzení stiskněte CTRL-D,\nstránka bude přidána k vašim oblíbeným odkazům.');
  return false;
} 

// character counter for input[type=text] and textarea
$(function($) {
	
	$('input[type=text][chars], textarea[chars]').keyup(function(){
		// add character counter
		var chars = $(this).attr('chars');
		var empty = chars - $(this).val().length;
		if( empty > 0) {
			$(this).next().eq(0).empty().append(empty).css('color', 'black');
		} else {
			$(this).next().eq(0).empty().append(0).css('color', 'red');
			$(this).val($(this).val().substring(0, chars));
		}	
	}).keyup();
});


$(function($){
		$(document).scroll(function(){
			var height = Math.max($(document).height(), $(window).height());
			$('.reklama.left, .reklama.right').css('top', ($(window).scrollTop() + 60) + 'px' );
			
		});
});

$(document).ready(function() {
	$('table.western').hide();
	$('table.jezdectvi tbody tr:last td, table.western tbody tr:last td').addClass('no-bottom-line');
});

function switchTableJezdectvi(obj, show, hide) {
		obj = obj.parentNode.parentNode.parentNode;
		
		$('table' + hide, obj).hide();
		$('table' + show, obj).show();
		$('h2 ' + show, obj).addClass('active');
		$('h2 ' + hide, obj).removeClass('active');
}
