$().ready(function(){
    $("#callbackbtn").toggle(function(){
        $("#callbackelement").animate({
            height: "352px"
        });
        $("#callbackbox").slideDown("slow");
        $("#callbackbtn").html("schließen <img src='/img/btn_zuklappen.png'>");
    }, function(){
        $("#callbackelement").animate({
            height: "220px"
        });
        $("#callbackbox").fadeOut("slow");
        $("#callbackbtn").html("Callback-Service nutzen <img src='/img/btn_aufklappen.png'>");
    })
});

$().ready(function(){
    $("#callbackAddForm").submit(function(){
        var name = $("#callbackName").val();
        var telephone = $("#callbackTelephone").val();
        var date = $("#callbackDate").val();
        var url = $("#callbackUrl").val();
        if (name == '') {
            $("#callbackName").css({
                'border-color': 'red',
                'background-color': '#FFCFCF'
            });
            $("#callbackName").focus();
        }
        else 
            if (telephone == '') {
                $("#callbackName").css({
                    'border-color': '#D7D9DB',
                    'background-color': '#ffffff'
                });
                $("#callbackTelephone").css({
                    'border-color': 'red',
                    'background-color': '#FFCFCF'
                });
                $("#callbackTelephone").focus();
            }
            else 
                if (date == '') {
                
                    $("#callbackTelephone").css({
                        'border-color': '#D7D9DB',
                        'background-color': '#ffffff'
                    });
                    $("#callbackDate").css({
                        'border-color': 'red',
                        'background-color': '#FFCFCF'
                    });
                    $("#callbackDate").focus();
                }
                else {
                    $.ajax({
                        type: "POST",
                        url: "/callbacks/add",
                        data: {
                            name: name,
                            telephone: telephone,
                            date: date,
                            url: url
                        },
                        success: function(data){
                            $("#callbackbtn").fadeOut();
                            $("#callbackbox").css({
                                'padding-left': '5px'
                            })
                            $("#callbackbox").fadeTo("slow", 0.1, callback);
                            
                            function callback(){
                                $("#callbackbox").text(data);
                                $("#callbackbox").fadeTo("slow", 1);
                                
                                $("#callbackelement").animate({
                                    height: "310px"
                                }, callback);
                            }
                        }
                        
                    });
                }
        return false;
    });
});


$(function(){
    $('.date-pick').datePicker();
});

$().ready(function(){
    $(".dlliste").click(function(){
        if ($(this).hasClass("dloffen").toString() == "true") {
            $("#dl" + $(".dloffen").attr("id")).slideUp();
            $("div").find(".dloffen").attr("class", "dlliste");
        }
        else 
            if ($(this).hasClass("dlliste").toString() == "true") {
                $("#dl" + $(".dloffen").attr("id")).slideUp();
                $(".dloffen").attr("class", "dlliste");
                $("#dl" + $(this).attr("id")).slideDown("slow");
                $(this).attr("class", "dloffen");
            }
    })
    
    $("#90").click(function(){
        $("#bigpic").attr({
            src: "/img/gk_awt_zg_agt_01.jpg"
        });
    })
    $("#91").click(function(){
        $("#bigpic").attr({
            src: "/uploads/images/gk_awt_zg_lsa_01.jpg"
        });
    })
    $("#97").click(function(){
        $("#bigpic").attr({
            src: "/img/gk_vfta_ts_01.jpg"
        });
    })
    $("#98").click(function(){
        $("#bigpic").attr({
            src: "/uploads/images/gk_awt_vfta_01.jpg"
        });
    })
    $("#99").click(function(){
        $("#bigpic").attr({
            src: "/uploads/images/gk_awt_vfta_01.jpg"
        });
    })
});

$().ready(function(){
    $("#callbackZeit").focus(function(){
        $(this).datepicker();
    })
});

$().ready(function(){
    $("#teilnahme:checkbox").click(function(){
        var checked = $("#teilnahme:checked").length;
        if (checked == '1') {
            $("#kwksenden").fadeIn("slow");
        }
        else {
            $("#kwksenden").fadeOut("slow");
        }
    })
});

$().ready(function(){
    $("div .slidepics").toggle(function(){
        $(this).animate({
            height: "330px"
        });
        var id = "#img_" + $(this).attr("id");
        $(id).attr({
            "style": "display: block"
        });
    }, function(){
        $(this).animate({
            height: "80px"
        });
        var id = "#img_" + $(this).attr("id");
        $(id).attr({
            "style": "display: none"
        });
    });
});



$().ready(function(){

    $("#standort1").toggle(function(){
        $("#standort1").attr({
            "style": "background-position-x: 535px; background: #D6D6D6 url(../img/vergroesserung.jpg) no-repeat scroll right top"
        });
        $("#standort1").animate({
            height: "30px"
        });
        
        $("#standort1 p").fadeOut("slow");
        
    }, function(){
        $("#standort1").attr({
            "style": "background-position-x: 530px; background: #D6D6D6 url(../img/minus_standorte.jpg) no-repeat scroll right top"
        });
        $("#standort1").animate({
            height: "125px"
        });
        
        $("#standort1 p").fadeIn("slow");
    });
    
});
$().ready(function(){
    $("#standort2").toggle(function(){
        $("#standort2").animate({
            height: "330px"
        }, 1000);
        $("#standort2").attr({
            "style": "background-position-x: 530px; background: #D6D6D6 url(../img/minus_standorte.jpg) no-repeat scroll right top"
        });
        $("#standort2 p").fadeIn("slow");
    }, function(){
        $(this).animate({
            height: "30px"
        }, 1000);
        $("#standort2").attr({
            "style": "background-position-x: 535px; background: #D6D6D6 url(../img/vergroesserung.jpg) no-repeat scroll right top"
        });
        $("#standort2 p").fadeOut("slow");
    });
});
$().ready(function(){
    $("#standort3").toggle(function(){
        $(this).animate({
            height: "220px"
        }, 1000);
        $("#standort3").attr({
            "style": "background-position-x: 530px; background: #D6D6D6 url(../img/minus_standorte.jpg) no-repeat scroll right top"
        });
        $("#standort3 p").fadeIn("slow");
    }, function(){
        $(this).animate({
            height: "30px"
        }, 1000);
        $("#standort3").attr({
            "style": "background-position-x: 535px; background: #D6D6D6 url(../img/vergroesserung.jpg) no-repeat scroll right top"
        });
        $("#standort3 p").fadeOut("slow");
    });
});

$().ready(function(){
    $(".faqtitel").toggle(function(){
        $("#answer" + $(this).attr("id")).slideDown("slow");
    }, function(){
        $("#answer" + $(this).attr("id")).slideUp("slow");
    })
});

$().ready(function(){
    $("#printbutton").click(function(){
        $("#print").fadeIn("slow");
        $("#container").fadeOut("slow");
        $("#logoabsolute").fadeOut("slow");
        var content = $("#content").html();
        $("#printcontent").html(content);
    })
    
    
    $("#print").click(function(){
        $(this).fadeOut("slow");
        $("#container").fadeIn("slow");
        $("#logoabsolute").fadeIn("slow");
    });
})

$().ready(function(){
	$('#ConsultantPlz').autotab({ target: 'data[Consultant][plz]',maxlength: 5, format: 'numeric' });
	    $("#ConsultantPlz").keydown(function(e){
			var plz = $(this).val().length;
        if (e.keyCode == 13 && plz < 5) {
            return false;
       }
    });
	
    $("#ConsultantPlz").keyup(function(){
        var plz = $(this).val().length;
        if (plz < 5) {
            $(this).css({
                'border-color': 'red',
                'background-color': '#FFCFCF'
            });
            $("#ConsultantAddForm .submit input").fadeOut();
        }
        else {
            $(this).css({
                'border-color': '#D7D9DB',
                'background-color': '#ffffff'
            });
            $("#ConsultantAddForm .submit input").fadeIn();
        }
    })
});

$().ready(function(){
$('#plzKaelte').autotab({ target: 'data[Sale][plz]', maxlength: 5,format: 'numeric' });
    $("#plzKaelte").keydown(function(e){
			var plz = $(this).val().length;
        if (e.keyCode == 13 && plz < 5) {
            return false;
       }
    });
    $("#plzKaelte").keyup(function(e){
        var plz = $(this).val().length;
        if (plz < 5) {
            $(this).css({
                'border-color': 'red',
                'background-color': '#FFCFCF'
            });
            $("#SaleKaelte .submit input").fadeOut();
        }
        else {
            $(this).css({
                'border-color': '#D7D9DB',
                'background-color': '#ffffff'
            });
            $("#SaleKaelte .submit input").fadeIn();
        }
    })
});

$().ready(function(){
$('#plzFluessig').autotab({ target: 'data[Sale][plz]', maxlength: 5,format: 'numeric' });
    $("#plzFluessig").keydown(function(e){
			var plz = $(this).val().length;
        if (e.keyCode == 13 && plz < 5) {
            return false;
       }
    });
    $("#plzFluessig").keyup(function(e){
        var plz = $(this).val().length;
        if (plz < 5) {
            $(this).css({
                'border-color': 'red',
                'background-color': '#FFCFCF'
            });
            $("#SaleFluessig .submit input").fadeOut();
        }
        else {
            $(this).css({
                'border-color': '#D7D9DB',
                'background-color': '#ffffff'
            });
            $("#SaleFluessig .submit input").fadeIn();
        }
    })
});
