/** * @license Dual licensed under the MIT or GPL Version 2 licenses. */ let volume_tip = false; let surface_tip = false; let linear_tip = false; let perimeter_tip = false; let weight_tip = false; let passed = 0; let passed_attr = 0; const volume_units = ["mm3","cm3","dm3","m3"]; const surface_units = ["mm2","cm2","dm2","m2"]; const linear_units = ["mm","cm","dm","m"]; const perimeter_units = ["mm","cm","dm","m"]; const weight_units = ["cg","dg","g","dag","hg","kg","ton"]; window.setInterval(function(){ calc_type(); checkconversion(); checktest(); height_dropdown_warning(); width_dropdown_warning(); depth_dropdown_warning(); weight_dropdown_warning(); }, 1000); function calc_type() { if ($('#calculation_type').val() == 'volume'){ $('[id^="perimeter"]').hide(); $('[id^="linear"]').hide(); $('[id^="surface"]').hide(); $('[id^="volume"]').show(); $('[id^="weight"]').hide(); $('[aria-label^="Perimeter Units"]').hide(); $('[aria-label^="Linear Units"]').hide(); $('[aria-label^="Surface Units"]').hide(); $('[aria-label^="Volume Units"]').show(); $('[aria-label^="Weight Units"]').hide(); if ($('input[name="direct_input"]:checked').length == 0) { $('[id^="ratio_field"]').show(); $('[id^="req_quan"]').show(); } else { $('[id^="ratio_field"]').hide(); $('[id^="req_quan"]').hide(); } $('[id^="height"]').show(); $('[id^="width"]').show(); $('[id^="depth"]').show(); } else if ($('#calculation_type').val() == 'surface'){ $('[id^="perimeter"]').hide(); $('[id^="linear"]').hide(); $('[id^="surface"]').show(); $('[id^="volume"]').hide(); $('[id^="weight"]').hide(); $('[aria-label^="Perimeter Units"]').hide(); $('[aria-label^="Linear Units"]').hide(); $('[aria-label^="Surface Units"]').show(); $('[aria-label^="Volume Units"]').hide(); $('[aria-label^="Weight Units"]').hide(); if ($('input[name="direct_input"]:checked').length == 0) { $('[id^="ratio_field"]').show(); $('[id^="req_quan"]').show(); } else { $('[id^="ratio_field"]').hide(); $('[id^="req_quan"]').hide(); } $('[id^="height"]').show(); $('[id^="width"]').show(); $('[id^="depth"]').hide(); } else if ($('#calculation_type').val() == 'linear'){ $('[id^="perimeter"]').hide(); $('[id^="linear"]').show(); $('[id^="surface"]').hide(); $('[id^="volume"]').hide(); $('[id^="weight"]').hide(); $('[aria-label^="Perimeter Units"]').hide(); $('[aria-label^="Linear Units"]').show(); $('[aria-label^="Surface Units"]').hide(); $('[aria-label^="Volume Units"]').hide(); $('[aria-label^="Weight Units"]').hide(); $('[id^="ratio_field"]').hide(); if ($('input[name="direct_input"]:checked').length == 0) { $('[id^="req_quan"]').show(); } else { $('[id^="req_quan"]').hide(); } $('[id^="height"]').hide(); $('[id^="width"]').show(); $('[id^="depth"]').hide(); } else if ($('#calculation_type').val() == 'perimeter'){ $('[id^="perimeter"]').show(); $('[id^="linear"]').hide(); $('[id^="surface"]').hide(); $('[id^="volume"]').hide(); $('[id^="weight"]').hide(); $('[aria-label^="Perimeter Units"]').show(); $('[aria-label^="Linear Units"]').hide(); $('[aria-label^="Surface Units"]').hide(); $('[aria-label^="Volume Units"]').hide(); $('[aria-label^="Weight Units"]').hide(); if ($('input[name="direct_input"]:checked').length == 0) { $('[id^="ratio_field"]').show(); } else $('[id^="ratio_field"]').hide(); $('[id^="height"]').show(); $('[id^="width"]').show(); $('[id^="depth"]').hide(); $('[id^="req_quan"]').hide(); } else if ($('#calculation_type').val() == 'weight'){ $('[id^="perimeter"]').hide(); $('[id^="linear"]').hide(); $('[id^="surface"]').hide(); $('[id^="volume"]').hide(); $('[id^="weight"]').show(); $('[aria-label^="Perimeter Units"]').hide(); $('[aria-label^="Linear Units"]').hide(); $('[aria-label^="Surface Units"]').hide(); $('[aria-label^="Volume Units"]').hide(); $('[aria-label^="Weight Units"]').show(); $('[id^="ratio_field"]').hide(); $('[id^="height"]').hide(); $('[id^="width"]').hide(); $('[id^="depth"]').hide(); if ($('input[name="direct_input"]:checked').length == 0) { $('[id^="req_quan"]').show(); } else { $('[id^="req_quan"]').hide(); } } } function recommended_settings() { if ($('#calculation_type').val() == 'volume'){ volume_example_set(); passed = 0; passed_attr = 0; volume_tip = true; surface_tip = false; linear_tip = false; perimeter_tip = false; weight_tip = false; } else if ($('#calculation_type').val() == 'surface'){ surface_example_set(); passed = 0; passed_attr = 0; volume_tip = false; surface_tip = true; linear_tip = false; perimeter_tip = false; weight_tip = false; } else if ($('#calculation_type').val() == 'linear'){ linear_example_set(); passed = 0; passed_attr = 0; volume_tip = false; surface_tip = false; linear_tip = true; perimeter_tip = false; weight_tip = false; } else if ($('#calculation_type').val() == 'perimeter'){ perimeter_example_set(); passed = 0; passed_attr = 0; volume_tip = false; surface_tip = false; linear_tip = false; perimeter_tip = true; weight_tip = false; } else if ($('#calculation_type').val() == 'weight'){ weight_example_set(); passed = 0; passed_attr = 0; volume_tip = false; surface_tip = false; linear_tip = false; perimeter_tip = false; weight_tip = true; } } $( "#link-ModuleSquaremeter" ).click(function() { calc_type(); var IsChecked = $('input[name="attselect"]:checked').length > 0; if (IsChecked) checktest4(); else checktest3(); }); $(document).on('change','#calculation_type',function(){ calc_type(); recommended_settings(); var IsChecked = $('input[name="attselect"]:checked').length > 0; if (IsChecked) checktest4(); else checktest3(); }); $('#attselect').change(function() { var IsChecked = $('input[name="attselect"]:checked').length > 0; if (IsChecked) { $(this).attr("checked", true); checktest4(); } else { $(this).attr("checked", false); checktest3(); } }); $('#secconversionselect').change(function() { var IsChecked = $('input[name="secconversionselect"]:checked').length > 0; if (IsChecked) { $(this).attr("checked", true); } else { $(this).attr("checked", false); } }); $('#direct_input').change(function(){ var IsChecked = $('input[name="direct_input"]:checked').length > 0; if (IsChecked) { $(this).attr("checked", true); } else { $(this).attr("checked", false); } if (this.checked) { $('#ratio_field').css('display', 'none'); $('#ratio').val(''); } else { $('#ratio_field').css('display', 'block'); } }); $('#unit_baseprice').change(function(){ var IsChecked = $('input[name="unit_baseprice"]:checked').length > 0; if (IsChecked) { $(this).attr("checked", true); } else { $(this).attr("checked", false); } }); $(document).on('change','#attribute_unit',function(){ calc_type(); var IsChecked = $('input[name="attselect"]:checked').length > 0; if (IsChecked) checktest4(); else checktest3(); }); $(document).on('change','#conversion_unit',function(){ calc_type(); var IsChecked = $('input[name="attselect"]:checked').length > 0; if (IsChecked) checktest4(); else checktest3(); }); function height_dropdown_warning() { var IsChecked = $('input[name="heightcheck"]:checked').length > 0; if (IsChecked) { var step = document.getElementById('step'); var step_global = Number(step.value); var step = document.getElementById('step_height'); var step_height = Number(step.value); if (step_height) step_value = step_height; else step_value = step_global; var minh = document.getElementById('minimum_height'); var minhc = Number(minh.value); var maxh = document.getElementById('maximum_height'); var maxhc = Number(maxh.value); value_to_be_generated = Math.round((maxhc - minhc)/step_value); var y=document.getElementById("height_dropdown_warning"); if (value_to_be_generated > 100) { y.innerHTML = value_to_be_generated + ' ' + dropdown_warning_message; } else { y.innerHTML = ""; } } else { var y=document.getElementById("height_dropdown_warning"); y.innerHTML = ""; } } function width_dropdown_warning() { var IsChecked = $('input[name="widthcheck"]:checked').length > 0; if (IsChecked) { var step = document.getElementById('step'); var step_global = Number(step.value); var step = document.getElementById('step_width'); var step_width = Number(step.value); if (step_width) step_value = step_width; else step_value = step_global; var minw = document.getElementById('minimum_width'); var minwc = Number(minw.value); var maxw = document.getElementById('maximum_width'); var maxwc = Number(maxw.value); value_to_be_generated = Math.round((maxwc - minwc)/step_value); var y=document.getElementById("width_dropdown_warning"); if (value_to_be_generated > 100) { y.innerHTML = value_to_be_generated + ' ' + dropdown_warning_message; } else { y.innerHTML = ""; } } else { var y=document.getElementById("width_dropdown_warning"); y.innerHTML = ""; } } function depth_dropdown_warning() { var IsChecked = $('input[name="depthcheck"]:checked').length > 0; if (IsChecked) { var step = document.getElementById('step'); var step_global = Number(step.value); var step = document.getElementById('step_depth'); var step_depth = Number(step.value); if (step_depth) step_value = step_depth; else step_value = step_global; var mind = document.getElementById('minimum_depth'); var mindc = Number(mind.value); var maxd = document.getElementById('maximum_depth'); var maxdc = Number(maxd.value); value_to_be_generated = Math.round((maxdc - mindc)/step_value); var y=document.getElementById("depth_dropdown_warning"); if (value_to_be_generated > 100) { y.innerHTML = value_to_be_generated + ' ' + dropdown_warning_message; } else { y.innerHTML = ""; } } else { var y=document.getElementById("depth_dropdown_warning"); y.innerHTML = ""; } } function weight_dropdown_warning() { var IsChecked = $('input[name="weightcheck"]:checked').length > 0; if (IsChecked) { var step = document.getElementById('step'); var step_value = Number(step.value); var minwe = document.getElementById('minimum_weight'); var minwec = Number(minwe.value); var maxwe = document.getElementById('maximum_weight'); var maxwec = Number(maxwe.value); value_to_be_generated = Math.round((maxwec - minwec)/step_value); var y=document.getElementById("weight_dropdown_warning"); if (value_to_be_generated > 100) { y.innerHTML = value_to_be_generated + ' ' + dropdown_warning_message; } else { y.innerHTML = ""; } } else { var y=document.getElementById("weight_dropdown_warning"); y.innerHTML = ""; } } function checktest(){ var maxw = document.getElementById('maximum_width'); var maxh = document.getElementById('maximum_height'); var maxd = document.getElementById('maximum_depth'); var maxwe = document.getElementById('maximum_weight'); var minw = document.getElementById('minimum_width'); var minh = document.getElementById('minimum_height'); var mind = document.getElementById('minimum_depth'); var minwe = document.getElementById('minimum_weight'); var conv = document.getElementById('conversion'); //var attr = document.getElementById('attribute'); var maxwu = document.getElementById('maximum_width_unit'); var maxhu = document.getElementById('maximum_height_unit'); var maxdu = document.getElementById('maximum_depth_unit'); var maxweu = document.getElementById('maximum_weight_unit'); var maxwc = Number(maxw.value); var maxhc = Number(maxh.value); var maxdc = Number(maxd.value); var maxwec = Number(maxwe.value); var minwc = Number(minw.value); var minhc = Number(minh.value); var mindc = Number(mind.value); var minwec = Number(minwe.value); var convc = Number(conv.value); //var attrc = Number(attr.value); var attrc = $('#attribute').val(); var maxwuc = maxwu.options[maxwu.selectedIndex].value; var maxhuc = maxhu.options[maxhu.selectedIndex].value; var maxduc = maxdu.options[maxdu.selectedIndex].value; var maxweuc = maxweu.options[maxweu.selectedIndex].value; var checknumberw = (isNaN( maxwc )) || (isNaN( minwc )) if (checknumberw == true) { var y2=document.getElementById("errort2"); y2.innerHTML = errort2; } else { var y2=document.getElementById("errort2"); y2.innerHTML=""; } var checknumberh = (isNaN( maxhc )) ||(isNaN( minhc )) if (checknumberh == true) { var y1=document.getElementById("errort1"); y1.innerHTML = errort1; } else { var y1=document.getElementById("errort1"); y1.innerHTML=""; } var checknumberd = (isNaN( maxdc )) ||(isNaN( mindc )) if (checknumberd == true) { var y6=document.getElementById("errort4"); y6.innerHTML = errort4; } else { var y6=document.getElementById("errort4"); y6.innerHTML=""; } var checknumberwe = (isNaN( maxwec )) ||(isNaN( minwec )) if (checknumberwe == true) { var y7=document.getElementById("errort8"); y7.innerHTML = errort8; } else { var y7=document.getElementById("errort8"); y7.innerHTML=""; } var IsChecked = $('input[name="attselect"]:checked').length > 0; if (IsChecked) { if (typeof attrc !== 'undefined' && attrc) { var checknumberc2 = (isNaN( attrc ) || attrc == '' || attrc.indexOf('.') > -1); } else { var checknumberc2 = false; } if (checknumberc2 == true) { var y=document.getElementById("errort7"); y.innerHTML = errort7; } else { var y=document.getElementById("errort7"); y.innerHTML=""; } var y1=document.getElementById("errort"); y1.innerHTML=""; } else { var checknumberc = (isNaN( convc ) || convc == '') if (checknumberc == true) { var y=document.getElementById("errort"); y.innerHTML = errort; } else { var y=document.getElementById("errort"); y.innerHTML=""; } var y1=document.getElementById("errort7"); y1.innerHTML=""; } var checknumberhu = (maxhuc == "") if ((checknumberhu == true) && ($("#height").is(":visible"))){ var z2=document.getElementById("error_height"); z2.innerHTML = error_height; } else { var z2=document.getElementById("error_height"); z2.innerHTML=""; } var checknumberwu = (maxwuc == "") if ((checknumberwu == true) && ($("#width").is(":visible"))){ var z3=document.getElementById("error_width"); z3.innerHTML = error_width; } else { var z3=document.getElementById("error_width"); z3.innerHTML=""; } var checknumberdu = (maxduc == "") if ((checknumberdu == true) && ($("#depth").is(":visible"))){ var z4=document.getElementById("error_depth"); z4.innerHTML = error_depth; } else { var z4=document.getElementById("error_depth"); z4.innerHTML=""; } var checknumberweu = (maxweuc == "") if ((checknumberweu == true) && ($("#weight").is(":visible"))){ var z1=document.getElementById("error_weight"); z1.innerHTML = error_weight; } else { var z1=document.getElementById("error_weight"); z1.innerHTML=""; } overalltest(); return false; } function overalltest() { if ((document.getElementById("errort2").innerHTML!="") || (document.getElementById("errort1").innerHTML!="") || (document.getElementById("errort4").innerHTML!="") || (document.getElementById("errort").innerHTML!="") || (document.getElementById("errort7").innerHTML!="") || (document.getElementById("errort8").innerHTML!="") || (document.getElementById("errort1_").innerHTML!="") || (document.getElementById("errort2_").innerHTML!="") || (document.getElementById("errort3_").innerHTML!="") || (document.getElementById("errort6_").innerHTML!="") || (document.getElementById("errort4_").innerHTML!="") || (document.getElementById("errort5_").innerHTML!="") || (document.getElementById("errort9_").innerHTML!="") || (document.getElementById("errort3__").innerHTML!="") || (document.getElementById("errort4__").innerHTML!="") || (document.getElementById("errort6__").innerHTML!="") || (document.getElementById("errort9__").innerHTML!="") || (document.getElementById("error_width").innerHTML!="") || (document.getElementById("error_height").innerHTML!="") || (document.getElementById("error_depth").innerHTML!="") || (document.getElementById("error_weight").innerHTML!="")) disablesave(); else enablesave(); } function disablesave() { if ($('#squaremeter_display').parent().prop('className') == 'switch-input -checked') { $( "#desc-product-save" ).hide(); $( "#desc-product-save-and-stay" ).hide(); $( ".js-btn-save" ).hide(); $( "#dropdownMenu" ).hide(); } } function enablesave() { $( "#desc-product-save" ).show(); $( "#desc-product-save-and-stay" ).show(); $( ".js-btn-save" ).show(); $( "#dropdownMenu" ).show(); } function checktest3(){ var typev = document.getElementById('calculation_type').value; var convunitv = document.getElementById('conversion_unit').value; var checkmatch = (typev == "surface" && (convunitv=="mm" || convunitv=="cm" || convunitv=="dm"|| convunitv=="m"|| convunitv=="mm3" || convunitv=="cm3" || convunitv=="dm3"|| convunitv=="m3" || convunitv=="cg" || convunitv=="dg" || convunitv=="g"|| convunitv=="dag" || convunitv=="hg" || convunitv=="kg"|| convunitv=="ton"|| convunitv=="")) if (checkmatch == true) { var y4=document.getElementById("errort4_"); y4.innerHTML = errort4_; } else { var y4=document.getElementById("errort4_"); y4.innerHTML=""; } var checkmatch2 = (typev == "volume" && (convunitv=="mm" || convunitv=="cm" || convunitv=="dm"|| convunitv=="m"|| convunitv=="mm2" || convunitv=="cm2"|| convunitv=="dm2"|| convunitv=="m2" || convunitv=="cg" || convunitv=="dg"|| convunitv=="g"|| convunitv=="dag" || convunitv=="hg" || convunitv=="kg"|| convunitv=="ton"|| convunitv=="")) if (checkmatch2 == true) { var y3=document.getElementById("errort3_"); y3.innerHTML = errort3_; } else { var y3=document.getElementById("errort3_"); y3.innerHTML=""; } var checkmatch3 = ((typev == "linear" || typev == "perimeter") && (convunitv=="mm3" || convunitv=="cm3" || convunitv=="dm3"|| convunitv=="m3"|| convunitv=="mm2" || convunitv=="cm2"|| convunitv=="dm2"|| convunitv=="m2" || convunitv=="cg" || convunitv=="dg"|| convunitv=="g"|| convunitv=="dag" || convunitv=="hg" || convunitv=="kg"|| convunitv=="ton"|| convunitv=="")) if (checkmatch3 == true) { var y3=document.getElementById("errort6_"); y3.innerHTML = errort6_; } else { var y3=document.getElementById("errort6_"); y3.innerHTML=""; } var checkmatch4 = ((typev == "weight") && (convunitv=="mm" || convunitv=="cm" || convunitv=="dm"|| convunitv=="m"|| convunitv=="mm3" || convunitv=="cm3" || convunitv=="dm3"|| convunitv=="m3"|| convunitv=="mm2" || convunitv=="cm2"|| convunitv=="dm2"|| convunitv=="m2" || convunitv=="")) if (checkmatch4 == true) { var y3=document.getElementById("errort9_"); y3.innerHTML = errort9_; } else { var y3=document.getElementById("errort9_"); y3.innerHTML=""; } var y41=document.getElementById("errort4__"); y41.innerHTML=""; var y32=document.getElementById("errort3__"); y32.innerHTML=""; var y33=document.getElementById("errort6__"); y33.innerHTML=""; var y34=document.getElementById("errort9__"); y34.innerHTML=""; overalltest(); return false; } function checktest4(){ var typev = document.getElementById('calculation_type').value; var attrvunitv = document.getElementById('attribute_unit').value; var checkmatch = (typev == "surface" && (attrvunitv=="mm" || attrvunitv=="cm" || attrvunitv=="dm"|| attrvunitv=="m"|| attrvunitv=="mm3" || attrvunitv=="cm3" || attrvunitv=="dm3"|| attrvunitv=="m3"|| attrvunitv=="cg" || attrvunitv=="dg"|| attrvunitv=="g"|| attrvunitv=="dag" || attrvunitv=="hg" || attrvunitv=="kg"|| attrvunitv=="ton" || attrvunitv=="")) if (checkmatch == true) { var y4=document.getElementById("errort4__"); y4.innerHTML = errort4__; } else { var y4=document.getElementById("errort4__"); y4.innerHTML=""; } var checkmatch2 = (typev == "volume" && (attrvunitv=="mm" || attrvunitv=="cm" || attrvunitv=="dm"|| attrvunitv=="m"|| attrvunitv=="mm2" || attrvunitv=="cm2"|| attrvunitv=="dm2"|| attrvunitv=="m2" || attrvunitv=="cg" || attrvunitv=="dg"|| attrvunitv=="g"|| attrvunitv=="dag" || attrvunitv=="hg" || attrvunitv=="kg"|| attrvunitv=="ton" || attrvunitv=="")) if (checkmatch2 == true) { var y3=document.getElementById("errort3__"); y3.innerHTML = errort3__; } else { var y3=document.getElementById("errort3__"); y3.innerHTML=""; } var checkmatch3 = ((typev == "linear" || typev == "perimeter") && (attrvunitv=="mm3" || attrvunitv=="cm3" || attrvunitv=="dm3"|| attrvunitv=="m3"|| attrvunitv=="mm2" || attrvunitv=="cm2"|| attrvunitv=="dm2"|| attrvunitv=="m2" || attrvunitv=="cg" || attrvunitv=="dg"|| attrvunitv=="g"|| attrvunitv=="dag" || attrvunitv=="hg" || attrvunitv=="kg"|| attrvunitv=="ton" || attrvunitv=="")) if (checkmatch3 == true) { var y3=document.getElementById("errort6__"); y3.innerHTML = errort6__; } else { var y3=document.getElementById("errort6__"); y3.innerHTML=""; } var checkmatch4 = ((typev == "weight") && (attrvunitv=="mm" || attrvunitv=="cm" || attrvunitv=="dm"|| attrvunitv=="m" || attrvunitv=="mm3" || attrvunitv=="cm3" || attrvunitv=="dm3"|| attrvunitv=="m3"|| attrvunitv=="mm2" || attrvunitv=="cm2"|| attrvunitv=="dm2"|| attrvunitv=="m2" || attrvunitv=="")) if (checkmatch4 == true) { var y3=document.getElementById("errort7__"); y3.innerHTML = errort7__; } else { var y3=document.getElementById("errort7__"); y3.innerHTML=""; } var y41=document.getElementById("errort4_"); y41.innerHTML=""; var y32=document.getElementById("errort3_"); y32.innerHTML=""; var y33=document.getElementById("errort6_"); y33.innerHTML=""; var y34=document.getElementById("errort9_"); y34.innerHTML=""; overalltest(); return false; } $('#attselect').click(function(){ if (this.checked) { $('#attselect_conv').css('display', 'none') $('#attselect_attr').css('display', 'block') } else { $('#attselect_conv').css('display', 'block') $('#attselect_attr').css('display', 'none') } }) $('#secconversionselect').click(function(){ if (this.checked) { $('#second_conversion').css('display', 'block') } else { $('#second_conversion').css('display', 'none') } }) $('#direct_input').click(function(){ if (this.checked) { $('#ratio_field').css('display', 'none'); $('#ratio').val(''); } else { $('#ratio_field').css('display', 'block'); } }) function checkconversion(){ if ($('#attselect').attr('checked')) { $('#attselect_conv').css('display', 'none') $('#attselect_attr').css('display', 'block') } else { $('#attselect_conv').css('display', 'block') $('#attselect_attr').css('display', 'none') } if ($('#secconversionselect').attr('checked')) { $('#second_conversion').css('display', 'block') } else { $('#second_conversion').css('display', 'none') } } function checkstep(){ var step = document.getElementById('step'); var stepc = Number(step.value); var checknumberstep = (isNaN( stepc )) || (isNaN( stepc )) || (stepc < 0) if (checknumberstep == true) { var y=document.getElementById("error_step"); y.innerHTML = error_step; } overalltest(); return false; } function checkstep_height(){ var step = document.getElementById('step_height'); var stepc = Number(step.value); var checknumberstep = (isNaN( stepc )) || (isNaN( stepc )) || (stepc < 0) if (checknumberstep == true) { var y=document.getElementById("error_step_height"); y.innerHTML = error_step_height; } overalltest(); return false; } function checkstep_width(){ var step = document.getElementById('step_width'); var stepc = Number(step.value); var checknumberstep = (isNaN( stepc )) || (isNaN( stepc )) || (stepc < 0) if (checknumberstep == true) { var y=document.getElementById("error_step_width"); y.innerHTML = error_step_width; } overalltest(); return false; } function checkstep_depth(){ var step = document.getElementById('step_depth'); var stepc = Number(step.value); var checknumberstep = (isNaN( stepc )) || (isNaN( stepc )) || (stepc < 0) if (checknumberstep == true) { var y=document.getElementById("error_step_depth"); y.innerHTML = error_step_depth; } overalltest(); return false; } $(document).ready(function() { $('#inputfile1').change(function(){ var file_data = $('#inputfile1').prop('files')[0]; //var id_product = $('#id_product1').val(); var id_product = $( "input[name$='id_product']" ).val(); if (id_product == null) var id_product = $( "#form_id_product" ).val(); var ext = file_data['name'].substr(file_data['name'].lastIndexOf(".")); var ext_withoutdot = file_data['name'].substr(file_data['name'].lastIndexOf(".")+1); if (ext_withoutdot=='jpg' || ext_withoutdot=='jpeg' || ext_withoutdot=='png' || ext_withoutdot=='gif' || ext_withoutdot=='PNG' || ext_withoutdot=='JPG' || ext_withoutdot=='JPEG' || ext_withoutdot=='bmp' || ext_withoutdot=='tif') var image_check=1; else var image_check=0; if (image_check==0) { $('#refresh').css('color', 'red'); $("#refresh").text(allowed_images + ":jpg, JPG, jpeg, JPEG, gif, png, PNG, bmp, tif"); $('#refresh').delay(5000).fadeOut(400); return; } var form_data = new FormData(); form_data.append('file', file_data); form_data.append('filename', id_product + ext); form_data.append('id_product', id_product); $.ajax({ url: "/modules/squaremeter/classes/upload.php", type: "POST", data: form_data, contentType: false, cache: false, processData:false, // complete : function(){ // alert(this.url) // }, success: function(data){ $(".image-preview").attr("src", data); $('#refresh').css('color', 'green'); $("#refresh").text("Saved. CTRL + F5 to refresh image").fadeIn(100); $('#refresh').delay(5000).fadeOut(400); } }); }); }); $('#module_squaremeter input').keypress(function(event) { if(event.which < 46 || event.which > 59) { event.preventDefault(); } // prevent if not number/dot if(event.which == 46 && $(this).val().indexOf('.') != -1) { event.preventDefault(); } // prevent if already dot }); $('#ratio').keypress(function(event) { if(event.which < 48 || event.which > 58) { event.preventDefault(); } // prevent if not number/colon if(event.which == 48 && $(this).val() == '') { event.preventDefault(); } // prevent if starts with zero if(event.which == 58 && $(this).val() == '') { event.preventDefault(); } // prevent if starts with colon var sectionToCheck = $(this).val(); var allFoundCharacters = sectionToCheck.match(/[@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/g); if (allFoundCharacters ) { if ((allFoundCharacters.length > 1) && (($('#calculation_type').val() == 'surface') || ($('#calculation_type').val() == 'perimeter'))) { $.growl.error({ title:error, message: H_W }); } if ((allFoundCharacters.length > 2) && ($('#calculation_type').val() == 'volume')) { $.growl.error({ title:error, message: H_W_D }); } } }); function volume_example_set(){ if ($('#conversion').val() == '') $('#conversion').val(1); volume_units.forEach(checkUnitExists); volume_units.forEach(checkUnitExistsAttribute); if (passed == 0) $('#conversion_unit').val('m3'); if (passed_attr == 0) $('#attribute_unit').val('m3'); if ($('#minimum_height').val() == '') $('#minimum_height').val('0'); if ($('#maximum_height').val() == '') $('#maximum_height').val('9999'); if ($('#maximum_height_unit').val() == '') $('#maximum_height_unit').val('m'); if ($('#minimum_width').val() == '') $('#minimum_width').val('0'); if ($('#maximum_width').val() == '') $('#maximum_width').val('9999'); if ($('#maximum_width_unit').val() == '') $('#maximum_width_unit').val('m'); if ($('#minimum_depth').val() == '') $('#minimum_depth').val('0'); if ($('#maximum_depth').val() == '') $('#maximum_depth').val('9999'); if ($('#maximum_depth_unit').val() == '') $('#maximum_depth_unit').val('m'); if($('#display_quantity').val() == '') $('#display_quantity').val('decimalok'); if($('#step').val() == '') $('#step').val('0.1'); if($('#display_price').val() == '') $('#display_price').val('pricetotalprice'); if ($('#secconversion').val() == '') $('#secconversion').val('1'); if(volume_tip == false) { $.growl.notice({ title: quick_tip, message: volume_tip_message }); } return false; } function surface_example_set(){ if ($('#conversion').val() == '') $('#conversion').val(1); surface_units.forEach(checkUnitExists); surface_units.forEach(checkUnitExistsAttribute); if (passed == 0) $('#conversion_unit').val('m2'); if (passed_attr == 0) $('#attribute_unit').val('m2'); if ($('#minimum_height').val() == '') $('#minimum_height').val('0'); if ($('#maximum_height').val() == '') $('#maximum_height').val('9999'); if ($('#maximum_height_unit').val() == '') $('#maximum_height_unit').val('m'); if ($('#minimum_width').val() == '') $('#minimum_width').val('0'); if ($('#maximum_width').val() == '') $('#maximum_width').val('9999'); if ($('#maximum_width_unit').val() == '') $('#maximum_width_unit').val('m'); if($('#display_quantity').val() == '') $('#display_quantity').val('decimalok'); if($('#step').val() == '') $('#step').val('0.1'); if($('#display_price').val() == '') $('#display_price').val('pricetotalprice'); if ($('#secconversion').val() == '') $('#secconversion').val('1'); if(surface_tip == false) { $.growl.notice({ title: quick_tip, message: surface_tip_message }); } return false; } function linear_example_set(){ if ($('#conversion').val() == '') $('#conversion').val(1); linear_units.forEach(checkUnitExists); linear_units.forEach(checkUnitExistsAttribute); if (passed == 0) $('#conversion_unit').val('m'); if (passed_attr == 0) $('#attribute_unit').val('m'); if ($('#minimum_width').val() == '') $('#minimum_width').val('0'); if ($('#maximum_width').val() == '') $('#maximum_width').val('9999'); if ($('#maximum_width_unit').val() == '') $('#maximum_width_unit').val('m'); if($('#display_quantity').val() == '') $('#display_quantity').val('decimalok'); if($('#step').val() == '') $('#step').val('0.1'); if($('#display_price').val() == '') $('#display_price').val('pricetotalprice'); if ($('#secconversion').val() == '') $('#secconversion').val('1'); if(linear_tip == false) { $.growl.notice({ title: quick_tip, message: linear_tip_message }); } return false; } function perimeter_example_set(){ if ($('#conversion').val() == '') $('#conversion').val(1); perimeter_units.forEach(checkUnitExists); perimeter_units.forEach(checkUnitExistsAttribute); if (passed == 0) $('#conversion_unit').val('m'); if (passed_attr == 0) $('#attribute_unit').val('m'); if ($('#minimum_height').val() == '') $('#minimum_height').val('0'); if ($('#maximum_height').val() == '') $('#maximum_height').val('9999'); if ($('#maximum_height_unit').val() == '') $('#maximum_height_unit').val('m'); if ($('#minimum_width').val() == '') $('#minimum_width').val('0'); if ($('#maximum_width').val() == '') $('#maximum_width').val('9999'); if ($('#maximum_width_unit').val() == '') $('#maximum_width_unit').val('m'); if($('#display_quantity').val() == '') $('#display_quantity').val('decimalok'); if($('#step').val() == '') $('#step').val('0.1'); if($('#display_price').val() == '') $('#display_price').val('pricetotalprice'); if ($('#secconversion').val() == '') $('#secconversion').val('1'); if(perimeter_tip == false) { $.growl.notice({ title: quick_tip, message: perimeter_tip_message }); } return false; } function weight_example_set(){ if ($('#conversion').val() == '') $('#conversion').val(1); weight_units.forEach(checkUnitExists); weight_units.forEach(checkUnitExistsAttribute); if (passed == 0) $('#conversion_unit').val('kg'); if (passed_attr == 0) $('#attribute_unit').val('kg'); if ($('#minimum_weight').val() == '') $('#minimum_weight').val('0'); if ($('#maximum_weight').val() == '') $('#maximum_weight').val('10'); if ($('#maximum_weight_unit').val() == '') $('#maximum_weight_unit').val('kg'); if($('#display_quantity').val() == '') $('#display_quantity').val('decimalok'); if($('#step').val() == '') $('#step').val('0.1'); if($('#display_price').val() == '') $('#display_price').val('pricetotalprice'); if ($('#secconversion').val() == '') $('#secconversion').val('1'); if(weight_tip == false) { $.growl.notice({ title: quick_tip, message: weight_tip_message }); } return false; } function checkUnitExists(unit) { if (unit == $('#conversion_unit').val()) passed = passed + 1; } function checkUnitExistsAttribute(unit) { if (unit == $('#attribute_unit').val()) passed_attr = passed_attr + 1; }