    
$(document).ready(function(){
    
   // Rechner abschicken
   $(".powerButton").click(function(event){
		//if($("#stromverbrauch").val() != '' && parseInt($("#stromverbrauch").val()) > 0)	{
		if(document.forms.rechnerform.plz.value == 0) {
			document.forms.plzform.action.value = "calculate";
			document.forms.plzform.media.value = 'POWER';
			document.forms.plzform.consumption.value = document.forms.rechnerform.consumption.value;
			Show_Popup();
			return false;
		}
		else {
			$('#rechnerform').submit();
		}
   });
   
   $(".gasButton").click(function(event){
		//if($("#stromverbrauch").val() != '' && parseInt($("#stromverbrauch").val()) > 0)	{
		if(document.forms.rechnerform.plz.value == 0) {
			document.forms.plzform.action.value = "calculate";
			document.forms.plzform.media.value = 'GAS';
			document.forms.plzform.consumption.value = document.forms.rechnerform.consumptiongas.value;
			Show_Popup();
			return false;
		}
		else {
			$('#rechnerform').submit();
		}
   });
   
   $('.submitLink').click(function(event){
   		if($("#consumption").val() != '' && parseInt($("#consumption").val()) > 0)	{
			$("#rechnerform").attr("action", this);
		}
		$("#rechnerform").attr("action", this);
		$('#rechnerform').submit();
   });
   
   // check plz
   $('form#plzform input:submit').click(function(event){
		var inputVal = $("form#plzform input:text").val();
		if(!inputVal.match(/^[0-9]{5}$/)){
			event.preventDefault();
			$('#plzform  p.plzError').fadeIn().delay(1000).fadeOut();
		}else{
			$('#plzform  p.plzError').hide();
		}
   });
   // popup close
   $('#popup1-close').click(function(event){
   		event.preventDefault();
   		$('#popup').fadeOut('fast');
    	$('#window').fadeOut('fast');
   });
   
    
   // Vorauswahl Ändert Grafik und Wert in Eingabefeld: 
    
   // Bei Direkteingabe, Vorgabemarkierung aufheben
   $("#consumption").keyup(function(event){  
	 event.preventDefault();
     $("#stromvorgabe1").children("img:first").attr('src','/fileadmin/templates/images/strom1.gif');
     $("#stromvorgabe2").children("img:first").attr('src','/fileadmin/templates/images/strom2.gif');
     $("#stromvorgabe3").children("img:first").attr('src','/fileadmin/templates/images/strom3.gif');
     $("#stromvorgabe4").children("img:first").attr('src','/fileadmin/templates/images/strom4.gif');
   });
    
   $("#stromvorgabe1").click(function(event){
     event.preventDefault();
	 $("#consumption").val("1500");
     $("#stromvorgabe1").children("img:first").attr('src','/fileadmin/templates/images/strom1a.gif').stop(true,true).hide().fadeIn();
     $("#stromvorgabe2").children("img:first").attr('src','/fileadmin/templates/images/strom2.gif');
     $("#stromvorgabe3").children("img:first").attr('src','/fileadmin/templates/images/strom3.gif');
     $("#stromvorgabe4").children("img:first").attr('src','/fileadmin/templates/images/strom4.gif');
   });
   
   $("#stromvorgabe2").click(function(event){
     event.preventDefault();
	 $("#consumption").val("2500");
     $("#stromvorgabe1").children("img:first").attr('src','/fileadmin/templates/images/strom1.gif');
     $("#stromvorgabe2").children("img:first").attr('src','/fileadmin/templates/images/strom2a.gif').stop(true,true).hide().fadeIn();
     $("#stromvorgabe3").children("img:first").attr('src','/fileadmin/templates/images/strom3.gif');
     $("#stromvorgabe4").children("img:first").attr('src','/fileadmin/templates/images/strom4.gif');         
   });
   
   $("#stromvorgabe3").click(function(event){
     event.preventDefault();
	 $("#consumption").val("3000");
     $("#stromvorgabe1").children("img:first").attr('src','/fileadmin/templates/images/strom1.gif');
     $("#stromvorgabe2").children("img:first").attr('src','/fileadmin/templates/images/strom2.gif');
     $("#stromvorgabe3").children("img:first").attr('src','/fileadmin/templates/images/strom3a.gif').stop(true,true).hide().fadeIn();
     $("#stromvorgabe4").children("img:first").attr('src','/fileadmin/templates/images/strom4.gif');         
   });              

   $("#stromvorgabe4").click(function(event){
     event.preventDefault();
	 $("#consumption").val("4000");
     $("#stromvorgabe1").children("img:first").attr('src','/fileadmin/templates/images/strom1.gif');
     $("#stromvorgabe2").children("img:first").attr('src','/fileadmin/templates/images/strom2.gif');
     $("#stromvorgabe3").children("img:first").attr('src','/fileadmin/templates/images/strom3.gif');
     $("#stromvorgabe4").children("img:first").attr('src','/fileadmin/templates/images/strom4a.gif').stop(true,true).hide().fadeIn();         
   });       
   
   
   // Bei Direkteingabe, Vorgabemarkierung aufheben
   $("#gasverbrauch").keyup(function(event){     
     event.preventDefault();
	 $("#gasvorgabe1").children("img:first").attr('src','/fileadmin/templates/images/gas1.gif');
     $("#gasvorgabe2").children("img:first").attr('src','/fileadmin/templates/images/gas2.gif');
     $("#gasvorgabe3").children("img:first").attr('src','/fileadmin/templates/images/gas3.gif');
   });   
   
   $("#gasvorgabe1").click(function(event){
     event.preventDefault();
	 $("#consumptiongas").val("11700");
     $("#gasvorgabe1").children("img:first").attr('src','/fileadmin/templates/images/gas1a.gif').stop(true,true).hide().fadeIn();
     $("#gasvorgabe2").children("img:first").attr('src','/fileadmin/templates/images/gas2.gif');
     $("#gasvorgabe3").children("img:first").attr('src','/fileadmin/templates/images/gas3.gif');
   });
   
   $("#gasvorgabe2").click(function(event){
     event.preventDefault();
	 $("#consumptiongas").val("20500");
     $("#gasvorgabe1").children("img:first").attr('src','/fileadmin/templates/images/gas1.gif');
     $("#gasvorgabe2").children("img:first").attr('src','/fileadmin/templates/images/gas2a.gif').stop(true,true).hide().fadeIn();
     $("#gasvorgabe3").children("img:first").attr('src','/fileadmin/templates/images/gas3.gif');
   });            

   $("#gasvorgabe3").click(function(event){
     event.preventDefault();
	 $("#consumptiongas").val("25000");
     $("#gasvorgabe1").children("img:first").attr('src','/fileadmin/templates/images/gas1.gif');
     $("#gasvorgabe2").children("img:first").attr('src','/fileadmin/templates/images/gas2.gif');
     $("#gasvorgabe3").children("img:first").attr('src','/fileadmin/templates/images/gas3a.gif').stop(true,true).hide().fadeIn();
   });    
   
   
   
});


function zusatzoptionen(anzeige){

    if (anzeige==1){

        document.getElementById("zusatzlayer").style.display = "block";
        document.getElementById("zusatzlayer").style.height = "0px";
        document.getElementById("balken-einblenden").style.display = "none";
        document.getElementById("balken-ausblenden").style.display = "block";
        
           
        /* Using multiple unit types within one animation. */


          $("#zusatzlayer").animate({
            opacity: 1,
            height: "463px"
          }, 1500 );

          $("#sparpotential").animate({
            opacity: 1,
            top: "1370px"
          }, 1500 );                        
                                
          $("#content").animate({
            opacity: 1,
            marginTop: "1528px"
          }, 1500 );                                
                           
                            
                            
          $("#zusatzbalken").animate({
            opacity: 1,
            top: "1340px"
          }, 1500 );    
          


    
    }

    if (anzeige==0){

        
        document.getElementById("balken-einblenden").style.display = "block";
        document.getElementById("balken-ausblenden").style.display = "none";
        
           
        /* Using multiple unit types within one animation. */


          $("#zusatzlayer").animate({
            opacity: 1,
            height: "0px"
          }, 1500 );

          $("#sparpotential").animate({
            opacity: 1,
            top: "920px"
          }, 1500 );                        
                                
          $("#content").animate({
            opacity: 1,
            marginTop: "1080px"
          }, 1500 );                                
                           
                            
                            
          $("#zusatzbalken").animate({
            opacity: 1,
            top: "889px"
          }, 1500 );    
                            
        
        
        
    }
    
    
}                


function Show_Popup(action, userid) {
    $('#popup').css({height: $(document).height()});
    $('#popup').css({opacity: 0.5}).fadeIn('fast');
    $('#window').fadeIn('fast');
    $('input.plzinput').focus();
}

function Show_Popup2(action, userid) {
    $('#popup').css({height: $(document).height()});
    $('#popup').css({opacity: 0.5}).fadeIn('fast');
    $('#window2').fadeIn('fast');
    
}

function Close_Popup() {
    $('#popup').fadeOut('fast');
    $('#window').fadeOut('fast');
}

function Close_Popup2() {
    $('#popup').fadeOut('fast');
    $('#window2').fadeOut('fast');
}


function changePlz()	{
	$('#standort').html('<form action="#" method="post"><input type="text" name="inputplz" id="inputplz" /></form>');
}
