﻿var calcType = 'd';
function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}
function FormatNumberBy3(num, decpoint, sep) {
  if (arguments.length == 2) {
    sep = ",";
  }
  if (arguments.length == 1) {
    sep = ",";
    decpoint = ".";
  }
  num = num.toString();
  a = num.split(decpoint);
  x = a[0]; // decimal
  y = a[1]; // fraction
  z = "";


  if (typeof(x) != "undefined") {
    for (i=x.length-1;i>=0;i--)
      z += x.charAt(i);
    z = z.replace(/(\d{3})/g, "$1" + sep);
    if (z.slice(-sep.length) == sep)
      z = z.slice(0, -sep.length);
    x = "";
    for (i=z.length-1;i>=0;i--)
      x += z.charAt(i);
    if (typeof(y) != "undefined" && y.length > 0)
      x += decpoint + y;
  }
  return x;
}
function restyle(e) {
	if (isNaN(e.value)) {
		e.className = 'entry';
	} else {
		e.className = 'entry entryBig';
	}
}
function calculate(ct,btnPush) {
	var d
	var m
	var y
	if (ct != window.calcType) window.calcType = ct;
	var htmlStr1 = "<table border=0 cellpadding=0 cellspacing=2 bgcolor='#009956'><tr><td colspan=2 class='resultTitle'>CONTRAST SAVINGS</td></tr><tr><td valign=top align=center>";
	if (window.calcType == 'd') { 
		htmlStr1 += "Diagnostic:<br><span class='savings'>39%";
	} else {
		htmlStr1 += "PCI &amp; Diag.:<br><span class='savings'>10%";
	}
	htmlStr1 += "</span></td><td align=right>";
	if (isNaN($('calcVal1').value) || isNaN($('calcVal2').value) || isNaN($('calcVal3').value)) {
		if (btnPush == 1) alert('You must enter numeric values in the three input fields.');
		return false;
	} else {
		d = $('calcVal1').value * $('calcVal2').value * $('calcVal3').value;
		if (window.calcType == 'd') {
			d = d * 0.39;
		} else {
			d = d * 0.1;
		}
		m = d * 22;
		y = m * 12;
		d = d.toFixed(0);
		d = FormatNumberBy3(d);
		m = m.toFixed(0);
		m = FormatNumberBy3(m);
		y = y.toFixed(0);
		y = FormatNumberBy3(y);
		htmlStr1 += "<b>"+d+"</b>" + " ml/day<br>" + "<b>"+m+"</b>" + " ml/mo.<br>" + "<b>"+y+"</b>" + " ml/yr.</td></tr>";
		if (window.calcType == 'd') {
			htmlStr1 += "<tr><td colspan=2 align=center><A href=\"javascript:calculate('p');\">Click here for PCI estimate</A></td></tr></table>";
			$('footerVar').innerHTML = '39';
		} else {
			htmlStr1 += "<tr><td colspan=2 align=center><A href=\"javascript:calculate('d');\">Click here for Diagnostic estimate</A></td></tr></table>";
			$('footerVar').innerHTML = '10';
		}
		$('result').innerHTML = htmlStr1;
		$('learnMore').style.display = 'block';
	}
}
function calcReset() {
	$('calcVal1').className = 'entry';
	$('calcVal2').className = 'entry';
	$('calcVal3').className = 'entry';
	$('result').innerHTML = '';
}