$(document).ready( function() {

    if($(".leftContent").length == 1 && $(".rightContent").length == 1)
    {
        if($(".leftContent").height() > $(".rightContent").height())
        {
            $(".rightContent").height($(".leftContent").height());
        }
        else
        {
            $(".leftContent .innerContent").height($(".rightContent").height() - $(".header").height() );
        }
    }

    if($("#calculatorForm1").length == 1)
    {
        $("#calcButton1").bind("click", function(event) {
            
            event.preventDefault();
            
            var pars = "&quantity=" + $("#quantityForCalc1").val().replace(/ /gi,"");
                pars += "&maturity=" + $("#maturityForCalc1").val();
                pars += "&currency=" + $("#currencyForCalc1").val();
                
            $.ajax({
                type: "POST",
                url: "Components/Calculator/CalculatorActionHandler.php",
                data: "action=Calculate&calculatorType=1" + pars,
                dataType: "json",
                success: function(response) {
                    $("#resultBox2").slideUp(400);
                    $("#resultBox1").slideUp(400, function() {
                        $("#interest1").html(response.interest);
                        $("#fee1").html(response.fee);
                        $("#installment1").html(response.installment);
                    });
                    $("#resultBox1").slideDown(400);
                }
            });
            
        });
        
        $("#calcButton2").bind("click", function(event) {
            
            event.preventDefault();
            
            var pars = "&quantity=" + $("#quantityForCalc2").val().replace(/ /gi,"");
                pars += "&maturity=" + $("#maturityForCalc2").val();
                pars += "&currency=" + $("#currencyForCalc2").val();
                
            $.ajax({
                type: "POST",
                url: "Components/Calculator/CalculatorActionHandler.php",
                data: "action=Calculate&calculatorType=2" + pars,
                dataType: "json",
                success: function(response) {
                    $("#resultBox1").slideUp(400);
                    $("#resultBox2").slideUp(400, function() {
                        $("#interest2").html(response.interest);
                        $("#fee2").html(response.fee);
                        $("#installment2").html(response.installment);
                    });
                    $("#resultBox2").slideDown(400);
                }
            });
            
        });
    }
    
    if($("#questionForm").length == 1)
    {
        $("#sendQuestionButton").bind('click', function(event) {
            event.preventDefault();
            var pars = "&fromEmail=" + $("#fromEmail").val();
                pars += "&message=" + encodeURIComponent($("#message").val());
            $.ajax({
                type: "POST",
                url: "Components/Information/InformationActionHandler.php",
                data: "action=SendMessage&fromEmail=" + pars,
                dataType: "json",
                success: function(response) {
                    $("#fromEmail").val("");
                    $("#message").val("");
                    $("#responseText").html("Elküldtük az üzeneted.");
                    $("#responseText").css({"color":"#090"});
                }
            });
        });
    }
    
});

