var lastfiltermaterial = "";
function updateForm() {
console.log("updateForm");
if($("#filtertype").val()!=''){
if($("input[name=fluidtype]:checked").val()!='type'){
$("#fluid").val(-1);
/*
$("#tvorgdiv").hide();
$("#tvorgkdiv").hide();
$("#fluiddiv").hide();
*/
$("#tvorgk").prop("disabled", true);
$("#tvorg").prop("disabled", true);
$("#fluid").prop("disabled", true);
$("#deltadtdiv").show();
$("#deltavtdiv").show();
$("#deltadtkdiv").show();
$("#deltavtkdiv").show();
$("#deltadt0div").show();
$("#deltavt0div").show();
$("#deltadt").prop("disabled", false);
$("#deltavt").prop("disabled", false);
$("#deltadtk").prop("disabled", false);
$("#deltavtk").prop("disabled", false);
$("#deltadt0").prop("disabled", false);
$("#deltavt0").prop("disabled", false);
}else{
$("#tvorgdiv").show();
$("#tvorgkdiv").show();
$("#fluiddiv").show();
$("#deltadtdiv").show();
$("#deltavtdiv").show();
$("#deltadtkdiv").show();
$("#deltavtkdiv").show();
$("#deltadt0div").show();
$("#deltavt0div").show();
$("#tvorgk").prop("disabled", false);
$("#tvorg").prop("disabled", false);
$("#fluid").prop("disabled", false);
$("#deltadt").prop("disabled", true);
$("#deltavt").prop("disabled", true);
$("#deltadtk").prop("disabled", true);
$("#deltavtk").prop("disabled", true);
$("#deltadt0").prop("disabled", true);
$("#deltavt0").prop("disabled", true);
/*
$("#deltadtdiv").hide();
$("#deltavtdiv").hide();
$("#deltadtkdiv").hide();
$("#deltavtkdiv").hide();
$("#deltadt0div").hide();
$("#deltavt0div").hide();
*/
}
if($("input[name=filterby]:checked").val()==2){
$("#pvorgdiv").show();
$("#subfiltertypediv").hide();
}else{
$("#subfiltertypediv").show();
$("#pvorgdiv").hide();
}
}else{
$("#subfiltertypediv").hide();
$("#pvorgdiv").hide();
}
$("#filtermaterial").removeClass("mustSelect");
if($("#filtermaterial").val()==''){
$("#filtermaterial").addClass("mustSelect");
}
$("#filterrating").removeClass("mustSelect");
if($("#filterrating").val()==''){
$("#filterrating").addClass("mustSelect");
}
$("#fluid").removeClass("mustSelect");
//if($("#fluid").val()=='-1' && !(($("#deltadtk").val()*1)>0 && ($("#deltavtk").val()*1)>0 && ($("#deltadt").val()*1)>0 && ($("#deltavt").val()*1)>0)){
if($("#fluid").val()=='-1'){
$("#fluid").addClass("mustSelect");
}
if($("#filtertype").val()=='SF,SFA,SMPF,SFZ,SF-TM,SF-SM'||$("#filtertype").val()=='SLF,SAF,SSF,SSFT'){
$("#filtervaluediv").show();
if($("#filtertype").val()=='SLF,SAF,SSF,SSFT'){
$("#filtervaluediv2").show();
$("#filtervalue").hide();
}else{
if($("#subfiltertype").val()=='SFZ'){
$("#filtervaluediv").hide();
$("#filtervalue").val('HV0');
}else{
$("#filtervaluediv2").hide();
$("#filtervalue").show();
}
}
}else{
$("#filtervaluediv").hide();
$("#filtervalue").val('HV0');
}
var ajaxparam = "fluid="+$("#fluid").val()+"&tvorg="+$("#tvorg").val()+"&pvorg="+$("#pvorg").val()+"&qvorh="+$("#qvorh").val()+"&tvorgk="+$("#tvorgk").val()+"&deltadt="+$("#deltadt").val()+"&deltavt="+$("#deltavt").val()+"&deltadtk="+$("#deltadtk").val()+"&deltavtk="+$("#deltavtk").val()+"&deltadt0="+$("#deltadt0").val()+"&deltavt0="+$("#deltavt0").val();
if($("input[name=fluidtype]:checked").val()=='type'){
if($("#fluid").val()==-1){
ajaxparam = "fluid="+$("#fluid").val()+"&qvorh="+$("#qvorh").val();
}
}else{
ajaxparam = "fluid="+$("#fluid").val()+"&tvorg="+$("#tvorg").val()+"&pvorg="+$("#pvorg").val()+"&qvorh="+$("#qvorh").val()+"&tvorgk="+$("#tvorgk").val()+"&deltadt="+$("#deltadt").val()+"&deltavt="+$("#deltavt").val()+"&deltadtk="+$("#deltadtk").val()+"&deltavtk="+$("#deltavtk").val()+"&deltadt0="+$("#deltadt0").val()+"&deltavt0="+$("#deltavt0").val();
}
console.log("ajaxparam: "+ajaxparam);
$.get( "/ajax/update_form.php?l=0&type="+$("#filtertype").val()+"&"+ajaxparam+"&debug="+$("#debug").val() + "&filtervalue="+$("#filtervalue").val() + "&filtermaterial="+$("#filtermaterial").val() + "&filterrating="+$("#filterrating").val() + "&filtertype="+$("#filtertype").val() + "&subfiltertype="+$("#subfiltertype").val() +
"&metrik=" + $("input[name=metrik]:checked").val()+"&filterby="+$("input[name=filterby]:checked").val()+"&deltaPGesMax="+$("#deltaPGesMax").val()+"&coldStart="+$("#coldStart").val() ,
function( data ) {
$( "#resulttable" ).html( data );
//stateSave: true,
$('#filtercalcresult').dataTable( {
responsive: {
breakpoints: [
{ name: 'desktop', width: Infinity },
{ name: 'tablet', width: 1024 },
{ name: 'fablet', width: 768 },
{ name: 'phone', width: 480 }
],
details: {
type: 'inline',
}
},
"aaSorting": [[ 5, "desc" ]]
} );
$("#filtercalcresult").DataTable().rows(':not(.parent)').nodes().to$().find('td:first-child').trigger('click');
/*
$("#filtercalcresult").DataTable().rows().every( function () {
var tr = $(this.node());
this.child(format(tr.data('child-value'))).show();
tr.addClass('shown');
});
*/
});
}
function roundToTwo(num) {
return Math.round(num * 10) / 10;
}
function setmetrik(textvalue,textvalue2) {
$('#pressurelabel').html(''+textvalue);
$('#flowlabel').html(''+textvalue2);
if($("input[name=metrik]:checked").val()=='psi'){
if($('#pvorg').val()!=''){
$('#pvorg').val(roundToTwo($('#pvorg').val()*14.5038));
}
if($('#deltaPGesMax').val()!=''){
$('#deltaPGesMax').val(roundToTwo($('#deltaPGesMax').val()*14.5038));
}
if($('#coldStart').val()!=''){
$('#coldStart').val(roundToTwo($('#coldStart').val()*14.5038));
}
if($('#qvorh').val()!=''){
$('#qvorh').val(roundToTwo($('#qvorh').val()/3.7854118));
}
$('.temperature').html("(°F)");
$('#tvorg').val(roundToTwo($('#tvorg').val()*1.8 + 32));
$('#tvorgk').val(roundToTwo($('#tvorgk').val()*1.8 + 32));
$('.temperature40').html("104°F");
/*
$('#deltadtk').val(roundToTwo($('#deltadtk').val()*62.42797372531));
$('#deltadt').val(roundToTwo($('#deltadt').val()*62.42797372531));
$('#deltadt0').val(roundToTwo($('#deltadt0').val()*62.42797372531));
$(".dichteeinheit").html("(lb/ft3)");
$(".viskositaeteinheit").html("(in2/s)");
$('#deltavtk').val(roundToTwo($('#deltavtk').val()/645.16));
$('#deltavt').val(roundToTwo($('#deltavt').val()/645.16));
$('#deltavt0').val(roundToTwo($('#deltavt0').val()/645.16));
*/
}else{
if($('#pvorg').val()!=''){
$('#pvorg').val(roundToTwo($('#pvorg').val()/14.5038));
}
if($('#deltaPGesMax').val()!=''){
$('#deltaPGesMax').val(roundToTwo($('#deltaPGesMax').val()/14.5038));
}
if($('#coldStart').val()!=''){
$('#coldStart').val(roundToTwo($('#coldStart').val()/14.5038));
}
if($('#qvorh').val()!=''){
$('#qvorh').val(roundToTwo($('#qvorh').val()*3.7854118));
}
$('#tvorg').val(roundToTwo(($('#tvorg').val()-32) / 1.8));
$('#tvorgk').val(roundToTwo(($('#tvorgk').val()-32) / 1.8));
/*
$('#deltadtk').val(roundToTwo($('#deltadtk').val()/62.42797372531));
$('#deltadt').val(roundToTwo($('#deltadt').val()/62.42797372531));
$('#deltadt0').val(roundToTwo($('#deltadt0').val()/62.42797372531));
$(".dichteeinheit").html("(kg/dm3)");
$(".viskositaeteinheit").html("(mm2/s)");
$('#deltavtk').val(roundToTwo($('#deltavtk').val()*645.16));
$('#deltavt').val(roundToTwo($('#deltavt').val()*645.16));
$('#deltavt0').val(roundToTwo($('#deltavt0').val()*645.16));
*/
$('.temperature').html("(°C)");
$('.temperature40').html("40°C");
}
updateForm();
updateForm();
}
function updateFiltertype2() {
lastfiltermaterial = $( "#filtermaterial" ).val();
if($("#subfiltertype").val()==''|| $("input[name=filterby]:checked").val()==2){
$.get( "/ajax/update_filtertype.php?filtertype="+$("#filtertype").val()+"&lastfiltermaterial="+lastfiltermaterial , function( data ) {
$( "#filtermaterial" ).html( data );
updateForm();
});
}else{
$.get( "/ajax/update_filtertype.php?filtertype="+ $("#subfiltertype").val()+"&lastfiltermaterial="+lastfiltermaterial , function( data ) {
$( "#filtermaterial" ).html( data );
updateForm();
});
}
}
function updateFiltertype() {
lastfiltermaterial = $( "#filtermaterial" ).val();
$.get( "/ajax/update_filtertype.php?filtertype="+ $("#filtertype").val()+"&lastfiltermaterial="+lastfiltermaterial, function( data ) {
$( "#filtermaterial" ).html( data );
updateForm();
});
$( "#subfiltertype" ).prop('disabled', true);
$.get( "/ajax/update_filtertype2.php?filtertype="+$("#filtertype").val()+"&filtertype2="+lastfiltertype , function( data ) {
$( "#subfiltertype" ).prop('disabled', false);
$( "#subfiltertype" ).html( data );
$('#subfiltertype').selectpicker({
liveSearch: true,
style: 'btn-light'
});
$('#subfiltertype').selectpicker('refresh');
console.log('refreshed.bs.select event');
// save the element
var $el = $('#subfiltertype');
// console.log( $el.data('selectpicker') );
// the list items with the options
var $lis = $el.data('selectpicker').$lis;
$lis.each(function(i) {
// get the title from the option
var tooltip_title = $el.find('option').eq(i).attr('desc');
$(this).tooltip({
'title': tooltip_title,
'html' : true,
'container': '#mainform',
'placement': 'top'
});
});
updateForm();
});
}
$(document).ready(function() {
$('input').keypress(function(e) {
if (e.which == 13) {
updateForm();
//console.log('test:'+this.tabIndex);
//$("[tabindex='"+(this.tabIndex+1)+"']").focus();
e.preventDefault();
}
});
$('.btooltip').tooltip({container: "#main", placement: "auto bottom", html:true});
//$('[data-toggle="tooltip"]').tooltip();
$('#filtertype').selectpicker({
liveSearch: true,
style: 'btn-light'
}).on('loaded.bs.select', function(e){
// console.log('bs.select loaded event');
// save the element
var $el = $(this);
// console.log( $el.data('selectpicker') );
// the list items with the options
var $lis = $el.data('selectpicker').$lis;
$lis.each(function(i) {
// get the title from the option
var tooltip_title = $el.find('option').eq(i).attr('desc');
$(this).tooltip({
'title': tooltip_title,
'html' : true,
'container': '#mainform',
'placement': 'top'
});
});
});
updateFiltertype();
//updateForm();
var $loading = $('#loadingDiv').hide();
var showLoading=false;
$(document)
.ajaxStart(function () {
showLoading=true;
setTimeout(function(){ if(showLoading) {$loading.show();} }, 1000);
})
.ajaxStop(function () {
showLoading=false;
$loading.hide();
});
} );