// Dlg_Results.cpp : implementation file
//

#include "stdafx.h"
#include "SAPP1.h"
#include "Dlg_Results.h"
#include "SAPP1Dlg.h"
#include "SAPPImpData.h"
#include <cmath>

// CDlg_Results dialog

IMPLEMENT_DYNAMIC(CDlg_Results, CDialog)
CDlg_Results::CDlg_Results(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_Results::IDD, pParent)
	, str_editAuxElec(_T(""))
	, str_editLightElec(_T(""))
	, str_editDHW(_T(""))
	, str_editHtDemBase(_T(""))
	, str_TCID(_T(""))
	, str_TCID2(_T(""))
	, str_editTotalEmissions(_T(""))
	, str_editTotalElec(_T(""))
	, str_comboClimate(_T(""))
	, str_listHouseType(_T(""))
	, str_listYearOfBuild(_T(""))
	, str_editFloorArea(_T(""))
	, str_comboFuel(_T(""))
	, str_editHeatingEff(_T(""))
	, str_comboDHWfuel(_T(""))
	, str_editDHWEff(_T(""))
	, str_comboCoolingFuel(_T(""))
	, str_editCoolingEff(_T(""))
	, str_editTotalEmissions2(_T(""))
	, str_editCapitalCost(_T(""))
	, str_LZCTelecSoldBase(_T(""))
	, str_LZCTelecSoldImp1(_T(""))
	, str_LZCTelecSoldImp2(_T(""))
	, str_LZCTelecSoldImp3(_T(""))
	, str_LZCTeleDispBase(_T(""))
	, str_LZCTeleDispImp1(_T(""))
	, str_LZCTeleDispImp2(_T(""))
	, str_LZCTeleDispImp3(_T(""))
	, str_editSpaceCoolingSupply(_T(""))
	, str_editSpaceCoolingSupplyImp1(_T(""))
	, str_editSpaceCoolingSupplyImp2(_T(""))
	, str_editSpaceCoolingSupplyImp3(_T(""))
	, str_editTotalElecImp1(_T(""))
	, str_editTotalElecImp2(_T(""))
	, str_editTotalElecImp3(_T(""))
	, str_editPrimaryFuelBase(_T(""))
	, str_editPrimaryFuelImp1(_T(""))
	, str_editPrimaryFuelImp2(_T(""))
	, str_editPrimaryFuelImp3(_T(""))
	, str_editSecFuelBase(_T(""))
	, str_editSecFuelImp1(_T(""))
	, str_editSecFuelImp2(_T(""))
	, str_editSecFuelImp3(_T(""))
	, str_editHtDemImp1(_T(""))
	, str_editDHWImp1(_T(""))
	, str_editLightElecImp1(_T(""))
	, str_editAuxElecImp1(_T(""))
	, str_editTotalCost2Imp1(_T(""))
	, str_editTotalEmissionsImp1(_T(""))
	, str_editTotalEmissions2Imp1(_T(""))
	, str_editHtDemImp2(_T(""))
	, str_editDHWImp2(_T(""))
	, str_editLightElecImp2(_T(""))
	, str_editAuxElecImp2(_T(""))
	, str_editTotalCost2Imp2(_T(""))
	, str_editTotalEmissionsImp2(_T(""))
	, str_editTotalEmissions2Imp2(_T(""))
	, str_editHtDemImp3(_T(""))
	, str_editDHWImp3(_T(""))
	, str_editLightElecImp3(_T(""))
	, str_editAuxElecImp3(_T(""))
	, str_editTotalCost2Imp3(_T(""))
	, str_editTotalEmissionsImp3(_T(""))
	, str_editTotalEmissions2Imp3(_T(""))
	, str_editSpaceCoolingSupplyImp4(_T(""))
	, str_editHtDemImp4(_T(""))
	, str_editHtDemImp5(_T(""))
	, str_editSpaceCoolingSupplyImp5(_T(""))
	, str_editDHWImp4(_T(""))
	, str_editDHWImp5(_T(""))
	, str_editLightElecImp4(_T(""))
	, str_editLightElecImp5(_T(""))
	, str_editAuxElecImp4(_T(""))
	, str_editAuxElecImp5(_T(""))
	, str_editTotalElecImp4(_T(""))
	, str_editTotalElecImp5(_T(""))
	, str_editPrimaryFuelImp4(_T(""))
	, str_editPrimaryFuelImp5(_T(""))
	, str_editSecFuelImp4(_T(""))
	, str_editSecFuelImp5(_T(""))
	, str_editTotalCost2Imp4(_T(""))
	, str_editTotalCost2Imp5(_T(""))
	, str_editTotalEmissionsImp4(_T(""))
	, str_editTotalEmissionsImp5(_T(""))
	, str_editTotalEmissions2Imp4(_T(""))
	, str_editTotalEmissions2Imp5(_T(""))
	, str_LZCTelecSoldImp4(_T(""))
	, str_LZCTelecSoldImp5(_T(""))
	, str_LZCTeleDispImp4(_T(""))
	, str_LZCTeleDispImp5(_T(""))
	, str_editHtDemCurrent(_T(""))
	, str_editSpaceCoolingSupplyCurrent(_T(""))
	, str_editDHWCurrent(_T(""))
	, str_editLightCurrent(_T(""))
	, str_editAuxElecCurrent(_T(""))
	, str_editTotalElecCurrent(_T(""))
	, str_editPrimFuelCurrent(_T(""))
	, str_editSecFuelCurrent(_T(""))
	, str_editLZCTElecSoldCurrent(_T(""))
	, str_editLZCTElecDispCurrent(_T(""))
	{
}

CDlg_Results::~CDlg_Results()
{
}

void CDlg_Results::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_EDIT1, m_editAuxElec);
	DDX_Control(pDX, IDC_EDIT2, m_editLightElec);
	DDX_Control(pDX, IDC_EDIT3, m_editDHW);
	DDX_Text(pDX, IDC_EDIT1, str_editAuxElec);
	DDX_Text(pDX, IDC_EDIT2, str_editLightElec);
	DDX_Text(pDX, IDC_EDIT3, str_editDHW);
	DDX_Control(pDX, IDC_EDIT4, m_editHtDemBase);
	DDX_Text(pDX, IDC_EDIT4, str_editHtDemBase);
	DDX_Control(pDX, IDC_EDIT5, m_TCID);
	DDX_Text(pDX, IDC_EDIT5, str_TCID);
	DDX_Control(pDX, IDC_EDIT6, m_TCID2);
	DDX_Text(pDX, IDC_EDIT6, str_TCID2);
	DDX_Control(pDX, IDC_EDIT10, m_editTotalEmissions);
	DDX_Text(pDX, IDC_EDIT10, str_editTotalEmissions);
	DDX_Control(pDX, IDC_EDIT12, m_editTotalElec);
	DDX_Text(pDX, IDC_EDIT12, str_editTotalElec);
	DDX_Control(pDX, IDC_COMBO1, m_comboClimate);
	DDX_CBString(pDX, IDC_COMBO1, str_comboClimate);
	DDX_Control(pDX, IDC_LIST2, m_listHouseType);
	DDX_LBString(pDX, IDC_LIST2, str_listHouseType);
	DDX_Control(pDX, IDC_LIST3, m_listYearOfBuild);
	DDX_LBString(pDX, IDC_LIST3, str_listYearOfBuild);
	DDX_Control(pDX, IDC_EDIT17, m_editFloorArea);
	DDX_Text(pDX, IDC_EDIT17, str_editFloorArea);
	DDX_Control(pDX, IDC_SLIDER1, m_sliderInsulation);
	DDX_Control(pDX, IDC_SLIDER2, m_sliderAirtightness);
	DDX_Control(pDX, IDC_SLIDER3, m_sliderCapacity);
	DDX_Control(pDX, IDC_SLIDER4, m_sliderSolarIngress);
	DDX_Control(pDX, IDC_SLIDER5, m_sliderOccupancy);
	DDX_Control(pDX, IDC_SLIDER6, m_sliderControllesSpace);
	DDX_Control(pDX, IDC_COMBO2, m_comboFuel);
	DDX_CBString(pDX, IDC_COMBO2, str_comboFuel);
	DDX_Control(pDX, IDC_EDIT18, m_editHeatingEff);
	DDX_Text(pDX, IDC_EDIT18, str_editHeatingEff);
	DDX_Control(pDX, IDC_COMBO4, m_comboDHWfuel);
	DDX_CBString(pDX, IDC_COMBO4, str_comboDHWfuel);
	DDX_Control(pDX, IDC_EDIT19, m_editDHWEff);
	DDX_Text(pDX, IDC_EDIT19, str_editDHWEff);
	DDX_Control(pDX, IDC_COMBO11, m_comboCoolingFuel);
	DDX_CBString(pDX, IDC_COMBO11, str_comboCoolingFuel);
	DDX_Control(pDX, IDC_EDIT20, m_editCoolingEff);
	DDX_Text(pDX, IDC_EDIT20, str_editCoolingEff);
	DDX_Control(pDX, IDC_CHECK1, m_chkInsulation);
	DDX_Control(pDX, IDC_CHECK2, m_chkAirtightness);
	DDX_Control(pDX, IDC_CHECK3, m_chkCapacity);
	DDX_Control(pDX, IDC_CHECK4, m_chkSolarIngress);
	DDX_Control(pDX, IDC_CHECK5, m_chkOccupancy);
	DDX_Control(pDX, IDC_CHECK6, m_chkControlledSpace);
	DDX_Control(pDX, IDC_CHECK13, m_chkHeatingFuel);
	DDX_Control(pDX, IDC_CHECK22, m_chkHeatingEff);
	DDX_Control(pDX, IDC_CHECK23, m_chkDHWfuel);
	DDX_Control(pDX, IDC_CHECK24, m_chkDHWEff);
	DDX_Control(pDX, IDC_CHECK25, m_chkCoolingFuel);
	DDX_Control(pDX, IDC_CHECK26, m_chkCoolingEff);
	DDX_Control(pDX, IDC_EDIT22, m_editTotalEmissions2);
	DDX_Text(pDX, IDC_EDIT22, str_editTotalEmissions2);
	DDX_Control(pDX, IDC_EDIT47, m_editCapitalCost);
	DDX_Text(pDX, IDC_EDIT47, str_editCapitalCost);
	DDX_Control(pDX, IDC_BUTTON7, m_btnBase);
	DDX_Control(pDX, IDC_BUTTON13, m_btnImp1);
	DDX_Control(pDX, IDC_BUTTON8, m_btnImp2);
	DDX_Control(pDX, IDC_BUTTON14, m_btnImp3);
	DDX_Control(pDX, IDC_EDIT27, m_editHtDemImp1);
	DDX_Control(pDX, IDC_EDIT50, m_editHtDemImp2);
	DDX_Control(pDX, IDC_EDIT68, m_editHtDemImp3);
	DDX_Control(pDX, IDC_EDIT26, m_editDHWImp1);
	DDX_Control(pDX, IDC_EDIT49, m_editDHWImp2);
	DDX_Control(pDX, IDC_EDIT67, m_editDHWImp3);
	DDX_Control(pDX, IDC_EDIT25, m_editLightElecImp1);
	DDX_Control(pDX, IDC_EDIT34, m_editLightElecImp2);
	DDX_Control(pDX, IDC_EDIT66, m_editLightElecImp3);
	DDX_Control(pDX, IDC_EDIT23, m_editAuxElecImp1);
	DDX_Control(pDX, IDC_EDIT33, m_editAuxElecImp2);
	DDX_Control(pDX, IDC_EDIT65, m_editAuxElecImp3);
	DDX_Control(pDX, IDC_EDIT30, m_editTotalElecImp1);
	DDX_Control(pDX, IDC_EDIT61, m_editTotalElecImp2);
	DDX_Control(pDX, IDC_EDIT70, m_editTotalElecImp3);

	DDX_Control(pDX, IDC_EDIT31, m_editTotalCost2Imp1);
	DDX_Control(pDX, IDC_EDIT62, m_editTotalCost2Imp2);
	DDX_Control(pDX, IDC_EDIT71, m_editTotalCost2Imp3);
	DDX_Control(pDX, IDC_EDIT29, m_editTotalEmissionsImp1);
	DDX_Control(pDX, IDC_EDIT60, m_editTotalEmissionsImp2);
	DDX_Control(pDX, IDC_EDIT69, m_editTotalEmissionsImp3);
	DDX_Control(pDX, IDC_EDIT32, m_editTotalEmissions2Imp1);
	DDX_Control(pDX, IDC_EDIT63, m_editTotalEmissions2Imp2);
	DDX_Control(pDX, IDC_EDIT72, m_editTotalEmissions2Imp3);
	DDX_Control(pDX, IDC_EDIT48, m_editCapitalCostImp1);
	DDX_Control(pDX, IDC_EDIT64, m_editCapitalCostImp2);
	DDX_Control(pDX, IDC_EDIT73, m_editCapitalCostImp3);
	DDX_Control(pDX, IDC_CHECK19, m_chkSDHW);
	DDX_Control(pDX, IDC_CHECK21, m_chkPV);
	DDX_Control(pDX, IDC_CHECK27, m_chkWT);
	DDX_Control(pDX, IDC_CHECK20, m_chkuCHP);
	DDX_Control(pDX, IDC_CHECK28, m_chkuHydro);
	DDX_Control(pDX, IDC_CHECK29, m_chkPCM);
	DDX_Control(pDX, IDC_CHECK30, m_chkMVHR);
	DDX_Control(pDX, IDC_STATIC_hL1, m_labelHL1);
	DDX_Control(pDX, IDC_STATIC_hL2, m_labelHL2);
	DDX_Control(pDX, IDC_STATIC_hL3, m_labelHL3);
	DDX_Control(pDX, IDC_STATIC_hL4, m_labelHL4);
	DDX_Control(pDX, IDC_STATIC_hL5, m_labelHL5);
	DDX_Control(pDX, IDC_STATIC_hL6, m_labelHL6);
	DDX_Control(pDX, IDC_STATIC_shT, m_labelspaceHeating);
	DDX_Control(pDX, IDC_STATIC_3, m_labelDHW);
	DDX_Control(pDX, IDC_STATIC_2, m_labelLighting);
	DDX_Control(pDX, IDC_STATIC_rS, m_labelRenSupply);
	DDX_Control(pDX, IDC_STATIC_label, m_labelPrimaryFuel);
	DDX_Control(pDX, IDC_STATIC_cost2, m_labelCost);
	DDX_Control(pDX, IDC_STATIC_cost5, m_labelSecFuel);
	DDX_Control(pDX, IDC_STATIC_emm, m_labelEmm);
	DDX_Control(pDX, IDC_STATIC_SDHW, m_labelSDHW);
	DDX_Control(pDX, IDC_STATIC_PV, m_labelPV);
	DDX_Control(pDX, IDC_STATIC_WT, m_labelWY);
	DDX_Control(pDX, IDC_STATIC_uCHP, m_labeluCHP);
	DDX_Control(pDX, IDC_STATIC_uHYDRO, m_labeluHydro);
	DDX_Control(pDX, IDC_STATIC_PCM, m_labelPCM);
	DDX_Control(pDX, IDC_STATIC_MVHR, m_labelMVHR);
	DDX_Control(pDX, IDC_EDIT75, m_LZCTelecSoldBase);
	DDX_Control(pDX, IDC_EDIT76, m_LZCTelecSoldImp1);
	DDX_Control(pDX, IDC_EDIT77, m_LZCTelecSoldImp2);
	DDX_Control(pDX, IDC_EDIT79, m_LZCTelecSoldImp3);
	DDX_Control(pDX, IDC_EDIT80, m_LZCTeleDispBase);
	DDX_Control(pDX, IDC_EDIT81, m_LZCTeleDispImp1);
	DDX_Control(pDX, IDC_EDIT82, m_LZCTeleDispImp2);
	DDX_Control(pDX, IDC_EDIT83, m_LZCTeleDispImp3);
	DDX_Text(pDX, IDC_EDIT75, str_LZCTelecSoldBase);
	DDX_Text(pDX, IDC_EDIT76, str_LZCTelecSoldImp1);
	DDX_Text(pDX, IDC_EDIT77, str_LZCTelecSoldImp2);
	DDX_Text(pDX, IDC_EDIT79, str_LZCTelecSoldImp3);
	DDX_Text(pDX, IDC_EDIT80, str_LZCTeleDispBase);
	DDX_Text(pDX, IDC_EDIT81, str_LZCTeleDispImp1);
	DDX_Text(pDX, IDC_EDIT82, str_LZCTeleDispImp2);
	DDX_Text(pDX, IDC_EDIT83, str_LZCTeleDispImp3);
	DDX_Control(pDX, IDC_EDIT78, m_editSpaceCoolingSupply);
	DDX_Control(pDX, IDC_EDIT84, m_editSpaceCoolingSupplyImp1);
	DDX_Control(pDX, IDC_EDIT85, m_editSpaceCoolingSupplyImp2);
	DDX_Control(pDX, IDC_EDIT86, m_editSpaceCoolingSupplyImp3);
	DDX_Text(pDX, IDC_EDIT78, str_editSpaceCoolingSupply);
	DDX_Text(pDX, IDC_EDIT84, str_editSpaceCoolingSupplyImp1);
	DDX_Text(pDX, IDC_EDIT85, str_editSpaceCoolingSupplyImp2);
	DDX_Text(pDX, IDC_EDIT86, str_editSpaceCoolingSupplyImp3);
	DDX_Text(pDX, IDC_EDIT30, str_editTotalElecImp1);
	DDX_Text(pDX, IDC_EDIT61, str_editTotalElecImp2);
	DDX_Text(pDX, IDC_EDIT70, str_editTotalElecImp3);
	DDX_Control(pDX, IDC_EDIT90, m_editPrimaryFuelBase);
	DDX_Control(pDX, IDC_EDIT91, m_editPrimaryFuelImp1);
	DDX_Control(pDX, IDC_EDIT92, m_editPrimaryFuelImp2);
	DDX_Control(pDX, IDC_EDIT93, m_editPrimaryFuelImp3);
	DDX_Control(pDX, IDC_EDIT94, m_editSecFuelBase);
	DDX_Control(pDX, IDC_EDIT95, m_editSecFuelImp1);
	DDX_Control(pDX, IDC_EDIT96, m_editSecFuelImp2);
	DDX_Control(pDX, IDC_EDIT97, m_editSecFuelImp3);
	DDX_Text(pDX, IDC_EDIT90, str_editPrimaryFuelBase);
	DDX_Text(pDX, IDC_EDIT91, str_editPrimaryFuelImp1);
	DDX_Text(pDX, IDC_EDIT92, str_editPrimaryFuelImp2);
	DDX_Text(pDX, IDC_EDIT93, str_editPrimaryFuelImp3);
	DDX_Text(pDX, IDC_EDIT94, str_editSecFuelBase);
	DDX_Text(pDX, IDC_EDIT95, str_editSecFuelImp1);
	DDX_Text(pDX, IDC_EDIT96, str_editSecFuelImp2);
	DDX_Text(pDX, IDC_EDIT97, str_editSecFuelImp3);
	DDX_Text(pDX, IDC_EDIT27, str_editHtDemImp1);
	DDX_Text(pDX, IDC_EDIT26, str_editDHWImp1);
	DDX_Text(pDX, IDC_EDIT25, str_editLightElecImp1);
	DDX_Text(pDX, IDC_EDIT23, str_editAuxElecImp1);
	DDX_Text(pDX, IDC_EDIT31, str_editTotalCost2Imp1);
	DDX_Text(pDX, IDC_EDIT29, str_editTotalEmissionsImp1);
	DDX_Text(pDX, IDC_EDIT32, str_editTotalEmissions2Imp1);
	DDX_Text(pDX, IDC_EDIT50, str_editHtDemImp2);
	DDX_Text(pDX, IDC_EDIT49, str_editDHWImp2);
	DDX_Text(pDX, IDC_EDIT34, str_editLightElecImp2);
	DDX_Text(pDX, IDC_EDIT33, str_editAuxElecImp2);
	DDX_Text(pDX, IDC_EDIT62, str_editTotalCost2Imp2);
	DDX_Text(pDX, IDC_EDIT60, str_editTotalEmissionsImp2);
	DDX_Text(pDX, IDC_EDIT63, str_editTotalEmissions2Imp2);
	DDX_Text(pDX, IDC_EDIT68, str_editHtDemImp3);
	DDX_Text(pDX, IDC_EDIT67, str_editDHWImp3);
	DDX_Text(pDX, IDC_EDIT66, str_editLightElecImp3);
	DDX_Text(pDX, IDC_EDIT65, str_editAuxElecImp3);
	DDX_Text(pDX, IDC_EDIT71, str_editTotalCost2Imp3);
	DDX_Text(pDX, IDC_EDIT69, str_editTotalEmissionsImp3);
	DDX_Text(pDX, IDC_EDIT72, str_editTotalEmissions2Imp3);
	DDX_Control(pDX, IDC_EDIT105, m_editSpaceCoolingSupplyImp4);
	DDX_Control(pDX, IDC_EDIT89, m_editHtDemImp4);
	DDX_Control(pDX, IDC_EDIT112, m_editHtDemImp5);
	DDX_Control(pDX, IDC_EDIT120, m_editSpaceCoolingSupplyImp5);
	DDX_Control(pDX, IDC_EDIT88, m_editDHWImp4);
	DDX_Control(pDX, IDC_EDIT111, m_editDHWImp5);
	DDX_Control(pDX, IDC_EDIT87, m_editLightElecImp4);
	DDX_Control(pDX, IDC_EDIT110, m_editLightElecImp5);
	DDX_Control(pDX, IDC_EDIT74, m_editAuxElecImp4);
	DDX_Control(pDX, IDC_EDIT109, m_editAuxElecImp5);
	DDX_Control(pDX, IDC_EDIT100, m_editTotalElecImp4);
	DDX_Control(pDX, IDC_EDIT115, m_editTotalElecImp5);
	DDX_Control(pDX, IDC_EDIT106, m_editPrimaryFuelImp4);
	DDX_Control(pDX, IDC_EDIT121, m_editPrimaryFuelImp5);
	DDX_Control(pDX, IDC_EDIT107, m_editSecFuelImp4);
	DDX_Control(pDX, IDC_EDIT122, m_editSecFuelImp5);

	DDX_Control(pDX, IDC_EDIT101, m_editTotalCost2Imp4);
	DDX_Control(pDX, IDC_EDIT116, m_editTotalCost2Imp5);
	DDX_Control(pDX, IDC_EDIT99, m_editTotalEmissionsImp4);
	DDX_Control(pDX, IDC_EDIT114, m_editTotalEmissionsImp5);
	DDX_Control(pDX, IDC_EDIT102, m_editTotalEmissions2Imp4);
	DDX_Control(pDX, IDC_EDIT117, m_editTotalEmissions2Imp5);
	DDX_Control(pDX, IDC_EDIT108, m_LZCTelecSoldImp4);
	DDX_Control(pDX, IDC_EDIT123, m_LZCTelecSoldImp5);
	DDX_Control(pDX, IDC_EDIT104, m_LZCTeleDispImp4);
	DDX_Control(pDX, IDC_EDIT119, m_LZCTeleDispImp5);

	DDX_Text(pDX, IDC_EDIT105, str_editSpaceCoolingSupplyImp4);
	DDX_Text(pDX, IDC_EDIT89, str_editHtDemImp4);
	DDX_Text(pDX, IDC_EDIT112, str_editHtDemImp5);
	DDX_Text(pDX, IDC_EDIT120, str_editSpaceCoolingSupplyImp5);
	DDX_Text(pDX, IDC_EDIT88, str_editDHWImp4);
	DDX_Text(pDX, IDC_EDIT111, str_editDHWImp5);
	DDX_Text(pDX, IDC_EDIT87, str_editLightElecImp4);
	DDX_Text(pDX, IDC_EDIT110, str_editLightElecImp5);
	DDX_Text(pDX, IDC_EDIT74, str_editAuxElecImp4);
	DDX_Text(pDX, IDC_EDIT109, str_editAuxElecImp5);
	DDX_Text(pDX, IDC_EDIT100, str_editTotalElecImp4);
	DDX_Text(pDX, IDC_EDIT115, str_editTotalElecImp5);
	DDX_Text(pDX, IDC_EDIT106, str_editPrimaryFuelImp4);
	DDX_Text(pDX, IDC_EDIT121, str_editPrimaryFuelImp5);
	DDX_Text(pDX, IDC_EDIT107, str_editSecFuelImp4);
	DDX_Text(pDX, IDC_EDIT122, str_editSecFuelImp5);
	DDX_Text(pDX, IDC_EDIT101, str_editTotalCost2Imp4);
	DDX_Text(pDX, IDC_EDIT116, str_editTotalCost2Imp5);
	DDX_Text(pDX, IDC_EDIT99, str_editTotalEmissionsImp4);
	DDX_Text(pDX, IDC_EDIT114, str_editTotalEmissionsImp5);
	DDX_Text(pDX, IDC_EDIT102, str_editTotalEmissions2Imp4);
	DDX_Text(pDX, IDC_EDIT117, str_editTotalEmissions2Imp5);
	DDX_Text(pDX, IDC_EDIT108, str_LZCTelecSoldImp4);
	DDX_Text(pDX, IDC_EDIT123, str_LZCTelecSoldImp5);
	DDX_Text(pDX, IDC_EDIT104, str_LZCTeleDispImp4);
	DDX_Text(pDX, IDC_EDIT119, str_LZCTeleDispImp5);
	DDX_Control(pDX, IDC_BUTTON15, m_btnImp4);
	DDX_Control(pDX, IDC_BUTTON16, m_btnImp5);
	DDX_Control(pDX, IDC_STATIC_1, m_labelAuxElec);
	DDX_Control(pDX, IDC_STATIC_shT2, m_labelCooling);
	DDX_Control(pDX, IDC_STATIC_emm2, m_labelElecSold);
	DDX_Control(pDX, IDC_STATIC_emm3, m_labelTotElecDisp);
	DDX_Control(pDX, IDC_CHECK34, m_chkActual);
	DDX_Control(pDX, IDC_CHECK31, m_chkperm2);
	DDX_Control(pDX, IDC_CHECK32, m_chkEnergy);
	DDX_Control(pDX, IDC_CHECK33, m_chkCost);
	DDX_Control(pDX, IDC_CHECK35, m_chkEmissions);
	DDX_Control(pDX, IDC_CHECK36, m_chkFGHRS);
	DDX_Control(pDX, IDC_CHECK37, m_chkWWHRS);
	DDX_Control(pDX, IDC_STATIC_Base, m_labelBase);
	DDX_Control(pDX, IDC_STATIC_Imp1, m_labelImp1);
	DDX_Control(pDX, IDC_STATIC_Imp2, m_labelImp2);
	DDX_Control(pDX, IDC_STATIC_Imp3, m_labelImp3);
	DDX_Control(pDX, IDC_STATIC_Imp4, m_labelImp4);
	DDX_Control(pDX, IDC_STATIC_Imp5, m_labelImp5);
	DDX_Control(pDX, IDC_STATIC_LIGHT2, m_labelElec);
	DDX_Control(pDX, IDC_STATIC_cost, m_labelElec2);
	DDX_Control(pDX, IDC_STATIC_LIGHT3, m_labelElec3);
	DDX_Control(pDX, IDC_STATIC_co2, m_labelCO2small);
	DDX_Control(pDX, IDC_EDIT7, m_editHtDemCurrent);
	DDX_Text(pDX, IDC_EDIT7, str_editHtDemCurrent);
	DDX_Control(pDX, IDC_EDIT8, m_editSpaceCoolingSupplyCurrent);
	DDX_Text(pDX, IDC_EDIT8, str_editSpaceCoolingSupplyCurrent);
	DDX_Control(pDX, IDC_EDIT11, m_editDHWCurrent);
	DDX_Text(pDX, IDC_EDIT11, str_editDHWCurrent);
	DDX_Control(pDX, IDC_EDIT14, m_editLightCurrent);
	DDX_Text(pDX, IDC_EDIT14, str_editLightCurrent);
	DDX_Control(pDX, IDC_EDIT13, m_editAuxElecCurrent);
	DDX_Text(pDX, IDC_EDIT13, str_editAuxElecCurrent);
	DDX_Control(pDX, IDC_EDIT15, m_editTotalElecCurrent);
	DDX_Text(pDX, IDC_EDIT15, str_editTotalElecCurrent);
	DDX_Control(pDX, IDC_EDIT16, m_editPrimFuelCurrent);
	DDX_Text(pDX, IDC_EDIT16, str_editPrimFuelCurrent);
	DDX_Control(pDX, IDC_EDIT124, m_editSecFuelCurrent);
	DDX_Text(pDX, IDC_EDIT124, str_editSecFuelCurrent);
	DDX_Control(pDX, IDC_EDIT129, m_editLZCTElecSoldCurrent);
	DDX_Text(pDX, IDC_EDIT129, str_editLZCTElecSoldCurrent);
	DDX_Control(pDX, IDC_EDIT130, m_editLZCTElecDispCurrent);
	DDX_Text(pDX, IDC_EDIT130, str_editLZCTElecDispCurrent);
	DDX_Control(pDX, ID_STATIC_kgCO2, m_labelsmall1);
	DDX_Control(pDX, ID_STATIC_kgCO3, m_labelsmall2);
	DDX_Control(pDX, ID_STATIC_kgCO4, m_labelsmall3);
	DDX_Control(pDX, ID_STATIC_kgCO5, m_labelsmall4);
	DDX_Control(pDX, ID_STATIC_kgCO7, m_labelsmall5);
	DDX_Control(pDX, ID_STATIC_kgCO6, m_labelsmall);
	DDX_Control(pDX, IDC_STATIC_BC, m_labelBC);
	DDX_Control(pDX, IDC_STATIC_SC, m_labelSC);
	DDX_Control(pDX, IDC_STATIC_LZCT, m_labelLZCT);
	DDX_Control(pDX, IDC_SLIDER7, m_sliderHeff);
	DDX_Control(pDX, IDC_SLIDER8, m_sliderDHWeff);

	DDX_Control(pDX, IDC_STATIC_FGHRS, m_lableFGHRS);
	DDX_Control(pDX, IDC_STATIC_WWHRS, m_lableWWHRS);
}
BEGIN_MESSAGE_MAP(CDlg_Results, CDialog)
	ON_EN_CHANGE(IDC_EDIT4, OnEnChangeEdit4)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER1, OnNMCustomdrawSlider1)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER2, OnNMCustomdrawSlider2)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER3, OnNMCustomdrawSlider3)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER4, OnNMCustomdrawSlider4)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER5, OnNMCustomdrawSlider5)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER6, OnNMCustomdrawSlider6)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
	ON_LBN_SELCHANGE(IDC_LIST2, OnLbnSelchangeList2)
	ON_LBN_SELCHANGE(IDC_LIST3, OnLbnSelchangeList3)
	ON_EN_CHANGE(IDC_EDIT17, OnEnChangeEdit17)
	ON_CBN_SELCHANGE(IDC_COMBO2, OnCbnSelchangeCombo2)
	ON_EN_CHANGE(IDC_EDIT18, OnEnChangeEdit18)
	ON_CBN_SELCHANGE(IDC_COMBO4, OnCbnSelchangeCombo4)
	ON_EN_CHANGE(IDC_EDIT19, OnEnChangeEdit19)
	ON_CBN_SELCHANGE(IDC_COMBO11, OnCbnSelchangeCombo11)
	ON_EN_CHANGE(IDC_EDIT20, OnEnChangeEdit20)
	ON_BN_CLICKED(IDC_CHECK1, OnBnClickedCheck1)
	ON_BN_CLICKED(IDC_CHECK2, OnBnClickedCheck2)
	ON_BN_CLICKED(IDC_CHECK3, OnBnClickedCheck3)
	ON_BN_CLICKED(IDC_CHECK4, OnBnClickedCheck4)
	ON_BN_CLICKED(IDC_CHECK5, OnBnClickedCheck5)
	ON_BN_CLICKED(IDC_CHECK6, OnBnClickedCheck6)
	ON_BN_CLICKED(IDC_CHECK13, OnBnClickedCheck13)
	ON_BN_CLICKED(IDC_CHECK22, OnBnClickedCheck22)
	ON_BN_CLICKED(IDC_CHECK23, OnBnClickedCheck23)
	ON_BN_CLICKED(IDC_CHECK24, OnBnClickedCheck24)
	ON_BN_CLICKED(IDC_CHECK25, OnBnClickedCheck25)
	ON_BN_CLICKED(IDC_CHECK26, OnBnClickedCheck26)
	ON_EN_CHANGE(IDC_EDIT3, OnEnChangeEdit3)
	ON_EN_CHANGE(IDC_EDIT34, OnEnChangeEdit34)
	ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
	ON_BN_CLICKED(IDC_CHECK19, OnBnClickedCheck19)
	ON_BN_CLICKED(IDC_CHECK21, OnBnClickedCheck21)
	ON_BN_CLICKED(IDC_CHECK27, OnBnClickedCheck27)
	ON_BN_CLICKED(IDC_CHECK20, OnBnClickedCheck20)
	ON_BN_CLICKED(IDC_CHECK28, OnBnClickedCheck28)
	ON_BN_CLICKED(IDC_CHECK29, OnBnClickedCheck29)
	ON_BN_CLICKED(IDC_CHECK30, OnBnClickedCheck30)
	ON_STN_CLICKED(IDC_STATIC_2, OnStnClickedStatic2)
	ON_BN_CLICKED(IDC_BUTTON7, OnBnClickedBase)
	ON_BN_CLICKED(IDC_BUTTON13, OnBnClickedImprovement1)
	ON_BN_CLICKED(IDC_BUTTON8, OnBnClickedImprovement2)
	ON_BN_CLICKED(IDC_BUTTON14, OnBnClickedImprovement3)
	ON_BN_CLICKED(IDC_BUTTON15, OnBnClickedImprovement4)
	ON_BN_CLICKED(IDC_BUTTON16, OnBnClickedImprovement5)
	ON_BN_CLICKED(IDC_CHECK34, OnBnClickedCheck34)
	ON_BN_CLICKED(IDC_CHECK31, OnBnClickedCheck31)
	ON_BN_CLICKED(IDC_CHECK32, OnBnClickedCheck32)
	ON_BN_CLICKED(IDC_CHECK33, OnBnClickedCheck33)
	ON_BN_CLICKED(IDC_CHECK35, OnBnClickedCheck35)
	ON_STN_CLICKED(IDC_STATIC_Units, OnStnClickedStaticUnits)
	ON_BN_CLICKED(IDC_CHECK36, OnBnClickedCheck36)
	ON_BN_CLICKED(IDC_CHECK37, OnBnClickedCheck37)
	ON_STN_CLICKED(IDC_STATIC_Imp1, OnStnClickedStaticImp1)
	ON_EN_CHANGE(IDC_EDIT50, OnEnChangeEdit50)
	ON_EN_CHANGE(IDC_EDIT68, OnEnChangeEdit68)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER7, OnNMCustomdrawSlider7)
	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER8, OnNMCustomdrawSlider8)
END_MESSAGE_MAP()

// CDlg_Results message handlers

void ApplyEffAdjustmentsToHeatingCalcs()
{
	//----------------------------------------------------------------------
	// APPLY HEATING ADJUSTMENTS
	//----------------------------------------------------------------------
	/*
	
	if (
		(is_make_eff_adjustments_slider_insulation == false) ||
		(is_make_eff_adjustments_slider_exposure == false) ||
		(is_make_eff_adjustments_slider_airChanges == false) ||
		(is_make_eff_adjustments_slider_capacity == false) ||
		(is_make_eff_adjustments_slider_occupancy == false) ||
		(is_make_eff_adjustments_slider_solarIngress == false) ||
		(is_make_eff_adjustments_slider_livingArea == false) )  
	*/
	
	//chkHeatingEff= m_chkHeatingEff.GetCheck();

	mainHtEff = mainHtEffNominal;

	TRACE("\n Nominal efficiency %f efficincy %f", mainHtEffNominal, mainHtEff );
	
    if (chkHeatingEff == 1  ){

		TRACE("\n  chkHeatingEff  =ON");
		return;
	}
	else
	{ 
		/*
		is_make_eff_adjustments_slider_insulation   = false;
		is_make_eff_adjustments_slider_exposure     = false;
		is_make_eff_adjustments_slider_airChanges   = false;
		is_make_eff_adjustments_slider_capacity     = false;
		is_make_eff_adjustments_slider_occupancy    = false;
		is_make_eff_adjustments_slider_livingArea   = false;
		is_make_eff_adjustments_slider_solarIngress = false;
		*/
		//---------------------------------------------------------
		// 1. APPLY EFFECIENCY ADJUSTMENTS from SAP2009 Table4c
		//---------------------------------------------------------

		 mainHtEff = mainHtEffNominal;

		 
		//---------------------------------------------------------
		// RANGE COOKER adjustments
		//---------------------------------------------------------
		if(strcmp(boilerType,"Range cooker") == 0)
		{
			 mainHtEff = mainHtEff / (1 -  (heatEmmFromCase/heatTransferredToWater));			 
		}

		//---------------------------------------------------------
		// CONDENSING BOILER OR CONDENSING COMBI adjustments
		//---------------------------------------------------------
		if((strcmp(boilerType,"Condensing") == 0) || (strcmp(boilerType,"Condensing combi") == 0))
		{
			//-------------------------------------------------------------------------
			// Set flags for is_enhanced_load_compensator and is_under_floor_system
			if(strcmp(mainHtCompensator,"Enhanced load compensator") == 0)
			{
				is_enhanced_load_compensator = true;
				is_under_floor_system = false;
			}
			else if(strcmp(mainHtCompensator,"Weather compensator") == 0)
			{
				is_enhanced_load_compensator = true;
				is_under_floor_system = false;
			}

			if(strcmp(mainHtEmitter,"Radiators") != 0)  
			{
				is_enhanced_load_compensator = false;
				is_under_floor_system = true;
			}

			//-------------------------------------------------------------------------
			// Apply adjustments based on fuel types and flags set above
			if(strcmp(mainFuel,"Mains gas")==0)
			{
				if((is_enhanced_load_compensator == true) || (is_under_floor_system == true))
				{
					mainHtEff = mainHtEff +3;
				 
				}
			}
			else if((strcmp(mainFuel,"Oil")==0) || (strcmp(mainFuel,"LPG")==0))
			{
				if(is_enhanced_load_compensator == true)
				{
					mainHtEff = mainHtEff + 1.5;
				 

				}
				if(is_under_floor_system == true)
				{
					mainHtEff = mainHtEff + 0.5;		 
				}
			}
		}
	 
		//---------------------------------------------------------
		// BOILER adjustments
		//---------------------------------------------------------
		if(strcmp(mainHtType,"Boiler") == 0) 
		{
			/*if( (strcmp(mainHtControls,"No time or thermostatic control of room temperature") ==0) ||
				(strcmp(mainHtControls,"Programmer - no thermostat") ==0) ||
				(strcmp(mainHtControls,"Programmer - TRVs and bypass") ==0) ||
				(strcmp(mainHtControls,"Programmer - TRVs and flow switch") ==0) ||
				(strcmp(isIterlockPresent,"No") ==0))
			{
				mainHtEff = mainHtEff - 5;
				TRACE("\nBoiler>> control  mainHtEff   %f", mainHtEff );	
			}
			

			// Hot water effeciency adjust
			if(strcmp(boilerType,"Combi") == 0)
			{
				WHtEff = WHtEff - 5;
			}
			*/



		}
		else if(( strcmp( mainHtType,"Warm air")==0) || ( strcmp( mainHtType,"Heat pump - warm air")==0))
		{
			if (strcmp(mainHtEmitter,"Radiators") == 0) 
			{
				if((is_enhanced_load_compensator == true) || (is_under_floor_system == true))
				{
					mainHtEff = mainHtEff * 0.75;
					 
				}
				else
				{
					mainHtEff = mainHtEff * 0.7;  //@min 20140303
					 
				}
			}
		}	

		//-------------------------------------------------------------
		// 2. APPLY TEMPERATURE ADJUSTMENTS from SAP2009 Table4e
		//-------------------------------------------------------------
		// These effeciency adjustments equivalent to SAP temperature 
		// adjustments have been obtained by detailed simulations
		// +0.6  = -6.1%   stdev = 1.1
		// +0.3  = -3.1%   stdev = 0.6
		// -0.1  = +1%     stdev = 0.4
		// -0.15 = +1.6%   stdev = 0.5

		//-------------------------------------------------------------
		// GROUP 0: NO HEATING SYSTEM PRESENT
		//-------------------------------------------------------------
		if(strcmp(mainHtType,"No heating system present") == 0) 
		{
			mainHtEff = mainHtEff - 3.1;  
		}

		//-------------------------------------------------------------
		// GROUP 1: BOILER SYSTEM WITH RADIATORS AND UNDERFLOOR HEATING	
		//-------------------------------------------------------------
			 
		if(strcmp(mainHtType,"Boiler") == 0) 
		{
			if(strcmp(boilerType,"CPSU") ==0) 
			{
				mainHtEff = mainHtEff + 1; 
		 
			}
			
			if((strcmp(mainHtControls,"No time or thermostatic control of room temperature") ==0) ||
				(strcmp(mainHtControls,"Programmer - no thermostat") ==0) )
			{
				mainHtEff = mainHtEff - 6.1; 
			 
			}
	  
			if(strcmp(mainHtControls,"Delayed start thermostat") ==0) 
			{
				mainHtEff = mainHtEff + 1.6; 
 
			}

		

			if(strcmp(boilerType,"Combi") == 0)
			{
				WHtEff = WHtEff - 5;
			}

		}
	 
		//-------------------------------------------------------------
		// GROUP 2: HEAT PUMPS WITH RADIATORS OR UNDERFLOOR HEATING
		//-------------------------------------------------------------
		if(strcmp(mainHtType,"Heat pump - wet system") == 0) 
		{
			if((strcmp(mainHtControls,"No time or thermostatic control of room temperature") ==0) ||
				(strcmp(mainHtControls,"Programmer - no thermostat") ==0) )
			{
				mainHtEff = mainHtEff - 3.1; 
			}

			if(strcmp(WHtype,"Integrated thermal store and gas-fired CPSU") == 0)
			{
				mainHtEff = mainHtEff + 1;
			}
		}

		//-------------------------------------------------------------
		// GROUP 3: COMMUNITY HEATING SCHEME
		//-------------------------------------------------------------
		if(strcmp(mainHtType,"Community heating") == 0)
		{
			if((strcmp(mainHtControls,"Flat rate charging - no thermostatic control of room temperature") ==0) ||
				(strcmp(mainHtControls,"Flat rate charging - programmer and no room thermostat") ==0) )
			{
				mainHtEff = mainHtEff - 3.1; 
			}
		}

		//-------------------------------------------------------------
		// GROUP 4: ELECTRIC STORAGE SYSTEMS
		//-------------------------------------------------------------
		if(strcmp(mainHtType,"Storage heaters") == 0)
		{
			if(strcmp(mainHtControls,"Manual charge control") ==0)
			{
				mainHtEff = mainHtEff - 3.1; 
			}
		}

		//-----------------------------------------------------------------------------------
		// GROUP 5: WARM AIR SYSTEMS(including heat pumps with warm air distribution)
		//-----------------------------------------------------------------------------------
		if((strcmp(mainHtType,"Heat pump - warm air") == 0) || (strcmp(mainHtType,"Warm air") == 0))
		{
			if((strcmp(mainHtControls,"No time or thermostatic control of room temperature") ==0) ||
				(strcmp(mainHtControls,"Programmer - no thermostat") ==0) )
			{
				mainHtEff = mainHtEff - 3.1; 
			}
		}

		//-----------------------------------------------------------------------------------
		// GROUP 6: ROOM HEATER SYSTEMS
		//-----------------------------------------------------------------------------------
		if(strcmp(mainHtType,"Room heaters") == 0) 
		{
			if(strcmp(mainHtControls,"No thermostatic control of room temperature") ==0) 
			{
				mainHtEff = mainHtEff - 3.1; 
			}
		}

		//-----------------------------------------------------------------------------------
		// GROUP 7: OTHER SYSTEMS
		//-----------------------------------------------------------------------------------
		if(strcmp(mainHtType,"Other systems") == 0) 
		{
			if((strcmp(mainHtControls,"No time or thermostatic control of room temperature") ==0) ||
				(strcmp(mainHtControls,"Programmer - no thermostat") ==0) )
			{
				mainHtEff = mainHtEff - 3.1; 
			}
		}	
 	} // if else close bracket


}



void CDlg_Results::ChangeIndexNumberBasedOnHouseTypeAndAgeForResultsDialog()
{
	if(strcmp(hemHouseType,"Detached")==0)
	{
		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation		    = "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O4";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 4.06;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation		    = "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O4";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 3.8;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation		    = "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O4";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 3.2;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation		    = "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A4";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O4";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 2.17;
		}
		else if (strcmp(hemYearOfBuild,"post 1982")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation		    = "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A4";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O4";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 1.73;
		}
		else if (strcmp(hemYearOfBuild,"post 2002")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I2";
			hemI_insulation1		= "I2";
			hemI_insulation2		= "I3";
			hemA_ach				= "A3";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O4";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 1.01;
		}
		else if (strcmp(hemYearOfBuild,"post 2006")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I2";
			hemI_insulation1		= "I2";
			hemI_insulation2		= "I3";
			hemA_ach				= "A3";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O4";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.89;
		}
		else if (strcmp(hemYearOfBuild,"post 2010")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I4";
			hemI_insulation1		= "I4";
			hemI_insulation2		= "I5";
			hemA_ach				= "A2";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O4";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.51;
		}
	}
	else if(strcmp(hemHouseType,"Semi-detached")==0)
	{
		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O2";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 3.51;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O2";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 3.27;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O2";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 2.70;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A4";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O2";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 1.83;
		}
		else if (strcmp(hemYearOfBuild,"post 1982")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I2";
			hemI_insulation1		= "I2";
			hemI_insulation2		= "I3";
			hemA_ach				= "A4";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O2";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 1.42;
		}
		else if (strcmp(hemYearOfBuild,"post 2002")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I3";
			hemI_insulation1		= "I3";
			hemI_insulation2		= "I4";
			hemA_ach				= "A3";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O2";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.80;
		}
		else if (strcmp(hemYearOfBuild,"post 2006")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I3";
			hemI_insulation1		= "I3";
			hemI_insulation2		= "I4";
			hemA_ach				= "A3";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O2";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.72;
		}
		else if (strcmp(hemYearOfBuild,"post 2010")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I4";
			hemI_insulation1		= "I4";
			hemI_insulation2		= "I5";
			hemA_ach				= "A2";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O2";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.40;
		}
	}
	else if(strcmp(hemHouseType,"Terraced")==0)
	{
		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O3";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 4.55;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O3";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 4.26;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O3";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 3.56;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A4";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O3";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 2.37;
		}
		else if (strcmp(hemYearOfBuild,"post 1982")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A4";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O3";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 1.9;
		}
		else if (strcmp(hemYearOfBuild,"post 2002")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I2";
			hemI_insulation1		= "I2";
			hemI_insulation2		= "I3";
			hemA_ach				= "A3";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O3";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 1.07;
		}
		else if (strcmp(hemYearOfBuild,"post 2006")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I2";
			hemI_insulation1		= "I2";
			hemI_insulation2		= "I3";
			hemA_ach				= "A3";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O3";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.85;
		}
		else if (strcmp(hemYearOfBuild,"post 2010")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I4";
			hemI_insulation1		= "I4";
			hemI_insulation2		= "I5";
			hemA_ach				= "A2";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S2";
			hemO_occupantDensity    = "O3";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.53;
		}
	}
	else if(strcmp(hemHouseType,"Tenement")==0)
	{
		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hemX_exposure           = "X4";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 3.6;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hemX_exposure           = "X4";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 3.31;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hemX_exposure           = "X4";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 2.76;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hemX_exposure           = "X4";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A4";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 1.83;
		}
		else if (strcmp(hemYearOfBuild,"post 1982")==0)
		{
			hemX_exposure           = "X4";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A4";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 1.55;
		}
		else if (strcmp(hemYearOfBuild,"post 2002")==0)
		{
			hemX_exposure           = "X4";
			hemI_insulation			= "I2";
			hemI_insulation1		= "I2";
			hemI_insulation2		= "I3";
			hemA_ach				= "A3";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.88;
		}
		else if (strcmp(hemYearOfBuild,"post 2006")==0)
		{
			hemX_exposure           = "X4";
			hemI_insulation			= "I2";
			hemI_insulation1		= "I2";
			hemI_insulation2		= "I3";
			hemA_ach				= "A3";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.8;
		}
		else if (strcmp(hemYearOfBuild,"post 2010")==0)
		{
			hemX_exposure           = "X4";
			hemI_insulation			= "I4";
			hemI_insulation1		= "I4";
			hemI_insulation2		= "I5";
			hemA_ach				= "A2";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 0.41;
		}
	}
	else if(strcmp(hemHouseType,"4-in-block")==0)
	{
		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hemX_exposure           = "X1";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 4.36;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hemX_exposure           = "X1";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 4.10;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hemX_exposure           = "X1";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 4.10;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hemX_exposure           = "X1";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A4";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";

			//hem_extInsulationValue = 3.38;
		}
	}
	else if(strcmp(hemHouseType,"Tower/Slab")==0)
	{
		if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hemX_exposure           = "X3";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";	
			
			//hem_extInsulationValue = 3.13;
		}
	}
	else if(strcmp(hemHouseType,"Conversion")==0)
	{
		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hemX_exposure           = "X2";
			hemI_insulation			= "I1";
			hemI_insulation1		= "I1";
			hemI_insulation2		= "I2";
			hemA_ach				= "A5";
			hemC_capacity			= "C1";
			hemS_solarGains			= "S1";
			hemO_occupantDensity    = "O1";
			hemL_livingAreaFraction = "L1";
			
			//hem_extInsulationValue = 3.83;
		}		
	}

	//-----------------------------------------
	// Select posotions for sliders
	//-----------------------------------------
	// EXPOSURE
	//-----------------------------------------

	//-----------------------------------------
	// INSULATION
	//-----------------------------------------
	if(hemI_insulation1 == "I1")
	{
		hemI_insulationSliderPos = 1;
	}
	else if(hemI_insulation1 == "I2")
	{
		hemI_insulationSliderPos = 2;
	}
	else if(hemI_insulation1 == "I3")
	{
		hemI_insulationSliderPos = 3;
	}
	else if(hemI_insulation1 == "I4")
	{
		hemI_insulationSliderPos = 4;
	}
	else if(hemI_insulation1 == "I5")
	{
		hemI_insulationSliderPos = 5;
	}
	
	//-----------------------------------------
	// AIR CHANGE RATE
	//-----------------------------------------
	if(hemA_ach == "A1")
	{
		hemA_achSliderPos = 1;
	}
	else if(hemA_ach == "A2")
	{
		hemA_achSliderPos = 2;
	}
	else if(hemA_ach == "A3")
	{
		hemA_achSliderPos = 3;
	}
	else if(hemA_ach == "A4")
	{
		hemA_achSliderPos = 4;
	}
	else if(hemA_ach == "A5")
	{
		hemA_achSliderPos = 5;
	}

	//-----------------------------------------
	// CAPACITY
	//-----------------------------------------
	if(hemC_capacity == "C1")
	{
		hemC_capacitySliderPos = 1;
	}
	else if(hemC_capacity == "C2")
	{
		hemC_capacitySliderPos = 2;
	}

	//-----------------------------------------
	// SOLAR INGRESS
	//-----------------------------------------
	if(hemS_solarGains == "S1")
	{
		hemS_solarGainsSliderPos = 1;
	}
	else if(hemS_solarGains == "S2")
	{
		hemS_solarGainsSliderPos = 2;
	}
	else if(hemS_solarGains == "S3")
	{
		hemS_solarGainsSliderPos = 3;
	}

	//-----------------------------------------
	// OCCUPANCY
	//-----------------------------------------
	if(hemO_occupantDensity == "O1")
	{
		hemO_OCCDensitySliderPos = 1;
	}
	else if(hemO_occupantDensity == "O2")
	{
		hemO_OCCDensitySliderPos = 2;
	}
	else if(hemO_occupantDensity == "O3")
	{
		hemO_OCCDensitySliderPos = 3;
	}
	else if(hemO_occupantDensity == "O4")
	{
		hemO_OCCDensitySliderPos = 4;
	}
	else if(hemO_occupantDensity == "O5")
	{
		hemO_OCCDensitySliderPos = 5;
	}
	
	//-----------------------------------------
	// CONTROLLED SPACE
	//-----------------------------------------
	if(hemL_livingAreaFraction == "L1")
	{
		hemL_LAFracSliderPos = 1;
	}
	else if(hemL_livingAreaFraction == "L2")
	{
		hemL_LAFracSliderPos = 2;
	}
	else if(hemL_livingAreaFraction == "L3")
	{
		hemL_LAFracSliderPos = 3;
	}
	else if(hemL_livingAreaFraction == "L4")
	{
		hemL_LAFracSliderPos = 4;
	}
	else if(hemL_livingAreaFraction == "L5")
	{
		hemL_LAFracSliderPos = 5;
	}
	
	UpdateData(TRUE);
}

void CDlg_Results::EnableOrDisableControls()
{
	if(is_climate_changed_from_results == true)
	{
		m_listHouseType.EnableWindow(TRUE);
	}
	else
	{
		m_listHouseType.EnableWindow(FALSE);
	}

	if(is_house_type_changed_from_results == true)
	{		
		m_listYearOfBuild.EnableWindow(TRUE);
	}
	else
	{		
		m_listYearOfBuild.EnableWindow(FALSE);
	}

	if(is_year_of_build_changed == true)
	{
		m_editFloorArea.EnableWindow(TRUE);

		// Base button should only be enabled after climate,
		// house type and year of build have been selected by user
		m_btnBase.EnableWindow(TRUE);

		//-----------------------------------------
		// ENERGY DEMAND DETERMINANTS
		//-----------------------------------------
		m_chkInsulation.EnableWindow(TRUE);
		m_chkAirtightness.EnableWindow(TRUE);
		m_chkCapacity.EnableWindow(TRUE);
		m_chkSolarIngress.EnableWindow(TRUE);
		m_chkOccupancy.EnableWindow(TRUE);
		m_chkControlledSpace.EnableWindow(TRUE);

		//-----------------------------------------
		// ENERGY SUPPLY DETERMINANTS
		//-----------------------------------------
		m_chkHeatingFuel.EnableWindow(TRUE);
		m_chkHeatingEff.EnableWindow(TRUE);
		m_chkDHWfuel.EnableWindow(TRUE);
		m_chkDHWEff.EnableWindow(TRUE);
		m_chkCoolingFuel.EnableWindow(TRUE);
		m_chkCoolingEff.EnableWindow(TRUE);

		//-----------------------------------------
		// RENEWABLES
		//-----------------------------------------
		m_chkSDHW.EnableWindow(TRUE);
		m_chkPV.EnableWindow(TRUE);
		m_chkWT.EnableWindow(TRUE);
		m_chkuCHP.EnableWindow(TRUE);
		m_chkuHydro.EnableWindow(TRUE);
		m_chkPCM.EnableWindow(TRUE);
		m_chkMVHR.EnableWindow(TRUE);
		m_chkFGHRS.EnableWindow(TRUE);
		m_chkWWHRS.EnableWindow(TRUE);

		//-----------------------------------------
		// INSULATION
		//-----------------------------------------
		if(m_chkInsulation.GetCheck() == 0)
		{
			chkInsulation = 0;
			m_sliderInsulation.EnableWindow(FALSE);
		}
		else
		{
			chkInsulation = 1;
			m_sliderInsulation.EnableWindow(TRUE);
		}

		//-----------------------------------------
		// AIR TIGHTNESS
		//-----------------------------------------
		if(m_chkAirtightness.GetCheck() == 0)
		{
			chkAirtightness = 0;
			m_sliderAirtightness.EnableWindow(FALSE);
		}
		else
		{
			chkAirtightness = 1;
			m_sliderAirtightness.EnableWindow(TRUE);
		}

		//-----------------------------------------
		// CAPACITY
		//-----------------------------------------
		if(m_chkCapacity.GetCheck() == 0)
		{
			chkCapacity = 0;
			m_sliderCapacity.EnableWindow(FALSE);
		}
		else
		{
			chkCapacity = 1;
			m_sliderCapacity.EnableWindow(TRUE);
		}

		//-----------------------------------------
		// SOLAR INGRESS
		//-----------------------------------------
		if(m_chkSolarIngress.GetCheck() == 0)
		{
			chkSolarIngress = 0;
			m_sliderSolarIngress.EnableWindow(FALSE);
		}
		else
		{
			chkSolarIngress = 1;
			m_sliderSolarIngress.EnableWindow(TRUE);
		}

		//-----------------------------------------
		// OCCUPANCY
		//-----------------------------------------
		if(m_chkOccupancy.GetCheck() == 0)
		{
			chkOccupancy = 0;
			m_sliderOccupancy.EnableWindow(FALSE);
		}
		else
		{
			chkOccupancy = 1;
			m_sliderOccupancy.EnableWindow(TRUE);
		}

		//-----------------------------------------
		// CONROLLED SPACE
		//-----------------------------------------
		if(m_chkControlledSpace.GetCheck() == 0)
		{
			chkControlledSpace = 0;
			m_sliderControllesSpace.EnableWindow(FALSE);
		}
		else
		{
			chkControlledSpace = 1;
			m_sliderControllesSpace.EnableWindow(TRUE);
		}
        
		//-----------------------------------------
		// Heff
		//-----------------------------------------
		if(m_chkHeatingEff.GetCheck() == 0)
		{
			chkHeatingEff = 0;
			m_sliderHeff.EnableWindow(FALSE);
		}
		else
		{
			chkHeatingEff = 1;
			m_sliderHeff.EnableWindow(TRUE);
		}

		//-----------------------------------------
		// DHWeff
		//-----------------------------------------
		if(m_chkDHWEff.GetCheck() == 0)
		{
			chkDHWEff = 0;
			m_sliderDHWeff.EnableWindow(FALSE);
		}
		else
		{
			chkDHWEff = 1;
			m_sliderDHWeff.EnableWindow(TRUE);
		}

		//-----------------------------------------
		// SDHW
		//-----------------------------------------
		if(m_chkSDHW.GetCheck() == 0)
		{
			chkSDHW = 0;
		}
		else
		{
			chkSDHW = 1;
		}

		//-----------------------------------------
		// PV
		//-----------------------------------------
		if(m_chkPV.GetCheck() == 0)
		{
			chkPV = 0;
		}
		else
		{
			chkPV = 1;
		}

		//-----------------------------------------
		// WT
		//-----------------------------------------
		if(m_chkWT.GetCheck() == 0)
		{
			chkWT = 0;
		}
		else
		{
			chkWT = 1;
		}

		//-----------------------------------------
		// uCHP
		//-----------------------------------------
		if(m_chkuCHP.GetCheck() == 0)
		{
			chkuCHP = 0;
		}
		else
		{
			chkuCHP = 1;
		}

		//-----------------------------------------
		// uCHP
		//-----------------------------------------
		if(m_chkuHydro.GetCheck() == 0)
		{
			chkuHydro = 0;
		}
		else
		{
			chkuHydro = 1;
		}

		//-----------------------------------------
		// uHydro
		//-----------------------------------------
		if(m_chkPCM.GetCheck() == 0)
		{
			chkPCM = 0;
		}
		else
		{
			chkPCM = 1;
		}

		//-----------------------------------------
		// uHydro
		//-----------------------------------------
		if(m_chkMVHR.GetCheck() == 0)
		{
			chkMVHR = 0;
		}
		else
		{
			chkMVHR = 1;
		}

		//-----------------------------------------
		// FGHRS and WWHRS
		//-----------------------------------------
		if(m_chkFGHRS.GetCheck() == 0)
		{
			chkFGHRS = 0;
		}
		else
		{
			chkFGHRS = 1;
		}

		if(m_chkWWHRS.GetCheck() == 0)
		{
			chkWWHRS = 0;
		}
		else
		{
			chkWWHRS = 1;
		}		

		// Check buttons to 
		if(m_chkActual.GetCheck() == 0)
		{
			chkActual = 0;
		}
		else
		{
			chkActual = 1;
		}
		
		if(m_chkperm2.GetCheck() == 0)
		{
			chkperm2 = 0;
		}
		else
		{
			chkperm2 = 1;
		}

		if(m_chkEnergy.GetCheck() == 0)
		{
			chkEnergy = 0;
		}
		else
		{
			chkEnergy = 1;
		}

		if(m_chkCost.GetCheck() == 0)
		{
			chkCost = 0;
		}
		else
		{
			chkCost = 1;
		}

		if(m_chkEmissions.GetCheck() == 0)
		{
			chkEmissions = 0;
		}
		else
		{
			chkEmissions = 1;
		}		
	}
	else
	{
		m_btnBase.EnableWindow(FALSE);

		//-----------------------------------------
		// ENERGY DEMAND DETERMINANTS
		//-----------------------------------------
		m_chkInsulation.EnableWindow(FALSE);
		m_chkAirtightness.EnableWindow(FALSE);
		m_chkCapacity.EnableWindow(FALSE);
		m_chkSolarIngress.EnableWindow(FALSE);
		m_chkOccupancy.EnableWindow(FALSE);
		m_chkControlledSpace.EnableWindow(FALSE);

		////-----------------------------------------
		//// ENERGY SUPPLY DETERMINANTS
		////-----------------------------------------
		m_chkHeatingEff.EnableWindow(FALSE);
		m_chkDHWEff.EnableWindow(FALSE);

		//-----------------------------------------
		// INSULATION
		//-----------------------------------------
		chkInsulation = 0;
		m_sliderInsulation.EnableWindow(FALSE);

		//-----------------------------------------
		// AIR TIGHTNESS
		//-----------------------------------------
		chkAirtightness = 0;
		m_sliderAirtightness.EnableWindow(FALSE);

		//-----------------------------------------
		// CAPACITY
		//-----------------------------------------
		chkCapacity = 0;
		m_sliderCapacity.EnableWindow(FALSE);
		
		//-----------------------------------------
		// SOLAR INGRESS
		//-----------------------------------------
		chkSolarIngress = 0;
		m_sliderSolarIngress.EnableWindow(FALSE);

		//-----------------------------------------
		// OCCUPANCY
		//-----------------------------------------
		chkOccupancy = 0;
		m_sliderOccupancy.EnableWindow(FALSE);

		//-----------------------------------------
		// CONROLLED SPACE
		//-----------------------------------------
		chkControlledSpace = 0;
		m_sliderControllesSpace.EnableWindow(FALSE);

		//-----------------------------------------
		// HEATING FUEL
		//-----------------------------------------
		m_comboFuel.EnableWindow(FALSE);

		//-----------------------------------------
		// HEATING EFF
		//-----------------------------------------
		chkHeatingEff = 0;
		m_sliderHeff.EnableWindow(FALSE);
		m_editHeatingEff.EnableWindow(FALSE);

		//-----------------------------------------
		// DHW FUEL
		//-----------------------------------------
		m_comboDHWfuel.EnableWindow(FALSE);

		//-----------------------------------------
		// DHW EFF
		//-----------------------------------------
		chkDHWEff = 0;
		m_sliderDHWeff.EnableWindow(FALSE);
		m_editDHWEff.EnableWindow(FALSE);

		//-----------------------------------------
		// COOLING FUEL
		//-----------------------------------------
		m_comboCoolingFuel.EnableWindow(FALSE);

		//-----------------------------------------
		// COOLING EFF
		//-----------------------------------------
		m_editCoolingEff.EnableWindow(FALSE);

		//-----------------------------------------
		// RENEWABLES
		//-----------------------------------------
		chkSDHW = 0;
		m_chkSDHW.EnableWindow(FALSE);

		chkPV = 0;
		m_chkPV.EnableWindow(FALSE);

		chkWT = 0;
		m_chkWT.EnableWindow(FALSE);

		chkuCHP = 0;
		m_chkuCHP.EnableWindow(FALSE);

		chkuHydro = 0;
		m_chkuHydro.EnableWindow(FALSE);

		chkPCM = 0;
		m_chkPCM.EnableWindow(FALSE);

		chkMVHR = 0;
		m_chkMVHR.EnableWindow(FALSE);

		chkFGHRS = 0;
		m_chkFGHRS.EnableWindow(FALSE);

		chkWWHRS = 0;
		m_chkWWHRS.EnableWindow(FALSE);		
	}

	if(	btnWaterHtFromMainState  == 1)
	{
		// Disable check box and slider
		chkDHWEff = 0;
		m_chkDHWEff.EnableWindow(FALSE);
		m_chkDHWEff.SetCheck(0);
		m_sliderDHWeff.EnableWindow(FALSE);

	}
	else
	{
		// Enable check box and slider
		chkDHWEff = 1;
		m_chkDHWEff.SetCheck(1);
		m_chkDHWEff.EnableWindow(TRUE);
		m_sliderDHWeff.EnableWindow(TRUE);
	}
	//-----------------------------------------------
	// Enable or disable base and improvement buttons
	//-----------------------------------------------
	if(is_base_selected == true)
	{
		m_btnImp1.EnableWindow(TRUE);
	}
	else
	{
		m_btnImp1.EnableWindow(FALSE);
	}

	if(is_imp1_selected == true)
	{
		m_btnImp2.EnableWindow(TRUE);
	}
	else
	{
		m_btnImp2.EnableWindow(FALSE);
	}

	if(is_imp2_selected == true)
	{
		m_btnImp3.EnableWindow(TRUE);
	}
	else
	{
		m_btnImp3.EnableWindow(FALSE);
	}

	if(is_imp3_selected == true)
	{
		m_btnImp4.EnableWindow(TRUE);
	}
	else
	{
		m_btnImp4.EnableWindow(FALSE);
	}

	if(is_imp4_selected == true)
	{
		m_btnImp5.EnableWindow(TRUE);
	}
	else
	{
		m_btnImp5.EnableWindow(FALSE);
	}
}

void CDlg_Results::ReadPreviousInputsForResultsDialog()
{
	if( chkInsulation == 0)
	{
		m_chkInsulation.SetCheck(0);
	}
	else
	{
		m_chkInsulation.SetCheck(1);
	}

	if(chkAirtightness == 0)
	{
		 m_chkAirtightness.SetCheck(0);
	}
	else
	{
		m_chkAirtightness.SetCheck(1);
	}

	if(chkCapacity == 0)
	{
		m_chkCapacity.SetCheck(0); 
	}
	else
	{
		m_chkCapacity.SetCheck(1); 
	}

	if(chkSolarIngress  == 0)
	{
		m_chkSolarIngress.SetCheck(0);
	}
	else
	{
		m_chkSolarIngress.SetCheck(1);
	}

	if(chkOccupancy  == 0)
	{
		 m_chkOccupancy.SetCheck(0);
	}
	else
	{
		m_chkOccupancy.SetCheck(1);
	}

	if(chkControlledSpace  == 0)
	{
		m_chkControlledSpace.SetCheck(0);
	}
	else
	{
		m_chkControlledSpace.SetCheck(1);
	}


	if(chkHeatingEff == 0)
	{
		m_chkHeatingEff.SetCheck(0);
	}
	else
	{
		m_chkHeatingEff.SetCheck(1);
	}


	if(chkSDHW  == 0)
	{
		 m_chkSDHW.SetCheck(0);
	}
	else
	{
		m_chkSDHW.SetCheck(1);
	}

	if(chkPV  == 0)
	{
		 m_chkPV.SetCheck(0);
	}
	else
	{
		m_chkPV.SetCheck(1);
	}

	if(chkWT  == 0)
	{
		 m_chkWT.SetCheck(0);
	}
	else
	{
		m_chkWT.SetCheck(1);
	}

	if(chkuCHP  == 0)
	{
		 m_chkuCHP.SetCheck(0);
	}
	else
	{
		m_chkuCHP.SetCheck(1);
	}

	if(chkuHydro  == 0)
	{
		 m_chkuHydro.SetCheck(0);
	}
	else
	{
		m_chkuHydro.SetCheck(1);
	}

	if(chkPCM  == 0)
	{
		 m_chkPCM.SetCheck(0);
	}
	else
	{
		m_chkPCM.SetCheck(1);
	}

	if(chkMVHR  == 0)
	{
		 m_chkMVHR.SetCheck(0);
	}
	else
	{
		m_chkMVHR.SetCheck(1);
	}

	if(chkFGHRS  == 0)
	{
		 m_chkFGHRS.SetCheck(0);
	}
	else
	{
		m_chkFGHRS.SetCheck(1);
	}

	if(chkWWHRS  == 0)
	{
		 m_chkWWHRS.SetCheck(0);
	}
	else
	{
		m_chkWWHRS.SetCheck(1);
	}


	// Result display options
	if(chkActual  == 0)
	{
		 m_chkActual.SetCheck(0);
	}
	else
	{
		m_chkActual.SetCheck(1);
	}

	if(chkperm2  == 0)
	{
		 m_chkperm2.SetCheck(0);
	}
	else
	{
		m_chkperm2.SetCheck(1);
	}

	if(chkEnergy  == 0)
	{
		 m_chkEnergy.SetCheck(0);
	}
	else
	{
		m_chkEnergy.SetCheck(1);
	}

	if(chkCost  == 0)
	{
		 m_chkCost.SetCheck(0);
	}
	else
	{
		m_chkCost.SetCheck(1);
	}

	if(chkEmissions  == 0)
	{
		 m_chkEmissions.SetCheck(0);
	}
	else
	{
		m_chkEmissions.SetCheck(1);
	}

	if(chkFGHRS  == 0)
	{
		 m_chkFGHRS.SetCheck(0);
	}
	else
	{
		m_chkFGHRS.SetCheck(1);
	}

	if(chkWWHRS  == 0)
	{
		 m_chkWWHRS.SetCheck(0);
	}
	else
	{
		m_chkWWHRS.SetCheck(1);
	}

	m_sliderInsulation.SetPos(hemI_insulationSliderPos);
	m_sliderAirtightness.SetPos(hemA_achSliderPos);
	m_sliderCapacity.SetPos(hemC_capacitySliderPos);
	m_sliderSolarIngress.SetPos(hemS_solarGainsSliderPos);
	m_sliderOccupancy.SetPos(hemO_OCCDensitySliderPos);
	m_sliderControllesSpace.SetPos(hemL_LAFracSliderPos);

	if(mainHtEffNominal <=65) //@min
	{
		m_sliderHeff.SetPos(1);
	}
	else if(mainHtEffNominal >65 && mainHtEffNominal <=80) //@min
	{
		m_sliderHeff.SetPos(2);
	}
	else if(mainHtEffNominal >80)  //@min
	{
		m_sliderHeff.SetPos(3);
	}

	if(WHtEff <=65)
	{
		m_sliderDHWeff.SetPos(1);
	}
	else if(WHtEff >65 && WHtEff <=80)
	{
		m_sliderDHWeff.SetPos(2);
	}
	else if(WHtEff >80)
	{
		m_sliderDHWeff.SetPos(3);
	}

	// Read Inputs from previous dialogs
	if(strcmp(hemHouseType,"Detached")==0)
	{
		m_listHouseType.SetCurSel(0);
	}
	else if(strcmp(hemHouseType,"Semi-detached")==0)
	{
		m_listHouseType.SetCurSel(1);
	}
	else if(strcmp(hemHouseType,"Terraced")==0)
	{
		m_listHouseType.SetCurSel(2);
	}
	else if(strcmp(hemHouseType,"Tenement")==0)
	{
		m_listHouseType.SetCurSel(3);
	}
	else if(strcmp(hemHouseType,"4-in-block")==0)
	{
		m_listHouseType.SetCurSel(4);
	}
	else if(strcmp(hemHouseType,"Tower/Slab")==0)
	{
		m_listHouseType.SetCurSel(5);
	}
	else if(strcmp(hemHouseType,"Conversion")==0)
	{
		m_listHouseType.SetCurSel(6);
	}
	

	if(strcmp(hemYearOfBuild,"pre 1919")==0)
	{
		m_listYearOfBuild.SetCurSel(0);
	}
	else if(strcmp(hemYearOfBuild,"1919-44")==0)
	{
		m_listYearOfBuild.SetCurSel(1);
	}
	else if(strcmp(hemYearOfBuild,"1945-64")==0)
	{
		m_listYearOfBuild.SetCurSel(2);
	}
	else if(strcmp(hemYearOfBuild,"1965-82")==0)
	{
		m_listYearOfBuild.SetCurSel(3);
	}
	else if(strcmp(hemYearOfBuild,"post 1982")==0)
	{
		m_listYearOfBuild.SetCurSel(4);
	}
	else if(strcmp(hemYearOfBuild,"post 2002")==0)
	{
		m_listYearOfBuild.SetCurSel(5);
	}
	else if(strcmp(hemYearOfBuild,"post 2006")==0)
	{
		m_listYearOfBuild.SetCurSel(6);
	}
	else if(strcmp(hemYearOfBuild,"post 2010")==0)
	{
		m_listYearOfBuild.SetCurSel(7);
	}

	str_listYearOfBuild = hemYearOfBuild;
	str_listHouseType   = hemHouseType;
	str_comboClimate    = locationString;

	m_comboClimate.SelectString(0,locationString);
	m_comboFuel.SelectString(0,mainFuel);
	//str_editHeatingEff.Format("%.0f", mainHtEff); @SHG 01.09.11
	
	if(	btnWaterHtFromMainState  == 1)
	{
		m_comboDHWfuel.SelectString(0,"From main");
		WHtEff  = mainHtEffNominal; //@min
		WHtFuel = mainFuel;

		// Disable check box and slider
		m_chkDHWEff.EnableWindow(FALSE);
		m_sliderDHWeff.EnableWindow(FALSE);

	}
	else
	{
		m_comboDHWfuel.SelectString(0,WHtFuel);

		// Disable check box and slider
		m_chkDHWEff.EnableWindow(TRUE);
		m_sliderDHWeff.EnableWindow(TRUE);
	}
	
	// str_editDHWEff.Format("%.0f",WHtEff); @SHG 01.09.11
	m_comboCoolingFuel.SelectString(0,hemCoolingFuel);
	str_editCoolingEff.Format("%.0f",hemCoolingEff);

	if(TFA_from_HEM == true)
	{
		TFA = TFAfromHEM;
	}
	else
	{
		TFA = storey1Area +
		  storey2Area +
		  storey3Area +
		  storey4Area +
		  storey5Area +
		  storey6Area;
	}
	str_editFloorArea.Format("%.0f",TFA);

	UpdateData(FALSE);
}



void CDlg_Results::ReadInputsFromResultsDialog()
{
	UpdateData(true);

	//--------------------------------------------------------
	// Read Context Determinants
	//--------------------------------------------------------
	mainFuel = str_comboFuel;
	
	//mainHtEff = atof(str_editHeatingEff);//edit by min 20143003 @SHG 01.09.11

	if(	str_comboDHWfuel	== "From main")
	{
		btnWaterHtFromMainState = 1;
		WHtEff = mainHtEff;
		WHtFuel = mainFuel;
	}
	else
	{
		btnWaterHtFromMainState = 0;
		WHtFuel = str_comboDHWfuel;		

		//WHtEff  = atof(str_editDHWEff);  @SHG 01.09.11
	}

	hemCoolingFuel = str_comboCoolingFuel;
	hemCoolingEff  = atof(str_editCoolingEff);

	if(strcmp(hemHouseType,"Detached")==0)
	{
		hemX_exposure = "X3";
	}
	else if(strcmp(hemHouseType,"Semi-detached")==0)
	{
		hemX_exposure = "X3";
	}
	else if(strcmp(hemHouseType,"Terraced")==0)
	{
		hemX_exposure = "X3";
	}
	else if(strcmp(hemHouseType,"Terraced")==0)
	{
		hemX_exposure = "X4";
	}
	else if(strcmp(hemHouseType,"4-in-block")==0)
	{
		hemX_exposure = "X1";
	}
	else if(strcmp(hemHouseType,"Tower/Slab")==0)
	{
		hemX_exposure = "X3";
	}
	else if(strcmp(hemHouseType,"Conversion")==0)
	{
		hemX_exposure = "X2";
	}
	
	//----------------------------------------------------------------------
	// Read slider positions and assign XIACSOL index number accordingly
	//----------------------------------------------------------------------
	// INSULATION 
	//----------------------------------------------------------------------
	
	// @SHG 26.09.2011
	// The following code is commented
	//if( hemI_insulationSliderPos== 1)
	//{
	//	hemI_insulation = "I1";
	//}
	//else if( hemI_insulationSliderPos== 2)
	//{
	//	hemI_insulation = "I2";
	//}
	//else if(hemI_insulationSliderPos== 3)
	//{
	//	hemI_insulation = "I3";
	//}
	//else if( hemI_insulationSliderPos == 4)
	//{
	//	hemI_insulation = "I4";
	//}
	//else if( hemI_insulationSliderPos== 5)
	//{
	//	hemI_insulation = "I5";
	//}
	
	//----------------------------------------------------------------------
	// AIR TIGHTNESS 
	//----------------------------------------------------------------------
	if( hemA_achSliderPos == 1)
	{
		hemA_ach = "A1";
		lambda = 0.10;
	}
	else if( hemA_achSliderPos == 2)
	{
		hemA_ach = "A2";
		lambda = 0.15;
	}
	else if( hemA_achSliderPos == 3)
	{
		hemA_ach = "A3";
		lambda = 0.20;
	}
	else if( hemA_achSliderPos == 4)
	{
		hemA_ach = "A4";
		lambda = 0.25;
	}
	else if( hemA_achSliderPos == 5)
	{
		hemA_ach = "A5";
		lambda = 0.30;
	}

	//----------------------------------------------------------------------
	// CAPACITY 
	//----------------------------------------------------------------------
	if( hemC_capacitySliderPos== 1)
	{
		hemC_capacity = "C1";
	}
	else if( hemC_capacitySliderPos== 2)
	{
		hemC_capacity = "C2";
	}

	//----------------------------------------------------------------------
	// SOLAR INGRESS 
	//----------------------------------------------------------------------
	if( hemS_solarGainsSliderPos== 1)
	{
		hemS_solarGains = "S1";
	}
	else if( hemS_solarGainsSliderPos== 2)
	{
		hemS_solarGains = "S2";
	}
	else if( hemS_solarGainsSliderPos == 3)
	{
		hemS_solarGains = "S3";
	}

	//----------------------------------------------------------------------
	// OCCUPANCY 
	//----------------------------------------------------------------------
	if( hemO_OCCDensitySliderPos == 1)
	{
		hemO_occupantDensity = "O1";
	}
	else if( hemO_OCCDensitySliderPos == 2)
	{
		hemO_occupantDensity = "O2";
	}
	else if( hemO_OCCDensitySliderPos == 3)
	{
		hemO_occupantDensity = "O3";
	}
	else if( hemO_OCCDensitySliderPos == 4)
	{
		hemO_occupantDensity = "O4";
	}
	else if( hemO_OCCDensitySliderPos == 5)
	{
		hemO_occupantDensity = "O5";
	}
	
	//----------------------------------------------------------------------
	// CONTROLLED SPACE 
	//----------------------------------------------------------------------
	if( hemL_LAFracSliderPos == 1)
	{
		hemL_livingAreaFraction = "L1";
	}
	else if( hemL_LAFracSliderPos == 2)
	{
		hemL_livingAreaFraction = "L2";
	}
	else if( hemL_LAFracSliderPos == 3)
	{
		hemL_livingAreaFraction = "L3";
	}
	else if( hemL_LAFracSliderPos == 4)
	{
		hemL_livingAreaFraction = "L4";
	}
	else if( hemL_LAFracSliderPos == 5)
	{
		hemL_livingAreaFraction = "L5";
	}
			
	if(strcmp(str_comboDHWfuel, "From main") != 0)
	{
		WHtFuel			= str_comboDHWfuel;
	}
	
	chkHeatingEff= m_chkHeatingEff.GetCheck();
	chkSDHW   = m_chkSDHW.GetCheck();
	chkPV     = m_chkPV.GetCheck();
	chkWT     = m_chkWT.GetCheck();
	chkuCHP   = m_chkuCHP.GetCheck();
	chkuHydro = m_chkuHydro.GetCheck();
	chkPCM    = m_chkPCM.GetCheck();
	chkMVHR   = m_chkMVHR.GetCheck();

	chkFGHRS = m_chkFGHRS.GetCheck();

	chkWWHRS = m_chkWWHRS.GetCheck();

	chkActual    = m_chkActual.GetCheck();
	chkperm2     = m_chkperm2.GetCheck();
	chkEnergy    = m_chkEnergy.GetCheck();
	chkEnergy    = m_chkEnergy.GetCheck();
	chkEmissions = m_chkEmissions.GetCheck();
	
	TFAfromHEM   = atof(str_editFloorArea);

	if(chkSDHW == 1)
	{
		isSHWPresent = "Yes";
	}
	else
	{
		isSHWPresent = "No";
	}

	if(chkPV == 1)
	{
		isPVPresent = "Yes";
	}
	else
	{
		isPVPresent = "No";
	}

	if(chkWT == 1)
	{
		isWTPresent = "Yes";
	}
	else
	{
		isWTPresent = "No";
	}

	if(chkuCHP == 1)
	{
		uCHPyn = "Yes";
	}
	else
	{
		uCHPyn = "No";
	}

	if(chkuHydro == 1)
	{
		uHydroyn = "Yes";
	}
	else
	{
		uHydroyn = "No";
	}


	if(chkMVHR == 1)
	{
		MVHRyn = "Yes";
		// Set ventilation type
		mechVentType = "Balanced (with heat recovery)";
		
		if(is_mvhr_eff_changed == false)
		{
			MVHRThermalEff = 75;
		}

		if (is_spf_changed == false)
		{
			SFP   = 2.0;
		}
		
	}
	else
	{
		MVHRyn = "No";
		// Set ventilation type to natural
		mechVentType = "Not present (natural)";
		SFP   = 1.0;

		// These flags will be set to true when datais read directly form ventilation tabs
		is_mvhr_eff_changed = false;
		is_spf_changed      = false;		
	}
	
	if(chkFGHRS == 1)
		FGHRSpresent = "Yes";
	else
		FGHRSpresent = "No";

	if(chkWWHRS == 1)
		WWHRSpresent = "Yes";
	else
		WWHRSpresent = "No";

	//str_editDHWEff.Format("%.0f",WHtEff);  @SHG 01.09.11
	UpdateData(false);
	CalculateResultsForSAPP(); // 2nd
}

void CDlg_Results::ReadValuesFromSHCSFile()
{
	//--------------------------------------------
	// Select values for y-values
	//--------------------------------------------
	if(strcmp(hemYearOfBuild,"pre 1919")==0)
	{
		hem_yValueEntry = 0.15;
	}
	else if(strcmp(hemYearOfBuild,"1919-44")==0)
	{
		hem_yValueEntry = 0.15;
	}
	else if(strcmp(hemYearOfBuild,"1945-64")==0)
	{
		hem_yValueEntry = 0.15;
	}
	else if(strcmp(hemYearOfBuild,"1965-82")==0)
	{
		hem_yValueEntry = 0.15;
	}
	else if(strcmp(hemYearOfBuild,"post 1982")==0)
	{
		hem_yValueEntry = 0.08;
	}
	else if(strcmp(hemYearOfBuild,"post 2002")==0)
	{
		hem_yValueEntry = 0.08;
	}
	else if(strcmp(hemYearOfBuild,"post 2006")==0)
	{
		hem_yValueEntry = 0.04;
	}
	else if(strcmp(hemYearOfBuild,"post 2010")==0)
	{
		hem_yValueEntry = 0.01;
	}

	//--------------------------------------------
	// Set data for y-values
	//--------------------------------------------

	if(strcmp(hemHouseType,"Detached")==0)
	{
		hem_extAreaSum = 308;
		
		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hem_extUvalueXareaSum = 573;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hem_extUvalueXareaSum = 540;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hem_extUvalueXareaSum = 459;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hem_extUvalueXareaSum = 307;
		}
		else if (strcmp(hemYearOfBuild,"post 1982")==0)
		{
			hem_extUvalueXareaSum = 245;
		}
		else if (strcmp(hemYearOfBuild,"post 2002")==0)
		{
			hem_extUvalueXareaSum = 143;
		}
		else if (strcmp(hemYearOfBuild,"post 2006")==0)
		{
			hem_extUvalueXareaSum = 126;
		}
		else if (strcmp(hemYearOfBuild,"post 2010")==0)
		{
			hem_extUvalueXareaSum = 72;
		}
	}
	else if(strcmp(hemHouseType,"Semi-detached")==0)
	{
		hem_extAreaSum = 182;

		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hem_extUvalueXareaSum = 306;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hem_extUvalueXareaSum = 285;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hem_extUvalueXareaSum = 235;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hem_extUvalueXareaSum = 160;
		}
		else if (strcmp(hemYearOfBuild,"post 1982")==0)
		{
			hem_extUvalueXareaSum = 124;
		}
		else if (strcmp(hemYearOfBuild,"post 2002")==0)
		{
			hem_extUvalueXareaSum = 70;
		}
		else if (strcmp(hemYearOfBuild,"post 2006")==0)
		{
			hem_extUvalueXareaSum = 63;
		}
		else if (strcmp(hemYearOfBuild,"post 2010")==0)
		{
			hem_extUvalueXareaSum = 35;
		}
	}
	else if(strcmp(hemHouseType,"Terraced")==0)
	{
		hem_extAreaSum = 223;
		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hem_extUvalueXareaSum = 410;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hem_extUvalueXareaSum = 384;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hem_extUvalueXareaSum = 321;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hem_extUvalueXareaSum = 214;
		}
		else if (strcmp(hemYearOfBuild,"post 1982")==0)
		{
			hem_extUvalueXareaSum = 171;
		}
		else if (strcmp(hemYearOfBuild,"post 2002")==0)
		{
			hem_extUvalueXareaSum = 97;
		}
		else if (strcmp(hemYearOfBuild,"post 2006")==0)
		{
			hem_extUvalueXareaSum = 77;
		}
		else if (strcmp(hemYearOfBuild,"post 2010")==0)
		{
			hem_extUvalueXareaSum = 48;
		}
	}
	else if(strcmp(hemHouseType,"Tenement")==0)
	{
		hem_extAreaSum = 97;

		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hem_extUvalueXareaSum = 216;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hem_extUvalueXareaSum = 199;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hem_extUvalueXareaSum = 166;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hem_extUvalueXareaSum = 110;
		}
		else if (strcmp(hemYearOfBuild,"post 1982")==0)
		{
			hem_extUvalueXareaSum = 93;
		}
		else if (strcmp(hemYearOfBuild,"post 2002")==0)
		{
			hem_extUvalueXareaSum = 53;
		}
		else if (strcmp(hemYearOfBuild,"post 2006")==0)
		{
			hem_extUvalueXareaSum = 48;
		}
		else if (strcmp(hemYearOfBuild,"post 2010")==0)
		{
			hem_extUvalueXareaSum = 25;
		}
	}
	else if(strcmp(hemHouseType,"4-in-block")==0)
	{
		hem_extAreaSum = 201;

		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hem_extUvalueXareaSum = 297;
		}
		else if (strcmp(hemYearOfBuild,"1919-44")==0)
		{
			hem_extUvalueXareaSum = 279;
		}
		else if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hem_extUvalueXareaSum = 279;
		}
		else if (strcmp(hemYearOfBuild,"1965-82")==0)
		{
			hem_extUvalueXareaSum = 230;
		}
	}
	else if(strcmp(hemHouseType,"Tower/Slab")==0)
	{
		hem_extAreaSum = 160;

		if (strcmp(hemYearOfBuild,"1945-64")==0)
		{
			hem_extUvalueXareaSum = 213;
		}
	}
	else if(strcmp(hemHouseType,"Conversion")==0)
	{
		hem_extAreaSum = 181;

		if(strcmp(hemYearOfBuild,"pre 1919")==0)
		{
			hem_extUvalueXareaSum = 261;
		}		
	}
}

void CDlg_Results::EstablishNumberOfOccupants()
{
	//----------------------------------------------------------------------
	// NUMBER OF OCCUPANTS
	//----------------------------------------------------------------------
	double temp;

	temp = exp ( -0.000349 * (TFA - 13.9) * (TFA - 13.9));
	
	if(TFA <= 13.9)
	{
		numOfOccupants = 1;
	}
	else
	{
		numOfOccupants = 1 + (1.76 * (1 - temp)) + (0.0013 * (TFA - 13.9));
	}
}

void CDlg_Results::CalculateAuxillaryElectricity()
{
	//----------------------------------------------------------------------
	// AUXILLARY ELECTRICITY
	//----------------------------------------------------------------------
	// Calculations for auxilary energy are based on SAP table 4f
	//-----------------------------------
	// Establish value for iStat
	//-----------------------------------
	if(strcmp(  mainHtControls, "No time or thermostatic control of room temperature")==0)
	{
		iStat = 1.3;
	}
	else
	{
		iStat = 1.0;
	}
	
	//-----------------------------------
	// Establish value for dwellingVoulme
	//-----------------------------------
	if(TFA_from_HEM == true)
	{
		TFA = TFAfromHEM;
		dwellingVoulme = TFA * 2.5;
	}
	else
	{
        dwellingVoulme =(storey1Area * storey1Height)+
					(storey2Area * storey2Height)+
					(storey3Area * storey3Height)+
					(storey4Area * storey4Height)+
					(storey5Area * storey5Height)+
					(storey6Area * storey6Height);
	}

	//-----------------------------------
	// Establish value for auxillaryElectricity
	//-----------------------------------
	auxillaryElectricity   = 0;

	bool is_combination_boiler = false;

	if( strcmp( mainHtType,"Boiler")==0)
	{
		auxillaryElectricity+= (130 * iStat);
	}

	if( strcmp( mainFuel,"Oil")==0)
	{
		auxillaryElectricity+= (100 * iStat);
	}

	if(( strcmp( mainFuel,"Mains gas")==0) && (( strcmp( isFanFluePresent,"Yes")==0)  ))
	{
		auxillaryElectricity+= 45;
	}

	if(( strcmp( mainHtType,"Warm air")==0) || ( strcmp( mainHtType,"Heat pump - warm air")==0))
	{
		auxillaryElectricity+= (0.6 * dwellingVoulme);
	}

	//---------------------------------------------------
	// Apply logic for combination boiler
	// For main heating type
	if((mainHtType == "Boiler") &&
	((boilerType == "Combi") || (boilerType == "Condensing combi")))
	{
		is_combination_boiler = true;
	}

	// For water heating type
	if((strcmp(WHtype,"Storage combi boiler - primary store") == 0) ||
	   (strcmp(WHtype,"Storage combi boiler - secondary store") == 0) ||
	   (strcmp(WHtype,"Instantaneous combi with closecoupled external store") == 0))
	{
		is_combination_boiler = true;
	}

	// Apply changes fpr Combi keep hot only in case of combination boiler 
	if(is_combination_boiler == true)
	{
		is_combination_boiler = true;

		if( strcmp( WHtCombiKeepHotYN,"Yes")==0)
		{
			auxillaryElectricity+= 900;
		}

		if(( strcmp( WHtCombiKeepHotYN,"Yes")==0) &&( strcmp( WHtWaterSepTimed,"Yes")==0))
		{
			auxillaryElectricity-= 300;
		}
	}
	 
	if( strcmp( mechVentType,"Not present (natural)")!=0)
	{
		auxillaryElectricity+= (SFP * 1.22 * dwellingVoulme);
	}

	if(strcmp( SHWSolarCircPump, "Electrically powered") ==0) 
	{
		auxillaryElectricity+= 75;
	}

	// Apply changes for mechanical ventilation options
	if (strcmp(mechVentType,"Mechanical extract vent")==0)
	{
		auxillaryElectricity = SFP * 1.22 * dwellingVoulme;
	}
	else if ((strcmp(mechVentType,"Balanced (with heat recovery)")==0) || (strcmp(mechVentType,"Balanced (without heat recovery)")==0))
	{
		auxillaryElectricity = SFP * 2.44 * 0.5 * dwellingVoulme; // 0.5 taken from SAP
	}
	else if (strcmp(mechVentType,"Positive input from outside")==0)
	{
		auxillaryElectricity = SFP * 1.22 * dwellingVoulme;
	}	 
}

void CDlg_Results::CalculateLightingElectricity()
{
	//----------------------------------------------------------------------
	// LIGHTING ENERGY
	//----------------------------------------------------------------------
	// Calculations adre based on SAP appendix L

	// EB is annual energy consumption for lighting if no low-energy lighting is used
	EB = 59.73 * pow((TFA * numOfOccupants), 0.4714);

	// Correction factor, C1 to take account of fixed lighting outlets with low-energy lamps
	C1 = 1 - 0.50 * (fractionLEL/100);

	// Light access factor, ZL

	if(strcmp(winOvershading , "Heavy")==0)
	{
		//ZL = 0.3; //edit by min 20140228
		ZL = 0.3;
	}
	else if(strcmp( winOvershading, "More than average")==0)
	{
		//ZL = 0.3;
		ZL=0.5;
	}
	else if(strcmp( winOvershading, "Average")==0) 
	{
		//ZL = 0.3;
		ZL= 0.7;
	}
	else
	{
	    ZL= 1;
	}

	// gL is the light transmittance factor
	if(strcmp(winGlazing , "Single")==0)
	{
		gL = 0.9;
	}
	else if(strcmp(winGlazing , "Triple")==0)
	{
		gL = 0.7;
	}
	else 
	{
		gL = 0.8;
	}
	
	// GL_total
	/*GL_total =  ((0.9 * winNArea  + gL * winNFrameFactor * ZL) +
				(0.9 * winNEArea + gL * winNEFrameFactor * ZL) +
				(0.9 * winEArea  + gL * winEFrameFactor * ZL) +
				(0.9 * winSEArea + gL * winSEFrameFactor * ZL) +
				(0.9 * winSArea  + gL * winSFrameFactor * ZL) +
				(0.9 * winSWArea + gL * winSWFrameFactor * ZL) +
				(0.9 * winWArea  + gL * winWFrameFactor * ZL) +
				(0.9 * winNWArea + gL * winNWFrameFactor * ZL) +
				(0.9 * rooflightsArea + gL * rooflightsFrameFactor * ZL) ) / TFA;  */
	
	//edit by min 20140228
	
	GL_total =  ((0.9 * winNArea  + gL * winNSolTrans * ZL) +
				(0.9 * winNEArea + gL * winNESolTrans * ZL) +
				(0.9 * winEArea  + gL * winESolTrans * ZL) +
				(0.9 * winSEArea + gL * winSESolTrans * ZL) +
				(0.9 * winSArea  + gL * winSSolTrans * ZL) +
				(0.9 * winSWArea + gL * winSWSolTrans * ZL) +
				(0.9 * winWArea  + gL * winWSolTrans * ZL) +
				(0.9 * winNWArea + gL * winNWSolTrans * ZL) +
				(0.9 * rooflightsArea + gL * rooflightsSolTrans * ZL) ) / TFA; 

 
	// correction factor, C2, for lighting energy use depending on the ratio of glass area to floor area, glass transmittance and light access factor
	C2 = 0.96;



	if(GL_total <= 0.095)
	{
		C2 = (52.2 * (GL_total * GL_total)) - (9.94 * GL_total) + 1.433;
	}

	lightElectricity = EB * C1 * C2; // Eqution L6
}

void CDlg_Results::CalculateDHW()
{
	//----------------------------------------------------------------------
	// DOMESTIC HOT WATER
	//----------------------------------------------------------------------
	// Following main SAP spread sheet
	//----------------------------------------------------------------------
	// Number of days in each month source: SAP table 1a
	monthlyNumOfDays.Jan = 31;
	monthlyNumOfDays.Feb = 28;
	monthlyNumOfDays.Mar = 31;
	monthlyNumOfDays.Apr = 30;
	monthlyNumOfDays.May = 31;
	monthlyNumOfDays.Jun = 30;
	monthlyNumOfDays.Jul = 31;
	monthlyNumOfDays.Aug = 31;
	monthlyNumOfDays.Sep = 30;
	monthlyNumOfDays.Oct = 31;
	monthlyNumOfDays.Nov = 30;
	monthlyNumOfDays.Dec = 31;

	//----------------------------------------------------------------------
	// Monthly DHW usage
	DHW_monthlyUsage.Jan = 1.1;
	DHW_monthlyUsage.Feb = 1.06;
	DHW_monthlyUsage.Mar = 1.02;
	DHW_monthlyUsage.Apr = 0.98;
	DHW_monthlyUsage.May = 0.94;
	DHW_monthlyUsage.Jun = 0.90;
	DHW_monthlyUsage.Jul = 0.90;
	DHW_monthlyUsage.Aug = 0.94;
	DHW_monthlyUsage.Sep = 0.98;
	DHW_monthlyUsage.Oct = 1.02;
	DHW_monthlyUsage.Nov = 1.06;
	DHW_monthlyUsage.Dec = 1.1;

	//----------------------------------------------------------------------
	// Monthly temperature rise source: SAP table 1d
	DHW_monthlyTempRise.Jan = 41.2;
	DHW_monthlyTempRise.Feb = 41.4;
	DHW_monthlyTempRise.Mar = 40.1;
	DHW_monthlyTempRise.Apr = 37.6;
	DHW_monthlyTempRise.May = 36.4;
	DHW_monthlyTempRise.Jun = 33.9;
	DHW_monthlyTempRise.Jul = 30.4;
	DHW_monthlyTempRise.Aug = 33.4;
	DHW_monthlyTempRise.Sep = 33.5;
	DHW_monthlyTempRise.Oct = 36.3;
	DHW_monthlyTempRise.Nov = 39.4;
	DHW_monthlyTempRise.Dec = 39.9;

	//----------------------------------------------------------------------
	// Mothly cold water temperature source: SAP table G2 (Used in WWHR calcs)
	DHW_coldWaterTemp.Jan = 11.1;
	DHW_coldWaterTemp.Feb = 10.8;
	DHW_coldWaterTemp.Mar = 11.8;
	DHW_coldWaterTemp.Apr = 14.7;
	DHW_coldWaterTemp.May = 16.1;
	DHW_coldWaterTemp.Jun = 18.2;
	DHW_coldWaterTemp.Jul = 21.3;
	DHW_coldWaterTemp.Aug = 19.2;
	DHW_coldWaterTemp.Sep = 18.8;
	DHW_coldWaterTemp.Oct = 16.3;
	DHW_coldWaterTemp.Nov = 13.3;
	DHW_coldWaterTemp.Dec = 11.8;

	//----------------------------------------------------------------------
	// Mothly factors for hot water use source: SAP table 1c (Used in WWHR calcs)
	DHW_monthlyFactorsForHotWaterUse.Jan = 1.10;
	DHW_monthlyFactorsForHotWaterUse.Feb = 1.06;
	DHW_monthlyFactorsForHotWaterUse.Mar = 1.02;
	DHW_monthlyFactorsForHotWaterUse.Apr = 0.98;
	DHW_monthlyFactorsForHotWaterUse.May = 0.94;
	DHW_monthlyFactorsForHotWaterUse.Jun = 0.90;
	DHW_monthlyFactorsForHotWaterUse.Jul = 0.90;
	DHW_monthlyFactorsForHotWaterUse.Aug = 0.94;
	DHW_monthlyFactorsForHotWaterUse.Sep = 0.98;
	DHW_monthlyFactorsForHotWaterUse.Oct = 1.02;
	DHW_monthlyFactorsForHotWaterUse.Nov = 1.06;
	DHW_monthlyFactorsForHotWaterUse.Dec = 1.10;
		
	// daily hot water demand
	Vd_avg = 25 * numOfOccupants + 36;

	DHW_energy =(Vd_avg * monthlyNumOfDays.Jan * 4.19 * DHW_monthlyTempRise.Jan * DHW_monthlyUsage.Jan)+
				(Vd_avg * monthlyNumOfDays.Feb * 4.19 * DHW_monthlyTempRise.Feb * DHW_monthlyUsage.Feb)+
				(Vd_avg * monthlyNumOfDays.Mar * 4.19 * DHW_monthlyTempRise.Mar * DHW_monthlyUsage.Mar)+
				(Vd_avg * monthlyNumOfDays.Apr * 4.19 * DHW_monthlyTempRise.Apr * DHW_monthlyUsage.Apr)+
				(Vd_avg * monthlyNumOfDays.May * 4.19 * DHW_monthlyTempRise.Jan * DHW_monthlyUsage.May)+
				(Vd_avg * monthlyNumOfDays.Jun * 4.19 * DHW_monthlyTempRise.Jun * DHW_monthlyUsage.Jun)+
				(Vd_avg * monthlyNumOfDays.Jul * 4.19 * DHW_monthlyTempRise.Jul * DHW_monthlyUsage.Jul)+
				(Vd_avg * monthlyNumOfDays.Aug * 4.19 * DHW_monthlyTempRise.Aug * DHW_monthlyUsage.Aug)+
				(Vd_avg * monthlyNumOfDays.Sep * 4.19 * DHW_monthlyTempRise.Sep * DHW_monthlyUsage.Sep)+
				(Vd_avg * monthlyNumOfDays.Oct * 4.19 * DHW_monthlyTempRise.Oct * DHW_monthlyUsage.Oct)+
				(Vd_avg * monthlyNumOfDays.Nov * 4.19 * DHW_monthlyTempRise.Nov * DHW_monthlyUsage.Nov)+
				(Vd_avg * monthlyNumOfDays.Dec * 4.19 * DHW_monthlyTempRise.Dec * DHW_monthlyUsage.Dec);

	DHW_energy = DHW_energy / (WHtEff/100);

	if(strcmp(uCHPyn,"Yes") ==0)
	{
		DHW_energy = DHW_energy / (uCHPHeatingEff/100);
	}

	DHW_energy = DHW_energy/3600;
}

void CDlg_Results::SubtractDHWLossFromSpaceHeatingRequirement()
{
	//-----------------------------------------------------
	// Subtract DHW loss from space heating requirements
	//-----------------------------------------------------
	DHWspaceHeatingGain = 0;
	usefulStorageLoss   = 0;
	isCylinderPresent   = true;

	// If DHW is form main
	if(btnWaterHtFromMainState == 1)
	{
		if((strcmp( boilerType,"Combi")==0) || (strcmp(boilerType ,"Condensing combi")==0))
		{
			isCylinderPresent = false;
		}
	}
	else
	{
		if((strcmp(WHtype,"Instantaneous combi with closecoupled external store") ==0) || (strcmp(WHtype,"Instantaneous at point of use") ==0))
		{
			isCylinderPresent = false;
		}
	}

	if(isCylinderPresent == true)
	{
		if(strcmp(WHtCylInHeatedSpace,"Yes")==0)
		{
			usefulStorageLoss = storageLoss;
		}
	}

	DHWspaceHeatingGain = (0.25 * (0.85 * DHW_energy + combiLoss))+
		(0.8 * (distributionLoss + usefulStorageLoss + primaryCircuitLoss));

	// Subtract DHWspaceHeatingGain from spaceHeatingDemand
	spaceHeatingDemand  = spaceHeatingDemand  - DHWspaceHeatingGain;
}

void CDlg_Results::CalculateFGHRS()
{
	//-----------------------------------------------------
	// FGHRS 
	//-----------------------------------------------------

	// Misc variables to be used in calculations
	double Vk   = 0; // storage voulume of cylinder
	double kn   = 0;
	double Qsp  = 0; // average space heating demand
	double Qsp1 = 0;
	double Qsp2 = 0;
	double s1   = 0;
	double s2   = 0;
	double s    = 0;
	double Qc   = 0;
	double Qce  = 0;
	double Qloss = 0;
	double sol_available = 0;
	double annualSolarRadiation = 0;
	double overshadingFactor = 0;
	double FGHRS_slr = 0;
	double FGHRS_UF = 0;
	double FGHRS_Veff = 0;
	double FGHRS_volRatio = 0;
	double FGHRS_volFactor = 0;
	double a1 = 0;
	double a2 = 0;
	double b1 = 0;
	double b2 = 0;
	double c1 = 0;
	double c2 = 0;

	//-----------------------------------------------------
	// Set value to zero before calculting new savings
	FGHRS_saving = 0;
	FGHRS_PVinput = 0;

	//---------------------------------------------------------
	// Annual solar radation
	//---------------------------------------------------------		
	if(FGHRSpvOrientation == "South")
	{
		if(FGHRSpvTilt == "30 deg")
		{
			annualSolarRadiation = 1073;	
		}
		else if(FGHRSpvTilt == "45 deg")
		{
			annualSolarRadiation = 1054;	
		}
		else if(FGHRSpvTilt == "60 deg")
		{
			annualSolarRadiation = 989;	
		}
		else if(FGHRSpvTilt == "Vertical")
		{
			annualSolarRadiation = 746;	
		}
	}
	else if(FGHRSpvOrientation == "SE/SW")
	{
		if(FGHRSpvTilt == "30 deg")
		{
			annualSolarRadiation = 1027;	
		}
		else if(FGHRSpvTilt == "45 deg")
		{
			annualSolarRadiation = 997;	
		}
		else if(FGHRSpvTilt == "60 deg")
		{
			annualSolarRadiation = 927;	
		}
		else if(FGHRSpvTilt == "Vertical")
		{
			annualSolarRadiation = 705;	
		}
	}
	else if(FGHRSpvOrientation == "E/W")
	{
		if(FGHRSpvTilt == "30 deg")
		{
			annualSolarRadiation = 913;	
		}
		else if(FGHRSpvTilt == "45 deg")
		{
			annualSolarRadiation = 854;	
		}
		else if(FGHRSpvTilt == "60 deg")
		{
			annualSolarRadiation = 776;	
		}
		else if(FGHRSpvTilt == "Vertical")
		{
			annualSolarRadiation = 582;	
		}
	}
	else if(FGHRSpvOrientation == "NE/NW")
	{
		if(FGHRSpvTilt == "30 deg")
		{
			annualSolarRadiation = 785;	
		}
		else if(FGHRSpvTilt == "45 deg")
		{
			annualSolarRadiation = 686;	
		}
		else if(FGHRSpvTilt == "60 deg")
		{
			annualSolarRadiation = 597;	
		}
		else if(FGHRSpvTilt == "Vertical")
		{
			annualSolarRadiation = 440;	
		}
	}
	else if(FGHRSpvOrientation == "North")
	{
		if(FGHRSpvTilt == "30 deg")
		{
			annualSolarRadiation = 730;	
		}
		else if(FGHRSpvTilt == "45 deg")
		{
			annualSolarRadiation = 640;	
		}
		else if(FGHRSpvTilt == "60 deg")
		{
			annualSolarRadiation = 500;	
		}
		else if(FGHRSpvTilt == "Vertical")
		{
			annualSolarRadiation = 371;	
		}
	}
	if(FGHRSpvTilt == "Horizontal")
	{
		annualSolarRadiation = 961;	
	}

	//---------------------------------------------------------
	//Overshading Factor
	//---------------------------------------------------------
	if(strcmp(FGHRSpvOvershading,"Heavy > 80%")==0)
	{
		overshadingFactor = 0.5;
	} 
	else if(strcmp(FGHRSpvOvershading,"Significant > 60%-80%")==0)
	{
		overshadingFactor = 0.65;
	}
	else if(strcmp(FGHRSpvOvershading,"Modest 20%-60%")==0)
	{
		overshadingFactor = 0.8;
	}
	else if(strcmp(FGHRSpvOvershading,"None or Very Little < 20%")==0)
	{
		overshadingFactor = 1.0;
	}
	else if(strcmp(FGHRSpvOvershading,"Unknown")==0)
	{
		overshadingFactor = 0.5;
	}
	//----------------------------------------------------------------------------
	// Establish Vk and kn
	//----------------------------------------------------------------------------
	Vk = WHtCylVolume;

	if((strcmp( WHtype,"Storage combi boiler - primary store")==0) ||
		(strcmp(WHtype ,"Instantaneous combi with closecoupled external store")==0))
	{
		Vk = 1.3 * Vk;
	}

	if(Vk >= 144)
		kn   = 0;
	else if(Vk >= 75)
		kn   = 0.48 - (Vk/300);
	else if(Vk >15)
		kn   = 1.1925 - 0.787 * (Vk/60);
	else 
		kn   = 1;

	//-----------------------------------------------------------------
	// If there is no FGHRS heat store
	//-----------------------------------------------------------------
	if(strcmp(FGHRSstore,"No")==0)
	{
		FGHRS_saving = FGHRSusefulFracHtRec_kf1 * kn * (DHW_energy - WWHRS_savings);
	}
	else
	{
		Qsp = 0;

		if(strcmp(FGHRSfittedMain,"Yes")==0)
			Qsp = spaceHeatingDemand * mainHtFractionSupplied;
		if (strcmp(FGHRSfittedSec,"Yes")==0)
			Qsp = spaceHeatingDemand * secHtFraction;
		if((strcmp(FGHRSfittedMain,"Yes")==0) && (strcmp(FGHRSfittedSec,"Yes")==0))
			Qsp = spaceHeatingDemand;

		Qsp = Qsp/12; // average space heating demand

		//-----------------------------------------------------------------
		// Qsp1 and Qsp2 immediately flank Qsp from FGHRS tables
		//-----------------------------------------------------------------

		unsigned int i = 0;

		// Boiler type inst combi no keep hot or close coupled store is one type
		// All else if other type

		for(i = 0; i < FGHRS_combiData.size(); i++)
		{
			if(strcmp(determineFGHRStype,"Yes")==0)
			{
				if(strcmp(FGHRS_combiData[i].FGHRSname,FGHRStype)==0)
				{
					if((Qsp>=FGHRS_combiData[i].Qsp_1) && (Qsp<FGHRS_combiData[i].Qsp_2))
					{
						a1 = FGHRS_combiData[i].Qsp1a_keepHot;
						a2 = FGHRS_combiData[i].Qsp2a_keepHot;
						b1 = FGHRS_combiData[i].Qsp1b_keepHot;
						b2 = FGHRS_combiData[i].Qsp2b_keepHot;
						c1 = FGHRS_combiData[i].Qsp1c_keepHot;
						c2 = FGHRS_combiData[i].Qsp2c_keepHot;
						Qsp1 = FGHRS_combiData[i].Qsp_1;
						Qsp2 = FGHRS_combiData[i].Qsp_2;
					}
					if((Qsp>=FGHRS_combiData[i].Qsp_2) && (Qsp<FGHRS_combiData[i].Qsp_3))
					{
						a1 = FGHRS_combiData[i].Qsp2a_keepHot;
						a2 = FGHRS_combiData[i].Qsp3a_keepHot;
						b1 = FGHRS_combiData[i].Qsp2b_keepHot;
						b2 = FGHRS_combiData[i].Qsp3b_keepHot;
						c1 = FGHRS_combiData[i].Qsp2c_keepHot;
						c2 = FGHRS_combiData[i].Qsp3c_keepHot;
						Qsp1 = FGHRS_combiData[i].Qsp_2;
						Qsp2 = FGHRS_combiData[i].Qsp_3;
					}
					if((Qsp>=FGHRS_combiData[i].Qsp_3) && (Qsp<FGHRS_combiData[i].Qsp_4))
					{
						a1 = FGHRS_combiData[i].Qsp3a_keepHot;
						a2 = FGHRS_combiData[i].Qsp4a_keepHot;
						b1 = FGHRS_combiData[i].Qsp3b_keepHot;
						b2 = FGHRS_combiData[i].Qsp4b_keepHot;
						c1 = FGHRS_combiData[i].Qsp3c_keepHot;
						c2 = FGHRS_combiData[i].Qsp4c_keepHot;
						Qsp1 = FGHRS_combiData[i].Qsp_3;
						Qsp2 = FGHRS_combiData[i].Qsp_4;
					}
					if((Qsp>=FGHRS_combiData[i].Qsp_4) && (Qsp<FGHRS_combiData[i].Qsp_5))
					{
						a1 = FGHRS_combiData[i].Qsp4a_keepHot;
						a2 = FGHRS_combiData[i].Qsp5a_keepHot;
						b1 = FGHRS_combiData[i].Qsp4b_keepHot;
						b2 = FGHRS_combiData[i].Qsp5b_keepHot;
						c1 = FGHRS_combiData[i].Qsp4c_keepHot;
						c2 = FGHRS_combiData[i].Qsp5c_keepHot;
						Qsp1 = FGHRS_combiData[i].Qsp_4;
						Qsp2 = FGHRS_combiData[i].Qsp_5;
					}
					if((Qsp>=FGHRS_combiData[i].Qsp_5) && (Qsp<=FGHRS_combiData[i].Qsp_6))
					{
						a1 = FGHRS_combiData[i].Qsp5a_keepHot;
						a2 = FGHRS_combiData[i].Qsp6a_keepHot;
						b1 = FGHRS_combiData[i].Qsp5b_keepHot;
						b2 = FGHRS_combiData[i].Qsp6b_keepHot;
						c1 = FGHRS_combiData[i].Qsp5c_keepHot;
						c2 = FGHRS_combiData[i].Qsp6c_keepHot;
						Qsp1 = FGHRS_combiData[i].Qsp_5;
						Qsp2 = FGHRS_combiData[i].Qsp_6;
					}
				}

			}
			else
			{
				if(strcmp(FGHRS_combiData[i].FGHRSname,FGHRStype)==0)
					{
						if((Qsp>=FGHRS_combiData[i].Qsp_1) && (Qsp<FGHRS_combiData[i].Qsp_2))
						{
							a1 = FGHRS_combiData[i].Qsp1a_otherCombi;
							a2 = FGHRS_combiData[i].Qsp2a_otherCombi;
							b1 = FGHRS_combiData[i].Qsp1b_otherCombi;
							b2 = FGHRS_combiData[i].Qsp2b_otherCombi;
							c1 = FGHRS_combiData[i].Qsp1c_otherCombi;
							c2 = FGHRS_combiData[i].Qsp2c_otherCombi;
							Qsp1 = FGHRS_combiData[i].Qsp_1;
							Qsp2 = FGHRS_combiData[i].Qsp_2;
						}
						if((Qsp>=FGHRS_combiData[i].Qsp_2) && (Qsp<FGHRS_combiData[i].Qsp_3))
						{
							a1 = FGHRS_combiData[i].Qsp2a_otherCombi;
							a2 = FGHRS_combiData[i].Qsp3a_otherCombi;
							b1 = FGHRS_combiData[i].Qsp2b_otherCombi;
							b2 = FGHRS_combiData[i].Qsp3b_otherCombi;
							c1 = FGHRS_combiData[i].Qsp2c_otherCombi;
							c2 = FGHRS_combiData[i].Qsp3c_otherCombi;
							Qsp1 = FGHRS_combiData[i].Qsp_2;
							Qsp2 = FGHRS_combiData[i].Qsp_3;
						}
						if((Qsp>=FGHRS_combiData[i].Qsp_3) && (Qsp<FGHRS_combiData[i].Qsp_4))
						{
							a1 = FGHRS_combiData[i].Qsp3a_otherCombi;
							a2 = FGHRS_combiData[i].Qsp4a_otherCombi;
							b1 = FGHRS_combiData[i].Qsp3b_otherCombi;
							b2 = FGHRS_combiData[i].Qsp4b_otherCombi;
							c1 = FGHRS_combiData[i].Qsp3c_otherCombi;
							c2 = FGHRS_combiData[i].Qsp4c_otherCombi;
							Qsp1 = FGHRS_combiData[i].Qsp_3;
							Qsp2 = FGHRS_combiData[i].Qsp_4;
						}
						if((Qsp>=FGHRS_combiData[i].Qsp_4) && (Qsp<FGHRS_combiData[i].Qsp_5))
						{
							a1 = FGHRS_combiData[i].Qsp4a_otherCombi;
							a2 = FGHRS_combiData[i].Qsp5a_otherCombi;
							b1 = FGHRS_combiData[i].Qsp4b_otherCombi;
							b2 = FGHRS_combiData[i].Qsp5b_otherCombi;
							c1 = FGHRS_combiData[i].Qsp4c_otherCombi;
							c2 = FGHRS_combiData[i].Qsp5c_otherCombi;
							Qsp1 = FGHRS_combiData[i].Qsp_4;
							Qsp2 = FGHRS_combiData[i].Qsp_5;
						}
						if((Qsp>=FGHRS_combiData[i].Qsp_5) && (Qsp<=FGHRS_combiData[i].Qsp_6))
						{
							a1 = FGHRS_combiData[i].Qsp5a_otherCombi;
							a2 = FGHRS_combiData[i].Qsp6a_otherCombi;
							b1 = FGHRS_combiData[i].Qsp5b_otherCombi;
							b2 = FGHRS_combiData[i].Qsp6b_otherCombi;
							c1 = FGHRS_combiData[i].Qsp5c_otherCombi;
							c2 = FGHRS_combiData[i].Qsp6c_otherCombi;
							Qsp1 = FGHRS_combiData[i].Qsp_5;
							Qsp2 = FGHRS_combiData[i].Qsp_6;
						}
					}
				}			
		}

		// Get a, b, c for Qsp1 & Qsp2 ie for that type of FGHRS and type of boiler
		// Int combi no keep hot or close coupled store is one type all else is other type

		s1 = (a1 * log((DHW_energy/12))) + (b1 * (DHW_energy/12)) + c1;
		s2 = (a2 * log((DHW_energy/12))) + (b2 * (DHW_energy/12)) + c2;
		s = 12 * (s2 + (s1 - s2) * ((Qsp - Qsp2)/(Qsp1 - Qsp2)));

		Qc  = combiLoss;
		Qce =  0; //  electrical energy used in month m by the keep-hotsource: SAP table 4f	

		// Keep hot facility of a combi boiler
		if(((strcmp(WHtype,"Storage combi boiler - primary store")==0) || (strcmp(WHtype,"Storage combi boiler - secondary store")==0) || (strcmp(WHtype,"Instantaneous combi with closecoupled external store")==0))
			&& ((strcmp(WHtCombiKeepHotYN,"Yes)")==0)))
		{
			if(strcmp(mainHtControls, "Time and temperature zone control")==0)
			{
				Qce = 600;
			}
			if(strcmp(mainHtControls, "No time or thermostatic control of room temperature")==0)
			{
				Qce = 900;
			}
		}

		Qloss = storageLoss + primaryCircuitLoss+ combiLoss;

		if(strcmp(WHtype,"Instantaneous at point of use")==0)
		{
			FGHRS_saving = s;
		}

		else if(((strcmp(WHtype,"Storage combi boiler - primary store")==0) || (strcmp(WHtype,"Storage combi boiler - secondary store")==0) || (strcmp(WHtype,"Instantaneous combi with closecoupled external store")==0))
			&& ((strcmp(WHtCombiKeepHotYN,"Yes)")==0)))
		{
			FGHRS_saving = s + 0.5 + FGHRStotFracHeatRec_kf2 * (Qc - Qce);
		}
		else if((strcmp(WHtype,"Storage combi boiler - primary store")==0) ||
			(strcmp(WHtype,"Storage combi boiler - secondary store")==0)||
			(strcmp(WHtype,"Cylinder - indirect")==0)||
			(strcmp(WHtype,"Hot water only thermal store")==0)||
			(strcmp(WHtype,"Instantaneous combi with closecoupled external store")==0))
		{
			FGHRS_saving = s + 0.5 + FGHRStotFracHeatRec_kf2 * (Qloss - ( 1 - kn) * (DHW_energy - WWHRS_savings));
		}			

		//---------------------------------------------------------
		// Now add FGHRSauxelec to auxillaryElectricity
		auxillaryElectricity = auxillaryElectricity + FGHRSauxelec;

		//---------------------------------------------------------
		// If PV powered heating is present
		if(strcmp(FGHRSpvPoweredHt,"Yes")==0)
		{
			sol_available = 0.84 * FGHRSpvPkPower * annualSolarRadiation * overshadingFactor * (1 - FGHRScableLoss);
			FGHRS_slr = sol_available/DHW_energy;

			if(FGHRS_slr >0)
				FGHRS_UF = 1 - (exp (-(1/(FGHRS_slr))));
			else
				FGHRS_UF = 0;

			FGHRS_Veff = 0.76 * Vk;
			
			FGHRS_volRatio = FGHRS_Veff/Vd_avg; // daily average volume use

			FGHRS_volFactor = 1 + 0.2 * log(FGHRS_volRatio);

			if(FGHRS_volFactor >1)
				FGHRS_volFactor = 1;

			FGHRS_PVinput = sol_available * FGHRS_UF * FGHRS_volFactor;
		}
	}
}

void CDlg_Results::CalculateWWHRS()
{
	//-----------------------------------------------------
	// WWHRS
	//-----------------------------------------------------
	double WWHRS_Seff = 0;
	double UF1_sys1 = 0;
	double UF2_sys1 = 0;
	double UF1_sys2 = 0;
	double UF2_sys2 = 0;
	double heatRecoveryEff1_sys1 = 0;
	double heatRecoveryEff2_sys1 = 0;
	double heatRecoveryEff1_sys2 = 0;
	double heatRecoveryEff2_sys2 = 0;
	double sumDHW_monthlyTempRise = 0;
	double sumDHW_coldWaterTemp   = 0;
	double sumMonthlyNumOfDays    = 0;
	double sumMonthlyFactorsForHotWaterUse    = 0;
	double WWHRS_Seff1 = 0;
	double WWHRS_Seff2 = 0;
	double Awm = 0;
	double Bwm = 0;

	WWHRS_savings = 0;

	//-----------------------------------------------------------------------------
	// Read UF1, heatRecoveryEff1 and UF2, heatRecoveryEff2 from WWHRS data file
	//-----------------------------------------------------------------------------
	unsigned int i = 0;

	for(i = 0; i < WWHRSData_1.size(); i++)
	{
		if((strcmp(WWHRS1Make,WWHRSData_1[i].make) ==0) 
			&& (strcmp(WWHRS1Model,WWHRSData_1[i].model) ==0)
			 && (strcmp(WWHRS1ModelQualifier,WWHRSData_1[i].modelQualifier) ==0))
		{
			heatRecoveryEff1_sys1 = WWHRSData_1[i].effeciencyMixer;
			heatRecoveryEff2_sys1 = WWHRSData_1[i].effeciencyInstElec;
			UF1_sys1 = WWHRSData_1[i].UfMixer;
			UF2_sys1 = WWHRSData_1[i].UfinstElec;
		}

		if((strcmp(WWHRS2Make,WWHRSData_1[i].make) ==0) 
			&& (strcmp(WWHRS2Model,WWHRSData_1[i].model) ==0)
			 && (strcmp(WWHRS2ModelQualifier,WWHRSData_1[i].modelQualifier) ==0))
		{
			heatRecoveryEff1_sys2 = WWHRSData_1[i].effeciencyMixer;
			heatRecoveryEff2_sys2 = WWHRSData_1[i].effeciencyInstElec;
			UF1_sys2 = WWHRSData_1[i].UfMixer;
			UF2_sys2 = WWHRSData_1[i].UfinstElec;
		}
	}	

	//----------------------------------------------------------------------
	// Sum of monthy tempreature rise factors
	sumDHW_monthlyTempRise = DHW_monthlyTempRise.Jan +
		DHW_monthlyTempRise.Feb +
		DHW_monthlyTempRise.Mar +
		DHW_monthlyTempRise.Apr +
		DHW_monthlyTempRise.May +
		DHW_monthlyTempRise.Jun +
		DHW_monthlyTempRise.Jul +
		DHW_monthlyTempRise.Aug +
		DHW_monthlyTempRise.Sep +
		DHW_monthlyTempRise.Oct +
		DHW_monthlyTempRise.Nov +
		DHW_monthlyTempRise.Dec;

	//----------------------------------------------------------------------
	// Sum of monthy cold water temperature rise
	sumDHW_coldWaterTemp = DHW_coldWaterTemp.Jan +
		DHW_coldWaterTemp.Feb +
		DHW_coldWaterTemp.Mar +
		DHW_coldWaterTemp.Apr +
		DHW_coldWaterTemp.May +
		DHW_coldWaterTemp.Jun +
		DHW_coldWaterTemp.Jul +
		DHW_coldWaterTemp.Aug +
		DHW_coldWaterTemp.Sep +
		DHW_coldWaterTemp.Oct +
		DHW_coldWaterTemp.Nov +
		DHW_coldWaterTemp.Dec ;

	//----------------------------------------------------------------------
	// Sum of monthy number of days
	sumMonthlyNumOfDays = monthlyNumOfDays.Jan+
		monthlyNumOfDays.Feb +
		monthlyNumOfDays.Mar +
		monthlyNumOfDays.Apr +
		monthlyNumOfDays.May +
		monthlyNumOfDays.Jun +
		monthlyNumOfDays.Jul +
		monthlyNumOfDays.Aug +
		monthlyNumOfDays.Sep +
		monthlyNumOfDays.Oct +
		monthlyNumOfDays.Nov +
		monthlyNumOfDays.Dec;

	//----------------------------------------------------------------------
	// Sum of monthy factors for hot water use
	sumMonthlyFactorsForHotWaterUse = DHW_monthlyFactorsForHotWaterUse.Jan +
		DHW_monthlyFactorsForHotWaterUse.Feb +
		DHW_monthlyFactorsForHotWaterUse.Mar +
		DHW_monthlyFactorsForHotWaterUse.Apr +
		DHW_monthlyFactorsForHotWaterUse.May +
		DHW_monthlyFactorsForHotWaterUse.Jun +
		DHW_monthlyFactorsForHotWaterUse.Jul +
		DHW_monthlyFactorsForHotWaterUse.Aug +
		DHW_monthlyFactorsForHotWaterUse.Sep +
		DHW_monthlyFactorsForHotWaterUse.Oct +
		DHW_monthlyFactorsForHotWaterUse.Nov +
		DHW_monthlyFactorsForHotWaterUse.Dec;

	// Calculate average system effectiveness

	WWHRS_Seff1 = ((WWHRSnumMixerShowersWithBath1 * 0.635 + WWHRSnumMixerShowersWithoutBath1)* UF1_sys1 * heatRecoveryEff1_sys1) +
				  ((WWHRSnumMixerShowersWithBath2 * 0.635 + WWHRSnumMixerShowersWithoutBath2)* UF1_sys2 * heatRecoveryEff1_sys2);
	
	WWHRS_Seff2 = ((WWHRSnumMixerShowersWithBath1 * 0.635 + WWHRSnumMixerShowersWithoutBath1)* UF2_sys1 * heatRecoveryEff2_sys1) + 
		          ((WWHRSnumMixerShowersWithBath2 * 0.635 + WWHRSnumMixerShowersWithoutBath2)* UF2_sys2 * heatRecoveryEff2_sys2);

	WWHRS_Seff = (WWHRS_Seff1 + WWHRS_Seff2)/WWHRSnumOfRooms;

	Awm = ((0.33 * 25 * sumDHW_monthlyTempRise)/(41 - sumDHW_coldWaterTemp)) + 26.1;
	Bwm = ((0.33 * 36 * sumDHW_monthlyTempRise)/(41 - sumDHW_coldWaterTemp));

	WWHRS_savings = ((numOfOccupants * Awm + Bwm) * WWHRS_Seff * (35 - sumDHW_coldWaterTemp) *  4.18 * sumMonthlyNumOfDays * sumMonthlyFactorsForHotWaterUse) / 3600;
}

void CDlg_Results::CalculateDistributionLosses()
{
	//-----------------------------------------------------
	// DISTRIBUTION LOSSES
	//-----------------------------------------------------
	if(strcmp(WHtype,"Instantaneous at point of use")!=0)
	{
		distributionLoss = 0.15 * DHW_energy;
	}
	else
	{
		distributionLoss = 0;
	}
}

void CDlg_Results::CalculateStorageLosses()
{
	storageLoss = 0;
	//-----------------------------------------------------
	// STORAGE LOSS
	//-----------------------------------------------------
	// Establish Temp factor and loss factor from SAP2009 Table 2b	
	if(strcmp(WHtype,"Cylinder - electric immersion") == 0)
	{
		tempFactor = 0.60;
	}
	if(strcmp(WHtype,"Cylinder - indirect") == 0)
	{
		tempFactor = 0.60;
	}
	if(strcmp(WHtype,"Storage combi boiler - primary store") == 0)
	{
		tempFactor = 0;			
	}
	if(strcmp(WHtype,"Storage combi boiler - secondary store") == 0)
	{
		tempFactor = 0;
	}
	if(strcmp(WHtype,"Instantaneous combi with closecoupled external store") == 0)
	{
		tempFactor = 0.60;
	}
	if(strcmp(WHtype,"Hot water only thermal store") == 0)
	{
		tempFactor = 0.89;
	}
	if(strcmp(WHtype,"Integrated thermal store and gas-fired CPSU") == 0)
	{
		tempFactor = 0.89;
	}
	if(strcmp(WHtype,"Electric CPSU: for winter operating temperature") == 0)
	{
		tempFactor = 1.09 + (winterOpTemp - 85);
	}
	if(strcmp(WHtype,"Plate heat exchanger in a community system") == 0)
	{
		tempFactor = 1.0;
	}	
	
	//Calcs based on SAP2009 Table 2b notes
	if(( strcmp(WHtCylThermostat,"Known")==0) ||
		( strcmp(WHtCylThermostat,"No")==0))
	{
		tempFactor = tempFactor * 1.3;
	}

	 lossFactor = WHtCylDeclaredFactor;
	//-----------------------------------------------------
	if(strcmp(WHtCylManufactLossFactor,"Known") == 0)
	{	
		storageLoss = lossFactor * tempFactor;
	}
	else
	{
		if(strcmp(DHWfromCommunityScheme,"Yes")==0)
		{
			tankVolume = 110;
		}
		else
		{
			tankVolume = WHtCylVolume;
		}
		
	
		if(tankVolume == 0) 
		{
			volumeFacor = 0;
		}
		else
		{
			volumeFacor = pow((120/tankVolume),(0.333)); // Implementing SAP table 2a
		}
				
		heatLossFactor = 1;

		// Implement SAP table 2
		if(strcmp(WHtCylInsType,"Loose jacket")==0)
		{
			heatLossFactor = 0.005 + (1.76/( WHtCylInsThickness + 1.28));
		}
		else if((strcmp(WHtCylInsType,"Loose jacket")==0) || (strcmp(WHtCylInsType,"Loose jacket")==0))
		{
			heatLossFactor = 0.005 + (0.55/( WHtCylInsThickness + 1.28));
		}
		
		storageLoss = tankVolume * volumeFacor * heatLossFactor * tempFactor;
	}//... if(strcmp(WHtCylManufactLossFactor,"Known") == 0) ends here

	//-----------------------------------------------------
	if(strcmp(WHtype,"Electric CPSU: for winter operating temperature") == 0)
	{	
		storageLoss = tankVolume  * 0.022;
		storageLoss = storageLoss * 365;
		storageLoss = storageLoss * ((50 - SHWDedSolStoreVol)/50);
	}

	if(strcmp(WHtype,"Instantaneous at point of use")==0)
	{
		storageLoss = 0;
	}	
}

void CDlg_Results::CalculatePrimaryCircuitLosses()
{
	primaryCircuitLoss = 0;

	//-----------------------------------------------------
	// PRIMARY CIRCUIT LOSS
	//-----------------------------------------------------
	// Calculations based on SAP table 3
	if(strcmp(WHtCylThermostat,"No") == 0) 
	{
		if(strcmp(WHtCylPrimaryPipeworkInsulated,"Yes")==0)
		{
			primaryCircuitLoss = 610;
		}
		else
		{
			primaryCircuitLoss = 1220;
		}
	}
	else
	{	
		if(strcmp(WHtCylPrimaryPipeworkInsulated,"Yes")==0)
		{
			primaryCircuitLoss = 360;
		}
		else
		{
			primaryCircuitLoss = 610;
		}
	}// ... if((strcmp(WHtCylThermostat,"No") == 0)  ends here

	//-----------------------------------------------------
	if(strcmp(DHWfromCommunityScheme,"Yes") == 0)
	{
		primaryCircuitLoss = 360;
	}
}

void CDlg_Results::CalculateCombiLosses()
{
	combiLoss = 0;
	//-----------------------------------------------------
	// COMBI  LOSS
	//-----------------------------------------------------
	if (((strcmp(WHtype,"Storage combi boiler - primary store")==0) || 
	   (strcmp(WHtype, "Storage combi boiler - secondary store")==0) || 
	   (strcmp(WHtype, "Instantaneous combi with closecoupled external store")==0)) ||	   
	   ((btnWaterHtFromMainState == 1) && (strcmp( boilerType,"Combi")==0)))
		   
	{
		F_u = 1.0;
		
		if(Vd_avg < 100)
		{	
			F_u = Vd_avg/100;
		}
		if(strcmp(WHtype, "Instantaneous combi with closecoupled external store")==0)
		{
			if(strcmp(WHtCombiKeepHotYN,"Yes")==0)
			{
				combiLoss = 600 * F_u;
			}
			else
			{
				if(strcmp(WHtWaterSepTimed,"Yes")==0)
				{
					combiLoss = 600 * F_u;
				}
				else
				{
					combiLoss = 900 * F_u;
				}
			}
		}
		else
		{
			if(tankVolume >= 55) 
			{
				combiLoss = 0;
			}
			else
			{
				combiLoss = (600 - (tankVolume - 15) * 15) * F_u;
			}

		} //... if(strcmp(WHtype, "Instantaneous combi with closecoupled external store")==0) ends here
	}
}


void CDlg_Results::CalculateSDHW()
{
	//---------------------------------------------------------
	//  SOLAR DOMESTIC HOT WATER
	//---------------------------------------------------------
	// Zero loss collector effeciency from user
	//---------------------------------------------------------
	SHW_ZLCE;
	
	//---------------------------------------------------------
	// Collector Heat Loss Coefficient from user
	//---------------------------------------------------------
	SHW_HeatLossCoefficient;
	
	//---------------------------------------------------------
	// Collector Performance Ratio
	//---------------------------------------------------------
	SHW_collectorPerformanceRatio = SHW_HeatLossCoefficient/SHW_ZLCE; 

	//---------------------------------------------------------
	// Annual solar radation
	//---------------------------------------------------------		
	if(SHWCollectorOrientation == "South")
	{
		 if(SHWCollectorTilt == "30 deg")
		{
			SHW_annualSolarRadiation_pm2 = 1073;	
		}
		else if(SHWCollectorTilt == "45 deg")
		{
			SHW_annualSolarRadiation_pm2 = 1054;	
		}
		else if(SHWCollectorTilt == "60 deg")
		{
			SHW_annualSolarRadiation_pm2 = 989;	
		}
		else if(SHWCollectorTilt == "Vertical")
		{
			SHW_annualSolarRadiation_pm2 = 746;	
		}
	}
	else if(SHWCollectorOrientation == "SE/SW")
	{
		 if(SHWCollectorTilt == "30 deg")
		{
			SHW_annualSolarRadiation_pm2 = 1027;	
		}
		else if(SHWCollectorTilt == "45 deg")
		{
			SHW_annualSolarRadiation_pm2 = 997;	
		}
		else if(SHWCollectorTilt == "60 deg")
		{
			SHW_annualSolarRadiation_pm2 = 927;	
		}
		else if(SHWCollectorTilt == "Vertical")
		{
			SHW_annualSolarRadiation_pm2 = 705;	
		}
	}
	else if(SHWCollectorOrientation == "E/W")
	{
		 if(SHWCollectorTilt == "30 deg")
		{
			SHW_annualSolarRadiation_pm2 = 913;	
		}
		else if(SHWCollectorTilt == "45 deg")
		{
			SHW_annualSolarRadiation_pm2 = 854;	
		}
		else if(SHWCollectorTilt == "60 deg")
		{
			SHW_annualSolarRadiation_pm2 = 776;	
		}
		else if(SHWCollectorTilt == "Vertical")
		{
			SHW_annualSolarRadiation_pm2 = 582;	
		}
	}
	else if(SHWCollectorOrientation == "NE/NW")
	{
		 if(SHWCollectorTilt == "30 deg")
		{
			SHW_annualSolarRadiation_pm2 = 785;	
		}
		else if(SHWCollectorTilt == "45 deg")
		{
			SHW_annualSolarRadiation_pm2 = 686;	
		}
		else if(SHWCollectorTilt == "60 deg")
		{
			SHW_annualSolarRadiation_pm2 = 597;	
		}
		else if(SHWCollectorTilt == "Vertical")
		{
			SHW_annualSolarRadiation_pm2 = 440;	
		}
	}
	else if(SHWCollectorOrientation == "North")
	{
		 if(SHWCollectorTilt == "30 deg")
		{
			SHW_annualSolarRadiation_pm2 = 730;	
		}
		else if(SHWCollectorTilt == "45 deg")
		{
			SHW_annualSolarRadiation_pm2 = 640;	
		}
		else if(SHWCollectorTilt == "60 deg")
		{
			SHW_annualSolarRadiation_pm2 = 500;	
		}
		else if(SHWCollectorTilt == "Vertical")
		{
			SHW_annualSolarRadiation_pm2 = 371;	
		}
	}
	
	if(SHWCollectorTilt == "Horizontal")
	{
		SHW_annualSolarRadiation_pm2 = 961;	
	}
	
	//---------------------------------------------------------
	//Overshading Factor
	//---------------------------------------------------------
	if(strcmp(SHWOvershading,"Heavy > 80%")==0)
	{
		SHW_overshadingFactor = 0.5;
	} 
	else if(strcmp(SHWOvershading,"Significant > 60%-80%")==0)
	{
		SHW_overshadingFactor = 0.65;
	}
	else if(strcmp(SHWOvershading,"Modest 20%-60%")==0)
	{
		SHW_overshadingFactor = 0.8;
	}
	else if(strcmp(SHWOvershading,"None or Very Little < 20%")==0)
	{
		SHW_overshadingFactor = 1.0;
	}
	else if(strcmp(SHWOvershading,"Unknown")==0)
	{
		SHW_overshadingFactor = 0.5;
	}

	//---------------------------------------------------------
	// Solar Energy Available
	//---------------------------------------------------------
	SHW_apertureArea = SHWApertureArea;
	SHW_solarEnergyAvailable = SHW_apertureArea *
		SHW_ZLCE *
		SHW_annualSolarRadiation_pm2 *
		SHW_overshadingFactor;


	//---------------------------------------------------------
	// SHW_solarToLoadRatio
	//---------------------------------------------------------
	double averageDailyLoad;  
	averageDailyLoad = DHW_energy/365; 

	SHW_solarToLoadRatio = SHW_solarEnergyAvailable/(DHW_energy - WWHRS_savings);

	//---------------------------------------------------------
	// SHW_collectorPerformanceFactor
	if(SHW_collectorPerformanceRatio <20)
	{
		SHW_collectorPerformanceFactor =  0.97 - 0.0367 * SHW_collectorPerformanceRatio
			+ 0.0006 * (SHW_collectorPerformanceRatio * SHW_collectorPerformanceRatio);
	}
	else
	{
		SHW_collectorPerformanceFactor = 0.693 - 0.0108 * (SHW_collectorPerformanceRatio * SHW_collectorPerformanceRatio);
	}

	//---------------------------------------------------------
	// Effective Solar Volume
	if(isSHWSolarStoreCombined == "Yes")
	{
		SHW_effectiveSolarVolume = SHWDedSolStoreVol + 0.3 *
			                               (WHtCylVolume - SHWDedSolStoreVol);
	}
	else
	{
		SHW_effectiveSolarVolume = SHWDedSolStoreVol;		
	}

	//---------------------------------------------------------
	// Daily Hot Water Demand
	if(TFA > 13.9)
	{
		N_OCC = 1 + 1.76 * (1 - pow((-0.000349 * (TFA -13.9)),2)) + 0.0013 * (TFA -13.9);
	}

	if(TFA <= 13.9)
	{
		N_OCC = 1 ;
	}

	SHW_annualHotWaterUsage = (25 * N_OCC) + 36;

	SHW_dailyHotWaterDemand_litres = SHW_annualHotWaterUsage;

	SHW_volumeRatio= SHW_effectiveSolarVolume/SHW_dailyHotWaterDemand_litres;

	if(SHW_volumeRatio<=1)
	{
		SHW_dedicatedSolarStorageVolumeFactor = 1 + 0.2 * log(SHW_volumeRatio);
	}
	else
	{
		SHW_dedicatedSolarStorageVolumeFactor = 1;
	}

	//---------------------------------------------------------
	// Uf
	double a = 0;
	double b = 0;

	if(SHWDedSolStoreVol < 50)
	{
		a = 0.72;
		b = 0.1;
	}
	else if ((SHWDedSolStoreVol > 50) && (SHWDedSolStoreVol <100) )
	{
		a = 0.9;
		b = 0.11;
	}
	else
	{
		a = 0.92;
		b = 0.12;
	}
	
		SHW_utilizationFactor = 1 - exp(-10 * SHW_solarToLoadRatio) *(a - b * SHW_solarToLoadRatio);


	// Final results for annual solar input
	SHW_annualSolarInput = SHW_solarEnergyAvailable * SHW_utilizationFactor * SHW_collectorPerformanceRatio *
		                   SHW_dedicatedSolarStorageVolumeFactor;

	solarDHWInput = SHW_annualSolarInput/TFA;

}
void CDlg_Results::CalculateDHWsupply()
{
	//---------------------------------------------------------
	// TOTAL DHW SUPPLY
	//---------------------------------------------------------
	domesticHotWaterSupply =( 0.85 * 
				DHW_energy +
				distributionLoss +
				storageLoss+ 
				primaryCircuitLoss+
				combiLoss )- 
				(solarDHWInput + 
				WWHRS_savings +
				FGHRS_saving +
				FGHRS_PVinput);	
}

void CDlg_Results::CalculatePVInput()
{
	//---------------------------------------------------------
	//  PV INPUT
	//---------------------------------------------------------
	// Annual solar radation
	//---------------------------------------------------------		
	if(PVCollectorOrientation == "South")
	{
		 if(PVCollectorTilt == "30 deg")
		{
			PV_annualSolarRadiation_pm2 = 1073;	
		}
		else if(PVCollectorTilt == "45 deg")
		{
			PV_annualSolarRadiation_pm2 = 1054;	
		}
		else if(PVCollectorTilt == "60 deg")
		{
			PV_annualSolarRadiation_pm2 = 989;	
		}
		else if(PVCollectorTilt == "Vertical")
		{
			PV_annualSolarRadiation_pm2 = 746;	
		}
	}
	else if(PVCollectorOrientation == "SE/SW")
	{
		 if(PVCollectorTilt == "30 deg")
		{
			PV_annualSolarRadiation_pm2 = 1027;	
		}
		else if(PVCollectorTilt == "45 deg")
		{
			PV_annualSolarRadiation_pm2 = 997;	
		}
		else if(PVCollectorTilt == "60 deg")
		{
			PV_annualSolarRadiation_pm2 = 927;	
		}
		else if(PVCollectorTilt == "Vertical")
		{
			PV_annualSolarRadiation_pm2 = 705;	
		}
	}
	else if(PVCollectorOrientation == "E/W")
	{
		 if(PVCollectorTilt == "30 deg")
		{
			PV_annualSolarRadiation_pm2 = 913;	
		}
		else if(PVCollectorTilt == "45 deg")
		{
			PV_annualSolarRadiation_pm2 = 854;	
		}
		else if(PVCollectorTilt == "60 deg")
		{
			PV_annualSolarRadiation_pm2 = 776;	
		}
		else if(PVCollectorTilt == "Vertical")
		{
			PV_annualSolarRadiation_pm2 = 582;	
		}
	}
	else if(PVCollectorOrientation == "NE/NW")
	{
		 if(PVCollectorTilt == "30 deg")
		{
			PV_annualSolarRadiation_pm2 = 785;	
		}
		else if(PVCollectorTilt == "45 deg")
		{
			PV_annualSolarRadiation_pm2 = 686;	
		}
		else if(PVCollectorTilt == "60 deg")
		{
			PV_annualSolarRadiation_pm2 = 597;	
		}
		else if(PVCollectorTilt == "Vertical")
		{
			PV_annualSolarRadiation_pm2 = 440;	
		}
	}
	else if(PVCollectorOrientation == "North")
	{
		 if(PVCollectorTilt == "30 deg")
		{
			PV_annualSolarRadiation_pm2 = 730;	
		}
		else if(PVCollectorTilt == "45 deg")
		{
			PV_annualSolarRadiation_pm2 = 640;	
		}
		else if(PVCollectorTilt == "60 deg")
		{
			PV_annualSolarRadiation_pm2 = 500;	
		}
		else if(PVCollectorTilt == "Vertical")
		{
			PV_annualSolarRadiation_pm2 = 371;	
		}
	}

	if(PVCollectorTilt == "Horizontal")
	{
		PV_annualSolarRadiation_pm2 = 961;	
	}
	
	//---------------------------------------------------------
	//Overshading Factor
	//---------------------------------------------------------
	if(strcmp(PVOvershading,"Heavy > 80%")==0)
	{
		PV_overshadingFactor = 0.5;
	} 
	else if(strcmp(PVOvershading,"Significant > 60%-80%")==0)
	{
		PV_overshadingFactor = 0.65;
	}
	else if(strcmp(PVOvershading,"Modest 20%-60%")==0)
	{
		PV_overshadingFactor = 0.8;
	}
	else if(strcmp(PVOvershading,"None or Very Little < 20%")==0)
	{
		PV_overshadingFactor = 1.0;
	}
	else if(strcmp(PVOvershading,"Unknown")==0)
	{
		PV_overshadingFactor = 0.5;
	}
		 
	if(isPVPresent == "Yes")
	{
		pvSupplyInput = 0.8 * installedPVPeakPower * PV_annualSolarRadiation_pm2 * PV_overshadingFactor;
	}
	else
	{
		pvSupplyInput = 0;
	}
}

void CDlg_Results::CalculateWTInput()
{
	//----------------------------------------------------------------------
	// WIND TURBINE INPUT
	//----------------------------------------------------------------------
	// Read s3 from climate file
	unsigned int i = 0;

	WTs3 = 125;
	for(i = 0; i < WindData_1.size(); i++)
	{
		if(strcmp(locationString,WindData_1[i].locationName) ==0)
		{
			WTs3 = WindData_1[i].s3;
		}		
	}	

	//----------------------------------------------------------------------------------
	// Apply Correction factor based on terrain type and height above ridge
	//----------------------------------------------------------------------------------
	if (dwellingTerrain == "Dense urban")
	{
		if(WTHeight>=10)
		{
			WTs3 = WTs3 * 0.56;
		}
		else if((WTHeight>=5) && (WTHeight<10))
		{
			WTs3 = WTs3 * 0.51;
		}
		else if((WTHeight>=2) && (WTHeight<5))
		{
			WTs3 = WTs3 * 0.40;
		}
		else if(WTHeight<2) 
		{
			WTs3 = WTs3 * 0.28;
		}
	}
	else if (dwellingTerrain == "Low rise urban/suburban")
	{
		if(WTHeight>=6)
		{
			WTs3 = WTs3 * 0.67;
		}
		else if((WTHeight>=4) && (WTHeight<6))
		{
			WTs3 = WTs3 * 0.61;
		}
		else if((WTHeight>=2) && (WTHeight<4))
		{
			WTs3 = WTs3 * 0.53;
		}
		else if(WTHeight<2) 
		{
			WTs3 = WTs3 * 0.39;
		}
	}
	else if (dwellingTerrain == "Rural")
	{
		if(WTHeight>=12)
		{
			WTs3 = WTs3 * 1.00;
		}
		else if((WTHeight>=7) && (WTHeight<12))
		{
			WTs3 = WTs3 * 0.94;
		}
		else if((WTHeight>=2) && (WTHeight<7))
		{
			WTs3 = WTs3 * 0.86;
		}
		else if(WTHeight<2) 
		{
			WTs3 = WTs3 * 0.82;
		}
	}

	//----------------------------------------------------------------------
	// WTs3 cannot exceed the value of 125
	if (WTs3>125)
	{
		WTs3 = 125;
	}

	// Turbine output equals 
	// P-wind = C_p * A 

	if(strcmp(isWTPresent,"Yes")==0)
	{
		WTsupplyInput = 1.92 * WTDiameter * WTDiameter * WTs3 * WTNumOf;
	}
	else
	{
		WTsupplyInput = 0;
	}
}

void CDlg_Results::CalculateMicroHydroInput()
{
	//----------------------------------------------------------------------
	// MICRO HYDRO
	//----------------------------------------------------------------------
	if(strcmp(uHydroyn,"Yes")==0)
	{
		uHydroAnnualEnergy = (uHydroAnnualAvgHead * uHydroAnnualAvgFlow * (uHydroEff/100) * 10 * 8766)/1000;
	}
	else
	{
		
		uHydroAnnualEnergy = 0;
	}
}

void CDlg_Results::CalculateTotalEnergy()
{
	//----------------------------------------------------------------------
	// Total renewable electricity
	totalRenElecSupply = pvSupplyInput + WTsupplyInput + uHydroAnnualEnergy;

	//----------------------------------------------------------------------
	// totalElectricalSupply is sum of aux elec, lighting elec, cooling and main heating, dhw, sec ht if fuel is elec
	totalElectricalSupply = auxillaryElectricity + lightElectricity + totalSpaceCoolingSupply;
	
	if (strcmp(mainFuel,"Electricity")==0)
	{
		totalElectricalSupply = totalElectricalSupply + mainSpaceHtSupply;
	}
	if (strcmp(secHtFuel,"Electricity")==0)
	{
		totalElectricalSupply = totalElectricalSupply + secSpaceHtSupply;
	}
	if (strcmp(WHtFuel,"Electricity")==0)
	{
		totalElectricalSupply = totalElectricalSupply + domesticHotWaterSupply;
	}
	
	//----------------------------------------------------------------------
	// Total space heating supply taking into account uCHP
	double temp_secHtFraction = 0;

	if(strcmp(isThereSecHeating,"No")==0)
	{
		temp_secHtFraction = 0;
	}
	else
	{
		temp_secHtFraction = secHtFraction;
	}

	if(strcmp(uCHPyn,"Yes")==0)
	{
		totalSpaceHtSupply = (spaceHeatingDemand * uCHPHeatingFraction) /(uCHPHeatingEff/100) +
							 (spaceHeatingDemand * (1-uCHPHeatingFraction) * (1- temp_secHtFraction)) /(mainHtEff/100) +
							 (spaceHeatingDemand * (1-uCHPHeatingFraction) * (temp_secHtFraction) /(secHtEff/100));

		uCHPAnnualElectricity =((spaceHeatingDemand * uCHPHeatingFraction) / (uCHPHeatingEff/100)) * (uCHPElectricEff/100);
	}
	else                                           
	{
		mainSpaceHtSupply = (spaceHeatingDemand * (1 - temp_secHtFraction)) / (mainHtEff/100) ;
		secSpaceHtSupply  = (spaceHeatingDemand * temp_secHtFraction)/ (secHtEff/100);
		totalSpaceHtSupply = mainSpaceHtSupply + secSpaceHtSupply;
		
		 	
		uCHPAnnualElectricity = 0;
	}    

	//----------------------------------------------------------------------
	// TOTAL ENERGY
	//----------------------------------------------------------------------
	totalSpaceCoolingSupply =0;

	totalEnergy = totalSpaceHtSupply +
		domesticHotWaterSupply +
		auxillaryElectricity+
		lightElectricity+
		totalSpaceCoolingSupply;
}

void CDlg_Results::CalculateCostEmissionsAndPrimaryEnergy()
{
	//----------------------------------------------------------------------
	// COST, EMISSIONS and PRIMARY ENERGY
	//----------------------------------------------------------------------
	unsigned int i = 0;
	CString tString;
	double tDouble;

	//----------------------------------------------------------------------
	// i) MAIN FUEL
	
		//----------------------------------------------------------------------------------------------
		// For fuels other than Electricity, done separately to take account of tariffs
		//----------------------------------------------------------------------------------------------
	if (strcmp(mainFuel,"Electricity")!=0)
	{
		for( i=0; i < SAPcostTable_New.size(); i++)
		{
			if(strcmp(mainFuel, SAPcostTable_New[i].fuelType) ==  0)
			{
				tString = SAPcostTable_New[i].fuelType;
				tDouble = SAPcostTable_New[i].unitPrice;
				tDouble = SAPcostTable_New[i].unitPrice/100;
				tDouble = mainSpaceHtSupply;
				tDouble			= mainSpaceHtSupply * SAPcostTable_New[i].unitPrice/100;

				mainSpaceHtSupply_fuelCost			= mainSpaceHtSupply * SAPcostTable_New[i].unitPrice/100;
				mainSpaceHtSupply_Emm				= mainSpaceHtSupply * SAPcostTable_New[i].emissions;
				mainSpaceHtSupply_PrimEnergyFactor  = mainSpaceHtSupply * SAPcostTable_New[i].primaryEnergyFactor;
			} 
		}
	}
	else if  (strcmp(mainFuel,"Electricity")==0)
	{
		for( i=0; i < SAPcostTable_New.size(); i++)
		{
			if ( (strcmp(mainFuel, SAPcostTable_New[i].fuelType) ==  0) && (strcmp(electricityTarrif, SAPcostTable_New[i].tariff) ==  0))
			{
				mainSpaceHtSupply_fuelCost			= mainSpaceHtSupply * SAPcostTable_New[i].unitPrice/100;
				mainSpaceHtSupply_Emm				= mainSpaceHtSupply * SAPcostTable_New[i].emissions;
				mainSpaceHtSupply_PrimEnergyFactor  = mainSpaceHtSupply * SAPcostTable_New[i].primaryEnergyFactor;
			} 
		}
	}	

	//----------------------------------------------------------------------
	// ii) SEC FUEL
	for( i=0; i < SAPcostTable_New.size(); i++)
	{
		//----------------------------------------------------------------------------------------------
		// For fuels other than Electricity, done separately to take account of tariffs
		//----------------------------------------------------------------------------------------------
		if (strcmp(secHtFuel,"Electricity")!=0)
		{
			if(strcmp(secHtFuel, SAPcostTable_New[i].fuelType) ==  0)
			{
				secSpaceHtSupply_fuelCost			= secSpaceHtSupply * SAPcostTable_New[i].unitPrice/100;
				secSpaceHtSupply_Emm				= secSpaceHtSupply * SAPcostTable_New[i].emissions;
				secSpaceHtSupply_PrimEnergyFactor   = secSpaceHtSupply * SAPcostTable_New[i].primaryEnergyFactor;
			} 
		}
		if  (strcmp(secHtFuel,"Electricity")==0)
		{
			if ( (strcmp(secHtFuel, SAPcostTable_New[i].fuelType) ==  0) && (strcmp(electricityTarrif, SAPcostTable_New[i].tariff) ==  0))
			{
				secSpaceHtSupply_fuelCost			= secSpaceHtSupply * SAPcostTable_New[i].unitPrice/100;
				secSpaceHtSupply_Emm				= secSpaceHtSupply * SAPcostTable_New[i].emissions;
				secSpaceHtSupply_PrimEnergyFactor   = secSpaceHtSupply * SAPcostTable_New[i].primaryEnergyFactor;
			} 
		}
	}	

	//----------------------------------------------------------------------
	// iii) WATER HEATING FUEL
	for( i=0; i < SAPcostTable_New.size(); i++)
	{
		//----------------------------------------------------------------------------------------------
		// For fuels other than Electricity, done separately to take account of tariffs
		//----------------------------------------------------------------------------------------------
		if (strcmp(WHtFuel ,"Electricity")!=0)
		{
			if(strcmp(WHtFuel, SAPcostTable_New[i].fuelType) ==  0)
			{
				domesticHotWaterSupply_fuelCost			= domesticHotWaterSupply * SAPcostTable_New[i].unitPrice/100;
				domesticHotWaterSupply_Emm				= domesticHotWaterSupply * SAPcostTable_New[i].emissions;
				domesticHotWaterSupply_PrimEnergyFactor = domesticHotWaterSupply * SAPcostTable_New[i].primaryEnergyFactor;
			} 
		}
		if  (strcmp(WHtFuel,"Electricity")==0)
		{
			if ( (strcmp(WHtFuel, SAPcostTable_New[i].fuelType) ==  0) && (strcmp(electricityTarrif, SAPcostTable_New[i].tariff) ==  0))
			{
				domesticHotWaterSupply_fuelCost			= domesticHotWaterSupply * SAPcostTable_New[i].unitPrice/100;
				domesticHotWaterSupply_Emm				= domesticHotWaterSupply * SAPcostTable_New[i].emissions;
				domesticHotWaterSupply_PrimEnergyFactor = domesticHotWaterSupply * SAPcostTable_New[i].primaryEnergyFactor;
			} 
		}
	}

	//----------------------------------------------------------------------
	// iv) AUXILARY, LIGHT AND COOLING IS ALWAYS ELECTRICITY
	for( i=0; i < SAPcostTable_New.size(); i++)
	{
		if ( (strcmp("Electricity", SAPcostTable_New[i].fuelType) ==  0) && (strcmp(electricityTarrif, SAPcostTable_New[i].tariff) ==  0))
		{
			auxillaryElectricity_fuelCost			 = auxillaryElectricity * SAPcostTable_New[i].unitPrice/100;
			auxillaryElectricity_Emm				 = auxillaryElectricity * SAPcostTable_New[i].emissions;
			auxillaryElectricity_PrimEnergyFactor    = auxillaryElectricity * SAPcostTable_New[i].primaryEnergyFactor;

			lightElectricity_fuelCost				 = lightElectricity * SAPcostTable_New[i].unitPrice/100;
			lightElectricity_Emm					 = lightElectricity * SAPcostTable_New[i].emissions;
			lightElectricity_PrimEnergyFactor		 = lightElectricity * SAPcostTable_New[i].primaryEnergyFactor;

			totalSpaceCoolingSupply_fuelCost		 = totalSpaceCoolingSupply * SAPcostTable_New[i].unitPrice/100;
			totalSpaceCoolingSupply_Emm				 = totalSpaceCoolingSupply * SAPcostTable_New[i].emissions;
			totalSpaceCoolingSupply_PrimEnergyFactor = totalSpaceCoolingSupply * SAPcostTable_New[i].primaryEnergyFactor;
			
			totalRenElecSupply_fuelCost				= totalRenElecSupply * SAPcostTable_New[i].unitPrice/100;
			totalRenElecSupply_Emm					= totalRenElecSupply * SAPcostTable_New[i].emissions;
			totalRenElecSupply_PrimEnergyFactor		= totalRenElecSupply * SAPcostTable_New[i].primaryEnergyFactor;

			LZCT_elecSold_fuelCost                  = LZCT_elecSold * SAPcostTable_New[i].unitPrice/100;
			LZCT_elecSold_Emm					    = LZCT_elecSold * SAPcostTable_New[i].emissions;
			LZCT_elecSold_PrimEnergyFactor		    = LZCT_elecSold * SAPcostTable_New[i].primaryEnergyFactor;
			
			LZCT_elecDisp_fuelCost					= LZCT_elecDisplaced* SAPcostTable_New[i].unitPrice/100;
			LZCT_elecDisp_Emm						= LZCT_elecDisplaced* SAPcostTable_New[i].emissions;
			LZCT_elecDisp_PrimEnergyFactor			= LZCT_elecDisplaced* SAPcostTable_New[i].primaryEnergyFactor;


		} 
	}

	//----------------------------------------------------------------------
	// Electricity calculations for LZCT
	//----------------------------------------------------------------------
	LZCT_elecDisplaced = (B_PV     * pvSupplyInput)+
						 (B_WT     * WTsupplyInput)+
						 (B_uHydro * uHydroAnnualEnergy)+
						 (B_uCHP   * uCHPAnnualElectricity);

	if(totalRenElecSupply == 0)
	{
		LZCT_elecSold = 0;
	}
	else
	{
		LZCT_elecSold = ((1 - B_PV)	    * pvSupplyInput)+
						((1 - B_WT)     * WTsupplyInput)+
						((1 - B_uHydro) * uHydroAnnualEnergy)+
						((1 - B_uCHP)   * uCHPAnnualElectricity);
	}

	if(LZCT_elecDisplaced > totalElectricalSupply)
	{
		LZCT_elecSold      = LZCT_elecSold + LZCT_elecDisplaced  - totalElectricalSupply;
		LZCT_elecDisplaced = totalElectricalSupply;
		totalElectricalSupply = 0;
	}
	else
	{
		totalElectricalSupply = totalElectricalSupply -LZCT_elecDisplaced;
	}

	//----------------------------------------------------------------------	
	totalCost = mainSpaceHtSupply_fuelCost +
		secSpaceHtSupply_fuelCost+
		domesticHotWaterSupply_fuelCost +
		auxillaryElectricity_fuelCost+
		lightElectricity_fuelCost+
		totalSpaceCoolingSupply_fuelCost - totalRenElecSupply_fuelCost;

	//----------------------------------------------------------------------
	totalEmissions = mainSpaceHtSupply_Emm +
		secSpaceHtSupply_Emm+
		domesticHotWaterSupply_Emm +
		auxillaryElectricity_Emm+
		lightElectricity_Emm+
		totalSpaceCoolingSupply_Emm - totalRenElecSupply_Emm;

	//----------------------------------------------------------------------
	totalPrimaryEnergy = mainSpaceHtSupply_PrimEnergyFactor +
		secSpaceHtSupply_PrimEnergyFactor+
		domesticHotWaterSupply_PrimEnergyFactor +
		auxillaryElectricity_PrimEnergyFactor+
		lightElectricity_PrimEnergyFactor+
		totalSpaceCoolingSupply_PrimEnergyFactor - totalRenElecSupply_PrimEnergyFactor;
}

void CDlg_Results::CalculatePrimaryAndSecondaryFuel()
{
	//----------------------------------------------------------------------
	// PRIMARY AND SECONDARY FUEL
	//----------------------------------------------------------------------
	unsigned int i = 0;

	// Initialize to 0
	mainGasTotalFuel = 0;
	LPGTotalFuel     = 0;
	botGasTotalFuel  = 0;
	oilTotalFuel     = 0;
	houseCoalTotalFuel   = 0;
	smokelessTotalFuel   = 0;
	anthraciteTotalFuel  = 0;
	woodLogsTotalFuel    = 0;
	woodPelletsTotalFuel = 0;
	woodchipsTotalFuel   = 0;
	dualFuelTotalFuel    = 0;
	electricityTotalFuel = 0;

	//-------------------------------------------------------------------
	// Add fuel for main heating
	//-------------------------------------------------------------------
	if(mainFuel == "Mains gas")
	{
		mainGasTotalFuel = mainGasTotalFuel + mainSpaceHtSupply ;
	}
	else if(mainFuel == "LPG")
	{
		LPGTotalFuel = LPGTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "Bottled gas")
	{
		botGasTotalFuel = botGasTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "Oil")
	{
		oilTotalFuel = oilTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "House coal")
	{
		houseCoalTotalFuel = houseCoalTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "Smokeless")
	{
		smokelessTotalFuel = smokelessTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "Anthracite")
	{
		anthraciteTotalFuel =  anthraciteTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "Wood logs")
	{
		woodLogsTotalFuel = woodLogsTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "Wood pellets")
	{
		woodPelletsTotalFuel = woodPelletsTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "Wood chips")
	{
		woodchipsTotalFuel = woodchipsTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "Dual fuel")
	{
		dualFuelTotalFuel = dualFuelTotalFuel + mainSpaceHtSupply;
	}
	else if(mainFuel == "Electricity")
	{
		electricityTotalFuel = electricityTotalFuel + mainSpaceHtSupply;
	}

	//-------------------------------------------------------------------
	// Add fuel for secondary heating
	//-------------------------------------------------------------------
	if(secHtFuel == "Mains gas")
	{
		mainGasTotalFuel = mainGasTotalFuel + secSpaceHtSupply ;
	}
	else if(secHtFuel == "LPG")
	{
		LPGTotalFuel = LPGTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "Bottled gas")
	{
		botGasTotalFuel = botGasTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "Oil")
	{
		oilTotalFuel = oilTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "House coal")
	{
		houseCoalTotalFuel = houseCoalTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "Smokeless")
	{
		smokelessTotalFuel = smokelessTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "Anthracite")
	{
		anthraciteTotalFuel =  anthraciteTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "Wood logs")
	{
		woodLogsTotalFuel = woodLogsTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "Wood pellets")
	{
		woodPelletsTotalFuel = woodPelletsTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "Wood chips")
	{
		woodchipsTotalFuel = woodchipsTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "Dual fuel")
	{
		dualFuelTotalFuel = dualFuelTotalFuel + secSpaceHtSupply;
	}
	else if(secHtFuel == "Electricity")
	{
		electricityTotalFuel = electricityTotalFuel + secSpaceHtSupply;
	}

	//-------------------------------------------------------------------
	// Add fuel for DHW
	//-------------------------------------------------------------------
	if(WHtFuel == "Mains gas")
	{
		mainGasTotalFuel = mainGasTotalFuel + domesticHotWaterSupply ;
	}
	else if(WHtFuel == "LPG")
	{
		LPGTotalFuel = LPGTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "Bottled gas")
	{
		botGasTotalFuel = botGasTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "Oil")
	{
		oilTotalFuel = oilTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "House coal")
	{
		houseCoalTotalFuel = houseCoalTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "Smokeless")
	{
		smokelessTotalFuel = smokelessTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "Anthracite")
	{
		anthraciteTotalFuel =  anthraciteTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "Wood logs")
	{
		woodLogsTotalFuel = woodLogsTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "Wood pellets")
	{
		woodPelletsTotalFuel = woodPelletsTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "Wood chips")
	{
		woodchipsTotalFuel = woodchipsTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "Dual fuel")
	{
		dualFuelTotalFuel = dualFuelTotalFuel + domesticHotWaterSupply;
	}
	else if(WHtFuel == "Electricity")
	{
		electricityTotalFuel = electricityTotalFuel + domesticHotWaterSupply;
	}

	////-------------------------------------------------------------------
	//// Add fuel for CHP
	////-------------------------------------------------------------------
	//if(CHPFuel == "Mains gas")
	//{
	//	mainGasTotalFuel = mainGasTotalFuel + mainSpaceHtSupply ;
	//}
	//else if(CHPFuel == "LPG")
	//{
	//	LPGTotalFuel = LPGTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "Bottled gas")
	//{
	//	botGasTotalFuel = botGasTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "Oil")
	//{
	//	oilTotalFuel = oilTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "House coal")
	//{
	//	houseCoalTotalFuel = houseCoalTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "Smokeless")
	//{
	//	smokelessTotalFuel = smokelessTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "Anthracite")
	//{
	//	anthraciteTotalFuel =  anthraciteTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "Wood logs")
	//{
	//	woodLogsTotalFuel = woodLogsTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "Wood pellets")
	//{
	//	woodPelletsTotalFuel = woodPelletsTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "Wood chips")
	//{
	//	woodchipsTotalFuel = woodchipsTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "Dual fuel")
	//{
	//	dualFuelTotalFuel = dualFuelTotalFuel + mainSpaceHtSupply;
	//}
	//else if(CHPFuel == "Electricity")
	//{
	//	electricityTotalFuel = electricityTotalFuel + mainSpaceHtSupply;
	//}

	// Also add auxillary, light and cooling to electricity
	electricityTotalFuel = electricityTotalFuel +(auxillaryElectricity + lightElectricity + totalSpaceCoolingSupply);


	primaryFuelUsed = 0;
	secFuelUsed     = 0;
	
		
	if (mainGasTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = "";
		primaryFuelUsed = mainGasTotalFuel;
		primaryFuelUsedString = "Mains gas";
		
	}
	if (LPGTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = LPGTotalFuel;
		primaryFuelUsedString = "LPG";
	}
	if (botGasTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed   = botGasTotalFuel;
		primaryFuelUsedString = "Bottled gas";
	}
	if (oilTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = oilTotalFuel;
		primaryFuelUsedString = "Oil";
	}
	if (houseCoalTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = houseCoalTotalFuel;
		primaryFuelUsedString = "House coal";
	}
	if (smokelessTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = smokelessTotalFuel;
		primaryFuelUsedString = "Smokeless";
	}
	if (anthraciteTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = anthraciteTotalFuel;
		primaryFuelUsedString = "Anthracite";
	}
	if (woodLogsTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = woodLogsTotalFuel;
		primaryFuelUsedString = "Wood logs";
	}
	if (woodPelletsTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = woodPelletsTotalFuel;
		primaryFuelUsedString = "Wood pellets";
	}
	if (woodchipsTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = woodchipsTotalFuel;
		primaryFuelUsedString = "Wood chips";
	}
	if (dualFuelTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = dualFuelTotalFuel;
		primaryFuelUsedString = "Wood chips";
	}
	if (electricityTotalFuel >primaryFuelUsed)
	{
		secFuelUsed = primaryFuelUsed;
		secFuelUsedString = primaryFuelUsedString;
		primaryFuelUsed = electricityTotalFuel;
		primaryFuelUsedString = "Electricity";
	}

	//----------------------------------------------------------------------
	// PRIMARY FUEL
	for( i=0; i < SAPcostTable_New.size(); i++)
	{
		//----------------------------------------------------------------------------------------------
		// For fuels other than Electricity, done separately to take account of tariffs
		//----------------------------------------------------------------------------------------------
		if (strcmp(primaryFuelUsedString ,"Electricity")!=0)
		{
			if(strcmp(primaryFuelUsedString, SAPcostTable_New[i].fuelType) ==  0)
			{
				primaryFuelUsed_fuelCost	= primaryFuelUsed * SAPcostTable_New[i].unitPrice/100;
				primaryFuelUsed_Emm			= primaryFuelUsed * SAPcostTable_New[i].emissions;
			} 
		}
		if  (strcmp(primaryFuelUsedString,"Electricity")==0)
		{
			if ( (strcmp(primaryFuelUsedString, SAPcostTable_New[i].fuelType) ==  0) && (strcmp(electricityTarrif, SAPcostTable_New[i].tariff) ==  0))
			{
				primaryFuelUsed_fuelCost	= primaryFuelUsed * SAPcostTable_New[i].unitPrice/100;
				primaryFuelUsed_Emm			= primaryFuelUsed * SAPcostTable_New[i].emissions;
			} 
		}
	}

	//----------------------------------------------------------------------
	// SECONDARY FUEL
	for( i=0; i < SAPcostTable_New.size(); i++)
	{
		//----------------------------------------------------------------------------------------------
		// For fuels other than Electricity, done separately to take account of tariffs
		//----------------------------------------------------------------------------------------------
		if (strcmp(secFuelUsedString ,"Electricity")!=0)
		{
			if(strcmp(secFuelUsedString, SAPcostTable_New[i].fuelType) ==  0)
			{
				secFuelUsed_fuelCost	= secFuelUsed * SAPcostTable_New[i].unitPrice/100;
				secFuelUsed_Emm		= secFuelUsed * SAPcostTable_New[i].emissions;			} 
		}
		if  (strcmp(secFuelUsedString,"Electricity")==0)
		{
			if ( (strcmp(secFuelUsedString, SAPcostTable_New[i].fuelType) ==  0) && (strcmp(electricityTarrif, SAPcostTable_New[i].tariff) ==  0))
			{
				secFuelUsed_fuelCost	= secFuelUsed * SAPcostTable_New[i].unitPrice/100;
				secFuelUsed_Emm			= secFuelUsed * SAPcostTable_New[i].emissions;
			} 
		}
	}
}

void CDlg_Results::CalculateResultsForSAPP()
{

	//----------------------------------------------------------------------
	// 1. APPLY HEATING ADJUSTMENTS
	ReadValuesFromSHCSFile();	
	
	//----------------------------------------------------------------------
	// 2. APPLY HEATING ADJUSTMENTS
	ApplyEffAdjustmentsToHeatingCalcs();

	//----------------------------------------------------------------------
	// 3. CREATE TC ID
	CreateIndexNumberForDatabase();

	//----------------------------------------------------------------------
	// 4. CALCULATE SPACE HEATING DEMAND BASED ON TC ID
	SpaceHeatingDemandResultsBasedOnTCIndex();

	//----------------------------------------------------------------------
	// 5. NUMBER OF OCCUPANTS
	EstablishNumberOfOccupants();	

	//----------------------------------------------------------------------
	// 6. If MVHR is selected
	if(strcmp(MVHRyn,"Yes")==0)
	{
		SpaceHeatingDemandIfMVHR();
	}

	//----------------------------------------------------------------------
	// PCM
	//----------------------------------------------------------------------
	// ?????
	// Reduce spaceHeatingDemand by 5%; code will be improved later
	///*if(strcmp(PCMyn,"Yes")==0)
	//{
	//	spaceHeatingDemand = 0.95 * spaceHeatingDemand;
	//}*/

	//----------------------------------------------------------------------
	// 7. DOMESTIC HOT WATER
	CalculateDHW();	

	//----------------------------------------------------------------------
	// 8. LIGHTING ELECTRICITY
	CalculateLightingElectricity();

	//----------------------------------------------------------------------
	// 9. DISTRIBUTION LOSSES
	CalculateDistributionLosses();

	//----------------------------------------------------------------------
	// 10. STORAGE LOSSES
	CalculateStorageLosses();

	//----------------------------------------------------------------------
	// 11. PRIMARY CIRCUIT LOSS
	CalculatePrimaryCircuitLosses();

	//----------------------------------------------------------------------
	// 12. COMBI LOSS
	CalculateCombiLosses();

	//----------------------------------------------------------------------
	// 13. WWHRS
	SubtractDHWLossFromSpaceHeatingRequirement();

	//----------------------------------------------------------------------
	// 14. WWHRS
	if(strcmp(WWHRSpresent,"Yes") ==0)
	{
		CalculateWWHRS();
	}
	else
	{
		WWHRS_savings = 0;
	}

	//----------------------------------------------------------------------
	// 15. SOLAR DOMESTIC HOT WATER
	if(isSHWPresent == "Yes")
	{
		CalculateSDHW();
	}
	else
	{
		solarDHWInput = 0;
	}	

	//----------------------------------------------------------------------
	// 16. FGHRS
	if(strcmp(FGHRSpresent,"Yes") ==0)
	{
		CalculateFGHRS();
	}
	else
	{
		FGHRS_saving  = 0;
		FGHRS_PVinput = 0;
	}

	//----------------------------------------------------------------------
	// 17. AUXILLARY ELECTRICITY
	CalculateAuxillaryElectricity();

	//----------------------------------------------------------------------
	// 18. DHW SUPPLY
	CalculateDHWsupply();

	//----------------------------------------------------------------------
	// 19. PV
	CalculatePVInput();

	//----------------------------------------------------------------------
	// 20. WIND TURBINE INPUT
	CalculateWTInput();	

	//----------------------------------------------------------------------
	// 21. MICRO HYDRO
	CalculateMicroHydroInput();

	//----------------------------------------------------------------------
	// 22. TOTAL ENERGY 
	CalculateTotalEnergy();
	
	//----------------------------------------------------------------------
	// 23. COST, EMISSIONS and PRIMARY ENERGY
	CalculateCostEmissionsAndPrimaryEnergy();

	//----------------------------------------------------------------------
	// 24. PRIMARY AND SECONDARY FUEL
	CalculatePrimaryAndSecondaryFuel();
	
	//----------------------------------------------------------------------
	// 25. DISPLAY FUNCTIONS
	//----------------------------------------------------------------------
	// Display results based on different options in Overview tab
	ModifyResultsBasedOnEnergyCostOrEmissions();

	//----------------------------------------------------------------------
	// Display results in appropriate edit boxes depending on whether Base,
	// Improvement1, Improvement2, Improvement3, Improvement4 or 
	// Improvement5 is selected	
	DisplayResultsBasedOnCaseForRunningProject();	

	if(is_file_opened ==true)
	{
		DisplayResultsBasedOnCaseForOpenedProject();
	}
}

void CDlg_Results:: CreateIndexNumberForDatabase()
{
	//----------------------------------------------------------------------
	// CREATE TC ID
	//----------------------------------------------------------------------
	if(TFA_from_HEM == true)
	{
		TFA = TFAfromHEM;
	}
	total_solarGains = 0;

	//---------------------------------------------------------------------------------
	// 1. AIR CHANGES / HOUR
	//---------------------------------------------------------------------------------
	// ACH range
	A_range1 = (A_limit1 + A_limit2) / 2;
	A_range2 = (A_limit2 + A_limit3) / 2;
	A_range3 = (A_limit3 + A_limit4) / 2;
	A_range4 = (A_limit4 + A_limit5) / 2;

	// Calculations based on SAP document carried out as follows

	// Infiltration due to chimneys, flues, fans, PSVs
	numOfChimneys_m3perh          = numsOpenFirePlaces * numOfChimneys_multip;
	numOfFlues_m3perh             = numsOpenFlues    * numOfFlues_multip;  
	numOfFansPassVents_m3perh     = (numsExtractFans    * numOfFansPassVents_multip) + (numsPassiveVents    * numOfFansPassVents_multip) ;  
	numOfFluelessGasFires_m3perh  = numsFluelessGasFires * numOfFluelessGasFires_multip;

	if(TFA_from_HEM == true)
	{
		dewllingVolume = TFA * 2.5;
	}
	else
	{
		dewllingVolume = (storey1Area*storey1Height) + 
					 (storey2Area*storey2Height) + 
					 (storey3Area*storey3Height) + 
					 (storey4Area*storey4Height) + 
					 (storey5Area*storey5Height) + 
					 (storey6Area*storey6Height) ;
	}

	infliltrationOpenings = (numOfChimneys_m3perh + numOfFlues_m3perh + numOfFansPassVents_m3perh + numOfFluelessGasFires_m3perh) / dewllingVolume;

	additionalInfiltration = (numOfStoreys - 1) * 0.1;
	
	windowInfiltration = 0.25 - (0.2 * perWindowDraughtStripped/100);
	
	infiltration_rate = infliltrationOpenings+ 
						additionalInfiltration+ 
						structInf+
						windowInfiltration+
						floorInf;

	// If a pressurisation test has been carried out or is intended, proceed
	// Air permeability value, q50, expressed in cubic metres per hour per square metre of envelope area, 'measuredQ50'
	// If based on air permeability value, then 
	
	if (strcmp(pressureTestYN,"Yes") == 0)
	{
		infiltration_rate18 =( measuredQ50 / 20 )+ infliltrationOpenings;
	}
	else
	{
		infiltration_rate18 = infiltration_rate;
	}

	// NOTE: Air permeability value applies if a pressurisation test has been done, or a design or specified air permeability is being used

	// Number of sides on which dwelling is sheltered , 'numOfShelteredSides'

	// Shelter factor 
	shelterFactor = 1 - (0.075 * numOfShelteredSides);

	// Infiltration rate incorporating shelter factor
	infiltrationRateWithshelterFactor = infiltration_rate18 * shelterFactor;
	
	// Infiltration rate modified for monthly wind speed
	//------------------------------------------------------
	// Monthly average wind speed from Table 7 of SAP sheet
	// NOTE: Use dummy values for now
	averageWindSpeed.Jan = 5.4;
	averageWindSpeed.Feb = 5.1;
	averageWindSpeed.Mar = 5.1;
	averageWindSpeed.Apr = 4.5;
	averageWindSpeed.May = 4.1;
	averageWindSpeed.Jun = 3.9;
	averageWindSpeed.Jul = 3.7;
	averageWindSpeed.Aug = 3.7;
	averageWindSpeed.Sep = 4.2;
	averageWindSpeed.Oct = 4.5;
	averageWindSpeed.Nov = 4.8;
	averageWindSpeed.Dec = 5.1;

	totalWindSpeed =(averageWindSpeed.Jan +
					averageWindSpeed.Feb +
					averageWindSpeed.Mar +
					averageWindSpeed.Apr +
					averageWindSpeed.May +
					averageWindSpeed.Jun +
					averageWindSpeed.Jul +
					averageWindSpeed.Aug +
					averageWindSpeed.Sep +
					averageWindSpeed.Oct +
					averageWindSpeed.Nov +
					averageWindSpeed.Dec)/12;

	//------------------------------------------------------
	// Wind Factor
	WindFactor.Jan = averageWindSpeed.Jan / 4;
	WindFactor.Feb = averageWindSpeed.Feb / 4;
	WindFactor.Mar = averageWindSpeed.Mar / 4;
	WindFactor.Apr = averageWindSpeed.Apr / 4;
	WindFactor.May = averageWindSpeed.May / 4;
	WindFactor.Jun = averageWindSpeed.Jun / 4;
	WindFactor.Jul = averageWindSpeed.Jul / 4;
	WindFactor.Aug = averageWindSpeed.Aug / 4;
	WindFactor.Sep = averageWindSpeed.Sep / 4;
	WindFactor.Oct = averageWindSpeed.Oct / 4;
	WindFactor.Nov = averageWindSpeed.Nov / 4;
	WindFactor.Dec = averageWindSpeed.Dec / 4;

	totalWindFactor =   (WindFactor.Jan +
					    WindFactor.Feb +
						WindFactor.Mar +
						WindFactor.Apr +
						WindFactor.May +
						WindFactor.Jun +
						WindFactor.Jul +
						WindFactor.Aug +
						WindFactor.Sep +
						WindFactor.Oct +
						WindFactor.Nov +
						WindFactor.Dec)/12;

	//--------------------------------------------------------------------
	// Adjusted infiltration rate (allowing for shelter and wind speed)
	effectiveInfiltrationRate.Jan = infiltrationRateWithshelterFactor * WindFactor.Jan;
	effectiveInfiltrationRate.Feb = infiltrationRateWithshelterFactor * WindFactor.Feb;
	effectiveInfiltrationRate.Mar = infiltrationRateWithshelterFactor * WindFactor.Mar;
	effectiveInfiltrationRate.Apr = infiltrationRateWithshelterFactor * WindFactor.Apr;
	effectiveInfiltrationRate.May = infiltrationRateWithshelterFactor * WindFactor.May;
	effectiveInfiltrationRate.Jun = infiltrationRateWithshelterFactor * WindFactor.Jun;
	effectiveInfiltrationRate.Jul = infiltrationRateWithshelterFactor * WindFactor.Jul;
	effectiveInfiltrationRate.Aug = infiltrationRateWithshelterFactor * WindFactor.Aug;
	effectiveInfiltrationRate.Sep = infiltrationRateWithshelterFactor * WindFactor.Sep;
	effectiveInfiltrationRate.Oct = infiltrationRateWithshelterFactor * WindFactor.Oct;
	effectiveInfiltrationRate.Nov = infiltrationRateWithshelterFactor * WindFactor.Nov;
	effectiveInfiltrationRate.Dec = infiltrationRateWithshelterFactor * WindFactor.Dec;

	effInfiltrationRate =  (effectiveInfiltrationRate.Jan +
								effectiveInfiltrationRate.Feb +
								effectiveInfiltrationRate.Mar +
								effectiveInfiltrationRate.Apr +
								effectiveInfiltrationRate.May +
								effectiveInfiltrationRate.Jun +
								effectiveInfiltrationRate.Jul +
								effectiveInfiltrationRate.Aug +
								effectiveInfiltrationRate.Sep +
								effectiveInfiltrationRate.Oct +
								effectiveInfiltrationRate.Nov +
								effectiveInfiltrationRate.Dec)/12;

	// If mechanical ventilation: air change rate through system
	achThrougSystem     = 0.5;

	// If exhaust air heat pump 
	valueIfExhaustAirHP = 0.5; 

	// If balanced with heat recovery:
	valueIfBalancedHR   = 0.9; 

	//------------------------------------------------------------------------------------------------------
	// a) If balanced mechanical ventilation with heat recovery (MVHR)
	//------------------------------------------------------------------------------------------------------
	IfBalancedMVHR.Jan = (effectiveInfiltrationRate.Jan + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Feb = (effectiveInfiltrationRate.Feb + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Mar = (effectiveInfiltrationRate.Mar + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Apr = (effectiveInfiltrationRate.Apr + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.May = (effectiveInfiltrationRate.May + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Jun = (effectiveInfiltrationRate.Jun + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Jul = (effectiveInfiltrationRate.Jul + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Aug = (effectiveInfiltrationRate.Aug + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Sep = (effectiveInfiltrationRate.Sep + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Oct = (effectiveInfiltrationRate.Oct + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Nov = (effectiveInfiltrationRate.Nov + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);
	IfBalancedMVHR.Dec = (effectiveInfiltrationRate.Dec + achThrougSystem)* ((1 - valueIfBalancedHR) / 100);

	//------------------------------------------------------------------------------------------------------
	// b) If balanced mechanical ventilation without heat recovery (MV)
	//------------------------------------------------------------------------------------------------------
	IfBalancedMVnoHR.Jan = effectiveInfiltrationRate.Jan + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Feb = effectiveInfiltrationRate.Feb + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Mar = effectiveInfiltrationRate.Mar + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Apr = effectiveInfiltrationRate.Apr + valueIfExhaustAirHP;
	IfBalancedMVnoHR.May = effectiveInfiltrationRate.May + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Jun = effectiveInfiltrationRate.Jun + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Jul = effectiveInfiltrationRate.Jul + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Aug = effectiveInfiltrationRate.Aug + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Sep = effectiveInfiltrationRate.Sep + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Oct = effectiveInfiltrationRate.Oct + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Nov = effectiveInfiltrationRate.Nov + valueIfExhaustAirHP;
	IfBalancedMVnoHR.Dec = effectiveInfiltrationRate.Dec + valueIfExhaustAirHP;

	////------------------------------------------------------------------------------------------------------
	//// c) If whole house extract ventilation or positive input ventilation from outside
	////------------------------------------------------------------------------------------------------------
	// Jan
	if(effectiveInfiltrationRate.Jan < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Jan = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Jan = effectiveInfiltrationRate.Jan + (0.5 * valueIfExhaustAirHP);
	}
	
	// Feb
	if(effectiveInfiltrationRate.Feb < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Feb = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Feb = effectiveInfiltrationRate.Feb + (0.5 * valueIfExhaustAirHP);
	}

	// Mar
	if(effectiveInfiltrationRate.Mar < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Mar = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Mar = effectiveInfiltrationRate.Mar + (0.5 * valueIfExhaustAirHP);
	}

	// Apr
	if(effectiveInfiltrationRate.Apr < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Apr = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Apr = effectiveInfiltrationRate.Apr + (0.5 * valueIfExhaustAirHP);
	}

	// May
	if(effectiveInfiltrationRate.May < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.May = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.May = effectiveInfiltrationRate.May + (0.5 * valueIfExhaustAirHP);
	}

	// Jun
	if(effectiveInfiltrationRate.Jun < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Jun = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Jun = effectiveInfiltrationRate.Jun + (0.5 * valueIfExhaustAirHP);
	}

	// Jul
	if(effectiveInfiltrationRate.Jul < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Jul = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Jul = effectiveInfiltrationRate.Jul + (0.5 * valueIfExhaustAirHP);
	}

	// Aug
	if(effectiveInfiltrationRate.Aug < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Aug = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Aug = effectiveInfiltrationRate.Aug + (0.5 * valueIfExhaustAirHP);
	}

	// Sep
	if(effectiveInfiltrationRate.Sep < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Sep = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Sep = effectiveInfiltrationRate.Sep + (0.5 * valueIfExhaustAirHP);
	}

	// Oct
	if(effectiveInfiltrationRate.Oct < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Oct = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Oct = effectiveInfiltrationRate.Oct + (0.5 * valueIfExhaustAirHP);
	}

	// Nov
	if(effectiveInfiltrationRate.Nov < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Nov = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Nov = effectiveInfiltrationRate.Nov + (0.5 * valueIfExhaustAirHP);
	}

	// Dec
	if(effectiveInfiltrationRate.Dec < (0.5 * valueIfExhaustAirHP))
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Dec = valueIfExhaustAirHP;
	}
	else
	{
		IfWholeHouseExractVentilationOrInputVentFromOutside.Dec = effectiveInfiltrationRate.Dec + (0.5 * valueIfExhaustAirHP);
	}

	////------------------------------------------------------------------------------------------------------
	//// d) If natural ventilation or whole house positive input ventilation from loft
	////------------------------------------------------------------------------------------------------------
	// Jan
	if(effectiveInfiltrationRate.Jan >= 1) 
	{
		 IfNaturalVentilationOrInputVentFromLoft.Jan = effectiveInfiltrationRate.Jan;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Jan = 0.5 + (effectiveInfiltrationRate.Jan * effectiveInfiltrationRate.Jan * 0.5);
	}

	// Feb
	if(effectiveInfiltrationRate.Feb >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Feb = effectiveInfiltrationRate.Feb;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Feb = 0.5 + (effectiveInfiltrationRate.Feb * effectiveInfiltrationRate.Feb * 0.5);
	}

	// Mar
	if(effectiveInfiltrationRate.Mar >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Mar = effectiveInfiltrationRate.Mar;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Mar = 0.5 + (effectiveInfiltrationRate.Mar * effectiveInfiltrationRate.Mar * 0.5);
	}

	// Apr
	if(effectiveInfiltrationRate.Apr >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Apr = effectiveInfiltrationRate.Apr;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Apr = 0.5 + (effectiveInfiltrationRate.Apr * effectiveInfiltrationRate.Apr * 0.5 );
	}

	// May
	if(effectiveInfiltrationRate.May >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.May = effectiveInfiltrationRate.May;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.May = 0.5 + (effectiveInfiltrationRate.May * effectiveInfiltrationRate.May * 0.5);
	}

	// Jun
	if(effectiveInfiltrationRate.Jun >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Jun = effectiveInfiltrationRate.Jun;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Jun = 0.5 + (effectiveInfiltrationRate.Jun * effectiveInfiltrationRate.Jun * 0.5);
	}

	// Jul
	if(effectiveInfiltrationRate.Jul >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Jul = effectiveInfiltrationRate.Jul;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Jul = 0.5 + (effectiveInfiltrationRate.Jul * effectiveInfiltrationRate.Jul * 0.5);
	}

	// Aug
	if(effectiveInfiltrationRate.Aug >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Aug = effectiveInfiltrationRate.Aug;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Aug = 0.5 + (effectiveInfiltrationRate.Aug * effectiveInfiltrationRate.Aug * 0.5);
	}

	// Sep
	if(effectiveInfiltrationRate.Sep >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Sep = effectiveInfiltrationRate.Sep;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Sep = 0.5 + (effectiveInfiltrationRate.Sep * effectiveInfiltrationRate.Sep * 0.5);
	}

	// Oct
	if(effectiveInfiltrationRate.Oct >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Oct = effectiveInfiltrationRate.Oct;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Oct = 0.5 + (effectiveInfiltrationRate.Oct * effectiveInfiltrationRate.Oct * 0.5);
	}

	// Nov
	if(effectiveInfiltrationRate.Nov >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Nov = effectiveInfiltrationRate.Nov;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Nov = 0.5 + (effectiveInfiltrationRate.Nov * effectiveInfiltrationRate.Nov * 0.5);
	}

	// Dec
	if(effectiveInfiltrationRate.Dec >= 1) 
	{
		IfNaturalVentilationOrInputVentFromLoft.Dec = effectiveInfiltrationRate.Dec;
	}
	else
	{
		IfNaturalVentilationOrInputVentFromLoft.Dec = 0.5 + (effectiveInfiltrationRate.Dec* effectiveInfiltrationRate.Dec * 0.5);
	}


	////------------------------------------------------------------------------------------------------------
	//// e) If natural ventilation or positive input ventilation from outside
	////------------------------------------------------------------------------------------------------------
	// Jan
	if(effectiveInfiltrationRate.Jan < (0.5 * valueIfExhaustAirHP)) 
	{
		 IfPositiveInputFromOutside.Jan = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Jan = effectiveInfiltrationRate.Jan * 0.5 * valueIfExhaustAirHP;
	}

	// Feb
	if(effectiveInfiltrationRate.Feb < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Feb = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Feb = effectiveInfiltrationRate.Feb * 0.5 * valueIfExhaustAirHP;
	}

	// Mar
	if(effectiveInfiltrationRate.Mar < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Mar = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Mar = effectiveInfiltrationRate.Mar * 0.5 * valueIfExhaustAirHP;
	}

	// Apr
	if(effectiveInfiltrationRate.Apr < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Apr = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Apr = effectiveInfiltrationRate.Apr * 0.5 * valueIfExhaustAirHP;
	}

	// May
	if(effectiveInfiltrationRate.May < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.May = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.May = effectiveInfiltrationRate.May * 0.5 * valueIfExhaustAirHP;
	}

	// Jun
	if(effectiveInfiltrationRate.Jun < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Jun = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Jun = effectiveInfiltrationRate.Jun * 0.5 * valueIfExhaustAirHP;
	}

	// Jul
	if(effectiveInfiltrationRate.Jul < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Jul = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Jul = effectiveInfiltrationRate.Jul * 0.5 * valueIfExhaustAirHP;
	}

	// Aug
	if(effectiveInfiltrationRate.Aug < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Aug = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Aug = effectiveInfiltrationRate.Aug * 0.5 * valueIfExhaustAirHP;
	}

	// Sep
	if(effectiveInfiltrationRate.Sep < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Sep = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Sep = 0.5 + effectiveInfiltrationRate.Sep * 0.5 * valueIfExhaustAirHP;
	}

	// Oct
	if(effectiveInfiltrationRate.Oct < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Oct = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Oct = effectiveInfiltrationRate.Oct * 0.5 * valueIfExhaustAirHP;
	}

	// Nov
	if(effectiveInfiltrationRate.Nov < (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Nov = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside.Nov = effectiveInfiltrationRate.Nov * 0.5 * valueIfExhaustAirHP;
	}

	// Dec
	if(effectiveInfiltrationRate.Dec< (0.5 * valueIfExhaustAirHP)) 
	{
		IfPositiveInputFromOutside.Dec = valueIfExhaustAirHP;
	}
	else
	{
		IfPositiveInputFromOutside .Dec = effectiveInfiltrationRate.Dec * 0.5 * valueIfExhaustAirHP;
	}
	
	//------------------------------------------------------------------------------------------------------
	// Finally: Effective air change rate; dependingon the type of ventilation
	//------------------------------------------------------------------------------------------------------
	if (strcmp( mechVentType,"Balanced (with heat recovery)" ) == 0)
	{
		EffectiveAirChangeRate.Jan = IfBalancedMVHR.Jan;
		EffectiveAirChangeRate.Feb = IfBalancedMVHR.Feb;
		EffectiveAirChangeRate.Mar = IfBalancedMVHR.Mar;
		EffectiveAirChangeRate.Apr = IfBalancedMVHR.Apr;
		EffectiveAirChangeRate.May = IfBalancedMVHR.May;
		EffectiveAirChangeRate.Jun = IfBalancedMVHR.Jun;
		EffectiveAirChangeRate.Jul = IfBalancedMVHR.Jul;
		EffectiveAirChangeRate.Aug = IfBalancedMVHR.Aug;
		EffectiveAirChangeRate.Sep = IfBalancedMVHR.Sep;
		EffectiveAirChangeRate.Oct = IfBalancedMVHR.Oct;
		EffectiveAirChangeRate.Nov = IfBalancedMVHR.Nov;
		EffectiveAirChangeRate.Dec = IfBalancedMVHR.Dec;
	}
	else if (strcmp( mechVentType,"Balanced (without heat recovery)" ) == 0)
	{
		EffectiveAirChangeRate.Jan = IfBalancedMVnoHR.Jan;
		EffectiveAirChangeRate.Feb = IfBalancedMVnoHR.Feb;
		EffectiveAirChangeRate.Mar = IfBalancedMVnoHR.Mar;
		EffectiveAirChangeRate.Apr = IfBalancedMVnoHR.Apr;
		EffectiveAirChangeRate.May = IfBalancedMVnoHR.May;
		EffectiveAirChangeRate.Jun = IfBalancedMVnoHR.Jun;
		EffectiveAirChangeRate.Jul = IfBalancedMVnoHR.Jul;
		EffectiveAirChangeRate.Aug = IfBalancedMVnoHR.Aug;
		EffectiveAirChangeRate.Sep = IfBalancedMVnoHR.Sep;
		EffectiveAirChangeRate.Oct = IfBalancedMVnoHR.Oct;
		EffectiveAirChangeRate.Nov = IfBalancedMVnoHR.Nov;
		EffectiveAirChangeRate.Dec = IfBalancedMVnoHR.Dec;
	}
	else if (strcmp( mechVentType,"Mechanical extract vent" ) == 0)
	{
		EffectiveAirChangeRate.Jan = IfWholeHouseExractVentilationOrInputVentFromOutside.Jan;
		EffectiveAirChangeRate.Feb = IfWholeHouseExractVentilationOrInputVentFromOutside.Feb;
		EffectiveAirChangeRate.Mar = IfWholeHouseExractVentilationOrInputVentFromOutside.Mar;
		EffectiveAirChangeRate.Apr = IfWholeHouseExractVentilationOrInputVentFromOutside.Apr;
		EffectiveAirChangeRate.May = IfWholeHouseExractVentilationOrInputVentFromOutside.May;
		EffectiveAirChangeRate.Jun = IfWholeHouseExractVentilationOrInputVentFromOutside.Jun;
		EffectiveAirChangeRate.Jul = IfWholeHouseExractVentilationOrInputVentFromOutside.Jul;
		EffectiveAirChangeRate.Aug = IfWholeHouseExractVentilationOrInputVentFromOutside.Aug;
		EffectiveAirChangeRate.Sep = IfWholeHouseExractVentilationOrInputVentFromOutside.Sep;
		EffectiveAirChangeRate.Oct = IfWholeHouseExractVentilationOrInputVentFromOutside.Oct;
		EffectiveAirChangeRate.Nov = IfWholeHouseExractVentilationOrInputVentFromOutside.Nov;
		EffectiveAirChangeRate.Dec = IfWholeHouseExractVentilationOrInputVentFromOutside.Dec;
	}
	else if (strcmp( mechVentType,"Positive input from loft" ) == 0)
	{
		EffectiveAirChangeRate.Jan = IfNaturalVentilationOrInputVentFromLoft.Jan;
		EffectiveAirChangeRate.Feb = IfNaturalVentilationOrInputVentFromLoft.Feb;
		EffectiveAirChangeRate.Mar = IfNaturalVentilationOrInputVentFromLoft.Mar;
		EffectiveAirChangeRate.Apr = IfNaturalVentilationOrInputVentFromLoft.Apr;
		EffectiveAirChangeRate.May = IfNaturalVentilationOrInputVentFromLoft.May;
		EffectiveAirChangeRate.Jun = IfNaturalVentilationOrInputVentFromLoft.Jun;
		EffectiveAirChangeRate.Jul = IfNaturalVentilationOrInputVentFromLoft.Jul;
		EffectiveAirChangeRate.Aug = IfNaturalVentilationOrInputVentFromLoft.Aug;
		EffectiveAirChangeRate.Sep = IfNaturalVentilationOrInputVentFromLoft.Sep;
		EffectiveAirChangeRate.Oct = IfNaturalVentilationOrInputVentFromLoft.Oct;
		EffectiveAirChangeRate.Nov = IfNaturalVentilationOrInputVentFromLoft.Nov;
		EffectiveAirChangeRate.Dec = IfNaturalVentilationOrInputVentFromLoft.Dec;
	}

	else if (strcmp( mechVentType,"Positive input from outside" ) == 0)
	{
		EffectiveAirChangeRate.Jan = IfPositiveInputFromOutside.Jan;
		EffectiveAirChangeRate.Feb = IfPositiveInputFromOutside.Feb;
		EffectiveAirChangeRate.Mar = IfPositiveInputFromOutside.Mar;
		EffectiveAirChangeRate.Apr = IfPositiveInputFromOutside.Apr;
		EffectiveAirChangeRate.May = IfPositiveInputFromOutside.May;
		EffectiveAirChangeRate.Jun = IfPositiveInputFromOutside.Jun;
		EffectiveAirChangeRate.Jul = IfPositiveInputFromOutside.Jul;
		EffectiveAirChangeRate.Aug = IfPositiveInputFromOutside.Aug;
		EffectiveAirChangeRate.Sep = IfPositiveInputFromOutside.Sep;
		EffectiveAirChangeRate.Oct = IfPositiveInputFromOutside.Oct;
		EffectiveAirChangeRate.Nov = IfPositiveInputFromOutside.Nov;
		EffectiveAirChangeRate.Dec = IfPositiveInputFromOutside.Dec;
	}

	else if (strcmp( mechVentType,"Not present (natural)" ) == 0)
	{
		EffectiveAirChangeRate.Jan = IfNaturalVentilationOrInputVentFromLoft.Jan;
		EffectiveAirChangeRate.Feb = IfNaturalVentilationOrInputVentFromLoft.Feb;
		EffectiveAirChangeRate.Mar = IfNaturalVentilationOrInputVentFromLoft.Mar;
		EffectiveAirChangeRate.Apr = IfNaturalVentilationOrInputVentFromLoft.Apr;
		EffectiveAirChangeRate.May = IfNaturalVentilationOrInputVentFromLoft.May;
		EffectiveAirChangeRate.Jun = IfNaturalVentilationOrInputVentFromLoft.Jun;
		EffectiveAirChangeRate.Jul = IfNaturalVentilationOrInputVentFromLoft.Jul;
		EffectiveAirChangeRate.Aug = IfNaturalVentilationOrInputVentFromLoft.Aug;
		EffectiveAirChangeRate.Sep = IfNaturalVentilationOrInputVentFromLoft.Sep;
		EffectiveAirChangeRate.Oct = IfNaturalVentilationOrInputVentFromLoft.Oct;
		EffectiveAirChangeRate.Nov = IfNaturalVentilationOrInputVentFromLoft.Nov;
		EffectiveAirChangeRate.Dec = IfNaturalVentilationOrInputVentFromLoft.Dec;
	}

	effectiveACH=  (EffectiveAirChangeRate.Jan +
					EffectiveAirChangeRate.Feb  +
					EffectiveAirChangeRate.Mar  +
					EffectiveAirChangeRate.Apr  +
					EffectiveAirChangeRate.May  +
					EffectiveAirChangeRate.Jun  +
					EffectiveAirChangeRate.Jul  +
					EffectiveAirChangeRate.Aug  +
					EffectiveAirChangeRate.Sep  +
					EffectiveAirChangeRate.Oct  +
					EffectiveAirChangeRate.Nov  +
					EffectiveAirChangeRate.Dec) / 12;


	//-------------------------------------------------------------------
	// Check if A1 to be determined from HEM dialog or detailed inputs
	//-------------------------------------------------------------------
	if(chkAirtightness == 1)
	{
		A_ach  = hemA_ach;
	}
	else
	{
        if(effectiveACH <= A_range1)
		{
			A_ach = "A1";
			lambda = 0.10;
		}
		else if ((effectiveACH >= A_range1) && (effectiveACH < A_range2))
		{
			A_ach = "A2";
			lambda = 0.15;
		}
		else if ((effectiveACH >= A_range2) && (effectiveACH < A_range3))
		{
			A_ach = "A3";
			lambda = 0.20;
		}
		else if ((effectiveACH >= A_range3) && (effectiveACH < A_range4))
		{
			A_ach = "A4";
			lambda = 0.25;
		}
		else 
		{
			A_ach = "A5";
			lambda = 0.30;
		}
	}

	//---------------------------------------------------------------------------------
	// 2. CAPACITY
	//---------------------------------------------------------------------------------

	//------------------------------------------------------------------
	// Capacity index
	//------------------------------------------------------------------
	//-------------------------------------------------------------------
	// Check if C_capacity to be determined from HEM dialog or detailed inputs
	//-------------------------------------------------------------------

	if(chkCapacity == 1)
	{
		C_capacity  = hemC_capacity;
	}
	else
	{
		if(thermalMassParameter<=C_limit)
		{
			C_capacity = "C1";
		}
		else
		{
			C_capacity = "C2";
		}
	}

	//---------------------------------------------------------------------------------
	// SOLAR GAINS
	//---------------------------------------------------------------------------------

	// Solar gains range
	S_range1 = (S_limit1 + S_limit2) / 2.0;
	S_range2 = (S_limit2 + S_limit3) / 2.0;

	S_range3=  S_limit3; // edit min 20140228

	// Sum(Area * Frame factor) / TFA_2
	
   
	/*total_solarGains = (winNArea* winNFrameFactor)+(winNEArea* winNEFrameFactor)+(winEArea* winEFrameFactor)+(winSEArea* winSEFrameFactor)+(winSArea*winSFrameFactor)+
	(winSWArea*winSWFrameFactor)+	(winWArea*winWFrameFactor)+(winNWArea*winNWFrameFactor)+(rooflightsArea*rooflightsFrameFactor);	
	 */

    //added winXSolTrans parameter edit by min 20140228

	/*
	 total_solarGains = (winNArea* winNFrameFactor*winNSolTrans)+(winNEArea* winNEFrameFactor*winNESolTrans)+(winEArea* winEFrameFactor*winESolTrans )+
		(winSEArea* winSEFrameFactor*winSESolTrans  )+(winSArea*winSFrameFactor*winSSolTrans)+
	    (winSWArea*winSWFrameFactor*winSWSolTrans)+	(winWArea*winWFrameFactor*winWSolTrans )+
	    (winNWArea*winNWFrameFactor*winNWSolTrans  )+(rooflightsArea*rooflightsFrameFactor*rooflightsSolTrans);
    */
	total_solarGains = (winNArea* winNFrameFactor*(1-winNSolTrans))+(winNEArea* winNEFrameFactor*(1-winNESolTrans))+
		(winEArea* winEFrameFactor*(1-winESolTrans) )+
		(winSEArea* winSEFrameFactor*(1-winSESolTrans)  )+(winSArea*winSFrameFactor*(1-winSSolTrans))+
	    (winSWArea*winSWFrameFactor*(1-winSWSolTrans))+	(winWArea*winWFrameFactor*(1-winWSolTrans) )+
	    (winNWArea*winNWFrameFactor*(1-winNWSolTrans ))+(rooflightsArea*rooflightsFrameFactor*(1-rooflightsSolTrans));

	total_solarGains = total_solarGains/TFA;

	//------------------------------------------------------------------
	// Solar gains index
	//------------------------------------------------------------------
	//-------------------------------------------------------------------
	// Check if S_solarGains to be determined from HEM dialog or detailed inputs
	//-------------------------------------------------------------------
	if(chkSolarIngress == 1)
	{
		S_solarGains  = hemS_solarGains;	
	}
	else
	{
		//TRACE("\n checkSolarIngress=0 ++++++++++++++" );    
		//TRACE("\n S_range1 (%f)  S_range2 (%f) S_range3  (%f) total_solarGains(%f)", S_range1, S_range2, S_range3, total_solarGains );    

		if(total_solarGains <= S_range1)
		{
			S_solarGains = "S1";			
		}
		else if ((total_solarGains >= S_range1) && (total_solarGains < S_range2))
		{		   
			S_solarGains = "S2";
		}
		else 
		{
			S_solarGains = "S3";
		}  
       TRACE("\n S_solarGains= %s", S_solarGains );    
	}
		
	//---------------------------------------------------------------------------------
	// EXPOSURE
	//---------------------------------------------------------------------------------
	
	// Exposure range
	X_range1 = (X_limit1 + X_limit2) / 2.0;
	X_range2 = (X_limit2 + X_limit3) / 2.0;
	X_range3 = (X_limit3 + X_limit4) / 2.0;
	X_range4 = (X_limit4 + X_limit5) / 2.0;

	netAreaWindows = winNArea+   
					  winNEArea+ 
				      winEArea+   
				      winSEArea+ 
				      winSArea+   
			          winSWArea+ 
				      winWArea+   
				      winNWArea;
				    
	netAreaRoofLights = rooflightsArea;

	netAreaWallType1 = grossAreaWall1 - netAreaDoors - netAreaWindows;
	netAreaRoofType1 = groosAreaRoof1 - netAreaRoofLights;

	extAreaSum = netAreaDoors     +
				 netAreaWindows   +
				 netAreaRoofLights+
				 netAreaGF +
				 netAreaExFloor  +
				 netAreaWallType1+
				 netAreaWallType2+
				 netAreaRoofType1 +
				 netAreaRoofType2 ;

	exposureValue = extAreaSum / TFA;

	//------------------------------------------------------------------
	// Exposure index
	//------------------------------------------------------------------
	if(exposureValue <= X_range1)
	{
		X_exposure = "X5";
	}
	else if ((exposureValue >= X_range1) && (exposureValue < X_range2))
	{
		X_exposure = "X4";
	}
	else if ((exposureValue >= X_range2) && (exposureValue < X_range3))
	{
		X_exposure = "X3";
	}
	else if ((exposureValue >= X_range3) && (exposureValue < X_range4))
	{
		X_exposure = "X2";
	}
	else 
	{
		X_exposure = "X1";
	}

	if((chkInsulation == 1) || 
		(chkAirtightness == 1) ||
		(chkCapacity == 1) ||
		(chkSolarIngress == 1) ||
		(chkOccupancy == 1) ||
		(chkControlledSpace == 1) )
	{
		X_exposure = hemX_exposure;
	}

	//---------------------------------------------------------------------------------
	// 5. INSULATION
	//---------------------------------------------------------------------------------
	// Insulation range
	if(S_solarGains == "S1")
	{
		if(X_exposure == "X1")
		{
			I_limit1 = 5.52;
			I_limit2 = 1.90;
			I_limit3 = 1.06;
			I_limit4 = 0.95;
			I_limit5 = 0.55;
		}
		else if(X_exposure == "X2")
		{
			I_limit1 = 4.82;
			I_limit2 = 1.62;
			I_limit3 = 0.90;
			I_limit4 = 0.80;
			I_limit5 = 0.47;
		}
		else if(X_exposure == "X3")
		{
			I_limit1 = 4.31;
			I_limit2 = 1.47;
			I_limit3 = 0.82;
			I_limit4 = 0.72;
			I_limit5 = 0.43;
		}
		else if(X_exposure == "X4")
		{
			I_limit1 = 3.43;
			I_limit2 = 1.01;
			I_limit3 = 0.57;
			I_limit4 = 0.50;
			I_limit5 = 0.30;
		}
		else if(X_exposure == "X5")
		{
			I_limit1 = 1.43;
			I_limit2 = 0.66;
			I_limit3 = 0.41;
			I_limit4 = 0.36;
			I_limit5 = 0.19;
		}
	}
	else if(S_solarGains == "S2")
	{
		if(X_exposure == "X1")
		{
			I_limit1 = 5.74;
			I_limit2 = 2.05;
			I_limit3 = 1.17;
			I_limit4 = 1.04;
			I_limit5 = 0.60;
		}
		else if(X_exposure == "X2")
		{
			I_limit1 = 4.97;
			I_limit2 = 1.72;
			I_limit3 = 0.97;
			I_limit4 = 0.86;
			I_limit5 = 0.50;
		}
		else if(X_exposure == "X3")
		{
			I_limit1 = 4.47;
			I_limit2 = 1.57;
			I_limit3 = 0.89;
			I_limit4 = 0.78;
			I_limit5 = 0.47;
		}
		else if(X_exposure == "X4")
		{
			I_limit1 = 3.59;
			I_limit2 = 1.11;
			I_limit3 = 0.64;
			I_limit4 = 0.56;
			I_limit5 = 0.34;
		}
		else if(X_exposure == "X5")
		{
			I_limit1 = 1.59;
			I_limit2 = 0.76;
			I_limit3 = 0.48;
			I_limit4 = 0.42;
			I_limit5 = 0.23;
		}
	}
	else if(S_solarGains == "S3")
	{
		if(X_exposure == "X1")
		{
			I_limit1 = 6.05;
			I_limit2 = 2.25;
			I_limit3 = 1.31;
			I_limit4 = 1.16;
			I_limit5 = 0.67;
		}
		else if(X_exposure == "X2")
		{
			I_limit1 = 5.17;
			I_limit2 = 1.86;
			I_limit3 = 1.06;
			I_limit4 = 0.94;
			I_limit5 = 0.55;
		}
		else if(X_exposure == "X3")
		{
			I_limit1 = 4.67;
			I_limit2 = 1.71;
			I_limit3 = 0.98;
			I_limit4 = 0.86;
			I_limit5 = 0.52;
		}
		else if(X_exposure == "X4")
		{
			I_limit1 = 3.79;
			I_limit2 = 1.25;
			I_limit3 = 0.73;
			I_limit4 = 0.64;
			I_limit5 = 0.39;
		}
		else if(X_exposure == "X5")
		{
			I_limit1 = 1.79;
			I_limit2 = 0.90;
			I_limit3 = 0.57;
			I_limit4 = 0.50;
			I_limit5 = 0.28;
		}
	}

	I_range1 = (I_limit1 + I_limit2) / 2;
	I_range2 = (I_limit2 + I_limit3) / 2;
	I_range3 = (I_limit3 + I_limit4) / 2;
	I_range4 = (I_limit4 + I_limit5) / 2;

	extUvalueXareaSum = ( netAreaDoors     * UvalueDoors)     +
						(netAreaWindows    * UvalueWindows)   + 
						(netAreaRoofLights * UvalueRooflights)+
						(netAreaGF         * UvalueGF) +
						(netAreaExFloor    * UvalueExposedFloor)  +
						(netAreaWallType1  * UvalueWallType1)+
						(netAreaWallType2  * UvalueWallType2)+
						(netAreaRoofType1  * UvalueRoofTYpe1) +
						(netAreaRoofType2  * UvalueRoofType2);
	
	extInsulationValue = extUvalueXareaSum / TFA;

	hem_extInsulationValue= extInsulationValue;

	//if((chkInsulation == 1) || 
	//	(chkAirtightness == 1) ||
	//	(chkCapacity == 1) ||
	//	(chkSolarIngress == 1) ||
	//	(chkOccupancy == 1) ||
	//	(chkControlledSpace == 1) )
	//{
	//		if((hem_extInsulationValue <= I_limit1) && (hem_extInsulationValue > I_limit2))
	//		{
	//			I_insulation1 = "I1";
	//			I_insulation2 = "I2";
	//			x_1 = I_limit1;
	//			x_2 = I_limit2;
	//		}
	//		else if ((hem_extInsulationValue <= I_limit2) && (hem_extInsulationValue > I_limit3))
	//		{
	//			I_insulation1 = "I2";
	//			I_insulation2 = "I3";
	//			x_1 = I_limit2;
	//			x_2 = I_limit3;
	//		}
	//		else if ((hem_extInsulationValue <= I_limit3) && (hem_extInsulationValue > I_limit4))
	//		{
	//			I_insulation1 = "I3";
	//			I_insulation2 = "I4";
	//			x_1 = I_limit3;
	//			x_2 = I_limit4;
	//		}
	//		else if ((hem_extInsulationValue <= I_limit4) && (hem_extInsulationValue > I_limit5))
	//		{
	//			I_insulation1 = "I4";
	//			I_insulation2 = "I5";
	//			x_1 = I_limit4;
	//			x_2 = I_limit5;
	//		}
	//		else  if(hem_extInsulationValue > I_limit1)
	//		{
	//			I_insulation1 = "I1";
	//			I_insulation2 = "I2";
	//			x_1 = I_limit1;
	//			x_2 = I_limit2;
	//		}
	//		else if(hem_extInsulationValue < I_limit5)
	//		{
	//			I_insulation1 = "I4";
	//			I_insulation2 = "I5";
	//			x_1 = I_limit4;
	//			x_2 = I_limit5;
	//		}		
	//	}
	//else
	//{
	//	I_insulation1 = hemI_insulation;
	//	I_insulation2 = hemI_insulation;
	//}
	
	// If slider position is changed due to change in house type or year of build
	// Interpolation is applied here
	if((is_ins_slider_moved_due_to_house_type_change == true) || (is_ins_slider_moved_due_to_year_bilud_change == true))
	{
		is_ins_slider_moved_due_to_house_type_change = false;
		is_ins_slider_moved_due_to_year_bilud_change = false;

		if((hem_extInsulationValue <= I_limit1) && (hem_extInsulationValue > I_limit2))
		{
			I_insulation1 = "I1";
			I_insulation2 = "I2";
			x_1 = I_limit1;
			x_2 = I_limit2;
		}
		else if ((hem_extInsulationValue <= I_limit2) && (hem_extInsulationValue > I_limit3))
		{
			I_insulation1 = "I2";
			I_insulation2 = "I3";
			x_1 = I_limit2;
			x_2 = I_limit3;
		}
		else if ((hem_extInsulationValue <= I_limit3) && (hem_extInsulationValue > I_limit4))
		{
			I_insulation1 = "I3";
			I_insulation2 = "I4";
			x_1 = I_limit3;
			x_2 = I_limit4;
		}
		else if ((hem_extInsulationValue <= I_limit4) && (hem_extInsulationValue > I_limit5))
		{
			I_insulation1 = "I4";
			I_insulation2 = "I5";
			x_1 = I_limit4;
			x_2 = I_limit5;
		}
		else  if(hem_extInsulationValue > I_limit1)
		{
			I_insulation1 = "I1";
			I_insulation2 = "I2";
			x_1 = I_limit1;
			x_2 = I_limit2;
		}
		else if(hem_extInsulationValue < I_limit5)
		{
			I_insulation1 = "I4";
			I_insulation2 = "I5";
			x_1 = I_limit4;
			x_2 = I_limit5;
		}			
	}
	else // else when slider position is changed when user moves the slider
	{
		// Check slider position
		if( hemI_insulationSliderPos== 1)
		{
			hemI_insulation = "I1";
		}
		else if( hemI_insulationSliderPos== 2)
		{
			hemI_insulation = "I2";
		}
		else if(hemI_insulationSliderPos== 3)
		{
			hemI_insulation = "I3";
		}
		else if( hemI_insulationSliderPos == 4)
		{
			hemI_insulation = "I4";
		}
		else if( hemI_insulationSliderPos== 5)
		{
			hemI_insulation = "I5";
		}

		I_insulation1 = hemI_insulation;
		I_insulation2 = hemI_insulation;		
	}


	//@SHG
	////	if((extInsulationValue <= I_limit1) && (extInsulationValue > I_limit2))
	////	{
	////		I_insulation1 = "I1";
	////		I_insulation2 = "I2";
	////		x_1 = I_limit1;
	////		x_2 = I_limit2;
	////	}
	////	else if ((extInsulationValue <= I_limit2) && (extInsulationValue > I_limit3))
	////	{
	////		I_insulation1 = "I2";
	////		I_insulation2 = "I3";
	////		x_1 = I_limit2;
	////		x_2 = I_limit3;
	////	}
	////	else if ((extInsulationValue <= I_limit3) && (extInsulationValue > I_limit4))
	////	{
	////		I_insulation1 = "I3";
	////		I_insulation2 = "I4";
	////		x_1 = I_limit3;
	////		x_2 = I_limit4;
	////	}
	////	else if ((extInsulationValue <= I_limit4) && (extInsulationValue > I_limit5))
	////	{
	////		I_insulation1 = "I4";
	////		I_insulation2 = "I5";
	////		x_1 = I_limit4;
	////		x_2 = I_limit5;
	////	}
	////	else  if(extInsulationValue > I_limit1)
	////	{
	////		I_insulation1 = "I1";
	////		I_insulation2 = "I2";
	////		x_1 = I_limit1;
	////		x_2 = I_limit2;
	////	}
	////	else if(extInsulationValue < I_limit5)
	////	{
	////		I_insulation1 = "I4";
	////		I_insulation2 = "I5";
	////		x_1 = I_limit4;
	////		x_2 = I_limit5;
	////	}
	////}


	if(I_insulation1 == "")
	{
		I_insulation1 = "I1";	
	}

	if(I_insulation2 == "")
	{
		I_insulation2 = "I1";	
	}
			 
	//---------------------------------------------------------------------------------
	// 6. OCCUPANT DENSITY
	//---------------------------------------------------------------------------------
    
	// Occupant density range
	O_range1 = (O_limit1 + O_limit2) / 2;
	O_range2 = (O_limit2 + O_limit3) / 2;
	O_range3 = (O_limit3 + O_limit4) / 2;
	O_range4 = (O_limit4 + O_limit5) / 2;

	//------------------------------------------------------------------
	// Occupant density index
	//------------------------------------------------------------------
	//-------------------------------------------------------------------
	// Check if O_occupantDensity to be determined from HEM dialog or detailed inputs
	//-------------------------------------------------------------------
	if(chkOccupancy == 1)
	{
		O_occupantDensity  = hemO_occupantDensity;
	}
	else
	{
		if(TFA <= O_range1)
		{
			O_occupantDensity = "O1";
		}
		else if ((TFA >= O_range1) && (TFA < O_range2))
		{
			O_occupantDensity = "O2";
		}
		else if ((TFA >= O_range2) && (TFA < O_range3))
		{
			O_occupantDensity = "O3";
		}
		else if ((TFA >= O_range3) && (TFA < O_range4))
		{
			O_occupantDensity = "O4";
		}
		else 
		{
			O_occupantDensity = "O5";
		}
	}

	//---------------------------------------------------------------------------------
	// 7. LIVING AREA FRACTION
	//---------------------------------------------------------------------------------

	// Living room fraction range
	L_range1 = (L_limit1 + L_limit2) / 2;
	L_range2 = (L_limit2 + L_limit3) / 2;
	L_range3 = (L_limit3 + L_limit4) / 2;
	L_range4 = (L_limit4 + L_limit5) / 2;

	//------------------------------------------------------------------
	// Living area fraction index
	//------------------------------------------------------------------
	if(chkControlledSpace == 1)
	{
		L_livingAreaFraction = hemL_livingAreaFraction;
	}
	else
	{
		if(livingRoomFraction <= L_range1)
		{
			L_livingAreaFraction = "L1";
		}
		else if ((livingRoomFraction >= L_range1) && (livingRoomFraction < L_range2))
		{
			L_livingAreaFraction = "L2";
		}
		else if((livingRoomFraction >= L_range2) && (livingRoomFraction < L_range3))
		{
			L_livingAreaFraction = "L3";
		}
		else if((livingRoomFraction >= L_range3) && (livingRoomFraction < L_range4))
		{
			L_livingAreaFraction = "L4";
		}
		else 
		{
			L_livingAreaFraction = "L5";
		}
	}
	//---------------------------------------------------------------------------------
	// Concatenate Index String
	//---------------------------------------------------------------------------------
	XIACSOL_string  =  X_exposure + I_insulation + A_ach + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
	
	XIACSOL_string1 =  X_exposure + I_insulation1 + A_ach + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
	
	XIACSOL_string2 =  X_exposure + I_insulation2 + A_ach + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
	
	// NOTE: display 2 TC ids
	// String for user display
	XIACSOL_string_disp = XIACSOL_string;
	XIACSOL_string_disp.Remove('X');
	XIACSOL_string_disp.Remove('I');
	XIACSOL_string_disp.Remove('A');
	XIACSOL_string_disp.Remove('C');
	XIACSOL_string_disp.Remove('S');
	XIACSOL_string_disp.Remove('O');
	XIACSOL_string_disp.Remove('L');
	XIACSOL_string_disp;

	// String for user display
	XIACSOL_string_disp = XIACSOL_string;
	XIACSOL_string_disp.Remove('X');
	XIACSOL_string_disp.Remove('I');
	XIACSOL_string_disp.Remove('A');
	XIACSOL_string_disp.Remove('C');
	XIACSOL_string_disp.Remove('S');
	XIACSOL_string_disp.Remove('O');
	XIACSOL_string_disp.Remove('L');
	XIACSOL_string_disp;

	// String for user display
	XIACSOL_string_disp1 = XIACSOL_string1;
	XIACSOL_string_disp1.Remove('X');
	XIACSOL_string_disp1.Remove('I');
	XIACSOL_string_disp1.Remove('A');
	XIACSOL_string_disp1.Remove('C');
	XIACSOL_string_disp1.Remove('S');
	XIACSOL_string_disp1.Remove('O');
	XIACSOL_string_disp1.Remove('L');
	XIACSOL_string_disp1;

	// String for user display
	XIACSOL_string_disp2 = XIACSOL_string2;
	XIACSOL_string_disp2.Remove('X');
	XIACSOL_string_disp2.Remove('I');
	XIACSOL_string_disp2.Remove('A');
	XIACSOL_string_disp2.Remove('C');
	XIACSOL_string_disp2.Remove('S');
	XIACSOL_string_disp2.Remove('O');
	XIACSOL_string_disp2.Remove('L');
	XIACSOL_string_disp2;

}

void CDlg_Results::SpaceHeatingDemandResultsBasedOnTCIndex()
{
	if(strcmp(locationString,"Select weather..")==0)
		return;
	//----------------------------------------------------------------------
	// CALCULATE SPACE HEATING DEMAND BASED ON TC ID
	//----------------------------------------------------------------------

	unsigned int i = 0; 
	unsigned int j = 0;

	double temp1 = 0;
	double temp2 = 0;
	double temp3 = 0;
	double temp4 = 0;
	double temp5 = 0;
	double temp6 = 0;
	double temp7 = 0;
	double temp8 = 0;
	double temp9 = 0;
	double temp10 = 0;

	double tempp1 = 0;
	double tempp2 = 0;
	double tempp3 = 0;
	double tempp4 = 0;
	double tempp5 = 0;
	double tempp6 = 0;
	double tempp7 = 0;
	double tempp8 = 0;
	double tempp9 = 0;
	double tempp10 = 0;

	CString tempstring;

	unsigned int size = 0;
	size = ClimateData_1.size();

	//------------------------------------------------------------------------------
	// A. Find the Location string index
	//------------------------------------------------------------------------------
	for( i=0; i < ClimateData_1.size(); i++)
	{
		if(strcmp(locationString, ClimateData_1[i].locationName) ==  0)
		{
			tempstring = ClimateData_1[i].locationName;
			break;
		} 
	}
	i;

	//------------------------------------------------------------------------------
	// B. Find the Index string index
	//------------------------------------------------------------------------------
	
	//------------------------------------------------------------------------------
	// IMPORTANT
	//------------------------------------------------------------------------------
	// Firstly for XIACSOL_string1 for interpolation
	//------------------------------------------------------------------------------
	XIACSOL_string = XIACSOL_string1;
	for( j=0; j < IndexDataNew_1.size(); j++)
	{
		if(strcmp(XIACSOL_string, IndexDataNew_1[j].index) ==  0) 
		{
			tempstring = IndexDataNew_1[j].index;
			break;
		} 
	}
	j;

	//------------------------------------------------------------------------------
	// 1. Results for monthly Climate and Index
	//------------------------------------------------------------------------------

	temp1 = ClimateData_1[i].Apr1;
	temp2 = ClimateData_1[i].Apr2;
	temp3 = ClimateData_1[i].Apr3;
	temp4 = ClimateData_1[i].Apr4;
	temp5 = ClimateData_1[i].Apr5;
	temp6 = ClimateData_1[i].Apr6;
	temp7 = ClimateData_1[i].Apr7;
	temp8 = ClimateData_1[i].Apr8;
	temp9 = ClimateData_1[i].Apr9;
	
	tempp1 = IndexDataNew_1[j].Apr1;
	tempp2 = IndexDataNew_1[j].Apr2;
	tempp3 = IndexDataNew_1[j].Apr3;
	tempp4 = IndexDataNew_1[j].Apr4;
	tempp5 = IndexDataNew_1[j].Apr5;
	tempp6 = IndexDataNew_1[j].Apr6;
	tempp7 = IndexDataNew_1[j].Apr7;
	tempp8 = IndexDataNew_1[j].Apr8;
	tempp9 = IndexDataNew_1[j].Apr9;
	tempp10 = IndexDataNew_1[j].Apr10;

	DSMResults1.Jan =(ClimateData_1[i].Jan1 * IndexDataNew_1[j].Jan1) +
							(ClimateData_1[i].Jan2 * IndexDataNew_1[j].Jan2) +
							(ClimateData_1[i].Jan3 * IndexDataNew_1[j].Jan3) +
							(ClimateData_1[i].Jan4 * IndexDataNew_1[j].Jan4) +
							(ClimateData_1[i].Jan5 * IndexDataNew_1[j].Jan5) +
							(ClimateData_1[i].Jan6 * IndexDataNew_1[j].Jan6) +
							(ClimateData_1[i].Jan7 * IndexDataNew_1[j].Jan7) +
							(ClimateData_1[i].Jan8 * IndexDataNew_1[j].Jan8) +
							(ClimateData_1[i].Jan9 * IndexDataNew_1[j].Jan9) +
  							(IndexDataNew_1[j].Jan10); 

	DSMResults1.Feb =(ClimateData_1[i].Feb1 * IndexDataNew_1[j].Feb1) +
							(ClimateData_1[i].Feb2 * IndexDataNew_1[j].Feb2) +
							(ClimateData_1[i].Feb3 * IndexDataNew_1[j].Feb3) +
							(ClimateData_1[i].Feb4 * IndexDataNew_1[j].Feb4) +
							(ClimateData_1[i].Feb5 * IndexDataNew_1[j].Feb5) +
							(ClimateData_1[i].Feb6 * IndexDataNew_1[j].Feb6) +
							(ClimateData_1[i].Feb7 * IndexDataNew_1[j].Feb7) +
							(ClimateData_1[i].Feb8 * IndexDataNew_1[j].Feb8) +
							(ClimateData_1[i].Feb9 * IndexDataNew_1[j].Feb9) +
							( IndexDataNew_1[j].Feb10);

	DSMResults1.Mar =(ClimateData_1[i].Mar1 * IndexDataNew_1[j].Mar1) +
							(ClimateData_1[i].Mar2 * IndexDataNew_1[j].Mar2) +
							(ClimateData_1[i].Mar3 * IndexDataNew_1[j].Mar3) +
							(ClimateData_1[i].Mar4 * IndexDataNew_1[j].Mar4) +
							(ClimateData_1[i].Mar5 * IndexDataNew_1[j].Mar5) +
							(ClimateData_1[i].Mar6 * IndexDataNew_1[j].Mar6) +
							(ClimateData_1[i].Mar7 * IndexDataNew_1[j].Mar7) +
							(ClimateData_1[i].Mar8 * IndexDataNew_1[j].Mar8) +
							(ClimateData_1[i].Mar9 * IndexDataNew_1[j].Mar9) +
							( IndexDataNew_1[j].Mar10);

	DSMResults1.Apr =(ClimateData_1[i].Apr1 * IndexDataNew_1[j].Apr1) +
							(ClimateData_1[i].Apr2 * IndexDataNew_1[j].Apr2) +
							(ClimateData_1[i].Apr3 * IndexDataNew_1[j].Apr3) +
							(ClimateData_1[i].Apr4 * IndexDataNew_1[j].Apr4) +
							(ClimateData_1[i].Apr5 * IndexDataNew_1[j].Apr5) +
							(ClimateData_1[i].Apr6 * IndexDataNew_1[j].Apr6) +
							(ClimateData_1[i].Apr7 * IndexDataNew_1[j].Apr7) +
							(ClimateData_1[i].Apr8 * IndexDataNew_1[j].Apr8) +
							(ClimateData_1[i].Apr9 * IndexDataNew_1[j].Apr9) +
							( IndexDataNew_1[j].Apr10);

	DSMResults1.May =(ClimateData_1[i].May1 * IndexDataNew_1[j].May1) +
							(ClimateData_1[i].May2 * IndexDataNew_1[j].May2) +
							(ClimateData_1[i].May3 * IndexDataNew_1[j].May3) +
							(ClimateData_1[i].May4 * IndexDataNew_1[j].May4) +
							(ClimateData_1[i].May5 * IndexDataNew_1[j].May5) +
							(ClimateData_1[i].May6 * IndexDataNew_1[j].May6) +
							(ClimateData_1[i].May7 * IndexDataNew_1[j].May7) +
							(ClimateData_1[i].May8 * IndexDataNew_1[j].May8) +
							(ClimateData_1[i].May9 * IndexDataNew_1[j].May9) +
							( IndexDataNew_1[j].May10);

	DSMResults1.Jun =(ClimateData_1[i].Jun1 * IndexDataNew_1[j].Jun1) +
							(ClimateData_1[i].Jun2 * IndexDataNew_1[j].Jun2) +
							(ClimateData_1[i].Jun3 * IndexDataNew_1[j].Jun3) +
							(ClimateData_1[i].Jun4 * IndexDataNew_1[j].Jun4) +
							(ClimateData_1[i].Jun5 * IndexDataNew_1[j].Jun5) +
							(ClimateData_1[i].Jun6 * IndexDataNew_1[j].Jun6) +
							(ClimateData_1[i].Jun7 * IndexDataNew_1[j].Jun7) +
							(ClimateData_1[i].Jun8 * IndexDataNew_1[j].Jun8) +
							(ClimateData_1[i].Jun9 * IndexDataNew_1[j].Jun9) +
							( IndexDataNew_1[j].Jun10);

	DSMResults1.Jul =(ClimateData_1[i].Jul1 * IndexDataNew_1[j].Jul1) +
							(ClimateData_1[i].Jul2 * IndexDataNew_1[j].Jul2) +
							(ClimateData_1[i].Jul3 * IndexDataNew_1[j].Jul3) +
							(ClimateData_1[i].Jul4 * IndexDataNew_1[j].Jul4) +
							(ClimateData_1[i].Jul5 * IndexDataNew_1[j].Jul5) +
							(ClimateData_1[i].Jul6 * IndexDataNew_1[j].Jul6) +
							(ClimateData_1[i].Jul7 * IndexDataNew_1[j].Jul7) +
							(ClimateData_1[i].Jul8 * IndexDataNew_1[j].Jul8) +
							(ClimateData_1[i].Jul9 * IndexDataNew_1[j].Jul9) +
							( IndexDataNew_1[j].Jul10);

	DSMResults1.Aug =(ClimateData_1[i].Aug1 * IndexDataNew_1[j].Aug1) +
							(ClimateData_1[i].Aug2 * IndexDataNew_1[j].Aug2) +
							(ClimateData_1[i].Aug3 * IndexDataNew_1[j].Aug3) +
							(ClimateData_1[i].Aug4 * IndexDataNew_1[j].Aug4) +
							(ClimateData_1[i].Aug5 * IndexDataNew_1[j].Aug5) +
							(ClimateData_1[i].Aug6 * IndexDataNew_1[j].Aug6) +
							(ClimateData_1[i].Aug7 * IndexDataNew_1[j].Aug7) +
							(ClimateData_1[i].Aug8 * IndexDataNew_1[j].Aug8) +
							(ClimateData_1[i].Aug9 * IndexDataNew_1[j].Aug9) +
							( IndexDataNew_1[j].Aug10);

	DSMResults1.Sep =(ClimateData_1[i].Sep1 * IndexDataNew_1[j].Sep1) +
							(ClimateData_1[i].Sep2 * IndexDataNew_1[j].Sep2) +
							(ClimateData_1[i].Sep3 * IndexDataNew_1[j].Sep3) +
							(ClimateData_1[i].Sep4 * IndexDataNew_1[j].Sep4) +
							(ClimateData_1[i].Sep5 * IndexDataNew_1[j].Sep5) +
							(ClimateData_1[i].Sep6 * IndexDataNew_1[j].Sep6) +
							(ClimateData_1[i].Sep7 * IndexDataNew_1[j].Sep7) +
							(ClimateData_1[i].Sep8 * IndexDataNew_1[j].Sep8) +
							(ClimateData_1[i].Sep9 * IndexDataNew_1[j].Sep9) +
							( IndexDataNew_1[j].Sep10);

	DSMResults1.Oct =(ClimateData_1[i].Oct1 * IndexDataNew_1[j].Oct1) +
							(ClimateData_1[i].Oct2 * IndexDataNew_1[j].Oct2) +
							(ClimateData_1[i].Oct3 * IndexDataNew_1[j].Oct3) +
							(ClimateData_1[i].Oct4 * IndexDataNew_1[j].Oct4) +
							(ClimateData_1[i].Oct5 * IndexDataNew_1[j].Oct5) +
							(ClimateData_1[i].Oct6 * IndexDataNew_1[j].Oct6) +
							(ClimateData_1[i].Oct7 * IndexDataNew_1[j].Oct7) +
							(ClimateData_1[i].Oct8 * IndexDataNew_1[j].Oct8) +
							(ClimateData_1[i].Oct9 * IndexDataNew_1[j].Oct9) +
							( IndexDataNew_1[j].Oct10);

	DSMResults1.Nov =(ClimateData_1[i].Nov1 * IndexDataNew_1[j].Nov1) +
							(ClimateData_1[i].Nov2 * IndexDataNew_1[j].Nov2) +
							(ClimateData_1[i].Nov3 * IndexDataNew_1[j].Nov3) +
							(ClimateData_1[i].Nov4 * IndexDataNew_1[j].Nov4) +
							(ClimateData_1[i].Nov5 * IndexDataNew_1[j].Nov5) +
							(ClimateData_1[i].Nov6 * IndexDataNew_1[j].Nov6) +
							(ClimateData_1[i].Nov7 * IndexDataNew_1[j].Nov7) +
							(ClimateData_1[i].Nov8 * IndexDataNew_1[j].Nov8) +
							(ClimateData_1[i].Nov9 * IndexDataNew_1[j].Nov9) +
							( IndexDataNew_1[j].Nov10);

	DSMResults1.Dec =(ClimateData_1[i].Dec1 * IndexDataNew_1[j].Dec1) +
							(ClimateData_1[i].Dec2 * IndexDataNew_1[j].Dec2) +
							(ClimateData_1[i].Dec3 * IndexDataNew_1[j].Dec3) +
							(ClimateData_1[i].Dec4 * IndexDataNew_1[j].Dec4) +
							(ClimateData_1[i].Dec5 * IndexDataNew_1[j].Dec5) +
							(ClimateData_1[i].Dec6 * IndexDataNew_1[j].Dec6) +
							(ClimateData_1[i].Dec7 * IndexDataNew_1[j].Dec7) +
							(ClimateData_1[i].Dec8 * IndexDataNew_1[j].Dec8) +
							(ClimateData_1[i].Dec9 * IndexDataNew_1[j].Dec9) +
							( IndexDataNew_1[j].Dec10);

	//------------------------------------------------------------------------------
	// 2. Ttoal Results for monthly Climate and Index
	//------------------------------------------------------------------------------
	DSMResults1.total = DSMResults1.Jan + 
							   DSMResults1.Feb +
							   DSMResults1.Mar +
							   DSMResults1.Apr +
							   DSMResults1.May +
							   DSMResults1.Jun +
							   DSMResults1.Jul +
							   DSMResults1.Aug +
							   DSMResults1.Sep +
							   DSMResults1.Oct +
							   DSMResults1.Nov +
							   DSMResults1.Dec;

	//------------------------------------------------------------------------------
	// 3. Multiple regression coefficient
	//------------------------------------------------------------------------------
	multipleLinearRegCoeff1 = (IndexDataNew_1[j].Jan11 + 
							  IndexDataNew_1[j].Feb11 +
							  IndexDataNew_1[j].Mar11 + 
							  IndexDataNew_1[j].Apr11 + 
							  IndexDataNew_1[j].May11 + 
							  IndexDataNew_1[j].Jun11 + 
							  IndexDataNew_1[j].Jul11 + 
							  IndexDataNew_1[j].Aug11 + 
							  IndexDataNew_1[j].Sep11 + 
							  IndexDataNew_1[j].Oct11 + 
							  IndexDataNew_1[j].Nov11 + 
							  IndexDataNew_1[j].Dec11 )/12;

	//------------------------------------------------------------------------------
	// Secondly for XIACSOL_string2
	//------------------------------------------------------------------------------
	XIACSOL_string = XIACSOL_string2;
	for( j=0; j < IndexDataNew_1.size(); j++)
	{
		if(strcmp(XIACSOL_string, IndexDataNew_1[j].index) ==  0) 
		{
			tempstring = IndexDataNew_1[j].index;	
			break;
		} 
	}
	j;

	//------------------------------------------------------------------------------
	// 1. Results for monthly Climate and Index
	//------------------------------------------------------------------------------

	temp1 = ClimateData_1[i].Apr1;
	temp2 = ClimateData_1[i].Apr2;
	temp3 = ClimateData_1[i].Apr3;
	temp4 = ClimateData_1[i].Apr4;
	temp5 = ClimateData_1[i].Apr5;
	temp6 = ClimateData_1[i].Apr6;
	temp7 = ClimateData_1[i].Apr7;
	temp8 = ClimateData_1[i].Apr8;
	temp9 = ClimateData_1[i].Apr9;
	
	//tempp1 = IndexDataNew_1[j].Apr1;
	//tempp2 = IndexDataNew_1[j].Apr2;
	//tempp3 = IndexDataNew_1[j].Apr3;
	//tempp4 = IndexDataNew_1[j].Apr4;
	//tempp5 = IndexDataNew_1[j].Apr5;
	//tempp6 = IndexDataNew_1[j].Apr6;
	//tempp7 = IndexDataNew_1[j].Apr7;
	//tempp8 = IndexDataNew_1[j].Apr8;
	//tempp9 = IndexDataNew_1[j].Apr9;
	//tempp10 = IndexDataNew_1[j].Apr10;

	DSMResults2.Jan =(ClimateData_1[i].Jan1 * IndexDataNew_1[j].Jan1) +
							(ClimateData_1[i].Jan2 * IndexDataNew_1[j].Jan2) +
							(ClimateData_1[i].Jan3 * IndexDataNew_1[j].Jan3) +
							(ClimateData_1[i].Jan4 * IndexDataNew_1[j].Jan4) +
							(ClimateData_1[i].Jan5 * IndexDataNew_1[j].Jan5) +
							(ClimateData_1[i].Jan6 * IndexDataNew_1[j].Jan6) +
							(ClimateData_1[i].Jan7 * IndexDataNew_1[j].Jan7) +
							(ClimateData_1[i].Jan8 * IndexDataNew_1[j].Jan8) +
							(ClimateData_1[i].Jan9 * IndexDataNew_1[j].Jan9) +
  							(IndexDataNew_1[j].Jan10); 

	DSMResults2.Feb =(ClimateData_1[i].Feb1 * IndexDataNew_1[j].Feb1) +
							(ClimateData_1[i].Feb2 * IndexDataNew_1[j].Feb2) +
							(ClimateData_1[i].Feb3 * IndexDataNew_1[j].Feb3) +
							(ClimateData_1[i].Feb4 * IndexDataNew_1[j].Feb4) +
							(ClimateData_1[i].Feb5 * IndexDataNew_1[j].Feb5) +
							(ClimateData_1[i].Feb6 * IndexDataNew_1[j].Feb6) +
							(ClimateData_1[i].Feb7 * IndexDataNew_1[j].Feb7) +
							(ClimateData_1[i].Feb8 * IndexDataNew_1[j].Feb8) +
							(ClimateData_1[i].Feb9 * IndexDataNew_1[j].Feb9) +
							( IndexDataNew_1[j].Feb10);

	DSMResults2.Mar =(ClimateData_1[i].Mar1 * IndexDataNew_1[j].Mar1) +
							(ClimateData_1[i].Mar2 * IndexDataNew_1[j].Mar2) +
							(ClimateData_1[i].Mar3 * IndexDataNew_1[j].Mar3) +
							(ClimateData_1[i].Mar4 * IndexDataNew_1[j].Mar4) +
							(ClimateData_1[i].Mar5 * IndexDataNew_1[j].Mar5) +
							(ClimateData_1[i].Mar6 * IndexDataNew_1[j].Mar6) +
							(ClimateData_1[i].Mar7 * IndexDataNew_1[j].Mar7) +
							(ClimateData_1[i].Mar8 * IndexDataNew_1[j].Mar8) +
							(ClimateData_1[i].Mar9 * IndexDataNew_1[j].Mar9) +
							( IndexDataNew_1[j].Mar10);

	DSMResults2.Apr =(ClimateData_1[i].Apr1 * IndexDataNew_1[j].Apr1) +
							(ClimateData_1[i].Apr2 * IndexDataNew_1[j].Apr2) +
							(ClimateData_1[i].Apr3 * IndexDataNew_1[j].Apr3) +
							(ClimateData_1[i].Apr4 * IndexDataNew_1[j].Apr4) +
							(ClimateData_1[i].Apr5 * IndexDataNew_1[j].Apr5) +
							(ClimateData_1[i].Apr6 * IndexDataNew_1[j].Apr6) +
							(ClimateData_1[i].Apr7 * IndexDataNew_1[j].Apr7) +
							(ClimateData_1[i].Apr8 * IndexDataNew_1[j].Apr8) +
							(ClimateData_1[i].Apr9 * IndexDataNew_1[j].Apr9) +
							( IndexDataNew_1[j].Apr10);

	DSMResults2.May =(ClimateData_1[i].May1 * IndexDataNew_1[j].May1) +
							(ClimateData_1[i].May2 * IndexDataNew_1[j].May2) +
							(ClimateData_1[i].May3 * IndexDataNew_1[j].May3) +
							(ClimateData_1[i].May4 * IndexDataNew_1[j].May4) +
							(ClimateData_1[i].May5 * IndexDataNew_1[j].May5) +
							(ClimateData_1[i].May6 * IndexDataNew_1[j].May6) +
							(ClimateData_1[i].May7 * IndexDataNew_1[j].May7) +
							(ClimateData_1[i].May8 * IndexDataNew_1[j].May8) +
							(ClimateData_1[i].May9 * IndexDataNew_1[j].May9) +
							( IndexDataNew_1[j].May10);

	DSMResults2.Jun =(ClimateData_1[i].Jun1 * IndexDataNew_1[j].Jun1) +
							(ClimateData_1[i].Jun2 * IndexDataNew_1[j].Jun2) +
							(ClimateData_1[i].Jun3 * IndexDataNew_1[j].Jun3) +
							(ClimateData_1[i].Jun4 * IndexDataNew_1[j].Jun4) +
							(ClimateData_1[i].Jun5 * IndexDataNew_1[j].Jun5) +
							(ClimateData_1[i].Jun6 * IndexDataNew_1[j].Jun6) +
							(ClimateData_1[i].Jun7 * IndexDataNew_1[j].Jun7) +
							(ClimateData_1[i].Jun8 * IndexDataNew_1[j].Jun8) +
							(ClimateData_1[i].Jun9 * IndexDataNew_1[j].Jun9) +
							( IndexDataNew_1[j].Jun10);

	DSMResults2.Jul =(ClimateData_1[i].Jul1 * IndexDataNew_1[j].Jul1) +
							(ClimateData_1[i].Jul2 * IndexDataNew_1[j].Jul2) +
							(ClimateData_1[i].Jul3 * IndexDataNew_1[j].Jul3) +
							(ClimateData_1[i].Jul4 * IndexDataNew_1[j].Jul4) +
							(ClimateData_1[i].Jul5 * IndexDataNew_1[j].Jul5) +
							(ClimateData_1[i].Jul6 * IndexDataNew_1[j].Jul6) +
							(ClimateData_1[i].Jul7 * IndexDataNew_1[j].Jul7) +
							(ClimateData_1[i].Jul8 * IndexDataNew_1[j].Jul8) +
							(ClimateData_1[i].Jul9 * IndexDataNew_1[j].Jul9) +
							( IndexDataNew_1[j].Jul10);

	DSMResults2.Aug =(ClimateData_1[i].Aug1 * IndexDataNew_1[j].Aug1) +
							(ClimateData_1[i].Aug2 * IndexDataNew_1[j].Aug2) +
							(ClimateData_1[i].Aug3 * IndexDataNew_1[j].Aug3) +
							(ClimateData_1[i].Aug4 * IndexDataNew_1[j].Aug4) +
							(ClimateData_1[i].Aug5 * IndexDataNew_1[j].Aug5) +
							(ClimateData_1[i].Aug6 * IndexDataNew_1[j].Aug6) +
							(ClimateData_1[i].Aug7 * IndexDataNew_1[j].Aug7) +
							(ClimateData_1[i].Aug8 * IndexDataNew_1[j].Aug8) +
							(ClimateData_1[i].Aug9 * IndexDataNew_1[j].Aug9) +
							( IndexDataNew_1[j].Aug10);

	DSMResults2.Sep =(ClimateData_1[i].Sep1 * IndexDataNew_1[j].Sep1) +
							(ClimateData_1[i].Sep2 * IndexDataNew_1[j].Sep2) +
							(ClimateData_1[i].Sep3 * IndexDataNew_1[j].Sep3) +
							(ClimateData_1[i].Sep4 * IndexDataNew_1[j].Sep4) +
							(ClimateData_1[i].Sep5 * IndexDataNew_1[j].Sep5) +
							(ClimateData_1[i].Sep6 * IndexDataNew_1[j].Sep6) +
							(ClimateData_1[i].Sep7 * IndexDataNew_1[j].Sep7) +
							(ClimateData_1[i].Sep8 * IndexDataNew_1[j].Sep8) +
							(ClimateData_1[i].Sep9 * IndexDataNew_1[j].Sep9) +
							( IndexDataNew_1[j].Sep10);

	DSMResults2.Oct =(ClimateData_1[i].Oct1 * IndexDataNew_1[j].Oct1) +
							(ClimateData_1[i].Oct2 * IndexDataNew_1[j].Oct2) +
							(ClimateData_1[i].Oct3 * IndexDataNew_1[j].Oct3) +
							(ClimateData_1[i].Oct4 * IndexDataNew_1[j].Oct4) +
							(ClimateData_1[i].Oct5 * IndexDataNew_1[j].Oct5) +
							(ClimateData_1[i].Oct6 * IndexDataNew_1[j].Oct6) +
							(ClimateData_1[i].Oct7 * IndexDataNew_1[j].Oct7) +
							(ClimateData_1[i].Oct8 * IndexDataNew_1[j].Oct8) +
							(ClimateData_1[i].Oct9 * IndexDataNew_1[j].Oct9) +
							( IndexDataNew_1[j].Oct10);

	DSMResults2.Nov =(ClimateData_1[i].Nov1 * IndexDataNew_1[j].Nov1) +
							(ClimateData_1[i].Nov2 * IndexDataNew_1[j].Nov2) +
							(ClimateData_1[i].Nov3 * IndexDataNew_1[j].Nov3) +
							(ClimateData_1[i].Nov4 * IndexDataNew_1[j].Nov4) +
							(ClimateData_1[i].Nov5 * IndexDataNew_1[j].Nov5) +
							(ClimateData_1[i].Nov6 * IndexDataNew_1[j].Nov6) +
							(ClimateData_1[i].Nov7 * IndexDataNew_1[j].Nov7) +
							(ClimateData_1[i].Nov8 * IndexDataNew_1[j].Nov8) +
							(ClimateData_1[i].Nov9 * IndexDataNew_1[j].Nov9) +
							( IndexDataNew_1[j].Nov10);

	DSMResults2.Dec =(ClimateData_1[i].Dec1 * IndexDataNew_1[j].Dec1) +
							(ClimateData_1[i].Dec2 * IndexDataNew_1[j].Dec2) +
							(ClimateData_1[i].Dec3 * IndexDataNew_1[j].Dec3) +
							(ClimateData_1[i].Dec4 * IndexDataNew_1[j].Dec4) +
							(ClimateData_1[i].Dec5 * IndexDataNew_1[j].Dec5) +
							(ClimateData_1[i].Dec6 * IndexDataNew_1[j].Dec6) +
							(ClimateData_1[i].Dec7 * IndexDataNew_1[j].Dec7) +
							(ClimateData_1[i].Dec8 * IndexDataNew_1[j].Dec8) +
							(ClimateData_1[i].Dec9 * IndexDataNew_1[j].Dec9) +
							( IndexDataNew_1[j].Dec10);

	//------------------------------------------------------------------------------
	// 2. Ttoal Results for monthly Climate and Index
	//------------------------------------------------------------------------------
	DSMResults2.total = DSMResults2.Jan + 
							   DSMResults2.Feb +
							   DSMResults2.Mar +
							   DSMResults2.Apr +
							   DSMResults2.May +
							   DSMResults2.Jun +
							   DSMResults2.Jul +
							   DSMResults2.Aug +
							   DSMResults2.Sep +
							   DSMResults2.Oct +
							   DSMResults2.Nov +
							   DSMResults2.Dec;

	//------------------------------------------------------------------------------
	// 3. Multiple regression coefficient
	//------------------------------------------------------------------------------
	multipleLinearRegCoeff2 = (IndexDataNew_1[j].Jan11 + 
							  IndexDataNew_1[j].Feb11 +
							  IndexDataNew_1[j].Mar11 + 
							  IndexDataNew_1[j].Apr11 + 
							  IndexDataNew_1[j].May11 + 
							  IndexDataNew_1[j].Jun11 + 
							  IndexDataNew_1[j].Jul11 + 
							  IndexDataNew_1[j].Aug11 + 
							  IndexDataNew_1[j].Sep11 + 
							  IndexDataNew_1[j].Oct11 + 
							  IndexDataNew_1[j].Nov11 + 
							  IndexDataNew_1[j].Dec11 )/12;

	if(enterYValue == 1)
	{
		if(yValue_from_HEM == true)
		{
			yValueEntry = hem_yValueEntry;
			hem_extAreaSum;
			hem_extUvalueXareaSum;
			thermBridgeYvalue_grossArea = (hem_extAreaSum * yValueEntry)/hem_extUvalueXareaSum;			
		}
		else
		{
			thermBridgeYvalue_grossArea = (extAreaSum * yValueEntry)/extUvalueXareaSum;
		}
	}
	else if(enterYValue == 0)
	{
		thermBridgeYvalue_grossArea = ( ThermBMetalBoxLintelResult +
										ThermBOtherLintelsResult+
										ThermBSillResult+
										ThermBJambResult+
										ThermBGFPerimeterResult+
										ThermBFloorWithinDwellingPerimeterResult+
										ThermBFloorBetweenDwellingPerimeterResult+
										ThermBBalcWithDwellingLengthResult+
										ThermBBalconyBwDwellingLengthResult+
										ThermBEavesInsCeilingResult+
										ThermBEavesInsRafterResult+
										ThermBGableInsCeilingResult+
										ThermBGableInsRafterResult+
										ThermBLengthNormalCornersResult+
										ThermBLengthInvertedCornersResult+
										ThermBPartyWallBwDwellingResult) / extUvalueXareaSum;
	}

	DSMResults1.total ;
	DSMResults2.total ;

	//DSMResults1.total = DSMResults1.total * (1 + (( thermBridgeYvalue_grossArea )));  //* extAreaSum) /extUvalueXareaSum));
	//DSMResults2.total = DSMResults2.total * (1 + (( thermBridgeYvalue_grossArea )));//  * extAreaSum) /extUvalueXareaSum));
		
	//DSMResults1.total = DSMResults1.total * (1 + (( thermBridgeYvalue_grossArea * extAreaSum) /extUvalueXareaSum));
	//DSMResults2.total = DSMResults2.total * (1 + (( thermBridgeYvalue_grossArea * extAreaSum) /extUvalueXareaSum));

	DSMResults1.total = DSMResults1.total * (1 + (( thermBridgeYvalue_grossArea + extUvalueXareaSum / extAreaSum ) ));
	DSMResults2.total = DSMResults2.total * (1 + (( thermBridgeYvalue_grossArea + extUvalueXareaSum / extAreaSum ) ));

	// TRACE("YVALUE %f  EXT_ARE %f uVALUE %f", thermBridgeYvalue_grossArea,extAreaSum, extUvalueXareaSum );
    
	DSMResults.total = DSMResults1.total  -  (((DSMResults1.total - DSMResults2.total) * (x_1 - extInsulationValue)) / (x_1 - x_2));
	DSMResults.total = DSMResults.total * (TFA / 90);


	TRACE("\nSpace heating demand = %f",  DSMResults.total );

	spaceHeatingDemand = DSMResults.total;			

}

void CDlg_Results::SpaceHeatingDemandIfMVHR()
{
	double DSMResultsI1 = 0;
	double DSMResultsI2 = 0;
	double y_1 = 0;
	double y_2 = 0;

	//----------------------------------------------------------------------
	// MVHR
	//----------------------------------------------------------------------
	// If MVHR is selected reduce air change per hour
	effectiveACH_MVHR = effectiveACH * (1-MVHRThermalEff/100);

	// Find A (ach) index for XIACSOL for which ach is closest to above effective MVHR ach
	// Find both greater and smaller index
	if(effectiveACH_MVHR <= A_limit1)
	{
		achMVHR1 = 0;
		achMVHR2 = A_limit1;		
	}
	else if(effectiveACH_MVHR <= A_limit2)
	{
		achMVHR1 = A_limit1;
		achMVHR2 = A_limit2;
		A_ach_MVHR1 = "A1";
		A_ach_MVHR2 = "A2";
	}
	else if(effectiveACH_MVHR <= A_limit3)
	{
		achMVHR1 = A_limit2;
		achMVHR2 = A_limit3;
		A_ach_MVHR1 = "A2";
		A_ach_MVHR2 = "A3";
	}
	else if(effectiveACH_MVHR <= A_limit4)
	{
		achMVHR1 = A_limit3;
		achMVHR2 = A_limit4;
		A_ach_MVHR1 = "A3";
		A_ach_MVHR2 = "A4";
	}
	else if(effectiveACH_MVHR <= A_limit5)
	{
		achMVHR1 = A_limit4;
		achMVHR2 = A_limit5;
		A_ach_MVHR1 = "A4";
		A_ach_MVHR2 = "A5";
	}

	if(achMVHR1 < 0.00001)
	{
		// Find space heat demand (DSMResults?.Total) corresponding to both insulation values for both A values
		// Two insulation values are used for interpolation based on SigmaUA/TFA
		XIACSOL_string1 =  X_exposure + I_insulation1 + "A1" + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
		XIACSOL_string2 =  X_exposure + I_insulation1 + "A2" + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
		SpaceHeatingDemandResultsBasedOnTCIndex();
		y_1= DSMResults1.total;
		y_2= DSMResults2.total;

		//For the special case when MVHR ach is less than ach for smallest A index extrapolate for A1 and A2
		DSMResults2.total = y_1;
		DSMResultsI1 = y_2 + ( achMVHR1- A_limit2) * (y_2 - y_1)/(A_limit2 - A_limit1); 

		// Now do the same for Insulation value 2
		XIACSOL_string1 =  X_exposure + I_insulation2 + "A1" + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
		XIACSOL_string2 =  X_exposure + I_insulation2 + "A2" + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
		SpaceHeatingDemandResultsBasedOnTCIndex();
		y_1= DSMResults1.total;
		y_2= DSMResults2.total;
		DSMResults2.total = y_1;
		DSMResultsI2 = y_2 + ( achMVHR1- A_limit2) * (y_2 - y_1)/(A_limit2 - A_limit1);

	}
	else
	{
		// Space Heating demand for I_insulation1
		XIACSOL_string1 =  X_exposure + I_insulation1 + A_ach_MVHR1 + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
		XIACSOL_string2 =  X_exposure + I_insulation1 + A_ach_MVHR2 + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
		SpaceHeatingDemandResultsBasedOnTCIndex();
		DSMResultsI1 = DSMResults1.total +(DSMResults2.total - DSMResults1.total)* (effectiveACH_MVHR - achMVHR1)/(achMVHR2 - achMVHR1);
	
		// Space Heating demand for I_insulation2
		XIACSOL_string1 =  X_exposure + I_insulation2 + A_ach_MVHR1 + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
		XIACSOL_string2 =  X_exposure + I_insulation2 + A_ach_MVHR2 + C_capacity + S_solarGains + O_occupantDensity + L_livingAreaFraction;
		SpaceHeatingDemandResultsBasedOnTCIndex();
		DSMResultsI2 = DSMResults1.total +(DSMResults2.total - DSMResults1.total)* (effectiveACH_MVHR - achMVHR1)/(achMVHR2 - achMVHR1);		
	}

	DSMResults.total = DSMResultsI1 -  (((DSMResultsI1 - DSMResultsI2) * (x_1 - extInsulationValue)) / (x_1 - x_2));

	DSMResults.total = DSMResults.total * (TFA / 90);

	spaceHeatingDemand = DSMResults.total;
	
	// NOTE: display 2 TC ids
	// String for user display
	XIACSOL_string_disp = XIACSOL_string;
	XIACSOL_string_disp.Remove('X');
	XIACSOL_string_disp.Remove('I');
	XIACSOL_string_disp.Remove('A');
	XIACSOL_string_disp.Remove('C');
	XIACSOL_string_disp.Remove('S');
	XIACSOL_string_disp.Remove('O');
	XIACSOL_string_disp.Remove('L');
	XIACSOL_string_disp;

	// String for user display
	XIACSOL_string_disp1 = XIACSOL_string1;
	XIACSOL_string_disp1.Remove('X');
	XIACSOL_string_disp1.Remove('I');
	XIACSOL_string_disp1.Remove('A');
	XIACSOL_string_disp1.Remove('C');
	XIACSOL_string_disp1.Remove('S');
	XIACSOL_string_disp1.Remove('O');
	XIACSOL_string_disp1.Remove('L');
	XIACSOL_string_disp1;

	// String for user display
	XIACSOL_string_disp2 = XIACSOL_string2;
	XIACSOL_string_disp2.Remove('X');
	XIACSOL_string_disp2.Remove('I');
	XIACSOL_string_disp2.Remove('A');
	XIACSOL_string_disp2.Remove('C');
	XIACSOL_string_disp2.Remove('S');
	XIACSOL_string_disp2.Remove('O');
	XIACSOL_string_disp2.Remove('L');
	XIACSOL_string_disp2;

}
void CDlg_Results::OnEnChangeEdit4()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
}

void CDlg_Results::OnNMCustomdrawSlider1(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	// TODO: Add your control notification handler code here

	static int lastInsulationSliderSelection = 0;

	hemI_insulationSliderPos =  m_sliderInsulation.GetPos();
	//---------------------------------------------------------------- 
	// This event handler is called in the following situations:
	//		-	when the mouse pointer is in the slider area even 
	//			if user has not moved the bar
	//		-	user has moved the bar
	// 
	// However, we want to do any activities ONLY if the user has
	// moved the slider and NOT when the pointer is in the slider area
	//
	// To avoid this, we compare the slider old value with current value. 
	// If it is same, nothing needs to be done; otherwise do whatever x
	// If it is are required

	if (hemI_insulationSliderPos == lastInsulationSliderSelection)
	{
		// Slider bar has not been moved; this function called because
		// pointer was in the slider area. No action required.
		return;
	}
	else
	{
		// Slider position has changed, store it for next function call
		lastInsulationSliderSelection = hemI_insulationSliderPos;

		is_make_eff_adjustments_slider_insulation = true;
		is_make_eff_adjustments_slider_exposure   = false;
		is_make_eff_adjustments_slider_airChanges = false;
		is_make_eff_adjustments_slider_capacity   = false;
		is_make_eff_adjustments_slider_occupancy  = false;
		is_make_eff_adjustments_slider_livingArea = false;
		is_make_eff_adjustments_slider_solarIngress = false;
		ReadInputsFromResultsDialog();		
	}

	*pResult = 0;
}

void CDlg_Results::OnNMCustomdrawSlider2(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	// TODO: Add your control notification handler code here

	static int lastSliderSelection = 0;

	hemA_achSliderPos = m_sliderAirtightness.GetPos();

	if (hemA_achSliderPos == lastSliderSelection)
	{
		// Slider bar has not been moved; this function called because
		// pointer was in the slider area. No action required.

		return;
	}
	else
	{
		// Slider position has changed; store it for next function
		// call
		lastSliderSelection = hemA_achSliderPos;
		is_make_eff_adjustments_slider_insulation = false;
		is_make_eff_adjustments_slider_exposure   = false;
		is_make_eff_adjustments_slider_airChanges = true;
		is_make_eff_adjustments_slider_capacity   = false;
		is_make_eff_adjustments_slider_occupancy  = false;
		is_make_eff_adjustments_slider_livingArea = false;
		is_make_eff_adjustments_slider_solarIngress = false;

		ReadInputsFromResultsDialog();
	}

	*pResult = 0;
}

void CDlg_Results::OnNMCustomdrawSlider3(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	// TODO: Add your control notification handler code here

	static int lastSliderSelection = 0;

	hemC_capacitySliderPos = m_sliderCapacity.GetPos();
	if (hemC_capacitySliderPos == lastSliderSelection)
	{
		// Slider bar has not been moved; this function called because
		// pointer was in the slider area. No action required.

		return;
	}
	else
	{
		// Slider position has changed; store it for next function
		// call
		lastSliderSelection = hemC_capacitySliderPos;
		is_make_eff_adjustments_slider_insulation = false;
		is_make_eff_adjustments_slider_exposure   = false;
		is_make_eff_adjustments_slider_airChanges = false;
		is_make_eff_adjustments_slider_capacity   = true;
		is_make_eff_adjustments_slider_occupancy  = false;
		is_make_eff_adjustments_slider_livingArea = false;
		is_make_eff_adjustments_slider_solarIngress = false;
		ReadInputsFromResultsDialog();
	}

	*pResult = 0;
}

void CDlg_Results::OnNMCustomdrawSlider4(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	// TODO: Add your control notification handler code here
	static int lastSliderSelection = 0;
   
	hemS_solarGainsSliderPos = m_sliderSolarIngress.GetPos();
	if (hemS_solarGainsSliderPos == lastSliderSelection)
	{
		// Slider bar has not been moved; this function called because
		// pointer was in the slider area. No action required.

		return;
	}
	else
	{
		// Slider position has changed; store it for next function
		// call
		lastSliderSelection = hemS_solarGainsSliderPos;
		is_make_eff_adjustments_slider_insulation = false;
		is_make_eff_adjustments_slider_exposure   = false;
		is_make_eff_adjustments_slider_airChanges = false;
		is_make_eff_adjustments_slider_capacity   = false;
		is_make_eff_adjustments_slider_occupancy  = false;
		is_make_eff_adjustments_slider_livingArea = false;
		is_make_eff_adjustments_slider_solarIngress = true;

		ReadInputsFromResultsDialog();
	}

	*pResult = 0;
}

void CDlg_Results::OnNMCustomdrawSlider5(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	// TODO: Add your control notification handler code here
	static int lastSliderSelection = 0;
   
	hemO_OCCDensitySliderPos = m_sliderOccupancy.GetPos();
	if (hemO_OCCDensitySliderPos == lastSliderSelection)
	{
		// Slider bar has not been moved; this function called because
		// pointer was in the slider area. No action required.

		return;
	}
	else
	{
		// Slider position has changed; store it for next function
		// call
		lastSliderSelection = hemO_OCCDensitySliderPos;
		is_make_eff_adjustments_slider_insulation = false;
		is_make_eff_adjustments_slider_exposure   = false;
		is_make_eff_adjustments_slider_airChanges = false;
		is_make_eff_adjustments_slider_capacity   = false;
		is_make_eff_adjustments_slider_occupancy  = true;
		is_make_eff_adjustments_slider_livingArea = false;
		is_make_eff_adjustments_slider_solarIngress = false;
		ReadInputsFromResultsDialog();
	}
	*pResult = 0;
}

void CDlg_Results::OnNMCustomdrawSlider6(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	// TODO: Add your control notification handler code here
	static int lastSliderSelection = 0;
   
	hemL_LAFracSliderPos = m_sliderControllesSpace.GetPos();
	if (hemL_LAFracSliderPos == lastSliderSelection)
	{
		// Slider bar has not been moved; this function called because
		// pointer was in the slider area. No action required.

		return;
	}
	else
	{
		// Slider position has changed; store it for next function
		// call
		lastSliderSelection = hemL_LAFracSliderPos;
		is_make_eff_adjustments_slider_insulation = false;
		is_make_eff_adjustments_slider_exposure   = false;
		is_make_eff_adjustments_slider_airChanges = false;
		is_make_eff_adjustments_slider_capacity   = false;
		is_make_eff_adjustments_slider_occupancy  = false;
		is_make_eff_adjustments_slider_livingArea = true;
		is_make_eff_adjustments_slider_solarIngress = false;
		ReadInputsFromResultsDialog();
	}

	
	*pResult = 0;
}

void CDlg_Results::OnCbnSelchangeCombo1()
{
	UpdateData(TRUE);

	enable_user_to_change_tab = true;
	file_new_selected = false;
	is_climate_changed_from_results = true;

	is_locationString_changed = true;

	locationString = str_comboClimate;
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnLbnSelchangeList2()
{
	UpdateData(true);

	is_house_type_changed_from_results = true;

	is_hemHouseType_changed = true;
	is_ins_slider_moved_due_to_house_type_change = true;
	is_ins_slider_moved_due_to_year_bilud_change = false;

	hemHouseType   = str_listHouseType;

	////---------------------------------------
	//// TFA is based on house type selected above
	////---------------------------------------
	//if(strcmp(hemHouseType,"Detached")==0)
	//{
	//	TFA = 141;
	//}
	//else if(strcmp(hemHouseType,"Semi-detached")==0)
	//{
	//	TFA = 87;
	//}
	//else if(strcmp(hemHouseType,"Terraced")==0)
	//{
	//	TFA = 90;
	//}
	//else if(strcmp(hemHouseType,"Tenement")==0)
	//{
	//	TFA = 60;
	//}
	//else if((strcmp(hemHouseType,"4-in-block")==0) || (strcmp(hemHouseType,"Tower/Slab")==0) || (strcmp(hemHouseType,"Conversion")==0))
	//{
	//	TFA = 68;
	//}	

	//---------------------------------------------
	//	YEAR OF BUILT is based on HOUSE TYPE
	//---------------------------------------------
	// Update year of built list based on house type
	m_listYearOfBuild.ResetContent();

	if((strcmp(str_listHouseType,"Detached")==0) 
		|| (strcmp(str_listHouseType,"Semi-detached")==0)
		|| (strcmp(str_listHouseType,"Terraced")==0) 
		|| (strcmp(str_listHouseType,"Tenement")==0) )
	{
		m_listYearOfBuild.InsertString(0,"pre 1919");
		m_listYearOfBuild.InsertString(1,"1919-44");
		m_listYearOfBuild.InsertString(2,"1945-64");
		m_listYearOfBuild.InsertString(3,"1965-82");
		m_listYearOfBuild.InsertString(4,"post 1982");
		m_listYearOfBuild.InsertString(5,"post 2002");
		m_listYearOfBuild.InsertString(6,"post 2006");
		m_listYearOfBuild.InsertString(7,"post 2010");
	}
	else if(strcmp(str_listHouseType,"4-in-block")==0)
	{
		m_listYearOfBuild.InsertString(0,"pre 1919");
		m_listYearOfBuild.InsertString(1,"1919-44");
		m_listYearOfBuild.InsertString(2,"1945-64");
		m_listYearOfBuild.InsertString(3,"1965-82");
	}
	else if(strcmp(str_listHouseType,"Tower/Slab")==0)
	{
		m_listYearOfBuild.InsertString(0,"1945-64");
	}
	else if(strcmp(str_listHouseType,"Conversion")==0)
	{
		m_listYearOfBuild.InsertString(0,"pre 1919");
	}

	WriteSHCSDataToDialogs();

	m_listYearOfBuild.SelectString(0,hemYearOfBuild);
	str_editFloorArea.Format("%.0f",TFA);
	UpdateData(FALSE);

	ChangeIndexNumberBasedOnHouseTypeAndAgeForResultsDialog();	
	ReadInputsFromResultsDialog();
	OnSelectHouseTypeFromResultsDlg();
	EnableOrDisableControls();
	CalculateResultsForSAPP(); // 3rd

	//---------------------------------------------
	// Update slider positions based on index number
	//---------------------------------------------
	m_sliderInsulation.SetPos(hemI_insulationSliderPos);
	m_sliderAirtightness.SetPos(hemA_achSliderPos);
	m_sliderCapacity.SetPos(hemC_capacitySliderPos);
	m_sliderSolarIngress.SetPos(hemS_solarGainsSliderPos);
	m_sliderOccupancy.SetPos(hemO_OCCDensitySliderPos);
	m_sliderControllesSpace.SetPos(hemL_LAFracSliderPos);
	m_sliderHeff.SetPos(hem_HeffSliderPos);
	m_sliderDHWeff.SetPos(hem_DHWeffSliderPos);
	UpdateData(true);	
}

void CDlg_Results::OnLbnSelchangeList3()
{
	UpdateData(true);
	is_year_of_build_changed = true;
	
    is_hemYearOfBuild_changed = true;

	is_ins_slider_moved_due_to_house_type_change = false;
	is_ins_slider_moved_due_to_year_bilud_change = true;

	//---------------------------------------------
	// Read House Type and Year of Built
	hemYearOfBuild = str_listYearOfBuild;
	
	//---------------------------------------------
	// Check slider check boxes 
	//---------------------------------------------
	if(is_results_values_read_first_time == true)
	{
		is_results_values_read_first_time = false;
		// Enable check boxes for determinants
		// @SHG
		//chkInsulation		= 0;
		chkInsulation		= 1;
		chkAirtightness		= 1;
		chkCapacity			= 1;
		chkSolarIngress		= 1;
		chkOccupancy		= 1;
		chkControlledSpace  = 1;
		chkHeatingEff       = 1;
		
		// @SHG
		// m_chkInsulation.SetCheck(0);
		m_chkInsulation.SetCheck(1);
		m_chkAirtightness.SetCheck(1);
		m_chkCapacity.SetCheck(1);
		m_chkSolarIngress.SetCheck(1);
		m_chkOccupancy.SetCheck(1);
		m_chkControlledSpace.SetCheck(1);
		m_chkHeatingEff.SetCheck(1);
		
		m_comboFuel.EnableWindow(TRUE);
		m_editHeatingEff.EnableWindow(TRUE);
		m_comboDHWfuel.EnableWindow(TRUE);		
		m_comboCoolingFuel.EnableWindow(TRUE);
		m_editCoolingEff.EnableWindow(TRUE);

		mainFuel = "Mains gas";
		m_comboDHWfuel.SelectString(0,"From main");
		btnWaterHtFromMainState  = 1;	
		chkDHWEff = 0;
		m_chkDHWEff.SetCheck(0);
		m_chkDHWEff.EnableWindow(FALSE);
		m_editDHWEff.EnableWindow(FALSE);		
	}

	//-------------------------------------------------------------------------
	// Update Heating fuel and effeciency each time user selects a house type
	//-------------------------------------------------------------------------
	WriteSHCSDataToDialogs();

	str_editFloorArea.Format("%.0f",TFA);
	UpdateData(false);

	if(mainHtEffNominal == 65)
		m_sliderHeff.SetPos(1);
	else if(mainHtEffNominal == 80)
		m_sliderHeff.SetPos(2);
	else if(mainHtEffNominal == 90)
		m_sliderHeff.SetPos(3);

	if(WHtEff == 65)
		m_sliderDHWeff.SetPos(1);
	else if(WHtEff == 80)
		m_sliderDHWeff.SetPos(2);
	else if(WHtEff == 90)
		m_sliderDHWeff.SetPos(3);

	str_comboFuel.Format("%s",mainFuel);	
	str_listYearOfBuild.Format("%s",hemYearOfBuild);
	
	if(	btnWaterHtFromMainState  == 1)
	{
		m_comboDHWfuel.SelectString(0,"From main");
		WHtEff = mainHtEffNominal; //@min
		WHtFuel = mainFuel;

		// Disable check box and slider
		m_chkDHWEff.EnableWindow(FALSE);
		m_sliderDHWeff.EnableWindow(FALSE);

	}
	else
	{
		str_comboDHWfuel.Format("%s",WHtFuel);
		// Disable check box and slider
		m_chkDHWEff.EnableWindow(TRUE);
		m_sliderDHWeff.EnableWindow(TRUE);
	}

	//str_editDHWEff.Format("%.0f",WHtEff);  @SHG 01.09.11
	
	//str_editHeatingEff.Format("%.0f",mainHtEff); 	//edit min 20140228 @SHG 01.09.11
	
	str_editFloorArea.Format("%.0f",TFA);
	UpdateData(FALSE);
	
	ChangeIndexNumberBasedOnHouseTypeAndAgeForResultsDialog();
	ReadInputsFromResultsDialog();
	//OnSelectYearOfBuildFromResultsDlg();
	EnableOrDisableControls();
	CalculateResultsForSAPP(); // 4th
	
	m_sliderInsulation.SetPos(hemI_insulationSliderPos);
	m_sliderAirtightness.SetPos(hemA_achSliderPos);
	m_sliderCapacity.SetPos(hemC_capacitySliderPos);
	m_sliderSolarIngress.SetPos(hemS_solarGainsSliderPos);
	m_sliderOccupancy.SetPos(hemO_OCCDensitySliderPos);
	m_sliderControllesSpace.SetPos(hemL_LAFracSliderPos);
	m_sliderHeff.SetPos(hem_HeffSliderPos);
	m_sliderDHWeff.SetPos(hem_DHWeffSliderPos);

	UpdateData(true);	
}

void CDlg_Results::OnEnChangeEdit17()
{
	TFA_from_HEM = true;	
	ChangeIndexNumberBasedOnHouseTypeAndAgeForResultsDialog();
	ReadInputsFromResultsDialog();

	isCheckRange_TFA = true;

	CalculateResultsForSAPP();
}

void CDlg_Results::OnCbnSelchangeCombo2()
{
	ReadInputsFromResultsDialog();
}

void CDlg_Results::OnEnChangeEdit18()
{
	ReadInputsFromResultsDialog();
}

void CDlg_Results::OnCbnSelchangeCombo4()
{
	ReadInputsFromResultsDialog();
	
	if(	btnWaterHtFromMainState  == 1)
	{
		// Disable check box and slider
		chkDHWEff = 0;
		m_chkDHWEff.EnableWindow(FALSE);
		m_chkDHWEff.SetCheck(0);
		m_sliderDHWeff.EnableWindow(FALSE);

	}
	else
	{
		// Enable check box and slider
		chkDHWEff = 1;
		m_chkDHWEff.SetCheck(1);
		m_chkDHWEff.EnableWindow(TRUE);
		m_sliderDHWeff.EnableWindow(TRUE);
	}
	UpdateData(FALSE);
}

void CDlg_Results::OnEnChangeEdit19()
{
	ReadInputsFromResultsDialog();
}

void CDlg_Results::OnCbnSelchangeCombo11()
{
	ReadInputsFromResultsDialog();
}

void CDlg_Results::OnEnChangeEdit20()
{
	ReadInputsFromResultsDialog();
}

void CDlg_Results::OnBnClickedCheck1()
{	
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck2()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck3()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck4()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck5()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck6()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck13()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck22()
{


	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck23()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck24()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck25()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck26()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnEnChangeEdit3()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
}

void CDlg_Results::OnEnChangeEdit34()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
}

void CDlg_Results::OnEnChangeEdit1()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
}

void CDlg_Results::OnBnClickedCheck19()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck21()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck27()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck20()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck28()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck29()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck30()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnStnClickedStatic2()
{
	// TODO: Add your control notification handler code here
}





void CDlg_Results::OnSelectHouseTypeFromResultsDlg()
{
	//-------------------------------------------------------------
	// Change poperty type to be displayed in Built Form Dialog
	//-------------------------------------------------------------

	if (strcmp(hemHouseType,"Conversion")==0)
	{
		if_change_house_type = false;
		if_change_flat_type  = false;
		return;
	}

	//-------------------------------------------------
	// Change property type
	//-------------------------------------------------
	if(strcmp(hemHouseType,"Detached")==0)
	{
		builtForm = "House";
		if_change_house_type = true;
		if_change_flat_type  = false;
	}

	if(strcmp(hemHouseType,"Semi-detached")==0)
	{
		builtForm = "House";
		if_change_house_type = true;
		if_change_flat_type  = false;
	}

	if(strcmp(hemHouseType,"Terraced")==0)
	{
		builtForm = "House";
		if_change_house_type = true;
		if_change_flat_type  = false;
	}

	if(strcmp(hemHouseType,"Tenement")==0)
	{
		builtForm = "Flat";
		if_change_house_type = false;
		if_change_flat_type  = true;
	}

	if(strcmp(hemHouseType,"4-in-block")==0)
	{
		builtForm = "Maisonette";
		if_change_house_type = false;
		if_change_flat_type  = true;

	}

	if(strcmp(hemHouseType,"Tower/Slab")==0) 
	{
		builtForm = "Flat";
		if_change_house_type = false;
		if_change_flat_type  = true;
	}
	
	//-------------------------------------------------------------
	// Change detachment for house and built flat type for flat
	//-------------------------------------------------------------
	if(if_change_house_type == true)
	{
		if(strcmp(hemHouseType,"Detached")==0)
		{
			Detachment = "Detached";	
		}

		if(strcmp(hemHouseType,"Semi-detached")==0)
		{
			Detachment = "Semi-detached";
		}

		if(strcmp(hemHouseType,"Terraced")==0)
		{
			Detachment = "Mid terrace";
		}
	}
	else if(if_change_flat_type == true)
	{
		if((strcmp(hemHouseType,"Tenement")==0) ||
		   (strcmp(hemHouseType,"4-in-block")==0) ||
		   (strcmp(hemHouseType,"Tower/Slab")==0))
		{
			FlatPosition     = "Ground floor";
		}		
	}

	//MessageBox("You have changed the house type!", "Warning", MB_OK);	
}

void CDlg_Results::DisplayHouseTypeOnResultsDlgBasedOnBuiltForm()
{
	if(file_new_selected ==true)
	{
		return;
	}

	CString previousHemHouseType;
	previousHemHouseType = hemHouseType;
	
	// If conversion, dont do anything
	if(strcmp(previousHemHouseType,"Conversion")==0)
	{
		return;
	}

	if(strcmp(Detachment,"Detached")==0)
	{
		m_listHouseType.SetCurSel(0);
		hemHouseType="Detached";
	}
	
	if(strcmp(Detachment,"Semi-detached")==0)
	{
		m_listHouseType.SetCurSel(1);
		hemHouseType="Semi-detached";
	}
	
	if((strcmp(Detachment,"Mid terrace")==0) ||
	   (strcmp(Detachment,"End terrace")==0) ||
	   (strcmp(Detachment,"Enclosed mid terrace")==0)||
	   (strcmp(Detachment,"Enclosed end terrace")==0))
	{
		m_listHouseType.SetCurSel(2);
		hemHouseType="Terraced";
	}

	if((strcmp(builtForm,"Flat")==0) && (strcmp(previousHemHouseType,"Tenement")==0))
	{
		m_listHouseType.SetCurSel(3);
		hemHouseType = "Tenement";
	}

	if((strcmp(builtForm,"Flat")==0) && (strcmp(previousHemHouseType,"Tower/Slab")==0))
	{
		m_listHouseType.SetCurSel(5);
		hemHouseType = "Tower/Slab";
	}

	if(strcmp(builtForm,"Maisonette")==0)
	{
		m_listHouseType.SetCurSel(4);
		hemHouseType="4-in-block";
	}	
}

void CDlg_Results::OnSelectYearOfBuildFromResultsDlg()
{
	CString hemYearOfBuild_previous;
	CString yearPropertBuilt_previous;
	hemYearOfBuild_previous   = hemYearOfBuild;
	yearPropertBuilt_previous = yearPropertBuilt;

	if(strcmp(hemYearOfBuild,"pre 1919")==0) 
	{	
		yearPropertBuilt = "1918";
	}
	if(strcmp(hemYearOfBuild,"1919-44")==0) 
	{	
		yearPropertBuilt = "1919";
	}
	if(strcmp(hemYearOfBuild,"1945-644")==0) 
	{	
		yearPropertBuilt = "1945";
	}
	if(strcmp(hemYearOfBuild,"1945-644")==0) 
	{	
		yearPropertBuilt = "1945";
	}
	

	//yearPropertBuilt
}


void CDlg_Results::DisplayYearOfBuildOnResultsDlgBasedOnBuiltForm()
{
	int yearPropertBuilt_temp;
	yearPropertBuilt_temp = atoi(yearPropertBuilt);

	if(yearPropertBuilt_temp <=1918)
	{
		m_listYearOfBuild.SetCurSel(0);
		hemYearOfBuild = "pre 1919";
	}
	if((yearPropertBuilt_temp >=1919) && (yearPropertBuilt_temp <=1944))
	{
		m_listYearOfBuild.SetCurSel(1);
		hemYearOfBuild = "1919-44";
	}
	if((yearPropertBuilt_temp >=1945) && (yearPropertBuilt_temp <=1964))
	{
		m_listYearOfBuild.SetCurSel(2);
		hemYearOfBuild = "1945-64";
	}
	if((yearPropertBuilt_temp >=1965) && (yearPropertBuilt_temp <=1982))
	{
		m_listYearOfBuild.SetCurSel(3);
		hemYearOfBuild = "1965-82";
	}
	if((yearPropertBuilt_temp >1982) && (yearPropertBuilt_temp <=2002))
	{
		m_listYearOfBuild.SetCurSel(4);
		hemYearOfBuild = "post 1982";
	}
	if((yearPropertBuilt_temp >=2002) && (yearPropertBuilt_temp <2006))
	{
		m_listYearOfBuild.SetCurSel(5);
		hemYearOfBuild = "post 2002";
	}
	if((yearPropertBuilt_temp >=2006) && (yearPropertBuilt_temp <2010))
	{
		m_listYearOfBuild.SetCurSel(6);
		hemYearOfBuild = "post 2006";
	}
	if(yearPropertBuilt_temp >=2010) 
	{

		m_listYearOfBuild.SetCurSel(7);
		hemYearOfBuild = "post 2010";
	}

}

void CDlg_Results::OnBnClickedCheck34()
{
	if(m_chkActual.GetCheck() == 0)
	{
		chkActual = 0;
		chkperm2 = 1;
		m_chkperm2.SetCheck(1);
	}
	else
	{
		chkActual = 1;
		chkperm2 = 0;
		m_chkperm2.SetCheck(0);
	}

	ReadInputsFromResultsDialog();

	if(is_base_selected == true)
	{
		DisplayBaseResultsForEnergyCostOrEmissions();
	}
	if(is_imp1_selected == true)
	{
		DisplayImp1ResultsForEnergyCostOrEmissions();
	}

	if(is_imp2_selected == true)
	{
		DisplayImp2ResultsForEnergyCostOrEmissions();
	}

	if(is_imp3_selected == true)
	{
		DisplayImp3ResultsForEnergyCostOrEmissions();
	}

	if(is_imp4_selected == true)
	{
		DisplayImp4ResultsForEnergyCostOrEmissions();
	}

	if(is_imp5_selected == true)
	{
		DisplayImp5ResultsForEnergyCostOrEmissions();
	}
}

void CDlg_Results::OnBnClickedCheck31()
{
	if(m_chkperm2.GetCheck() == 0)
	{
		chkActual = 1;
		chkperm2 = 0;
		m_chkActual.SetCheck(1);
	}
	else
	{
		chkActual = 0;
		chkperm2 = 1;
		m_chkActual.SetCheck(0);
	}

	ReadInputsFromResultsDialog();
	if(is_base_selected == true)
	{
		DisplayBaseResultsForEnergyCostOrEmissions();
	}
	if(is_imp1_selected == true)
	{
		DisplayImp1ResultsForEnergyCostOrEmissions();
	}

	if(is_imp2_selected == true)
	{
		DisplayImp2ResultsForEnergyCostOrEmissions();
	}

	if(is_imp3_selected == true)
	{
		DisplayImp3ResultsForEnergyCostOrEmissions();
	}

	if(is_imp4_selected == true)
	{
		DisplayImp4ResultsForEnergyCostOrEmissions();
	}

	if(is_imp5_selected == true)
	{
		DisplayImp5ResultsForEnergyCostOrEmissions();
	}
}

void CDlg_Results::OnBnClickedCheck32()
{
	if(m_chkEnergy.GetCheck() == 1)
	{
		chkEnergy    = 1;
		chkCost      = 0;
		chkEmissions = 0;
		m_chkCost.SetCheck(0);
		m_chkEmissions .SetCheck(0);
	}
	else
	{
		chkEnergy    = 0;
	}

	//-------------------------------------------------------------
	// If all energy, cost and emission check boxes are not checked,
	// set energy chk box to true 
	if((chkEnergy == 0) && (chkCost == 0) && (chkEmissions == 0))
	{
		chkEnergy = 1;
		m_chkEnergy.SetCheck(1);
	}
		

	ReadInputsFromResultsDialog();

	if(is_base_selected == true)
	{
		DisplayBaseResultsForEnergyCostOrEmissions();
	}
	if(is_imp1_selected == true)
	{
		DisplayImp1ResultsForEnergyCostOrEmissions();
	}

	if(is_imp2_selected == true)
	{
		DisplayImp2ResultsForEnergyCostOrEmissions();
	}

	if(is_imp3_selected == true)
	{
		DisplayImp3ResultsForEnergyCostOrEmissions();
	}

	if(is_imp4_selected == true)
	{
		DisplayImp4ResultsForEnergyCostOrEmissions();
	}

	if(is_imp5_selected == true)
	{
		DisplayImp5ResultsForEnergyCostOrEmissions();
	}
}

void CDlg_Results::OnBnClickedCheck33()
{
	if(m_chkCost.GetCheck() == 1)
	{
		chkCost      = 1;
		chkEnergy    = 0;		
		chkEmissions = 0;
		m_chkEnergy.SetCheck(0);
		m_chkEmissions .SetCheck(0);
	}
	else
	{
		chkCost    = 0;
	}

	//-------------------------------------------------------------
	// If all energy, cost and emission check boxes are not checked,
	// set energy chk box to true 
	if((chkEnergy == 0) && (chkCost == 0) && (chkEmissions == 0))
	{
		chkEnergy = 1;
		m_chkEnergy.SetCheck(1);
	}

	ReadInputsFromResultsDialog();
	if(is_base_selected == true)
	{
		DisplayBaseResultsForEnergyCostOrEmissions();
	}
	if(is_imp1_selected == true)
	{
		DisplayImp1ResultsForEnergyCostOrEmissions();
	}

	if(is_imp2_selected == true)
	{
		DisplayImp2ResultsForEnergyCostOrEmissions();
	}

	if(is_imp3_selected == true)
	{
		DisplayImp3ResultsForEnergyCostOrEmissions();
	}

	if(is_imp4_selected == true)
	{
		DisplayImp4ResultsForEnergyCostOrEmissions();
	}

	if(is_imp5_selected == true)
	{
		DisplayImp5ResultsForEnergyCostOrEmissions();
	}
}

void CDlg_Results::OnBnClickedCheck35()
{
	if(m_chkEmissions.GetCheck() == 1)
	{
		chkEmissions = 1;
		chkCost      = 0;
		chkEnergy    = 0;		
		
		m_chkEnergy.SetCheck(0);
		m_chkCost .SetCheck(0);
	}
	else
	{
		chkEmissions    = 0;
	}

	//-------------------------------------------------------------
	// If all energy, cost and emission check boxes are not checked,
	// set energy chk box to true 
	if((chkEnergy == 0) && (chkCost == 0) && (chkEmissions == 0))
	{
		chkEnergy = 1;
		m_chkEnergy.SetCheck(1);
	}

	ReadInputsFromResultsDialog();

	if(is_base_selected == true)
	{
		DisplayBaseResultsForEnergyCostOrEmissions();
	}
	if(is_imp1_selected == true)
	{
		DisplayImp1ResultsForEnergyCostOrEmissions();
	}

	if(is_imp2_selected == true)
	{
		DisplayImp2ResultsForEnergyCostOrEmissions();
	}

	if(is_imp3_selected == true)
	{
		DisplayImp3ResultsForEnergyCostOrEmissions();
	}

	if(is_imp4_selected == true)
	{
		DisplayImp4ResultsForEnergyCostOrEmissions();
	}

	if(is_imp5_selected == true)
	{
		DisplayImp5ResultsForEnergyCostOrEmissions();
	}
}

void CDlg_Results::OnStnClickedStaticUnits()
{

}

void CDlg_Results::OnBnClickedCheck36()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnBnClickedCheck37()
{
	ReadInputsFromResultsDialog();
	EnableOrDisableControls();
}

void CDlg_Results::OnStnClickedStaticImp1()
{
	// TODO: Add your control notification handler code here
}

void CDlg_Results::OnEnChangeEdit50()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
}

void CDlg_Results::OnEnChangeEdit68()
{
	// TODO:  If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.

	// TODO:  Add your control notification handler code here
}

void CDlg_Results::OnNMCustomdrawSlider7(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);

	static int lastSliderSelection = 0;

	hem_HeffSliderPos = m_sliderHeff.GetPos();
	if (hem_HeffSliderPos == lastSliderSelection)
	{
		// Slider bar has not been moved; this function called because
		// pointer was in the slider area. No action required.

		return;
	}
	else
	{
		// Slider position has changed; store it for next function
		// call
		lastSliderSelection = hem_HeffSliderPos;

		// Heating Eff
		if( hem_HeffSliderPos == 1)
		{
			mainHtEffNominal = 65;  //@min 20140303
		}
		else if( hem_HeffSliderPos == 2)
		{
			mainHtEffNominal = 80;  //@min
		}
		else if( hem_HeffSliderPos == 3)
		{
			mainHtEffNominal = 90;  //@min
		}
		ReadInputsFromResultsDialog();
	}

	*pResult = 0;
}

void CDlg_Results::OnNMCustomdrawSlider8(NMHDR *pNMHDR, LRESULT *pResult)
{
	LPNMCUSTOMDRAW pNMCD = reinterpret_cast<LPNMCUSTOMDRAW>(pNMHDR);
	
	static int lastSliderSelection = 0;

	hem_DHWeffSliderPos = m_sliderDHWeff.GetPos();
	if (hem_DHWeffSliderPos == lastSliderSelection)
	{
		// Slider bar has not been moved; this function called because
		// pointer was in the slider area. No action required.
		return;
	}
	else
	{
		// Slider position has changed; store it for next function
		// call
		lastSliderSelection = hem_DHWeffSliderPos;
		
		// DHW Eff
		if( hem_DHWeffSliderPos == 1)
		{
			WHtEff = 65;
		}
		else if( hem_DHWeffSliderPos == 2)
		{
			WHtEff = 80;
		}
		else if( hem_DHWeffSliderPos == 3)
		{
			WHtEff = 90;
		}
		ReadInputsFromResultsDialog();
	}
	*pResult = 0;
}


 