// JavaScript Document

//------------------------------------------
//  Zobrazeni popup okna s chybou
//------------------------------------------
function alertPopup(s)
{
	var x = $('<div id="popup_error"><h1>Chyba</h1>' + s.replace('\n', '<br />') + '<div class="clear"></div><input type="button" name="close" value="zavřít" class="fr" onclick="$(\'#popup_error\').remove();" /></div>');
	x.appendTo('body');
	x.center();
	x.show();

	return false;
}

function ControlVal( element, ealert, etype, evalue )
{
  	var etest = false;
	
	// type of num //
	if( etype == "checkbox" )
	{
		if( element.checked ) etest = true;
	}
	else if( etype == "numeric" )
	{
		if( element.value > evalue ) etest = true;
	}
	else if( etype == "text" )
	{
		if( element.value.length > evalue ) etest = true;
	}
	else if( etype == "email" )
	{
		re = new RegExp("^([a-zA-Z0-9]{1})+[a-zA-Z0-9_\.\-]+[@]{1}([^.][a-zA-Z0-9_\.\-]+[.])+[a-z]{2,3}$");
		etest = re.test( element.value );
	}
	else if( etype == "phone" )
	{
		if( element.value > 10000000 ) 
		{
			if( element.value.length > 8 ) etest = true;
		}
	}
	else if( etype == "date" )
	{
		if( ( ealert = IsDate( element ) ) == true ) etest = true;
	}
	else
	{
		etest = true;
	}
	
	
	if( etest == false )
	{
		if( ealert != "" )
		{
			alert( ealert );
		}

		element.focus();
	}
	
	return etest;
}



function trimAll(sString)
{
  while (sString.substring(0,1) == ' ')
  {
    sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ')
  {
    sString = sString.substring(0,sString.length-1);
  }
  return sString;
}



function keyWords()
{
  var hRef1 = '<a href="';
  var hRef2 = '">';
  var hRef3 = '<\/a>';

   ReplaceContent( hRef1, hRef2, hRef3, 250 ) 
}

function keyWordsFromPop()
{
  var hRef1 = '<a href="#" onClick="window.parent.location.href=\'http://www.vyletnik.cz';
  var hRef2 = '\';">';
  var hRef3 = '<\/a>';

  ReplaceContent( hRef1, hRef2, hRef3, 5 )
}


function novyokno( odkaz )
{
    try
	{
		var test;
		
		test = ! window.open( odkaz );
		return test;
	}
	
	catch (e)
	{
		alert( "Při otvírání nového okna došlo k vnitřní chybě JavaScriptu. Zkuste povolit otevírání nových oken nebo kontaktujte správce webu! Odkaz se otevře ve stávajícím okně" );
		return true;
	}
}


function ReplaceContent( hRef1, hRef2, hRef3, cnt )
{

  var nahrad = '';

  var idTxt = getObj('idClanek');
  var txt = idTxt.innerHTML;

  if ( txt.length > cnt )
  {
  for( c = 0; c < linky.length; c++ )
  {
    vyrazy[c] = trimAll( vyrazy[c] );
    if( txt.indexOf( vyrazy[c] ) > -1 )
    {
      var arrTMP = txt.split( vyrazy[c] );
      txt = '';
      nahrad = '';
      for( i = 1; i <= arrTMP.length; i++ )
      {
        txt = txt + arrTMP[i-1];
        if ( !( i == arrTMP.length ) )
        {
          var add = '';
          var ctrl = false;
          for ( k = 0; k < 20; k++ )
          {
            if ( !( arrTMP[i].substring(0,1) == ' ' || arrTMP[i].substring(0,1) == '<' || arrTMP[i].substring(0,1) == '' || arrTMP[i].substring(0,1) == ',' || arrTMP[i].substring(0,1) == '.' || arrTMP[i].substring(0,1) == '"' || arrTMP[i].substring(0,1) == "'" || arrTMP[i].substring(0,1) == "(" || arrTMP[i].substring(0,1) == ")" || arrTMP[i].substring(0,1) == "&" || arrTMP[i].substring(0,1) == "\n" || arrTMP[i].substring(0,1) == "\t" ) )
            {
              ctrl = true;
              add = add + arrTMP[i].substring(0,1);
            }
            else
            {
              ctrl = false;
            }
            if ( ctrl )
            {
              arrTMP[i] = arrTMP[i].substring(1);
            }
          }
          nahrad = hRef1+linky[c]+hRef2+vyrazy[c]+add+hRef3;
          //alert ( nahrad );
          txt = txt + nahrad;
        }
      }
    }
  }
  }
  idTxt.innerHTML = txt;

}


function chnageOptions(formName)
{
  var sMenu = getObj(formName);
  var selRegion = sMenu.region.options[sMenu.region.selectedIndex].value;
  alert(selRegion);
}


function chng_opt_obl(region_v) {

  with (document.form_new_log || document.register_search_form) {

  kat=eval(region_v);

  while (kat.length < oblast.options.length)

  oblast.options[(oblast.options.length-1)]=null;

  for (i=0; i<kat.length; i++) {

      eval("oblast.options[i]=new Option"+kat[i]);

  }
}

}



function keyWordsFromComment(elem_id)
{
  var hRef1 = '<a href="';
  var hRef2 = '">';
  var hRef3 = '<\/a>';

  ReplaceContentComment( elem_id, hRef1, hRef2, hRef3, 5 )
}


function ReplaceContentComment( elem_id, hRef1, hRef2, hRef3, cnt )
{

  var nahrad = '';

  var idTxt = getObj(elem_id);
  var txt = idTxt.innerHTML;

  if ( txt.length > cnt )
  {
  for( c = 0; c < linky.length; c++ )
  {
    vyrazy[c] = trimAll( vyrazy[c] );
    if( txt.indexOf( vyrazy[c] ) > -1 )
    {
      var arrTMP = txt.split( vyrazy[c] );
      txt = '';
      nahrad = '';
      for( i = 1; i <= arrTMP.length; i++ )
      {
        txt = txt + arrTMP[i-1];
        if ( !( i == arrTMP.length ) )
        {
          var add = '';
          var ctrl = false;
          for ( k = 0; k < 20; k++ )
          {
            if ( !( arrTMP[i].substring(0,1) == ' ' || arrTMP[i].substring(0,1) == '<' || arrTMP[i].substring(0,1) == '' || arrTMP[i].substring(0,1) == ',' || arrTMP[i].substring(0,1) == '.' || arrTMP[i].substring(0,1) == '"' || arrTMP[i].substring(0,1) == "'" || arrTMP[i].substring(0,1) == "(" || arrTMP[i].substring(0,1) == ")" || arrTMP[i].substring(0,1) == "&" || arrTMP[i].substring(0,1) == "\n" || arrTMP[i].substring(0,1) == "\t" ) )
            {
              ctrl = true;
              add = add + arrTMP[i].substring(0,1);
            }
            else
            {
              ctrl = false;
            }
            if ( ctrl )
            {
              arrTMP[i] = arrTMP[i].substring(1);
            }
          }
          nahrad = hRef1+linky[c]+hRef2+vyrazy[c]+add+hRef3;
          //alert ( nahrad );
          txt = txt + nahrad;
        }
      }
    }
  }
  }
  idTxt.innerHTML = txt;

}


//------------------------------------------
//  Vyber elementu
//------------------------------------------
function g(id)
{
	return window.document.getElementById(id);
}


//------------------------------------------
//  Kontrola zda je prvek typu Array
//------------------------------------------
function isArray(obj) {
   if (obj.constructor.toString().indexOf("Array") == -1)
      return false;
   else
      return true;
}



var tbl_element;
function addTableRow(table_id, count_by_id)
{
	var table_element = window.document.getElementById(table_id);
	var newrow = table_element.insertRow(-1);
	var rows_count = 0;
	var row_id = '';
	if (count_by_id == false) {
		rows_count = (table_element.rows.length-4)+1;
	} else {
		for (var i=0; i < table_element.rows.length; i++) {
			if (table_element.rows[i].id != null && table_element.rows[i].id != "") {
				var id = parseInt(table_element.rows[i].id.replace("o_", ""));
				if (id >= rows_count) {
					rows_count = id;
				}
			}
		}
		rows_count++;
		row_id = 'o_'+rows_count;
	}
	//var newrow = window.document.createElement("tr");
	newrow.id = row_id;
	
	var newcol1 = window.document.createElement("td");
	var newinput = window.document.createElement("input");
	newinput.name = "odpoved["+rows_count+"]";
	newinput.size = 60;
	newinput.value = "";
	
	var newcol2 = window.document.createElement("td");
	newcol2.style.textAlign = "center";
	var newcheckbox = window.document.createElement('input');
	newcheckbox.type = "checkbox";
	newcheckbox.name = "odpoved_pravdiva["+rows_count+"]";
	
	newcol1.appendChild(newinput);
	newcol2.appendChild(newcheckbox);
	
	newrow.appendChild(newcol1);
	newrow.appendChild(newcol2);
	
	//table_element.appendChild(newrow);
	tbl_element = table_element;
}


//------------------------------------------
//  Zatrhnuti skupiny elementu
//------------------------------------------
function checkPack(ids, check, disable, controlCheck)
{
    if (typeof(disable) == "undefined") disable = true;
    if (typeof(controlCheck) == "undefined") controlCheck = false;

	for (var i = 0; i < ids.length; i++) {
		if (!controlCheck) {
		    checkId(ids[i], check);
		}
		if (disable) setDisabled(ids[i], check);
	}

	return true;
}


//------------------------------------------
//  Kontroluje zatrhnuti skupiny
//------------------------------------------
function controlCheckingPack(id, array)
{
    if (isChecked(id)) {
        checkPack(array, false, true, true);
    } else {
        checkPack(array, true, true, true);
    }

    return true;
}

//------------------------------------------
//  Zatrhnuti elementu
//------------------------------------------
function checkId(id, check)
{
	if (window.document.getElementById(id) != null) {
		if (check == true) {
			window.document.getElementById(id).checked = "checked";
		} else {
			window.document.getElementById(id).checked = "";
		}
	}
}

//------------------------------------------
//  Nastaveni vlastnosti disabled
//------------------------------------------
function setDisabled(id, disabled)
{
    if (g(id) != null) {
		if (disabled == true) {
			g(id).disabled = true;
		} else {
			g(id).disabled = false;
		}
		tbl_element = g(id);
	}

	return true;
}

//------------------------------------------
//  Kontrol na zatrhnuti elementu
//------------------------------------------
function isChecked(id)
{
	if (window.document.getElementById(id) != null) {
		if (window.document.getElementById(id).checked == "") {
			return false;
		} else {
			return true;
		}
	} else {
		return null
	}
}

//------------------------------------------
//  Nastaveni vlastnosti display
//------------------------------------------
function setDisplay(id, display)
{
	if (window.document.getElementById(id) != null) {
		if (!display) {
			window.document.getElementById(id).style.display = "none";
		} else {
			window.document.getElementById(id).style.display = "";
		}
	}
}


//------------------------------------------
//  Kontrola na zobrazeni prvku (display)
//------------------------------------------
function isDisplayed(id)
{
	if (g(id)) {
		if (g(id).style.display != "none") {
			return true;
		} else {
			return false;
		}
	}

	return false;
}


//------------------------------------------
//  Skryti elementu dle ID
//------------------------------------------
function hideElementById(id)
{
    if (isArray(id)) {
        for (var i = 0; i < id.length; i++) {
            if (g(id[i])) {
                g(id[i]).style.display = "none";
            }
        }
    } else {
        if (g(id)) {
            g(id).style.display = "none";
        }
    }
}


//------------------------------------------
//  Zmena vlastnosti display
//------------------------------------------
function changeDisplay(id)
{
	if (isDisplayed(id)) {
		g(id).style.display = "none";
	} else {
		g(id).style.display = "";
	}
}


//------------------------------------------
//  Prepinani display
//------------------------------------------
function swapElementDisplay(enabled_id, id2, enabled_text_id, disabled_text_id)
{
    var setBold = false;
    if ((typeof(enabled_text_id) != "undefined") && (typeof(disabled_text_id) != "undefined")) {
        setBold = true;
    }
    if(g(enabled_id) != null && g(id2) != null) {
        setDisplay(enabled_id, true);
        setDisplay(id2, false);

        if (setBold) {
            g(enabled_text_id).style.fontWeight = "bold";
            g(enabled_text_id).style.color = "#FFFFFF";
            g(disabled_text_id).style.fontWeight = "normal";
            g(disabled_text_id).style.color = "#000000";
        }
    }
}

function swapImgType(id, id2){
      document.getElementById(id2).style.background = 'url("../images/mapa/zalozky/hover_no1.jpg") no-repeat';
      document.getElementById(id).style.background = 'url("../images/mapa/zalozky/hover1.jpg") no-repeat;';
}


//------------------------------------------
//  Zmena src elementu obrazku
//------------------------------------------
function swapImages(element, image1, image2)
{
    if (element.src.indexOf(image1) != -1) {
        element.src = image2;
    } else {
        element.src = image1;
    }
}


//------------------------------------------
//  Zmena textu elementu
//------------------------------------------
function swapText(element_id, text1, text2)
{
    if (g(element_id).innerHTML == text1) {
        if (g(element_id).tagName == 'A') {
            g(element_id).title = text2;
        }
        g(element_id).innerHTML = text2;
    } else {
        if (g(element_id).tagName == 'A') {
            g(element_id).title = text1;
        }
        g(element_id).innerHTML = text1;
    }
}


//------------------------------------------
//  Zmena hodnoty promenne
//------------------------------------------
function swapValues(variable, val1, val2)
{
    if (variable == val1) {
        variable = val2;
    } else {
         variable = val1;
    }
}


//------------------------------------------
//  Odeslani vice formularu najednou (2)
//------------------------------------------
function submitForms(form1, form2)
{
    var length = form2.elements.length - 1;
    for (var i = 0; i <= length; i++) {


        //------------------------------------------
        //  Je nutno brat vzdy element 0, jelikoz
        //   seznam elementu se zmensuje postupne
        //------------------------------------------
        form2.elements[0].style.display = "none";
        form1.appendChild(form2.elements[0]);
    }
}


//------------------------------------------
//  Animovane zobrazeni/skryti elementu
//------------------------------------------
function CollapsedShowHide(id)
{
    animatedcollapse.toggle(id);
    /*if (g(id).style.display == "none") {
        animatedcollapse.show(id);
    } else {
        animatedcollapse.hide(id);
    }*/
}


//------------------------------------------
//  PHP addslashes
//------------------------------------------
function addslashes(str)
{
    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}


//------------------------------------------
//  Odeslani ajax formulare
//------------------------------------------
function sendAjaxForm(url, formID, attr)
{
    if (typeof(attr) == "undefined") {
        attr = '?';
    } else {
        attr = '?'+attr+'&';
    }

    var str = $('#'+formID).serialize();
    $.post(url+attr+str, function(data){
        alert(data);
    }, "json");
}


//------------------------------------------
//  Ulozeni obrazku
//------------------------------------------
function ulozObrazek(kontaktID)
{
    var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de&&de.clientHeight) || document.body.clientHeight;
	
	if (!document.getElementById('wnd_'+kontaktID)) {
	    $('<div class="popupWnd" style="border: 1px solid #000000; background: #fff; width: 600px; height: 200px; position: absolute; text-align: left; top: '+((h-200)/2)+'px; left: '+((w-400)/2)+'px; font-size: 11px;"></div>').attr('id', 'wnd_'+kontaktID).appendTo('body');
	    $('<a href="javascript:;" style="position: absolute; top: 0px; right: 0px;" onclick="closeWnd(\''+kontaktID+'\');">Close</a>').appendTo('#wnd_'+kontaktID);
	    $.post('/soutez_admin_ajax.php?kontaktID='+kontaktID, function(data){
	        $('#wnd_'+kontaktID).html($('#wnd_'+kontaktID).html()+data);
	    });
	} else {
	    $('#wnd_'+kontaktID).show();
	}
	
}


//------------------------------------------
//  Zavreni okna
//------------------------------------------
function closeWnd(kontaktID)
{
    $('#wnd_'+kontaktID).hide();
}


//------------------------------------------
//  Volani fce pro kopirovani obrazku
//------------------------------------------
function saveImg(kontaktID, img, region, oblast, misto, popis)
{
    
    $.post('/soutez_admin_ajax.php?kontaktID='+kontaktID+'&img='+img+'&region='+region+'&oblast='+oblast+'&misto='+misto+'&popis='+popis+'', function(data){
        alert(data);
    });
}


//------------------------------------------
//Ovladani poli formulare pro prihlaseni
//------------------------------------------
function LoginInputs(login_id, pass_id, send_button)
{
	$('#'+login_id).blur(function(){
        if ($('#'+login_id).val() == 'Jméno' || $('#'+login_id).val() == '') {
            $('#'+login_id).val('Jméno');
        }
    });
    $('#'+login_id).focus(function(){
        if ($('#'+login_id).val() == 'Jméno') {
            $('#'+login_id).val('');
        }
    });
    $('#'+pass_id).blur(function(){
        if ($('#'+pass_id).val() == 'Heslo' || $('#'+pass_id).val() == '') {
            $('#'+pass_id).val('Heslo');
        }
    });
    $('#'+pass_id).focus(function(){
        if ($('#'+pass_id).val() == 'Heslo') {
            $('#'+pass_id).val('');
        }
    });
    $('#'+send_button).click(function(){
        if ($('#'+login_id).val() == '' || $('#'+pass_id).val() == '') {
            return false;
        }
    });
}


//------------------------------------------
//  Fce vykonavane elementy
//------------------------------------------
var element = '';
$().ready(function(){

    //----------------------------------------------
    // Prepinani zalozek
    //----------------------------------------------
    $('.switchBookmarks').find('a').each(function() {
        $(this).click(function() {
            var id = $(this).attr('id');
            $('.switchBookmarks').find('a').each(function() {
                if ($(this).attr('id') != id) {
                    $(this).parent().attr('class', '');
                    $('#'+($(this).attr('id').replace('_label', ''))).hide('slow', function() {
                        $('#'+id.replace('_label', '')).show('slow');
                        $('#'+id).parent().attr('class', 'active');
                    });
                }
            })
        });
    });

	//------------------------------------------
    //  Suggestbox
    //------------------------------------------
	var suggestContentLoader = vyletnik.ui.suggest.ContentLoader();
	var suggestPanel = vyletnik.ui.Suggest('#sbi', suggestContentLoader);
	suggestPanel.init();


	$('#footer_send_login').click(function(){
		$('#footer_login_form').submit();
	});
	LoginInputs('footer_login', 'footer_password', 'footer_send_login');
	LoginInputs('login_name', 'login_pass', 'send_login');


    //------------------------------------------
    //  Pole s napovedou
    //------------------------------------------
    $(".help_img").each(function() {
        $(this).easytooltip(this.id+'_help');
    });


    //------------------------------------------
    //  Image zoom
    //------------------------------------------
    /*var options = {
        zoomWidth: 300,
        zoomHeight: 250,
        xOffset: 10,
        yOffset: 0,
        position: "right"
    };
    $(".zoom").jqzoom(options);*/


    //------------------------------------------
    //  Nastaveni mista jako oblibeneho
    //------------------------------------------
    $('.set_favorit_place').click(function(){
    	//location.href = 'http://' + location.host + '/user/?setUserPlace=' + $(this).attr('id');
    });
    $('.set_favorit_place').mouseover(function(){
    	$(this).attr('src', '/images/star.png');
    });
    $('.set_favorit_place').mouseout(function(){
    	$(this).attr('src', '/images/star_blank.png');
    });


    //------------------------------------------
    //  Hodnoceni mist - zobrazovani hvezdicek
    //------------------------------------------
    if ($('#rating').text().length > 0) {
        var rating = $('#rating').text();
        $('.rate').attr('src', '/images/star_blank.png');
        for (var i = 1; i <= rating; i++) {
            $('#img_'+i).attr('src', '/images/star.png');
        }
    } else {
        $('#rating_bar img').mouseover(function() {
            var id_parts = $(this).attr('id').split('_');
            $('.rate').attr('src', '/images/star_blank.png');
            for (var i = 1; i <= id_parts[1]; i++) {
                $('#img_'+i).attr('src', '/images/star.png');
            }
        }).mouseout(function() {
            var id_parts = $(this).attr('id').split('_');
            for (var i = 1; i <= id_parts[1]; i++) {
                $('#img_'+i).attr('src', '/images/star_blank.png');
            }
        });
    }
    
    //------------------------------------------
    //  Hodnoceni mist - vyplneni predchoziho hlasovani
    //------------------------------------------
    if ($('#rating').text().length > 0) {
        var rating = $('#rating').text();
        for (var i = 1; i <= rating; i++) {
            $('#img_'+i).attr('src', '/images/star.png');
        }
    }
    
    //---------------------------------------------------
    // zobrazeni pruhu pro hodnoceni
    //---------------------------------------------------
    $('.i_rate').click(function() {
        $(this).siblings('.rating_strip').toggle("slow");
        return false;
    });
    
    //--------------------------------------------------
    // zobrazeni hvezdicek v pruhu
    //--------------------------------------------------
    $('.rating_strip img').mouseover(function() {
        var id_parts = $(this).parent().attr('class').split('_');
        $('.rate').attr('src', '/images/star_blank.png');
        $(this).attr('src', '/images/star.png');
        for (var i = 1; i <= id_parts[1]; i++) {
            $(this).parent().siblings('.img_'+i).children().attr('src', '/images/star.png');
        }
    }).mouseout(function() {
        $('.rate').attr('src', '/images/star_blank.png');
    });

    //------------------------------------------
    //  Automaticka kontrola formularu
    //------------------------------------------
    $('#controlForm').submit(function(){
    	var elements = new Array();
    	$("input[rel^='control']").each(function(){
    		elements.push($(this).attr('id'));
    	});
    	$("select[rel^='control']").each(function(){
    		elements.push($(this).attr('id'));
    	});
    	$("textarea[rel^='control']").each(function(){
    		elements.push($(this).attr('id'));
    	});
    	return controlForm('controlForm', elements);
    });


    //------------------------------------------
    //  Vkladani poli pro vlozeni souboru
    //------------------------------------------
    $('#addFiles').click(function(){
    	addImagesFields($(this).attr('rel'));
    });


    //------------------------------------------
    //  Nacteni FCKEditoru
    //------------------------------------------
    $("textarea[rel^='fck_text']").each(function(){
    	var text = new FCKeditor($(this).attr('id'));
        text.BasePath   = '/extends/fckeditor/';
        text.Height = '700';
        text.ToolbarSet='Basic';
        text.ReplaceTextarea();
    });


    //------------------------------------------
    //  Odkazy do noveho okna
    //------------------------------------------
    $("a[rel^='open_indow']").each(function(){
    	$(this).click(function(){
    		return !window.open($(this).attr('href'), $(this).attr('title'), 'scrollbars=yes,width=550,height=500');
    	});
    });


    //------------------------------------------
    //  Potvrzeni akce
    //------------------------------------------
    $("input[rel^='accept']").each(function(){
    	$(this).click(function(){
    		return confirm('Opravdu chcete akci provést?');
    	});
    });


    //------------------------------------------
    //  Overovani poli pro provedeni akce
    //------------------------------------------
    if ($('#check').length > 0) {
    	$('#check').val('5');
    	$('#checkmd5').val(md5('5'));
    }
    $("input[rel^='checkrow']").each(function() {
    	$(this).val('5');
	});
    $("input[rel^='checkmd5']").each(function() {
    	$(this).val(md5('5'));
	});


    //------------------------------------------
    //  Ajax reakce na komentar
    //------------------------------------------
    $("a[rel^='reaguj']").each(function() {
    	var reaguj_data = $(this).attr('rel').split('_');
    	if (reaguj_data.length == 5) {
	    	$(this).click(function(){
	    		if ($("div[id^='hiddenform']").length > 0) {
	    			$("div[id^='hiddenform']").each(function(){
	    				$(this).hide('fast');
	    				$(this).remove('fast');
	    			});
	    		}
	    		if ($('#hiddenform_'+reaguj_data[1]).length == 0) {
		    		$.post('/ajax/reaguj.php?item=ajaxformAction&react='+reaguj_data[1]+'&section='+reaguj_data[2]+'&id='+reaguj_data[3]+'&usr='+$('#user_id').val(), function(data){
		        		$('#komentar_'+reaguj_data[1]).append('<div class="hidden" id="hiddenform_'+reaguj_data[1]+'">' + data + '</div>');
		        		$('#hiddenform_'+reaguj_data[1]).show('fast');
		        		$("input[rel^='checkrow']").each(function() {
		        	    	$(this).val('5');
		        		});
		        		$("input[rel^='checkmd5']").each(function() {
		        	    	$(this).val(md5('5'));
		        		});
		        	});
	    		} else {
	    			$('#hiddenform_'+reaguj_data[1]).hide('fast');
	    			$('#hiddenform_'+reaguj_data[1]).remove();
	    		}

	    		return false;
	    	});
    	}
	});


    /*wide_ilayer.ilayer_css();
    if (get_cookie('iLayer') != 'closed') {
    	wide_ilayer.ilayer_show();
    	window.setTimeout(function(){
    		wide_ilayer.ilayer_hide_automatic();
    	}, 9000);
    }
    $('#reklama_right_rectangle').mouseover(function(e){
    	wide_ilayer.ilayer_show();
    });*/
    
    if ($('.i_profil').length > 0) {
        window.setInterval('highlight_profil()', 1000);
    }
    
    //------------------------------------------
	//Kontrola parametru URL - spusteni lightboxu
	//------------------------------------------
	if (window.location.toString().indexOf('fotogalerie') >= 0 && window.location.toString().indexOf('#foto_') >= 0) {
		$('#photolink_' + window.location.hash.replace('#foto_', '')).click();
	}
	
	$("#weather-strip div").css('width', '48px');
});

//------------------------------------------------
//Vlozeni poli pro vkladani obrazku
//@param  id elementu s obsahem inputu
//------------------------------------------------
function addImagesFields(id_div_group)
{
	$('#'+id_div_group).css('margin-left', '12px');
	$('#'+id_div_group+' :last-child').clone().appendTo('#'+id_div_group);
	$('#'+id_div_group+' :last-child').val('');
}


//------------------------------------------------
//  Kontrola formulare
//  @param  id formulare
//  @param  hodnoty pro kontrolu (var1, var2, ...)
//------------------------------------------------
var obj;
function controlForm()
{
    var ret = true;
    var err_string = '';
    if (arguments.length <= 1) {
        return false;
    } else {
        var userForm = $('#'+arguments[0]);
        var arg = new Array();


    	//------------------------------------------
        //  Kontrola argumentu
        //------------------------------------------
    	if (arguments[1].constructor.toString().indexOf("Array") >= 0) {
    		arg = arguments[1];
    	} else {
    		arg = arguments.slice(1, arguments.length - 1);
    	}
        for (var i = 0; i <= arg.length - 1; i++) {
            var element = $('#'+arg[i]);
            if ((element.attr('tagName') == 'INPUT' && element.attr('type') == 'text') || element.attr('tagName') == 'TEXTAREA') {
                if ($('#'+arg[i]).val() == '') {
                    ret = false;
                    if ($('#'+arg[i]+'_label')) err_string += "<br /><b>Chybně vyplněno pole:</b> <span class=\"red_bold\">" + $('#'+arg[i]+'_label').text() + "</span>";
                }
            } else if (element.attr('tagName') == 'INPUT' && element.attr('type') == 'checkbox') {
                if (element.attr('checked') == false) {
                    ret = false;
                    if ($('#'+arg[i]+'_label')) err_string += "<br /><b>Není zatržena volba:</b> <span class=\"red_bold\">" + $('#'+arg[i]+'_label').text() + "</span>";
                }
            } else if (element.attr('tagName') == 'SELECT') {
                if ($('#'+arg[i]+' :selected').val() == '' || typeof($('#'+arg[i]+' :selected').val()) == "undefined") {
                    ret = false;
                    if ($('#'+arg[i]+'_label')) err_string += "<br /><b>Není vybrána hodnota v poli:</b> <span class=\"red_bold\">" + $('#'+arg[i]+'_label').text() + "</span>";
                }
            } else if (element.attr('tagName') == 'INPUT' && element.attr('type') == 'radio') {
                if (typeof(radio) == "undefined") {
                	var radio = new Array();
                }
                if (typeof(radio[element.attr('name')]) == "undefined") {
                	radio[element.attr('name')] = new Array();
                }
                radio[element.attr('name')].push(element.attr('id'));
            } else if (element.attr('tagName') == 'INPUT' && element.attr('type') == 'file') {
            	if ($('#'+arg[i]).val() == '') {
            		if ($('#'+arg[i]+'_label')) err_string += "<br /><b>Nebyl vybrán soubor v poli:</b> <span class=\"red_bold\">" + $('#'+arg[i]+'_label').text() + "</span>";
            		ret = false;
            	} else {


	            	//------------------------------------------
	                //  Kontrola typu obrazku
	                //------------------------------------------
	            	if (element.attr('rel').indexOf('img') >= 0) {
	            		var imgs = Array('jpg', 'jpeg', 'gif', 'png', 'bmp');
	            		if (imgs.indexOf(element.val().split('.').pop().toLowerCase()) < 0) {
	            			if ($('#'+arg[i]+'_label')) err_string += "<br /><b>Pro pole: <span class=\"red_bold\">" + $('#'+arg[i]+'_label').text() + "</span> jsou povoleny pouze soubory: " + imgs.join(', ') + "</b>";
	            			ret = false;
	            		}
	            	}
            	}
            }
        }
    }


    //------------------------------------------
    //  Kontrola skupin radio boxu
    //------------------------------------------
    if (typeof(radio) != "undefined") {
    	for (radio_key in radio) {
    		var empty = true;
    		for (radio_subkey in radio[radio_key]) {
    			if ($('#'+radio[radio_key][radio_subkey]).attr('checked')) {
    				empty = false;
    			}
    		}

    		if (empty) {
    			if ($('#'+radio_key+'_label')) err_string += "<br />Není vybrána hodnota pro : " + $('#'+radio_key+'_label').text();
    		}
    	}
    }


    if (!ret) {
        if (err_string != '') err_string = "<br /><span class=\"red_bold\">Chyby:</span>" + err_string;
        //alert('Některá pole formuláře nejsou správně vyplněna. Zkontroujte si prosím zadaná data a odešlete formulář znovu.' + err_string);
        return alertPopup('Některá pole formuláře nejsou správně vyplněna. Zkontroujte si prosím zadaná data a odešlete formulář znovu.' + err_string);
    }


    return ret;
}


//------------------------------------------------
//  Kontrola formulare
//  @param  id casti pro zobrazeni
//  @param  id casti pr skryti (var1, var2, ...)
//------------------------------------------------
function showTab()
{
    if (arguments.length <= 1) {
        return false;
    } else {


        //------------------------------------------
        //  Skryti elementu
        //------------------------------------------
        for (var i = 1; i <= arguments.length - 1; i++) {
            $('#'+arguments[i]).hide();
            $('#'+arguments[i]+'_label').css("color", "rgb(0, 0, 0)");
        }


        //------------------------------------------
		//  Zobrazeni elementu
		//------------------------------------------
		$('#'+arguments[0]+'_label').css("color", "rgb(255, 255, 255)");
        $('#'+arguments[0]).show();
    }
}


//------------------------------------------------
//Filtrace slov dle parametru @rel
//@param  id nazvu pro filtraci seznamu elementu
//@param  text filtrace
//------------------------------------------------
function filterSelect()
{
	if (arguments.length <= 1) {
        return false;
    } else {
    	var attrib = arguments[0];
    	var filter = arguments[1];
    	//alert(arguments[0] + ' - ' + arguments[1]);
    	$("tr[rel^='" + attrib + "']").each(function(){
    		if ($(this).attr('rel').indexOf(filter) < 0) {
    			$(this).hide();
    		} else {
    			$(this).show();
    		}
    	});
    }
}


//------------------------------------------
//  Kliknuti na ikonku facebooku
//------------------------------------------
function fbs_click() {
    u=location.href;
    t=document.title;
    window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    
    return false;
}


//------------------------------------------
//  Kliknuti na ikonku Google Bookmarks
//------------------------------------------
function gb_click() {
    u=location.href;
    t=document.title;
    window.open('http://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk='+encodeURIComponent(u)+'&title='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
    
    return false;
}


//------------------------------------------
//  MD5 pro JS
//------------------------------------------
function md5(string) {
	 
	function RotateLeft(lValue, iShiftBits) {
		return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
	}
 
	function AddUnsigned(lX,lY) {
		var lX4,lY4,lX8,lY8,lResult;
		lX8 = (lX & 0x80000000);
		lY8 = (lY & 0x80000000);
		lX4 = (lX & 0x40000000);
		lY4 = (lY & 0x40000000);
		lResult = (lX & 0x3FFFFFFF)+(lY & 0x3FFFFFFF);
		if (lX4 & lY4) {
			return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
		}
		if (lX4 | lY4) {
			if (lResult & 0x40000000) {
				return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
			} else {
				return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
			}
		} else {
			return (lResult ^ lX8 ^ lY8);
		}
 	}
 
 	function F(x,y,z) { return (x & y) | ((~x) & z); }
 	function G(x,y,z) { return (x & z) | (y & (~z)); }
 	function H(x,y,z) { return (x ^ y ^ z); }
	function I(x,y,z) { return (y ^ (x | (~z))); }
 
	function FF(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(F(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function GG(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(G(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function HH(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(H(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function II(a,b,c,d,x,s,ac) {
		a = AddUnsigned(a, AddUnsigned(AddUnsigned(I(b, c, d), x), ac));
		return AddUnsigned(RotateLeft(a, s), b);
	};
 
	function ConvertToWordArray(string) {
		var lWordCount;
		var lMessageLength = string.length;
		var lNumberOfWords_temp1=lMessageLength + 8;
		var lNumberOfWords_temp2=(lNumberOfWords_temp1-(lNumberOfWords_temp1 % 64))/64;
		var lNumberOfWords = (lNumberOfWords_temp2+1)*16;
		var lWordArray=Array(lNumberOfWords-1);
		var lBytePosition = 0;
		var lByteCount = 0;
		while ( lByteCount < lMessageLength ) {
			lWordCount = (lByteCount-(lByteCount % 4))/4;
			lBytePosition = (lByteCount % 4)*8;
			lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount)<<lBytePosition));
			lByteCount++;
		}
		lWordCount = (lByteCount-(lByteCount % 4))/4;
		lBytePosition = (lByteCount % 4)*8;
		lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80<<lBytePosition);
		lWordArray[lNumberOfWords-2] = lMessageLength<<3;
		lWordArray[lNumberOfWords-1] = lMessageLength>>>29;
		return lWordArray;
	};
 
	function WordToHex(lValue) {
		var WordToHexValue="",WordToHexValue_temp="",lByte,lCount;
		for (lCount = 0;lCount<=3;lCount++) {
			lByte = (lValue>>>(lCount*8)) & 255;
			WordToHexValue_temp = "0" + lByte.toString(16);
			WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length-2,2);
		}
		return WordToHexValue;
	};
 
	function Utf8Encode(string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	};
 
	var x=Array();
	var k,AA,BB,CC,DD,a,b,c,d;
	var S11=7, S12=12, S13=17, S14=22;
	var S21=5, S22=9 , S23=14, S24=20;
	var S31=4, S32=11, S33=16, S34=23;
	var S41=6, S42=10, S43=15, S44=21;
 
	string = Utf8Encode(string);
 
	x = ConvertToWordArray(string);
 
	a = 0x67452301; b = 0xEFCDAB89; c = 0x98BADCFE; d = 0x10325476;
 
	for (k=0;k<x.length;k+=16) {
		AA=a; BB=b; CC=c; DD=d;
		a=FF(a,b,c,d,x[k+0], S11,0xD76AA478);
		d=FF(d,a,b,c,x[k+1], S12,0xE8C7B756);
		c=FF(c,d,a,b,x[k+2], S13,0x242070DB);
		b=FF(b,c,d,a,x[k+3], S14,0xC1BDCEEE);
		a=FF(a,b,c,d,x[k+4], S11,0xF57C0FAF);
		d=FF(d,a,b,c,x[k+5], S12,0x4787C62A);
		c=FF(c,d,a,b,x[k+6], S13,0xA8304613);
		b=FF(b,c,d,a,x[k+7], S14,0xFD469501);
		a=FF(a,b,c,d,x[k+8], S11,0x698098D8);
		d=FF(d,a,b,c,x[k+9], S12,0x8B44F7AF);
		c=FF(c,d,a,b,x[k+10],S13,0xFFFF5BB1);
		b=FF(b,c,d,a,x[k+11],S14,0x895CD7BE);
		a=FF(a,b,c,d,x[k+12],S11,0x6B901122);
		d=FF(d,a,b,c,x[k+13],S12,0xFD987193);
		c=FF(c,d,a,b,x[k+14],S13,0xA679438E);
		b=FF(b,c,d,a,x[k+15],S14,0x49B40821);
		a=GG(a,b,c,d,x[k+1], S21,0xF61E2562);
		d=GG(d,a,b,c,x[k+6], S22,0xC040B340);
		c=GG(c,d,a,b,x[k+11],S23,0x265E5A51);
		b=GG(b,c,d,a,x[k+0], S24,0xE9B6C7AA);
		a=GG(a,b,c,d,x[k+5], S21,0xD62F105D);
		d=GG(d,a,b,c,x[k+10],S22,0x2441453);
		c=GG(c,d,a,b,x[k+15],S23,0xD8A1E681);
		b=GG(b,c,d,a,x[k+4], S24,0xE7D3FBC8);
		a=GG(a,b,c,d,x[k+9], S21,0x21E1CDE6);
		d=GG(d,a,b,c,x[k+14],S22,0xC33707D6);
		c=GG(c,d,a,b,x[k+3], S23,0xF4D50D87);
		b=GG(b,c,d,a,x[k+8], S24,0x455A14ED);
		a=GG(a,b,c,d,x[k+13],S21,0xA9E3E905);
		d=GG(d,a,b,c,x[k+2], S22,0xFCEFA3F8);
		c=GG(c,d,a,b,x[k+7], S23,0x676F02D9);
		b=GG(b,c,d,a,x[k+12],S24,0x8D2A4C8A);
		a=HH(a,b,c,d,x[k+5], S31,0xFFFA3942);
		d=HH(d,a,b,c,x[k+8], S32,0x8771F681);
		c=HH(c,d,a,b,x[k+11],S33,0x6D9D6122);
		b=HH(b,c,d,a,x[k+14],S34,0xFDE5380C);
		a=HH(a,b,c,d,x[k+1], S31,0xA4BEEA44);
		d=HH(d,a,b,c,x[k+4], S32,0x4BDECFA9);
		c=HH(c,d,a,b,x[k+7], S33,0xF6BB4B60);
		b=HH(b,c,d,a,x[k+10],S34,0xBEBFBC70);
		a=HH(a,b,c,d,x[k+13],S31,0x289B7EC6);
		d=HH(d,a,b,c,x[k+0], S32,0xEAA127FA);
		c=HH(c,d,a,b,x[k+3], S33,0xD4EF3085);
		b=HH(b,c,d,a,x[k+6], S34,0x4881D05);
		a=HH(a,b,c,d,x[k+9], S31,0xD9D4D039);
		d=HH(d,a,b,c,x[k+12],S32,0xE6DB99E5);
		c=HH(c,d,a,b,x[k+15],S33,0x1FA27CF8);
		b=HH(b,c,d,a,x[k+2], S34,0xC4AC5665);
		a=II(a,b,c,d,x[k+0], S41,0xF4292244);
		d=II(d,a,b,c,x[k+7], S42,0x432AFF97);
		c=II(c,d,a,b,x[k+14],S43,0xAB9423A7);
		b=II(b,c,d,a,x[k+5], S44,0xFC93A039);
		a=II(a,b,c,d,x[k+12],S41,0x655B59C3);
		d=II(d,a,b,c,x[k+3], S42,0x8F0CCC92);
		c=II(c,d,a,b,x[k+10],S43,0xFFEFF47D);
		b=II(b,c,d,a,x[k+1], S44,0x85845DD1);
		a=II(a,b,c,d,x[k+8], S41,0x6FA87E4F);
		d=II(d,a,b,c,x[k+15],S42,0xFE2CE6E0);
		c=II(c,d,a,b,x[k+6], S43,0xA3014314);
		b=II(b,c,d,a,x[k+13],S44,0x4E0811A1);
		a=II(a,b,c,d,x[k+4], S41,0xF7537E82);
		d=II(d,a,b,c,x[k+11],S42,0xBD3AF235);
		c=II(c,d,a,b,x[k+2], S43,0x2AD7D2BB);
		b=II(b,c,d,a,x[k+9], S44,0xEB86D391);
		a=AddUnsigned(a,AA);
		b=AddUnsigned(b,BB);
		c=AddUnsigned(c,CC);
		d=AddUnsigned(d,DD);
	}
 
	var temp = WordToHex(a)+WordToHex(b)+WordToHex(c)+WordToHex(d);
 
	return temp.toLowerCase();
}


//------------------------------------------
//  Definice ilayeru
//------------------------------------------
var wide_ilayer = function() {
	return {


		ilayer_css: function() {
			$('#yeti_layer').css({
				'position' : 'absolute',
				'width': '600px',
				'height': '300px',
				'marginLeft' : '-600px',
				'zIndex' : '99999'
			});
		},


		//------------------------------------------
		//  Zobrazeni ilayeru
		//------------------------------------------
		ilayer_show: function() {
			$('#yeti_layer').show();
		},


		//------------------------------------------
		//  Skryti ilayeru - manualni
		//------------------------------------------
		ilayer_hide: function() {
			$('#yeti_layer').hide();
			set_cookie('iLayer', 'closed', 12);
		},


		//------------------------------------------
		//  Skryti ilayeru - automaticke
		//------------------------------------------
		ilayer_hide_automatic: function() {
			$('#yeti_layer').hide();
		}
	};
}();


function iLayerContrent()
{
	return '<script type="text/javascript"><!--//<![CDATA[var m3_u = (location.protocol==\'https:\'?\'https://www.paseo.cz/openads/www/delivery/ajs.php\':\'http://www.paseo.cz/openads/www/delivery/ajs.php\');var m3_r = Math.floor(Math.random()*99999999999);if (!document.MAX_used) document.MAX_used = \',\';document.write ("<scr"+"ipt type=\'text/javascript\' src=\'"+m3_u);document.write ("?zoneid=189");document.write (\'&amp;cb=\' + m3_r);if (document.MAX_used != \',\') document.write ("&amp;exclude=" + document.MAX_used);document.write (document.charset ? \'&amp;charset=\'+document.charset : (document.characterSet ? \'&amp;charset=\'+document.characterSet : \'\'));document.write ("&amp;loc=" + escape(window.location));if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));if (document.context) document.write ("&context=" + escape(document.context));if (document.mmm_fo) document.write ("&amp;mmm_fo=1");document.write ("\'><\/scr"+"ipt>");//]]>--></script><script type="text/javascript" src="http://www.paseo.cz/openads/www/delivery/ajs.php?zoneid=189&amp;cb=88943316547&amp;charset=UTF-8&amp;loc=http%3A//test2.vyletnik.cz/&amp;mmm_fo=1"></script>';
}


function get_cookie(cookie_name)
{
	var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );

	if (results) {
		return (unescape(results[2]));
	} else {
		return null;
	}
}

function set_cookie(c_name, value, expirehours)
{
  var exdate = new Date();
  exdate.setHours(exdate.getHours() + expirehours);
  document.cookie = c_name + "=" + escape(value) + ((expirehours == null) ? "" : ";expires=" + exdate.toGMTString());
}

function nastav_oblibene(id){
    $("#favorit_place_" + id).toggleClass('hidden');
    $("#not_favorit_place_" + id).toggleClass('hidden');
    $.ajax({
        type: "POST",
        data: "id="+id,
        url: "/ajax/set-oblibene.php"
    });
    return false;
}

function rate(id, value, elem)
{
    $.post('/ajax/hodnot.php?id='+id+'&value='+value, function(data){
        /* detail mista */
        if ($('#rating_bar').length > 0) {
            $('#rating_bar img').unbind('mouseout').unbind('mouseover');
            
            $('#rating').text(value);
            $('.rate').attr('src', '/images/star_blank.png');
            for (var i = 1; i <= value; i++) {
                $('#img_'+i).attr('src', '/images/star.png');
            }
        }
        
        if ($('.rating_strip').length > 0) {
            $('.rating_strip').hide('slow');
            
            if (data.length) elem.parent().parent().children('.i_rate').children('span').text(data);
        }
    });
    return true;
}

function highlight_profil()
{
    $('.i_profil').animate({"opacity": "toggle"}, { duration: "slow" });
}

function radit(key)
{
    $('#form').append('<input type=\'hidden\' name=\'radit\' value=\'' + key + '\' />').submit();
}
