protected void btnNext_Click(object sender, EventArgs e)
        {
            Set_smoking_drug_alcohol_buttons();

            if (IsValid &&
                btnCurrentSmokerYes.BackColor == Color.LightGray &&
                btnNarcoticYes.BackColor == Color.LightGray &&
                btnAlcoholYes.BackColor == Color.LightGray)
            {
                String strAccountName = strLastName + " (" + strFirstName + ") Household";

                Session["Title"]       = ddlTitle.SelectedItem.Text;
                Session["MiddleName"]  = txtMiddleName.Text;
                Session["DateOfBirth"] = txtDateOfBirth.Text;
                //if (rbMale.Checked) Session["Gender"] = "Male";
                //if (rbFemale.Checked) Session["Gender"] = "Female";
                Session["SSN"]           = txtSSN.Text;
                Session["Telephone1"]    = txtTelephone1.Text;
                Session["Telephone2"]    = txtTelephone2.Text;
                Session["Telephone3"]    = txtTelephone3.Text;
                Session["StreetAddress"] = txtAddress.Text;

                // This section should uncommented in production code
                Session["ZipCode"] = txtZipCode.Text;
                Session["State"]   = ddlState.SelectedItem.Text;
                Session["City"]    = ddlCity.SelectedItem.Text;

                //Session["ZipCode"] = "60714";
                //Session["State"] = "Illinois";
                //Session["City"] = "Niles";

                //InitializedSfdcbinding();


                //String strQueryForAccountIdOnEmail = "select Id from Account where cmm_Email__c = '" + strEmail + "'";

                //SForce.QueryResult qrAccountId = Sfdcbinding.query(strQueryForAccountIdOnEmail);

                //if (qrAccountId.size > 0)
                //{
                //SForce.Account acctHouseholdId = qrAccountId.records[0] as SForce.Account;

                //}


                //SForce.SaveResult[] srNewContact = Sfdcbinding.create(new SForce.sObject[] { ctPrimary });

                //String strPrimaryContactId = null;

                //if (srNewContact[0].success)
                //{
                //    lblSaveSuccessFailure.Text += "Contact added successfully";

                //    strPrimaryContactId = srNewContact[0].id;
                //    Session["ContactId"] = srNewContact[0].id;
                //}
                //else
                //{
                //    lblSaveSuccessFailure.Text += srNewContact[0].errors[0].message;
                //}

                Boolean bUpdatePrimarySuccess = false;
                String  strPrimaryContactId   = null;
                String  strQueryForPrimaryId  = "select Id from Contact where Email = '" + txtEmail.Text + "'";

                SForce.QueryResult qrPrimary = Sfdcbinding.query(strQueryForPrimaryId);

                if (qrPrimary.size > 0)
                {
                    SForce.Contact ctPrimary = new SForce.Contact();
                    ctPrimary.Id = qrPrimary.records[0].Id;
                    ctPrimary.cmm_Household__c = strAccountId;
                    //ctPrimary.Email = txtEmail.Text;
                    ctPrimary.Title = ddlTitle.SelectedItem.Text;
                    //ctPrimary.LastName = txtLastName.Text;
                    //ctPrimary.FirstName = txtFirstName.Text;
                    ctPrimary.MiddleName            = txtMiddleName.Text;
                    ctPrimary.cmm_Household_Role__c = "Head of Household";

                    String strBirthDate = txtDateOfBirth.Text;

                    String[] arryBirthDate = strBirthDate.Split('/');

                    int nBirthMonth = Int32.Parse(arryBirthDate[0]);
                    int nBirthDay   = Int32.Parse(arryBirthDate[1]);
                    int nBirthYear  = Int32.Parse(arryBirthDate[2]);

                    ctPrimary.Birthdate          = new DateTime(nBirthYear, nBirthMonth, nBirthDay);
                    ctPrimary.BirthdateSpecified = true;

                    ctPrimary.cmm_Gender__c = rbGenderList.SelectedItem.Text;

                    ctPrimary.Social_Security_Number__c = txtSSN.Text;
                    ctPrimary.Phone       = txtTelephone1.Text;
                    ctPrimary.HomePhone   = txtTelephone1.Text;
                    ctPrimary.MobilePhone = txtTelephone2.Text;
                    ctPrimary.OtherPhone  = txtTelephone3.Text;

                    SForce.SaveResult[] srUpdatePrimary = Sfdcbinding.update(new SForce.sObject[] { ctPrimary });

                    if (srUpdatePrimary[0].success)
                    {
                        strPrimaryContactId   = qrPrimary.records[0].Id;
                        Session["ContactId"]  = qrPrimary.records[0].Id;
                        bUpdatePrimarySuccess = true;
                    }
                }


                String strQueryForContactId = "select Name from Contact where Email = '" + txtEmail.Text + "'";

                SForce.QueryResult qrContactId = Sfdcbinding.query(strQueryForContactId);

                //String strContactId = strPrimaryContactId;
                //String strMemberName = null;

                if (qrContactId.size > 0)
                {
                    SForce.Contact ctName = (SForce.Contact)qrContactId.records[0];
                    //strContactId = ctId.Id;
                    //strMemberName = ctId.Name;
                    //Session["ContactId"] = strContactId;

                    //               MemberSmokingDrugAlcohol primarySDA = new MemberSmokingDrugAlcohol();

                    //               primarySDA.AccountId = strAccountId;
                    //               primarySDA.HouseholdRole = HouseholdRoles.Primary;
                    //               primarySDA.ContactId = strPrimaryContactId;
                    //               primarySDA.Name = ctName.Name;
                    //               primarySDA.bCurrentSmoker = false;
                    //               primarySDA.bCurrentDrug = false;
                    //primarySDA.bAlcohol = false;
                    //               if (btnFormerSmokerYes.BackColor == Color.Green) primarySDA.bFormerSmoker = true;
                    //               if (btnFormerSmokerNo.BackColor == Color.Blue) primarySDA.bFormerSmoker = false;
                    //               if (btnFormerNarcoticYes.BackColor == Color.Green) primarySDA.bFormerDrug = true;
                    //               if (btnFormerNarcoticNo.BackColor == Color.Blue) primarySDA.bFormerDrug = false;
                    //               //if (btnAlcoholYes.BackColor == Color.Green) primarySDA.bAlcohol = true;
                    //               //if (btnAlcoholNo.BackColor == Color.Blue) primarySDA.bAlcohol = false;

                    //               lstMemberSDA.Add(primarySDA);
                    //               Session["MemberSmokingDrugAlcohol"] = lstMemberSDA;

                    // Save lstMemberSDA to salesforce for incomplete application - done
                    string strQueryForPrimarySDA = "select Id from tmp_SmokingDrugAlcohol__c where cmm_Account__c = '" + strAccountId + "' and " +
                                                   "cmm_Household_Role__c = 'Head of Household'";

                    SForce.QueryResult qrTmpPrimarySDA = Sfdcbinding.query(strQueryForPrimarySDA);
                    if (qrTmpPrimarySDA.size > 0)
                    {
                        SForce.tmp_SmokingDrugAlcohol__c tmpHeadSDA = qrTmpPrimarySDA.records[0] as SForce.tmp_SmokingDrugAlcohol__c;

                        SForce.tmp_SmokingDrugAlcohol__c tmpPrimarySDA = new SForce.tmp_SmokingDrugAlcohol__c();

                        tmpPrimarySDA.Id = tmpHeadSDA.Id;
                        tmpPrimarySDA.cmm_bCurrentSmoker__c = "No";
                        tmpPrimarySDA.cmm_bCurrentDrug__c   = "No";
                        tmpPrimarySDA.cmm_bAlcohol__c       = "No";
                        if (btnFormerSmokerYes.BackColor == Color.Green)
                        {
                            tmpPrimarySDA.cmm_bFormerSmoker__c = "Yes";
                        }
                        if (btnFormerSmokerNo.BackColor == Color.Blue)
                        {
                            tmpPrimarySDA.cmm_bFormerSmoker__c = "No";
                        }
                        if (btnFormerNarcoticYes.BackColor == Color.Green)
                        {
                            tmpPrimarySDA.cmm_bFormerDrug__c = "Yes";
                        }
                        if (btnFormerNarcoticNo.BackColor == Color.Blue)
                        {
                            tmpPrimarySDA.cmm_bFormerDrug__c = "No";
                        }

                        SForce.SaveResult[] srUpdateTmpPrimarySDA = Sfdcbinding.update(new SForce.sObject[] { tmpPrimarySDA });

                        if (srUpdateTmpPrimarySDA[0].success)
                        {
                            // temporary instance of salesforc object is udpated successfully
                        }
                    }
                    else if (qrTmpPrimarySDA.size == 0)
                    {
                        SForce.tmp_SmokingDrugAlcohol__c tmpPrimarySDA = new SForce.tmp_SmokingDrugAlcohol__c();

                        tmpPrimarySDA.cmm_Account_Creation_Step_Code__c          = 3;
                        tmpPrimarySDA.cmm_Account_Creation_Step_Code__cSpecified = true;
                        tmpPrimarySDA.cmm_Account__c        = strAccountId;
                        tmpPrimarySDA.cmm_Contact__c        = strPrimaryContactId;
                        tmpPrimarySDA.cmm_Household_Role__c = "Head of Household";
                        tmpPrimarySDA.cmm_Name__c           = ctName.Name;
                        tmpPrimarySDA.cmm_bCurrentSmoker__c = "No";
                        tmpPrimarySDA.cmm_bCurrentDrug__c   = "No";
                        tmpPrimarySDA.cmm_bAlcohol__c       = "No";
                        if (btnFormerSmokerYes.BackColor == Color.Green)
                        {
                            tmpPrimarySDA.cmm_bFormerSmoker__c = "Yes";
                        }
                        if (btnFormerSmokerNo.BackColor == Color.Blue)
                        {
                            tmpPrimarySDA.cmm_bFormerSmoker__c = "No";
                        }
                        if (btnFormerNarcoticYes.BackColor == Color.Green)
                        {
                            tmpPrimarySDA.cmm_bFormerDrug__c = "Yes";
                        }
                        if (btnFormerNarcoticNo.BackColor == Color.Blue)
                        {
                            tmpPrimarySDA.cmm_bFormerDrug__c = "No";
                        }
                        //if (btnAlcoholYes.BackColor == Color.Green) tmpPrimarySDA.cmm_bAlcohol__c = "Yes";
                        //if (btnAlcoholNo.BackColor == Color.Blue) tmpPrimarySDA.cmm_bAlcohol__c = "No";

                        SForce.SaveResult[] srTmpPrimarySDA = Sfdcbinding.create(new SForce.sObject[] { tmpPrimarySDA });

                        if (srTmpPrimarySDA[0].success)
                        {
                            // temporary instance of salesforce object is created successfully
                        }
                    }
                }


                //SForce.Account acctUpdate = new SForce.Account();

                //if (strAccountId != null) acctUpdate.Id = strAccountId;
                //if (strPrimaryContactId != null) acctUpdate.cmm_Contact__c = strPrimaryContactId;

                //SForce.SaveResult[] updateResultsAccount = Sfdcbinding.update(new SForce.sObject[] { acctUpdate });

                //if (updateResultsAccount[0].success)
                //{
                //    lblSaveSuccessFailure.Text += "Account update succeeded";
                //}
                //else
                //{
                //    lblSaveSuccessFailure.Text += updateResultsAccount[0].errors[0].message;
                //}

                //SForce.Contact ctUpdate = new SForce.Contact();

                //if (strPrimaryContactId != null) ctUpdate.Id = strPrimaryContactId;
                //if (strAccountId != null) ctUpdate.cmm_Household__c = strAccountId;

                //SForce.SaveResult[] updateResultsContact = Sfdcbinding.update(new SForce.sObject[] { ctUpdate });

                //if (updateResultsContact[0].success)
                //{
                //    lblSaveSuccessFailure.Text += "Contact update succeeded";
                //}
                //else
                //{
                //    lblSaveSuccessFailure.Text += updateResultsContact[0].errors[0].message;
                //}



                Boolean bUpdateAcctHouseholdSuccess = false;

                SForce.Account acctHousehold = new SForce.Account();
                acctHousehold.Id = strAccountId;
                acctHousehold.cmm_Account_Creation_Step_Code__c = "3";
                acctHousehold.cmm_Contact__c     = strPrimaryContactId;
                acctHousehold.ShippingStreet     = txtAddress.Text;
                acctHousehold.ShippingCity       = ddlCity.SelectedValue;
                acctHousehold.ShippingState      = ddlState.SelectedValue;
                acctHousehold.ShippingPostalCode = txtZipCode.Text;

                acctHousehold.BillingStreet     = txtAddress.Text;
                acctHousehold.BillingCity       = ddlCity.SelectedValue;
                acctHousehold.BillingState      = ddlState.SelectedValue;
                acctHousehold.BillingPostalCode = txtZipCode.Text;

                SForce.SaveResult[] updateResults = Sfdcbinding.update(new SForce.sObject[] { acctHousehold });

                if (updateResults[0].success)
                {
                    // The Household account updated with Shipping address
                    //Session["PreviousPage"] = "PersonalDetails";
                    //Response.Redirect("~/FamilyDetails.aspx");
                    bUpdateAcctHouseholdSuccess = true;
                }

                if (bUpdatePrimarySuccess && bUpdateAcctHouseholdSuccess)
                {
                    Session["PreviousPage"] = "PersonalDetails";
                    Response.Redirect("~/FamilyDetails.aspx");
                }


                //if (updateResultsAccount[0].success && updateResultsContact[0].success)
                //{

                //    //SForce.Account acctPrimary = new SForce.Account();
                //    //if (strAccountId != null) acctPrimary.Id = strAccountId;
                //    //acctPrimary.cmm_Account_Creation_Step_Code__c = "2";

                //    //SForce.SaveResult[] srAccount = Sfdcbinding.update(new SForce.sObject[] { acctPrimary });

                //    //if (srAccount[0].success)
                //    //{
                //    //    Session["PreviousPage"] = "CreateAccount";
                //    //    Response.Redirect("~/PersonalDetails.aspx");
                //    //}

                //    SForce.Account acctPrimary = new SForce.Account();
                //    acctPrimary.Id = strAccountId;
                //    acctPrimary.cmm_Account_Creation_Step_Code__c = "3";

                //    acctPrimary.BillingStreet = txtAddress.Text;
                //    acctPrimary.BillingCity = ddlCity.SelectedItem.Text;
                //    acctPrimary.BillingState = ddlState.SelectedItem.Text;
                //    acctPrimary.BillingPostalCode = txtZipCode.Text;

                //    SForce.SaveResult[] srAccount = Sfdcbinding.update(new SForce.sObject[] { acctPrimary });

                //    if (srAccount[0].success)
                //    {
                //        // the update has succeeded
                //        Session["PreviousPage"] = "PersonalDetails";
                //        Response.Redirect("~/FamilyDetails.aspx");
                //    }
                //}
            }
            else
            {
                // user is current smoker or taking narcotic drug
                mpeUserSmokingDrugAlcohol.Show();
            }
        }
        protected void LoadPrimarySDAInfo()
        {
            String strQueryForPrimarySDA = "select cmm_Account__c, cmm_Contact__c, cmm_Name__c, " +
                                           "cmm_bCurrentSmoker__c, cmm_bFormerSmoker__c, cmm_bCurrentDrug__c, cmm_bFormerDrug__c, cmm_bAlcohol__c " +
                                           "from tmp_SmokingDrugAlcohol__c where cmm_Account__c = '" + strAccountId + "' and " +
                                           "cmm_Household_Role__c = 'Head of Household'";

            SForce.QueryResult qrPrimarySDA = Sfdcbinding.query(strQueryForPrimarySDA);

            if (qrPrimarySDA.size > 0)
            {
                SForce.tmp_SmokingDrugAlcohol__c tmpPrimarySDA = qrPrimarySDA.records[0] as SForce.tmp_SmokingDrugAlcohol__c;

                if (tmpPrimarySDA.cmm_bCurrentSmoker__c == "Yes")
                {
                    btnCurrentSmokerYes.BackColor = Color.Red;
                    btnCurrentSmokerYes.ForeColor = Color.White;
                    btnCurrentSmokerNo.BackColor  = Color.LightGray;
                    btnCurrentSmokerNo.ForeColor  = Color.Black;
                    hdnCurrentSmokerYes.Value     = "red";
                    hdnCurrentSmokerNo.Value      = "lightgrey";
                }
                else if (tmpPrimarySDA.cmm_bCurrentSmoker__c == "No")
                {
                    btnCurrentSmokerYes.BackColor = Color.LightGray;
                    btnCurrentSmokerYes.ForeColor = Color.Black;
                    btnCurrentSmokerNo.BackColor  = Color.Blue;
                    btnCurrentSmokerNo.ForeColor  = Color.White;
                    hdnCurrentSmokerYes.Value     = "lightgrey";
                    hdnCurrentSmokerNo.Value      = "blue";
                }
                if (tmpPrimarySDA.cmm_bFormerSmoker__c == "Yes")
                {
                    btnFormerSmokerYes.BackColor = Color.Green;
                    btnFormerSmokerYes.ForeColor = Color.White;
                    btnFormerSmokerNo.BackColor  = Color.LightGray;
                    btnFormerSmokerNo.ForeColor  = Color.Black;
                    hdnFormerSmokerYes.Value     = "green";
                    hdnFormerSmokerNo.Value      = "lightgrey";
                }
                else if (tmpPrimarySDA.cmm_bFormerSmoker__c == "No")
                {
                    btnFormerSmokerYes.BackColor = Color.LightGray;
                    btnFormerSmokerYes.ForeColor = Color.Black;
                    btnFormerSmokerNo.BackColor  = Color.Blue;
                    btnFormerSmokerNo.ForeColor  = Color.White;
                    hdnFormerSmokerYes.Value     = "lightgrey";
                    hdnFormerSmokerNo.Value      = "blue";
                }
                if (tmpPrimarySDA.cmm_bCurrentDrug__c == "Yes")
                {
                    btnNarcoticYes.BackColor = Color.Red;
                    btnNarcoticYes.ForeColor = Color.White;
                    btnNarcoticNo.BackColor  = Color.LightGray;
                    btnNarcoticNo.ForeColor  = Color.Black;
                    hdnNarcoticYes.Value     = "red";
                    hdnNarcoticNo.Value      = "lightgrey";
                }
                else if (tmpPrimarySDA.cmm_bCurrentDrug__c == "No")
                {
                    btnNarcoticYes.BackColor = Color.LightGray;
                    btnNarcoticYes.ForeColor = Color.Black;
                    btnNarcoticNo.BackColor  = Color.Blue;
                    btnNarcoticNo.ForeColor  = Color.White;
                    hdnNarcoticYes.Value     = "lightgrey";
                    hdnNarcoticNo.Value      = "blue";
                }
                if (tmpPrimarySDA.cmm_bFormerDrug__c == "Yes")
                {
                    btnFormerNarcoticYes.BackColor = Color.Green;
                    btnFormerNarcoticYes.ForeColor = Color.White;
                    btnFormerNarcoticNo.BackColor  = Color.LightGray;
                    btnFormerNarcoticNo.ForeColor  = Color.Black;
                    hdnFormerNarcoticYes.Value     = "green";
                    hdnFormerNarcoticNo.Value      = "lightgrey";
                }
                else if (tmpPrimarySDA.cmm_bFormerDrug__c == "No")
                {
                    btnFormerNarcoticYes.BackColor = Color.LightGray;
                    btnFormerNarcoticYes.ForeColor = Color.Black;
                    btnFormerNarcoticNo.BackColor  = Color.Blue;
                    btnFormerNarcoticNo.ForeColor  = Color.White;
                    hdnFormerNarcoticYes.Value     = "lightgrey";
                    hdnFormerNarcoticNo.Value      = "blue";
                }
                if (tmpPrimarySDA.cmm_bAlcohol__c == "Yes")
                {
                    btnAlcoholYes.BackColor = Color.Red;
                    btnAlcoholYes.ForeColor = Color.White;
                    btnAlcoholNo.BackColor  = Color.LightGray;
                    btnAlcoholNo.ForeColor  = Color.Black;
                    hdnAlcoholYes.Value     = "red";
                    hdnAlcoholNo.Value      = "lightgrey";
                }
                else if (tmpPrimarySDA.cmm_bAlcohol__c == "No")
                {
                    btnAlcoholYes.BackColor = Color.LightGray;
                    btnAlcoholYes.ForeColor = Color.Black;
                    btnAlcoholNo.BackColor  = Color.Blue;
                    btnAlcoholNo.ForeColor  = Color.White;
                    hdnAlcoholYes.Value     = "lightgrey";
                    hdnAlcoholNo.Value      = "blue";
                }
            }
        }