
// zmazanie formu
function clearForm() {
  $.fn.clearForm = function() {
    return this.each(function() {
      var type = this.type, tag = this.tagName.toLowerCase();        
      if (tag == 'form')
       return $(':input',this).clearForm();
      if (type == 'text' || type == 'password' || tag == 'textarea')
       this.value = '';
      else if (type == 'checkbox' || type == 'radio')
       this.checked = false;
      else if (tag == 'select')
       this.selectedIndex = -1;
      }
    );
  };    
}

// zaslanie ceniku
function sendPricelist() {
  $(function() {
    $("#zaslaniCeniku").validate({
      rules: {
        secure: {
          minlength: 3
        },
        telefon: {
          minlength: 9
        },
        psc: {
          minlength: 5
        }
      },
      success: function(label) {
        label.html("&nbsp;").addClass("checked");
      }        
    });
    
    $('#zaslaniCeniku').submit(function() {
      if( $("#zaslaniCeniku").valid() ) {
        $.ajax({
          url: "/scripts/ajax/email.ajax.php",
          type: "POST",
          dataType: "html",
          data: ({
                    jmeno : $("#jmeno").val(),
                    prijmeni : $("#prijmeni").val(),
                    telefon : $("#telefon").val(),
                    email : $("#email").val(),
                    ulice : $("#ulice").val(),
                    mesto : $("#mesto").val(),
                    psc : $("#psc").val(),
                    zeme : $("#zeme").val(),
                    send : "send"
                }),
          success: function(msg) {
            $("#response").html(msg);
            $("#zaslaniCeniku").clearForm(); // zmazanie formu
            $("label.checked").remove(); // zmazanie fajek
          }
        });
        return false;
      }
    });
  });
}

// plati pre newsletter, skryva a zobrazuje ten formular a vypisuje hlasky
var commentF = {
  cb: function(msg) {
    $("#comment-ajax").html(msg);
  },
  show: function() {
    $("#comment-form").fadeIn("slow");
    $("#footer-item-reasons").fadeIn("slow");
    $("#comment-ajax").hide();
  },
  showAndClear: function() {
    $("#comment-form").fadeIn("slow");
    $("#footer-item-reasons").fadeIn("slow");
    $("#comment-ajax").hide();
    clearForm(); $("#comment-form").clearForm(); // zmazanie formu
  },
  before: function() {
    $("#comment-form").hide();
    $("#footer-item-reasons").hide();
    $("#comment-ajax").show();
  }
}


$(function(){
 $("#comment-form").submit( function() {
    commentF.before();
    
    $.ajax({
      url: "/scripts/ajax/emailFooter.ajax.php",
      type: "POST",      
      data: ({  email : $("#emailFooter").val(), sprava : $("#textFooter").val() }),
      success: function(msg) {
        commentF.cb(msg);
      }
    });
    return false;
  });
  return false;
})
