	$(function() {
    $("#errorbox").dialog({title: "Error", autoOpen: false, modal: true, buttons:
      {"Fix error": function(){
        $(".flashc").css("display","block");
        $(this).dialog("close");}}
    });
		$('#datumPrijezdu').datepicker({minDate: '+0D', maxDate: '+2Y', numberOfMonths: 1});
		$('#datumOdjezdu').datepicker({minDate: '+0D', maxDate: '+2Y', numberOfMonths: 1});
		
		$("#presubmit").click(function(){
		  if(!checkOrder())
		    return false;
		  $("#f_prijezd").html($("#datumPrijezdu").val());
		  $("#f_odjezd").html($("#datumOdjezdu").val());
		  $("#f_osob").html($("#osob").val());
		  $("#f_jmeno").html($("#jmeno").val());
		  $("#f_email").html($("#email").val());
		  $("#f_telefon").html($("#telefon").val());
      $("#right-column").hide("slow");
      $("#right-column-order").show("slow");
      return false;
    });

		$("#finalsubmit").click(function(){
		  if(!checkOrder())
		    return false;
		  if($("#potvrzeni").attr("checked")!=true){
        reporterror("You have to agree with terms of reservation.");
        return false;
      }
		  $("#f_prijezd").html($("#datumPrijezdu").val());
		  $("#f_odjezd").html($("#datumOdjezdu").val());
		  $("#f_osob").html($("#osob").val());
		  $("#f_jmeno").html($("#jmeno").val());
		  $("#f_email").html($("#email").val());
		  $("#f_telefon").html($("#telefon").val());
		  $("#f_poznamka").val($("#poznamka").val());
      $("#right-column").hide("slow");
      $("#right-column-order").show("slow");  
      $("#orderform").submit();    
    });

    $(".flaga").css("opacity","0.35");
    $(".flaga").css("filter","Alpha(Opacity=35)");

    $(".flaga").mouseover(function(){
      $(this).css("opacity","1");
      $(this).css("filter","Alpha(Opacity=100)");
    });
    $(".flaga").mouseout(function(){
      $(this).css("opacity","0.35");
      $(this).css("filter","Alpha(Opacity=35)");
    });
    
    
	});
	
	function checkOrder(){
	  if($("#datumPrijezdu").val().length<11){
	    reporterror("Enter the date of arrival – use interactive calendar.");
    	return false;    
    }
	  if($("#datumOdjezdu").val().length<11){
	    reporterror("Enter the date of departure – use interactive calendar.");
    	return false;    
    }
	  if($("#osob").val().length<1){
	    reporterror("Enter the number of persons.");
    	return false;    
    }
	  if($("#jmeno").val().length<5){
	    reporterror("Enter your firstname and surname.");
    	return false;    
    }
	  if($("#email").val().length<5){
	    reporterror("Enter your e-mail.");
    	return false;    
    }
	  if($("#telefon").val().length<9){
	    reporterror("Enter your phone number.");
    	return false;    
    }
    return true;
  }
  
  function reporterror(msg){
    $(".flashc").css("display","none");
    $("#errorbox").html("<p>"+msg+"</p>").dialog("open");  
  }