<!--

	function returnObjById( id ) {
	    if (document.getElementById)
	        var returnVar = document.getElementById(id);
	    else if (document.all)
	        var returnVar = document.all[id];
	    else if (document.layers)
	        var returnVar = document.layers[id];
	    return returnVar;
	}
	
	function hide ( div ) {
		returnObjById(div).style.display = "none";
	}
	
	function show ( div ) {
		returnObjById(div).style.display = "";
	}

	function updateSearch ( div ) {
		var div = returnObjById(div);
		// byty
		if (div.value == '4') {
			show('forFlats');
			if ($("#rychle-hledani").is(':checked')) {
				$(".podrobne").hide();
			}
		} else {
			hide('forFlats');
		}
		
		// domy a vily
		if (div.value == '6') {
			show('forHouses');
			if ( returnObjById('type').value == '2' ) {
				show('equiph');
			} else {
				hide('equiph');
			}
		} else {
			hide('forHouses');
		}
		
		// pozemky
		if (div.value == '3') {
			show('forLands');
		} else {
			hide('forLands');
		}
		
		// chaty
		if (div.value == '10') {
			show('forChaty');
		} else {
			hide('forChaty');
		}
		
		
	}
	
	var okresy_pro_kraje = function (kraj, okres, callback) {
		$.getJSON('/okresy_pro_kraje.php', {'kraj' : kraj},
		function (data) {
			var text = '';
			for (var i = 0; i <= data.length - 1; i++) {
				text += '<option value="'+ data[i].kod_okresu +'" '; 
				if (okres && (okres == data[i].kod_okresu)) text += 'selected';
				text +=' title="'+ data[i].seo_url +'">'+ data[i].zkratka_okresu +'</option>';
			}
			$("#district_id").html(text);
			if (typeof callback == 'function'){
				callback.call(this, data);
		    }
		});
		return false;
	}
	
	$(function() {

		$("#rychle-hledani").click(function() {
			$("#search-form #forFlats").find("input").each(function () {
				$(this).val('');
				$(this).attr('checked', false);
				$(this).attr('selected', false);
			});
			$("#search-form #forFlats").fadeOut("slow");
			$("#search-form tr td").fadeIn("slow");
		}); 
		
		$("#podrobne-hledani").click(function() {
			$("#search-form tr td").fadeIn("slow");
			$("#search-form #forFlats").fadeIn("slow");
			$("#search-form #forFlats .rychle").hide();
		}); 
		
		$("input.cena").change(function(){
			val = $(this).val();
			pom = '';
			j = 0;
			for (var i = val.length - 1; i >= 0; i--) {
				if (val[i] != ' ') {
					j = j + 1;
					pom += val[i];
					if (((j % 3) == 0)) { pom += ' ';}
					
				}
			}
			$(this).val(pom.split("").reverse().join(""));
		});
    });
	
	$(document).ready(function () {
		
		$("form[name='contactForm']").submit(function () {
			// email
			var error = '';
			if ($(this).find("input[name='no-email']").is(':checked') == false) {
				var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			   	if(reg.test($(this).find('input[name="email"]').val()) == false)
			   	{
			   		error += 'Špatný formát e-mailové adresy.\n';
			   	}
			}
		 	// tel
			var reg = /^([0-9 \+]){8,100}$/;
		   	if(reg.test($(this).find('input[name="phone"]').val()) == false)
		   	{
		   		error += 'Zadejte telefonní číslo.\n';
		   	}
		   	if (error != '') { 
		   		alert(error);
		   		return false;
		   	} else {
		   		return true; 
		   	}
		});
		
	}); 
	
	
// -->
