$(document).ready(function() {

//main tooltips 
  $('a.moreinfo').cluetip({
    activation: 'hover',
    closeText: 'Zavřít',
    sticky: true,
    width: 550,
    local: true,
    showTitle: false, 
    cursor: 'pointer',
    tracking: false,
    waitImage: true,
    dropShadowSteps: 3,
    arrows: false,
    fx: {             
      open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
      openSpeed:  '450'
    }
    });

//tooltips for clients
  $('a.client').cluetip({
    width: 350,
    local: true, 
    cursor: 'pointer',
    activation: 'hover',
    showTitle: false, 
    waitImage: true,
    dropShadowSteps: 3,
    arrows: true,
    clickThrough: true,
    fx: {             
      open:       'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
      openSpeed:  '450'
    }
    });

//form validation

  $("form").validate({ 
	    rules: { 
	      name: {
          required: true,
          minlength: 7
        },    
	      email: {              
          required: true, 
          email: true
	      }, 
	      phone: { 
	        required: true,
	        digits: true,
          minlength: 9,
          maxlength: 9
	      }
	    }, 
	    messages: { 
	      name: {
          required: "Vyplňte jméno a příjmení",
          minlength: "Vyplňte minimálně 7 znaků"
        },
        email: {
          required: "Vyplňte email",
          email: "Email má tvar xxx@xxx.xx"
        },
        phone: {
          required: "Vyplňte telefon",
          minlength: "Telefon má 9 číslic",
          digits: "Telefon má 9 číslic"
        }
	    }   
	  }); 

    //sends only a valid form
$(function() {
    
    $("form").submit(function() { 
    
    var company = $("input#company").val();
    var name = $("input#name").val();
		var phone = $("input#phone").val();
		var email = $("input#email").val();
    var text = $("textarea").val();
    
    //only valid form will be processed to send
    if ($("form").valid()) {
   	
		var dataString =  'company=' + company + '&name=' + name + '&email=' + email + '&phone=' + phone + '&text=' + text;
		//alert (dataString);return false;
    	
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#message').html("<img id='checkmark' src='images/check.png' />")
        .append("<h3>Formulář byl úspěšně odeslán!</h3>")
        .append("<p>Děkujeme za Váš zájem, brzy se ozveme.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message');
        });
      }
     });
    return false;
   }
	});
});     
    
});
