var plzMiniCache=[];
var lastMiniVal;
function checkMiniPlz(ob) {
	var plz=$(ob).val();
	if(plz==lastMiniVal)
		return;
		lastMiniVal=plz;  
	
		if($(ob).val().length==5){
			if(typeof plzMiniCache[plz]!="undefined") {                
				checkMiniPlzResult(plzMiniCache[plz],ob); 
			}
			else {            
				$.ajax({
				url: '/?type=5000',
				dataType: 'json',
				success:function(result)
				{
					plzMiniCache[plz]=result; 
					checkMiniPlzResult(result,ob);               
				},
				data:{"plz":plz}
				});
			}
		}
		else {
			if($(ob).val().length<5)
				$(ob).parent().children("div.autocomplete").css("display","none").html("");
				//$(".minirechner div.autocomplete").css("display","none").html("");  
			}
		}
    
function checkMiniPlzResult(result,ob) {
	var plz=$(ob).val().split(" "); 

	if(typeof result=="string"){              
		$(ob).val(plz[0]+" "+result).blur();
	}
	else {
		if(result) {
			$auto = $(ob).parent().children("div.autocomplete").css("display","block").html("");
			//$auto = $(".minirechner div.autocomplete").css("display","block").html("");  

			for(i=0;i<result.length;i++){
				var val=plz[0]+' '+ result[i];
				$auto.append('<a class="advice"><div class="advice">'+val+'</div></a>').children("a:last").children().click(function(){selectMiniCity(this,ob)});
			}
		}
	} 
}
function selectMiniCity(get,ob){
	$(ob).val(get.innerHTML);
	$(ob).parent().children("div.autocomplete").html("");
	//$(".minirechner div.autocomplete").html("");  
}

function calcHT(ht, nt){
	var ntWert = parseInt(nt);
	var htWert = parseInt(ht);
	var htntWert = ntWert + htWert;
	$("input[name='tx_mmetariffv2_pi1[kwh_ht]']").val(htntWert);
	}

function calcHTNT(ht) {
	var ntWert = parseInt((ht/100)*55);
	var htWert = parseInt((ht/100)*45);
	$("input[name='tx_mmetariffv2_pi1[kwh_nt]']").val(ntWert);
	$("input[name='tx_mmetariffv2_pi1[kwh_ht]']").val(htWert);
	}
