// Dlg_Openings.cpp : implementation file
//

#include "stdafx.h"
#include "SAPP1.h"
#include "Dlg_Openings.h"
#include "SAPP1Dlg.h"
#include "Dlg_ListOpenings.h"
#include "Dlg_AddOpenings.h"


using namespace std;

// CDlg_Openings dialog

IMPLEMENT_DYNAMIC(CDlg_Openings, CDialog)
CDlg_Openings::CDlg_Openings(CWnd* pParent /*=NULL*/)
	: CDialog(CDlg_Openings::IDD, pParent)
	, str_comboFromSource(_T(""))
	, str_editDescription(_T(""))
	, str_comboGlazingType(_T(""))
	, str_comboLowECoating(_T(""))
	, str_comboUserDefEmissivity(_T(""))
	, str_editEmissivity(_T(""))
	, str_comboArgonFilled(_T(""))
	, str_comboGap(_T(""))
	, str_editPitch(_T(""))
	, str_comboOrientation(_T(""))
	, str_comboOvershading(_T(""))
	, str_editWidth(_T(""))
	, str_editHeight(_T(""))
	, str_comboLocationName(_T(""))
	, str_editOverhangDepth(_T(""))
	, str_editOverhangWidth(_T(""))
	, str_comboMaster(_T(""))
	, str_comboLinkedTo(_T(""))
	, str_comboFrame(_T(""))
	, str_comboThermalBreak(_T(""))
	, str_comboDraughtProofing(_T(""))
	, str_comboMetalLintel(_T(""))
	, str_comboTransmittanceFactor(_T(""))
	, str_editTransmittance(_T(""))
	, str_comboFrameFactor(_T(""))
	, str_editFractionGlazed(_T(""))
	, str_comboUValue(_T(""))
	, str_editUValue(_T(""))
	, str_editRef(_T(""))
	, str_editOpeningName(_T(""))
	, str_comboOPeningWallRoof(_T(""))
{
}

CDlg_Openings::~CDlg_Openings()
{
}

void CDlg_Openings::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//DDX_Control(pDX, IDC_STATIC_1, m_labelDescription);
	DDX_Control(pDX, IDC_STATIC_2, m_labelGlazing);
	DDX_Control(pDX, IDC_STATIC_3, m_labelSizeLocation);
	DDX_Control(pDX, IDC_STATIC_5, m_labelLinkage);
	DDX_Control(pDX, IDC_STATIC_6, m_labelFrame);
	DDX_Control(pDX, IDC_STATIC_4, m_labelTransmittance);
	DDX_Control(pDX, IDC_STATIC_7, m_labelFrameFactor);
	DDX_Control(pDX, IDC_STATIC_8, m_labelUvalue);
	DDX_Control(pDX, IDC_COMBO_Source, m_comboFromSource);
	DDX_Control(pDX, IDC_EDIT1, m_editDescription);
	DDX_Control(pDX, IDC_COMBO_GlazingType, m_comboGlazingType);
	DDX_Control(pDX, IDC_COMBO_LowE, m_comboLowECoating);
	DDX_Control(pDX, IDC_COMBO_userDefEm, m_comboUserDefEmissivity);
	DDX_Control(pDX, IDC_EDIT2, m_editEmissivity);
	DDX_Control(pDX, IDC_COMBO_ArgonFilled, m_comboArgonFilled);
	DDX_Control(pDX, IDC_COMBO_Gap, m_comboGap);
	DDX_Control(pDX, IDC_EDIT3, m_editPitch);
	DDX_Control(pDX, IDC_COMBO_Orientation, m_comboOrientation);
	DDX_Control(pDX, IDC_COMBO_Overshading, m_comboOvershading);
	DDX_Control(pDX, IDC_EDIT4, m_editWidth);
	DDX_Control(pDX, IDC_EDIT5, m_editHeight);
	DDX_Control(pDX, IDC_COMBO_LocationName, m_comboLocationName);
	DDX_Control(pDX, IDC_EDIT7, m_editOverhangDepth);
	DDX_Control(pDX, IDC_EDIT6, m_editOverhangWidth);
	DDX_Control(pDX, IDC_COMBO_Master, m_comboMaster);
	DDX_Control(pDX, IDC_COMBO_LinkedTo, m_comboLinkedTo);
	DDX_Control(pDX, IDC_COMBO_Frame, m_comboFrame);
	DDX_Control(pDX, IDC_COMBO_ThermalBreak, m_comboThermalBreak);
	DDX_Control(pDX, IDC_COMBO_DraughtProofing, m_comboDraughtProofing);
	DDX_Control(pDX, IDC_COMBO_MetalLintel, m_comboMetalLintel);
	DDX_Control(pDX, IDC_COMBO_TransFactor, m_comboTransmittanceFactor);
	DDX_Control(pDX, IDC_COMBO_FrameFactor, m_comboFrameFactor);
	DDX_Control(pDX, IDC_COMBO_uValue, m_comboUValue);
	DDX_Control(pDX, IDC_EDIT8, m_editTransmittance);
	DDX_Control(pDX, IDC_EDIT9, m_editFractionGlazed);
	DDX_Control(pDX, IDC_EDIT10, m_editUValue);
	DDX_CBString(pDX, IDC_COMBO_Source, str_comboFromSource);
	DDX_Text(pDX, IDC_EDIT1, str_editDescription);
	DDX_CBString(pDX, IDC_COMBO_GlazingType, str_comboGlazingType);
	DDX_CBString(pDX, IDC_COMBO_LowE, str_comboLowECoating);
	DDX_CBString(pDX, IDC_COMBO_userDefEm, str_comboUserDefEmissivity);
	DDX_Text(pDX, IDC_EDIT2, str_editEmissivity);
	DDX_CBString(pDX, IDC_COMBO_ArgonFilled, str_comboArgonFilled);
	DDX_CBString(pDX, IDC_COMBO_Gap, str_comboGap);
	DDX_Text(pDX, IDC_EDIT3, str_editPitch);
	DDX_CBString(pDX, IDC_COMBO_Orientation, str_comboOrientation);
	DDX_CBString(pDX, IDC_COMBO_Overshading, str_comboOvershading);
	DDX_Text(pDX, IDC_EDIT4, str_editWidth);
	DDX_Text(pDX, IDC_EDIT5, str_editHeight);
	DDX_CBString(pDX, IDC_COMBO_LocationName, str_comboLocationName);
	DDX_Text(pDX, IDC_EDIT7, str_editOverhangDepth);
	DDX_Text(pDX, IDC_EDIT6, str_editOverhangWidth);
	DDX_CBString(pDX, IDC_COMBO_Master, str_comboMaster);
	DDX_CBString(pDX, IDC_COMBO_LinkedTo, str_comboLinkedTo);
	DDX_CBString(pDX, IDC_COMBO_Frame, str_comboFrame);
	DDX_CBString(pDX, IDC_COMBO_ThermalBreak, str_comboThermalBreak);
	DDX_CBString(pDX, IDC_COMBO_DraughtProofing, str_comboDraughtProofing);
	DDX_CBString(pDX, IDC_COMBO_MetalLintel, str_comboMetalLintel);
	DDX_CBString(pDX, IDC_COMBO_TransFactor, str_comboTransmittanceFactor);
	DDX_Text(pDX, IDC_EDIT8, str_editTransmittance);
	DDX_CBString(pDX, IDC_COMBO_FrameFactor, str_comboFrameFactor);
	DDX_Text(pDX, IDC_EDIT9, str_editFractionGlazed);
	DDX_CBString(pDX, IDC_COMBO_uValue, str_comboUValue);
	DDX_Text(pDX, IDC_EDIT10, str_editUValue);
	DDX_Control(pDX, IDC_EDIT11, m_editRef);
	DDX_Text(pDX, IDC_EDIT11, str_editRef);
	DDX_Control(pDX, IDC_EDIT12, m_editOpeningName);
	DDX_Text(pDX, IDC_EDIT12, str_editOpeningName);
	DDX_Control(pDX, IDC_COMBO1, m_comboOPeningWallRoof);
	DDX_CBString(pDX, IDC_COMBO1, str_comboOPeningWallRoof);
}


BEGIN_MESSAGE_MAP(CDlg_Openings, CDialog)
	ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButtonAdd)
	ON_BN_CLICKED(IDC_BUTTON2, OnBnClickedButtonView)
	ON_CBN_SELCHANGE(IDC_COMBO_Source, OnCbnSelchangeComboSource)
	ON_EN_CHANGE(IDC_EDIT1, OnEnChangeEdit1)
	ON_CBN_SELCHANGE(IDC_COMBO_GlazingType, OnCbnSelchangeComboGlazingtype)
	ON_CBN_SELCHANGE(IDC_COMBO_LowE, OnCbnSelchangeComboLowe)
	ON_CBN_SELCHANGE(IDC_COMBO_userDefEm, OnCbnSelchangeCombouserdefem)
	ON_EN_CHANGE(IDC_EDIT2, OnEnChangeEdit2)
	ON_CBN_SELCHANGE(IDC_COMBO_ArgonFilled, OnCbnSelchangeComboArgonfilled)
	ON_CBN_SELCHANGE(IDC_COMBO_Gap, OnCbnSelchangeComboGap)
	ON_EN_CHANGE(IDC_EDIT3, OnEnChangeEdit3)
	ON_CBN_SELCHANGE(IDC_COMBO_Orientation, OnCbnSelchangeComboOrientation)
	ON_CBN_SELCHANGE(IDC_COMBO_Overshading, OnCbnSelchangeComboOvershading)
	ON_EN_CHANGE(IDC_EDIT4, OnEnChangeEdit4)
	ON_EN_CHANGE(IDC_EDIT5, OnEnChangeEdit5)
	ON_CBN_SELCHANGE(IDC_COMBO_LocationName, OnCbnSelchangeComboLocationname)
	ON_EN_CHANGE(IDC_EDIT7, OnEnChangeEdit7)
	ON_EN_CHANGE(IDC_EDIT6, OnEnChangeEdit6)
	ON_CBN_SELCHANGE(IDC_COMBO_Master, OnCbnSelchangeComboMaster)
	ON_CBN_SELCHANGE(IDC_COMBO_LinkedTo, OnCbnSelchangeComboLinkedto)
	ON_CBN_SELCHANGE(IDC_COMBO_Frame, OnCbnSelchangeComboFrame)
	ON_CBN_SELCHANGE(IDC_COMBO_ThermalBreak, OnCbnSelchangeComboThermalbreak)
	ON_CBN_SELCHANGE(IDC_COMBO_DraughtProofing, OnCbnSelchangeComboDraughtproofing)
	ON_CBN_SELCHANGE(IDC_COMBO_MetalLintel, OnCbnSelchangeComboMetallintel)
	ON_CBN_SELCHANGE(IDC_COMBO_TransFactor, OnCbnSelchangeComboTransfactor)
	ON_EN_CHANGE(IDC_EDIT8, OnEnChangeEdit8)
	ON_CBN_SELCHANGE(IDC_COMBO_FrameFactor, OnCbnSelchangeComboFramefactor)
	ON_EN_CHANGE(IDC_EDIT9, OnEnChangeEdit9)
	ON_CBN_SELCHANGE(IDC_COMBO_uValue, OnCbnSelchangeCombouvalue)
	ON_EN_CHANGE(IDC_EDIT10, OnEnChangeEdit10)
	ON_EN_CHANGE(IDC_EDIT11, OnEnChangeEdit11)
	ON_EN_CHANGE(IDC_EDIT12, OnEnChangeEdit12)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnCbnSelchangeCombo1)
END_MESSAGE_MAP()

using namespace std;

//---------------------------------------------------
// GLOBAL VARIABLES
//---------------------------------------------------
// REMOVED vector <openingsList> openingsList1;

CString openingFromSource;
CString openingDescription;
CString openingGlzType;
CString openingLowECoating;
CString openingUsedDefEmissivity;
double openingEmissivty;

CString openingArgonFilled;
CString openingGap;
double openingPitch; // ???unknown
CString openingOrientation;
CString openingOvershading;

double openingWidth;
double openingHeight;
CString openingLocationName;
double openingOverhangDepth;
double openingOverhangWidth;

CString openingRef;
CString openingLinkageMaster;
CString openingLinkedTo;

CString openingFrame;
CString openingThermalBreak;
CString openingDraughtProofing;
CString openingMetalLintel;

CString openingTransmittanceSelected;
double openingTransmittanceFactor;

CString openingFrameSelected;
double openingFrameFactor;

CString openingUvalueSelected;
double openingUvalue;
CString openingRoofWall;


CString opening1FromSource;
CString opening2FromSource;
CString opening3FromSource;
CString opening4FromSource;
CString opening5FromSource;
CString opening6FromSource;
CString opening7FromSource;
CString opening8FromSource;
CString opening9FromSource;
CString opening10FromSource;

CString opening1Description;
CString opening2Description;
CString opening3Description;
CString opening4Description;
CString opening5Description;
CString opening6Description;
CString opening7Description;
CString opening8Description;
CString opening9Description;
CString opening10Description;

CString opening1GlzType;
CString opening2GlzType;
CString opening3GlzType;
CString opening4GlzType;
CString opening5GlzType;
CString opening6GlzType;
CString opening7GlzType;
CString opening8GlzType;
CString opening9GlzType;
CString opening10GlzType;


CString opening1LowECoating;
CString opening2LowECoating;
CString opening3LowECoating;
CString opening4LowECoating;
CString opening5LowECoating;
CString opening6LowECoating;
CString opening7LowECoating;
CString opening8LowECoating;
CString opening9LowECoating;
CString opening10LowECoating;

CString opening1UsedDefEmissivity;
CString opening2UsedDefEmissivity;
CString opening3UsedDefEmissivity;
CString opening4UsedDefEmissivity;
CString opening5UsedDefEmissivity;
CString opening6UsedDefEmissivity;
CString opening7UsedDefEmissivity;
CString opening8UsedDefEmissivity;
CString opening9UsedDefEmissivity;
CString opening10UsedDefEmissivity;

double opening1Emissivty;
double opening2Emissivty;
double opening3Emissivty;
double opening4Emissivty;
double opening5Emissivty;
double opening6Emissivty;
double opening7Emissivty;
double opening8Emissivty;
double opening9Emissivty;
double opening10Emissivty;

CString opening1ArgonFilled;
CString opening2ArgonFilled;
CString opening3ArgonFilled;
CString opening4ArgonFilled;
CString opening5ArgonFilled;
CString opening6ArgonFilled;
CString opening7ArgonFilled;
CString opening8ArgonFilled;
CString opening9ArgonFilled;
CString opening10ArgonFilled;

CString opening1Gap;
CString opening2Gap;
CString opening3Gap;
CString opening4Gap;
CString opening5Gap;
CString opening6Gap;
CString opening7Gap;
CString opening8Gap;
CString opening9Gap;
CString opening10Gap;


double opening1Pitch; // ???unknown
double opening2Pitch; // ???unknown
double opening3Pitch; // ???unknown
double opening4Pitch; // ???unknown
double opening5Pitch; // ???unknown
double opening6Pitch; // ???unknown
double opening7Pitch; // ???unknown
double opening8Pitch; // ???unknown
double opening9Pitch; // ???unknown
double opening10Pitch; // ???unknown

CString opening1Orientation;
CString opening2Orientation;
CString opening3Orientation;
CString opening4Orientation;
CString opening5Orientation;
CString opening6Orientation;
CString opening7Orientation;
CString opening8Orientation;
CString opening9Orientation;
CString opening10Orientation;

CString opening1Overshading;
CString opening2Overshading;
CString opening3Overshading;
CString opening4Overshading;
CString opening5Overshading;
CString opening6Overshading;
CString opening7Overshading;
CString opening8Overshading;
CString opening9Overshading;
CString opening10Overshading;

double opening1Width;
double opening2Width;
double opening3Width;
double opening4Width;
double opening5Width;
double opening6Width;
double opening7Width;
double opening8Width;
double opening9Width;
double opening10Width;

double opening1Height;
double opening2Height;
double opening3Height;
double opening4Height;
double opening5Height;
double opening6Height;
double opening7Height;
double opening8Height;
double opening9Height;
double opening10Height;

CString opening1LocationName;
CString opening2LocationName;
CString opening3LocationName;
CString opening4LocationName;
CString opening5LocationName;
CString opening6LocationName;
CString opening7LocationName;
CString opening8LocationName;
CString opening9LocationName;
CString opening10LocationName;

double opening1OverhangDepth;
double opening2OverhangDepth;
double opening3OverhangDepth;
double opening4OverhangDepth;
double opening5OverhangDepth;
double opening6OverhangDepth;
double opening7OverhangDepth;
double opening8OverhangDepth;
double opening9OverhangDepth;
double opening10OverhangDepth;

double opening1OverhangWidth;
double opening2OverhangWidth;
double opening3OverhangWidth;
double opening4OverhangWidth;
double opening5OverhangWidth;
double opening6OverhangWidth;
double opening7OverhangWidth;
double opening8OverhangWidth;
double opening9OverhangWidth;
double opening10OverhangWidth;

CString opening1Ref;
CString opening2Ref;
CString opening3Ref;
CString opening4Ref;
CString opening5Ref;
CString opening6Ref;
CString opening7Ref;
CString opening8Ref;
CString opening9Ref;
CString opening10Ref;

CString opening1LinkageMaster;
CString opening2LinkageMaster;
CString opening3LinkageMaster;
CString opening4LinkageMaster;
CString opening5LinkageMaster;
CString opening6LinkageMaster;
CString opening7LinkageMaster;
CString opening8LinkageMaster;
CString opening9LinkageMaster;
CString opening10LinkageMaster;

CString opening1LinkedTo;
CString opening2LinkedTo;
CString opening3LinkedTo;
CString opening4LinkedTo;
CString opening5LinkedTo;
CString opening6LinkedTo;
CString opening7LinkedTo;
CString opening8LinkedTo;
CString opening9LinkedTo;
CString opening10LinkedTo;

CString opening1Frame;
CString opening2Frame;
CString opening3Frame;
CString opening4Frame;
CString opening5Frame;
CString opening6Frame;
CString opening7Frame;
CString opening8Frame;
CString opening9Frame;
CString opening10Frame;

CString opening1ThermalBreak;
CString opening2ThermalBreak;
CString opening3ThermalBreak;
CString opening4ThermalBreak;
CString opening5ThermalBreak;
CString opening6ThermalBreak;
CString opening7ThermalBreak;
CString opening8ThermalBreak;
CString opening9ThermalBreak;
CString opening10ThermalBreak;


CString opening1DraughtProofing;
CString opening2DraughtProofing;
CString opening3DraughtProofing;
CString opening4DraughtProofing;
CString opening5DraughtProofing;
CString opening6DraughtProofing;
CString opening7DraughtProofing;
CString opening8DraughtProofing;
CString opening9DraughtProofing;
CString opening10DraughtProofing;

CString opening1MetalLintel;
CString opening2MetalLintel;
CString opening3MetalLintel;
CString opening4MetalLintel;
CString opening5MetalLintel;
CString opening6MetalLintel;
CString opening7MetalLintel;
CString opening8MetalLintel;
CString opening9MetalLintel;
CString opening10MetalLintel;

CString opening1TransmittanceSelected;
CString opening2TransmittanceSelected;
CString opening3TransmittanceSelected;
CString opening4TransmittanceSelected;
CString opening5TransmittanceSelected;
CString opening6TransmittanceSelected;
CString opening7TransmittanceSelected;
CString opening8TransmittanceSelected;
CString opening9TransmittanceSelected;
CString opening10TransmittanceSelected;

double opening1TransmittanceFactor;
double opening2TransmittanceFactor;
double opening3TransmittanceFactor;
double opening4TransmittanceFactor;
double opening5TransmittanceFactor;
double opening6TransmittanceFactor;
double opening7TransmittanceFactor;
double opening8TransmittanceFactor;
double opening9TransmittanceFactor;
double opening10TransmittanceFactor;

CString opening1FrameSelected;
CString opening2FrameSelected;
CString opening3FrameSelected;
CString opening4FrameSelected;
CString opening5FrameSelected;
CString opening6FrameSelected;
CString opening7FrameSelected;
CString opening8FrameSelected;
CString opening9FrameSelected;
CString opening10FrameSelected;

double opening1FrameFactor;
double opening2FrameFactor;
double opening3FrameFactor;
double opening4FrameFactor;
double opening5FrameFactor;
double opening6FrameFactor;
double opening7FrameFactor;
double opening8FrameFactor;
double opening9FrameFactor;
double opening10FrameFactor;

CString opening1UvalueSelected;
CString opening2UvalueSelected;
CString opening3UvalueSelected;
CString opening4UvalueSelected;
CString opening5UvalueSelected;
CString opening6UvalueSelected;
CString opening7UvalueSelected;
CString opening8UvalueSelected;
CString opening9UvalueSelected;
CString opening10UvalueSelected;

double opening1Uvalue;
double opening2Uvalue;
double opening3Uvalue;
double opening4Uvalue;
double opening5Uvalue;
double opening6Uvalue;
double opening7Uvalue;
double opening8Uvalue;
double opening9Uvalue;
double opening10Uvalue;

bool is_opening1_added = false;
bool is_opening2_added = false;
bool is_opening3_added = false;
bool is_opening4_added = false;
bool is_opening5_added = false;
bool is_opening6_added = false;
bool is_opening7_added = false;
bool is_opening8_added = false;
bool is_opening9_added = false;
bool is_opening10_added = false;



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

	//---------------------------------------------------
	// LABELS
	//---------------------------------------------------
	m_labelGlazing.SetFont(m_Font1); 
	m_labelGlazing.SetTextColor(BLUE);

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

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

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

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

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

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

	AddStringsForOpeningsDlg();
	ReadPreviousInputsFromOpeningsDlg();

	return TRUE;
}

void CDlg_Openings::AddStringsForOpeningsDlg()
{
	m_comboFromSource.InsertString(0,"Table 6x (SAP 2005)");
	m_comboFromSource.InsertString(1,"BFRC (www.bfrc.org)");
	m_comboFromSource.InsertString(2,"From manufacturer");

	m_comboOPeningWallRoof.InsertString(0,"Wall");
	m_comboOPeningWallRoof.InsertString(1,"Roof");

	m_comboGlazingType.InsertString(0,"Single");
	m_comboGlazingType.InsertString(1,"Double");
	m_comboGlazingType.InsertString(2,"Double Low E");
	m_comboGlazingType.InsertString(3,"Triple");
	m_comboGlazingType.InsertString(4,"Triple Low E");

	m_comboLowECoating.InsertString(0,"Hard");
	m_comboLowECoating.InsertString(1,"Soft");

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

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

	m_comboGap.InsertString(0,"6mm");
	m_comboGap.InsertString(1,"12mm");
	m_comboGap.InsertString(2,"16mm or more");

	m_comboOrientation.InsertString(0,"North");
	m_comboOrientation.InsertString(1,"North East");
	m_comboOrientation.InsertString(2,"East");
	m_comboOrientation.InsertString(3,"South East");
	m_comboOrientation.InsertString(4,"South");
	m_comboOrientation.InsertString(5,"South West");
	m_comboOrientation.InsertString(6,"West");
	m_comboOrientation.InsertString(7,"North West");

	m_comboOvershading.InsertString(0,"None / Very little");
	m_comboOvershading.InsertString(1,"Average");
	m_comboOvershading.InsertString(2,"More than average");
	m_comboOvershading.InsertString(3,"Heavy");

	// LOCATION ????

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

	m_comboLinkedTo.InsertString(0,"None");

	m_comboFrame.InsertString(0,"Wood");
	m_comboFrame.InsertString(1,"Metal");
	m_comboFrame.InsertString(2,"u-PVC");
	m_comboFrame.InsertString(3,"Metal - thermal break");

	// if wood, u-PVC or sash no thermal break
	// if Metal
	m_comboThermalBreak.InsertString(0,"None");
	m_comboThermalBreak.InsertString(1,"4mm");
	m_comboThermalBreak.InsertString(2,"8mm");
	m_comboThermalBreak.InsertString(3,"12mm");
	m_comboThermalBreak.InsertString(4,"20mm");
	m_comboThermalBreak.InsertString(5,"32mm");

	m_comboDraughtProofing.InsertString(0,"Unopenable");
	m_comboDraughtProofing.InsertString(1,"Good seal");
	m_comboDraughtProofing.InsertString(2,"Loose seal");
	m_comboDraughtProofing.InsertString(3,"Tight not sealed");
	m_comboDraughtProofing.InsertString(4,"Loose");
	m_comboDraughtProofing.InsertString(5,"Very loose");

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

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

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

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

	m_comboLocationName.InsertString(0,"not available");
}


void CDlg_Openings::ReadPreviousInputsFromOpeningsDlg()
{
	str_comboFromSource.Format("%s",  openingFromSource);
	str_editDescription.Format("%s",  openingDescription);
	str_comboGlazingType.Format("%s", openingGlzType);
	str_comboLowECoating.Format("%s", openingLowECoating);
	str_comboUserDefEmissivity.Format("%s",  openingUsedDefEmissivity);
	str_editEmissivity.Format("%.1f",  openingEmissivty);

	str_comboArgonFilled.Format("%s",  openingArgonFilled);
	str_comboGap.Format("%s",  openingGap);
	str_editPitch.Format("%.1f",  openingPitch); // ???unknown
	str_comboOrientation.Format("%s",  openingOrientation);
	str_comboOvershading.Format("%s",  openingOvershading);

	str_editWidth.Format("%.1f",  openingWidth);
	str_editHeight.Format("%.1f",  openingHeight);
	str_comboLocationName.Format("%s",  openingLocationName);
	str_editOverhangDepth.Format("%.1f",  openingOverhangDepth);
	str_editOverhangWidth.Format("%.1f",  openingOverhangWidth);

	//CString openingRef //???
	str_editRef.Format("%s",openingRef);
	str_comboMaster.Format("%s",  openingLinkageMaster);
	str_comboLinkedTo.Format("%s",  openingLinkedTo);

	str_comboFrame.Format("%s",  openingFrame);
	str_comboThermalBreak.Format("%s",  openingThermalBreak);
	str_comboDraughtProofing.Format("%s",  openingDraughtProofing);
	str_comboMetalLintel.Format("%s",  openingMetalLintel);

	str_comboTransmittanceFactor.Format("%s",  openingTransmittanceSelected);
	str_editTransmittance.Format("%.1f",  openingTransmittanceFactor);

	str_comboFrameFactor.Format("%s",  openingFrameSelected);
	str_editFractionGlazed.Format("%.1f",  openingFrameFactor);

	str_comboUValue.Format("%s",  openingUvalueSelected);
	str_editUValue.Format("%.1f",  openingUvalue);

	UpdateData(FALSE);
}

void CDlg_Openings::ReadInputsFromOpeningsDlg()
{
	double adjFactorThermBreak = 0.0;
	double adjFactorWoodPVC = 0.0;

	UpdateData(TRUE);
    
	openingRoofWall = str_comboOPeningWallRoof;
	openingFromSource = str_comboFromSource;
	openingDescription = str_editDescription;
	openingGlzType = str_comboGlazingType;
	openingLowECoating = str_comboLowECoating;
	openingUsedDefEmissivity = str_comboUserDefEmissivity;
	openingEmissivty = atof(str_editEmissivity);

	openingArgonFilled = str_comboArgonFilled;
	openingGap = str_comboGap;
	openingPitch = atof(str_editPitch); // ???unknown
	openingOrientation = str_comboOrientation;
	openingOvershading = str_comboOvershading;

	openingWidth = atof(str_editWidth);
	openingHeight = atof(str_editHeight);
	openingLocationName = str_comboLocationName;
	openingOverhangDepth = atof(str_editOverhangDepth);
	openingOverhangWidth = atof(str_editOverhangWidth);

	//CString openingRef //???
	openingRef = str_editRef;
	openingLinkageMaster = str_comboMaster;
	openingLinkedTo = str_comboLinkedTo;

	openingFrame = str_comboFrame;
	openingThermalBreak = str_comboThermalBreak;
	openingDraughtProofing = str_comboDraughtProofing;
	openingMetalLintel = str_comboMetalLintel;

	openingTransmittanceSelected = str_comboTransmittanceFactor;
	openingTransmittanceFactor = atof(str_editTransmittance);

	openingFrameSelected = str_comboFrameFactor;
	openingFrameFactor = atof(str_editFractionGlazed);

	openingUvalueSelected  = str_comboUValue;
	openingUvalue = atof(str_editUValue);

	newOpeningName = str_editOpeningName;

	//-----------------------------------------
	// TRANSMITTANCE FACTOR
	//-----------------------------------------
	if(str_comboTransmittanceFactor == "No")
	{
		// Set edit box to read only
		m_editTransmittance.SetReadOnly(TRUE);

		// Check for glazing type and low-e option and display default value
		if(str_comboGlazingType == "Single")
		{
			openingTransmittanceFactor = 0.85;			
		}
		else if(str_comboGlazingType == "Double")
		{
			openingTransmittanceFactor = 0.76;
		}
		else if((str_comboGlazingType == "Double Low E") && (str_comboLowECoating == "Hard"))
		{
			openingTransmittanceFactor = 0.72;
		}
		else if((str_comboGlazingType == "Double Low E") && (str_comboLowECoating == "Soft"))
		{
			openingTransmittanceFactor = 0.63;
		}
		else if(str_comboGlazingType == "Triple")
		{
			openingTransmittanceFactor = 0.68;
		}
		else if((str_comboGlazingType == "Triple Low E") && (str_comboLowECoating == "Hard"))
		{
			openingTransmittanceFactor = 0.64;
		}
		else if((str_comboGlazingType == "Triple Low E") && (str_comboLowECoating == "Soft"))
		{
			openingTransmittanceFactor = 0.57;
		}
		
		str_editTransmittance.Format("%.2f",openingTransmittanceFactor);
	}
	else
	{
		m_editTransmittance.SetReadOnly(FALSE);
	}

	//-----------------------------------------
	// FRAME FACTOR
	//-----------------------------------------
	if(str_comboFrameFactor == "No")
	{
		// Set edit box to read only
		m_editFractionGlazed.SetReadOnly(TRUE);

		if(str_comboFrame == "Wood")
		{
			openingFrameFactor = 0.7;			
		}
		else if(str_comboFrame == "Metal")
		{
			openingFrameFactor = 0.8;
		}
		else if(str_comboFrame == "u-PVC")
		{
			openingFrameFactor = 0.7;
		}
		else if(str_comboFrame == "Metal - thermal break")
		{
			openingFrameFactor = 0.8;
		}
		str_editFractionGlazed.Format("%.1f",openingFrameFactor);
	}
	else
	{
		// Set edit box to read only
		m_editFractionGlazed.SetReadOnly(FALSE);
	}

	
	//--------------------------------------------------
	// U-VALUE 
	//--------------------------------------------------
	// Note: all u-values taken form SAP 2009 Table 6
	if(str_comboUValue == "No")
	{
		// Set edit box to read only
		m_editUValue.SetReadOnly(TRUE);

		//-----------------------------------------------------------------------------------
		// Check type if opening selected for wall or roof to apply adjustments to u-value
		//-----------------------------------------------------------------------------------
		if((openingRoofWall== "Roof") && (openingGlzType ==  "Single"))
		{
			adjFactorWoodPVC = 0.5;
		}
		else if((openingRoofWall== "Roof") && ((openingGlzType ==  "Double") || (openingGlzType ==  "Double Low E")))
		{
			adjFactorWoodPVC = 0.3;
		}
		else if((openingRoofWall== "Roof") && ((openingGlzType ==  "Triple") || (openingGlzType ==  "Triple Low E")))
		{
			adjFactorWoodPVC = 0.2;
		}

		if(openingRoofWall== "Wall")
		{
			adjFactorWoodPVC = 0.0;
		}

		//---------------------
        // WOOD or u-PVC
		//---------------------
		// 1. With 6mm gap
		if(((str_comboFrame == "Wood") || (str_comboFrame == "u-PVC")) && (openingGap == "6mm"))
		{

			//----------------------------------------------------
			// Single glazed
			//----------------------------------------------------
			if(openingGlzType ==  "Single") 
			{
				openingUvalue = 4.8 + adjFactorWoodPVC;			
			}

			//----------------------------------------------------
			// Double glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.6 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.6 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.7 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.7 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "No")) //|| ((openingEmissivty>0.2)&& (openingEmissivty<=1)) )
			{
				openingUvalue = 3.1 + adjFactorWoodPVC;	
			}
			else if( (openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E")) 
			{
				openingUvalue = 3.1 + adjFactorWoodPVC;	
			}
			//----------------------------------------------------
			// Double glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.3 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.3 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.4 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.5 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "Yes")) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.9 + adjFactorWoodPVC;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E"))
			{
				openingUvalue = 2.9 + adjFactorWoodPVC;	
			}

			//----------------------------------------------------
			// triple glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.9 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.0 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.1 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.1 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "No") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.4 + adjFactorWoodPVC;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E"))
			{
				openingUvalue = 2.4 + adjFactorWoodPVC;	
			}
			//----------------------------------------------------
			// triple glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.7 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.8 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 1.8 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 1.9 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "Yes") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.2 + adjFactorWoodPVC;	
			}	
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E"))
			{
				openingUvalue = 2.2 + adjFactorWoodPVC;	
			}
		}

		//---------------------
		// 2. With 12mm gap
		if(((str_comboFrame == "Wood") || (str_comboFrame == "u-PVC")) && (openingGap == "12mm"))
		{
			//----------------------------------------------------
			// Single glazed
			//----------------------------------------------------
			if(openingGlzType ==  "Single") 
			{
				openingUvalue = 4.8 + adjFactorWoodPVC;				
			}

			//----------------------------------------------------
			// Double glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.0 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.1 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.2 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.3 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "No") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.8 + adjFactorWoodPVC;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 2.8 + adjFactorWoodPVC;	
			}
			//----------------------------------------------------
			// Double glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.8 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.9 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.0 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.1 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "Yes") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.7 + adjFactorWoodPVC;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 2.7 + adjFactorWoodPVC;	
			}

			//----------------------------------------------------
			// triple glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.5 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.6 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 1.7 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 1.7 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "No")  ) //&& ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.1 + adjFactorWoodPVC;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 2.1 + adjFactorWoodPVC;	
			}

			//----------------------------------------------------
			// triple glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.4 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.5 + adjFactorWoodPVC;	
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 1.5 + adjFactorWoodPVC;	
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 1.6 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "Yes") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.0 + adjFactorWoodPVC;	
			}	
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 2.0 + adjFactorWoodPVC;	
			}
		}

		//---------------------
		// 3. With 16mm or more gap
		if(((str_comboFrame == "Wood") || (str_comboFrame == "u-PVC")) && (openingGap == "16mm or more"))
		{
			//----------------------------------------------------
			// Single glazed
			//----------------------------------------------------
			if(openingGlzType ==  "Single") 
			{
				openingUvalue = 4.8 + adjFactorWoodPVC;				
			}

			//----------------------------------------------------
			// Double glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.8 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.9 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.0 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.1 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "No") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.7 + adjFactorWoodPVC;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 2.7 + adjFactorWoodPVC;	
			}
			//----------------------------------------------------
			// Double glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.7 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.8 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 1.9 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.0 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "Yes") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.6 + adjFactorWoodPVC;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 2.6 + adjFactorWoodPVC;	
			}
			//----------------------------------------------------
			// triple glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.4 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.5 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 1.6 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 1.6 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "No") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.0 + adjFactorWoodPVC;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 2.0 + adjFactorWoodPVC;	
			}

			//----------------------------------------------------
			// triple glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.3 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.4 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 1.4 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 1.5 + adjFactorWoodPVC;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "Yes")  ) //&& ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 1.9 + adjFactorWoodPVC;	
			}		
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 1.9 + adjFactorWoodPVC;	
			}
		}

		//-------------------------------------------------------------
		// Check type of thermal break to apply adjustments to u-value
		//-------------------------------------------------------------
		if(str_comboThermalBreak == "None")
		{	
            adjFactorThermBreak = 0.3;
		}
		else if(str_comboThermalBreak == "4mm")
		{	
            adjFactorThermBreak = 0.0;
		}
		else if(str_comboThermalBreak == "8mm")
		{	
            adjFactorThermBreak = -0.1;
		}
		else if(str_comboThermalBreak == "12mm")
		{	
            adjFactorThermBreak = -0.2;
		}
		else if(str_comboThermalBreak == "20mm")
		{	
            adjFactorThermBreak = -0.3;
		}
		else if(str_comboThermalBreak == "32mm")
		{	
            adjFactorThermBreak = -0.4;
		}

		

		//----------------------------------------------------
		// METAL FRAME, THERMAL BREAK 4mm, GAP 6mm
		//----------------------------------------------------
		// 1. With 6mm gap
		if((str_comboFrame == "Metal") && (openingGap == "6mm"))
		{
			//----------------------------------------------------
			// Single glazed
			//----------------------------------------------------
			if(openingGlzType ==  "Single") 
			{
				openingUvalue = 5.7;			
			}

			//----------------------------------------------------
			// Double glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 3.2 + adjFactorThermBreak;			
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 3.2 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 3.3 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 3.3 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "No") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 3.7 + adjFactorThermBreak;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 3.7 + adjFactorThermBreak;	
			}
			//----------------------------------------------------
			// Double glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.8 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.9 + adjFactorThermBreak;	
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 3.0 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 3.0 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "Yes") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 3.5 + adjFactorThermBreak;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 3.5 + adjFactorThermBreak;	
			}

			//----------------------------------------------------
			// triple glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.4 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.5 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.5 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.6 + adjFactorThermBreak;	
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "No") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.9 + adjFactorThermBreak;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 2.9 + adjFactorThermBreak;	
			}

			//----------------------------------------------------
			// triple glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.2 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.2 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.3 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.3 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "Yes")  ) //&& ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.8 + adjFactorThermBreak;	
			}	
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 2.8 + adjFactorThermBreak;	
			}
		}

		//----------------------------------------------------
		// 2. With 12mm gap
		if((str_comboFrame == "Metal") && (openingGap == "12mm"))
		{
			//----------------------------------------------------
			// Single glazed
			//----------------------------------------------------
			if(openingGlzType ==  "Single") 
			{
				openingUvalue = 5.7;			
			}

			//----------------------------------------------------
			// Double glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.5 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.6 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.7 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.8 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "No") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 3.4 + adjFactorThermBreak;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 3.4 + adjFactorThermBreak;	
			}
			//----------------------------------------------------
			// Double glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.2 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.4 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.5 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.6 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "Yes")) //  && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 3.3 + adjFactorThermBreak;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 3.3 + adjFactorThermBreak;	
			}

			//----------------------------------------------------
			// triple glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.9 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.0 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.1 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.1 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "No")  ) //&& ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.6 + adjFactorThermBreak;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 2.6 + adjFactorThermBreak;	
			}

			//----------------------------------------------------
			// triple glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.8 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.9 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 1.9 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.0 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "Yes")) //  && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.5 + adjFactorThermBreak;	
			}	
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 2.5 + adjFactorThermBreak;	
			}
		}

		//----------------------------------------------------
		// 3. With 16mm or more gap
		if((str_comboFrame == "Metal") && (str_comboThermalBreak == "4mm") && (openingGap == "16mm or more"))
		{
			//----------------------------------------------------
			// Single glazed
			//----------------------------------------------------
			if(openingGlzType ==  "Single") 
			{
				openingUvalue = 5.7;			
			}

			//----------------------------------------------------
			// Double glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.3 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.4 + adjFactorThermBreak;	
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.5 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.6 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "No")  ) //&& ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 3.3 + adjFactorThermBreak;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 3.3 + adjFactorThermBreak;	
			}
			//----------------------------------------------------
			// Double glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 2.1 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 2.3 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.4 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.5 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Double") && (openingArgonFilled == "Yes") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 3.2 + adjFactorThermBreak;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Double Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 3.2 + adjFactorThermBreak;	
			}

			//----------------------------------------------------
			// triple glazed, air filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.8 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.9 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 2.0 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 2.0 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "No") ) // && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.5 + adjFactorThermBreak;	
			}
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1)&& (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "No"))
			{
				openingUvalue = 2.5 + adjFactorThermBreak;	
			}

			//----------------------------------------------------
			// triple glazed, argon filled
			//----------------------------------------------------
			if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>=0)&& (openingEmissivty<=0.05))) 
			{
				openingUvalue = 1.7 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Soft") && ((openingEmissivty>0.05)&& (openingEmissivty<=0.10))) 
			{
				openingUvalue = 1.8 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.10)&& (openingEmissivty<=0.15))) 
			{
				openingUvalue = 1.8 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes") && (openingLowECoating == "Hard") && ((openingEmissivty>0.15)&& (openingEmissivty<=0.2))) 
			{
				openingUvalue = 1.9 + adjFactorThermBreak;				
			}
			else if((openingGlzType ==  "Triple") && (openingArgonFilled == "Yes")) //  && ((openingEmissivty>0.2)&& (openingEmissivty<=1))) 
			{
				openingUvalue = 2.4 + adjFactorThermBreak;	
			}		
			else if((openingEmissivty>0.2)&& (openingEmissivty<=1) && (openingGlzType ==  "Triple Low E") && (openingArgonFilled == "Yes"))
			{
				openingUvalue = 2.4 + adjFactorThermBreak;	
			}
		}
	str_editUValue.Format("%.1f",openingUvalue);

	}
	else
	{
		m_editUValue.SetReadOnly(FALSE);
	}



	UpdateData(FALSE);
}

void CDlg_Openings::OnBnClickedButtonAdd()
{	
	
	openingListData tempEntry;
	unsigned int sizeOfVector;
	unsigned int i = 0;

	if(str_editOpeningName == "")
	{
		MessageBox("Please specify name of the opening.", "Warning", MB_OK);
		return;
	}

	// Display warning if user specifies an opening name that has been already defined
	if(addOpening>0)
	{
		for(i = 0; i<=openingListData_New.size();i++)
		{
			if (openingListData_New[i].openingName == newOpeningName)
			{
				MessageBox("This opening name already exists, please enter a new name", "Warning", MB_OK);
				return;
			}
		}
	}
	
	//------------------------------------------
	// Display dialog to add openings
	//------------------------------------------
	CDlg_AddOpenings Dlg_AddOpenings;
	Dlg_AddOpenings.DoModal();


	

	if(is_new_opeing_added == true)
	{
		is_new_opeing_added = false;

		//------------------------------------------
		// Write data for opening type in vector
		//------------------------------------------


		strcpy(tempEntry.openingName,newOpeningName);
		//strcpy(tempEntry.openingFromSource, openingFromSource); 20feb
		//strcpy(tempEntry.openingDescription, openingDescription); 20feb
		strcpy(tempEntry.openingGlzType, openingGlzType);
		strcpy(tempEntry.openingLowECoating, openingLowECoating);
		strcpy(tempEntry.openingUsedDefEmissivity, openingUsedDefEmissivity);
		tempEntry.openingEmissivty = openingEmissivty;

		strcpy(tempEntry.openingArgonFilled, openingArgonFilled);
		strcpy(tempEntry.openingGap, openingGap);
		tempEntry.openingPitch = openingPitch; // ???unknown
		strcpy(tempEntry.openingOrientation, openingOrientation);
		strcpy(tempEntry.openingOvershading, openingOvershading);

		tempEntry.openingWidth  = openingWidth;
		tempEntry.openingHeight = openingHeight;
		strcpy(tempEntry.openingLocationName, openingLocationName);
		tempEntry.openingOverhangDepth = openingOverhangDepth;
		tempEntry.openingOverhangWidth = openingOverhangWidth;

		strcpy(tempEntry.openingRef, openingRef);
		strcpy(tempEntry.openingLinkageMaster, openingLinkageMaster);
		strcpy(tempEntry.openingLinkedTo, openingLinkedTo);

		strcpy(tempEntry.openingFrame, openingFrame);
		strcpy(tempEntry.openingThermalBreak, openingThermalBreak);
		strcpy(tempEntry.openingDraughtProofing, openingDraughtProofing);
		strcpy(tempEntry.openingMetalLintel, openingMetalLintel);

		strcpy(tempEntry.openingTransmittanceSelected, openingTransmittanceSelected);
		tempEntry.openingTransmittanceFactor = openingTransmittanceFactor;

		strcpy(tempEntry.openingFrameSelected, openingFrameSelected);
		tempEntry.openingFrameFactor = openingFrameFactor;

		strcpy(tempEntry.openingUvalueSelected, openingUvalueSelected);
		tempEntry.openingUvalue = openingUvalue;

		openingListData_New.push_back(tempEntry);

		sizeOfVector= openingListData_New.size();
	}	
}


void CDlg_Openings::OnBnClickedButtonView()
{
	CDlg_ListOpenings DlgListOpenings;
	DlgListOpenings.DoModal();
}

void CDlg_Openings::OnCbnSelchangeComboSource()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnEnChangeEdit1()
{
	//------------------------------------------------------------------------------
	// 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_editDescription, lpszValidChars) != 0) 
	{
		str_editDescription = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboGlazingtype()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboLowe()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeCombouserdefem()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::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_editEmissivity, lpszValidChars) != 0) 
	{
		str_editEmissivity = "";
		UpdateData(FALSE);
		return;
	}

	openingEmissivty = atof(str_editEmissivity);
	if((openingEmissivty<0) && (openingEmissivty>1))
	{
		MessageBox("The value of emissivity should be from 0 - 1.\n              Please enter a new value.", "Warning", MB_OK);
		str_editEmissivity = "";
		UpdateData(FALSE);
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboArgonfilled()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboGap()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnEnChangeEdit3()
{
	//------------------------------------------------------------------------------
	// 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_editPitch, lpszValidChars) != 0) 
	{
		str_editPitch = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboOrientation()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboOvershading()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnEnChangeEdit4()
{
	//------------------------------------------------------------------------------
	// 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_editWidth, lpszValidChars) != 0) 
	{
		str_editWidth = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnEnChangeEdit5()
{
	//------------------------------------------------------------------------------
	// 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_editHeight, lpszValidChars) != 0) 
	{
		str_editHeight = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboLocationname()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnEnChangeEdit7()
{
	//------------------------------------------------------------------------------
	// 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_editOverhangDepth, lpszValidChars) != 0) 
	{
		str_editOverhangDepth = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnEnChangeEdit6()
{
	//------------------------------------------------------------------------------
	// 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_editOverhangWidth, lpszValidChars) != 0) 
	{
		str_editOverhangWidth = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboMaster()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboLinkedto()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboFrame()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboThermalbreak()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboDraughtproofing()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboMetallintel()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboTransfactor()
{
	ReadInputsFromOpeningsDlg();	
}

void CDlg_Openings::OnEnChangeEdit8()
{
    //------------------------------------------------------------------------------
	// 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_editTransmittance, lpszValidChars) != 0) 
	{
		str_editTransmittance = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeComboFramefactor()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnEnChangeEdit9()
{
	//------------------------------------------------------------------------------
	// 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_editFractionGlazed, lpszValidChars) != 0) 
	{
		str_editFractionGlazed = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnCbnSelchangeCombouvalue()
{
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnEnChangeEdit10()
{
	//------------------------------------------------------------------------------
	// 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_editUValue, lpszValidChars) != 0) 
	{
		str_editUValue = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}

void CDlg_Openings::OnEnChangeEdit11()
{
	//------------------------------------------------------------------------------
	// 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_editRef, lpszValidChars) != 0) 
	{
		str_editRef = "";
		UpdateData(FALSE);
		return;
	}
	ReadInputsFromOpeningsDlg();
}


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

void CDlg_Openings::OnCbnSelchangeCombo1()
{
	ReadInputsFromOpeningsDlg();
}

BOOL CDlg_Openings::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 ;
	} 

	return CDialog::PreTranslateMessage(pMsg);
}
