// JavaScript Document

    var urlToIcon = 'http://'+window.location.host+'/images/pubguide/';    
    var WebUrl = 'http://'+window.location.host+'/cz/';

    var AjaxLoad = 0;
    
//    var urlToIcon = 'http://localhost/arakis/pilsnerurquell/websvn/images/pubguide/';
//    var WebUrl = 'http://localhost/arakis/pilsnerurquell/websvn/cz/';
    
    var blogyLink = "Klub-Blogy";
    var PnpNextStep = "";

function SetUrlLocation( set , textContentIdTo , textContentIdFrom, linker)
{

  var tmp_link = top.document.location.href;
  var link = tmp_link.split("#");
  var new_link_temp = link[0] + "#" + set;
  var new_link = WebUrl + set + ".html";
  var actual_page_id = null;
  
  top.document.location.replace( new_link_temp );

  AjaxLoad = 1;

  if (linker && textContentIdTo != 'AjaxContentLB') 
  {
		if (linker.hasAttribute("href")) loadingAnimation(1,linker,'klub',jQuery(linker).text());
		else loadingAnimation(1,linker,'klub');
  }
  
  if (textContentIdTo == 'AjaxContentLB') {
    linker.style.cursor = "wait";
    document.getElementById("AjaxContentLB").style.cursor = "wait";    
    actual_page_id = document.getElementById("pnp_actual_step").value;
          
        if (PnpNextStep != textContentIdFrom) {
            PnpNextStep = textContentIdFrom;
        }
        else {
            PnpNextStep = '';
        }
        
        if (textContentIdFrom == "Step1") {
            // alert(actual_page_id + " | " + PnpNextStep + " | " + textContentIdFrom);
        }
        
        // podminky pri preklikavani horni listy
        if (actual_page_id == 'step1')  // jdeme z kroku 1
        {            
            document.getElementById("pnp_actual_step").value = "";
            SetPubAndDates(linker,set);
            document.getElementById("AjaxContentLB").style.cursor = "default";    
            return false;
        }
        if (actual_page_id == 'step2')  // jdeme z krok 2
        {               
            document.getElementById("pnp_actual_step").value = "";
            SetMeetingInfo(linker,set); 
            document.getElementById("AjaxContentLB").style.cursor = "default";    
            return false;
        }
        if (actual_page_id == 'step3')  // jdeme z krok 3
        {            
            SetMeetingUser(0);
            var u_count = parseInt(document.getElementById("pnp_user_count").value);
            document.getElementById("AjaxContentLB").style.cursor = "default";                
            if (u_count <= 0)
            {               
               return false;
            }
        }         
  }  
  
  
  $("#" + textContentIdTo).load(new_link + " #" + textContentIdFrom + " ", function() 
    {
      //callback
      
      /// pro Pojd Na pivo
      if (textContentIdTo != 'AjaxContentLB') {
	    loadingAnimation(0);      
      } 
           
      if (textContentIdFrom == "Step1") {
        LoadCalendar(); 
        StartPubListener();
        
        var dts = document.getElementById("pnp_selected_dates").value;
        if (dts != null && NewCalendar != "")
        {
            var tmp_dts = dts.split("|");
            if (tmp_dts.length > 0)
            {
                for (var i = 0; i < tmp_dts.length;i++) {
                    var tmp = tmp_dts[i].split("_");
                    if (tmp.length == 2) {
                        NewCalendar.addToList(tmp[1],tmp[0]); 
                    }
                }
            }
        }        
      }

      if (textContentIdFrom == "Step2") {
        $('#timePickerWrap').timePicker({ input: 'pnp_action_time'});
      }

      if (textContentIdFrom == "Step3") {          
        StartUserListener();
        ListMeetingUsers();    
      }
            
      // zakladni veci pro vsechny
      Cufon.replace('#' + textContentIdTo + ' .textize');
      selectizeAllSelects();
      
      if (textContentIdTo == 'AjaxContentLB') {        
        document.getElementById("AjaxContentLB").style.cursor = "default";
        linker.style.cursor = "default";
      }
    });

  return false;
}

// nacte stranku podle kotvy v URl
function klubLoadByAnchor()
{
    var tmp_link = top.document.location.href;
    var link = tmp_link.split("#");
    var params;
    var textContentIdFrom = "klubcommon";
        
    if (link[1] != null && AjaxLoad == 0) {
      // window.parent.location = WebUrl + link[1] + ".html";      
      if (link[1] == blogyLink) {
        textContentIdFrom = "klubblogy";
      }

      SetUrlLocation( link[1] , "AjaxContent" , textContentIdFrom);
    }
}

function klubHideMessages(mess_id)
{
  var tmp = document.getElementById("nastenka-" + mess_id).style.display;
  
  if (tmp == "none") {
    document.getElementById("nastenka-" + mess_id).style.display = "block"; 
  }
  else {
    document.getElementById("nastenka-" + mess_id).style.display = "none";
  }
  
  return false;
}

// zjisti na co bylo reagovano a pokusi se nalezt formular s textareou na vkladani komentatu + nastavi formularove hidden pole (reakce na ktery prispevek) podle ID odkazu pred tim kterym div.vzkazN
function klubReact(e,idparent) {
	var puvE, newE;

	if (e) {
		e = jQuery(e);
		puvE = idparent; // e.parent().closest('.vzkazN').find(":nth-child(1)").attr('id').split('-')[1]; // rozdeli id prispevku podle "-" a pouzije druhou cast, muze byt upraveno dle libosti
		e = e.closest('.vzkazyNastenka').find('form').eq(0);
		
		if (e) {
			e = e.find('textarea');
			if (e && e.length > 0) {
				e = e.eq(0);
				e.trigger('focus');
				newE = document.getElementById('hiddenPrispevekNumber');
				if (!newE) {
					e.parent().append('<input id="hiddenPrispevekNumber" type="hidden" name="prispevek" />'); // nazev muze byt upraven dle libosti
				}
				newE = jQuery("#hiddenPrispevekNumber");
				newE.attr('value',puvE);
			}
		}
	}
}

// nalezne rodicovsky prvek vzkazTxt a pokusi se nalezt dalsi DIV, kteremu prepne class hide => skryti
function klubHide(e)
{
	if (e) {
		e = jQuery(e).closest('.vzkazTxt').next('div');
		if (e && e.hasClass('vzkazN')){
			e.toggleClass('hideIt');
		}
	}
}
