// Dlg_Ventilation.cpp : implementation file
//

#include "stdafx.h"
#include "SAPP1.h"
#include "SAPP1Dlg.h"
#include "Dlg_Ventilation.h"

CToolTipCtrl *m_ToolTip;

// CDlg_Ventilation dialog

IMPLEMENT_DYNAMIC(CDlg_Ventilation, CDialog)
CDlg_Ventilation::CDlg_Ventilation(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_Ventilation::IDD, pParent)
	, str_comboDesignAirPerm(_T(""))
	, str_comboPressureTestScot(_T(""))
	, str_comboAccreditedDetailsScot(_T(""))
	, str_comboseekExemption(_T(""))
	, str_editDesignAirPermRate(_T(""))
	, str_editAsBuiltAirPermRate(_T(""))
	, str_comboIsAirPermMeasured(_T(""))
	, str_editAsBuiltRef(_T(""))
	, str_comboAsBuiltTestDate(_T(""))
	, str_comboDraughtLobby(_T(""))
	, str_comboMechVentType(_T(""))
	, str_comboMechVentValuesFrom(_T(""))
	, str_comboNumsWetRooms(_T(""))
	, str_comboDuctInsulation(_T(""))
	, str_editNumsOpenFirePlaces(_T(""))
	, str_editNumsOpenFlues(_T(""))
	, str_editNumsFluelessGasFires(_T(""))
	, str_editNumsExtractFans(_T(""))
	, str_editNumsPassiveVents(_T(""))
	, str_comboACPresent(_T(""))
	, str_editACenergyUse(_T(""))
	, str_comboPressTest(_T(""))
	, str_editMeasuredq50(_T(""))
	, str_editNumOfStoreys(_T(""))
	, str_comboStructInf(_T(""))
	, str_comboFloorInf(_T(""))
	, str_comboPerDraughtStripped(_T(""))
	, str_editVentEff(_T(""))
	, str_editSFP(_T(""))
	, str_comboNumShelteredSides(_T(""))
{
}

CDlg_Ventilation::~CDlg_Ventilation()
{
}

void CDlg_Ventilation::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_STATIC_air, m_labelAirPermeability);
	DDX_Control(pDX, IDC_STATIC_numOfChimneys, m_labelNumOfChimneysAndFlues);
	DDX_Control(pDX, IDC_STATIC_numOfPassiveVentsFans, m_labelNumOfPassiveVentsnFans);
	DDX_Control(pDX, IDC_STATIC_mechVentilation, m_labelMechVentilation);
	DDX_Control(pDX, IDC_STATIC_air5, m_labelAirCond);
	DDX_Control(pDX, IDC_STATIC_CSH, m_labelCSH);
	DDX_Control(pDX, IDC_COMBO_DesignAirPermeability, m_comboDesignAirPerm);
	DDX_Control(pDX, IDC_COMBO_PressureTestScotland, m_comboPressureTestScot);
	DDX_Control(pDX, IDC_COMBOAccreditedDetailsScotland, m_comboAccreditedDetailsScot);
	DDX_Control(pDX, IDC_COMBO_SeekExemption, m_comboseekExemption);
	DDX_Control(pDX, IDC_COMBO_MeasuredInThisDwelling, m_comboIsAirPermMeasured);
	DDX_Control(pDX, IDC_COMBO_AsBuiltTestDate, m_comboAsBuiltTestDate);
	DDX_Control(pDX, IDC_COMBO_DraughtLobby, m_comboDraughtLobby);
	DDX_Control(pDX, IDC_COMBO_MechVent, m_comboMechVentType);
	DDX_Control(pDX, IDC_COMBO_ValuesFrom, m_comboMechVentValuesFrom);
	DDX_Control(pDX, IDC_COMBO_NumOfWetRooms, m_comboNumsWetRooms);
	DDX_Control(pDX, IDC_COMBO_DuctInsulation, m_comboDuctInsulation);
	DDX_Control(pDX, IDC_COMBO_ACpresent, m_comboACPresent);
	DDX_Control(pDX, IDC_EDIT_DesAirPermeabilityRate, m_editDesignAirPermRate);
	DDX_Control(pDX, IDC_EDITAsBuiltAirPermRate, m_editAsBuiltAirPermRate);
	DDX_Control(pDX, IDC_EDIT_AsBuiltRef, m_editAsBuiltRef);
	DDX_Control(pDX, IDC_EDIT_OPenFirePlaces, m_editNumsOpenFirePlaces);
	DDX_Control(pDX, IDC_EDIT_OpenFlues, m_editNumsFluelessGasFires);
	DDX_Control(pDX, IDC_EDIT_FluelessGasFires, m_editNumsOpenFlues);
	DDX_Control(pDX, IDC_EDIT_NumExtractFans, m_editNumsExtractFans);
	DDX_Control(pDX, IDC_EDIT_NumPassiveVents, m_editNumsPassiveVents);
	DDX_Control(pDX, IDC_EDIT_ACenergyUse, m_editACenergyUse);

	DDX_CBString(pDX, IDC_COMBO_DesignAirPermeability, str_comboDesignAirPerm);
	DDX_CBString(pDX, IDC_COMBO_PressureTestScotland, str_comboPressureTestScot);
	DDX_CBString(pDX, IDC_COMBOAccreditedDetailsScotland, str_comboAccreditedDetailsScot);
	DDX_CBString(pDX, IDC_COMBO_SeekExemption, str_comboseekExemption);
	DDX_Text(pDX, IDC_EDIT_DesAirPermeabilityRate, str_editDesignAirPermRate);
	DDX_Text(pDX, IDC_EDITAsBuiltAirPermRate, str_editAsBuiltAirPermRate);
	DDX_CBString(pDX, IDC_COMBO_MeasuredInThisDwelling, str_comboIsAirPermMeasured);
	DDX_Text(pDX, IDC_EDIT_AsBuiltRef, str_editAsBuiltRef);
	DDX_CBString(pDX, IDC_COMBO_AsBuiltTestDate, str_comboAsBuiltTestDate);
	DDX_CBString(pDX, IDC_COMBO_DraughtLobby, str_comboDraughtLobby);
	DDX_CBString(pDX, IDC_COMBO_MechVent, str_comboMechVentType);
	DDX_CBString(pDX, IDC_COMBO_ValuesFrom, str_comboMechVentValuesFrom);
	DDX_CBString(pDX, IDC_COMBO_NumOfWetRooms, str_comboNumsWetRooms);
	DDX_CBString(pDX, IDC_COMBO_DuctInsulation, str_comboDuctInsulation);
	DDX_Text(pDX, IDC_EDIT_OPenFirePlaces, str_editNumsOpenFirePlaces);
	DDX_Text(pDX, IDC_EDIT_FluelessGasFires, str_editNumsOpenFlues);
	DDX_Text(pDX, IDC_EDIT_OpenFlues, str_editNumsFluelessGasFires);
	DDX_Text(pDX, IDC_EDIT_NumExtractFans, str_editNumsExtractFans);
	DDX_Text(pDX, IDC_EDIT_NumPassiveVents, str_editNumsPassiveVents);
	DDX_CBString(pDX, IDC_COMBO_ACpresent, str_comboACPresent);
	DDX_Text(pDX, IDC_EDIT_ACenergyUse, str_editACenergyUse);
	DDX_Control(pDX, IDC_COMBO1, m_comboPressTest);
	DDX_CBString(pDX, IDC_COMBO1, str_comboPressTest);
	DDX_Control(pDX, IDC_EDIT1, m_editMeasuredq50);
	DDX_Text(pDX, IDC_EDIT1, str_editMeasuredq50);
	DDX_Control(pDX, IDC_EDIT2, m_editNumOfStoreys);
	DDX_Text(pDX, IDC_EDIT2, str_editNumOfStoreys);
	DDX_Control(pDX, IDC_COMBO12, m_comboStructInf);
	DDX_CBString(pDX, IDC_COMBO12, str_comboStructInf);
	DDX_Control(pDX, IDC_COMBO13, m_comboFloorInf);
	DDX_CBString(pDX, IDC_COMBO13, str_comboFloorInf);
	DDX_Control(pDX, IDC_COMBO15, m_comboPerDraughtStripped);
	DDX_CBString(pDX, IDC_COMBO15, str_comboPerDraughtStripped);
	DDX_Control(pDX, IDC_EDIT3, m_editVentEff);
	DDX_Text(pDX, IDC_EDIT3, str_editVentEff);
	DDX_Control(pDX, IDC_STATIC_1, m_labelMechVentEff);
	DDX_Control(pDX, IDC_EDIT4, m_editSFP);
	DDX_Text(pDX, IDC_EDIT4, str_editSFP);
	DDX_Control(pDX, IDC_STATIC_2, m_labelSFP);
	DDX_Control(pDX, IDC_COMBO4, m_comboNumShelteredSides);
	DDX_CBString(pDX, IDC_COMBO4, str_comboNumShelteredSides);
	DDX_Control(pDX, IDC_STATIC_3, m_labelPer);
	DDX_Control(pDX, IDC_STATIC_suspFloor, m_labelSuspFloorInf);
	DDX_Control(pDX, IDC_STATIC_4, m_labelSFPunit);
	DDX_Control(pDX, IDC_STATIC_SFPinfo, m_labelSFPinfo);
	DDX_Control(pDX, IDC_STATIC_mq50, m_labelMeasuredQ50);
	DDX_Control(pDX, IDC_STATIC_numStoreys, m_labelNumStoreys);
	DDX_Control(pDX, IDC_STATIC_structInf, m_labelStructInf);
	DDX_Control(pDX, IDC_STATIC_draughtLobby, m_labelDraughtLobby);
	DDX_Control(pDX, IDC_STATIC_perWindows, m_labelPerWindows);

	
}

BEGIN_MESSAGE_MAP(CDlg_Ventilation, CDialog)
	ON_CBN_SELCHANGE(IDC_COMBO_DesignAirPermeability, OnCbnSelchangeComboDesignairpermeability)
	ON_CBN_SELCHANGE(IDC_COMBO_PressureTestScotland, OnCbnSelchangeComboPressuretestscotland)
	ON_CBN_SELCHANGE(IDC_COMBOAccreditedDetailsScotland, OnCbnSelchangeComboaccrediteddetailsscotland)
	ON_CBN_SELCHANGE(IDC_COMBO_SeekExemption, OnCbnSelchangeComboSeekexemption)
	ON_EN_CHANGE(IDC_EDIT_DesAirPermeabilityRate, OnEnChangeEditDesairpermeabilityrate)
	ON_EN_CHANGE(IDC_EDITAsBuiltAirPermRate, OnEnChangeEditasbuiltairpermrate)
	ON_CBN_SELCHANGE(IDC_COMBO_MeasuredInThisDwelling, OnCbnSelchangeComboMeasuredinthisdwelling)
	ON_EN_CHANGE(IDC_EDIT_AsBuiltRef, OnEnChangeEditAsbuiltref)
	ON_CBN_SELCHANGE(IDC_COMBO_AsBuiltTestDate, OnCbnSelchangeComboAsbuilttestdate)
	ON_CBN_SELCHANGE(IDC_COMBO_DraughtLobby, OnCbnSelchangeComboDraughtlobby)
	ON_CBN_SELCHANGE(IDC_COMBO_MechVent, OnCbnSelchangeComboMechvent)
	ON_CBN_SELCHANGE(IDC_COMBO_ValuesFrom, OnCbnSelchangeComboValuesfrom)
	ON_CBN_SELCHANGE(IDC_COMBO_NumOfWetRooms, OnCbnSelchangeComboNumofwetrooms)
	ON_CBN_SELCHANGE(IDC_COMBO_DuctInsulation, OnCbnSelchangeComboDuctinsulation)
	ON_EN_CHANGE(IDC_EDIT_OPenFirePlaces, OnEnChangeEditOpenfireplaces)
	ON_EN_CHANGE(IDC_EDIT_FluelessGasFires, OnEnChangeEditFluelessgasfires)
	ON_EN_CHANGE(IDC_EDIT_OpenFlues, OnEnChangeEditOpenflues)
	ON_EN_CHANGE(IDC_EDIT_NumExtractFans, OnEnChangeEditNumextractfans)
	ON_EN_CHANGE(IDC_EDIT_NumPassiveVents, OnEnChangeEditNumpassivevents)
	ON_CBN_SELCHANGE(IDC_COMBO_ACpresent, OnCbnSelchangeComboAcpresent)
	ON_EN_CHANGE(IDC_EDIT_ACenergyUse, OnEnChangeEditAcenergyuse)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
	ON_CBN_SELCHANGE(IDC_COMBO12, OnCbnSelchangeCombo12)
	ON_CBN_SELCHANGE(IDC_COMBO13, OnCbnSelchangeCombo13)
	ON_CBN_SELCHANGE(IDC_COMBO15, OnCbnSelchangeCombo15)
	ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
	ON_EN_CHANGE(IDC_EDIT2, OnEnChangeEdit2)
	ON_EN_CHANGE(IDC_EDIT4, OnEnChangeEdit4)
	ON_EN_CHANGE(IDC_EDIT3, OnEnChangeEdit3)	
	
END_MESSAGE_MAP()

// CDlg_Ventilation message handlers

BOOL CDlg_Ventilation::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	//---------------------------------------------------
	// LABELS
	//---------------------------------------------------
	CFont *m_Font1 = new CFont;
	m_Font1->CreatePointFont(90, "Arial Bold");

	m_labelAirPermeability.SetFont(m_Font1); 
	m_labelAirPermeability.SetTextColor(BLUE);  

	m_labelNumOfChimneysAndFlues.SetFont(m_Font1); 
	m_labelNumOfChimneysAndFlues.SetTextColor(BLUE);  

	m_labelNumOfPassiveVentsnFans.SetFont(m_Font1);  
	m_labelNumOfPassiveVentsnFans.SetTextColor(BLUE);  

	m_labelMechVentilation.SetFont(m_Font1);  
	m_labelMechVentilation.SetTextColor(BLUE);  

	m_labelAirCond.SetFont(m_Font1); 
	m_labelAirCond.SetTextColor(BLUE);  

	m_labelCSH.SetTextColor(RED);
	m_labelSFPinfo.SetTextColor(RED);

	//---------------------------------------------------
	// DROP DOWN MENUS
	//---------------------------------------------------
	AddStringsForVentilationDlg();	
	
	if(file_new_selected ==true)
	{
		SetAllValuesToDefault();		
	}

	DisplayValuesForVentilationDlg();
	ReadInputsFromVentilationDlg();

	//---------------------------------------------------
	// Disable or enaable edit boxes
	//---------------------------------------------------
	if(strcmp(pressureTestYN,"Yes")==0)
	{
		m_editMeasuredq50.ShowWindow(TRUE);
		m_editNumOfStoreys.ShowWindow(FALSE);
		m_comboStructInf.ShowWindow(FALSE);
		m_comboFloorInf.ShowWindow(FALSE);
		m_comboDraughtLobby.ShowWindow(FALSE);
		m_comboPerDraughtStripped.ShowWindow(FALSE);
		
		m_labelMeasuredQ50.ShowWindow(TRUE);
		m_labelNumStoreys.ShowWindow(FALSE);
		m_labelStructInf.ShowWindow(FALSE);
		m_labelDraughtLobby.ShowWindow(FALSE);
		m_labelPerWindows.ShowWindow(FALSE);
		m_labelSuspFloorInf.ShowWindow(FALSE);
	}
	else
	{
		m_editMeasuredq50.ShowWindow(FALSE);
		m_editNumOfStoreys.ShowWindow(TRUE);
		m_comboStructInf.ShowWindow(TRUE);
		m_comboFloorInf.ShowWindow(TRUE);
		m_comboDraughtLobby.ShowWindow(TRUE);
		m_comboPerDraughtStripped.ShowWindow(TRUE);

		m_labelMeasuredQ50.ShowWindow(FALSE);
		m_labelNumStoreys.ShowWindow(TRUE);
		m_labelStructInf.ShowWindow(TRUE);
		m_labelDraughtLobby.ShowWindow(TRUE);
		m_labelPerWindows.ShowWindow(TRUE);
		m_labelSuspFloorInf.ShowWindow(TRUE);
	}

	//-------------------------------------------------------
	//Add tool tips
	//-------------------------------------------------------	
	m_ToolTip= new CToolTipCtrl();
	m_ToolTip->Create(this);
	m_ToolTip->AddTool(&m_labelSuspFloorInf,"0.1 if sealed, 0.2 if unsealed, 0 if solid");
	m_ToolTip->Activate(TRUE);

    return TRUE;
}

void CDlg_Ventilation::AddStringsForVentilationDlg()
{
	m_comboDesignAirPerm.InsertString(0,"Yes");
	m_comboDesignAirPerm.InsertString(1,"No");

	m_comboPressureTestScot.InsertString(0,"Yes");
	m_comboPressureTestScot.InsertString(1,"No");

	m_comboAccreditedDetailsScot.InsertString(0,"Yes");
	m_comboAccreditedDetailsScot.InsertString(1,"No");

	m_comboseekExemption.InsertString(0,"Yes");
	m_comboseekExemption.InsertString(1,"No");

	m_comboIsAirPermMeasured.InsertString(0,"Yes");
	m_comboIsAirPermMeasured.InsertString(1,"No");

	m_comboAsBuiltTestDate.InsertString(0,"not available");

	m_comboMechVentType.InsertString(0,"Not present (natural)");
	m_comboMechVentType.InsertString(1,"Balanced (with heat recovery)");
	m_comboMechVentType.InsertString(2,"Balanced (without heat recovery)");
	m_comboMechVentType.InsertString(3,"Mechanical extract vent");
	m_comboMechVentType.InsertString(4,"Positive input from loft");
	m_comboMechVentType.InsertString(5,"Positive input from outside");

	m_comboPressTest.InsertString(0,"Yes");
	m_comboPressTest.InsertString(1,"No");

	m_comboStructInf.InsertString(0,"0.25");
	m_comboStructInf.InsertString(1,"0.35");

	m_comboFloorInf.InsertString(0,"0.1");
	m_comboFloorInf.InsertString(1,"0.2");
	m_comboFloorInf.InsertString(2,"0");

	m_comboDraughtLobby.InsertString(0,"Yes");
	m_comboDraughtLobby.InsertString(1,"No");

	m_comboPerDraughtStripped.InsertString(0,"0");
	m_comboPerDraughtStripped.InsertString(1,"10");
	m_comboPerDraughtStripped.InsertString(2,"30");
	m_comboPerDraughtStripped.InsertString(3,"30");
	m_comboPerDraughtStripped.InsertString(4,"40");
	m_comboPerDraughtStripped.InsertString(5,"50");
	m_comboPerDraughtStripped.InsertString(6,"60");
	m_comboPerDraughtStripped.InsertString(7,"70");
	m_comboPerDraughtStripped.InsertString(8,"80");
	m_comboPerDraughtStripped.InsertString(9,"90");
	m_comboPerDraughtStripped.InsertString(10,"100");

	m_comboNumShelteredSides.InsertString(0,"0");
	m_comboNumShelteredSides.InsertString(1,"1");
	m_comboNumShelteredSides.InsertString(2,"2");
	m_comboNumShelteredSides.InsertString(3,"3");
	m_comboNumShelteredSides.InsertString(4,"4");
}

void CDlg_Ventilation::EnableOrDisableControlsBasedOnDesignAirPerm()
{
	if (str_comboDesignAirPerm == "Yes")
	{
		m_comboPressureTestScot.EnableWindow(FALSE);
		m_comboAccreditedDetailsScot.EnableWindow(FALSE);
		m_comboseekExemption.EnableWindow(TRUE);
		m_comboIsAirPermMeasured.EnableWindow(FALSE);
		m_comboAsBuiltTestDate.EnableWindow(FALSE);
		m_comboDraughtLobby.EnableWindow(FALSE);
	}
	else	
	{
		m_comboPressureTestScot.EnableWindow(FALSE);
		m_comboAccreditedDetailsScot.EnableWindow(FALSE);
		m_comboseekExemption.EnableWindow(FALSE);
		m_comboIsAirPermMeasured.EnableWindow(FALSE);
		m_comboAsBuiltTestDate.EnableWindow(FALSE);
		m_comboDraughtLobby.EnableWindow(FALSE);
	}	
}

void CDlg_Ventilation::OnCbnSelchangeComboDesignairpermeability()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::DisplayValuesForVentilationDlg()
{ 
	str_comboDesignAirPerm.Format("%s",designAirPermeability);
	str_comboPressureTestScot.Format("%s",pressureTestScotland);
	str_comboAccreditedDetailsScot.Format("%s",accreditedDetailsScotland);
	str_comboseekExemption.Format("%s",seekExemptionForLT3Dwellings);

	str_editDesignAirPermRate.Format("%.1f",designAirPermRate);
	str_editAsBuiltAirPermRate.Format("%.1f",asBuiltAirPermRate);

	str_comboIsAirPermMeasured.Format("%s",airPermMeasuredInDwelling);
	str_editAsBuiltRef.Format("%s",asBuiltRef);
	str_comboAsBuiltTestDate.Format("%s",asBuiltTestDate);
	
	str_comboMechVentType.Format("%s",mechVentType);
	str_editVentEff.Format("%.0f",MVHRThermalEff);
	str_editSFP.Format("%.0f",SFP);

	str_comboPressTest.Format("%s",pressureTestYN);
	str_editMeasuredq50.Format("%.0f",measuredQ50);
	str_editNumOfStoreys.Format("%d",numOfStoreys);
	str_comboStructInf.Format("%.2f",structInf);
	str_comboFloorInf.Format("%.1f",floorInf);
	str_comboDraughtLobby.Format("%s",draughtLobby);
	str_comboPerDraughtStripped.Format("%d",perWindowDraughtStripped);
	str_comboNumShelteredSides.Format("%d",numOfShelteredSides);
		
	str_editNumsOpenFirePlaces.Format("%d",numsOpenFirePlaces);
	str_editNumsOpenFlues.Format("%d",numsOpenFlues);
	str_editNumsFluelessGasFires.Format("%d",numsFluelessGasFires);

	str_editNumsExtractFans.Format("%d",numsExtractFans);
	str_editNumsPassiveVents.Format("%d",numsPassiveVents);

	str_comboACPresent.Format("%s",isACPresent);
	str_editACenergyUse.Format("%.1f",ACEnergyUse);

	UpdateData(FALSE);
}

void CDlg_Ventilation::ReadInputsFromVentilationDlg()
{
	UpdateData(TRUE);

	designAirPermeability     = str_comboDesignAirPerm;
	pressureTestScotland      = str_comboPressureTestScot;
	accreditedDetailsScotland = str_comboAccreditedDetailsScot;
	seekExemptionForLT3Dwellings = str_comboseekExemption;

	designAirPermRate  = atof(str_editDesignAirPermRate);
	asBuiltAirPermRate = atof(str_editAsBuiltAirPermRate);

	airPermMeasuredInDwelling = str_comboIsAirPermMeasured;
	asBuiltRef      = str_editAsBuiltRef;
	asBuiltTestDate = str_comboAsBuiltTestDate;
	
	pressureTestYN = str_comboPressTest;
	measuredQ50    = atof(str_editMeasuredq50);
	numOfStoreys   = atoi(str_editNumOfStoreys);
	structInf      = atof(str_comboStructInf);
	floorInf       = atof(str_comboFloorInf);
	draughtLobby   = str_comboDraughtLobby;
	perWindowDraughtStripped = atoi(str_comboPerDraughtStripped);
	numOfShelteredSides = atoi(str_comboNumShelteredSides);

	mechVentType       = str_comboMechVentType;

	//-----------------------------------------------------
	// DISPLAY EFFICIENCY BOX ONLY IF...
	//-----------------------------------------------------
	if(strcmp(mechVentType,"Balanced (with heat recovery)")==0)
	{
		m_labelMechVentEff.ShowWindow(TRUE);
		m_editVentEff.ShowWindow(TRUE);
		m_labelPer.ShowWindow(TRUE);
	}
	else
	{
		m_labelMechVentEff.ShowWindow(FALSE);
		m_editVentEff.ShowWindow(FALSE);
		m_labelPer.ShowWindow(FALSE);
	}

	MVHRThermalEff = atof(str_editVentEff);
	SFP = atof(str_editSFP);

	//-----------------------------------------------------
	// DISPLAY SFP BOX ONLY IF...
	//-----------------------------------------------------
	if((strcmp(mechVentType,"Balanced (with heat recovery)")==0)
		|| (strcmp(mechVentType,"Balanced (without heat recovery)")==0)
		|| (strcmp(mechVentType,"Positive input from outside")==0)
		|| (strcmp(mechVentType,"Positive input from loft")==0)
		|| (strcmp(mechVentType,"Mechanical extract vent")==0))
	{
		m_labelSFP.ShowWindow(TRUE);
		m_editSFP.ShowWindow(TRUE);
		m_labelSFPunit.ShowWindow(TRUE);
		m_labelSFPinfo.ShowWindow(TRUE);
		chkMVHR = 1;//0; //edit by min 20140228

	}
	else
	{
		m_labelSFP.ShowWindow(FALSE);
		m_editSFP.ShowWindow(FALSE);
		m_labelSFPunit.ShowWindow(FALSE);
		m_labelSFPinfo.ShowWindow(FALSE);
		chkMVHR = 0; 
		

	}

	SFP = atof(str_editSFP);
	numsOpenFirePlaces   = atoi(str_editNumsOpenFirePlaces);
	numsOpenFlues        = atoi(str_editNumsOpenFlues);
	numsFluelessGasFires = atoi(str_editNumsFluelessGasFires);

	numsExtractFans  = atoi(str_editNumsExtractFans);
	numsPassiveVents = atoi(str_editNumsPassiveVents);

	isACPresent = str_comboACPresent;
	ACEnergyUse = atof(str_editACenergyUse);
}

void CDlg_Ventilation::OnCbnSelchangeComboPressuretestscotland()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeComboaccrediteddetailsscotland()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeComboSeekexemption()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnEnChangeEditDesairpermeabilityrate()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T(".0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editDesignAirPermRate, lpszValidChars) != 0) 
	{
		str_editDesignAirPermRate = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnEnChangeEditasbuiltairpermrate()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T(".0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editAsBuiltAirPermRate, lpszValidChars) != 0) 
	{
		str_editAsBuiltAirPermRate = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeComboMeasuredinthisdwelling()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnEnChangeEditAsbuiltref()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editAsBuiltRef, lpszValidChars) != 0) 
	{
		str_editAsBuiltRef = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeComboAsbuilttestdate()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeComboDraughtlobby()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeComboMechvent()
{
	ReadInputsFromVentilationDlg();
	//-----------------------------------
	// Establish value for SFP
	//-----------------------------------
	if(strcmp(mechVentType , "Mechanical extract vent")==0)
	{
		SFP   = 0.8;
	}
	else if((strcmp(mechVentType ,"Balanced (with heat recovery)")==0) || (strcmp(mechVentType,"Balanced (without heat recovery)")==0))
	{
		SFP   = 2.0;
	}
	else
	{
		SFP   = 1.0;
	}

	str_editSFP.Format("%.0f",SFP);
	UpdateData(FALSE);
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeComboValuesfrom()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeComboNumofwetrooms()
{
	UpdateData(TRUE);
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeComboDuctinsulation()
{
	UpdateData(TRUE);
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnEnChangeEditOpenfireplaces()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editNumsOpenFirePlaces, lpszValidChars) != 0) 
	{
		str_editNumsOpenFirePlaces = " ";	
		UpdateData(FALSE);
		return;
	}

	ReadInputsFromVentilationDlg();
				
	// Check limit
	isCheckRange_numsOpenFirePlaces   = true;
}

void CDlg_Ventilation::OnEnChangeEditFluelessgasfires()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editNumsOpenFlues, lpszValidChars) != 0) 
	{
		str_editNumsOpenFlues = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
				
	// Check limit
	isCheckRange_numsOpenFlues   = true;
}

void CDlg_Ventilation::OnEnChangeEditOpenflues()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editNumsFluelessGasFires, lpszValidChars) != 0) 
	{
		str_editNumsFluelessGasFires = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
				
	// Check limit
	isCheckRange_numsFluelessGasFires   = true;
}

void CDlg_Ventilation::OnEnChangeEditNumextractfans()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editNumsExtractFans, lpszValidChars) != 0) 
	{
		str_editNumsExtractFans = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
				
	// Check limit
	isCheckRange_numsExtractFans  = true;
}

void CDlg_Ventilation::OnEnChangeEditNumpassivevents()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editNumsPassiveVents, lpszValidChars) != 0) 
	{
		str_editNumsPassiveVents = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
				
	// Check limit
	isCheckRange_numsPassiveVents  = true;
}

void CDlg_Ventilation::OnCbnSelchangeComboAcpresent()
{
	UpdateData(TRUE);
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnEnChangeEditAcenergyuse()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T(".0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editACenergyUse, lpszValidChars) != 0) 
	{
		str_editACenergyUse = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeCombo1()
{
	ReadInputsFromVentilationDlg();

	if(strcmp(pressureTestYN,"Yes")==0)
	{
		m_editMeasuredq50.ShowWindow(TRUE);
		m_editNumOfStoreys.ShowWindow(FALSE);
		m_comboStructInf.ShowWindow(FALSE);
		m_comboFloorInf.ShowWindow(FALSE);
		m_comboDraughtLobby.ShowWindow(FALSE);
		m_comboPerDraughtStripped.ShowWindow(FALSE);

		m_labelMeasuredQ50.ShowWindow(TRUE);
		m_labelNumStoreys.ShowWindow(FALSE);
		m_labelStructInf.ShowWindow(FALSE);
		m_labelDraughtLobby.ShowWindow(FALSE);
		m_labelPerWindows.ShowWindow(FALSE);
		m_labelSuspFloorInf.ShowWindow(FALSE);
	}
	else
	{
		m_editMeasuredq50.ShowWindow(FALSE);
		m_editNumOfStoreys.ShowWindow(TRUE);
		m_comboStructInf.ShowWindow(TRUE);
		m_comboFloorInf.ShowWindow(TRUE);
		m_comboDraughtLobby.ShowWindow(TRUE);
		m_comboPerDraughtStripped.ShowWindow(TRUE);

		m_labelMeasuredQ50.ShowWindow(FALSE);
		m_labelNumStoreys.ShowWindow(TRUE);
		m_labelStructInf.ShowWindow(TRUE);
		m_labelDraughtLobby.ShowWindow(TRUE);
		m_labelPerWindows.ShowWindow(TRUE);
		m_labelSuspFloorInf.ShowWindow(TRUE);
	}
}

void CDlg_Ventilation::OnCbnSelchangeCombo12()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeCombo13()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnCbnSelchangeCombo15()
{
	ReadInputsFromVentilationDlg();
}

void CDlg_Ventilation::OnEnChangeEdit1()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editMeasuredq50, lpszValidChars) != 0) 
	{
		str_editMeasuredq50 = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
				
	// Check limit
	isCheckRange_measuredQ50 = true;
}

void CDlg_Ventilation::OnEnChangeEdit2()
{
	//------------------------------------------------------------------------------
	// Empty edit box if user types any character other than numeric characters or '.'
	UpdateData(TRUE);
	static TCHAR * lpszValidChars = _T("0123456789");
	// szText is the string we want to check for invalid chracters
	if (_tcsspnp(str_editNumOfStoreys, lpszValidChars) != 0) 
	{
		str_editNumOfStoreys = " ";	
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromVentilationDlg();
					
	// Check limit
	isCheckRange_numOfStoreys= true;
}

void CDlg_Ventilation::OnEnChangeEdit4()
{
	is_spf_changed = true;
	ReadInputsFromVentilationDlg();
					
	// Check limit
	isCheckRange_SFP= true;
}

void CDlg_Ventilation::OnEnChangeEdit3()
{
	is_mvhr_eff_changed = true;
	ReadInputsFromVentilationDlg();
}

BOOL CDlg_Ventilation::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(pMsg->message==WM_KEYDOWN)
	{
		if(pMsg->wParam==VK_RETURN || pMsg->wParam==VK_ESCAPE)
			pMsg->wParam=NULL ;
	} 

	if(m_ToolTip != NULL)
       m_ToolTip->RelayEvent(pMsg);

	return CDialog::PreTranslateMessage(pMsg);
}

