/** JS pro ucetni.cz (c) Marek Aufart 2010 www.aurem.cz */

$(document).ready(function(){

$('a.anketa_odkaz').each(function(){
	$(this).attr('href', $(this).attr('href').replace('#',''));
});

$('.up_detail').hide();
$('.up_obj').hide();

$(".form_text_html").submit(function (){
  var t = $("#fth_text1").text();
  $("#fth_text_input1").text(t.replace(/'/g, "\""));

});
 // var t = $(".otazka_text").text();
 // $(".otazka_text").text(t.replace(/\n/g, "<br />"));

$('.tag_otazek').click(function () {
  var cil = $(this).attr('href');
  document.location = cil;
  return false;
});

$(".forum_admin_panel").hide();
$("a.forum_admin_ovladac").click(function(){
  var div="#forum_admin_panel_"+$(this).attr("title");
  $(div).toggle(300);
  return false;
});
$(".forum_admin_skryvac").click(function(){
  var div="#forum_admin_panel_"+$(this).attr("title");
  $(div).toggle(300);
  return false;
});

$(".jq_form_otazka").focus(
	function () {
		var t = $(this).attr("title");
		$("#form_napoveda").hide();
		$("#form_napoveda").text(t);
		$("#form_napoveda").fadeIn();
	});
$("#forum_polozit_dotaz").hide();
$(".link_polozit_dotaz").click(
	function () {
		$("#forum_polozit_dotaz").show("slow");
		$(".link_polozit_dotaz").hide();
		return false;
	});
$(".zrus_form_polozit_dotaz").click(
	function () {
		$("#forum_polozit_dotaz").hide();
		$(".link_polozit_dotaz").show();
		return false;
	});

$('.ma_roky').hide();

$('.rok_ma').click(function () {
  $('.ma_roky:visible').hide();
  var div="#ma_"+$(this).attr("title");
  $(div).fadeIn();
});

$(".jqc_form1").submit(function (){

  var chyby="";

  $(".jqc_form1 .jqc_text").each(function() {
    var d = jQuery.trim($(this).val());
    if (d=="") {
      $(this).css( "background", "#ff8888" );
      chyby+=" - nevyplněné pole "+$(this).attr("name")+"\n";
    } else {
      $(this).css( "background", "#ffffff" );
    }
  });

  $(".jqc_form1 .jqc_num").each(function() {
    var d = jQuery.trim($(this).val());
    if (!d.match(/^[0-9\+\-\ ]+$/)) {
      $(this).css( "background", "#ff8888" );
      chyby+=" - číslo v poli "+$(this).attr("name")+"\n";
    } else {
      $(this).css( "background", "#ffffff" );
    }
  });

  $(".jqc_form1 .jqc_email").each(function() {
    var d = jQuery.trim($(this).val());
    if (!d.match(/^.+@.+\.[a-zA-Z]+$/)) {
      $(this).css( "background", "#ff8888" );
      chyby+=" - chybný email v poli "+$(this).attr("name")+"\n";
    } else {
      $(this).css( "background", "#ffffff" );
    }
  });
  
  $(".jqc_form1 input.jqc_passwd2").each(function() {
    if ($(this).val()!=$("#jqc_form1 input.jqc_passwd").val()) {
      $(this).css( "background", "#ff8888" );
      chyby+=" - hesla se neshodují "+"\n";
    } else {
      $(this).css( "background", "#ffffff" );
    }
  });
 
 if (chyby!="") {
    alert("Špatně vyplněný formulář:\n"+chyby+"prosím, opravte...");
    return false;
  } else {
    return true;
  }
});

$(".jqc_form2").submit(function (){

  var chyby="";

  $(".jqc_form2 .jqc_text").each(function() {
    var d = jQuery.trim($(this).val());
    if (d=="") {
      $(this).css( "background", "#ff8888" );
      chyby+=" - nevyplněné pole "+$(this).attr("name")+"\n";
    } else {
      $(this).css( "background", "#ffffff" );
    }
  });

  $(".jqc_form2 .jqc_num").each(function() {
    var d = jQuery.trim($(this).val());
    if (!d.match(/^[0-9\+\-\ ]+$/)) {
      $(this).css( "background", "#ff8888" );
      chyby+=" - číslo v poli "+$(this).attr("name")+"\n";
    } else {
      $(this).css( "background", "#ffffff" );
    }
  });

  $(".jqc_form2 .jqc_email").each(function() {
    var d = jQuery.trim($(this).val());
    if (!d.match(/^.+@.+\.[a-zA-Z]+$/)) {
      $(this).css( "background", "#ff8888" );
      chyby+=" - chybný email v poli "+$(this).attr("name")+"\n";
    } else {
      $(this).css( "background", "#ffffff" );
    }
  });
  
  $(".jqc_form2 input.jqc_passwd2").each(function() {
    if ($(this).val()!=$("#jqc_form1 input.jqc_passwd").val()) {
      $(this).css( "background", "#ff8888" );
      chyby+=" - hesla se neshodují "+"\n";
    } else {
      $(this).css( "background", "#ffffff" );
    }
  });
 
 if (chyby!="") {
    alert("Špatně vyplněný formulář:\n"+chyby+"prosím, opravte...");
    return false;
  } else {
    return true;
  }
});

});
