protected void lnkBtnLocationAdd_Click(object sender, EventArgs e)
    {
        try
        {
            //ddlRoleList.Items.Clear();
            //Utils.GetLookUpData<DropDownList>(ref ddlRoleList, LookUps.RoleName, Conversion.ParseInt(ddlOrganizationType.SelectedValue));

            OrganizationInfo objOrg = new OrganizationInfo();

            objOrg.LegalName = txtLocationBusinessName.Text.Trim();
            objOrg.DBAName = txtLocationDBAName.Text.Trim();
            objOrg.IsLocationEventPermanent = chkLocationPermanent.Checked;

            if (objOrg.IsLocationEventPermanent == false)
            {
                try
                {
                    objOrg.LocationEventTypeId = Convert.ToInt32(ddlLocationEventType.SelectedValue);
                    objOrg.LocationEventStartDate = Convert.ToDateTime(txtLocationFromDate.Text, System.Globalization.CultureInfo.InvariantCulture);
                    objOrg.LocationEventEndDate = Convert.ToDateTime(txtLocationToDate.Text, System.Globalization.CultureInfo.InvariantCulture);
                }
                catch (Exception ex)
                {
                    objOrg.IsLocationEventPermanent = true;
                }
            }

            objOrg.LocationPermitNumber = txtLocationPermitNumber.Text.Trim();
            objOrg.IsActive = true;
            objOrg.IsOrganization = false;
            objOrg.LanguageId = LanguageId;
            objOrg.ParentId = Convert.ToInt32(hdnOrganizationID.Value);

            ContactInfo objContact = new ContactInfo();

            objContact.FirstName = txtLocationContactFirstName.Text.Trim();
            objContact.LastName = txtLocationContactLastName.Text.Trim();
            objContact.ContactTitleId = Convert.ToInt32(ddlLocationContactTitle.SelectedValue);
            objContact.Email = txtLocationContactEmail.Text.Trim();
            objContact.IsActive = true;
            objContact.IsPrimary = true;
            objContact.LanguageId = LanguageId;
            //objContact.ContactTypeId = Convert.ToInt32(ContactInfo.ContactTypes.Business);
            objContact.ContactTypeId = Convert.ToInt32(LookupsManagement.LookupType.ContactTypes_Business);

            Phones objBusinessPhone = new Phones();

            objBusinessPhone.Number = txtLocationBusinessPhone1.Text.Trim() + "-" + txtLocationBusinessPhone2.Text.Trim() + "-" + txtLocationBusinessPhone3.Text.Trim();
            objBusinessPhone.Extension = txtLocationBusinessPhoneExtension.Text.Trim();
            objBusinessPhone.IsActive = true;
            //objBusinessPhone.PhoneTypeId = Convert.ToInt32(Phones.PhoneType.Business);
            objBusinessPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Business);

            Phones objCellPhone = new Phones();

            objCellPhone.Number = txtLocationCellPhone1.Text.Trim() + "-" + txtLocationCellPhone2.Text.Trim() + "-" + txtLocationCellPhone3.Text.Trim();
            objCellPhone.IsAcceptTextMessages = chkLocationContactAcceptTextMessages.Checked;
            objCellPhone.IsActive = true;
            //objCellPhone.PhoneTypeId = Convert.ToInt32(Phones.PhoneType.Cell);
            objCellPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Cell);

            OrganizationInfo.Organization_Address objOrganization_Address = new OrganizationInfo.Organization_Address();

            objOrganization_Address.ZipCodeID = Convert.ToInt32(hdnLocationZipCodeID.Value);
            objOrganization_Address.ZipPostalCode = txtLocationZipCode.Text.Trim();
            objOrganization_Address.Address1 = txtLocationAddress1.Text.Trim();
            objOrganization_Address.Address2 = txtLocationAddress2.Text.Trim();
            objOrganization_Address.City = txtLocationCity.Text;
            objOrganization_Address.StateID = Convert.ToInt32(ddlLocationState.SelectedValue);
            objOrganization_Address.CountryID = Convert.ToInt32(ddlLocationCountry.SelectedValue);
            objOrganization_Address.DateCreated = DateTime.Now;
            objOrganization_Address.IsActive = true;
            //objOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(OrganizationInfo.Organization_Address.Organization_AddressType.Business);
            objOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(LookupsManagement.LookupType.OrganizationAddressType_Business);

            OrganizationInfo.SaveAdditionalLocationInfo(objOrg, objContact, objBusinessPhone, objCellPhone, objOrganization_Address);

            gvAdditionLocations.DataSource = OrganizationInfo.GetAdditionalLocationsByOrganizationId(Convert.ToInt32(hdnOrganizationID.Value));
            gvAdditionLocations.DataBind();
            LoadHeaderTextForAddLocations();

            ToolkitScriptManager.RegisterStartupScript(this, this.GetType(), "ClearAdditionalLocationFields", "ClearAdditionalLocationFields();", true);

            txtLocationZipCode.Text = "";
        }
        catch (Exception ex)
        {
            new SqlLog().InsertSqlLog(0, "RegistrationForm.lnkBtnAdditionalLocationAdd_Click", ex);
        }
    }
    protected void lnkbtnUpdate_Click(object sender, EventArgs e)
    {


        OrganizationInfo objOrg = new OrganizationInfo();

        objOrg.OrganizationId = OrganizationID;

        objOrg.LegalName = txtBusinessName.Text.Trim();
        objOrg.DBAName = txtDBAName.Text.Trim();
        objOrg.Website = txtWebsite.Text.Trim();
        objOrg.IsActive = true;
        objOrg.IsOrganization = true;
        objOrg.LanguageId = LanguageId;

        objOrg.RoleId = Conversion.ParseInt(UserInfo.UserRole.Stewardship);

        ContactInfo objPrimaryContact = new ContactInfo();

        objPrimaryContact.FirstName = txtFirstName.Text.Trim();
        objPrimaryContact.LastName = txtLastName.Text.Trim();
        objPrimaryContact.Email = txtPrimaryEmail.Text.Trim();

        objPrimaryContact.IsActive = true;
        objPrimaryContact.IsPrimary = true;
        objPrimaryContact.LanguageId = LanguageId;
        objPrimaryContact.ContactTypeId = Convert.ToInt32(LookupsManagement.LookupType.ContactTypes_Business);

        Phones objPrimaryContactBusinessPhone = new Phones();

        objPrimaryContactBusinessPhone.Number = txtPhoneNumber.Text.Trim().ToString();
        objPrimaryContactBusinessPhone.Extension = txtPhoneExtension.Text.Trim().ToString();
        objPrimaryContactBusinessPhone.IsActive = true;
        objPrimaryContactBusinessPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Business);

        Phones objPrimaryContactCellPhone = new Phones();

        objPrimaryContactCellPhone.Number = txtCellPhoneNumber.Text.Trim();
        objPrimaryContactCellPhone.IsActive = true;
        objPrimaryContactCellPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Cell);

        ContactInfo objBillingContact = new ContactInfo();
        objBillingContact.Email = txtBillingMailAddress.Text.Trim();
        objBillingContact.IsActive = true;
        objBillingContact.IsPrimary = false;
        objBillingContact.LanguageId = LanguageId;
        objBillingContact.ContactTypeId = Convert.ToInt32(ContactInfo.ContactTypes.Billing);
        objBillingContact.ContactTypeId = Convert.ToInt32(LookupsManagement.LookupType.ContactTypes_Billing);

        Phones objBillingContactBusinessPhone = new Phones();
        objBillingContactBusinessPhone.IsActive = true;
        objBillingContactBusinessPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Business);

        Phones objBillingContactCellPhone = new Phones();

        objBillingContactCellPhone.IsActive = true;
        objBillingContactCellPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Cell);

        OrganizationInfo.Organization_Address objBusinessOrganization_Address = new OrganizationInfo.Organization_Address();

        objBusinessOrganization_Address.ZipCodeID = Convert.ToInt32(hdnBusinessZipCodeId.Value);
        objBusinessOrganization_Address.ZipPostalCode = txtZipCode.Text.Trim().ToString();
        objBusinessOrganization_Address.Address1 = txtBusinessAddress1.Text.Trim();
        objBusinessOrganization_Address.Address2 = txtBusinessAddress2.Text.Trim();
        objBusinessOrganization_Address.City = txtCity.Text.Trim().ToString();
        objBusinessOrganization_Address.StateID = Convert.ToInt32(ddlState.SelectedValue);
        objBusinessOrganization_Address.CountryID = Convert.ToInt32(ddlCountry.SelectedValue);
        objBusinessOrganization_Address.DateCreated = DateTime.Now;
        objBusinessOrganization_Address.IsActive = true;
        objBusinessOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(LookupsManagement.LookupType.OrganizationAddressType_Business);

        OrganizationInfo.Organization_Address objMailingOrganization_Address = new OrganizationInfo.Organization_Address();
        objMailingOrganization_Address.DateCreated = DateTime.Now;
        objMailingOrganization_Address.IsActive = true;
        objMailingOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(LookupsManagement.LookupType.OrganizationAddressType_Mailing);

        OrganizationInfo.UpdateStewardshipInfo(objOrg, objPrimaryContact, objPrimaryContactBusinessPhone, objPrimaryContactCellPhone, objBillingContact, objBillingContactBusinessPhone, objBillingContactCellPhone, objBusinessOrganization_Address, objMailingOrganization_Address);
        lblinfo.Visible = true;
        lblinfo.Text = "Successfully updated";
        lblinfo.Style.Add("color", "green");
        viewStakeholdersForApproval();
        pnlDisplay.Visible = true;
        pnlEdit.Visible = false;

    }
    /*

		private void UpdateData(int OrganizationId)
		{
			OrganizationInfo ObjOrg = new OrganizationInfo(OrganizationId);
			ObjOrg.Address = txtBusinessAddress1.Text;
			
			ObjOrg.BillMailAddress = txtMailingAddress1.Text;

			ObjOrg.BusinessType = new List<int>();

			ObjOrg.CountryID = Convert.ToInt32(ddlBusinessCountry.SelectedValue);
			ObjOrg.CountryName = ddlBusinessCountry.Text;

			ObjOrg.DBAName = txtDBAName.Text;

			ObjOrg.IsActive = true;
			ObjOrg.IsOrganization = true;

			ObjOrg.LegalName = txtBusinessLegalName.Text;
			ObjOrg.OwnerManager = txtPrimaryContactFirstName.Text;
			ObjOrg.StateID = Convert.ToInt32(ddlBusinessProvince.SelectedValue);
			ObjOrg.ZipPostalCode = txtBusinessZipCode.Text;

			OrganizationInfo.Supplier ObjOrgSupplier = ObjOrg.objSupplier;

			ObjOrgSupplier.BussinessPhone = txtSupplierBusinessPhone1.Text.Trim() + "-" + txtSupplierBusinessPhone2.Text.Trim() + "-" + txtSupplierBusinessPhone3.Text.Trim();
			ObjOrgSupplier.City = txtSupplierCity.Text;
			ObjOrgSupplier.CompanyName = txtSupplierCompanyName.Text;
			ObjOrgSupplier.ContactName = txtSupplierscontactName.Text;
			ObjOrgSupplier.CountryID = int.Parse(ddlSuppliersCountry.SelectedValue);
			ObjOrgSupplier.Email = txtSuppliersownerEmail.Text;
			ObjOrgSupplier.IsActive = true;
			ObjOrgSupplier.OwnerManagerEmail = txtSuppliersownerEmail.Text;
			ObjOrgSupplier.StateId = Convert.ToInt32(ddlSuppliersProvince.SelectedValue);

			ObjOrg.objSupplier = ObjOrgSupplier;

			OrganizationInfo.Client objOrgClient = ObjOrg.objClient;

			objOrgClient.BussinessPhone = txtClientBusinessPhone1.Text.Trim() + "-" + txtClientBusinessPhone2.Text.Trim() + "-" + txtClientBusinessPhone3.Text.Trim();
			objOrgClient.City = txtClientCity.Text;
			objOrgClient.CompanyName = txtclientsCompanyName.Text;
			objOrgClient.ContactName = txtclientsContactName.Text;
			objOrgClient.CountryID = int.Parse(ddlclientsCountry.SelectedValue);
			objOrgClient.IsActive = true;
			objOrgClient.OwnerManagerEmail = txtclientsEmail.Text;
			objOrgClient.StateId = Convert.ToInt32(ddlclientsProvince.SelectedValue);

			ObjOrg.objClient = objOrgClient;

			ObjOrg.ObjOrgBusiness = new List<OrganizationInfo.Organization_Business>();

			//OrganizationInfo.Organization_Business objOrgBusiness;

			//foreach (RepeaterItem rptItem in rptBusiness.Items)
			//{
			//    objOrgBusiness = new OrganizationInfo.Organization_Business();

			//    CheckBox chkY = (CheckBox)rptItem.FindControl("chkY");
			//    CheckBox chkN = (CheckBox)rptItem.FindControl("chkN");

			//    if (chkY.Checked || chkN.Checked)
			//    {
			//        objOrgBusiness.BusinessID = Convert.ToInt32(((HiddenField)rptItem.FindControl("hdnID")).Value);
			//        objOrgBusiness.IsNew = chkY.Checked;

			//        ObjOrg.ObjOrgBusiness.Add(objOrgBusiness);

			//    }
			//}

			ObjOrg.CertificationID = new List<int>();

			foreach (RepeaterItem rptItem in rptStakeCertificates.Items)
			{
				if (((CheckBox)rptItem.FindControl("chk")).Checked)
				{
					ObjOrg.CertificationID.Add(Convert.ToInt32(((HiddenField)rptItem.FindControl("hdnID")).Value));
				}
			}

			foreach (RepeaterItem rptItem in rptTireCertificates.Items)
			{
				if (((CheckBox)rptItem.FindControl("chk")).Checked)
				{
					ObjOrg.CertificationID.Add(Convert.ToInt32(((HiddenField)rptItem.FindControl("hdnID")).Value));
				}
			}

			ObjOrg.UpdateOrganizationInfo();
		}

		private void SaveData()
		{
			OrganizationInfo ObjOrg = new OrganizationInfo();
			ObjOrg.Abbreviation = "";
			ObjOrg.Address = txtBusinessAddress1.Text;
			//ObjOrg.BillingContact = txtbillingContact.Text;
			ObjOrg.BillMailAddress = txtMailingAddress1.Text;

			ObjOrg.BusinessType = new List<int>();

			ObjOrg.City = "";
			ObjOrg.Clientid = 0;
			ObjOrg.ContactId = 0;
			ObjOrg.CountryID = Convert.ToInt32(ddlBusinessCountry.SelectedValue);
			ObjOrg.CountryName = ddlBusinessCountry.Text;
			ObjOrg.DateCreated = DateTime.Now.Date;
			ObjOrg.DBAName = txtDBAName.Text;
			ObjOrg.Description = "";
			ObjOrg.IsActive = true;

			ObjOrg.IsOrganization = true;
			ObjOrg.Language = "";
			ObjOrg.LanguageId = LanguageId;
			ObjOrg.LegalName = txtBusinessLegalName.Text;
			ObjOrg.LocationID = 0;
			ObjOrg.OrganizationId = 0;
			ObjOrg.OrganizationTypeId = 1;
			ObjOrg.OwnerManager = txtPrimaryContactFirstName.Text;
			ObjOrg.ParentId = 0;
			ObjOrg.PhoneId = 0;
			ObjOrg.RoleId = 0;
			ObjOrg.RoleName = "";
			ObjOrg.Specific = "";
			if (Request.QueryString["StakeHolderID"] != null && Utils.IsNumeric(Request.QueryString["StakeHolderID"]))
			{
				ObjOrg.StakeHolderId = Convert.ToInt32(Request.QueryString["StakeHolderID"]);
			}
			else
			{
				ObjOrg.StakeHolderId = 0;
			}

			ObjOrg.StateID = Convert.ToInt32(ddlBusinessProvince.SelectedValue);
			ObjOrg.Supplierid = 0;
			ObjOrg.TX_ID = "";
			ObjOrg.Website = "";
			ObjOrg.ZipPostalCode = txtBusinessZipCode.Text;

			OrganizationInfo.Supplier ObjOrgSupplier = new OrganizationInfo.Supplier();

			ObjOrgSupplier.BussinessPhone = txtSupplierBusinessPhone1.Text.Trim() + "-" + txtSupplierBusinessPhone2.Text.Trim() + "-" + txtSupplierBusinessPhone3.Text.Trim();
			ObjOrgSupplier.City = txtSupplierCity.Text;
			ObjOrgSupplier.CompanyName = txtSupplierCompanyName.Text;
			ObjOrgSupplier.ContactName = txtSupplierscontactName.Text;
			ObjOrgSupplier.Count = 0;
			ObjOrgSupplier.CountryID = int.Parse(ddlSuppliersCountry.SelectedValue);
			ObjOrgSupplier.DateCreated = DateTime.Now;
			ObjOrgSupplier.Email = txtSuppliersownerEmail.Text;
			ObjOrgSupplier.IsActive = true;
			ObjOrgSupplier.LanguageID = LanguageId;
			ObjOrgSupplier.OwnerManagerEmail = txtSuppliersownerEmail.Text;
			ObjOrgSupplier.StateId = Convert.ToInt32(ddlSuppliersProvince.SelectedValue);
			ObjOrgSupplier.SupplierID = 0;

			ObjOrg.objSupplier = ObjOrgSupplier;

			OrganizationInfo.Client objOrgClient = new OrganizationInfo.Client();

			objOrgClient.BussinessPhone = txtClientBusinessPhone1.Text.Trim() + "-" + txtClientBusinessPhone2.Text.Trim() + "-" + txtClientBusinessPhone3.Text.Trim();
			objOrgClient.City = txtClientCity.Text;
			objOrgClient.ClientID = 0;
			objOrgClient.CompanyName = txtclientsCompanyName.Text;
			objOrgClient.ContactName = txtclientsContactName.Text;
			objOrgClient.CountryID = int.Parse(ddlclientsCountry.SelectedValue);
			objOrgClient.DateCreated = DateTime.Now;
			objOrgClient.IsActive = true;
			objOrgClient.LanguageId = LanguageId;
			objOrgClient.OwnerManagerEmail = txtclientsEmail.Text;
			objOrgClient.StateId = Convert.ToInt32(ddlclientsProvince.SelectedValue);

			ObjOrg.objClient = objOrgClient;

			ObjOrg.ObjOrgBusiness = new List<OrganizationInfo.Organization_Business>();

			//OrganizationInfo.Organization_Business objOrgBusiness;

			//foreach (RepeaterItem rptItem in rptBusiness.Items)
			//{
			//    objOrgBusiness = new OrganizationInfo.Organization_Business();

			//    CheckBox chkY = (CheckBox)rptItem.FindControl("chkY");
			//    CheckBox chkN = (CheckBox)rptItem.FindControl("chkN");

			//    if (chkY.Checked || chkN.Checked)
			//    {
			//        objOrgBusiness.BusinessID = Convert.ToInt32(((HiddenField)rptItem.FindControl("hdnID")).Value);
			//        objOrgBusiness.IsNew = chkY.Checked;

			//        ObjOrg.ObjOrgBusiness.Add(objOrgBusiness);

			//    }
			//}

			ObjOrg.CertificationID = new List<int>();

			foreach (RepeaterItem rptItem in rptStakeCertificates.Items)
			{
				if (((CheckBox)rptItem.FindControl("chk")).Checked)
				{
					ObjOrg.CertificationID.Add(Convert.ToInt32(((HiddenField)rptItem.FindControl("hdnID")).Value));
				}
			}

			foreach (RepeaterItem rptItem in rptTireCertificates.Items)
			{
				if (((CheckBox)rptItem.FindControl("chk")).Checked)
				{
					ObjOrg.CertificationID.Add(Convert.ToInt32(((HiddenField)rptItem.FindControl("hdnID")).Value));
				}
			}

			ObjOrg.InsertOrganizationInfo();
		}

		private void LoadInfo(int OrganizationID)
		{
			OrganizationInfo ObjOrg = new OrganizationInfo(OrganizationID);

			txtBusinessLegalName.Text = ObjOrg.LegalName;
			txtDBAName.Text = ObjOrg.DBAName;
			txtBusinessAddress1.Text = ObjOrg.Address;
			ddlBusinessProvince.SelectedValue = Convert.ToString(ObjOrg.StateID);
			ddlBusinessCountry.SelectedValue = Convert.ToString(ObjOrg.CountryID);
			txtBusinessZipCode.Text = ObjOrg.ZipPostalCode;
			txtMailingAddress1.Text = ObjOrg.BillMailAddress;
			txtPrimaryContactFirstName.Text = ObjOrg.OwnerManager;
			//txtbillingContact.Text = ObjOrg.BillingContact;

			//ddlownertitle.SelectedValue = "";
			//ddlbillingContact1.SelectedValue = "";
			//txtBusinessNumber1.Text = "";
			//txtBusinessNumber2.Text = "";
			//txtBusinessNumber3.Text = "";

			if (ObjOrg.objSupplier != null)
			{
				txtSupplierCompanyName.Text = ObjOrg.objSupplier.CompanyName;
				ddlSuppliersCountry.SelectedValue = Convert.ToString(ObjOrg.objSupplier.CountryID);
				ddlSuppliersProvince.SelectedValue = Convert.ToString(ObjOrg.objSupplier.StateId);
				txtClientCity.Text = ObjOrg.objSupplier.City;
				txtSupplierscontactName.Text = ObjOrg.objSupplier.ContactName;

				txtSupplierBusinessPhone1.Text = ObjOrg.objSupplier.BussinessPhone.Split('-')[0];
				txtSupplierBusinessPhone2.Text = ObjOrg.objSupplier.BussinessPhone.Split('-')[1];
				txtSupplierBusinessPhone3.Text = ObjOrg.objSupplier.BussinessPhone.Split('-')[2];
				txtSuppliersownerEmail.Text = ObjOrg.objSupplier.OwnerManagerEmail;
			}

			if (ObjOrg.objClient != null)
			{
				txtclientsCompanyName.Text = ObjOrg.objClient.CompanyName;
				ddlclientsCountry.SelectedValue = Convert.ToString(ObjOrg.objClient.CountryID);
				ddlclientsProvince.SelectedValue = Convert.ToString(ObjOrg.objClient.StateId);
				txtClientCity.Text = Convert.ToString(ObjOrg.objClient.City);
				txtclientsContactName.Text = ObjOrg.objClient.ContactName;
				txtClientBusinessPhone1.Text = ObjOrg.objClient.BussinessPhone.Split('-')[0];
				txtClientBusinessPhone2.Text = ObjOrg.objClient.BussinessPhone.Split('-')[1];
				txtClientBusinessPhone3.Text = ObjOrg.objClient.BussinessPhone.Split('-')[2];
				txtclientsEmail.Text = ObjOrg.objClient.OwnerManagerEmail;
			}

			chkotsPrivacy.Checked = true;
			chktiretraxPrivacy.Checked = true;

			foreach (int item in ObjOrg.CertificationID)
			{
				foreach (RepeaterItem rptItem in rptStakeCertificates.Items)
				{
					if (item == Convert.ToInt32(((HiddenField)rptItem.FindControl("hdnID")).Value))
					{
						((CheckBox)rptItem.FindControl("chk")).Checked = true;
					}
				}
			}

			foreach (int item in ObjOrg.CertificationID)
			{
				foreach (RepeaterItem rptItem in rptTireCertificates.Items)
				{
					if (item == Convert.ToInt32(((HiddenField)rptItem.FindControl("hdnID")).Value))
					{
						((CheckBox)rptItem.FindControl("chk")).Checked = true;
					}
				}
			}

			//foreach (OrganizationInfo.Organization_Business item in ObjOrg.ObjOrgBusiness)
			//{
			//    foreach (RepeaterItem rptItem in rptBusiness.Items)
			//    {
			//        if (item.BusinessID == Convert.ToInt32(((HiddenField)rptItem.FindControl("hdnID")).Value))
			//        {
			//            if (item.IsNew)
			//                ((CheckBox)rptItem.FindControl("chkY")).Checked = true;
			//            else
			//                ((CheckBox)rptItem.FindControl("chkN")).Checked = true;
			//        }
			//    }
			//}
		}
		*/
    #endregion

    #region AddBasicInfo

    protected void lnkbtnStep1_Click(object sender, EventArgs e)
    {
        try
        {
            string standardstewardshipIds = System.Configuration.ConfigurationManager.AppSettings["StewardshipStandardIDs"];
            string[] arr = standardstewardshipIds.Split(',');
            for (int i = 0; i < arr.Count(); i++)
            {

                if (ddlOrganizationType.SelectedValue == arr[i]) //LookupsManagement.LookupType.OrganizationTypes_Stewardship
                {
                    if (OrganizationInfo.CheckStateAvailableForStewarship(Conversion.ParseInt(ddlBusinessProvince.SelectedValue)) > 0)
                    {
                        lblStewardshipExists.Visible = true;
                        return;
                    }
                }
            }
            int organizationIdWithSimilerEmail = 0;
            organizationIdWithSimilerEmail = OrganizationInfo.getOrganizationIdByEmail(txtPrimaryContactEmail.Text.Trim(), Conversion.ParseInt(ddlBusinessProvince.SelectedValue));
            if (organizationIdWithSimilerEmail > 0)
            {
                lblemailalreadyexists.Text = ResourceMgr.GetError("Email already exists for this state. Choose another");
                lblemailalreadyexists.Visible = true;
                return;
            }
            else
            {
                lblemailalreadyexists.Visible = false;
            }
            OrganizationInfo objOrg = new OrganizationInfo();

            if (Utils.IsNumeric(hdnOrganizationID.Value) == true)
                objOrg.OrganizationId = Convert.ToInt32(hdnOrganizationID.Value);
            else
                objOrg.OrganizationId = -1;

            objOrg.LegalName = txtBusinessLegalName.Text.Trim();
            objOrg.DBAName = txtDBAName.Text.Trim();
            objOrg.OrganizationTypeId = Convert.ToInt32(ddlOrganizationType.SelectedValue);
            ViewState["OrganizationTypeId"] = objOrg.OrganizationTypeId.ToString();
            objOrg.OrganizationSubTypeID = Convert.ToInt32(ddlOrganizationSubType.SelectedValue);
            //string SubIDs = "";
            //foreach (ListItem item in ddlOrganizationSubType.Items)
            //{
            //    if (item.Selected)
            //    {
            //        SubIDs += item.Value + ",";
            //    }
            //}

            //SubIDs = SubIDs.TrimEnd(',');
            ViewState["OrganizationSubTypeId"] = objOrg.OrganizationSubTypeID.ToString();

            objOrg.Website = txtBusinessWebsite.Text.Trim();

            objOrg.AccountingInterfaceId = Convert.ToInt32(ddlBusinessAccountingInterface.SelectedValue);
            objOrg.InventoryInterfaceId = Convert.ToInt32(ddlBusinessInventoryInterface.SelectedValue);
            objOrg.IsAutoFundTransfer = chkBusinessAcceptAutoFundTransfers.Checked;
            objOrg.IsActive = true;
            objOrg.IsOrganization = true;
            objOrg.LanguageId = LanguageId;

            int RoleId = Convert.ToInt32(UserInfo.UserRole.Stakeholder);

            if (Convert.ToInt32(ddlOrganizationType.SelectedValue) == Convert.ToInt32(LookupsManagement.LookupType.OrganizationTypes_Stewardship) ||
                Convert.ToInt32(ddlOrganizationType.SelectedValue) == Convert.ToInt32(LookupsManagement.LookupType.OrganizationTypes_GlobalSteward) ||
                Convert.ToInt32(ddlOrganizationType.SelectedValue) == Convert.ToInt32(LookupsManagement.LookupType.OrganizationTypes_LocalSteward)
                )
            {
                RoleId = Convert.ToInt32(UserInfo.UserRole.Stewardship);
            }

            objOrg.RoleId = RoleId;

            ContactInfo objPrimaryContact = new ContactInfo();

            objPrimaryContact.FirstName = txtPrimaryContactFirstName.Text.Trim();
            objPrimaryContact.LastName = txtPrimaryContactLastName.Text.Trim();
            objPrimaryContact.ContactTitleId = Convert.ToInt32(ddlPrimaryContactTitle.SelectedValue);
            objPrimaryContact.Email = txtPrimaryContactEmail.Text.Trim();
            ViewState["PrimaryEmail"] = txtPrimaryContactEmail.Text.Trim();
            objPrimaryContact.IsActive = true;
            objPrimaryContact.IsPrimary = true;
            objPrimaryContact.LanguageId = LanguageId;
            //objPrimaryContact.ContactTypeId = Convert.ToInt32(ContactInfo.ContactTypes.Business);
            objPrimaryContact.ContactTypeId = Convert.ToInt32(LookupsManagement.LookupType.ContactTypes_Business);

            Phones objPrimaryContactBusinessPhone = new Phones();

            objPrimaryContactBusinessPhone.Number = txtPrimaryContactBusinessPhone1.Text.Trim() + "-" + txtPrimaryContactBusinessPhone2.Text.Trim() + "-" + txtPrimaryContactBusinessPhone3.Text.Trim();
            objPrimaryContactBusinessPhone.Extension = txtPrimaryContactBusinessPhoneExtension.Text.Trim();
            objPrimaryContactBusinessPhone.IsActive = true;
            //objPrimaryContactBusinessPhone.PhoneTypeId = Convert.ToInt32(Phones.PhoneType.Business);
            objPrimaryContactBusinessPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Business);

            Phones objPrimaryContactCellPhone = new Phones();

            objPrimaryContactCellPhone.Number = txtPrimaryContactCellPhone1.Text.Trim() + "-" + txtPrimaryContactCellPhone2.Text.Trim() + "-" + txtPrimaryContactCellPhone3.Text.Trim();
            objPrimaryContactCellPhone.IsAcceptTextMessages = chkPrimaryContactAcceptTextMessages.Checked;
            objPrimaryContactCellPhone.IsActive = true;
            //objPrimaryContactCellPhone.PhoneTypeId = Convert.ToInt32(Phones.PhoneType.Cell);
            objPrimaryContactCellPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Cell);

            ContactInfo objBillingContact = new ContactInfo();

            objBillingContact.FirstName = txtBillingContactFirstName.Text.Trim();
            objBillingContact.LastName = txtBillingContactLastName.Text.Trim();
            objBillingContact.ContactTitleId = Convert.ToInt32(ddlBillingContactTitle.SelectedValue);
            objBillingContact.Email = txtBillingContactEmail.Text.Trim();
            objBillingContact.IsActive = true;
            objBillingContact.IsPrimary = false;
            objBillingContact.LanguageId = LanguageId;
            //objBillingContact.ContactTypeId = Convert.ToInt32(ContactInfo.ContactTypes.Billing);
            objBillingContact.ContactTypeId = Convert.ToInt32(LookupsManagement.LookupType.ContactTypes_Billing);

            Phones objBillingContactBusinessPhone = new Phones();

            objBillingContactBusinessPhone.Number = txtBillingContactPhoneNumber1.Text.Trim() + "-" + txtBillingContactPhoneNumber2.Text.Trim() + "-" + txtBillingContactPhoneNumber3.Text.Trim();
            objBillingContactBusinessPhone.Extension = txtBillingContactPhoneExtension.Text.Trim();
            objBillingContactBusinessPhone.IsActive = true;
            //objBillingContactBusinessPhone.PhoneTypeId = Convert.ToInt32(Phones.PhoneType.Business);
            objBillingContactBusinessPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Business);

            Phones objBillingContactCellPhone = new Phones();

            objBillingContactCellPhone.Number = txtBillingContactCellNumber1.Text.Trim() + "-" + txtBillingContactCellNumber2.Text.Trim() + "-" + txtBillingContactCellNumber3.Text.Trim();
            objBillingContactCellPhone.IsAcceptTextMessages = chkBillingContactAcceptTextMessages.Checked;
            objBillingContactCellPhone.IsActive = true;
            //objBillingContactCellPhone.PhoneTypeId = Convert.ToInt32(Phones.PhoneType.Cell);
            objBillingContactCellPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Cell);

            OrganizationInfo.Organization_Address objBusinessOrganization_Address = new OrganizationInfo.Organization_Address();

            objBusinessOrganization_Address.ZipCodeID = Convert.ToInt32(hdnBusinessZipCodeId.Value);
            objBusinessOrganization_Address.ZipPostalCode = txtBusinessZipCode.Text.Trim();
            objBusinessOrganization_Address.Address1 = txtBusinessAddress1.Text.Trim();
            objBusinessOrganization_Address.Address2 = txtBusinessAddress2.Text.Trim();
            objBusinessOrganization_Address.City = txtBuinessCity.Text;
            objBusinessOrganization_Address.CityId = Convert.ToDouble(hfCityId.Value);
            objBusinessOrganization_Address.StateID = Convert.ToInt32(ddlBusinessProvince.SelectedValue);
            objBusinessOrganization_Address.CountryID = Convert.ToInt32(ddlBusinessCountry.SelectedValue);
            objBusinessOrganization_Address.DateCreated = DateTime.Now;
            objBusinessOrganization_Address.IsActive = true;
            //objBusinessOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(OrganizationInfo.Organization_Address.Organization_AddressType.Business);
            objBusinessOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(LookupsManagement.LookupType.OrganizationAddressType_Business);

            OrganizationInfo.Organization_Address objMailingOrganization_Address = new OrganizationInfo.Organization_Address();

            objMailingOrganization_Address.ZipCodeID = Convert.ToInt32(hdnMailingZipCodeId.Value);
            objMailingOrganization_Address.ZipPostalCode = txtMailingZipCode.Text.Trim();
            objMailingOrganization_Address.Address1 = txtMailingAddress1.Text.Trim();
            objMailingOrganization_Address.Address2 = txtMailingAddress2.Text.Trim();
            objMailingOrganization_Address.City = txtMailingCity.Text;
            objMailingOrganization_Address.CityId = Convert.ToDouble(hfmailingCityId.Value);
            objMailingOrganization_Address.StateID = Convert.ToInt32(ddlMailingState.SelectedValue);
            objMailingOrganization_Address.CountryID = Convert.ToInt32(ddlMailingCountry.SelectedValue);
            objMailingOrganization_Address.DateCreated = DateTime.Now;
            objMailingOrganization_Address.IsActive = true;
            //objMailingOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(OrganizationInfo.Organization_Address.Organization_AddressType.Mailing);
            objMailingOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(LookupsManagement.LookupType.OrganizationAddressType_Mailing);

            string catIDs = "";
            foreach (ListItem item in chkProductId.Items)
            {
                if (item.Selected)
                {
                    catIDs += item.Value + ",";
                }
            }

            catIDs = catIDs.TrimEnd(',');

            OrganizationInfo.SavePrimaryInfo(objOrg, objPrimaryContact, objPrimaryContactBusinessPhone, objPrimaryContactCellPhone, objBillingContact, objBillingContactBusinessPhone, objBillingContactCellPhone, objBusinessOrganization_Address, objMailingOrganization_Address, catIDs);


            
            foreach (ListItem item in chkProductId.Items)
            {
                DataSet Check = Product.GetAllSubCategories(Convert.ToInt32(item.Value));
                if (Check != null && Check.Tables[0].Rows.Count > 0 && item.Selected)
                {
                    string SubIds = "";
                    foreach(DataRow row in Check.Tables[0].Rows)
                    {
                        SubIds += row["SubProductId"] + ",";
                    }
                    SubIds = SubIds.TrimEnd(',');
                    Product.InsertProductTypes(Convert.ToInt32(objOrg.OrganizationId), Convert.ToInt32(item.Value), SubIds);
                }
            }

            hdnOrganizationID.Value = Convert.ToString(objOrg.OrganizationId);
            int organizationtypeid = Convert.ToInt32(ddlOrganizationType.SelectedItem.Value);
            // OrganizationInfo.SetStatus(OrganizationStatus.Pending, objOrg.OrganizationId, "Registered", organizationtypeid);
            // Utils.GetLookUpData<DropDownList>(ref ddlRoleList, LookUps.RoleName, Conversion.ParseInt(ddlOrganizationType.SelectedValue));

            if (objOrg.OrganizationId > 0)
            {
                //if (Page.IsValid)
                //{
                //    string keyfor = ddlOrganizationType.SelectedItem.Text.Trim();
                //    string tabName = "";

                //    switch (keyfor)
                //    {
                //        case "Consumer":
                //            tabName = "tab-7";
                //            break;
                //        default:
                //            break;
                //    }

                //    ToolkitScriptManager.RegisterStartupScript(this, this.GetType(), "Step2", String.Format("GotoNextStep('{2}');SetHiddenFieldValue('{0}','{1}');", hdnOrganizationID.ClientID, objOrg.OrganizationId,tabName), true);
                //}

            }



            //Utils.GetLookUpData<DropDownList>(ref ddlRoleList, LookUps.RoleTypes, Conversion.ParseInt(ddlOrganizationType.SelectedValue));//Role Types by organizationTypeId

        }
        catch (Exception ex)
        {
            new SqlLog().InsertSqlLog(0, "RegistrationForm.lnkbtnStep1_Click", ex);
        }
    }
    protected void lnkbtnUpdate_Click(object sender, EventArgs e)
    {
       // int stateId = OrganizationInfo.getStateId(OrganizationID);
       //int  organizationIdWithSimilerEmail = OrganizationInfo.getOrganizationIdByEmail(txtPrimaryEmail.Text.Trim(), stateId);
       //if (organizationIdWithSimilerEmail > 0)
       //{
       //    lblemailalreadyexists.Text = "Email already exists for this state. Choose another";
       //    lblemailalreadyexists.Visible = true;
       //    return;
       //}
        DataTable dt = null;
        double stateId = OrganizationInfo.getStateId(OrganizationID);
        dt = OrganizationInfo.GetCityStateAndCountryByZipCode(txtZipCode.Text.Trim(), GlobalCountryID, stateId);

        if (dt.Rows.Count > 0)
        {
           
        }
        else
        {
            txtZipCode.Text = "";
            txtZipCode.Focus();
            lblBusinessZipCode.Text = "* Zipcode does not exist in this state.";
            return;
        }
        OrganizationInfo objOrg = new OrganizationInfo(OrganizationID);
        if (dddlcelltextmsgs.SelectedValue == "1")
            objOrg.CellAcceptTextMessages = true;
        else
            objOrg.CellAcceptTextMessages = false;
        if (ddlbusinesstextmsgs.SelectedValue == "1")
            objOrg.AcceptTextMessages = true;
        else
            objOrg.AcceptTextMessages = false;
        objOrg.OrganizationId = OrganizationID;
   //     objOrg.Fax = txtFax.Text.Trim();
 //       objOrg.Address = txtAddress.Text.Trim();
      //  objOrg.BusinessType = txtBusinessType.Text.Trim();
 //       objOrg.BillMailAddress = txtBillingMailAddress.Text.Trim();
  //      objOrg.BillingContact = txtBillingContact.Text.Trim();
 //       objOrg.CellExtension = txtCellPhoneExtension.Text.Trim();
        objOrg.LegalName = txtBusinessName.Text.Trim();
        objOrg.DBAName = txtDBAName.Text.Trim();
        objOrg.Website = txtWebsite.Text.Trim();
        objOrg.IsActive = true;
        objOrg.IsOrganization = true;
        objOrg.LanguageId =LanguageId;
        objOrg.ContactTitleName = txtContactTitle.Text.Trim();
        objOrg.RoleId = Conversion.ParseInt(UserInfo.UserRole.Stewardship);
        objOrg.UpdateOrganizationInfo();
        ContactInfo objPrimaryContact = new ContactInfo();

        objPrimaryContact.FirstName = txtFirstName.Text.Trim();
        objPrimaryContact.LastName = txtLastName.Text.Trim();
        objPrimaryContact.Email = txtPrimaryEmail.Text.Trim();
        
        objPrimaryContact.IsActive = true;
        objPrimaryContact.IsPrimary = true;
        objPrimaryContact.LanguageId = LanguageId;
        objPrimaryContact.ContactTypeId = Convert.ToInt32(LookupsManagement.LookupType.ContactTypes_Business);
        
        Phones objPrimaryContactBusinessPhone = new Phones();

        objPrimaryContactBusinessPhone.Number =txtPhoneNumber.Text.Trim().ToString();
        objPrimaryContactBusinessPhone.Extension = txtPhoneExtension.Text.Trim().ToString();
        objPrimaryContactBusinessPhone.IsActive = true;
        objPrimaryContactBusinessPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Business);

        Phones objPrimaryContactCellPhone = new Phones();

        objPrimaryContactCellPhone.Number = txtCellPhoneNumber.Text.Trim();
        objPrimaryContactCellPhone.IsActive = true;
        objPrimaryContactCellPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Cell);

        ContactInfo objBillingContact = new ContactInfo();
   //      objBillingContact.Email = txtBillingMailAddress.Text.Trim();
        objBillingContact.IsActive = true;
        objBillingContact.IsPrimary = false;
        objBillingContact.LanguageId = LanguageId;
        objBillingContact.ContactTypeId = Convert.ToInt32(ContactInfo.ContactTypes.Billing);
        objBillingContact.ContactTypeId = Convert.ToInt32(LookupsManagement.LookupType.ContactTypes_Billing);

        Phones objBillingContactBusinessPhone = new Phones();
        objBillingContactBusinessPhone.IsActive = true;
        objBillingContactBusinessPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Business);

        Phones objBillingContactCellPhone = new Phones();

        objBillingContactCellPhone.IsActive = true;
        objBillingContactCellPhone.PhoneTypeId = Convert.ToInt32(LookupsManagement.LookupType.PhoneType_Cell);

        OrganizationInfo.Organization_Address objBusinessOrganization_Address = new OrganizationInfo.Organization_Address();

        objBusinessOrganization_Address.ZipCodeID = Convert.ToInt32(hdnBusinessZipCodeId.Value);
        objBusinessOrganization_Address.ZipPostalCode = txtZipCode.Text.Trim().ToString();
        objBusinessOrganization_Address.Address1 = txtBusinessAddress1.Text.Trim();
        objBusinessOrganization_Address.Address2 = txtBusinessAddress2.Text.Trim();
       objBusinessOrganization_Address.City = txtCity.Text.Trim().ToString();
        objBusinessOrganization_Address.StateID = Convert.ToInt32(ddlState.SelectedValue);
        objBusinessOrganization_Address.CountryID = Convert.ToInt32(ddlCountry.SelectedValue);
        objBusinessOrganization_Address.DateCreated = DateTime.Now;
        objBusinessOrganization_Address.IsActive = true;
        objBusinessOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(LookupsManagement.LookupType.OrganizationAddressType_Business);

        OrganizationInfo.Organization_Address objMailingOrganization_Address = new OrganizationInfo.Organization_Address();
        objMailingOrganization_Address.DateCreated = DateTime.Now;
        objMailingOrganization_Address.IsActive = true;
        objMailingOrganization_Address.Organization_AddressTypeId = Convert.ToInt32(LookupsManagement.LookupType.OrganizationAddressType_Mailing);

        OrganizationInfo.UpdateStewardshipInfo(objOrg, objPrimaryContact, objPrimaryContactBusinessPhone, objPrimaryContactCellPhone, objBillingContact, objBillingContactBusinessPhone, objBillingContactCellPhone, objBusinessOrganization_Address, objMailingOrganization_Address);
        lblinfo.Visible = true;
        lblinfo.Text = "Successfully updated";
        viewStakeholdersForApproval();
        pnlDisplay.Visible = true;
        pnlEdit.Visible = false;

    }