function ThousandSeparator(decimalDigits,Value) { // Separator Length. Here this is thousand separator var separatorLength = 3; var separatorChar = "."; var OriginalValue=Value; var TempValue = "" + OriginalValue; var NewValue = ""; // Store digits after decimal var pStr; // store digits before decimal var dStr; // Add decimal point if it is not there if (TempValue.indexOf(".")==-1){ TempValue+="." } dStr=TempValue.substr(0,TempValue.indexOf(".")); pStr=TempValue.substr(TempValue.indexOf(".")) // Add "0" for remaining digits after decimal point while (pStr.length-1< decimalDigits){pStr+="0"} if(pStr =='.') pStr =""; if(dStr.length > separatorLength) { // Logic of separation while( dStr.length > separatorLength) { NewValue = separatorChar + dStr.substr(dStr.length-separatorLength) + NewValue; dStr = dStr.substr(0,dStr.length-separatorLength); } NewValue = dStr + NewValue; } else { NewValue = dStr; } // Add decimal part NewValue = NewValue + pStr; // Show Final value //alert(NewValue); return NewValue; } function valInit() { jQuery( "#bandwidthSimulatorTime" ).val( 24 ); jQuery( "#bandwidthSimulatorDest" ).val( 4000 ); jQuery( "#bandwidthSimulatorSize" ).val( 4 ); jQuery( '#bandwidthKbpsValue' ).html( bandwidthCalc(4000, 5, 24) ); jQuery( '#bandwidthEuroValue' ).html( priceCalc(1) ); perDayCalc(1, 5); updateSliderHandleTitle(); jQuery( "#bandwidthResult2" ).after('
'); jQuery( "#bandwidthResult2v2" ).hide(); } function bandwidthCalc(n, s, t) { numDest = n; dimMsg = s; tempoRec = t; banda = (dimMsg*numDest*8)/(tempoRec*3600); bandaInt = (parseInt(banda/8))*8; // banda riservata ala cliente bandaCliente = 0; if(bandaInt < banda) bandaCliente = bandaInt + 8; else bandaCliente = bandaInt; return bandaCliente/8; } function priceCalc(b) { var euro = 336; if (b>=1 && b<2) { euro = 336; } if (b>=2 && b<3) { euro = 492; } if (b>=3 && b<4) { euro = 648; } if (b>=4 && b<5) { euro = 735; } if (b>=5 && b<8) { euro = 836; } if (b>=8 && b<10) { euro = 1113; } if (b>=10 && b<12) { euro = 1272; } if (b>=12 && b<19) { euro = 2046; } if (b>=19 && b<24) { euro = 2046; } if (b>=24 && b<38) { euro = 2498; } if (b>=38 && b<47) { euro = 3407; } if (b>=47 && b<58) { euro = 4154; } if (b>=58 && b<75) { euro = 4953; } if (b>=75) { euro = 0; } return euro; } function perDayCalc(b, s) { // Numero di email giornaliere bwHour = parseInt ((b*60*60)/(s) ); bwDay = bwHour * 24 ; bwWeek = bwDay * 7 ; bwMonth = bwDay * 30 ; bwYear = bwMonth * 12 ; jQuery('#bandwidthEmailHourValue').html(ThousandSeparator(0, bwHour)); jQuery('#bandwidthEmailDayValue').html(ThousandSeparator(0, bwDay)); jQuery('#bandwidthEmailMonthValue').html(ThousandSeparator(0, bwMonth)); jQuery('#bandwidthEmailYearValue').html(ThousandSeparator(0, bwYear)); } function updateSliderHandleTitle() { if(jQuery( "#bandwidthSimulatorDest" ).val()<2000 || jQuery( "#bandwidthSimulatorDest" ).val()>100000) { jQuery( "#bandwidthSlider1" ).find(".ui-slider-handle").attr("title", ""); } else { jQuery( "#bandwidthSlider1" ).find(".ui-slider-handle").attr("title", jQuery( "#bandwidthSimulatorDest" ).val() + " destinatari"); } if(jQuery( "#bandwidthSimulatorTime" ).val()<6 ) { jQuery( "#bandwidthSlider2" ).find(".ui-slider-handle").attr("title", ""); } else { jQuery( "#bandwidthSlider2" ).find(".ui-slider-handle").attr("title", jQuery( "#bandwidthSimulatorTime" ).val() + " ore"); } jQuery( "#bandwidthSlider3" ).find(".ui-slider-handle").attr("title", jQuery( "#bandwidthSimulatorSize" ).val() + " KB"); } jQuery(document).ready(function() { jQuery('#bandwidthSimulator').append(''); jQuery('#bandwidthSimulator').append(''); jQuery('#bandwidthSimulator').append(''); jQuery('#bandwidthSlider1').slider({ min: 1, value: 25, step: 25, range: "min", slide: function(event, ui) { if (ui.value<=14) { acv = 1000; } if ( ui.value >= 15 && ui.value <=40) { acv = 4000; } if ( ui.value >= 41 && ui.value <=60) { acv = 20000; } if ( ui.value >= 61 && ui.value <=80) { acv = 100000; } if (ui.value >= 81) { acv = 2000000; } jQuery( "#bandwidthSimulatorDest" ).val(acv ); jQuery( "#bandwidthKbpsValue" ).html(bandwidthCalc(jQuery( "#bandwidthSimulatorDest" ).val(),jQuery( "#bandwidthSimulatorSize" ).val(),jQuery( "#bandwidthSimulatorTime" ).val())); if ( priceCalc(jQuery( "#bandwidthKbpsValue" ).html()) > 0 ) { jQuery( ".bandwidth-result" ).css({'display': 'inline-block'}); jQuery( "#bandwidthResult2v2" ).css({'display': 'none'}); jQuery( "#bandwidthEuroValue" ).html(ThousandSeparator(0, priceCalc(jQuery( "#bandwidthKbpsValue" ).html()))); } else { jQuery( ".bandwidth-result" ).css({'display': 'none'}); jQuery( "#bandwidthResult2v2" ).css({'display': 'inline-block'}); } perDayCalc(jQuery( "#bandwidthKbpsValue" ).html(), jQuery( "#bandwidthSimulatorSize" ).val()); updateSliderHandleTitle(); } }); jQuery('#bandwidthSlider2').slider({ min: 1, value: 75, step: 25, range: "min", slide: function(event, ui) { if (ui.value<=14) { tmc = 0.0005; } if ( ui.value >= 15 && ui.value <=40) { tmc = 6; } if ( ui.value >= 41 && ui.value <=60) { tmc = 12; } if ( ui.value >= 61 && ui.value <=80) { tmc = 24; } if (ui.value >= 81) { tmc = 0.005; } jQuery( "#bandwidthSimulatorTime" ).val( tmc ); jQuery( "#bandwidthKbpsValue" ).html(bandwidthCalc(jQuery( "#bandwidthSimulatorDest" ).val(),jQuery( "#bandwidthSimulatorSize" ).val(),tmc)); if ( priceCalc(jQuery( "#bandwidthKbpsValue" ).html()) > 0 ) { jQuery( ".bandwidth-result" ).css({'display': 'inline-block'}); jQuery( "#bandwidthResult2v2" ).css({'display': 'none'}); jQuery( "#bandwidthEuroValue" ).html(ThousandSeparator(0, priceCalc(jQuery( "#bandwidthKbpsValue" ).html()))); } else { jQuery( ".bandwidth-result" ).css({'display': 'none'}); jQuery( "#bandwidthResult2v2" ).css({'display': 'inline-block'}); } perDayCalc(jQuery( "#bandwidthKbpsValue" ).html(), jQuery( "#bandwidthSimulatorSize" ).val()); updateSliderHandleTitle(); } }); jQuery('#bandwidthSlider3').slider({ min: 1, value: 1, step: 50, range: "min", slide: function(event, ui) { if (ui.value<=32) { wgt = 4; } if ( ui.value >= 33 && ui.value <=65) { wgt = 20; } if (ui.value >= 66) { wgt = 100; } jQuery( "#bandwidthSimulatorSize" ).val( wgt ); jQuery( "#bandwidthKbpsValue" ).html(bandwidthCalc(jQuery( "#bandwidthSimulatorDest" ).val(),wgt,jQuery( "#bandwidthSimulatorTime" ).val())); if ( priceCalc(jQuery( "#bandwidthKbpsValue" ).html()) > 0 ) { jQuery( ".bandwidth-result" ).css({'display': 'inline-block'}); jQuery( "#bandwidthResult2v2" ).css({'display': 'none'}); jQuery( "#bandwidthEuroValue" ).html(ThousandSeparator(0, priceCalc(jQuery( "#bandwidthKbpsValue" ).html()))); } else { jQuery( ".bandwidth-result" ).css({'display': 'none'}); jQuery( "#bandwidthResult2v2" ).css({'display': 'inline-block'}); } perDayCalc(jQuery( "#bandwidthKbpsValue" ).html(), jQuery( "#bandwidthSimulatorSize" ).val()); updateSliderHandleTitle(); } }); valInit(); });