$(document).ready(function() {
    
    
    $("#sendMsgForm").bind("submit", function() {
        var str = $(this).serialize();
        $.ajax({
            type: "POST",
            url: "php/MessageSend.php",
            data: str,
            success: function(msg) {
                $("#sendMsgForm").ajaxComplete(function(event, request, settings) {
                    if(msg=="SENT"){
                        $( this ).dialog( "close" );
                    }
                    else{
                        updateTips( "Uh?! Něco se pokazilo. Zkuste vkzaz odeslat znovu nebo kontaktujte podporu." )
                    }
                });
                            
                            
            }
        });
        return false;
    });
    
    $("#sendOrderForm").bind("submit", function() {
        var str = $(this).serialize();
        $.ajax({
            type: "POST",
            url: "php/OrderSend.php",
            data: str,
            success: function(msg) {
                $("#sendOrderForm").ajaxComplete(function(event, request, settings) {
                    if(msg=="SENT"){
                        $( this ).dialog( "close" );
                    }
                    else{
                        updateTips( "Uh?! Něco se pokazilo. Zkuste vkzaz odeslat znovu nebo kontaktujte podporu." )
                    }
                });
                            
                            
            }
        });
        return false;
    });
    
    $("#sendOrderFormProduct").bind("submit", function() {
        var str = $(this).serialize();
        $.ajax({
            type: "POST",
            url: "php/OrderSendProduct.php",
            data: str,
            success: function(msg) {
                $("#sendOrderFormProduct").ajaxComplete(function(event, request, settings) {
                    if(msg=="SENT"){
                        $( this ).dialog( "close" );
                    }
                    else{
                        updateTips( "Uh?! Něco se pokazilo. Zkuste vkzaz odeslat znovu nebo kontaktujte podporu." )
                    }
                });
                            
                            
            }
        });
        return false;
    });
    
    $( ".sendMsgButton" ).click(function() {
        tips = $( ".validateTips" )
        $( "#sendMsgForm" ).dialog( "open" );
    });
    
    $( "#sendOrderButton" ).click(function() {
        tips = $( ".validateOrderTips" )
        $( "#sendOrderForm" ).dialog( "open" );
    });
    
    $( ".order" ).click(function() {
        var orderedProduct = $(this).attr("title");
        tips = $( ".validateOrderTips" )
        $( "#sendOrderFormProduct" ).dialog( "open" );
        $("#orderedProduct").val(orderedProduct);
    });
    
    $(".hoverBox").hover(function () {
        $(this).find("img").fadeOut("medium");
        $(this).find("p").fadeIn("medium");
    },
    function () {
        $(this).find("img").fadeIn("medium");
        $(this).find("p").fadeOut("medium");
    });

    $("#sendOrderButton").button();
    
});


