//public NSLayoutConstraint LocationPickerWidthConstraintProperty
        //{
        //	get
        //	{
        //		return LocationPickerWidthConstraint;
        //	}
        //}

        //public NSLayoutConstraint MapCCodePickerWidthConstraintProperty
        //{
        //	get
        //	{
        //		return MapCCodePickerWidthConstraint;
        //	}
        //}



        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);
            StepActivated?.Invoke(this, new MultiStepProcessStepEventArgs {
                Index = StepIndex
            });


            if (!Settings.AnyClassificationChosen())
            {
                var alert = UIAlertController.Create("Please Choose a Classification", "A minimum of one classification is required.", UIAlertControllerStyle.Alert);

                alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                {
                    RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;
                    var finalStep = registrationVC.Steps.FirstOrDefault();
                    registrationVC._pageViewController.SetViewControllers(new[] { finalStep as UIViewController }, UIPageViewControllerNavigationDirection.Reverse, true, (finished) =>
                    {
                        if (finished)
                        {
                            //finalStep.StepActivated(this, new MultiStepProcessStepEventArgs());
                        }
                    });
                }));
                //alert.AddAction(UIAlertAction.Create("Snooze", UIAlertActionStyle.Default, action => Snooze()));
                //if (alert.PopoverPresentationController != null)
                //	alert.PopoverPresentationController.BarButtonItem = myItem;
                PresentViewController(alert, animated: true, completionHandler: () =>
                {
                });
            }
        }
        partial void UIButton27947_TouchUpInside(UIButton sender)
        {
            Settings.IsRegistered = true;

            RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;

            var loginVC = registrationVC.PresentingViewController as LoginViewController;

            //if loginVS is null, than started registration from the GlobalAir Magazine navigation controller or tabbarcontroller main home view
            if (loginVC == null)
            {
                //presenting viewcontroller will be tabbarcontroller if did registration from tab nav controller
                var tabBarController = registrationVC.PresentingViewController as UITabBarController;
                if (tabBarController != null)
                {
                    registrationVC.DismissViewController(true, null);
                    //MagazineViewController myMagazineVC = this.Storyboard.InstantiateViewController("MagazineViewController") as MagazineViewController;
                    var viewController = tabBarController.ViewControllers.FirstOrDefault(row => row is MagazineViewController);
                    tabBarController.SelectedViewController = viewController;
                }
                else
                {
                    //if wasn't registering from login page or tabbarviewcontroller than registered from the Globalair magazinae nav controller
                    registrationVC.NavigationController.PopViewController(true);
                }
            }
            else
            {
                registrationVC.DismissViewController(true, null);
                loginVC.PerformSegue("MagazineSegue", loginVC);
            }
        }
        void NextButton_TouchUpInside(object sender, EventArgs e)
        {
            RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;
            var stepFour = registrationVC.Steps[3];

            registrationVC._pageViewController.SetViewControllers(new[] { stepFour as UIViewController }, UIPageViewControllerNavigationDirection.Forward, true, (finished) =>
            {
                if (finished)
                {
                    //finalStep.StepActivated(this, new MultiStepProcessStepEventArgs());
                }
            });
        }
        async void CompleteRegistrationButton_TouchUpInside(object sender, EventArgs e)
        {
            if (Reachability.IsHostReachable(Settings._baseDomain))
            {
                LoadingOverlay loadingIndicator = new LoadingOverlay(this.View.Frame, "Loading ...");
                this.View.AddSubview(loadingIndicator);
                //Attempt to register in the API
                var response = await MagAppRegisterResponse.RegisterAsync();

                if (response.Status == "Success")
                {
                    Settings.IsRegistered = true;

                    var alert = UIAlertController.Create("Congratulations!", "You have successfully registered.", UIAlertControllerStyle.Alert);

                    alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                    {
                    }));

                    PresentViewController(alert, animated: true, completionHandler: () =>
                    {
                        RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;

                        var loginVC = registrationVC.PresentingViewController as LoginViewController;
                        registrationVC.DismissViewController(true, null);
                        if (loginVC != null)
                        {
                            loginVC.PerformSegue("LoadTabBarControllerSeque", loginVC);
                        }
                    });
                }
                else
                {
                    loadingIndicator.Hide();
                    HelperMethods.SendBasicAlert("Oops.", "There was a problem registering. Please try again.");
                }
            }
            else
            {
                HelperMethods.SendBasicAlert("Please connect to the internet", "Internet access is required.");
            }
        }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);



            StepActivated?.Invoke(this, new MultiStepProcessStepEventArgs {
                Index = StepIndex
            });


            if (!Settings.AnyClassificationChosen())
            {
                var alert = UIAlertController.Create("Please Choose a Classification", "A minimum of one classification is required.", UIAlertControllerStyle.Alert);

                alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                {
                    RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;
                    var firstStep = registrationVC.Steps.FirstOrDefault();
                    registrationVC._pageViewController.SetViewControllers(new[] { firstStep as UIViewController }, UIPageViewControllerNavigationDirection.Reverse, true, (finished) =>
                    {
                        if (finished)
                        {
                            //finalStep.StepActivated(this, new MultiStepProcessStepEventArgs());
                        }
                    });
                }));

                PresentViewController(alert, animated: true, completionHandler: () =>
                {
                });
            }

            //(UIKeyboard.WillHideNotification, KeyBoardDownNotification);



            //Register for events
            View.AddGestureRecognizer(HideKeyboardGesture);
            NextButton.TouchUpInside           += NextButton_TouchUpInside;
            EmailTextField.EditingDidEnd       += EmailTextField_EditingDidEnd;
            PasswordTextField.EditingDidEnd    += PasswordTextField_EditingDidEnd;
            FirstNameTextField.EditingDidEnd   += FirstNameTextField_EditingDidEnd;
            LastNameTextField.EditingDidEnd    += LastNameTextField_EditingDidEnd;
            HomeAirportTextField.EditingDidEnd += HomeAirportTextField_EditingDidEnd;
            CompanyTextField.EditingDidEnd     += CompanyTextField_EditingDidEnd;
            PhoneTextField.EditingDidEnd       += PhoneTextField_EditingDidEnd;

            EmailTextField.AttributedPlaceholder = new NSAttributedString(
                "EMAIL (Username)",
                font: EmailTextField.Font,
                foregroundColor: UIColor.White
                );
            PasswordTextField.AttributedPlaceholder = new NSAttributedString(
                "PASSWORD",
                font: PasswordTextField.Font,
                foregroundColor: UIColor.White
                );

            ReEmailTextField.AttributedPlaceholder = new NSAttributedString(
                "RE-ENTER EMAIL",
                font: ReEmailTextField.Font,
                foregroundColor: UIColor.White
                );
            RePasswordTextField.AttributedPlaceholder = new NSAttributedString(
                "RE-ENTER PASSWORD",
                font: RePasswordTextField.Font,
                foregroundColor: UIColor.White
                );

            FirstNameTextField.AttributedPlaceholder = new NSAttributedString(
                "FIRST NAME",
                font: FirstNameTextField.Font,
                foregroundColor: UIColor.White
                );
            LastNameTextField.AttributedPlaceholder = new NSAttributedString(
                "LAST NAME",
                font: LastNameTextField.Font,
                foregroundColor: UIColor.White
                );
            HomeAirportTextField.AttributedPlaceholder = new NSAttributedString(
                "HOME AIRPORT (Optional)",
                font: HomeAirportTextField.Font,
                foregroundColor: UIColor.White
                );
            CompanyTextField.AttributedPlaceholder = new NSAttributedString(
                "COMPANY (Optional)",
                font: CompanyTextField.Font,
                foregroundColor: UIColor.White
                );
            PhoneTextField.AttributedPlaceholder = new NSAttributedString(
                "MOBILE PHONE",
                font: PhoneTextField.Font,
                foregroundColor: UIColor.White
                );
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            UIImageView background = new UIImageView();

//assign our image file to the UIImageView
            background.Image = UIImage.FromBundle("new_home_bg1");

            //assign the UIImageView as the background view of the table
            this.TableView.BackgroundView = background;

            //set the textbox background to light gray
            this.TableView.BackgroundColor = UIColor.LightGray;

            //set the background of each table cell to clear
            foreach (var cell in this.TableView.VisibleCells)
            {
                cell.BackgroundColor = UIColor.Clear;
                cell.SelectionStyle  = UITableViewCellSelectionStyle.None;
            }

            var statusBarHeight = UIApplication.SharedApplication.StatusBarFrame.Height;

            MultiStepProcessHorizontalViewController parentViewController = this.ParentViewController as MultiStepProcessHorizontalViewController;
            var navigationController = parentViewController.ContainerViewController.NavigationController;
            var navBarHeight         = navigationController.NavigationBar.Bounds.Height;

            TableView.ContentInset = new UIEdgeInsets(statusBarHeight + navBarHeight, 0, 50, 0);

            MapCCodeList         = new List <Location>();
            LocationList         = new List <Location>();
            provinceList         = new List <Location>();
            stateList            = new List <Location>();
            FilteredLocationList = new List <Location>();
            SelectedMapCCode     = new Location();
            SelectedLocation     = new Location();

            LocationsPickerViewProperty.Alpha = 0f;
            //LocationPickerWidthConstraintProperty.Constant = 0f;
            //if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone)
            //{
            //	MapCCodePickerWidthConstraint.Constant = 80f;
            //}
            //else {
            //	MapCCodePickerWidthConstraint.Constant = 150f;
            //}

            //Load values if already registered
            if (Settings.IsRegistered)
            {
                EmailTextField.Text       = Settings.Email;
                PasswordTextField.Text    = Settings.Password;
                FirstNameTextField.Text   = Settings.FirstName;
                LastNameTextField.Text    = Settings.LastName;
                PhoneTextField.Text       = Settings.Phone;
                CompanyTextField.Text     = Settings.Company;
                HomeAirportTextField.Text = Settings.HomeAirport;
            }

            //hide keyboard when touch anywhere
            HideKeyboardGesture = new UITapGestureRecognizer(() =>
            {
                View.EndEditing(true);
            });

            Task.Run(async() =>
            {
                LocationResponse location = new LocationResponse();
                if (Reachability.IsHostReachable(Settings._baseDomain))
                {
                    location = await LocationResponse.GetLocations();
                    if (location.Status != "Success")
                    {
                        InvokeOnMainThread(() =>
                        {
                            var alert = UIAlertController.Create("There was a problem loading registration data", "Please try again.", UIAlertControllerStyle.Alert);

                            alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                            {
                                RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;
                                //var firstStep = registrationVC.Steps.FirstOrDefault();
                                //registrationVC._pageViewController.SetViewControllers(new[] { firstStep as UIViewController }, UIPageViewControllerNavigationDirection.Reverse, true, (finished) =>
                                //{
                                //	if (finished)
                                //	{
                                //		//finalStep.StepActivated(this, new MultiStepProcessStepEventArgs());

                                //	}
                                //});
                                registrationVC.DismissViewController(true, null);
                            }));

                            PresentViewController(alert, animated: true, completionHandler: () =>
                            {
                            });
                        });
                    }
                    else
                    {
                        //Save to settings file to use object during the rest of the registration process
                        Settings.LocationResponse = location;

                        var distinctMapCodes = location.Locations.Select(row => row.MapCCode).Distinct().ToList();
                        List <Location> filteredLocationListByFirstMapCode = new List <Location>();
                        foreach (var mapCode in distinctMapCodes)
                        {
                            Location loc = location.Locations.FirstOrDefault(row => row.MapCCode == mapCode);

                            if (loc != null)
                            {
                                if (loc.MapCCode == "WO")
                                {
                                    Location placeholderLocation     = new Location();
                                    placeholderLocation.LocationId   = loc.LocationId;
                                    placeholderLocation.LocName      = "World";
                                    placeholderLocation.Abbreviation = loc.Abbreviation;
                                    placeholderLocation.MapCCode     = loc.MapCCode;
                                    placeholderLocation.DisplayOrder = loc.DisplayOrder;
                                    filteredLocationListByFirstMapCode.Add(placeholderLocation);
                                }
                                else
                                {
                                    filteredLocationListByFirstMapCode.Add(loc);
                                }
                            }
                        }
                        MapCCodeList = filteredLocationListByFirstMapCode.OrderByDescending(row => row.DisplayOrder).ToList();

                        Location sleLocation     = new Location();
                        sleLocation.LocationId   = 0;
                        sleLocation.LocName      = "Select";
                        sleLocation.Abbreviation = "Select";
                        sleLocation.MapCCode     = "SE";
                        sleLocation.DisplayOrder = 0;
                        MapCCodeList.Insert(0, sleLocation);

                        LocationList         = location.Locations.OrderBy(row => row.DisplayOrder).ToList();
                        provinceList         = location.ProvinceLst.OrderBy(row => row.DisplayOrder).ToList();
                        stateList            = location.StatesLst.OrderBy(row => row.DisplayOrder).ToList();
                        FilteredLocationList = LocationList;

                        if (MapCCodeList.Count > 1 && Settings.LocationPickerSelectedId == 0)
                        {
                            //Assign value to registration objec
                            Settings.LocationPickerSelectedId = MapCCodeList[0].LocationId;
                        }

                        InvokeOnMainThread(() =>
                        {
                            MapCCodePicker.Model = new MapCCodeMod(this);
                            LocationPicker.Model = new LocationsMod(this);

                            if (Settings.IsRegistered)
                            {
                                var previouslSelectedLocation = MapCCodeList.FirstOrDefault(row => row.LocationId == Settings.LocationPickerSelectedId);

                                if (previouslSelectedLocation != null)
                                {
                                    int currentIndex = MapCCodeList.IndexOf(MapCCodeList.FirstOrDefault(row => row.LocationId == Settings.LocationPickerSelectedId));;
                                    MapCCodePicker.Select(currentIndex, 0, true);
                                }
                                else
                                {
                                    if (Settings.LocationPickerSelectedId != 0)
                                    {
                                        int locationId = Settings.LocationPickerSelectedId;
                                        int mapCIndex  = MapCCodeList.IndexOf(MapCCodeList.FirstOrDefault(row => row.LocationId == 0));
                                        MapCCodePicker.Select(mapCIndex, 0, true);
                                        MapCCodePicker.Model.Selected(MapCCodePicker, mapCIndex, 0);

                                        int locationCInddex = FilteredLocationList.IndexOf(FilteredLocationList.FirstOrDefault(row => row.LocationId == locationId));
                                        LocationPicker.Select(locationCInddex, 0, true);
                                        LocationPicker.Model.Selected(LocationPicker, locationCInddex, 0);
                                        //LocationPicker.Alpha = 1f;
                                    }
                                }
                            }
                            else
                            {
                                //MapCCodePicker.Model.Selected(MapCCodePicker, 0, 0);
                                MapCCodePicker.Select(0, 0, true);
                            }
                        });
                    }
                }
                else
                {
                    InvokeOnMainThread(() =>
                    {
                        var alert = UIAlertController.Create("Please connect to the internet", "Internet access is required.", UIAlertControllerStyle.Alert);

                        alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                        {
                            RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;
                            //var firstStep = registrationVC.Steps.FirstOrDefault();
                            //registrationVC._pageViewController.SetViewControllers(new[] { firstStep as UIViewController }, UIPageViewControllerNavigationDirection.Reverse, true, (finished) =>
                            //{
                            //	if (finished)
                            //	{
                            //		//finalStep.StepActivated(this, new MultiStepProcessStepEventArgs());

                            //	}
                            //});
                            registrationVC.DismissViewController(true, null);
                        }));

                        PresentViewController(alert, animated: true, completionHandler: () =>
                        {
                        });
                    });
                }
            });
        }
        partial void OnClick(UIButton sender)
        {
            EmailTextField.ResignFirstResponder();
            PasswordTextField.ResignFirstResponder();
            FirstNameTextField.ResignFirstResponder();
            LastNameTextField.ResignFirstResponder();

            //Ensure required fields are input
            if (Settings.Email == null || Settings.Email == string.Empty)
            {
                HelperMethods.SendBasicAlert("Validation", "Please input a valid email address");
                return;
            }
            if (Settings.Password == null || Settings.Password == string.Empty)
            {
                HelperMethods.SendBasicAlert("Validation", "Please input a valid password");
                return;
            }

            if (Settings.Email != ReEmailTextField.Text)
            {
                HelperMethods.SendBasicAlert("Validation", "Email doesn't match");
                return;
            }

            if (Settings.Password != RePasswordTextField.Text)
            {
                HelperMethods.SendBasicAlert("Validation", "Password doesn't match");
                return;
            }


            if (Settings.FirstName == null || Settings.FirstName == string.Empty)
            {
                HelperMethods.SendBasicAlert("Validation", "Please input your first name");
                return;
            }
            if (Settings.LastName == null || Settings.LastName == string.Empty)
            {
                HelperMethods.SendBasicAlert("Validation", "Please input your last name");
                return;
            }
            if (Settings.Phone == null || Settings.Phone == string.Empty)
            {
                HelperMethods.SendBasicAlert("Validation", "Please input your phone number");
                return;
            }

            if (Settings.LocationPickerSelectedId == 0)
            {
                HelperMethods.SendBasicAlert("Validation", "Please select your location");
                return;
            }

            RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;
            var stepThree = registrationVC.Steps[2];

            registrationVC._pageViewController.SetViewControllers(new[] { stepThree as UIViewController }, UIPageViewControllerNavigationDirection.Forward, true, (finished) =>
            {
                if (finished)
                {
                    //finalStep.StepActivated(this, new MultiStepProcessStepEventArgs());
                }
            });
            //throw new NotImplementedException();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            PageHeaderLabel.BackgroundColor = UIColor.Gray;

            SizeF size = new SizeF(320, UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? 600 : 800);

            ProfileScrollView.ContentSize = size;


            MapCCodeList         = new List <Location>();
            LocationList         = new List <Location>();
            provinceList         = new List <Location>();
            stateList            = new List <Location>();
            FilteredLocationList = new List <Location>();
            SelectedMapCCode     = new Location();
            SelectedLocation     = new Location();


            FirstNameTextField.AttributedPlaceholder = new NSAttributedString(
                "FIRST NAME",
                font: FirstNameTextField.Font,
                foregroundColor: UIColor.White
                );

            LastNameTextField.AttributedPlaceholder = new NSAttributedString(

                "LAST NAME",
                font: LastNameTextField.Font,
                foregroundColor: UIColor.White
                );

            MobilePhoneTextField.AttributedPlaceholder = new NSAttributedString(
                "MOBILE PHONE",
                font: MobilePhoneTextField.Font,
                foregroundColor: UIColor.White
                );



            CompanyTextField.AttributedPlaceholder = new NSAttributedString(
                "COMPANY",
                font: CompanyTextField.Font,
                foregroundColor: UIColor.White
                );


            FirstNameTextField.Text   = Settings.FirstName;
            MobilePhoneTextField.Text = Settings.Phone;
            LastNameTextField.Text    = Settings.LastName;
            //Task.Run(async () => {
            //	try
            //	{
            //		AuthResponse response1 = await AuthResponse.GetAuthResponseAsync(Settings.AppID, Settings.Username, Settings.Password);

            //		APIManager manager = new APIManager();

            //		var reponseProfile = await manager.getUserProfile(Settings.AppID, Settings.Username, response1.AuthToken, Settings.Password);


            //		InvokeOnMainThread(() =>
            //				{

            //					//CompanyTextField.Text = reponseProfile.Company;
            //				});

            //	}
            //	catch (Exception e) {

            //	}

            //});

            //ContainerViewWidthConstraint.Constant = View.Bounds.Width - 40;
            ContainerView.BackgroundColor = UIColor.Clear;
            ContainerView.Alpha           = .8f;

            //CGSize contentSize = new CGSize(View.Bounds.Width - 40, ContainerView.Bounds.Height);
            //ProfileScrollView.ContentSize = contentSize;
            //LocationResponseList = new List<LocationResponse>();


            MapCCodePickerView.Model = new MapCCodeModel(this);


            Task.Run(async() =>
            {
                try
                {
                    LocationResponse location = new LocationResponse();
                    if (Reachability.IsHostReachable(Settings._baseDomain))
                    {
                        location = await LocationResponse.GetLocations();
                        if (location.Equals(null))
                        {
                            return;
                        }
                        if (location.Status != "Success")
                        {
                            InvokeOnMainThread(() =>
                            {
                                var alert = UIAlertController.Create("There was a problem loading location data", "Please try again.", UIAlertControllerStyle.Alert);

                                alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                                {
                                    this.DismissViewController(true, null);
                                }));

                                PresentViewController(alert, animated: true, completionHandler: () =>
                                {
                                });
                            });
                        }
                        else
                        {
                            //Save to settings file to use object during the rest of the registration process
                            Settings.LocationResponse = location;

                            var distinctMapCodes = location.Locations.Select(row => row.MapCCode).Distinct().ToList();
                            List <Location> filteredLocationListByFirstMapCode = new List <Location>();



                            foreach (var mapCode in distinctMapCodes)
                            {
                                Location loc = location.Locations.FirstOrDefault(row => row.MapCCode == mapCode);

                                if (loc != null)
                                {
                                    if (loc.MapCCode == "WO")
                                    {
                                        Location placeholderLocation     = new Location();
                                        placeholderLocation.LocationId   = loc.LocationId;
                                        placeholderLocation.LocName      = "World";
                                        placeholderLocation.Abbreviation = loc.Abbreviation;
                                        placeholderLocation.MapCCode     = loc.MapCCode;
                                        placeholderLocation.DisplayOrder = loc.DisplayOrder + 1;
                                        filteredLocationListByFirstMapCode.Add(placeholderLocation);
                                    }
                                    else
                                    {
                                        filteredLocationListByFirstMapCode.Add(loc);
                                    }
                                }
                            }
                            MapCCodeList             = filteredLocationListByFirstMapCode.OrderByDescending(row => row.DisplayOrder).ToList();
                            Location sleLocation     = new Location();
                            sleLocation.LocationId   = 0;
                            sleLocation.LocName      = "Select";
                            sleLocation.Abbreviation = "Select";
                            sleLocation.MapCCode     = "SE";
                            sleLocation.DisplayOrder = 0;
                            MapCCodeList.Insert(0, sleLocation);

                            LocationList         = location.Locations.OrderBy(row => row.DisplayOrder).ToList();
                            FilteredLocationList = LocationList;
                            provinceList         = location.ProvinceLst.OrderBy(row => row.DisplayOrder).ToList();
                            stateList            = location.StatesLst.OrderBy(row => row.DisplayOrder).ToList();

                            if (MapCCodeList.Count > 1 && Settings.LocationPickerSelectedId == 0)
                            {
                                //Assign value to registration objec
                                Settings.LocationPickerSelectedId = MapCCodeList[0].LocationId;
                            }

                            InvokeOnMainThread(() =>
                            {
                                MapCCodePickerView.Model = new MapCCodeModel(this);
                                LocationsPicker.Model    = new LocationsModel(this);

                                if (Settings.IsRegistered)
                                {
                                    var previouslSelectedLocation = MapCCodeList.FirstOrDefault(row => row.LocationId == Settings.LocationPickerSelectedId);

                                    if (previouslSelectedLocation != null)
                                    {
                                        int currentIndex = MapCCodeList.IndexOf(MapCCodeList.FirstOrDefault(row => row.LocationId == Settings.LocationPickerSelectedId));;
                                        MapCCodePickerView.Select(currentIndex, 0, true);
                                    }
                                    else
                                    {
                                        if (Settings.LocationPickerSelectedId != 0)
                                        {
                                            int locationId = Settings.LocationPickerSelectedId;
                                            int mapCIndex  = MapCCodeList.IndexOf(MapCCodeList.FirstOrDefault(row => row.LocationId == 0));
                                            MapCCodePickerView.Select(mapCIndex, 0, true);
                                            MapCCodePickerView.Model.Selected(MapCCodePickerView, mapCIndex, 0);

                                            int locationCInddex = FilteredLocationList.IndexOf(FilteredLocationList.FirstOrDefault(row => row.LocationId == locationId));
                                            LocationsPicker.Select(locationCInddex, 0, true);
                                            LocationsPicker.Model.Selected(LocationsPicker, locationCInddex, 0);
                                            //LocationPicker.Alpha = 1f;
                                        }
                                    }
                                }
                                else
                                {
                                    //MapCCodePicker.Model.Selected(MapCCodePicker, 0, 0);
                                    MapCCodePickerView.Select(0, 0, true);
                                }
                            });
                        }
                    }
                    else
                    {
                        InvokeOnMainThread(() =>
                        {
                            var alert = UIAlertController.Create("Please connect to the internet", "Internet access is required.", UIAlertControllerStyle.Alert);

                            alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, (obj) =>
                            {
                                RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;
                                //var firstStep = registrationVC.Steps.FirstOrDefault();
                                //registrationVC._pageViewController.SetViewControllers(new[] { firstStep as UIViewController }, UIPageViewControllerNavigationDirection.Reverse, true, (finished) =>
                                //{
                                //	if (finished)
                                //	{
                                //		//finalStep.StepActivated(this, new MultiStepProcessStepEventArgs());

                                //	}
                                //});
                                registrationVC.DismissViewController(true, null);
                            }));

                            PresentViewController(alert, animated: true, completionHandler: () =>
                            {
                            });
                        });
                    }
                }
                catch (Exception exe) {
                }
            }
                     );
        }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            base.ViewDidAppear(animated);

// This screen name value will remain set on the tracker and sent with
// hits until it is set to a new value or to null.
            Gai.SharedInstance.DefaultTracker.Set(GaiConstants.ScreenName, "Page View");

            Gai.SharedInstance.DefaultTracker.Send(DictionaryBuilder.CreateAppView().Build());

            StepActivated?.Invoke(this, new MultiStepProcessStepEventArgs {
                Index = StepIndex
            });


            bool needsToReturnToPreviousStep = false;
            //Ensure required fields are input
            string validationMessage = string.Empty;

            if (Settings.Email == null || Settings.Email == string.Empty)
            {
                validationMessage           = "Please input a valid email address";
                needsToReturnToPreviousStep = true;
            }
            if (Settings.Password == null || Settings.Password == string.Empty)
            {
                validationMessage           = "Please input a valid password";
                needsToReturnToPreviousStep = true;
            }
            if (Settings.FirstName == null || Settings.FirstName == string.Empty)
            {
                validationMessage           = "Please input your first name";
                needsToReturnToPreviousStep = true;
            }
            if (Settings.LastName == null || Settings.LastName == string.Empty)
            {
                validationMessage           = "Please input your last name";
                needsToReturnToPreviousStep = true;
            }
            if (Settings.Phone == null || Settings.Phone == string.Empty)
            {
                validationMessage           = "Please input your cell phone number";
                needsToReturnToPreviousStep = true;
            }
            if (Settings.LocationPickerSelectedId == 0)
            {
                validationMessage           = "Please select your location";
                needsToReturnToPreviousStep = true;
            }
            if (needsToReturnToPreviousStep)
            {
                HelperMethods.SendBasicAlert("Validation", validationMessage);
                RegistrationViewController registrationVC = (RegistrationViewController)((MultiStepProcessHorizontalViewController)this.ParentViewController).ContainerViewController;
                var secondStep = registrationVC.Steps[1];
                InvokeOnMainThread(() =>
                {
                    registrationVC._pageViewController.SetViewControllers(new[] { secondStep as UIViewController }, UIPageViewControllerNavigationDirection.Reverse, true, (finished) =>
                    {
                        if (finished)
                        {
                            //finalStep.StepActivated(this, new MultiStepProcessStepEventArgs());
                        }
                    });
                });
            }


            //Register events
            PilotSwitch.ValueChanged += PilotSwitch_ValueChanged;
            NextButton.TouchUpInside += NextButton_TouchUpInside;
        }