var set_all_flags = 1; var enter_key_code = 13; $(document).ready(initcospage); function bindcoshandlers() { $('.js-cos-expand__more').click(expandmore); $('.js-cos-expand__less').click(collapsemore); $('#shownpshacalcdialog').click(displaynpshacalculator); } function refreshschedule() {} function expandmore() { moretwistiestate = 'inline'; $('.js-cos-expand__more').addclass('hide'); $('.js-cos-expand__less').removeclass('hide'); $('.js-cos-expand').removeclass('hide'); $('.o-product-lines-container-scroll').addclass('is-auto-height'); twistieajax('more', 'inline'); } function collapsemore() { moretwistiestate = 'none'; $('.js-cos-expand__less').addclass('hide'); $('.js-cos-expand').addclass('hide'); $('.js-cos-expand__more').removeclass('hide'); $('.o-product-lines-container-scroll').removeclass('is-auto-height'); twistieajax('more', 'none'); } function toggleproductlineselection(checkboxname) { $('#product_selection_' + checkboxname).toggleclass('is-selected'); $('#' + checkboxname).prop('disabled', function(i, val) { return !val; }); } function toggledetails(checkboxname) { $('#prod_line_' + checkboxname + '_desc').toggleclass('hide'); } function isvalidsearchinputs() { flowvalid = validateinput_nonzero(flow_input_field, grouping_symbol, decimal_symbol); headvalid = validateinput_nonzero(head_input_field, grouping_symbol, decimal_symbol); return searchinputsarepresent() && flowvalid && headvalid && isproductlineselected(); } function searchinputsarepresent() { flow = document.getelementbyid(flow_input_field); head = document.getelementbyid(head_input_field); return flow.value && head.value; } function isproductlineselected() { selectedproductlinecount = $(".c-product-line-select.is-selected").length; return (selectedproductlinecount > 0); } function onsearchclick() { //alert("����"); if (isvalidsearchinputs()) { enableloadingspinner(); document.iqform.submit(); } else { $("#invalid_search").foundation('open'); } } function setsearchbuttonstate() { if (isvalidsearchinputs()) { enablesearchbutton(); } else { disablesearchbutton(); } } function enablesearchbutton() { addclasssafely("#searchbutton", 'c-button--success');} function disablesearchbutton() { removeclasssafely("#searchbutton", 'c-button--success'); } function enablelistmodelsbutton() { addclasssafely("#listmodelsspan",'success'); } function disablelistmodelsbutton() { removeclasssafely("#listmodelsspan",'success'); } function setlistmodelsbuttonstate() { if (isproductlineselected()) { enablelistmodelsbutton(); } else { disablelistmodelsbutton(); } } function addclasssafely(element, cssclass) { element = $(element); if (!element.hasclass(cssclass)) { element.addclass(cssclass); } } function removeclasssafely(element, cssclass) { element = $(element); if (element.hasclass(cssclass)) { element.removeclass(cssclass); } } function twistieajax(twistieid, displaystyle) { savedynamictwistiedisplay(twistieid, displaystyle); } function setmoretwistiestate() { if(moretwistiestate === 'inline') { expandmore(); } else { collapsemore(); } } function bindenterkeyhandler() { $(document).bind('keypress', (function(event) { if (event.keycode == enter_key_code) { onsearchclick(); } })); } function initcospage() { bindenterkeyhandler(); bindcoshandlers(); setmoretwistiestate(); setsearchbuttonstate(); setlistmodelsbuttonstate(); setheadstatic(); scrolltoverticalintuitive(); initmodals(); excludefromrowclickhandler(); $(window).scroll(function(){ setscrollpositionyintuitive(); }) setliquidoverride(); } function excludefromrowclickhandler() { $(".js-stop-click-propagation").click(function(event) { event.stoppropagation(); }); } function initmodals() { $('.close-button').each(function() { $(this).attr('data-close', ''); }); $('.dropdown.menu').each(function() { $(this).attr('data-dropdown-menu', ''); }); } function setliquidoverride() { $('#overrideliquidproperties').change(function() { $('#sgmax, #constfluiddensityunit, #viscosityrated, #viscosityratedunit, #fluiddensity').prop('disabled', function(i, v) { return !v; }); document.iqform.liquidpropertiesparam.value = $('#overrideliquidproperties').prop('checked'); if(!$('#overrideliquidproperties').prop('checked')) { $('#liquidcalloutdiv').addclass('grey'); refreshmaincos(); } else { $('#liquidcalloutdiv').removeclass('grey'); } }); if($('#overrideliquidproperties').prop('checked')) { $('#sgmax, #constfluiddensityunit, #viscosityrated, #viscosityratedunit, #fluiddensity').removeprop('disabled'); $('#liquidcalloutdiv').removeclass('grey'); } else { $('#sgmax, #constfluiddensityunit, #viscosityrated, #viscosityratedunit, #fluiddensity').prop('disabled', 'disabled'); $('#liquidcalloutdiv').addclass('grey'); } } function recalculateliquids() { $.ajax({ url : context_path + "/ajax/conditionsofservice/liquids", type : 'post', data : getsearchdataliquids(), success : function(data) { $('#morefields').replacewith(data); $(document).foundation(); initcospage(); }, error : function(xhr, status, error) { redirectifsessionexpired(xhr.responsetext); } }); } function filterproductlines() { $.ajax({ url : context_path + "/ajax/productlines/filtering", type : 'post', data : getproductlinepickerstate(), success : function(data) { $('#productlinelist').replacewith(data); $(document).foundation(); initcospage(); }, error : function(xhr, status, error) { redirectifsessionexpired(xhr.responsetext); } }); } /* collects all inputs in the productlinepicker */ function getproductlinepickerstate() { var state = {}; $('#productlinepicker :input:enabled').each(function() { var that = $(this); state[that.attr('name')] = that.val(); }) return state; } function getsearchdataliquids() { var state = {}; $('#cosinputs :input:enabled').each(function() { var that = $(this); state[that.attr('name')] = that.val(); }) $('#hiddeninputs :input:enabled').each(function() { var that = $(this); state[that.attr('name')] = that.val(); }) state['calculateliquidpropertiesspecifiers'] = 'true'; return state; } function setotherfield(firstfield, otherfield) { $('#' + otherfield).val($('#' + firstfield).val()); } function onchangefield(flagstoset) { upserthiddeninput('searchresultsdirtyflag', 'true'); setsavedflag(false); } function recalculatepage() { submitandnavigateto(target_conditions_of_service); } function submitandnavigateto(targetpage) { if(targetpage == target_conditions_of_service) { enableloadingspinner(); document.iqform.action = target_navigation_flags; document.iqform.currentpage.value = current_page; document.iqform.targetpage.value = targetpage; document.iqform.submit(); } else if (isvalidsearchinputs()) { enableloadingspinner(); document.iqform.action = target_navigation_flags; document.iqform.currentpage.value = current_page; document.iqform.targetpage.value = targetpage; document.iqform.submit(); } else { $("#invalid_search").foundation('open'); } } function displaynpshacalculator() { datatosend = getcosstate() datatosend['initialload'] = 'true'; $.ajax({ url : context_path + "/ajax/npshacalculator/display", type : 'post', initialload : 'true', data : datatosend, success : function(data) { $('#npshacalculatorcontent').replacewith(data); $(document).foundation(); }, error : function(xhr, status, error) { redirectifsessionexpired(xhr.responsetext); } }); } function recalcnpshacalculator() { $.ajax({ async : false, // if the user clicks the "submit" button, ensure this completes first url : context_path + "/ajax/npshacalculator/recalc", type : 'post', data : getnpshacalculatorstate(), success : function(data) { $('#npshacalculatorresults').replacewith(data); $(document).foundation(); }, error : function(xhr, status, error) { redirectifsessionexpired(xhr.responsetext); } }); } function submitnpshacalculator() { datatosend = getnpshacalculatorstate(); datatosend['recalcparentbrowser'] = 'true'; $.ajax({ url : context_path + "/ajax/npshacalculator", type : 'post', data : datatosend, success : function(data) { ajaxrefresh_maincos(data); }, error : function(xhr, status, error) { redirectifsessionexpired(xhr.responsetext); } }); $(".close-reveal-modal").click(); } function getnpshacalculatorstate() { var state = {}; collectinputs('#npshacalculatorcontent').each(function() { var that = $(this); state[that.attr('name')] = that.val(); }) return state; } function getcosstate() { var state = {}; collectinputs('#maincos').each(function() { var that = $(this); state[that.attr('name')] = that.val(); }) state['calculateliquidpropertiesspecifiers'] = 'true'; return state; } function refreshmaincos() { $.ajax({ url : context_path + "/ajax/conditionsofservice/refresh", type : 'post', data : getcosstateforliquidchange(), success : function(data) { ajaxrefresh_maincos(data); }, error : function(xhr, status, error) { redirectifsessionexpired(xhr.responsetext); } }); } function getcosstateforliquidchange() { data = getcosstate(); if(!$('#overrideliquidproperties').prop('checked')) { delete data.sgmax; delete data.sgmaxdirty; delete data.sgmaxdirtyunit; delete data.viscosityrated; delete data.viscosityrateddirty; delete data.viscosityratedunit; delete data.fluiddensity; delete data.fluiddensitydirty; delete data.fluiddensityunit; } console.log(data); return data; } function ajaxrefresh_maincos(data) { $('#maincos').replacewith(data); $(document).foundation(); initcospage(); } function disableproductlinepicker() { $("#productlinelist").children().attr("disabled","disabled"); $('.c-product-line').css('opacity', '0.25'); } function setheadstatic(){ if ($('.js-static-head-container').length > 0 ){ $("#qtyofpumpsinparallel").change(function() { onqtyofpumpsinparallel(); }); setheadstaticdisplaystate(); } } function onqtyofpumpsinparallel() { $("#headstaticsystemcurve1dirty").val('true'); setheadstaticdisplaystate(); } function setheadstaticdisplaystate(){ if ($("#qtyofpumpsinparallel").val()> 1) { $('.js-static-head-container').removeclass('hide'); } else { $('.js-static-head-container').addclass('hide'); } } function setscrollpositionyintuitive() { var top = (document.documentelement && document.documentelement.scrolltop) || document.body.scrolltop; var y = parseint(top); if (!isnan(y)) { window.document.forms[0].positiony.value = y; } } function scrolltoverticalintuitive() { window.scrollto(0, $('#positiony').val()); } function setscrollpositionyvalue(fieldobj, divobj){ var y = parseint(divobj.scrolly); if(!isnan(y)){ fieldobj.value =y; } } function onselectallproductlinesclick(){ if ($('.js-select-all').hasclass('is-selected')){ $('input[type="hidden"][name^="pl"]:not(:disabled)').each(function(){ $(this).prop("disabled", true); $('#product_selection_' + $(this).attr("id")).removeclass('is-selected'); }); $('.js-select-all').removeclass('is-selected'); } else { $('input[type="hidden"][name^="pl"]:disabled').each(function(){ $(this).prop("disabled", false); $('#product_selection_' + $(this).attr("id")).addclass('is-selected'); }); $('.js-select-all').addclass('is-selected'); } }