Cufon.replace("#top");
Cufon.replace("#menu a", { hover: true });
Cufon.replace("#subheader");
Cufon.replace("#right h2");
Cufon.replace("#tip a");

$(document).ready(function() {
  
  //
  // formular
  //
  $property = $("#property");
  $express = $("#express");
  
  function update1() {
    if ($property.get(0).checked == true) {
      $express.get(0).disabled = false;
      $express.parent().removeClass("disabled");
    } else {
      $express.get(0).disabled = true;
      $express.parent().addClass("disabled");
    }
  }
  
  function update2() {
    if (($("#name").val().trim() != "" && $("#name").val() != $("#name").attr("title"))
        && ($("#sum").val().trim() != "" && $("#sum").val() != $("#sum").attr("title"))
        && ($("#phone").val().trim() != "" && $("#phone").val() != $("#phone").attr("title"))
        && ($("#city").val().trim() != "" && $("#city").val() != $("#city").attr("title"))
        && ($("#agree").get(0).checked == true)
        && ($("#region").val() != 0)
        /*&& ($("#city").val() != 0)*/) {
      $("#submit").attr("disabled", false);
      $(".button").removeClass("buttonDisabled");
    } else {
      $("#submit").attr("disabled", true);
      $(".button").addClass("buttonDisabled");
    }
  }
  
  $property.change(function() {
    update1();
  });
  
  $("#name, #phone, #sum, #city").focus(function() {
    $(this).keyup(function() {
      update2();
    });
  });
  $("#name, #phone, #sum, #city").blur(function() {
    $(this).unbind("keyup");
    update2();
  });
  
  $("#agree").change(function() {
    update2();
  });
  /*
  function updateCity(data) {
    $city = $("#city");
    $cityWrap = $city.parent().parent();
    //fill city
    $city.html(data);
    //remove previous jNice
    $city.parent().remove();
    $cityWrap.append($city);
    //add jNice
    $city.parent().jNice();
  }
  
  $("#region").get(0).onchange = function() {
    var value = $("#region").val();
    if (value != 0) {
      $.get("/region/" + value, function(data) {
        updateCity(data);
        update2();
      });
    } else {
      updateCity("<option value='0'>Nejprve zvolte kraj…</option>");
      update2();
    }
  }
  
  $("#region").get(0).onchange();
  */
  /*$("#city").get(0).onchange = function() {
    update2();
  }*/
  
  update1();
  update2();
  
  //
  // cleartext
  //
  $("input:text, textarea, input:password").each(function(){
        if(this.value == '')
            this.value = this.title;
  });
  $("input:text, textarea, input:password").focus(function(){
      if(this.value == this.title)
          this.value = '';
          
  });
  $("input:text, textarea, input:password").blur(function(){
      if(this.value == '')
          this.value = this.title;
  });
  $("input:image, input:button, input:submit").click(function(){
      $(this.form.elements).each(function(){
          if(this.type =='text' || this.type =='textarea' || this.type =='password' ){
              if(this.value == this.title && this.title != ''){
                  this.value='';
              }
          }
      });
  });
});
