var ratingMaxValue = 9;
var ratingMinValue = -9;

window.onload = init;
function init() {
	document.onclick = hide_inputPhrases;
}

function hide_inputPhrases (e)
{
	if (document.all) e = event;
	if (e.target) source = e.target;
	else if (e.srcElement) source = e.srcElement;
	if (source.nodeType == 3) source = source.parentNode;
	if (source.tagName.toLowerCase()!='input')
  {
    $("#quickSearch .phrases").addClass("hidden");
    $("#newMessageForm .inputUserList").addClass("hidden");
  }
}

function updateCoords(c)
{
	jQuery('#x').val(c.x);
	jQuery('#y').val(c.y);
	jQuery('#w').val(c.w);
	jQuery('#h').val(c.h);
};

function checkCoords()
{
	if (parseInt(jQuery('#w').val())>0) return true;
	alert('Vyberte platný výřez obrázku!');
	return false;
};

$(document).ready(function(){

  // antispammove ochrany
  $("#newComment_antispam").val(8*3);
  $("#antispam").hide().addClass("hidden");
  $("#contactForm_antispam").val(8*3);
  $("#contactForm_antispamOuter").hide().addClass("hidden");
  

  // odeslani clanku emailem
  $("#sendArticle").hide();
  $("#sendArticle_open").show().click (function() {
    $("#sendArticle").slideToggle("normal")
    return false;
  });
  $("#sendArticle_close").show().click (function(){
    $("#sendArticle").slideToggle("normal");
		return false;
  });

  // kalendarove akce - odeslani pozvanky
  $(".boxCalendarList .ico-invite").click(function () {
    if ($(this).hasClass("inviteDone"))
    {
      $(this).removeClass("inviteDone");
      $(this).parents(".item").find(".boxInvite").hide();
    }
    else
    {
      $(this).addClass("inviteDone");
      $(this).parents(".item").find(".boxInvite").show();
    }
    return false;
  });

  // zvyrazneni komentaru
  $("#articleComments .item").mouseover (function() { $(this).addClass("highlight"); }).mouseout (function() { $(this).removeClass("highlight"); });
  $("#articleComments .item .react").click(function () {
    var obj = $(this).parents(".item");
    var date = $(obj).find(".date").text();
    var subject = $(obj).find(".subject strong").text();
    var id = $(obj).find("input[name='comment_id']").val();
    var level = Number($(obj).find("input[name='comment_level']").val())+1;
    var text = '<p class="offsetBottom react_message">Reagujete na příspěvek ze dne <strong>'+date+'</strong> (<a href="javascript:cancelCommentReaction('+id+');">Zrušit reakci</a>)</p>';

    $("#articleCommentsForm input[name='reply']").val(id);
    $("#articleCommentsForm input[name='level']").val(level);
    $("#articleCommentsForm input[name='comments_subject']").val('Re: '+subject);
    $("#articleCommentsForm .react_message").remove();
    $("#articleCommentsForm input[name='redirect']").after(text);
    $("#articleCommentsForm textarea").focus();

    $("#articleComments .item").each(function () {
      $(this).removeClass("marked");
    });
    $("#comment_"+id).addClass("marked");
    return false;
  });

  // formulare
  $("#articleCommentsForm form").submit(function() { return articleComment_validate (); });
  $(".boxInvite form").submit(function() {
    if (sendArticle ($(this)))
    {
      alert("Pozvánka bude nyní odeslána všem adresátům, které jste uvedli.");
      return true;
    }
    return false;
  });
  $(".boxSendArticle form").submit(function() {
    if (sendArticle ($(this)))
    {
      alert("Nyní se odešle e-mailová zpráva všem příjemcům, které jste uvedli.");
      return true;
    }
    return false;
  });

  // seznam ignorovanych
  $("#profileIgnoreList .ico-delete").click(function () { return confirm("Opravdu chcete uživatele odstranit ze seznamu ignorovaných?"); });
  $("#profileFriendList .ico-delete").click(function () { return confirm("Opravdu chcete uživatele odstranit ze seznamu vašich přátel?"); });

  // zvyrazneni polozky v tabulce boxu .boxTableList
  $(".boxTableList tr").mouseover (function() { $(this).addClass("highlight"); });
  $(".boxTableList tr").mouseout (function() { $(this).removeClass("highlight"); });

  // vyhledavani - fraze
  $("#quickSearch .button").attr("autocomplete", "off");
  $("#quickSearch .button").focus(function () { if ($(this).val() == 'Zadejte hledané slovo nebo frázi') $(this).val(""); });
  $("#quickSearch .button").keyup(function () {
    var phrase = $(this).val();
    if (phrase != '')
    {
      $.ajax({
        type: 'GET',
        url: '/ajax/ajax_searchAutocomplete.php',
        data: 'phrase='+phrase,
        success: function(results) {
          if (results == '') $("#quickSearch .phrases").addClass("hidden");
  				else
  				{
  	      	$("#quickSearch .phrases").removeClass("hidden");
  	      	$("#quickSearch .phrases").html (results);
    				$("#quickSearch .phrases a").click(function() {
      				var text = $(this).children(".fl").text();
      				$("#quickSearch .button").val(text);
      				$("#quickSearch form").submit();
      				return false;
  					});
  			 	}
        }
      });
		}
		else $("#quickSearch .phrases").addClass("hidden");
	});


  $("#quickSearch .button").blur(function() {
    if($(this).val() == '') $(this).val("Zadejte hledané slovo nebo frázi");
  });

  // uvodni strana clanku - vyber tematu
  $("#newArticles_section").change(function () {
    var obj = $(this).parents(".boxArticles").find(".in");
    var section = $(this).val();
    var content = $(obj).html();

    $.ajax({
      type: 'GET',
      url: '/ajax/ajax_getArticles.php',
      data: 'section='+section,
      beforeSend: function() { $(obj).empty(); $(obj).addClass("loading"); },
      error: function(msg) { document.location = '?section='+section; },
      success: function(results) { $(obj).removeClass("loading"); $(obj).html(results); }
    });
  });
  $(".boxArticles form input:submit").addClass("hidden");

  // ajaxova anketa
  $(".boxInquiry form").submit(function () {
    var obj = $(this).parents(".in");
    var action = $(obj).find("input[name='action']").val();
    var inq_id = $(obj).find("input[name='inquiry_id']").val();
    var ans_id = $(obj).find(":checked").val();
    var error = false;

    $.ajax({
      type: 'POST',
      url: '/ajax/ajax_sendVote.php',
      data: 'action='+action+'&inquiry_id='+inq_id+'&answer_id='+ans_id,
      error: function(msg) { alert('AJAX: Chyba při načítání skriptu.'); },
      success: function(results) { $(obj).html(results); }
    });
    return false;
  });

  // vyhledavani
  $("#quickSearch form").submit(function() {
    if($("#quickSearch .button").val() == "Zadejte hledané slovo nebo frázi" || $("#quickSearch .button").val() == '' || $("#quickSearch .button").val().length < 3)
    {
      alert('Zadejte řádnou vyhledávací frázi a odeslání opakujte.');
      return false;
    } else
      return true;
  });

  // odeslani profilu emailem
  $("#sendProfileViaEmail").click(function () {
    $("#sendProfileViaEmail_rhombus").slideToggle("normal");
    return false;
	});

	// podrobný filtr
	$("#filter_displayExtended").click(function () {
	  if ($("#profilesFilter_extended").val() == 0) $("#profilesFilter_extended").val(1);
	  else $("#profilesFilter_extended").val(0);
	  $("#boxes_filterProfiles .extended").slideToggle("normal");
	  return false;
	});

	// registrace
	//$("#registration_login").attr("autocomplete", "off");
  $("#newRegistrationForm #registration_login").blur(function() { return reg_checkUsername ($(this)); });
	$("#newRegistrationForm #registration_email").blur(function() { return reg_checkEmail ($(this)); });
	$("#newRegistrationForm #registration_realName").blur(function() { return reg_checkRealName ($(this)); });
	$("#newRegistrationForm #registration_password2").blur(function() { return reg_checkPasswords ($("#registration_password"), $(this)); });
	$("#newRegistrationForm #registration_phone").blur(function() { return reg_checkPhone ($(this)); });
	$("#newRegistrationForm #registration_www").blur(function() { return reg_checkWeb ($(this)); });
	$("#newRegistrationForm").submit(function() { return reg_validate(); });

	// zakladni nastaveni
	$("#basicSettingsForm #registration_email").blur(function() { return reg_checkEmail ($(this)); });
	$("#basicSettingsForm #registration_realName").blur(function() { return reg_checkRealName ($(this)); });
	$("#basicSettingsForm #registration_password2").blur(function() { return basicSettings_checkPasswords ($("#registration_password"), $(this)); });
	$("#basicSettingsForm #registration_phone").blur(function() { return reg_checkPhone ($(this)); });
	$("#basicSettingsForm #registration_www").blur(function() { return reg_checkWeb ($(this)); });
	$("#basicSettingsForm").submit(function() { return basicSettings_validate(); });

	// profilova ikonka
	$("#newProfileIconForm").submit(function() { return profileIcon_validate(); });
  $("#cropIconForm").submit(function() { return checkCoords(); });
  jQuery('#cropbox').Jcrop({
		aspectRatio: 1,
		onSelect: updateCoords,
		setSelect: [ 0, 0, 100, 100 ]
	});

	// novy vzkaz
 	$("#message_userto").attr("autocomplete", "off");
  $("#message_userto").keyup(function () {
    var username = $(this).val();
    if (username != '')
    {
      $.ajax({
        type: 'GET',
        url: '/ajax/ajax_recipientAutocomplete.php',
        data: 'user='+username,
        success: function(results) {
  	      if (results == '') $("#newMessageForm .inputUserList").addClass("hidden");
  				else
  				{
  	      	$("#newMessageForm .inputUserList").removeClass("hidden");
  	      	$("#newMessageForm .inputUserList").html(results);
    				$("#newMessageForm .inputUserList a").click(function() {
      				var text = $(this).text();
      				$("#message_userto").val(text);
      				$("#newMessageForm .inputUserList").addClass("hidden");
      				return false;
  					});
  			 	}
        }
      });
		}
		else $("#newMessageForm .inputUserList").addClass("hidden");
	});
	$("#newMessageForm").submit(function () { return newMessage_validate (); });

	// vzkazy seznam
	$(".boxMessages td.detailClick a").mouseover(function () {
	  $(this).parents("tr").find(".nick").addClass("highlight");
	  $(this).parents("tr").find(".subject").addClass("highlight");
	  $(this).parents("tr").find(".status").addClass("highlight");
	});
	$(".boxMessages tr").mouseout(function () {
	  $(this).find(".nick").removeClass("highlight");
	  $(this).find(".subject").removeClass("highlight");
	  $(this).find(".status").removeClass("highlight");
	});
	$("#profileMessagesList").submit(function () {
	  if ($(this).find(":checked").length == 0)
		{
			alert ('Nejsou vybrány žádné zprávy k odstranění.');
			return false;
		}
	});

  // editor zprav
  $("#editor_bold").click(function () { insertAroundSelection(document.getElementById("message_text"),'[bold]', '[/bold]'); return false; });
  $("#editor_italic").click(function () { insertAroundSelection(document.getElementById("message_text"),'[italic]', '[/italic]'); return false; });
  $("#editor_url").click(function (){
    var url = prompt ("Zadejte požadovanou url adresu...", "http://");
    if (url != 'http://' && isUrl (url)) insertAroundSelection(document.getElementById("message_text"),'[url='+url+']', '[/url]');
    return false;
  });
  $("#editor_blockquote").click(function () { insertAroundSelection(document.getElementById("message_text"),'[citace]', '[/citace]'); return false; });
  $("#editor_lowerField").click(function () { $('#message_text').animate({ height: $('#message_text').height()-50}, 333 ); return false; });
  $("#editor_upperField").click(function () { $('#message_text').animate({ height: $('#message_text').height()+50}, 333 ); return false; });

  // detail vzkazu
  $("#messages_deleteMessage").click(function () { return confirm("Chcete pokračovat a vzkaz tak nenávratně odstranit?"); });
  $("#messages_addToIgnoreList").click(function () { return confirm("Chcete uživatele přidat do seznamu ignorovaných uživatelů?"); });
  $("#messages_badMessage").click(function () { return confirm("Opravdu chcete vzkaz označit jako nevhodný a odeslat jej redakci k prověření?"); });

  // preposlani vzkazu
  $("#messages_resendMessage").submit(function() {
    if ($("#resendMessage_friend").val() == 0) {
      alert ("Vyberte příjemce zprávy ze seznamu vašich přátel.");
      $("#resendMessage_friend").focus();
      return false;
    }
    return true;
  });

	// zapomenute heslo
  $("#forgetPasswordForm #lostPass_login").blur(function() { return forgetPassword_checkUsername ($(this)); });
	$("#forgetPasswordForm #lostPass_email").blur(function() { return reg_checkEmail ($(this)); });
	$("#forgetPasswordForm").submit(function() { return forgetPassword_validate (); });
	$("#forgetPasswordGenerationForm #lostPass_password2").blur(function() { return reg_checkPasswords ($("#lostPass_password1"), $(this)); });
	$("#forgetPasswordGenerationForm").submit(function()
	{
		if (!reg_checkPasswords ($("#lostPass_password1"), $("#lostPass_password2")))
		{
			$("#lostPass_password1").focus();
		  return false;
		}
		else return true;
	});

	// prihlasovaci formular
 	$("#userLoginForm").submit(function() { return loginForm_validate (); });

  // rychle prihlaseni
  $("#quickLoginBox").submit(function() { return quickLogin_validate (); });

	// kontaktni formular v paticce podwebu
	$("#footerContactForm #contactForm_name").blur(function() { return reg_checkRealName ($(this)); });
	$("#footerContactForm #contactForm_contact").blur(function() { return reg_checkEmail ($(this)); });
	$("#footerContactForm #contactForm_message").blur(function() { return contactForm_checkMessage ($(this)); });
	$("#footerContactForm").submit(function() { return contactForm_validate (); });

	// profil - ikonky a formulare
	$(".boxMainPhoto .ico-delete").click(function () {
	  if (confirm ("Opravdu chcete odstranit hlavní fotografii vašeho profilu?")) return true;
	  else return false;
	});
	$(".boxProfilesPhotos .ico-delete").click(function () {
	  if (confirm ("Nenávratně odstranit tuto fotografii z vašeho profilu?")) return true;
	  else return false;
	});
	$(".boxDiscussion .ico-delete").click(function () {
	  if (confirm ("Nenávratně odstranit tento vzkaz?")) return true;
	  else return false;
	});
	$("#newProfilePhotoForm").submit(function () {
	  if ($("#boxes_newPhoto_photo").val() == '')
	  {
	    alert ("Vyberte platný soubor ve vašem počítači a odeslání opakujte.");
	  	$("#boxes_newPhoto_photo").focus();
	    return false;
		}
		else return true;
	});
	$("#profileNullRating").click(function () {
	  if (confirm ("Opravdu chcete vynulovat vaše průběžné hodnocení?")) return true;
	  else return false;
	});
	$("#profileDeleteVideo").click(function () {
	  if (confirm ("Nenávratně odstranit video z vašeho seznamu?")) return true;
	  else return false;
	});
	$("#boxes_information_substatus").change(function () { $("#chooseYourSubstatus").submit(); });
	$("#boxes_area_areaid").change(function () { $("#chooseAreaForm").submit(); });
	$("#profileNewVideoForm #boxes_newVideo_title").blur(function () { return newVideo_checkTitle($(this)); });
	$("#profileNewVideoForm #boxes_newVideo_url").blur(function () { return newVideo_checkUrl($(this)); });
	$("#profileNewVideoForm").submit(function () { return newVideo_validate(); });
	$("#sendProfileForm").submit(function () { return sendProfile_validate(); });
	$("#newPublicMessageForm #newPublicMessage_subject").blur(function () { return publicMessage_checkSubject($(this)); });
	$("#newPublicMessageForm #newPublicMessage_text").blur(function () { return contactForm_checkMessage($(this)); });
	$("#newPublicMessageForm").submit(function () { return publicMessage_validate(); });

	// kazdemu odkazu, ktery ma title vytvorime bublinu
	/*
	var title;
	if (!isIe)
	{
		$("a[title]").mouseover(function () {
		  title = $(this).attr("title");
	    createTitleTip(title);
		  $(this).removeAttr("title");
		  return false;
		});
		$("a[title!='']").mouseout(function () {
		  $(this).attr ("title", title);
		  destroyTitleTip();
		  return false;
		});
	}*/
	$(".cluetip").cluetip({
    splitTitle: '|',
    showTitle: true,
    tracking: true,
    topOffset: -20,
    positionBy: 'mouse',
    dropShadow: true,
    fx: {
      open: 'fadeIn',
      openSpeed: ''
    }
  });

	// kalendar a jeho ajax refresh
	$(".boxCalendar .left a").click(function () {
    var date = $(".boxCalendar input[name='prevMonth']").val();
    setCalendarContent (date);
    return false;
  });
	$(".boxCalendar .right a").click(function () {
    var date = $(".boxCalendar input[name='nextMonth']").val();
    setCalendarContent (date);
    return false;
  });

	// box ostatni fotogalerie a jax strankovani
	$(".boxOtherGallery a.prev").click(function () {
    var pagenumber = $(".boxOtherGallery input[name='p_plug_og']").val();
    var gallery = $(".boxOtherGallery input[name='gallery']").val();
    setOtherGalleriesContent (pagenumber-1, gallery);
    return false;
  });
	$(".boxOtherGallery a.next").click(function () {
    var pagenumber = $(".boxOtherGallery input[name='p_plug_og']").val();
    var gallery = $(".boxOtherGallery input[name='gallery']").val();
    setOtherGalleriesContent (Number(pagenumber)+1, gallery);
    return false;
  });

  // pridani clanku k oblibenym
  $("#addToFavourites").click(function () {
    var aid = $(".boxArticle .h .hidden").text();
    var obj = $(this).parents("li");
    $.ajax({
      type: 'GET',
      url: '/ajax/ajax_addToFavourites.php',
      data: 'action=addToFavourites&id='+aid,
      error: function(msg) { alert('AJAX: Chyba při načítání skriptu.'); },
      success: function(results) {
        if (results == '') $(obj).remove();
        else alert (results);
      }
    });
    return false;
  });

  // komentare a jejich hodnocenia skryvani
  $(".boxComments .item .rating").removeClass("hidden");
  var commentItems = $(".boxComments .item");
  var rateValue = 0;
  jQuery.each(commentItems, function() {
    rateValue = Number($(this).find(".rating .value").text());
    if (rateValue < -4)
    {
      $(this).find(".text").addClass("hidden");
      $(this).find(".show_hide").removeClass("hidden");
    }
  });
  $(".boxComments .item .show_hide").click(function () {
    if ($(this).hasClass("showed"))
    {
      $(this).parents(".self").find(".text").addClass("hidden");
      $(this).removeClass("showed");
      $(this).text("Ukázat komentář");
    }
    else
    {
      $(this).parents(".self").find(".text").removeClass("hidden");
      $(this).addClass("showed");
      $(this).text("Skrýt komentář");
    }
  });
  $(".boxComments .item .rating a.plus").click(function () {
    var obj = $(this).parents(".rating").find(".value");
    var value = Number($(this).parents(".rating").find(".value").text());
    setRatingValue (obj, value+1, 'plus');
    return false;
  });
  $(".boxComments .item .rating a.minus").click(function () {
    var obj = $(this).parents(".rating").find(".value");
    var value = Number($(this).parents(".rating").find(".value").text());
    setRatingValue (obj, value-1, 'minus');
    return false;
  });

  // filtr komentaru
  $(".boxComments .h .hidden").show();
  $("#boxComments_filter").change(function () {
    switch($(this).val())
    {
      case 'positive':
        jQuery.each(commentItems, function(i, n) {
          rateValue = Number($(this).find(".rating .value").text());
          if (rateValue < 1) $(this).hide();
          else $(this).show();
        });
      break;
      case 'negative':
        jQuery.each(commentItems, function(i, n) {
          rateValue = Number($(this).find(".rating .value").text());
          if (rateValue > -1) $(this).hide();
          else $(this).show();
        });
      break;
      default: jQuery.each(commentItems, function() { $(this).show(); });
    }
  });
  
  $(".boxNextProfile a.next").click(function() {
    var obj = $(this).parents(".box").find(".in");
    $.ajax({
      type: 'GET',
      url: '/ajax/ajax_getRandomUser.php',
      beforeSend: function() { $(obj).empty(); },
      error: function(msg) { document.location = window.location; },
      success: function(results) { $(obj).html(results); }
    });
    return false;
  });

	$("#normalPaging").hide();
	$("#sliderPaging").show().removeClass("hidden");
	$(".paging .prev").click(function () {
    var number = $(".ui-slider-actual").text();
    var locArray = new Array();
    var location = '?';
    if (httpGetVars('q') != '' && httpGetVars('q') != undefined) locArray.push('q='+httpGetVars('q'));
    if (httpGetVars('action') != '' && httpGetVars('action') != undefined) locArray.push('action='+httpGetVars('action'));
    if (httpGetVars('extended') != '' && httpGetVars('extended') != undefined) locArray.push('extended='+httpGetVars('extended'));
    if (httpGetVars('sex') != '' && httpGetVars('sex') != undefined) locArray.push('sex='+httpGetVars('sex'));
    if (httpGetVars('user') != '' && httpGetVars('user') != undefined) locArray.push('user='+httpGetVars('user'));
    if (httpGetVars('area') != '' && httpGetVars('area') != undefined) locArray.push('area='+httpGetVars('area'));
    if (httpGetVars('country') != '' && httpGetVars('country') != undefined) locArray.push('country='+httpGetVars('country'));
    if (httpGetVars('city') != '' && httpGetVars('city') != undefined) locArray.push('city='+httpGetVars('city'));
    if (httpGetVars('dbfriends') != '' && httpGetVars('dbfriends') != undefined) locArray.push('dbfriends='+httpGetVars('dbfriends'));
    if (httpGetVars('dbyesterday') != '' && httpGetVars('dbyesterday') != undefined) locArray.push('dbyesterday='+httpGetVars('dbyesterday'));
    //if (httpGetVars('sort') != '' && httpGetVars('sort') != undefined) locArray.push('sort='+httpGetVars('sort'));
    
    // filtr tanecnich kurzu, parametry strankovani
    if (httpGetVars('style') != '' && httpGetVars('style') != undefined) locArray.push('style='+httpGetVars('style'));
    if (httpGetVars('date') != '' && httpGetVars('date') != undefined) locArray.push('date='+httpGetVars('date'));
    if (httpGetVars('text') != '' && httpGetVars('text') != undefined) locArray.push('text='+httpGetVars('text'));
    if (httpGetVars('day_mo') != '' && httpGetVars('day_mo') != undefined) locArray.push('day_mo='+httpGetVars('day_mo'));
    if (httpGetVars('day_tu') != '' && httpGetVars('day_tu') != undefined) locArray.push('day_tu='+httpGetVars('day_tu'));
    if (httpGetVars('day_we') != '' && httpGetVars('day_we') != undefined) locArray.push('day_we='+httpGetVars('day_we'));
    if (httpGetVars('day_th') != '' && httpGetVars('day_th') != undefined) locArray.push('day_th='+httpGetVars('day_th'));
    if (httpGetVars('day_fr') != '' && httpGetVars('day_fr') != undefined) locArray.push('day_fr='+httpGetVars('day_fr'));
    if (httpGetVars('day_sa') != '' && httpGetVars('day_sa') != undefined) locArray.push('day_sa='+httpGetVars('day_sa'));
    if (httpGetVars('day_su') != '' && httpGetVars('day_su') != undefined) locArray.push('day_su='+httpGetVars('day_su'));
    if (httpGetVars('order') != '' && httpGetVars('order') != undefined) locArray.push('order='+httpGetVars('order'));
    
    // type pole
    if (httpGetVars('types[]') != '' && httpGetVars('types[]') != undefined) {
      var types = httpGetVars('types[]');
      for(i = 0; i < types.length; i++) locArray.push('types[]='+types[i]);
    }
    
    locArray.push('paging='+ (Number(number)-1));
    document.location = location+locArray.join('&');
    return false;
  });
	$(".paging .next").click(function () {
    var number = $(".ui-slider-actual").text();
    var locArray = new Array();
    var location = '?';
    if (httpGetVars('q') != '' && httpGetVars('q') != undefined) locArray.push('q='+httpGetVars('q'));
    if (httpGetVars('action') != '' && httpGetVars('action') != undefined) locArray.push('action='+httpGetVars('action'));
    if (httpGetVars('extended') != '' && httpGetVars('extended') != undefined) locArray.push('extended='+httpGetVars('extended'));
    if (httpGetVars('sex') != '' && httpGetVars('sex') != undefined) locArray.push('sex='+httpGetVars('sex'));
    if (httpGetVars('user') != '' && httpGetVars('user') != undefined) locArray.push('user='+httpGetVars('user'));
    if (httpGetVars('area') != '' && httpGetVars('area') != undefined) locArray.push('area='+httpGetVars('area'));
    if (httpGetVars('country') != '' && httpGetVars('country') != undefined) locArray.push('country='+httpGetVars('country'));
    if (httpGetVars('city') != '' && httpGetVars('city') != undefined) locArray.push('city='+httpGetVars('city'));
    if (httpGetVars('dbfriends') != '' && httpGetVars('dbfriends') != undefined) locArray.push('dbfriends='+httpGetVars('dbfriends'));
    if (httpGetVars('dbyesterday') != '' && httpGetVars('dbyesterday') != undefined) locArray.push('dbyesterday='+httpGetVars('dbyesterday'));
    //if (httpGetVars('sort') != '' && httpGetVars('sort') != undefined) locArray.push('sort='+httpGetVars('sort'));
    
    // filtr tanecnich kurzu, parametry strankovani
    if (httpGetVars('style') != '' && httpGetVars('style') != undefined) locArray.push('style='+httpGetVars('style'));
    if (httpGetVars('date') != '' && httpGetVars('date') != undefined) locArray.push('date='+httpGetVars('date'));
    if (httpGetVars('text') != '' && httpGetVars('text') != undefined) locArray.push('text='+httpGetVars('text'));
    if (httpGetVars('day_mo') != '' && httpGetVars('day_mo') != undefined) locArray.push('day_mo='+httpGetVars('day_mo'));
    if (httpGetVars('day_tu') != '' && httpGetVars('day_tu') != undefined) locArray.push('day_tu='+httpGetVars('day_tu'));
    if (httpGetVars('day_we') != '' && httpGetVars('day_we') != undefined) locArray.push('day_we='+httpGetVars('day_we'));
    if (httpGetVars('day_th') != '' && httpGetVars('day_th') != undefined) locArray.push('day_th='+httpGetVars('day_th'));
    if (httpGetVars('day_fr') != '' && httpGetVars('day_fr') != undefined) locArray.push('day_fr='+httpGetVars('day_fr'));
    if (httpGetVars('day_sa') != '' && httpGetVars('day_sa') != undefined) locArray.push('day_sa='+httpGetVars('day_sa'));
    if (httpGetVars('day_su') != '' && httpGetVars('day_su') != undefined) locArray.push('day_su='+httpGetVars('day_su'));
    if (httpGetVars('order') != '' && httpGetVars('order') != undefined) locArray.push('order='+httpGetVars('order'));
    
    // type pole
    if (httpGetVars('types[]') != '' && httpGetVars('types[]') != undefined) {
      var types = httpGetVars('types[]');
      for(i = 0; i < types.length; i++) locArray.push('types[]='+types[i]);
    }
    
    locArray.push('paging='+ (Number(number)+1));
    document.location = location+locArray.join('&');
    return false;
  });
  
  // datepicker
  $('.datepicker-min').datepick({changeMonth: false, changeYear: false, showAnim:'fadeIn', dateFormat:'yy-mm-dd', minDate: 0});
  $('.datepicker').datepick({changeMonth: false, changeYear: false, showAnim:'fadeIn', dateFormat:'yy-mm-dd'});

  // kurzy
  $('.boxNewCourse .morePhotos').hide();
  $('.boxNewCourse .display a').click(function() { $('.boxNewCourse .morePhotos').show(); return false; });
  $('.boxNewCourse .clone .col2 .new a').click(function() {
    var label =   $('.boxNewCourse .clone .col1 label').clone();
    var select =  $('.boxNewCourse .clone .col1 select').clone();

    $(this).parents(".col2").find("p").remove();
    $(label).attr('for', 'newcourse_style2');
    $(select).attr('name', 'style2').attr('id', 'newcourse_style2');

    $('.boxNewCourse .clone .col2').append(label).append(select);
    $('.boxNewCourse .clone .col3 .new').show();
    return false;
  });
  $('.boxNewCourse .clone .col3 .new a').click(function() {
    var label =   $('.boxNewCourse .clone .col1 label').clone();
    var select =  $('.boxNewCourse .clone .col1 select').clone();

    $(this).parents(".col3").find("p").remove();
    $(label).attr('for', 'newcourse_style3');
    $(select).attr('name', 'style3').attr('id', 'newcourse_style3');

    $('.boxNewCourse .clone .col3').append(label).append(select);
    return false;
  });
  if($(".boxNewCourse .repeat_course #newcourse_repeat1").attr("checked")) {
    $(".boxNewCourse .repeat_days").hide();
    $(".boxNewCourse .repeat_days :checkbox").attr("disabled", "disabled");
  }
  $(".boxNewCourse .repeat_course input:radio").change(function() {
    if($(this).val() == 1) {
      $(this).parents(".in").find(".repeat_days").show();
      $(this).parents(".in").find(".repeat_days :checkbox").attr("disabled", "");
    } else {
      $(this).parents(".in").find(".repeat_days").hide();
      $(this).parents(".in").find(".repeat_days :checkbox").attr("disabled", "disabled");
    }
  });
  
  // filtr kurzu
  $("#coursefilter_order").change(function() {
    $(this).parents("form").submit();
    return false;
  });
  $(".boxCourses .filter .checkboxes").hide();
  $(".boxCourses .filter .checkboxes :checkbox").attr("disabled", "disabled");
  $(".boxCourses .filter input:radio").change(function() {
    if($(this).val() == 1) {
      $(this).parents(".filter").find(".checkboxes").show();
      $(this).parents(".filter").find(".checkboxes :checkbox").attr("disabled", "");
    } else {
      $(this).parents(".filter").find(".checkboxes").hide();
      $(this).parents(".filter").find(".checkboxes :checkbox").attr("disabled", "disabled");
    }
  });
  
  
  // dashboard
  // actions button on hover
  $(".boxDashboard .actions").hide();
  $(".boxDashboard .item").hover(
    function() {
      $(this).find(".actions").show();
    }, 
    function() {
      $(this).find(".actions").hide();
    }
  );
  
});

function httpGetVars (name)
{
  var pole = unescape(window.location.search).substr(1).split("&");
  var httpGetVars = new Array();
  for(i = 0; i < pole.length; i++) {
      if(pole[i].split("=")[0].substr(pole[i].split("=")[0].length - 2) == '[]') {
        if(!httpGetVars[pole[i].split("=")[0]]) httpGetVars[pole[i].split("=")[0]] = new Array();
        httpGetVars[pole[i].split("=")[0]].push(pole[i].split("=")[1]);
      } else httpGetVars[pole[i].split("=")[0]] = pole[i].split("=")[1];
  }
  return httpGetVars[name];
}

function pagingSlider (number, maxnumber)
{
  $('#slider').slider({
    steps: (maxnumber - 1),
    startValue: (number - 1),
    maxValue: (maxnumber - 1),
    slide: function(e, ui) { $('#slider span').text(ui.value + 1); },
    change: function(e, ui) {
      var locArray = new Array();
      var location = '?';
      if (httpGetVars('q') != '' && httpGetVars('q') != undefined) locArray.push('q='+httpGetVars('q'));
      
      if (httpGetVars('action') != '' && httpGetVars('action') != undefined) locArray.push('action='+httpGetVars('action'));
      if (httpGetVars('extended') != '' && httpGetVars('extended') != undefined) locArray.push('extended='+httpGetVars('extended'));
      if (httpGetVars('sex') != '' && httpGetVars('sex') != undefined) locArray.push('sex='+httpGetVars('sex'));
      if (httpGetVars('user') != '' && httpGetVars('user') != undefined) locArray.push('user='+httpGetVars('user'));
      if (httpGetVars('area') != '' && httpGetVars('area') != undefined) locArray.push('area='+httpGetVars('area'));
      if (httpGetVars('country') != '' && httpGetVars('country') != undefined) locArray.push('country='+httpGetVars('country'));
      if (httpGetVars('city') != '' && httpGetVars('city') != undefined) locArray.push('city='+httpGetVars('city'));
      if (httpGetVars('dbfriends') != '' && httpGetVars('dbfriends') != undefined) locArray.push('dbfriends='+httpGetVars('dbfriends'));
      if (httpGetVars('dbyesterday') != '' && httpGetVars('dbyesterday') != undefined) locArray.push('dbyesterday='+httpGetVars('dbyesterday'));
      //if (httpGetVars('sort') != '' && httpGetVars('sort') != undefined) locArray.push('sort='+httpGetVars('sort'));
      
      // filtr tanecnich kurzu, parametry strankovani
      if (httpGetVars('style') != '' && httpGetVars('style') != undefined) locArray.push('style='+httpGetVars('style'));
      if (httpGetVars('date') != '' && httpGetVars('date') != undefined) locArray.push('date='+httpGetVars('date'));
      if (httpGetVars('text') != '' && httpGetVars('text') != undefined) locArray.push('text='+httpGetVars('text'));
      if (httpGetVars('day_mo') != '' && httpGetVars('day_mo') != undefined) locArray.push('day_mo='+httpGetVars('day_mo'));
      if (httpGetVars('day_tu') != '' && httpGetVars('day_tu') != undefined) locArray.push('day_tu='+httpGetVars('day_tu'));
      if (httpGetVars('day_we') != '' && httpGetVars('day_we') != undefined) locArray.push('day_we='+httpGetVars('day_we'));
      if (httpGetVars('day_th') != '' && httpGetVars('day_th') != undefined) locArray.push('day_th='+httpGetVars('day_th'));
      if (httpGetVars('day_fr') != '' && httpGetVars('day_fr') != undefined) locArray.push('day_fr='+httpGetVars('day_fr'));
      if (httpGetVars('day_sa') != '' && httpGetVars('day_sa') != undefined) locArray.push('day_sa='+httpGetVars('day_sa'));
      if (httpGetVars('day_su') != '' && httpGetVars('day_su') != undefined) locArray.push('day_su='+httpGetVars('day_su'));
      if (httpGetVars('order') != '' && httpGetVars('order') != undefined) locArray.push('order='+httpGetVars('order'));
      
      // type pole
      if (httpGetVars('types[]') != '' && httpGetVars('types[]') != undefined) {
        var types = httpGetVars('types[]');
        for(i = 0; i < types.length; i++) locArray.push('types[]='+types[i]);
      }
      
      locArray.push('paging='+ (Number(ui.value)+1));
      //alert(location+locArray.join('&'));
      document.location = location+locArray.join('&');
    }
  });
}

function loadArticles (pageNumber)
{
  var obj = $(".boxArticles .in");
  $.ajax({
    type: 'GET',
    url: '/ajax/ajax_getArticles.php',
    data: 'sekce='+httpGetVars("sekce")+'&paging='+ pageNumber,
    beforeSend: function() { $(obj).empty(); $(obj).addClass("loading"); },
    error: function(msg) { document.location = '?section='+section; },
    success: function(results) { $(obj).removeClass("loading"); $(obj).html(results); }
  });
  return true;
}

function setRatingValue (obj, value, direction)
{
  var comm_id = $(obj).parents(".item").find("input[name='comment_id']").val();
  $.ajax({
    type: 'GET',
    url: '/ajax/ajax_rateComment.php',
    data: 'action=rateComment&id='+comm_id+'&direction='+direction,
    error: function(msg) { alert('AJAX: Chyba při načítání skriptu.'); },
    success: function(results) {
      if (results != '') alert(results);
      else
      {
        if (value < 0)
        {
          $(obj).addClass("minus");
          $(obj).text(value);
        }
        else if (value == 0)
        {
          $(obj).removeClass("minus");
          $(obj).removeClass("plus");
          $(obj).text(value);
        }
        else if (value > 0)
        {
          $(obj).addClass("plus");
          $(obj).text('+'+value);
        }

        switch (direction)
        {
          case 'plus':
            if (value == -4)
            {
              $(obj).parents(".item").find(".text").removeClass("hidden");
              $(obj).parents(".item").find(".show_hide").addClass("showed");
              $(obj).parents(".item").find(".show_hide").addClass("hidden");
            }
          break;
          case 'minus':
            if (value == -5)
            {
              $(obj).parents(".item").find(".text").addClass("hidden");
              $(obj).parents(".item").find(".show_hide").removeClass("showed");
              $(obj).parents(".item").find(".show_hide").removeClass("hidden");
              $(obj).parents(".item").find(".show_hide").text("Ukázat komentář");
            }
          break;
        }
      }
    }
  });
}

function cancelCommentReaction (id)
{
  $("#articleCommentsForm input[name='reply']").val(0);
  $("#articleCommentsForm input[name='level']").val(0);
  $("#articleCommentsForm input[name='comments_subject']").val('');
  $("#articleCommentsForm .react_message").hide();
  $("#comment_"+id).removeClass("marked");
  //$("#articleCommentsForm .react_message").remove();
}

function sendArticle (obj)
{
  if ($(obj).find("input[name='name']").val() == "") {
    alert ("Vyplňte Vaše jméno.");
    $(obj).find("input[name='name']").focus();
    return false;
  }
  if (!isEmail ($(obj).find("input[name='emailFrom']").val())) {
    alert ("Vyplňte Vaši e-mailovou adresu.");
    $(obj).find("input[name='emailFrom']").focus();
    return false;
  }
  if ($(obj).find("input[name='emailTo']").val() == "") {
    alert ("Vyplňte e-mailovou adresu adresáta zprávy.");
    $(obj).find("input[name='emailTo']").focus();
    return false;
  }
  else
  {
    var emails = $(obj).find("input[name='emailTo']").val().split(',');
    var error = false;
    jQuery.each(emails, function (i, val) {
      val = jQuery.trim(val);
      if (val != "")
        if (!isEmail (val)) error = true;
    });

    if (error)
    {
      alert("Nevhodně zadaná e-mailová adresa nebo jejich rozsah.");
      $(obj).find("input[name='emailTo']").focus();
    }
    return !error;
  }
  return true;
}

function setCalendarContent(date)
{
  var obj = $(".boxCalendar .in");
  $.ajax({
    type: 'GET',
    url: '/ajax/ajax_calendarHtml.php',
    data: 'date='+date,
    error: function(msg) { document.location = '?date='+date; },
    success: function(results) { $(obj).html(results); }
  });
}

function setOtherGalleriesContent(pagenumber, gallery_id)
{
  var obj = $(".boxOtherGallery .in");
  $.ajax({
    type: 'GET',
    url: '/ajax/ajax_getOtherGalleries.php',
    data: 'p_plug_og='+pagenumber+'&gallery='+gallery_id,
    beforeSend: function() { $(obj).empty(); $(obj).addClass("loading"); },
    error: function(msg) { alert('AJAX: Chyba při načítání skriptu.'); },
    success: function(results) { $(obj).removeClass("loading"); $(obj).html(results); }
  });
}


// overeni platnosti emailu
function isEmail(value)
{
  re = /^[-a-z0-9!#$%&\'*+/=?^_`{|}~]+(\.[-a-z0-9!#$%&\'*+/=?^_`{|}~]+)*@([^.]+[.])+[a-z]{2,3}$/;
  return value.search(re) == 0;
}

// overeni platnosti telefonu
function isPhone(value)
{
	if (value == '+420') return true;
  re = /^\+[0-9]{12}$/;
  return value.search(re) == 0;
}

// overeni platnosti telefonu
function isUrl(value)
{
  if (value == 'http://') return true;
  re = /^\http:\/\/([a-z0-9-_]+\.)*[a-z0-9-_]+\.[a-z]{2,4}([^.]+)*$/;
  return value.search(re) == 0;
}

function reg_checkUsername (obj)
{
	var name = $(obj).val();
	var send = true;
	if (name != '')
	{
    $.ajax({
      type: 'GET',
      url: '/ajax/ajax_regCheckUsername.php',
      data: 'user_name='+name,
      error: function(msg) { $(obj).removeClass("button_error"); $(obj).removeAttr("title"); },
      success: function(results) {
  			if (results == '')
  			{
  				$(obj).removeClass("button_error");
  				$(obj).removeAttr("title");
  			}
  			else
  			{
  				$(obj).addClass("button_error");
  				$(obj).attr("title", 'Uživatelské jméno '+name+' již v databázi existuje. Zvolte si prosím jiné, které je doposud volné.');
  			}
      }
    });

		if ($(obj).hasClass("button_error")) send = false;
	}
	else
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Kolonka s uživatelským jménem musí být vyplněna.");
		send = false;
	}
	return send;
}

function reg_checkEmail (obj)
{
	if (!isEmail ($(obj).val()))
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Nevhodně zadaná emailová adresa.");
		return false;
	}
	else
	{
		$(obj).removeClass("button_error");
		$(obj).removeAttr("title");
		return true;
	}
}

function reg_checkRealName (obj)
{
	if ($(obj).val() == '')
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Kolonka s vaším jménem musí být vyplněna.");
		return false;
	}
	else
	{
		$(obj).removeClass("button_error");
		$(obj).removeAttr("title");
		return true;
	}
}

function reg_checkPasswords (p1, p2)
{
	var alt = "Zadaná hesla se neshodují nebo jsou kratší než 5 znaků.";
	if ($(p1).val() == '' ||
			$(p1).val().length < 5 ||
			$(p2).val() == '' ||
			$(p2).val().length < 5 ||
			$(p1).val() != $(p2).val()
	)
	{
	 	$(p1).addClass("button_error");
		$(p2).addClass("button_error");
		$(p1).attr("title", alt);
		$(p2).attr("title", alt);
		return false;
	}
	else
	{
		$(p1).removeClass("button_error");
		$(p2).removeClass("button_error");
		$(p1).removeAttr("title");
		$(p2).removeAttr("title");
		return true;
	}
}

function reg_checkPhone (obj)
{
	if ($(obj).val() != '' && !isPhone ($(obj).val()))
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Nevhodný tvar telefonního čísla - zadejte ve formátu: +420723xxxYYYzzz");
		return false;
	}
	else
	{
		$(obj).removeClass("button_error");
		$(obj).removeAttr("title");
		return true;
	}
}

function reg_checkWeb (obj)
{
	if ($(obj).val() != '' && !isUrl ($(obj).val()))
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Nevhodný tvar vaší webové adresy.");
		return false;
	}
	else
	{
		$(obj).removeClass("button_error");
		$(obj).removeAttr("title");
		return true;
	}
}

function newVideo_checkTitle (obj)
{
	if ($(obj).val() == '')
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Kolonka s titulkem videa musí být vyplněna");
		return false;
	}
	else
	{
		$(obj).removeClass("button_error");
		$(obj).removeAttr("title");
		return true;
	}
}

function newVideo_checkUrl (obj)
{
	var value = obj.val();
  if (value == 'http://') return true;
  re = /^http:\/\/(www\.)*([a-z]+.)*youtube.com\/watch\?v=[a-zA-Z0-9_-]{11}.*$/;

	if (value.search(re) != 0)
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Nevhodný tvar adresy vkládaného videa");
		return false;
	}
	else
	{
		$(obj).removeClass("button_error");
		$(obj).removeAttr("title");
		return true;
	}
}

function newMessage_checkUserto (obj1, obj2)
{
	if ($(obj1).val() == '' && $(obj2).val() == '')
	{
	  $(obj1).addClass("button_error");
	  $(obj2).addClass("button_error");
	  $(obj1).attr("title", "Příjemce vzkazu není vyplněn.");
	  $(obj2).attr("title", "Příjemce vzkazu není vyplněn.");
	  return false;
	}
	else
	{
		$(obj1).removeClass("button_error");
		$(obj2).removeClass("button_error");
		$(obj1).removeAttr("title");
		$(obj2).removeAttr("title");
		return true;
	}
}

function newMessage_validate ()
{
	var send = true;
	var focus = $("#message_friend");

	if (!newMessage_checkUserto ($("#message_friend"), $("#message_userto")))
	{
		if (send) focus = $("#message_friend");
		send = false;
	}
	if (!publicMessage_checkSubject ($("#message_subject")))
	{
		if (send) focus = $("#message_subject");
		send = false;
 	}
	if (!contactForm_checkMessage ($("#message_text")))
	{
		if (send) focus = $("#message_text");
		send = false;
	}

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function reg_validate ()
{
	var send = true;
	var focus = $("#registration_email");

	if (!reg_checkEmail ($("#registration_email")))
	{
		if (send) focus = $("#registration_email");
		send = false;
	}
	if (!reg_checkRealName ($("#registration_realName")))
	{
		if (send) focus = $("#registration_realName");
		send = false;
 	}
	if (!reg_checkUsername ($("#registration_login")))
	{
		if (send) focus = $("#registration_login");
		send = false;
	}
	if (!reg_checkPasswords ($("#registration_password"), $("#registration_password2")))
	{
		if (send) focus = $("#registration_password");
		send = false;
	}
	if (!reg_checkPhone ($("#registration_phone")))
	{
		if (send) focus = $("#registration_phone");
		send = false;
	}
	if (!reg_checkWeb ($("#registration_www")))
	{
		if (send) focus = $("#registration_www");
		send = false;
	}
	if ($("#newRegistrationForm :checkbox:checked").length == 0)
	{
		if (send)
		{
			focus = $("#registration_confirm");
			focus.attr("title", "Musíte vyjádřit váš souhlas s podmínkami registrace.");
		}
		send = false;
	}

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function basicSettings_validate ()
{
	var send = true;
	var focus = $("#registration_email");

	if (!reg_checkEmail ($("#registration_email")))
	{
		if (send) focus = $("#registration_email");
		send = false;
	}
	if (!reg_checkRealName ($("#registration_realName")))
	{
		if (send) focus = $("#registration_realName");
		send = false;
 	}
	if (!basicSettings_checkPasswords ($("#registration_password"), $("#registration_password2")))
	{
		if (send) focus = $("#registration_password");
		send = false;
	}
	if (!reg_checkPhone ($("#registration_phone")))
	{
		if (send) focus = $("#registration_phone");
		send = false;
	}
	if (!reg_checkWeb ($("#registration_www")))
	{
		if (send) focus = $("#registration_www");
		send = false;
	}

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function articleComment_validate ()
{
	var send = true;
	var focus = $("#newComment_subject");

	if ($("#newComment_subject").val() == '')
	{
		if (send) focus = $("#newComment_subject");
		$("#newComment_subject").attr("title", "Vyplňte předmět komentáře");
		$("#newComment_subject").addClass("button_error");
		send = false;
	}
	else
	{
    $("#newComment_subject").removeClass("button_error");
    $("#newComment_subject").removeAttr("title");
  }

	if ($("#newComment_text").val().length < 10)
	{
		if (send) focus = $("#newComment_text");
		$("#newComment_text").attr("title", "Text komentáře je příliš krátký ...");
		$("#newComment_text").addClass("button_error");
		send = false;
	}
	else
	{
    $("#newComment_text").removeClass("button_error");
    $("#newComment_text").removeAttr("title");
  }

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function profileIcon_validate ()
{
	var send = true;
	var focus = $("#profileIcon_file");

	if ($("#profileIcon_file").val() == '')
	{
		if (send) focus = $("#profileIcon_file");
		$("#profileIcon_file").attr("title", "Vyberte platný soubor z vašeho počítače.");
		send = false;
	}

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function loginForm_validate ()
{
	var send = true;
	var focus = $("#loginForm_name");

	if ($("#loginForm_name").val() == '')
	{
		if (send) focus = $("#loginForm_name");
		$("#loginForm_name").addClass("button_error");
		$("#loginForm_name").attr("title", "Vyplňte vaše uživatelské jméno");
		send = false;
	}
	else
  {
    $("#loginForm_name").removeClass("button_error");
    $("#loginForm_name").removeAttr("title");
  }

	if ($("#loginForm_password").val() == '')
	{
		$("#loginForm_password").addClass("button_error");
		$("#loginForm_password").attr("title", "Vyplňte vaše heslo a odeslání opakujte");
		if (send) focus = $("#loginForm_password");
		send = false;
	}
	else
  {
    $("#loginForm_password").removeClass("button_error");
    $("#loginForm_password").removeAttr("title");
  }

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function quickLogin_validate ()
{
	var send = true;
	var focus = $("#userAuth_username");

	if ($("#userAuth_username").val() == '')
	{
		if (send) focus = $("#userAuth_username");
		$("#userAuth_username").addClass("button_error");
		$("#userAuth_username").attr("title", "Vyplňte vaše uživatelské jméno");
		send = false;
	}
	else
  {
    $("#userAuth_username").removeClass("button_error");
    $("#userAuth_username").removeAttr("title");
  }

	if ($("#userAuth_password").val() == '')
	{
		$("#userAuth_password").addClass("button_error");
		$("#userAuth_password").attr("title", "Vyplňte vaše heslo a odeslání opakujte");
		if (send) focus = $("#userAuth_password");
		send = false;
	}
	else
  {
    $("#userAuth_password").removeClass("button_error");
    $("#userAuth_password").removeAttr("title");
  }

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function basicSettings_checkPasswords (p1, p2)
{
	var alt = "Zadaná hesla se neshodují nebo jsou kratší než 5 znaků.";
	if (($(p1).val() != '' || $(p2).val() != '') &&
			($(p1).val().length < 5 || $(p2).val().length < 5 || $(p1).val() != $(p2).val())
	)
	{
	 	$(p1).addClass("button_error");
		$(p2).addClass("button_error");
		$(p1).attr("title", alt);
		$(p2).attr("title", alt);
		return false;
	}
	else
	{
		$(p1).removeClass("button_error");
		$(p2).removeClass("button_error");
		$(p1).removeAttr("title");
		$(p2).removeAttr("title");
		return true;
	}
}

function forgetPassword_checkUsername (obj)
{
	var name = $(obj).val();
	var send = true;
	if (name != '')
	{
    $.ajax({
      type: 'GET',
      url: '/ajax/ajax_regCheckUsername.php',
      data: 'user_name='+name,
      error: function(msg) { $(obj).removeClass("button_error"); $(obj).removeAttr("title"); },
      success: function(results) {
  			if (results == '')
  			{
  				$(obj).addClass("button_error");
  				$(obj).attr("title", "Zvolené uživatelské jméno se v databázi nevyskytuje.");
  			}
  			else
  			{
  				$(obj).removeClass("button_error");
  				$(obj).removeAttr("title");
  			}
      }
    });

		if ($(obj).hasClass("button_error")) send = false;
	}
	else
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Kolonka s uživatelským jménem musí být vyplněna.");
		send = false;
	}
	return send;
}

function forgetPassword_validate ()
{
	var send = true;
	var focus = $("#lostPass_login");

	if (!forgetPassword_checkUsername ($("#lostPass_login")))
	{
		if (send) focus = $("#lostPass_login");
		send = false;
	}
	if (!reg_checkEmail ($("#lostPass_email")))
	{
		if (send) focus = $("#lostPass_email");
		send = false;
	}

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function contactForm_checkMessage (obj)
{
	if ($(obj).val() == '' || $(obj).val().length < 10)
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Text vzkazu musí být minimálně 10 znaků dlouhý.");
		return false;
	}
	else
	{
		$(obj).removeClass("button_error");
		$(obj).removeAttr("title");
		return true;
	}
}

function contactForm_validate ()
{
	var send = true;
	var focus = $("#contactForm_name");

	if (!reg_checkRealName ($("#contactForm_name")))
	{
		if (send) focus = $("#contactForm_name");
		send = false;
	}
	if (!reg_checkEmail ($("#contactForm_contact")))
	{
		if (send) focus = $("#contactForm_contact");
		send = false;
	}
	if (!contactForm_checkMessage ($("#contactForm_message")))
	{
		if (send) focus = $("#contactForm_message");
		send = false;
	}

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function newVideo_validate ()
{
	var send = true;
	var focus = $("#boxes_newVideo_title");

	if (!newVideo_checkTitle ($("#boxes_newVideo_title")))
	{
		if (send) focus = $("#boxes_newVideo_title");
		send = false;
	}
	if (!newVideo_checkUrl ($("#boxes_newVideo_url")))
	{
		if (send) focus = $("#boxes_newVideo_url");
		send = false;
	}

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function sendProfile_validate ()
{
	var send = true;
	var focus = $("#sendProfile_userto");

	if ($("#sendProfile_userto").val() == null)
	{
	  $("#sendProfile_userto").addClass("button_error");
	  $("#sendProfile_userto").attr("title", "Vyberte příjemce ze seznamu vašich přátel")
		if (send) focus = $("#sendProfile_userto");
		send = false;
	}
	else
  {
    $("#sendProfile_userto").removeClass("button_error");
    $("#sendProfile_userto").removeAttr("title");
  }

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function publicMessage_validate ()
{
	var send = true;
	var focus = $("#newPublicMessage_subject");

	if (!publicMessage_checkSubject ($("#newPublicMessage_subject")))
	{
		if (send) focus = $("#newPublicMessage_subject");
		send = false;
	}
	if (!contactForm_checkMessage ($("#newPublicMessage_text")))
	{
		if (send) focus = $("#newPublicMessage_text");
		send = false;
	}

	if (!send)
  {
    focus.focus();
    alert (focus.attr("title"));
  }
	return send;
}

function publicMessage_checkSubject (obj)
{
	if ($(obj).val() == '')
	{
		$(obj).addClass("button_error");
		$(obj).attr("title", "Kolonka s předmětem zprávy musí být vyplněna.");
		return false;
	}
	else
	{
		$(obj).removeClass("button_error");
		$(obj).removeAttr("title");
		return true;
	}
}

// vložení kolem vybraného textu
function insertAroundSelection(obj,startVal,endVal)
{
  var o = obj;
  o.focus();
  if (document.selection)
  {
    sel = document.selection.createRange();
    var selText = sel.text;
    sel.text = startVal + selText + endVal;
  }
  else if (o.selectionStart || o.selectionStart == '0')
  {
    var startPos = o.selectionStart;
    var endPos = o.selectionEnd;
    o.value = o.value.substring (0,startPos) + startVal + o.value.substring (startPos,endPos) + endVal + o.value.substring (endPos,o.value.length);
    setCursorPos (o, startPos,startPos);
  }
  else
  {
    o.value += startVal + endVal;
    setCursorPos (o, startPos, startPos);
  }
  return false;
}
