/* =-=-=-=-=-=-=-=-=-=- */
/* Drop Down Menu Logic */
/* -=-=-=-=-=-=-=-=-=-= */
var ddtimeout		= 500;
var ddclosetimer	= 0;
var ddmenuitem		= 0;

var javascriptVariableConverter = "/sustainability/products/calculator/convert-javascript-variables-to-coldfusion.cfm";

function dropmenu_open() {
	dropmenu_canceltimer();
	dropmenu_close();
	ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
}

function dropmenu_close() {
	if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
}

function dropmenu_timer() {
	ddclosetimer = window.setTimeout(dropmenu_close, ddtimeout);
}

function dropmenu_canceltimer() {
	if (ddclosetimer) {
		window.clearTimeout(ddclosetimer);
		ddclosetimer = null;
	}
}


/* =-=-=-=-=-=-=-=-= */
/* Formula Functions */
/* -=-=-=-=-=-=-=-=- */
function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
	var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	return newnumber;
}

function convertToPercent(fraction) {
	fraction = (fraction * 100);
	
	if (fraction == 'Infinity') {
		fraction = '100';
	}
	
	return Math.round(fraction);
} 


function makePositive(nStr) {
	var nStr = nStr;
	var firstChar = nStr.charAt(0);
	
	if (firstChar == '-') {
		nStr = nStr.substr(1);
	}
	
	return nStr;

}

function displayNumber(nStr) {
	var nStrOrig = nStr;

	nStr = Math.abs(nStr);

	nStr = roundNumber(nStr, 0);

	if (nStr.toString().length > 11) {
		nStr = nStr / 1000000000;
		nStr = nStr.toFixed(0) + "B";
	} else if (nStr.toString().length > 10) {
		nStr = nStr / 1000000000;
		nStr = nStr.toFixed(1) + "B";
	} else if (nStr.toString().length > 9) {
		nStr = nStr / 1000000000;
		nStr = nStr.toFixed(2) + "B";
	} else if (nStr.toString().length > 8) {
		nStr = nStr / 1000000;
		nStr = nStr.toFixed(0) + "M";
	} else if (nStr.toString().length > 7) {
		nStr = nStr / 1000000;
		nStr = nStr.toFixed(1) + "M";
	} else if (nStr.toString().length > 6) {
		nStr = nStr / 1000000;
		nStr = nStr.toFixed(2) + "M";
	} else {
		nStr = addCommas(roundNumber(nStrOrig,2));
	}

	nStr = makePositive(nStr);
	
	return nStr;
}

function addCommas(nStr) {
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
/* When document is ready, fire everything off */
/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

var tab_one	= 0;
var tab_two	= 0;
var tab_three	= 0;
var tab_four	= 0;
var calc_summary_text 		= '';
var calc_percent_change_text 	= '';
var calc_percent_change = '';
var calc_percent_icon = '';
var calc_percent_impact = '';

$(document).ready(function() {
	// Setup the tabs
	$("#impact-calculations #impact-tabs").tabs({ selected: 1 } ).addClass('ui-tabs-vertical ui-helper-clearfix');
	
	// Setup the drop down menu
	$('#impact-learn-more > li').bind('mouseover', dropmenu_open);
	$('#impact-learn-more > li').bind('mouseout',  dropmenu_timer);


	// Setup the second carousel, which is shown by default
	$('#second-impact-carousel').jcarousel();
	tab_two = 1;
	
	// Setup the second, third and fourth carousel when the user clicks to view it
	$('#impact-tabs').bind('tabsshow', function(event, ui) {
		if (ui.panel.id == "tabs-energy-consumption" && tab_one == 0) {
			$('#first-impact-carousel').jcarousel();
			tab_one = 1;
		} else if (ui.panel.id == "tabs-air-acidification" && tab_three == 0) {
			$('#third-impact-carousel').jcarousel();
			tab_three = 1;
		} else if (ui.panel.id == "tabs-water-eutrophication" && tab_four ==0) {
			$('#fourth-impact-carousel').jcarousel();
			tab_four = 1;
		}
	});



	// Setup the formulas
	setupFormulas();
	
	
	// Set the icon area to blur when the input fields are changed
	$('#calculator #visual-representation div.impact-body div.left div.field input').bind('change', function () {
		$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "visible");
		$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "visible");
		
		if ($('#recalculate').hasClass('disabled')) {
			$('#recalculate').removeClass('disabled');
		}
	});
	
	// Remove the onclick action for the text fields only
	$('#current-design-name').unbind('change');
	$('#baseline-design-name').unbind('change');
	

	
	// Print friendly version
	$('#print-friendly-version-old').bind('click', printFriendly);
	
	// Automatically select the first formula
	$("#formula-19 a").triggerHandler("click");

	/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=- /
	/* Calculate Button 							*/
	/* this allows a user to click the calculate button	*/
	/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=- */
	$('#recalculate').bind('click', resetFormulas);

	/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
	/* Enter Keyboard Actions						*/
	/* this simulates the above calculate button action.	*/
	/* if a user user presses the enter key on their		*/ 
	/* keyboard all values get reset.					*/
	/* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
	$('#current-design-name').keypress(function (keyID) {
		if (keyID.which == 13) {
			resetFormulas();
			$('#current-design-name').unbind('change');
		}
	});
	$('#current-design-value').keypress(function (keyID) { 
		if (keyID.which == 13) {
			$('#calculator #visual-representation div.impact-body div.left div.field input').unbind('change').bind('change', function () {
				$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "hidden");
				$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "hidden");
				if ($('#recalculate').hasClass('disabled')) {
					$('#recalculate').removeClass('disabled');
				}
			});
			resetFormulas();
		} else {
			$('#calculator #visual-representation div.impact-body div.left div.field input').unbind('change').bind('change', function () {
				$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "visible");
				$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "visible");
				if ($('#recalculate').hasClass('disabled')) {
					$('#recalculate').removeClass('disabled');
				}
			});
		}
	});
	
	$('#current-design-quantity').keypress (function (keyID) {
		if (keyID.which == 13) {
			$('#calculator #visual-representation div.impact-body div.left div.field input').unbind('change').bind('change', function () {
				$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "hidden");
				$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "hidden");
				if ($('#recalculate').hasClass('disabled')) {
					$('#recalculate').removeClass('disabled');
				}
			});
			resetFormulas();
		} else {
			$('#calculator #visual-representation div.impact-body div.left div.field input').unbind('change').bind('change', function () {
				$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "visible");
				$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "visible");
				if ($('#recalculate').hasClass('disabled')) {
					$('#recalculate').removeClass('disabled');
				}
			});
		}
	});
	$('#baseline-design-name').keypress (function (keyID) {
		if (keyID.which == 13) {
			resetFormulas();
		}
	});
	$('#baseline-design-value').keypress (function (keyID) {
		if (keyID.which == 13) {
			$('#calculator #visual-representation div.impact-body div.left div.field input').unbind('change').bind('change', function () {
				$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "hidden");
				$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "hidden");
				if ($('#recalculate').hasClass('disabled')) {
					$('#recalculate').removeClass('disabled');
				}
			});
			resetFormulas();
		} else {
			$('#calculator #visual-representation div.impact-body div.left div.field input').unbind('change').bind('change', function () {
				$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "visible");
				$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "visible");
				if ($('#recalculate').hasClass('disabled')) {
					$('#recalculate').removeClass('disabled');
				}
			});
		}
	});
	$('#baseline-design-quantity').keypress (function (keyID) {
		if (keyID.which == 13) {
			$('#calculator #visual-representation div.impact-body div.left div.field input').unbind('change').bind('change', function () {
				$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "hidden");
				$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "hidden");
				if ($('#recalculate').hasClass('disabled')) {
					$('#recalculate').removeClass('disabled');
				}
			});
			resetFormulas();
		} else {
			$('#calculator #visual-representation div.impact-body div.left div.field input').unbind('change').bind('change', function () {
				$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "visible");
				$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "visible");
				if ($('#recalculate').hasClass('disabled')) {
					$('#recalculate').removeClass('disabled');
				}
			});
		}
	});
	
	/* Original code, before above nightmare occurred 
	
	$('#current-design-name').keypress(function (e) { if (e.which == 13) { resetFormulas(); } });
	$('#current-design-value').keypress(function (e) { if (e.which == 13) { resetFormulas(); } });
	$('#current-design-quantity').keypress(function (e) { if (e.which == 13) { resetFormulas(); } });
	$('#baseline-design-name').keypress(function (e) { if (e.which == 13) { resetFormulas(); } });
	$('#baseline-design-value').keypress(function (e) { if (e.which == 13) { resetFormulas(); } });
	$('#baseline-design-quantity').keypress(function (e) { if (e.which == 13) { resetFormulas(); } });
	*/
	
});

function printFriendly() {
	$('#impact-header').css('display', 'none');
	$('#bannerImage').css('display', 'none');
	$('#impact-breadcrumb').css('display', 'none');
	$('#impact-footer').css('display', 'none');
	$('#wrap').css('background-image', 'none');
	$('#container').css('background-image', 'none');
	$('impact-body').css('background-image', 'none');
	
	return false;
}

function determineCategoryID(this_category) {
	if (this_category == "Energy Consumption") {
		var this_category_id = 1;
	} else if (this_category == "Carbon Footprint") {
		var this_category_id = 2;
	} else if (this_category == "Air Acidification") {
		var this_category_id = 3;
	} else if (this_category == "Water Eutrophication") {
		var this_category_id = 4;
	}
	
	return this_category_id;
}

// Formula click actions
function showFormula (event, ui) {
	
	// Establish the "Formula ID"
	thisID = $(this).parent().get(0).id;
	formulaID = $(this).parent().get(0).id.split("-")[1];
	
	// Bring the formula data variables into the local scope for ease of use
	var this_category = swsc_category[formulaID];
	var this_description_long = swsc_description_long[formulaID];
	var this_description_short = swsc_description_short[formulaID];
	var this_icon = swsc_icon[formulaID];
	var this_current_result = swsc_current_result[formulaID] * 1;
	var this_baseline_result = swsc_baseline_result[formulaID] * 1;
	var this_conversion_pre = swsc_conversion_pre[formulaID];
	var this_conversion_post = swsc_conversion_post[formulaID];

	// Determine the "Category ID"
	var this_category_id = determineCategoryID(this_category);
	
	// Bring the current/baseline data variables, for this category, into the local scope
	var this_swsc_baseline_design_name = swsc_baseline_design_name[this_category_id];
	var this_swsc_baseline_design_value = swsc_baseline_design_value[this_category_id];
	var this_swsc_baseline_design_quantity = swsc_baseline_design_quantity[this_category_id];
	var this_swsc_current_design_name = swsc_current_design_name[this_category_id];
	var this_swsc_current_design_value = swsc_current_design_value[this_category_id];
	var this_swsc_current_design_quantity = swsc_current_design_quantity[this_category_id];
	
	
	$.get(javascriptVariableConverter, {
		 	formula_id: formulaID,
		 	category_name: this_category,
			category_long_description: this_description_long
		} 
		
	);
	
	// Change the background color of ALL of the formulas to transparent	
	$('#calculator #impact-calculations #impact-tabs .jcarousel-skin-solidworks .jcarousel-item a').each(function (i) {
		if ($(this).hasClass("selected")) {
			$(this).removeClass("selected");
		}
	});

	// Change the background color so it appears selected
	$('#'+thisID + ' a').addClass("selected");
	
	// Change the formula title
	$('#calculator #visual-representation div.impact-header h1').html(this_category + ": <strong>" + this_description_long + "</strong>");
	if ((this_category + ': ' + this_description_long).length > 80) {
		$('#calculator #visual-representation div.impact-header h1').css('font-size', '10px');
	} else {
		$('#calculator #visual-representation div.impact-header h1').css('font-size', '11px');
	}

	$('#calculator #visual-representation div.impact-header h1').html(this_category + ": <strong>" + this_description_long + "</strong>");
	if ((this_category + ': ' + this_description_long).length > 80) {
		$('#calculator #visual-representation div.impact-header h1').css('font-size', '10px');
	} else {
		$('#calculator #visual-representation div.impact-header h1').css('font-size', '11px');
	}


	/* -=-=-=-=-=-=-=-=-=-=-=-= */
	/* Set Current Form Values	*/
	/* -=-=-=-=-=-=-=-=-=-=-=-= */
	if ((default_state == 1 || default_state == 2 || default_state == 3) && (this_swsc_current_design_name.length == 0 || this_swsc_current_design_name == 'File Name')) {
		$('#calculator #visual-representation #current-design-name').css('color', '#828487');
		$('#current-design-name').val("File Name");
	} else {		
		$('#calculator #visual-representation #current-design-name').css('color', '#000000');
		$('#current-design-name').val(this_swsc_current_design_name);
	}
		
	if ((default_state == 1 || default_state == 2 || default_state == 3) && this_swsc_current_design_value == 0) {
		$('#calculator #visual-representation #current-design-value').css('color', '#828487');
		$('#current-design-value').val("Impact Value");
	} else {
		$('#calculator #visual-representation #current-design-value').css('color', '#000000');
		$('#current-design-value').val(this_swsc_current_design_value);
	}
	
	if ((default_state == 1 || default_state == 2 || default_state == 3) && (this_swsc_current_design_value == 0 || this_swsc_current_design_quantity == 0)) {		
		$('#calculator #visual-representation #current-design-quantity').css('color', '#828487');
		$('#current-design-quantity').val("1");
	} else {
		$('#calculator #visual-representation #current-design-quantity').css('color', '#000000');
		$('#current-design-quantity').val(this_swsc_current_design_quantity);
	}

	if (default_state == 2) {
		$('#calculator #visual-representation div.impact-body div.left div.current div.field input').css('color', '#828487');
		//$('#current-design-name').val("File Name");
		$('#current-design-value').val("Impact Value");
		$('#current-design-quantity').val("1");
	} 
	
	if (default_state == 4) {
		$('#calculator #visual-representation div.impact-body div.left div.current div.field input').css('color', '#000000');
		$('#current-design-name').val(this_swsc_current_design_name);
		$('#current-design-value').val(this_swsc_current_design_value);
		$('#current-design-quantity').val(this_swsc_current_design_quantity);
	}
	
	
	/* -=-=-=-=-=-=-=-=-=-=-=-= */
	/* Set Baseline Form Values	*/
	/* -=-=-=-=-=-=-=-=-=-=-=-= */
	if ((default_state == 1 || default_state == 2 || default_state == 4) && (this_swsc_baseline_design_name.length == 0 || this_swsc_baseline_design_name == 'File Name')) {	
		$('#calculator #visual-representation #baseline-design-name').css('color', '#828487');
		$('#baseline-design-name').val("File Name");
	} else {
		$('#calculator #visual-representation #baseline-design-name').css('color', '#000000');
		$('#baseline-design-name').val(this_swsc_baseline_design_name);
	}
		
	if ((default_state == 1 || default_state == 2 || default_state == 4) && this_swsc_baseline_design_value == 0) {
		$('#calculator #visual-representation #baseline-design-value').css('color', '#828487');
		$('#baseline-design-value').val("Impact Value");
	} else {
		$('#calculator #visual-representation #baseline-design-value').css('color', '#000000');
		$('#baseline-design-value').val(this_swsc_baseline_design_value);
	}
	
	if ((default_state == 1 || default_state == 2 || default_state == 4) && (this_swsc_baseline_design_value == 0 || this_swsc_baseline_design_quantity == 0)) {
		$('#calculator #visual-representation #baseline-design-quantity').css('color', '#828487');
		$('#baseline-design-quantity').val("1");
	} else {
		$('#calculator #visual-representation #baseline-design-quantity').css('color', '#000000');
		$('#baseline-design-quantity').val(this_swsc_baseline_design_quantity);
	}

	if (default_state == 2) {
		$('#calculator #visual-representation div.impact-body div.left div.baseline div.field input').css('color', '#828487');
		$('#baseline-design-name').val("File Name");
		$('#baseline-design-value').val("Impact Value");
		$('#baseline-design-quantity').val("1");
	} 

	if (default_state == 3) {
		$('#calculator #visual-representation div.impact-body div.left div.baseline div.field input').css('color', '#000000');
		$('#baseline-design-name').val(this_swsc_baseline_design_name);
		$('#baseline-design-value').val(this_swsc_baseline_design_value);
		$('#baseline-design-quantity').val(this_swsc_baseline_design_quantity);
	}


	// Current Values: Bind click event to remove default value (and change color to black) if something is there
	$('#current-design-name').unbind('click').bind('click', function() { $('#recalculate').removeClass('disabled'); if($('#current-design-name').val() == 'File Name') { $('#current-design-name').css('color', '#000000'); $('#current-design-name').val(''); } });
	$('#current-design-value').unbind('click').bind('click', function() { $('#recalculate').removeClass('disabled'); if($('#current-design-value').val() == 'Impact Value') { $('#current-design-value').css('color', '#000000'); $('#current-design-value').val(''); } });
	$('#current-design-quantity').unbind('click').bind('click', function() { $('#recalculate').removeClass('disabled'); if($('#current-design-quantity').val() == '1') { $('#current-design-quantity').css('color', '#000000'); $('#current-design-quantity').val(''); } });
	
	// Current Values: Bind blur event to re-add default value (and change color to gray) if nothing is there
	$('#current-design-name').unbind('blur').bind('blur', function() { if($('#current-design-name').val() == '') { $('#current-design-name').val('File Name'); $('#current-design-name').css('color', '#828487'); $('#recalculate').addClass('disabled'); } });
	$('#current-design-value').unbind('blur').bind('blur', function() { if($('#current-design-value').val() == '' || $('#current-design-value').val() == 0) { $('#current-design-value').css('color', '#828487'); $('#current-design-value').val('Impact Value'); } });
	$('#cur rent-design-quantity').unbind('blur').bind('blur', function() { if($('#current-design-quantity').val() == '') { $('#current-design-quantity').val('1'); $('#current-design-quantity').css('color', '#828487'); $('#recalculate').addClass('disabled'); } });

	// Baseline Values: Bind click event to remove default value (and change color to black) if something is there
	$('#baseline-design-name').unbind('click').bind('click', function() { $('#recalculate').removeClass('disabled'); if($('#baseline-design-name').val() == 'File Name') { $('#baseline-design-name').css('color', '#000000'); $('#baseline-design-name').val(''); } });
	$('#baseline-design-value').unbind('click').bind('click', function() { $('#recalculate').removeClass('disabled'); if($('#baseline-design-value').val() == 'Impact Value') { $('#baseline-design-value').css('color', '#000000'); $('#baseline-design-value').val(''); } });
	$('#baseline-design-quantity').unbind('click').bind('click', function() { $('#recalculate').removeClass('disabled'); if($('#baseline-design-quantity').val() == '1') { $('#baseline-design-quantity').css('color', '#000000'); $('#baseline-design-quantity').val(''); } });
	
	// Baseline Values: Bind blur event to re-add default value (and change color to gray) if nothing is there
	$('#baseline-design-name').unbind('blur').bind('blur', function() { if($('#baseline-design-name').val() == '') { $('#baseline-design-name').val('File Name'); $('#baseline-design-name').css('color', '#828487'); $('#recalculate').addClass('disabled'); } });
	$('#baseline-design-value').unbind('blur').bind('blur', function() { if($('#baseline-design-value').val() == '') { $('#baseline-design-value').val('Impact Value'); $('#baseline-design-value').css('color', '#828487'); $('#recalculate').addClass('disabled'); } });
	$('#baseline-design-quantity').unbind('blur').bind('blur', function() { if($('#baseline-design-quantity').val() == '') { $('#baseline-design-quantity').val('1'); $('#baseline-design-quantity').css('color', '#828487'); $('#recalculate').addClass('disabled'); } });

	/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
	/* Set Value Units Based On Category	*/
	/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
	if (this_category == "Energy Consumption") {
		value_units = "MJ";
	} else if (this_category == "Carbon Footprint") {
		value_units = "kg CO<sub>2</sub>";
	} else if (this_category == "Air Acidification") {
		value_units = "kg SO<sub>2</sub>";
	} else if (this_category == "Water Eutrophication") {
		value_units = "kg PO<sub>4</sub>";
	} else {
		value_units = "";
	}

	$.get(javascriptVariableConverter, { category_id: this_category_id } );
	
	
	//category_units: value_units/
	$('#calculator #visual-representation div.impact-body div.left div.field span').html(value_units);



	// determine the actual change and the percentage change
	//alert(this_current_result + " - " + this_baseline_result);
	change_actual = this_current_result - this_baseline_result;
	change_actual = Math.round(change_actual*1000)/1000;
	change_percent = (convertToPercent(change_actual/this_baseline_result)).toString();
	change_percent = Math.abs(change_percent);
	
	// determine key definition
	var half_powers_ten = new Array(0.5, 1, 5, 10, 50, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000, 1000000, 5000000, 10000000, 50000000, 100000000, 500000000, 1000000000, 5000000000, 10000000000, 50000000000, 100000000000, 500000000000);
	var compare_value;
	var max_value = 0;
	var isDone = 0;
	var key = "";
	
	// determine if current or baseline is higher
	if (this_current_result > this_baseline_result) {
		compare_value = this_current_result;
	} else if (this_baseline_result > this_current_result) {
		compare_value = this_baseline_result;
	} else { // they are the same
		compare_value = this_baseline_result;
	}
	
	// figure out the half power of ten that is next highest
	jQuery.each(half_powers_ten, function(index, value) {
		if ((compare_value <= value) && isDone == 0) {
			isDone = 1;
			key = value / 10;
			max_value = value;
		}
	});
	
	
	
	/* -=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
	/* Change Current Totals								*/
	/* This logic determines the value that will be displayed 	*/
	/* on the right side of the Current Design row.			*/
	/* -=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
	if (default_state == 3 || default_state == 2 || this_swsc_current_design_value == 0) {

		current_design_result = "";
		$('#current-design-total').css("font-size", "14px");
		$('#current-design-total').html(current_design_result);
		
	// if no display number is "0" or display number is so small no icons will show set display value to Negligible
	} else if (displayNumber(this_current_result) == 0 || Math.round((this_current_result / max_value) * 500) <= 0) {
		
		current_design_result = "Negligible";
		$('#current-design-total').css("font-size", "12px");
		$('#current-design-total').html(current_design_result);

	} else {
		
		current_design_result = displayNumber(this_current_result);
		$('#current-design-total').css("font-size", "14px");
		$('#current-design-total').html(current_design_result);
		
	}

	current_design_user_input_name = $('#current-design-name').val();
	current_design_user_input_value = $('#current-design-value').val() + " <sup>" + value_units + "</sup>";				 
	current_design_user_input_quantity = $('#current-design-quantity').val();

	/* -=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
	/* Change Baseline Totals							*/
	/* This logic determines the value that will be displayed 	*/
	/* on the right side of the Baseline Design row.			*/
	/* -=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */

	if (default_state == 4 || default_state == 2 || this_swsc_baseline_design_value == 0) {
		
		// set total value and font size
		baseline_design_result = "";
		$('#baseline-design-total').css("font-size", "14px");
		$('#baseline-design-total').html(baseline_design_result);
		
	// if no display number is "0" or display number is so small no icons will show set display value to Negligible
	} else if (displayNumber(this_baseline_result) == 0 || Math.round((this_baseline_result / max_value) * 500) <= 0) {
		
		// set total value and font size
		baseline_design_result = "Negligible";
		$('#baseline-design-total').css("font-size", "12px");
		$('#baseline-design-total').html(baseline_design_result);

	} else {

		// set total value and font size
		baseline_design_result = displayNumber(this_baseline_result);
		$('#baseline-design-total').css("font-size", "14px");
		$('#baseline-design-total').html(baseline_design_result);
	
	}
	
	baseline_design_user_input_name = $('#baseline-design-name').val();
	baseline_design_user_input_value = $('#baseline-design-value').val() + " <sup>" + value_units + "</sup>";				 
	baseline_design_user_input_quantity = $('#baseline-design-quantity').val();
	

	
	
	// convert current and baseline total javascript variables to coldfusion client variables
	$.get(javascriptVariableConverter, { 
		 
		current_design_user_input_name: $('#current-design-name').val(),
		current_design_user_input_value: $('#current-design-value').val() + " <sup>" + value_units + "</sup>",			 
		current_design_user_input_quantity: $('#current-design-quantity').val(),
		current_design_result: current_design_result,
		baseline_design_user_input_name: $('#baseline-design-name').val(),
		baseline_design_user_input_value: $('#baseline-design-value').val() + " <sup>" + value_units + "</sup>",				 
		baseline_design_user_input_quantity: $('#baseline-design-quantity').val(),
		baseline_design_result: baseline_design_result

  	} );
	
	/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
	/* Set Current Design Row Background Image and CSS	*/
	/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
	var current_design_icon_width = 0;
	if (default_state == 2 || this_swsc_current_design_value == 0) { 
		current_design_icon = '';
		current_design_icon_width = 489;
		$('#calculator #visual-representation div.impact-body div.right div.current div.container div.icons').css("background-image", "url('/includes/sustainability/calculator/img/calculator/bg-visual-representation-icons-current-no-value.png')");
		$('#calculator #visual-representation div.impact-body div.right div.current div.icons').css("width", current_design_icon_width + "px");
		$('#calculator #visual-representation div.impact-body div.right div.current').css("padding-top", "17px");
		$('#calculator #visual-representation div.impact-body div.right div.current').css("height", "84px");
	} else if (this_current_result == 0 && default_state != 1) {
		current_design_icon = this_icon;
		current_design_icon_width = 0;
		$('#calculator #visual-representation div.impact-body div.right div.current div.container div.icons').css("background-image", "url('/includes/sustainability/calculator/img/calculator/icons/" + this_icon + "')");
		$('#calculator #visual-representation div.impact-body div.right div.current div.icons').css("width", current_design_icon_width + "px");
		$('#calculator #visual-representation div.impact-body div.right div.current').css("padding-top", "33px");
		$('#calculator #visual-representation div.impact-body div.right div.current').css("height", "68px");
		baseline_icon_width = 0;
	} else {
		current_design_icon = this_icon;
		current_design_icon_width = ((this_current_result / max_value) * 500);
		$('#calculator #visual-representation div.impact-body div.right div.current div.container div.icons').css("background-image", "url('/includes/sustainability/calculator/img/calculator/icons/" + this_icon + "')");
		$('#calculator #visual-representation div.impact-body div.right div.current div.icons').css("width", current_design_icon_width + "px");
		$('#calculator #visual-representation div.impact-body div.right div.current').css("padding-top", "33px");
		$('#calculator #visual-representation div.impact-body div.right div.current').css("height", "68px");	
	}

	/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
	/* Set Baseline Design Row Background Image and CSS	*/
	/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
	var baseline_design_icon_width = 0;
	if (default_state == 2 || this_swsc_baseline_design_value == 0) {
		baseline_design_icon_width = 489;
		$('#calculator #visual-representation div.impact-body div.right div.baseline div.icons').css("background-image", "url('/includes/sustainability/calculator/img/calculator/bg-visual-representation-icons-baseline-no-value.png')");
		$('#calculator #visual-representation div.impact-body div.right div.baseline div.icons').css("width", baseline_design_icon_width + "px");
		$('#calculator #visual-representation div.impact-body div.right div.baseline').css("padding-top", "17px");
		$('#calculator #visual-representation div.impact-body div.right div.baseline').css("height", "84px");
	} else if (this_baseline_result == 0) {
		baseline_design_icon_width = 0;
		$('#calculator #visual-representation div.impact-body div.right div.baseline div.icons').css("background-image", "url('/includes/sustainability/calculator/img/calculator/icons/" + this_icon + "')");
		$('#calculator #visual-representation div.impact-body div.right div.baseline div.icons').css("width", baseline_design_icon_width + "px");
		$('#calculator #visual-representation div.impact-body div.right div.baseline').css("padding-top", "33px");
		$('#calculator #visual-representation div.impact-body div.right div.baseline').css("height", "68px");
	} else {
		baseline_design_icon_width = ((this_baseline_result / max_value) * 500);
		$('#calculator #visual-representation div.impact-body div.right div.baseline div.icons').css("background-image", "url('/includes/sustainability/calculator/img/calculator/icons/" + this_icon + "')");
		$('#calculator #visual-representation div.impact-body div.right div.baseline div.icons').css("width", baseline_design_icon_width + "px");
		$('#calculator #visual-representation div.impact-body div.right div.baseline').css("padding-top", "33px");
		$('#calculator #visual-representation div.impact-body div.right div.baseline').css("height", "68px");
	}

	// convert javascript variables to coldfusion client variables
	$.get(javascriptVariableConverter, { 
		 
		current_design_icon_width: current_design_icon_width, 
		baseline_design_icon_width: baseline_design_icon_width 
	
	} );
	
	/* -=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= */
	/* Change Key Icon, Key Measurement and Key Description						*/
	/* This logic determines whether or not to display the key icon and if so which one.	*/ 
	/* The key icon is located in the middle of the row under the Baseline Design row.	*/
	/* -=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=	*/
	calc_key_value = key;	
	calc_key_value_formatted = displayNumber(calc_key_value);
	calc_key_text = this_description_short;
	
	$('#calculator #visual-representation div.impact-footer div#key').html("= " + calc_key_value_formatted + " " + calc_key_text);
	
	$.get(javascriptVariableConverter, { category_key_icon: this_icon, category_key_value: calc_key_value, category_key_value_formatted: calc_key_value_formatted, category_key_text: calc_key_text } );
	
	 if (default_state == 2) {
		 
		// when no values are available hide key icon
		$('#calculator #visual-representation div.impact-footer div#key').css("visibility", "hidden");

	} else {

		// at least one set of values either current or baseline are available show icon
		// the icon used is determined by the values set calculator_vars.js
		$('#calculator #visual-representation div.impact-footer div#key').css("visibility", "visible");
		$('#calculator #visual-representation div.impact-footer div#key').css("background-image", "url('/includes/sustainability/calculator/img/calculator/icons/small/" + this_icon + "')");
	
	}

	/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
	/* Set Percent Change Text, Number, Image and Summary Paragraph	*/
	/* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
	calc_percent_change = change_percent;
	
	if ((default_state == 1 && this_swsc_current_design_value == 0 && this_swsc_baseline_design_value > 0) || default_state == 3) { 
		
		// hide the percentage increase/decrease arrow
		$('#percent-change strong').css("visibility", "hidden");

		// set and display blank percentage area
		$('#percent-change p').css("padding-right", "10px");
		$('#percent-change p').html(calc_percent_change_text);
		
		// set baseline design only summary - NO COMPARISON
		calc_summary_text = "The baseline design will contribute " + displayNumber($('#baseline-design-value').val() * $('#baseline-design-quantity').val()) + 
						" " + value_units + " towards " + this_category + "." + " This is the equivalent of " + 
						this_conversion_pre.toLowerCase() + " " + displayNumber(change_actual) + " " + this_conversion_post + ".";
		
		// show summary text
		$('#summary div.impact-body div.summary-text blockquote p').html(calc_summary_text);

		// convert javascript variables to coldfusion client variables
		$.get(javascriptVariableConverter, { summary_text: calc_summary_text, percent_change_text: calc_percent_change_text, percent_change: calc_percent_change} );

	} else if ((default_state == 1 && this_swsc_current_design_value > 0 && this_swsc_baseline_design_value == 0) || default_state == 4) {
		
		// hide the percentage increase/decrease arrow
		$('#percent-change strong').css("visibility", "hidden");
		
		// set and display blank percentage area
		$('#percent-change p').css("padding-right", "10px");
		$('#percent-change p').html("");

		// set current design only summary - NO COMPARISON
		calc_summary_text = "The current design will contributed " + displayNumber($('#current-design-value').val() * $('#current-design-quantity').val()) + " " + 
					value_units + " towards " + this_category + ". This is the equivalent of " + this_conversion_pre.toLowerCase() + " " + 
					displayNumber(change_actual) + " " + this_conversion_post + ".";
		
		// show summary text
		$('#summary div.impact-body div.summary-text blockquote p').html(calc_summary_text);

		// convert javascript variables to coldfusion client variables
		$.get(javascriptVariableConverter, { summary_text: calc_summary_text, percent_change_text: calc_percent_change_text, percent_change: calc_percent_change} );

	} else if (default_state == 2 || (this_swsc_current_design_value == 0 && this_swsc_baseline_design_value == 0)) { 

		// hide the percentage increase/decrease arrow
		$('#percent-change strong').css("visibility", "hidden"); 

		// set and display blank percentage area
		$('#percent-change p').css("padding-right", "10px");
		$('#percent-change p').html("");
		
		// set default summary - BLANK FORM
		calc_summary_text = "Enter Values and Quantity to calculate conversions.";
		
		// show summary text
		$('#summary div.impact-body div.summary-text blockquote p').html(calc_summary_text);

		// convert javascript variables to coldfusion client variables
		$.get(javascriptVariableConverter, { summary_text: calc_summary_text, percent_change_text: calc_percent_change_text, percent_change: calc_percent_change} );
		
	} else if (change_actual > 0) { // this means the current design value is greater than the baseline design value

		$('#percent-change strong').css("visibility", "visible");
		$('#percent-change strong').css("background-image", "url('/includes/sustainability/calculator/img/calculator/bg-visual-representations-percent-change-increase.png')");

		// set percentage text and number
		calc_percent_change_text = "Worsened impact by <em>" + displayNumber(change_actual) + "</em> " + this_description_short;
		$('#percent-change p').css("padding-right", "55px");
		
		// show percentage text and number
		$('#percent-change p').html(calc_percent_change_text);
		
		// determine and set which percentage text size to use to prevent overflow
		if (("Worsened impact by " + displayNumber(change_actual) + " " + this_description_short).length > 65) {
			$('#percent-change p').css('font-size', '10px');
		} else {
			$('#percent-change p').css('font-size', '13px');
		}

		// set current design and baseline design summary paragraph - WITH COMPARISON
		calc_summary_text = "The current design will contribute " + displayNumber($('#current-design-value').val() * $('#current-design-quantity').val()) + " " + 
						value_units + " towards " + this_category + "." + " The baseline design will contribute " + 
						displayNumber($('#baseline-design-value').val() * $('#baseline-design-quantity').val()) + " " + value_units + "." + 
						" The current design will increase " + change_percent + "% of the impact," + " which is worsening the impact by the equivalent of " + 
						this_conversion_pre + " " + displayNumber(change_actual) + " " + this_conversion_post + ".";
		
		// show summary text
		$('#summary div.impact-body div.summary-text blockquote p').html(calc_summary_text);

		// convert javascript variables to coldfusion client variables
		$.get(javascriptVariableConverter, { summary_text: calc_summary_text, percent_change_text: calc_percent_change_text, percent_change: calc_percent_change, percent_change_impact: 'increase'} );
		
	} else if (change_actual < 0) { //  this means the baseline design value is greater than the current design value

		// show decrease arrow
		$('#percent-change strong').css("visibility", "visible");
		$('#percent-change strong').css("background-image", "url('/includes/sustainability/calculator/img/calculator/bg-visual-representations-percent-change-decrease.png')");
		
		// show percentage text and number 
		calc_percent_change_text = "Saved the equivalent of <em>" + displayNumber(change_actual) + "</em> " + this_description_short;
		$('#percent-change p').css("padding-right", "55px");
		$('#percent-change p').html(calc_percent_change_text);
		
		// determine which percentage text size to use to prevent overflow
		if (("Saved the equivalent of " + displayNumber(change_actual) + " " + this_description_short).length > 65) {
			$('#percent-change p').css('font-size', '11px');
		} else {
			$('#percent-change p').css('font-size', '13px');
		}
			
		// show summary paragraph - WITH COMPARISON
		calc_summary_text = "The current design will contribute " + displayNumber($('#current-design-value').val() * $('#current-design-quantity').val()) + " " + 
						value_units + " towards " + this_category + "." + " The baseline design will contribute " + 
						displayNumber($('#baseline-design-value').val() * $('#baseline-design-quantity').val()) + " " + value_units + "." + 
						" The current design will reduce " + change_percent + "% of the impact," + " which is saving the equivalent of " + this_conversion_pre + " " + 
						displayNumber(change_actual) + " " + this_conversion_post + ".";
			
		// show summary text
		$('#summary div.impact-body div.summary-text blockquote p').html(calc_summary_text); 

		// convert javascript variables to coldfusion client variables
		$.get(javascriptVariableConverter, { summary_text: calc_summary_text, percent_change_text: calc_percent_change_text, percent_change: calc_percent_change, percent_change_impact: 'decrease' } );
		
	} else if (this_current_result == 0 && this_baseline_result == 0) {
	
		// set the increase/decrease arrow to hidden. 
		$('#percent-change strong').css("visibility", "hidden"); 
	
		// set and display blank percentage area
		$('#percent-change p').css("padding-right", "10px");
		$('#percent-change p').html(calc_percent_change_text);

		// set summary paragraph - WITH COMPARISON
		calc_summary_text = "The current design will contribute " + displayNumber($('#current-design-value').val() * $('#current-design-quantity').val()) + " " + 
						value_units + " towards " + this_category + "." +  " The baseline design will contribute " + 
						displayNumber($('#baseline-design-value').val() * $('#baseline-design-quantity').val()) + " " + value_units + "." + 
						" There is a negligible difference between the current and baseline designs in the form " + " of " + this_conversion_pre + " " + 
						this_conversion_post + ".";

		// show summary text
		$('#summary div.impact-body div.summary-text blockquote p').html(calc_summary_text);

		// convert javascript variables to coldfusion client variables
		$.get(javascriptVariableConverter, { summary_text: calc_summary_text, percent_change_text: calc_percent_change_text, percent_change: calc_percent_change } );
	
	} else {

		if (this_current_result != 0 && this_baseline_result != 0) {
		
			// show increase arrow
			$('#percent-change strong').css("visibility", "visible");
			$('#percent-change strong').css("background-image", "url('/includes/sustainability/calculator/img/calculator/bg-visual-representations-percent-change-increase.png')");
	
			// set percentage text and number 
			calc_percent_change_text = "Worsened impact by <em>" + displayNumber(change_actual) + "</em> " + this_description_short;
			
			// display percentage text and number
			$('#percent-change p').css("padding-right", "55px");
			$('#percent-change p').html(calc_percent_change_text);
			
			// convert javascript variables to coldfusion client variables
			$.get(javascriptVariableConverter, { percent_change_text: calc_percent_change_text, percent_change_impact: 'increase' } );
	
		} else {
			
			// hide the percentage increase/decrease arrow
			$('#percent-change strong').css("visibility", "hidden");
			
			// show blank percentage area
			$('#percent-change p').css("padding-right", "10px");
			$('#percent-change p').html(calc_percent_change_text);
			
		}
		
			// determine text size to prevent overflow
			if (calc_percent_change_text.length > 65) {
			$('#percent-change p').css('font-size', '11px');
			} else {
				$('#percent-change p').css('font-size', '13px');
			}
		
		// determine which percentage text size to use to prevent overflow
		calc_summary_text = "The current design will contribute " + displayNumber($('#current-design-value').val() * $('#current-design-quantity').val()) + " " + 
						value_units + " towards " + this_category + "." + " The baseline design will contribute " + 
						displayNumber($('#baseline-design-value').val() * $('#baseline-design-quantity').val()) + " " + value_units + "." + 
						" The current design will increase " + change_percent + "% of the impact," +  " which is worsening the impact by the equivalent of " + 
						this_conversion_pre + " " + displayNumber(change_actual) + " " + this_conversion_post + ".";

		// show summary text
		$('#summary div.impact-body div.summary-text blockquote p').html(calc_summary_text);

		// convert javascript variables to coldfusion client variables
		$.get(javascriptVariableConverter, { summary_text: calc_summary_text, percent_change_text: calc_percent_change_text, percent_change: calc_percent_change} );
	}

	// change the font size of the percentage icon based on the length to prevent overflow
	if (change_percent.length > 2) {
		
		$('#percent-change strong').css('font-size', '13px');
	
	} else {
	
		$('#percent-change strong').css('font-size', '16px');
	
	}
	
	$('#percent-change strong').html(change_percent + "%");
	
	// prevent the real click action
	return false;
};


function resetFormulas() {
	
	// Determine the currently selected formula and category
	var selectedFormula 		= $('#calculator #impact-calculations #impact-tabs .jcarousel-skin-solidworks .jcarousel-item a.selected:eq(0)').parent().get(0).id;
	var formulaID 				= selectedFormula.split("-")[1];
	var this_category 			= swsc_category[formulaID];
	var this_category_id 		= determineCategoryID(this_category);
	
	// collect and set form results
	var current_design_name		= document.getElementById('current-design-name').value;
	var current_design_value 	= document.getElementById('current-design-value').value;
	var current_design_quantity	= document.getElementById('current-design-quantity').value; 

	var baseline_design_name 	= document.getElementById('baseline-design-name').value;
	var baseline_design_value 	= document.getElementById('baseline-design-value').value;
	var baseline_design_quantity 	= document.getElementById('baseline-design-quantity').value;
	
	if (current_design_value == 'Impact Value') {
		current_design_value  = 0;
	}
	if (baseline_design_value == 'Impact Value') {
		baseline_design_value = 0;
	}

	// reset the appropriate arrays with the form values just submitted
	swsc_current_design_name[1]	= current_design_name;
	swsc_current_design_name[2]	= current_design_name;
	swsc_current_design_name[3]	= current_design_name;
	swsc_current_design_name[4]	= current_design_name;
	
	swsc_current_design_value[this_category_id]		= current_design_value;
	swsc_current_design_quantity[this_category_id]	= current_design_quantity; 
	
	swsc_baseline_design_name[1]		= baseline_design_name;
	swsc_baseline_design_name[2]		= baseline_design_name;
	swsc_baseline_design_name[3]		= baseline_design_name;
	swsc_baseline_design_name[4]		= baseline_design_name;

	swsc_baseline_design_value[this_category_id]		= baseline_design_value;
	swsc_baseline_design_quantity[this_category_id]	= baseline_design_quantity;

	// update default state
	if (current_design_value == "Impact Value" && baseline_design_value == "Impact Value") {
		default_state = 2;
	} else if (current_design_value == "Impact Value") {
		default_state = 3;
	} else if (baseline_design_value == "Impact Value") {
		default_state = 4;
	} else {
		default_state = 1;
	}

	$.get(javascriptVariableConverter, { current_design_name: current_design_name, current_design_value: current_design_value, current_design_quantity: current_design_quantity, baseline_design_name: baseline_design_name, baseline_design_value: baseline_design_value, baseline_design_quantity: baseline_design_quantity } );

	// reset all formula variables
	$.ajax({
		type: "GET",
		async: false,
		url: "/includes/sustainability/calculator/incs/calculator_vars.js",
		dataType: "script",
		cache: "false"
	});
	
	

	// Setup the formulas with the new data
	setupFormulas();

	// Remove the opacity settings
	$('#calculator #visual-representation div.impact-body div.right div.opaque').css("visibility", "hidden");
	$('#calculator #visual-representation div.impact-body div.right div.opaque_text').css("visibility", "hidden");

	// disable the calculate button
	$('#recalculate').addClass('disabled');
	
	// reload the currently selected formula to reflect the new data
	$('#' + selectedFormula + ' a').triggerHandler("click");
	
	
	return false;
}



function setupFormulas() {
	// Update the default state, based on what values appear in the form
	//alert(max_value);

	//jQuery.each($("#calculator #impact-calculations #impact-tabs div ul li"), function(index, value) { // not sure why div is listed ????????????
	
	//crappyday = $('#calculator #visual-representation div.impact-body div.right div.baseline div.icons').css("width");										   
	//crappyday = $('#calculator #visual-representation div.impact-body div.right div.current div.icons').css("background-image");		
			
			
			// #main #wrap #calculator #impact-calculations 
	jQuery.each($("#impact-tabs ul li"), function(index, value) {
	
		// establish the ID number of the currently selected formula
		formulaID = this.id.split("-")[1];
				

		//alert(crappyday.substring(0,myfoo.length-2) + " --- " + crappyday);		
		
		// make sure it exists before doing anything
		if (swsc_icon[formulaID] !== undefined) {
			
			// unbind any current events
			$('#' + this.id + ' a').unbind();
			
			// then bind the right ones
			$('#' + this.id + ' a').bind('click', showFormula);
			
			// set the icon
			$('#' + this.id + ' a img').attr("src", "/includes/sustainability/calculator/img/calculator/icons/" + swsc_icon[formulaID]);
			
			// set the current / baseline range
			if (default_state == 1 && displayNumber(swsc_current_result[formulaID]) > 0 && displayNumber(swsc_baseline_result[formulaID]) == 0) { 

				$('#' + this.id + ' a h3').html(displayNumber(swsc_current_result[formulaID]));
			
			} else if (default_state == 1 && displayNumber(swsc_baseline_result[formulaID]) > 0 && displayNumber(swsc_current_result[formulaID]) == 0) { 

				$('#' + this.id + ' a h3').html(displayNumber(swsc_baseline_result[formulaID]));

			} else if (default_state == 1 && displayNumber(swsc_current_result[formulaID]) == 0 && displayNumber(swsc_baseline_result[formulaID]) == 0) { 
						
				$('#' + this.id + ' a h3').html("");

			} else if (default_state == 2) { 

				$('#' + this.id + ' a h3').html("");

			} else if (default_state == 3 || swsc_current_result[formulaID] == 0) { 
			
				$('#' + this.id + ' a h3').html(displayNumber(swsc_baseline_result[formulaID]));
			
			} else if (default_state == 4 || swsc_baseline_result[formulaID] == 0) { 
			
				$('#' + this.id + ' a h3').html(displayNumber(swsc_current_result[formulaID]));
			
			} else {

			
				$('#' + this.id + ' a h3').html(displayNumber(swsc_current_result[formulaID]) + " - " + displayNumber(swsc_baseline_result[formulaID]));
			
			}
			
			// Set the description
			if (default_state == 2) { 
			
				$('#' + this.id + ' a p').html(swsc_description_short[formulaID].replace(/^\w/, function($0) { return $0.toUpperCase(); }));
			
			} else {
				
				$('#' + this.id + ' a p').html(swsc_description_short[formulaID]);
			
			}
		}
		
	});
	
	
	return false;
}

