public override async void ViewDidAppear(bool animated)
			{
				base.ViewDidAppear(animated);
				if (_cancelledByUser || _justLoggedIn) return;
				Auth0Client auth0Client = null;
				//IdentityService identityService = null;
				if (_nativeView == null) return;
				var message = String.Empty;
				try
				{
					auth0Client = new Auth0Client(App.Instance.OAuthSettings.Domain, App.Instance.OAuthSettings.ClientId);//SimpleIoc.Default.GetInstance<Auth0Client>();
					//identityService = SimpleIoc.Default.GetInstance<IIdentityService>() as IdentityService;
					//if (identityService == null) return;
				 var user = await auth0Client.LoginAsync(ViewController, "servcorp.adfs.prod", true);


					_justLoggedIn = true;
				    

					//					if (eventArgs.IsAuthenticated) {
					//						// Use eventArgs.Account to do wonderful things
					App.Instance.SaveToken(user.Auth0AccessToken);

				    App.Instance.SuccessfulLoginAction.Invoke();
					//					} else {
					//						// The user cancelled
					//					}
				}
				catch (System.Threading.Tasks.TaskCanceledException cancelException)
				{
				App.Instance.FailureLoginAction.Invoke();
				//await App.Instance.NavigationPage.Navigation.PushModalAsync (new StartPage());
				MessagingCenter.Send<App> (App.Instance, "AuthenticationFailed");

					if (cancelException.Task != null &&
						cancelException.Task.Status == TaskStatus.Canceled)
						_cancelledByUser = true;
					message = cancelException.Message;
				App.Instance.ErrorMessage = message;
				App.Instance.NavigationPage.PopToRootAsync ().Wait();
				}
				catch (Exception exception)
				{
					message = exception.Message;
					//throw;
				}

				//if (identityService != null) identityService.SetIdentity(auth0Client, _cancelledByUser, message);
			}
//		public override void ViewDidLoad ()
//		{
//			
//		}
	
   protected override async void OnElementChanged (ElementChangedEventArgs<Page> e)
	{
			base.OnElementChanged(e);

			if (_cancelledByUser || _justLoggedIn) return;


			Auth0Client auth0Client = null;
			//IdentityService identityService = null;
			//if (_nativeView == null) return;
			var message = String.Empty;
			try
			{
				auth0Client = new Auth0Client(App.Instance.OAuthSettings.Domain, App.Instance.OAuthSettings.ClientId);//SimpleIoc.Default.GetInstance<Auth0Client>();
				//identityService = SimpleIoc.Default.GetInstance<IIdentityService>() as IdentityService;
				//if (identityService == null) return;
				var user = await auth0Client.LoginAsync(this.Context, "servcorp.adfs.prod", true);

				_justLoggedIn = true;
				App.Instance.SuccessfulLoginAction.Invoke();

				//					if (eventArgs.IsAuthenticated) {
				//						// Use eventArgs.Account to do wonderful things
				App.Instance.SaveToken(user.Auth0AccessToken);
				//					} else {
				//						// The user cancelled
				//					}
			}
			catch (System.Threading.Tasks.TaskCanceledException cancelException)
			{
				if (cancelException.Task != null &&
					cancelException.Task.Status == TaskStatus.Canceled)
					_cancelledByUser = true;
				message = cancelException.Message;
			}
			catch (Exception exception)
			{
				message = exception.Message;
				//throw;
			}
	}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            this.NavigationItem.SetHidesBackButton (true, false);
            this.NavigationItem.SetLeftBarButtonItem(null, true);

            SetUILayOut ();

            // Code to start the Xamarin Test Cloud Agent
            #if ENABLE_TEST_CLOUD
            Xamarin.Calabash.Start ();
            #endif

            AppDelegate.IsFromSignUp = false;
            ButtonLogin.TouchUpInside +=  async (object sender, EventArgs e) => {

                loadingOverlay = new LoadingOverlay(this.View.Bounds);
                this.View.Add(loadingOverlay);

                if ( ValidateCredentials ()) {
                    // Call to Get user details and validate credentials
                    LandingTabBarVC landingVC = this.Storyboard.InstantiateViewController ("LandingTabBarVC") as LandingTabBarVC;
                    if (landingVC != null) {
                        this.NavigationController.PushViewController(landingVC, true);
                    }
                }
            };

            ButtonLinkedInLogin.TouchUpInside += async (object sender, EventArgs e) => {

                //var auth0 = new Auth0Client("donow.auth0.com","1ghdA3NFkpT9V7ibOuIKp8QK3oF49RId");
                var auth0 = new Auth0Client("donowx.auth0.com","T2GQGMUwY1jxHHD2sKTGtiX865rynYQh");
                Auth0User user = null;
                try
                {
                    user = await auth0.LoginAsync(this,"linkedin");

                }
                catch (AggregateException ex)
                {
                //this.SetResultText(e.Flatten().Message);
                }
                catch (Exception ex)
                {
                //this.SetResultText(e.Message);
                }

                if(user != null)
                {
                    loadingOverlay = new LoadingOverlay(this.View.Bounds);
                    this.View.Add(loadingOverlay);

                    AppDelegate.UserProfile = Newtonsoft.Json.JsonConvert.DeserializeObject<Profile>(user.Profile.ToString());

                    if(AppDelegate.UserProfile.email_verified == true)
                    {

                        //AppDelegate.UserDetails =  AppDelegate.userBL.GetUserFromEmail(AppDelegate.UserProfile.email);
                        AppDelegate.UserDetails =  AppDelegate.userBL.GetUserDetails(AppDelegate.UserProfile.email);

                        if(AppDelegate.UserDetails != null && AppDelegate.UserDetails.UserId > 0)
                        {

                            LandingTabBarVC landingVC = this.Storyboard.InstantiateViewController ("LandingTabBarVC") as LandingTabBarVC;
                            if (landingVC != null) {
                                this.NavigationController.PushViewController(landingVC, true);
                            }
                        }
                        else
                        {
                            signUpOtherDetailsVC signUpVC = this.Storyboard.InstantiateViewController ("signUpOtherDetailsVC") as signUpOtherDetailsVC;
                            if (signUpVC != null) {
            //								signUpVC.NavigationItem.SetHidesBackButton (true, false);
            //								signUpVC.NavigationItem.SetLeftBarButtonItem(null, true);

                                if (signUpVC != null) {
                                    signUpVC.NavigationItem.SetHidesBackButton (true, false);
                                }
                                this.NavigationController.PushViewController(signUpVC, true);
                            }
                        }
                    }
                }
            };

            ButtonSignUp.TouchUpInside += (object sender, EventArgs e) => {
                AppDelegate.UserProfile = null;
                signUpLoginDetailsVC signUpVC = this.Storyboard.InstantiateViewController ("signUpLoginDetailsVC") as signUpLoginDetailsVC;
                if (signUpVC != null) {
                    this.NavigationController.PushViewController(signUpVC, true);
                }
            };

            ButtonForgotPassword.TouchUpInside += (object sender, EventArgs e) => {

                ForgotPasswordVC forgotPasswordVC = this.Storyboard.InstantiateViewController ("ForgotPasswordVC") as ForgotPasswordVC;
                if (forgotPasswordVC != null) {
                    this.NavigationController.PushViewController(forgotPasswordVC, true);
                }
            };

            ButtonVideo.TouchUpInside += (object sender, EventArgs e) => {
                var url = new NSUrl ("http://www.youtube.com/watch?v=I0N-4Dtog6E");
                if (!UIApplication.SharedApplication.OpenUrl (url)) {
                    var av = new UIAlertView ("Error:",
                        "error in opening video link",
                        null,
                        "OK",
                        null);
                    av.Show ();
                };
            };

            ButtonWebsite.TouchUpInside += (object sender, EventArgs e) => {
                var url = new NSUrl ("http://donowx.com");
                if (!UIApplication.SharedApplication.OpenUrl (url)) {
                    var av = new UIAlertView ("Error:",
                        "error in opening video link",
                        null,
                        "OK",
                        null);
                    av.Show ();
                };
            };
        }