var ActiveMenu='';
var HiliteMenu='';
var	MenuTimer = null;
var	TimerStart = null;
var	TimerFlag = false;

var ActiveMenu_opac= new Array();
var HiliteMenu_opac= new Array();
var	MenuTimer_opac =  new Array();
var	TimerStart_opac = new Array();
var	TimerFlag_opac =  new Array();

function unescapeHTML(html) {
    var htmlNode = document.createElement("DIV");
    htmlNode.innerHTML = html;
    if(htmlNode.innerText)
        return htmlNode.innerText;// IE
    return htmlNode.textContent;// FF
}

function MM_callJS(jsStr) { //v2.0
    return eval(jsStr)
}

function MM_findObj(n, d) { //v4.01
    var p,i,x;
    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n);
    return x;
}



function RunFoo()
{
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="490" height="250">\n');
    document.write('<param name="movie" value="/media/Flash/test.swf" />\n');
    document.write('<param name="quality" value="high" />\n');
    document.write('<param name="wmode" value="transparent" />\n');
    document.write(' <param name="allowScriptAccess" value="always" />\n');
    document.write('<embed allowScriptAccess="always" wmode="transparent" src="/media/Flash/test.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="490" height="250"></embed>\n');
    document.write(' </object>\n');
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
    window.open(theURL,winName,features);
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
    var obj = MM_findObj(objName);
    //alert(obj.name + ' ' + theProp + ' ' + theValue + ' ' + theProp.indexOf("style."));
    if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
        //alert("obj."+theProp+"="+theValue);
        if (theValue == true || theValue == false)
            eval("obj."+theProp+"="+theValue);
        else eval("obj."+theProp+"='"+theValue+"'");
    }
}

function Kontrola(f) {
    var vysledek = true;
    var strerr = "";
    if (f.jmeno.value=="") strerr += "Jméno\n";
    if (f.text.value=="") strerr += "Text\n";
    if (f.preposlat.checked && f.email.value=="") strerr += "E-mail\n";

    if ("" != strerr) {
        alert("Vyplňte prosím:\n\n" + strerr);
        return false;
    }
    var test = "^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$";
    if(f.email.value && f.email.value!="" && f.email.value!="@") {
        if (!(f.email.value.match(test))) {
            alert('Není vyplněna správná emailová adresa!!!');
            return false;
        };
    
}
}

function trim(string)
{
    var re= /^\s*|\s*$/g;
    return string.replace(re,"");
}

function check_email(f) {
    var vysledek = true;
    var strerr = "";
    var email = trim(f.login.value);
    var test = "^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,4}$";
    if (!(email.match(test)) && email.length!=6) {
        alert('Login je celá emailová adresa ve formátu jmeno@neco.cz .');
        return false;
    }
    return vysledek;
}


function zobrazSkryj_pos(idecko,action){
    el=document.getElementById(idecko).style; 
    if (action=='hide') el.display='none';
    if (action=='show') {
        el.display='block';
    }
}


function zobrazSkryj_zmena(idecko){
    el=document.getElementById(idecko).style; 
    if (el.display=='none') {
        el.display='block';
        return true
        }
    if (el.display=='block') {
        el.display='none';
        return true
        }
}

function zobrazSkryj_pos_inline(idecko,action){
    el=document.getElementById(idecko).style; 
    if (action=='hide') el.display='none';
    if (action=='show') {
        el.display='inline';
    }
}

function select_kraj(id) {
    if (id==349) {
        MM_changeProp('country['+id+']','','checked','checked','INPUT/CHECKBOX');
    } else {
        MM_changeProp('kraj['+id+']','','checked','checked','INPUT/CHECKBOX');
    }
}

function select_kraj_KU(id) {
    var my_el;
    if (id==349) {
        my_el = document.getElementById('country_map['+id+']');
    } else {
        my_el = document.getElementById('kraj_map['+id+']');
    }
    if (my_el.checked) 
        my_el.checked=false;
    else 
        my_el.checked=true;

}

function typ_upresnit_fce(id) 
{ 
    if (id.value==5)   zobrazSkryj_pos_inline('upresnit','show');
    else zobrazSkryj_pos_inline('upresnit','hide');
 
}
 
function potvrzeni(message){
    if (!confirm(message)) return false;
}


function MM_showHideLayers() { //v6.0
    var i,p,v,obj,args=MM_showHideLayers.arguments;
    for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) {
        v=args[i+2];
        if (obj.style) {
            obj=obj.style;
            v=(v=='show')?'visible':(v=='hide')?'hidden':v;
        }
        obj.visibility=v;
    }
}
function clearMyTimeout()
{
    if (MenuTimer) clearTimeout(MenuTimer);
    MenuTimer = null;
    TimerFlag = false;
}

function startMyTimeout(menuitem)
{
    TimerStart = new Date();
    TimerFlag = true;
    ActiveMenu = menuitem;
    MenuTimer = setTimeout("HideMenu()", 100);
}


function HideMenu()
{
    if (!TimerFlag) return;
    var elapsed = new Date() - TimerStart;
    if (elapsed < 1000) {
        HideMenuTimer = setTimeout("HideMenu()", 100-elapsed);
        return;
    }
    TimerFlag = false;
    MM_showHideLayers(ActiveMenu,'','hide', HiliteMenu,'','show');
	
}



function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 200);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        //alert(timer);
			
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
        {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr;
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
    var d=document;
    if(d.images){
        if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
        for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
                d.MM_p[j]=new Image;
                d.MM_p[j++].src=a[i];
            }
        }
}


function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments;
    document.MM_sr=new Array;
    for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){
            document.MM_sr[j++]=x;
            if(!x.oSrc) x.oSrc=x.src;
            x.src=a[i+2];
        }
}

function change_image (id, image1, image2, host) {
    var img = MM_findObj(id);
	
    image1 = 'http://'+host+image1;
    image2 = 'http://'+host+image2;
    // alert(img.src+' '+image1+' '+image2);
    if (img.src==image1) {
        img.src=image2;
        return true
    };
    if (img.src==image2) {
        img.src=image1;
        return true
    };
}

function show_map_registrace(){
    var ulice=document.getElementById('ulice').value; 
    var mesto=document.getElementById('mesto').value; 
    if (ulice) {
        if (mesto) {
            MM_openBrWindow('http://mapy.seznam.cz/?query='+ulice+','+mesto,'mapa','');
        } else {
            alert ('Vyplňte prosím město.');	
            return false;
		
        }
    } else {
        alert ('Vyplňte prosím adresu zařízení.');	
        return false;
    }

}

function change(id, toto) {
    x=document.getElementById(id);
    if (toto.className == 'li_plus'){
        x.style.display="block";
        toto.className = 'li_minus';
    }
    else
    {
        x.style.display="none";
        toto.className = 'li_plus';
    }
}
	
// Scrolling = 0;
function ScrollWin(position) {
// while(Scrolling != position) {
// this.scroll(1,Scrolling)
// Scrolling++;
// }
// window.location.hash="zalozky";


}
  

function getElementsByClassName(oElm, strTagName, strClassName){
    var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    strClassName = strClassName.replace(/\-/g, "\\-");
    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;
    for(var i=0; i<arrElements.length; i++){
        oElement = arrElements[i];
        if(oRegExp.test(oElement.className)){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}


function hide_all_class(class_id) {
    var elements=getElementsByClassName(document,'div', class_id);
	
    if(elements.length) {
        for(i=0;i<elements.length;i++) 
        {
            elements[i].style.visibility='hidden';
        }
		
    }
}

function show_all_edit(class_id, action) {
    var elements=getElementsByClassName(document,'a', class_id);
	
    if(elements.length) {
        for(i=0;i<elements.length;i++) 
        {
            elements[i].style.display=action;
        }
		
    }
}

function ajaxAlert(originalRequest){
    window.alert(originalRequest);
}

function popUp(test) {
    return;	
}

function change_popis (id, popis1, popis2) {
    var el =document.getElementById(id);
    var content = el.innerHTML;
	
    if (content==popis1) {
        el.innerHTML =popis2;
    }
    if (content==popis2) {
        el.innerHTML =popis1;
    }
	
}

function uncheck_all() {
    document.getElementById('hotely_check').checked=false;
    document.getElementById('pensiony_check').checked=false;
    document.getElementById('rs_check').checked=false;
    document.getElementById('kempy_check').checked=false;
}

function check_all() {
    document.getElementById('hotely_check').checked=true;
    document.getElementById('pensiony_check').checked=true;
    document.getElementById('rs_check').checked=true;
    document.getElementById('kempy_check').checked=true;
}

function enable_disable_zar(zar) {
    if (zar == 'all') {
        document.getElementById('hotely_check').disabled=false;
        document.getElementById('pensiony_check').disabled=false;
        document.getElementById('rs_check').disabled=false;
        document.getElementById('kempy_check').disabled=false;  
    }
    else {
        document.getElementById('hotely_check').disabled=true;
        document.getElementById('pensiony_check').disabled=true;
        document.getElementById('rs_check').disabled=true;
        document.getElementById('kempy_check').disabled=true;  

    /*  
    if (zar == 'hotely') {
      document.getElementById('hotely_check').disabled=false; 
    }    
    else {
      document.getElementById('hotely_check').disabled=true; 
    }
    if (zar == 'pensiony') {
      document.getElementById('pensiony_check').disabled=false; 
    }    
    else {
      document.getElementById('pensiony_check').disabled=true; 
    }
    if (zar == 'rs') {
      document.getElementById('rs_check').disabled=false; 
    }    
    else {
      document.getElementById('rs_check').disabled=true; 
    }
    if (zar == 'kempy') {
      document.getElementById('kempy_check').disabled=false; 
    }    
    else {
      document.getElementById('kempy_check').disabled=true; 
    }
    */
    }

}

function select_zar_type(zalozka) {

    if (zalozka=='fulltext' || zalozka=='podrobne') {
        check_all();
        enable_disable_zar('all');      
    } else {
        if (zalozka=='hotely') {
            uncheck_all();
            MM_changeProp('hotely_check','','checked','checked','INPUT/CHECKBOX');
            enable_disable_zar('hotely');   
        } else {
            if (zalozka=='pensiony') {
                uncheck_all();
                MM_changeProp('pensiony_check','','checked','checked','INPUT/CHECKBOX');
                enable_disable_zar('pensiony');       
            } else {
                if (zalozka=='rs') {
                    uncheck_all();
                    MM_changeProp('rs_check','','checked','checked','INPUT/CHECKBOX');
                    enable_disable_zar('rs');        
                } else {
                    uncheck_all();
                    MM_changeProp('kempy_check','','checked','checked','INPUT/CHECKBOX');
                    enable_disable_zar('kempy'); 
                }   
            }    
        }
    }
/*var chkBoxes = new Array();
	var el1 = document.getElementById('hotely_check');
	chkBoxes[1] = document.getElementById('pensiony_check');
	chkBoxes[2] = document.getElementById('rs_check');
	chkBoxes[3] = document.getElementById('kempy_check');
	FancyForm.update(el1.getParent());*/
//FancyForm.update();
// FancyForm.start();
}

function setCookie (value, show_window) {
    var myCookie = Cookie.write('gmap1', value);
    if (show_window) {
		
    } else {
        var myCookie = Cookie.write('gmap2', value);
    }
}
function loadCookie (name) {
    var myCookie = Cookie.read(name);
    //alert(myCookie);
    return myCookie;
}


function openNavi (odkaz) {
    Shadowbox.open({
        content:    odkaz,
        player:     "iframe",
        width:      885

    });
}

function kontakt_show(id, verze, title) {

    SmartyAjax.call('/ajax_call.php', 'post', 'page=save_kontakt_stats&include=yes&typ=tel&id='+id);

    var odkaz="/index.php?page=detail_phone_form&only=yes&verze="+verze+"&id="+id;
    Shadowbox.open({
        content:    odkaz,
        player:     "iframe",
        width:      690,
        height:     560,
        title:      title
    });
    
//$('shadowbox_loading').style.backgroundColor="red";   
}


//našeptávač
                                                    
function setNaseptavacEvents() {
    if (document.getElementById("fulltext")!=null &&  document.getElementById("fulltext_naseptavac")!=null) {
        if (navigator.appVersion.indexOf('MSIE 6.0', 0)==-1) {
            $$("#fulltext").addEvent('keyup', function() {
                if (this.value.length>3) {
                    //naseptavacChange(this);
                    document.getElementById('fulltext_naseptavac').style.display='block';  
                }  			         			 
            }); 
               
            $$("body").addEvent('click', function() {  
                document.getElementById('fulltext_naseptavac').style.display='none';    			         			 
            }); 
        }
    }              
}
            
function naseptavacChange(input_id, typ) {
    if (navigator.appVersion.indexOf('MSIE 6.0', 0)==-1) {
        var value=input_id.value;         
        if (value.length>3) {
            SmartyAjax.update('fulltext_naseptavac','/ajax_call.php', 'post', 'page=fulltext_naseptavac&include=yes&string='+value+'&typ='+typ);
        }       
    }
}

//statistiky zařízení
function showAdminStats(id, loadUrl){
    //alert("ID: "+id);
    if ($("#"+id).css("display")=="none") {
        $("#"+id).load(loadUrl, function (){
            $("#"+id).slideToggle();
        });
    } else {
        $("#"+id).slideToggle();
    }
     
}
/* function loadFacStats(zarId, rok) {
               //SmartyAjax.update('statistiky_table','/admin.php', 'get', 'page=admin_facility_stats_ajax&id_facility='+zarId+'&rok='+rok+'&include=yes');
               $('#statistiky_table').load('/admin.php?page=admin_facility_stats_ajax&id_facility='+zarId+'&rok='+rok+'&include=yes');
               return false;
            }

            function loadBestCamp(zarId) {               
               //SmartyAjax.update('best_results','/admin.php', 'get', 'page=zar_statistiky_porovnani_ajax&id_facility='+zarId+'&include=yes');
               $('#best_results').load('/admin.php?page=zar_statistiky_porovnani_ajax&id_facility='+zarId+'&include=yes');
               return false;
            }

            function switchTabs(id) {
                $('#stats_tabs').getChildren().each(function (li) {
                    li.removeClass('current');
                });

                $(id).addClass('current');
            }*/
function loadFacStats(zarId, rok) {
    $('#statistiky_table').load('/index.php?page=admin_facility_stats_ajax&id_facility='+zarId+'&rok='+rok+'&include=yes');
    return false;
}

function loadBestCamp(zarId) {               
    $('#best_results').load('/index.php?page=zar_statistiky_porovnani_ajax&id_facility='+zarId+'&include=yes');
    return false;
}

function switchTabs(id) {
    $('#stats_tabs').children('li').each(function (index, li) {
        $(li).removeClass('current');
    });

    $('#'+id).addClass('current');
}

function loadFacStatsRS(zarId, rok) {
    $('statistiky_table').load('/index.php?page=admin_facility_stats_ajax&id_facility='+zarId+'&rok='+rok+'&include=yes');
    return false;
}

function loadBestCampRS(zarId) {               
    $('best_results').load('/index.php?page=zar_statistiky_porovnani_ajax&id_facility='+zarId+'&include=yes');
    return false;
}

function switchTabsRS(id) {
    /*$('stats_tabs').children('li').each(function (index, li) {
        $(li).removeClass('current');
    });

    $(''+id).addClass('current');*/
    
    $('stats_tabs').getChildren().each(function (li) {
        li.removeClass('current');
    });
    $(id).addClass('current');
}
