$(document).ready(function() {





/*** LEFT TEASER SEARCHBOX START***/
if($('.LeftForm input.finput').val() != '' && $('.LeftForm input.finput').val() != 'Name, PLZ, Ort'){
    $('.LeftForm span.location').show();
    $('.LeftForm span.asp').show();
} else {
    $('.LeftForm span.asp').hide();
    $('.LeftForm span.location').hide();
}

$('.location').click(function(){
	$('.leftform').attr('name', 'city'); 
	$('.left-pid').val($('.footer-city-pid').val()); 
	$('.left-fform').submit();
});

$('.asp').click(function(){
	$('.leftform').attr('name', 'tx_m01ansprechpartnersuche_pi1[asp]'); 
	$('.left-pid').val($('.footer-asp-pid').val()); 
	$('.left-fform').submit();
	
});
 
$('.LeftForm input.finput').keypress(function(e) {  
  
  //alert($('.LeftForm input.finput').val() )
  
  if($('.LeftForm input.finput').val() != '' && $('.LeftForm input.finput').val() != 'Name, PLZ, Ort'){
    $('.LeftForm span.location').slideDown(function(){
      $('.LeftForm span.asp').slideDown();
    });
  } else {
    $('.LeftForm span.asp').slideUp(function(){
      $('.LeftForm span.location').slideUp();
    });
  }
  
  if(e.keyCode == 13) {
    return false;
  }            
});

$('.LeftForm input.finput').focusout(function() {
  
  if($('.LeftForm input.finput').val() != '' && $('.LeftForm input.finput').val() != 'Name, PLZ, Ort'){
    $('.LeftForm span.location').slideDown(function(){
      $('.LeftForm span.asp').slideDown();
    });
  } else {
    $('.LeftForm span.asp').slideUp(function(){
      $('.LeftForm span.location').slideUp();
    });
  }
});
/*** LEFT TEASER SEARCHBOX ENDE***/


/*** MEDIATHEK SLIDER ****/
    $(".slidetabs").tabs(".images > .SliderWrapper", {

            // enable "cross-fading" effect
            effect: 'fade',
            fadeOutSpeed: "slow",

            // start from the beginning after the last tab
            rotate: true

    // use the slideshow plugin. It accepts its own configuration
    }).slideshow({clickable: false});
/*** MEDIATHEK SLIDER ****/


/****ACCORDION ****/
    /*$(".nAll2").accordion({autoHeight: false, event: 'mouseover',  navigation: true, collapsible: true, active:false});*/
    /*$(".nKarriere2").accordion({autoHeight: false, event: 'mouseover',  navigation: true, collapsible: true, active:false});*/

    /*$(".sub_child_a ul").show();*/
    
    $(".lb_man_01").colorbox({inline:true, href:"#man_lb_01",opacity:0.8});
    $(".lb_man_02").colorbox({inline:true, href:"#man_lb_02",opacity:0.8});
    $(".lb_man_03").colorbox({inline:true, href:"#man_lb_03",opacity:0.8});
    $(".lb_man_04").colorbox({inline:true, href:"#man_lb_04",opacity:0.8});
    $(".lb_man_05").colorbox({inline:true, href:"#man_lb_05",opacity:0.8});
	 $(".lb_man_06").colorbox({inline:true, href:"#man_lb_06",opacity:0.8});
    
    $(".initiativ").colorbox({iframe:true, width:"760px",height:"70%",opacity:0.8});
    
    $(".CBrefImage").colorbox();


    $("#rueckruf").submit(function() {
        var form = '.form1';
        submitRequest('#cback_n', '#cback_v','#cback_t','#fehler_n','#fehler_v','#fehler_t',form);
        return false;
    });

    $("#newsletter_form").submit(function() {
        var form = '.form2';
        submitRequest('#cback_n2', '#cback_v2','#cback_e','#fehler_n2','#fehler_v2','#fehler_e',form);
        return false;
    });

    $("#kontakt_form").submit(function() {
        var form = '.form3'; //prüfen ob newsletter checked ist, noch einbauen
        var check = $('#cback_news').attr('checked');
        submitRequest2('#cback_n3', '#cback_v3','#cback_e2','#cback_text',check,'#fehler_n3','#fehler_v3','#fehler_e2','#fehler_text',form);
        return false;
    });
	 
    $("#sellingSl").scrollable();



    /***************** POWERMAIL FORM START *******************/
    var defaultText = null;


    //ALLE FORMULARE     
    $('.tx-powermail-pi1 input.powermail_text').focusin(function() {
        if( $(this).val() == 'Ihr Vorname*') {
            $(this).val('');
            defaultText = 'Ihr Vorname*';
        }
        if( $(this).val() == 'Ihr Nachname*') {
            $(this).val('');
             defaultText = 'Ihr Nachname*';
        }
        if( $(this).val() == 'Ihre Telefonnummer') {
            $(this).val('');
             defaultText = 'Ihre Telefonnummer';
        }
        if( $(this).val() == 'Ihre E-Mail*') {
            $(this).val('');
             defaultText = 'Ihre E-Mail*';
        }
    });
    
    $('.tx-powermail-pi1 input.powermail_text').focusout(function() {
        if( $(this).val() == '' ) {
             $(this).val(defaultText);
        }
    });
    /***************** POWERMAIL FORM ENDE *******************/

});

function submitRequest(name, vorname, telefon, fehler1, fehler2, fehler3, form){
    var formular = form + ' .form_r_01';
    var formular_erf = form + ' .form_r_02';
    var error = '';

    if (($(name).val() == 'Name'))
    {
        $(fehler1).fadeIn();
        $(name).css('color', '#D95500');
        error += 'f1';
    }
    else
        $(fehler1).fadeOut();

    if (($(vorname).val() == 'Vorname'))
    {
        $(fehler2).fadeIn();
        $(vorname).css('color', '#D95500');
        error += 'f2';
    }
    else
        $(fehler2).fadeOut();

    if (($(telefon).val() == 'Telefon') || ($(telefon).val() == 'E-Mail'))
    {
        $(fehler3).fadeIn();
        $(telefon).css('color', '#D95500');
        error += 'f3';
    }
    else
        $(fehler3).fadeOut();

    if(error == '' && form == '.form1')
    {
        $.ajax({
                type: "POST",
                data: ({submit:"submit", abs_name: $(name).val(), abs_vorname: $(vorname).val(), abs_telefon: $(telefon).val() }),
                url: "fileadmin/template/rueckruf.php",
                global: false,
                dataType: "html",
                async:false,
                success: function(data){
                    if(data == 'ok')
                    {
                       $(formular).hide();
                       $(formular_erf).fadeIn();
                    }
                }
        });
    }

    if(error == '' && form == '.form2')
    {
        $.ajax({
                type: "POST",
                data: ({submit:"submit", abs_name: $(name).val(), abs_vorname: $(vorname).val(), abs_email: $(telefon).val() }),
                url: "fileadmin/template/newsletter.php",
                global: false,
                dataType: "html",
                async:false,
                success: function(data){
                    if(data == 'ok')
                    {
                       $(formular).hide();
                       $(formular_erf).fadeIn();
                    }
                    else if(data == 'emailnok')
                    {
                        $(fehler3).fadeIn();
                        $(telefon).css('color', '#D95500');
                    }
                }
        });
    }

    return true;
}

function submitRequest2(name, vorname, email, text, check, fehler1, fehler2, fehler3, fehler4, form){
    var formular = form + ' .form_r_01';
    var formular_erf = form + ' .form_r_02';
    var error = '';

    if (($(name).val() == 'Name'))
    {
        $(fehler1).fadeIn();
        $(name).css('color', '#D95500');
        error += 'f1';
    }
    else
        $(fehler1).fadeOut();

    if (($(vorname).val() == 'Vorname'))
    {
        $(fehler2).fadeIn();
        $(vorname).css('color', '#D95500');
        error += 'f2';
    }
    else
        $(fehler2).fadeOut();

    if (($(email).val() == 'E-Mail'))
    {
        $(fehler3).fadeIn();
        $(email).css('color', '#D95500');
        error += 'f3';
    }
    else
        $(fehler3).fadeOut();

    if (($(text).val() == 'Nachricht'))
    {
        $(fehler4).fadeIn();
        $(text).css('color', '#D95500');
        error += 'f4';
    }
    else
        $(fehler4).fadeOut();

    if(error == '')
    {
        $.ajax({
                type: "POST",
                data: ({submit:"submit", abs_name: $(name).val(), abs_vorname: $(vorname).val(), abs_email: $(email).val(), abs_text: $(text).val(), abs_check: check}),
                url: "fileadmin/template/kontakt.php",
                global: false,
                dataType: "html",
                async:false,
                success: function(data){
                    if(data == 'ok')
                    {
                       $(formular).hide();
                       $(formular_erf).fadeIn();
                    }
                    else if(data == 'emailnok')
                    {
                        $(fehler3).fadeIn();
                        $(email).css('color', '#D95500');
                    }
                }
        });
    }
    return true;
}

function validmail(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email) == false) {
	  return 'invalid';
	}
	else return 'valid';
}
