Main menu

Calculators

Is your marketing delivering the results?

If your marketing works on the premise of Yes (they bought stuff) or No (they didn\'t), you could be missing all sorts of things your prospects are trying to tell you.

RELEASE; $document = &JFactory::getDocument(); if($curr_version=='2.5'){ $document->addStyleSheet('modules/mod_formula/fields/style.css'); } $document->addScript('modules/mod_formula/fields/calc.js'); $mid = $module->id; $fields = array(); $results = array(); $nr_of_fields = 12; for ($i = 1; $i <= $nr_of_fields; $i++) { $field = new stdClass(); $field->id = trim($params->get('field'.$i.'_id')); $field->label = trim($params->get('field'.$i.'_label')); $field->value = $params->get('field'.$i.'_value'); $field->tooltip = trim($params->get('field'.$i.'_tooltip')); $field->show = ($field->label != '') ? 1 : 0; $fields[] = $field; } $nr_of_results = 6; for ($i = 1; $i <= $nr_of_results; $i++) { if ($params->get('result'.$i.'_formula') != '') { $result = new stdClass(); $result->id = trim($params->get('result'.$i.'_id')); $result->label = trim($params->get('result'.$i.'_label')); $result->formula = str_replace( array(' ', 'abs', 'log', 'pow', 'sqrt', 'exp'), array('', 'Math.abs', 'Math.log', 'Math.pow', 'Math.sqrt', 'Math.exp'), $params->get('result'.$i.'_formula') ); $result->format = (int) $params->get('result'.$i.'_format', 1); $result->dec = (int) $params->get('result'.$i.'_dec', 2); $result->show = ($result->label != '') ? 1 : 0; $results[] = $result; } } $label_width = filter_var($params->get('label_width'), FILTER_SANITIZE_NUMBER_INT); $entry_width = filter_var($params->get('entry_width'), FILTER_SANITIZE_NUMBER_INT); $total_width = $label_width + $entry_width; $reset = $params->get('reset_show') ? $params->get('reset_text', 'Reset') : 0; $script = array(); $script[] = " function calcGetTotal_".$mid."(mid, pass) { rad = (1/180)*Math.PI; function sin(angle) { return Math.sin(angle*rad); } function cos(angle) { return Math.cos(angle*rad); } function tan(angle) { return Math.tan(angle*rad); } function asin(angle) { return Math.asin(angle*rad); } function acos(angle) { return Math.acos(angle*rad); } function atan(angle) { return Math.atan(angle*rad); } "; foreach ($fields as $field) { $script[] = " var ".$field->id." = parseFloat(document.getElementById('".$field->id."_'+mid).value); ".$field->id." = ".$field->id." ? ".$field->id." : 0; "; } foreach ($results as $result) { $script[] = " var ".$result->id." = parseFloat(document.getElementById('".$result->id."_'+mid).value); ".$result->id." = ".$result->id." ? ".$result->id." : 0; "; } foreach ($results as $result) { $f = 'parseFloat('.$result->formula.')'; switch ($result->format) { case 2: $math = 'addCommas(roundNumber('.$f.','.$result->dec.'),'.$result->dec.')'; break; case 3: $math = 'roundNumber(('.$f.'*100),'.$result->dec.')+"%"'; break; case 4: $math = '"$"+addCommas2(roundNumber('.$f.','.$result->dec.'),'.$result->dec.')'; break; default: $math = 'addCommas(Math.round('.$f.'))'; break; } $script[] = " ".$result->id." = parseFloat(".$math."); document.getElementById('".$result->id."_".$mid."').value = ".$math."; document.getElementById('".$result->id."_'+mid+'_output').innerHTML = ".$math."; "; } // do a second pass is to work around later results being used in formulas (ie result 3 used in formula of result 1) $script[] = " if (!pass) { calcGetTotal_".$mid."(mid, 1); } return true; } "; $document->addScriptDeclaration(preg_replace('#(\r?\n)?[ \t]+(\r?\n)#s', '\1', implode('', $script))); $css = " form#calc_".$mid." { width: ".($total_width + 40)."px; } form#calc_".$mid." .field { width: ".($total_width + 35)."px; } form#calc_".$mid." .field_label { width: ".($label_width)."px; } form#calc_".$mid." input { width: ".($entry_width)."px; } form#calc_".$mid." input[type=\"reset\"] { width: ".($total_width + 35)."px; } "; $document->addStyleDeclaration($css); ?>
id.'_'.$mid; ?>
class="input-prepend"class="field"show) ? '' : ' style="display:none;"'; ?> onmousemove="tooltip(this,event)" onmouseout="tooltipHide(this)" > label; ?>
label; ?>
tooltip ? '
'.$field->tooltip.'
' : ''; ?>
id.'_'.$mid; ?>
show) ? '' : ' style="display:none;"'; ?>> label.": "; ?>
class="btn btn-success"class="calculate" style=""onclick="calcGetTotal_(,1);">Calculate