$(document).ready(function() {

$("#domeny").hide();
$("#domeny").prevAll('label:first').hide();
$("#domeny").next('br').hide();

prenajata_domena();

$(function(){
  $("input[@name='prenajata_domena']").change(function(){
    prenajata_domena() ;
  }
  )
});

function prenajata_domena() {    
    if ($("input[name='prenajata_domena']:checked").val()==1){
      $("#domeny").show();
      $("#domeny").prevAll('label:first').show();
      $("#domeny").next('br').show();     
    } else{
      $("#domeny").hide();
      $("#domeny").prevAll('label:first').hide();
      $("#domeny").next('br').hide();    
    }
}   

$(function(){
  $("select#kategoria1").change(function(){
    $("select#kategoria2").children("optgroup").children("option").each(function(x) {
      if ($(this).val() == $("select#kategoria1").val()){
        $(this).remove();
      }
    });
    $("select#kategoria3").children("optgroup").children("option").each(function(x) {
      if ($(this).val() == $("select#kategoria1").val()){
        $(this).remove();
      }
    });    
  })
});

$(function(){
  $("select#kategoria2").change(function(){
    $("select#kategoria3").children("optgroup").children("option").each(function(x) {
      if ($(this).val() == $("select#kategoria2").val()){
        $(this).remove();
      }
    });
    $("select#kategoria1").children("optgroup").children("option").each(function(x) {
      if ($(this).val() == $("select#kategoria2").val()){
        $(this).remove();
      }
    });    
  })
});

$(function(){
  $("select#kategoria3").change(function(){
    $("select#kategoria2").children("optgroup").children("option").each(function(x) {
      if ($(this).val() == $("select#kategoria3").val()){
        $(this).remove();
      }
    });
    $("select#kategoria1").children("optgroup").children("option").each(function(x) {
      if ($(this).val() == $("select#kategoria3").val()){
        $(this).remove();
      }
    });    
  })
});

$('textarea.resizable:not(.processed)').TextAreaResizer();
$("input[@name='co']").attr('value','Zde zadejte hledaný text...');
$("input[@name='co']").click(function() {
 $(this).attr('value','');
});
var names = ["#adresa_pobociek","#telefon2","#logo","#voip","#icq","#foto1","#foto2","#foto3","#foto4","#foto5","#foto6","#foto7","#foto8","#foto9","#mapa","#email2","#www","#fax","#kategoria2","#kategoria3","#dlzka-1","#gps"];
for ( var i in names ) {
 if(names[i] == '#adresa_pobociek') {
  $(names[i]).next('.grippie').hide();
  $(names[i]).hide();
  $(names[i]).parent().parent().prevAll('label:first').hide();
  $(names[i]).next('br').hide();
 }
 else {
  $(names[i]).hide();
  $(names[i]).prevAll('label:first').hide();
  $(names[i]).next('br').hide();
 }
} 
$(function(){
  $("select#stat").change(function(){
    $.get("ajax.php",{hodnota: $(this).val(), mod:'stat'}, function(j){
      $("select#mesto").html(j);
    }, "html")
  })
});

tarif();

$(function(){
$("input[@name='tarif']").change(function() {
  tarif();
});
});

function tarif() {
 var vvalue = $("input[@name='tarif']").fieldValue();
 //  *** Standard balicek ***  //
 if (vvalue == 1) {
 
 

     // Pass HTML element id and character limit.
     $('#popis').maxChar(200, {singularMessage:' Znak zůstává',pluralMessage:' Znaků zůstává',indicator:'odpocitavanie'});


 
  // Skryjeme vsetko
  for ( var i in names ) {
 if(names[i] == '#adresa_pobociek') {
  $(names[i]).next('.grippie').hide();
  $(names[i]).hide();
  $(names[i]).parent().parent().prevAll('label:first').hide();
  $(names[i]).next('br').hide();
 }
 else {
  $(names[i]).hide();
  $(names[i]).prevAll('label:first').hide();
  $(names[i]).next('br').hide();
 }
  } 
 }
 //  *** Optimal balicek ***  //
 if (vvalue == 2) {
 
 

     // Pass HTML element id and character limit.
     $('#popis').maxChar(500, {singularMessage:' Znak zůstává',pluralMessage:' Znaků zůstává',indicator:'odpocitavanie'});


  // Logo
  if ($("#logo").is(':hidden')) {
   $("#logo").show();
   $("#logo").prevAll('label:first').show();
   $("#logo").next('br').show();
  }
  // Fax
  if ($("#fax").is(':hidden')) {
   $("#fax").show();
   $("#fax").prevAll('label:first').show();
   $("#fax").next('br').show();
  }
  // ICQ
  if ($("#icq").is(':hidden')) {
   $("#icq").show();
   $("#icq").prevAll('label:first').show();
   $("#icq").next('br').show();
  }
  // WWW
  if ($("#www").is(':hidden')) {
   $("#www").show();
   $("#www").prevAll('label:first').show();
   $("#www").next('br').show();
  }
  // Mapa
  if ($("#mapa").is(':hidden')) {
   $("#mapa").show();
   $("#mapa").prevAll('label:first').show();
   $("#mapa").next('br').show();
  }
  // Foto 1-3
  for(i=1;i<4;i++) {
   if ($("#foto"+i).is(':hidden')) {
    $("#foto"+i).show();
    $("#foto"+i).prevAll('label:first').show();
    $("#foto"+i).next('br').show();
   }
  }
  // Kategoria 2
  if ($("#kategoria2").is(':hidden')) {
   $("#kategoria2").show();
   $("#kategoria2").prevAll('label:first').show();
   $("#kategoria2").next('br').show();
  }
  // Odstranime zvysky z Ekluziv
  // Foto 4-9
  for(i=4;i<10;i++) {
   if ($("#foto"+i).not(':hidden')) {
    $("#foto"+i).hide();
    $("#foto"+i).prevAll('label:first').hide();
    $("#foto"+i).next('br').hide();
   }
  }
  // Email 2
  if ($("#email2").not(':hidden')) {
   $("#email2").hide();
   $("#email2").prevAll('label:first').hide();
   $("#email2").next('br').hide();
  }
  // Voip
  if ($("#voip").not(':hidden')) {
   $("#voip").hide();
   $("#voip").prevAll('label:first').hide();
   $("#voip").next('br').hide();
  }
  // Adresa pobociek
  if ($("#adresa_pobociek").not(':hidden')) {
     $("#adresa_pobociek").next('.grippie').hide();
     $("#adresa_pobociek").hide();
     $("#adresa_pobociek").parent().parent().prevAll('label:first').hide();
     $("#adresa_pobociek").next('br').hide();
  }
  // Kategoria 3
  if ($("#kategoria3").not(':hidden')) {
   $("#kategoria3").hide();
   $("#kategoria3").prevAll('label:first').hide();
   $("#kategoria3").next('br').hide();
  }
  // Dlzka 1
  if ($("#dlzka-1").not(':hidden')) {
   $("#dlzka-1").hide();
  }
  // GPS
  if ($("#gps").not(':hidden')) {
   $("#gps").hide();
   $("#gps").prevAll('label:first').hide();
   $("#gps").next('br').hide();
  }
 }
 //  *** Ekluziv balicek ***  //
 if (vvalue == 3) {
 


     // Pass HTML element id and character limit.
     $('#popis').maxChar(1000000, {singularMessage:' Znak zůstává',pluralMessage:' Znaků zůstává',indicator:'odpocitavanie'});


 
    // Telefon 2
  if ($("#telefon2").is(':hidden')) {
   $("#telefon2").show();
   $("#telefon2").prevAll('label:first').show();
   $("#telefon2").next('br').show();
  }
  // Adresa pobociek
  if ($("#adresa_pobociek").is(':hidden')) {
     $("#adresa_pobociek").next('.grippie').show();
     $("#adresa_pobociek").show();
     $("#adresa_pobociek").parent().parent().prevAll('label:first').show();
     $("#adresa_pobociek").next('br').show();
  }
  // Fax
  if ($("#fax").is(':hidden')) {
   $("#fax").show();
   $("#fax").prevAll('label:first').show();
   $("#fax").next('br').show();
  }

  // Email 2
  if ($("#email2").is(':hidden')) {
   $("#email2").show();
   $("#email2").prevAll('label:first').show();
   $("#email2").next('br').show();
  }
  // ICQ
  if ($("#icq").is(':hidden')) {
   $("#icq").show();
   $("#icq").prevAll('label:first').show();
   $("#icq").next('br').show();
  }
  // WWW
  if ($("#www").is(':hidden')) {
   $("#www").show();
   $("#www").prevAll('label:first').show();
   $("#www").next('br').show();
  }
  // Mapa
  if ($("#mapa").is(':hidden')) {
   $("#mapa").show();
   $("#mapa").prevAll('label:first').show();
   $("#mapa").next('br').show();
  }
  // Foto 1-9
  for(i=1;i<10;i++) {
   if ($("#foto"+i).is(':hidden')) {
    $("#foto"+i).show();
    $("#foto"+i).prevAll('label:first').show();
    $("#foto"+i).next('br').show();
   }
  }
  // Logo
  if ($("#logo").is(':hidden')) {
   $("#logo").show();
   $("#logo").prevAll('label:first').show();
   $("#logo").next('br').show();
  }
  // Kategoria 2
  if ($("#kategoria2").is(':hidden')) {
   $("#kategoria2").show();
   $("#kategoria2").prevAll('label:first').show();
   $("#kategoria2").next('br').show();
  }
  // Kategoria 3
  if ($("#kategoria3").is(':hidden')) {
   $("#kategoria3").show();
   $("#kategoria3").prevAll('label:first').show();
   $("#kategoria3").next('br').show();
  }
  // Dlzka 1
  if ($("#dlzka-1").is(':hidden')) {
   $("#dlzka-1").show();
  }
  // GPS
  if ($("#gps").is(':hidden')) {
   $("#gps").show();
   $("#gps").prevAll('label:first').show();
   $("#gps").next('br').show();
  }
  // VOIP
  if ($("#voip").is(':hidden')) {
   $("#voip").show();
   $("#voip").prevAll('label:first').show();
   $("#voip").next('br').show();
  }  
 }

}

$(".form_help").ezpz_tooltip({
	contentPosition: 'belowStatic',
	stayOnContent: true,
	offset: 0,
	showContent: function(content) {
		content.fadeIn('slow');
	}
});

});
