var timestamp_od=0;
var timestamp_do=0;
var id_od='';
var id_do='';

// = Functions
//----------------------------------------
function isEmailAddress (string) 
{
  var addressPattern = 
    /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
  return addressPattern.test(string);
}
function checkEmail (field) 
{
  if (!isEmailAddress(field.value)) {
    alert('Please enter correct email address!');
    field.focus();
    field.select();
  }
}
function stripHTML(oldString) 
{
  var re= /<\S[^>]*>/g; 
  oldString = oldString.replace(re,""); 
  return oldString;
}
function posli_mail(jazyk)
{
var error_message='';
  needmeno = new Array(6);
  needmeno['sk']='Pred odoslaním uveďte meno.';
  needmeno['cz']='Před odesláním vyplňte jméno.';
  needmeno['en']='Please type in you name';
  needmeno['de']='Vorden absenden geben sie ihren Nahmen ein.';
  needmeno['hu']='Név';
  needmeno['pl']='włóżcie Imię i nazwisko';
  needkontakt = new Array(6);
  needkontakt['sk']='Zadajte telefonický kontakt alebo E-mailovú adresu';
  needkontakt['cz']='Vyplňte telefonický kontakt anebo E-mailovou adresu';
  needkontakt['en']='please fill in the phone number or E-mail address';
  needkontakt['de']='geben Sie Telefonnumer oder die E-Mail-Adresse ein';
  needkontakt['hu']='kérjük adjon meg legalább egy telefonszámot vagy e-mail címet';
  needkontakt['pl']='włóżcie kontakt telefoniczny lub adres e-mailowy';
  needatum = new Array(6);
  needatum['sk']='Vyplňte prosím začiatok a koniec vášho pobytu';
  needatum['cz']='Vyplňte prosím začátek a konec vašeho pobytu';
  needatum['en']='Please fill in the dates of your arrival and departure';
  needatum['de']='Please fill in the dates of your arrival and departure';
  needatum['hu']='Please fill in the dates of your arrival and departure';
  needatum['pl']='Please fill in the dates of your arrival and departure';
  needpocetosob = new Array(6);
  needpocetosob['sk']='Vyplňte prosím počet ubytovaných osôb';
  needpocetosob['cz']='Vyplňte prosím počet ubytovaných osob';
  needpocetosob['en']='Please fill in the number of accomodated persons';
  needpocetosob['de']='Please fill in the number of accomodated persons';
  needpocetosob['hu']='Please fill in the number of accomodated persons';
  needpocetosob['pl']='Please fill in the number of accomodated persons';
  
  oddelovac="";
  
  if (document.getElementById('meno').value == "")
  {
  	error_message=error_message+needmeno[jazyk];   	
  	oddelovac="\n\n";
  }
  if ($('#elposta').val() == "" || !isEmailAddress($('#elposta').val()) && $('#telefon').val() == "")
  {	
  	error_message=error_message+oddelovac+needkontakt[jazyk];
  	oddelovac="\n\n";
  }
  if ($('#pobyt_od').val() == "" || $('#pobyt_do').val() == "")
  {	
  	error_message=error_message+oddelovac+needatum[jazyk];
  	oddelovac="\n\n";
  }
  if ($('#pocet_osob').val() == "")
  {	
  	error_message=error_message+oddelovac+needpocetosob[jazyk];
  	oddelovac="\n\n";
  }    
  if (error_message !== '')
  {
    alert (error_message);
    return false;
  }
  else 
  { 
    return true; 
  }
}
function targetBlank(href) {
	var newWindow = window.open(href, "print_page", "toolbar=yes,titlebar=yes,directories=yes,menubar=yes,location=yes,scrollbars=yes,status=yes,resizable=yes");
	if(!newWindow) return false;
	return true;
}
function posliobj(fff)
{
  //document.forms[0].suhlas.checked)
  //fff.elements["suhlas"].value)
  if (fff.elements["suhlas"].checked) 
  {
  	fff.submit();
  }
  else
  {
 	  alert ("Vypĺnte položku: Súhlas s podmienkami registrácie");
 	}
}
function bookmark(url,title)
{
  if (url=='')
  {
    var title="1-2-3-ubytovanie.sk";
    var url="http://www.1-2-3-ubytovanie.sk";
  }
  else
  {
    
  }
  if (window.sidebar) 
  {
    window.sidebar.addPanel(title, url,"");
  }
  else if( window.opera && window.print )
  {
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();
  }
  else if( document.all ) 
  { 
    window.external.AddFavorite( url, title);
  }
}
function installSearchEngine() 
{
 if (window.external && ("AddSearchProvider" in window.external)) 
 {
   // Firefox 2 and IE 7, OpenSearch
   window.external.AddSearchProvider("http://www.1-2-3-ubytovanie.sk/addSearchEngine.xml");
 } 
 else if (window.sidebar && ("addSearchEngine" in window.sidebar)) 
 {
   // Firefox <= 1.5, Sherlock
   //window.sidebar.addSearchEngine("http://example.com/search-plugin.src",
   //                               "http://example.com/search-icon.png",
   //                               "Search Plugin", "");
   alert("Tento prehliadac funkciu nepodporuje, skuste Internet Explorer 7, alebo Firefox 2");                                  
 } 
 else 
 {
   // No search engine support (IE 6, Opera, etc).
   alert("Tento prehliadac funkciu nepodporuje, skuste Internet Explorer 7, alebo Firefox 2");
 }
}


function get_phone_content(url,target)
{
  var pole=url.split('#', 2);
  final_url=pole[0]+'?ajax_tel=1';
  $.get(final_url, function(data)
  {    
    //alert("Data Loaded: " + data);
    $("div[id='"+target+"']").html(data); 
  });
}
// ------------------------------------
// ^ Functions 


function get_map_data(url,target)
{
 
  if ($("div[id='"+target+"']").attr("rel")=='loaded')
  {
    //alert('not loading');
  }
  else
  {
    map_url=url+'?ajax_map=1';
    $.get(map_url, function(data)
    {    
      //alert('loading');
      $("div[id='"+target+"']").attr('rel','loaded');
      $("div[id='"+target+"']").html(data);     
    });
  }

  zoznam_url=url+'?ajax_zoznam=1';
  $.get(zoznam_url, function(data)
  {    
    //alert("Data Loaded: " + data);
    $(".zoznam-v-stlpcoch").html(data); 
    $("#zlk").slideDown("slow");
    $("#zlk").fadeTo("fast",0.97);
  });
}


function get_all_tips(url,target)
{
 
  if ($("div[id='"+target+"']").attr("rel")=='loaded')
  {
    //alert('not loading');
  }
  else
  {
    my_url=url+'&ajax_tips=1';
    //alert(my_url+' loading');    
    $.get(my_url, function(data)
    {          
      $("div[id='"+target+"']").attr('rel','loaded');
      $("div[id='"+target+"']").html(data);
      $("#vsetky_tipy").hide();           
    });
  }

  /*
  zoznam_url=url+'?ajax_zoznam=1';
  $.get(zoznam_url, function(data)
  {    
    //alert("Data Loaded: " + data);
    $(".zoznam-v-stlpcoch").html(data); 
    $("#zlk").slideDown("slow");
    $("#zlk").fadeTo("fast",0.97);
  });
  */
}


$(document).ready(function() 
{


$("#other-icons a").hover(
  function () {
    var textpopisu=$(this).html();
    $("#sharepopis").html(textpopisu)
    $("#smssend").css('display','none');
    $("#sharepopis").css('display','block');
  },
  function () {        
    $("#smssend").css('display','block');
    $("#sharepopis").css('display','none');
  }
);

/*
  $(".toggle-switcher").click( function()
  {
    myid=$(this).attr("rel");
    $("div[id='"+myid+"']").slideDown("fast");
    return false;    
  });
  */
  

  
  
    $(".toggle-switcher").click( function()
    {            
      myid=$(this).attr("rel");            
      $("div[id='"+myid+"']").slideToggle("fast");
      $("#zlk").fadeTo("fast",0.97);
      
      return false;      
    });

  
  $(".get_phones").click(function()
  {
    var link=$(this).attr("href");
    var ciel=$(this).attr("rel");    
    get_phone_content(link,ciel+'-content')
    // vynimky v pripade ze klikol na link a nie zalozku tak musime zrusit akciu kliku
    if(ciel=='phones') { return false; }    
  });

  $("#mapa_lokalit_Map area").mouseover(function()
  {
    clasa=$(this).attr("rel");
    $("#mapa-lokalit-hover").attr("class",clasa);
  });
  $("#mapa_lokalit_Map area").mouseout(function()
  {
    $("#mapa-lokalit-hover").attr("class",''); 
  });

  $("#je-toto-vase").click(function () 
  {
    $("#je-toto-vase-text").toggle();
  });
  $(".switchable li a").click(function() 
  { 
    if ($(this).attr("class")=='thickbox')
    {
      return false;
    }
    if ($(this).attr("rel")=='clickthrough')
    {
      return true;
    }
    var id_panelu_ktory_aktivovat=$(this).attr("rel");
    var vypni_panely=$(this).parent().parent().attr("id");
    $('.zalozky #'+vypni_panely+' a').removeClass("active");
    $('.zalozky #'+vypni_panely+' li').removeClass("active");
    $(this).addClass("active");
    $('.'+vypni_panely).css("display","none");    
    $("div[id='"+id_panelu_ktory_aktivovat+"']").css("display","block");
    
    
    if (
        $(this).attr("rel")=='mapa-krajov' || 
        $(this).attr("rel")=='mapa-lokalit-back' ||
        $(this).attr("rel")=='mapa-okresov'
       )
    {    
      get_map_data($(this).attr("href"),$(this).attr("rel"));            
    }
    
                   
    return false;
  });


  $("#vsetky_tipy").click(function()
  {  
    get_all_tips($(this).attr("href"),'tipy');   
    return false;
  });

  $("#vsetky_nove_ubytovania").click(function()
  {  
    $("#zbaleny-blok").css("overflow","auto");    
    $("#zbaleny-blok").css("height","100%");
    $("#nu-uvod").css("height","100%");          
    return false;
  });
  
   
  $(".installsearch").click(function() 
  {
    installSearchEngine();
  });
  /*
  $("#searchbox").click( function() 
  {
    //alert($(this).val());
    if ($(this).val()=='...') { $(this).val(''); }
  });
  //replaceme
  */

  if (!window.opera) 
  {
    $("body").click( function(e)
    {
    		if ($(e.target).attr("rel")=="replaceme") { 
          //alert('kliked');
          myurl=$(e.target).attr("href");
          myurl=myurl+'&ajax_load=1';
           if ($(e.target).text()=='zoznam') { $(e.target).text('načítavam'); }
          $.post( myurl ,
          { balast: "1" },
          function(data){
                //$(e.target).append(data);
                //if ($(e.target).text()=='nahravam') {} 
                //$(e.target).parent().html(data);
                $("#replaceme").html(data); 
                //$(e.target).remove();
          }
          );
          return false;
        }
        if ($(e.target).attr("class")=='click-clear')
        {
          $(e.target).attr("value",'');
        }
    });
  }

  $("#zoznam-ubytovacich-zariadeni div").addClass("zoz-hidden");
  $("#zoznam-ubytovacich-zariadeni h3").toggle(function()
  {
    $(this).parent().removeClass("zoz-hidden");
    $(this).parent().addClass("zoz-visible");
  },function()
  {
    $(this).parent().removeClass("zoz-visible");
    $(this).parent().addClass("zoz-hidden");
  });
  
  //$("#vyhladavaci-panel2").html(strVar);  

/* REZERVACIA */  
/* -------------------------------------------------------------- */
  $("#reset-datum-pobytu").click(function() 
  {
     parent.$('#pobyt_od').val('');
     parent.$('#pobyt_od_timestamp').val('');
     parent.$('#pobyt_do').val('');
     parent.$('#pobyt_do_timestamp').val('');  
    $("#kalendar td").removeClass("pobyt_od");
		$("#kalendar td").removeClass("pobyt_do");
		$("#reset-datum-pobytu").css("display","none");
		return false;
  });

function fix_kalendar_info()
{
		id_od=parent.$('#pobyt_od').val();	
		id_do=parent.$('#pobyt_do').val();
		
		if (id_od !== '')
		{ 
      $("#reset-datum-pobytu").css("display","inline"); 		
      $("td[id='d"+id_od+"']").addClass("pobyt_od");
      timestamp_od=$("td[id='d"+id_od+"']").attr("rel");
      if (timestamp_od !== '')
      {
        parent.$('#pobyt_od_timestamp').val(timestamp_od);
      }
    }    
    if (id_do !== '')
		{      		
      $("#reset-datum-pobytu").css("display","inline");  
      $("td[id='d"+id_do+"']").addClass("pobyt_do");
      timestamp_do=$("td[id='d"+id_do+"']").attr("rel");
      if (timestamp_do !== '')
      {
        parent.$('#pobyt_do_timestamp').val(timestamp_do);
      }
    }    
}

fix_kalendar_info();

  /*
  $("#kalendar").bind("contextmenu",function(e){
  	return false;
  });
  */

  
  $("#kalendar").click( function(e)
  {


  if ($(e.target).attr('tagName') == 'TD' || $(e.target).attr('tagName') == 'td')
  {
    //ked klikne na datum, ocakava sa ze sa vzdy zobrazi link "zrusit vyber"
    $("#reset-datum-pobytu").css("display","inline");

    e.stopPropagation();
  
      fix_kalendar_info();
      
      
  		
  		$("td[id='d"+id_od+"']").removeClass("pobyt_od");
  		$("td[id='d"+id_do+"']").removeClass("pobyt_do");
  		
  		if (id_od == '')
  		{  		
  		 	oddo_datum=$(e.target).attr("id");
  			oddo_datum_value=oddo_datum.replace('d','');
        oddo_timestamp=$(e.target).attr("rel");					
        parent.$('#pobyt_od').val(oddo_datum_value);
        parent.$('#pobyt_od_timestamp').val(oddo_timestamp);            
      }
      else 
  		{          	                  	  
        oddo_datum=$(e.target).attr("id");
  			oddo_datum_value=oddo_datum.replace('d','');
        oddo_timestamp=$(e.target).attr("rel");
        
        if (oddo_timestamp<timestamp_od)
        {
          parent.$('#pobyt_od').val(oddo_datum_value);
          parent.$('#pobyt_od_timestamp').val(oddo_timestamp);  
          oddo_datum_value=id_od;
          oddo_timestamp=timestamp_od;         
        }
        				
        parent.$('#pobyt_do').val(oddo_datum_value);
        parent.$('#pobyt_do_timestamp').val(oddo_timestamp);     
      }
   
  
        
        timestamp_od=parent.$('#pobyt_od_timestamp').val();
    		id_od='d'+parent.$('#pobyt_od').val();
    		timestamp_do=parent.$('#pobyt_do_timestamp').val();	
    		id_do='d'+parent.$('#pobyt_do').val();
        
  
  		if (timestamp_od !=='')
  		{		      
        $("td[id='"+id_od+"']").addClass("pobyt_od");      
  		}
  
  		if (timestamp_do !=='')
  		{		  
        
        $("td[id='"+id_do+"']").addClass("pobyt_do");      
  		}
    } 
            
	
  });
  

});
/* ----------------------------------------------------- */

//OLD - zo suboru nove-funkcie.js
var clicking_on_checkboxes=0;
function ajaxpost(hideornot) 
{   

$("#qsload").css('display','block');

  if (hideornot=='hide') 
  {
    $("select").attr("disabled","disabled");
    $("input").attr("disabled","disabled");      
  }
  
  myurl=document.URL;
  $("#go-search").after('<input id="ajax_content_podrobne" type="hidden" name="ajax" value="1" />');
  $("#quickform").ajaxSubmit(function(data)
  {
    if (data !== '') 
    {
      //set_searcher(); 
      //alert(data);
      //re=data;
      
      $("#qsload").css('display','none');
      
      $("#quickform").html(data);                       
      
      if (hideornot=='hide') 
      {
        $("#vynuluj").hide();          
      } 
      else 
      {
        $("#vynuluj").show();
      }   
    } 
  });
}

var tub=new Array();
tub['kriteria[hlavicka10][apartman]']="apartman";
tub['kriteria[hlavicka10][camp]']="camp";
tub['kriteria[hlavicka10][chata]']="chata";
tub['kriteria[hlavicka10][hotel]']="hotel";
tub['kriteria[hlavicka10][motel]']="motel";
tub['kriteria[hlavicka10][penzion]']="penzion";
tub['kriteria[hlavicka10][privat]']="privat";
tub['kriteria[hlavicka10][ubytovna]']="ubytovna";

function set_form_listener(podstranka) 
{
  $("#o_cene_toggle").click(function () 
  {
  //$("#o_cene").toggle();
    if ($("#o_cene_toggle").attr("checked")== true)
    {
      $("#o_cene_vysvetlivka").css("display","none");
      $("#o_cene").css("display","inline");
      $(".price").attr('disabled',false);
    }
    else
    {
      $("#o_cene_vysvetlivka").css("display","inline");
      $("#o_cene").css("display","none");
      $(".price").attr('disabled',true);
    }
  });

  $("#go-search").click(function() 
  {
    var searchstr='';
    var hladane='';
    var ciarka='';
    var dvojbodka='';
    //ZOSTAVI URL Z CHECKBOXOV
    $("#hlavicka10 input:checkbox").each(function(i)
    {
      if ($(this).attr("checked")==true) 
      {
        searchstr=searchstr+dvojbodka+tub[$(this).attr('name')];
        dvojbodka=':';
      }      
      ciarka=',';
    });
    if (searchstr=='') 
    {
      searchstr='-';
    }
    //ZOSTAVI ZVYSOK URL ZO SELECTOV
    $("#quickform select").each(function(i)
    {          
      if ($(this).attr('disabled')==false)
      {      
        if ($('option:selected', this).val()=='') 
        { 
          hladane='-'; 
        } 
        else 
        {
          hladane=$('option:selected', this).val();
        }
        searchstr=searchstr+ciarka+hladane
        ciarka=',';
      }
    });
    //alert(searchstr);
    window.top.location.href='http://www.1-2-3-ubytovanie.sk/'+podstranka+'/'+searchstr;
    return false;
  });
  $("#vynuluj").click(function()
  {
    //$("#quickform select").val("");
    //$("#quickform input:checkbox").attr("checked",false);
    //total=$("#total").text(); 
    //$("#vysledok strong").text(total);
    ajaxpost('hide');    
    return false;
  });  
  $("#hlavicka10").mouseup( function() 
  {  
    if (clicking_on_checkboxes==0) 
    {
      $(this).stopTime("b=1").oneTime(1500,"b=1",function() 
      {
        clicking_on_checkboxes==2;
        ajaxpost('show');
      });
    }           
    if (clicking_on_checkboxes==2) 
    {
      clicking_on_checkboxes=0;
    } 
    else 
    {
      if (clicking_on_checkboxes !== 0) 
      {
        clicking_on_checkboxes=1;
      }
    }
  });
 
 
  $("#quickform select").change(function() 
  {
    var poc=0;    
    var prave_vybrate_kriterium= $(this).val();  
    //Skontroluje kolko je vybratych selectov
    $("#quickform select").each(function(i)
    {
      if ($('option:selected', this).val()=='') 
      {
        $('option:selected', this).parent().removeClass("chosen");
        //$('option:selected', this).parent().prev().removeClass("chosen");
      } 
      else 
      {
        poc++; 
        //alert($('option:selected', this).val());                
        pocet=$('option:selected', this).attr("rel");
        $('option:selected', this).parent().addClass("chosen");
        //$('option:selected', this).parent().prev().addClass("chosen");
      }
    });
    
    //alert(poc);
    //Podla poctu vybratych selektov vykona akciu
    //Ak nie je vybrate nic tak natiahne pocet z prvku "total"
    if (poc==0) 
    {      
      var total=$("#total").text(); 
      $("#vysledok strong").text(total);      
      $("#vynuluj").hide();             
    } 
    else 
    {
      if (poc==1 && 1==2) 
      {
        if (prave_vybrate_kriterium=='') 
        { 
        ajaxpost('show'); 
        } 
        else 
        {                       
          // nula_viac_ako_pat  jedna  dve_az_styri
          $("#vysledok strong").text(pocet);
          if (pocet==0 || pocet>4) 
          { 
            $("#vysledok span").text($("#vysledok span").attr("rel")); 
          }
          if (pocet==1) 
          {  
            $("#vysledok span").text($("#vysledok span").attr("id")); 
          }            
          if (pocet>1 && pocet<5) 
          { 
            $("#vysledok span").text($("#vysledok span").attr("class")); 
          }            
          $("#vynuluj").show();                    
        }
      } 
      else 
      {        
        ajaxpost('show');
      }
    }
  }); 
  
}


