public EmpireWideMain()
		{
			
			var mainLayout = new StackLayout
			{
				BackgroundColor = Color.FromRgb (0, 0, 128),
				Children = {
					planetStatusCheck,
					stationStatusCheck,
					speciesStats,
				}
			};

			Content = mainLayout;
			if (Device.OS == TargetPlatform.iOS)
			{
				mainLayout.Padding = new Thickness (0, 20, 0, 0);
			}

			planetStatusCheck.Clicked += async (sender, e) =>
			{
				await Navigation.PushAsync(new BodyStatus(account, false));
			};
			stationStatusCheck.Clicked += async (sender, e) =>
			{
				await Navigation.PushAsync(new BodyStatus(account, true));
			};
			speciesStats.Clicked += async (sender, e) =>
			{
				await Navigation.PushAsync(new SpeciesStats(account));
			};

			this.Appearing += async (sender, e) =>
			{
				AccountManager acntMgr = new AccountManager();
				account = await acntMgr.GetActiveAccountAsync();
			};
		}
        public BuildingViewCell()
        {
            layout.Children.Add(buildingImage);
            layout.Children.Add(planetName);
            layout.Children.Add(buildingLevel);
            layout.Children.Add(efficiency);
            layout.Children.Add(buildingID);
            layout.Children.Add(buildingimg);
            layout.Children.Add(repair);
            layout.Children.Add(upgrade);
            layout.Children.Add(downgrade);

            layout.Children.Add(buildingUrl);

            buildingID.SetBinding(Label.TextProperty, "BuildingID");

            planetName.SetBinding(Label.TextProperty, "BuildingName");
            buildingLevel.SetBinding(Label.TextProperty, "BuildingLevel");
            efficiency.SetBinding(Label.TextProperty, "Efficiency");
            buildingimg.SetBinding(Label.TextProperty, "ImageName");
            buildingImage.SetBinding(Image.SourceProperty, new Binding("url"));
            buildingUrl.SetBinding(Label.TextProperty, "BuildingURL");
            if (Convert.ToInt16(buildingLevel.Text) < 30)
            {
                up.IsVisible = false;
                up.IsEnabled = false;
            }
            //var uri = new Uri(("https://github.com/plainblack/Lacuna-Assets/tree/master/planet_side/50/" + buildingimg.Text + ".png"));
            //buildingImage.Source = ImageSource.FromUri(uri);
            buildingimg.IsVisible = false;
            buildingUrl.IsVisible = false;

            View = layout;
            upgrade.GestureRecognizers.Add((new TapGestureRecognizer
            {
                Command = new Command(async o =>
                {
                    AccountManager acntMgr = new AccountManager();
                    var account = await acntMgr.GetActiveAccountAsync();
                    var json = Buildings.Upgrade(account.SessionID, buildingID.Text);
                    var server = new Server();
                    var response = await server.GetHttpResultAsync(account.Server, buildingUrl.Text, json);
                })
            }));

            repair.GestureRecognizers.Add((new TapGestureRecognizer
            {
                Command = new Command(async o =>
                {
                    AccountManager acntMgr = new AccountManager();
                    var account = await acntMgr.GetActiveAccountAsync();
                    var json = Buildings.Repair(account.SessionID, buildingID.Text);
                    var server = new Server();
                    var response = await server.GetHttpResultAsync(account.Server, buildingUrl.Text, json);
                })
            }));

            downgrade.GestureRecognizers.Add((new TapGestureRecognizer
            {
                Command = new Command(async o =>
                {
                    AccountManager acntMgr = new AccountManager();
                    var account = await acntMgr.GetActiveAccountAsync();
                    var json = Buildings.Downgrade(account.SessionID, buildingID.Text);
                    var server = new Server();
                    var response = await server.GetHttpResultAsync(account.Server, buildingUrl.Text, json);
                })
            }));
            up.Clicked += async (sender, e) =>
            {
                AccountManager acntMgr = new AccountManager();
                var account = await acntMgr.GetActiveAccountAsync();
                var json = Buildings.Upgrade(account.SessionID, buildingID.Text);
                var server = new Server();
                var response = server.GetHttpResultAsync(account.Server, buildingUrl.Text, buildingID.Text);

            };
        }
		public CaptchaPage(AccountModel account)
		{
            Resources = Styles.Styles.StyleDictionary;
			BoxView topSpacer = new BoxView
			{
				BackgroundColor = Color.Transparent,
				VerticalOptions = LayoutOptions.StartAndExpand,
			};
            Entry answerEntry = new Entry
            {
                Placeholder = "Answer",
				Style = (Style)Styles.Styles.StyleDictionary[Styles.Styles.StyleName.EntryStyle.ToString()],				
				VerticalOptions = LayoutOptions.CenterAndExpand,
			};
            Button answerButton = new Button
            {
                Text = "Answer",
				Style = (Style)Styles.Styles.StyleDictionary[Styles.Styles.StyleName.RegularButton.ToString()],
				VerticalOptions = LayoutOptions.EndAndExpand,
            };
			var mainLayout = new StackLayout
			{
				Style = (Style)Styles.Styles.StyleDictionary[Styles.Styles.StyleName.MainLayout.ToString()],
				Children = {
					topSpacer,
					captchaImage,
					answerEntry,
					answerButton
				}
			};

			Content = mainLayout;
			if (Device.OS == TargetPlatform.iOS)
			{
				mainLayout.Padding = new Thickness (0, 20, 0, 0);
			}

			answerButton.Clicked += async (sender, e) =>{
				if (answerEntry.Text.Length > 0)
				{
					answerButton.IsEnabled = false;
					var s = new LacunaExpress.Data.Server();
					var json = Captcha.Solve(account.SessionID, guid, answerEntry.Text);
					var response = await s.GetHttpResultStringAsyncAsString(account.Server, Captcha.url, json);
					if (response != null)
					{
						var r = Newtonsoft.Json.JsonConvert.DeserializeObject<CaptchaResponse>(response);
						if(r.result==1){
							var oldacnt = account;
							account.CaptchaLastRenewed = DateTime.Now;
							AccountManager accountMan = new AccountManager();
							accountMan.ModifyAccountAsync(account, oldacnt);
							await Navigation.PopModalAsync();
						}
						else
						{
							answerButton.IsEnabled = true;
							GetCaptcha(account);
							answerEntry.Text = "";
						}
					}
					else
					{
						answerButton.IsEnabled = true;
						GetCaptcha(account);
						answerEntry.Text = "";
					}
				}
			};
			this.Appearing += async (sender, e) =>
			{
				var captchaValidUntil = DateTime.Now.AddMinutes(-25);
				if (account.CaptchaLastRenewed > captchaValidUntil) 
				{
					await Navigation.PopModalAsync();
				}else
				{
					GetCaptcha(account);
				}
			};			
		}
		async Task<bool> LoadPage(Boolean typeStation){
			AccountManager accountMan = new AccountManager();
			account = await accountMan.GetActiveAccountAsync();
            var originalAccount = account;
            if (typeStation)
			{
				bodyList.Clear();
				foreach(var s in account.Stations.Keys)
				{
					var json = LacunaExpanseAPIWrapper.Body.GetBuildings(1, account.SessionID, s);
					var server = new LacunaExpress.Data.Server();
					var response = await server.GetHttpResultAsync(account.Server, LacunaExpanseAPIWrapper.Body.url, json);
					if (response.result != null)
					{
						BodyStatusModel bdy = new BodyStatusModel();
						bdy.response = response;
						bdy.Name     = response.result.status.body.name;
						bdy.Star     = response.result.status.body.star_name;
						bdy.Zone     = response.result.status.body.zone;
						bdy.X        = response.result.status.body.x;
						bdy.Y        = response.result.status.body.y;
                        if (!Scripts.StatusCheckers.StationOk(response))
                        {
                            bdy.Status = "Warning";
                            notifyAllianceOfStations.IsVisible = true;
                            warningStations.Add(bdy.Name +"{ Planet "+bdy.Name+" "+ response.result.status.body.id+" }");                           
                        }
						bodyList.Add(bdy);
                        if (response.result.buildings != null)
                        {
                            foreach(var b in response.result.buildings)
                            {
                                if (account.Parliaments == null)
                                    account.Parliaments = new List<BuildingCache>();
                                if(b.Value.url.Contains(Parliament.URL))
                                    account.Parliaments.Add(new BuildingCache { planetID = b.Value.name, buildingID = b.Key, level = Convert.ToInt16(b.Value.level) });
                            }
                            //var parliament = (from p in response.result.buildings
                            //                  where p.Value.url.Contains(Parliament.URL)
                            //                  select new { id = p.Key, level = p.Value.level, }).First();

                            //account.Parliaments.Add(new BuildingCache { planetID = bdy.Name, buildingID = parliament.id, level = Convert.ToInt16(parliament.level) });
                        }
                    }
				}
                if(account.Parliaments.Count >0)
                    accountMan.ModifyAccountAsync(account, originalAccount);
            }
			else
			{
				bodyList.Clear();
				foreach (var c in account.Colonies.Keys)
				{
					var json = LacunaExpanseAPIWrapper.Body.GetBuildings(1, account.SessionID, c);
					var s = new LacunaExpress.Data.Server();
					var response = await s.GetHttpResultAsync(account.Server, LacunaExpanseAPIWrapper.Body.url, json);
					if (response.result != null)
					{
						BodyStatusModel bdy = new BodyStatusModel();
						bdy.response = response;
						bdy.Name = response.result.status.body.name;
						bdy.Star = response.result.status.body.star_name;
						bdy.Zone = response.result.status.body.zone;
						bdy.X = response.result.status.body.x;
						bdy.Y = response.result.status.body.y;
						if (!Scripts.StatusCheckers.PlanetOk(response))
							bdy.Status = "Warning";
						bodyList.Add(bdy);
					}

					//BodyStatus bodyresult = response.result.Bodies;
					//(BodyStatus)bodyresult = 
				}
			}
			return true;
		}			
		public BodyStatusDetail(Response response, string pName)
		{
			this.response = response;
			var mainLayout = new StackLayout
			{
				BackgroundColor = Color.FromRgb (0, 0, 128),
				Children = {
					planetName,
					planetLocation,
					enemyIncoming,
					damagedBuildings,	
					fissures,					
					bleeders,					
					food,
					water,
					ore,
					energy,
					happiness,
					waste,
					repairBuildings,
					destroyBleeders,
					fillFissure
				}
			};

			Content = mainLayout;
			if (Device.OS == TargetPlatform.iOS)
			{
				mainLayout.Padding = new Thickness (0, 20, 0, 0);
			}

            repairBuildings.Clicked += async (sender, e) =>
            {
                var damagedIDs = LacunaExpress.Scripts.BuildingToolsScripts.GetDamagedBuildingIDs(response.result.buildings);
                
                if(account != null)
                {
					//foreach(var p in account.AllBodies)
					//{
					//	if (p.Value.Equals(planetName.Text))
					//	{
					//		planetID = p.Key;
					//		break;
					//	}
					//}
					
                    //planetID = account.AllBodies.Where(x => x.Value.Equals(planetName)).First().Key;
                    var json = LacunaExpanseAPIWrapper.Body.RepairList(1, account.SessionID, planetID, damagedIDs);
                    var server = new LacunaExpress.Data.Server();
                    var r = await server.GetHttpResultAsync(account.Server, LacunaExpanseAPIWrapper.Body.url, json);
                    var xyz = r;
                }
               
            };

            this.Appearing += async (sender, e) => 
            {
                AccountManager acntMgr = new AccountManager();
                account = await acntMgr.GetActiveAccountAsync();
                planetName.Text = pName;
				planetID = (from i in account.AllBodies
							where i.Value.Equals(planetName.Text)
							select i.Key).First();
                //planetLocation.Text = response.result.status.body.name;
                //planetID = response.result.status.body.id
                food.Text      = "Food: " + response.result.status.body.food_stored + "/" + response.result.status.body.food_hour;
                water.Text     = "Water: " + response.result.status.body.water_stored + "/" + response.result.status.body.water_hour;
                ore.Text       = "Ore: " + response.result.status.body.ore_stored + "/" + response.result.status.body.ore_hour;
                energy.Text    = "Energy: " + response.result.status.body.energy_stored + "/" + response.result.status.body.energy_hour;
                happiness.Text = "Happiness: " + response.result.status.body.happiness + "/" + response.result.status.body.happiness_hour;
                waste.Text     = "Waste: " + response.result.status.body.waste_stored + "/" + response.result.status.body.waste_hour;

                enemyIncoming.Text = "Enemy Incoming: " + response.result.status.body.incoming_enemy_ships;

                int bleederCount = 0;
                int fissureCount = 0;
                int damagedBuildingsCount = 0;
                foreach (var b in response.result.buildings)
                {
                    if (Convert.ToInt64(b.Value.efficiency) < 100)
                    {
                        damagedBuildingsCount++;
                        repairBuildings.IsVisible = true;
                    }
                    if (b.Value.name.Contains("eeder"))
                        bleederCount++;
                    if (b.Value.name.Contains("issure"))
                        fissureCount++;
                }
                damagedBuildings.Text = "Damaged Buildings: " + damagedBuildingsCount;
                fissures.Text = "Fissures: " + fissureCount;
                bleeders.Text = "Bleeders: " + bleederCount;
            };
		}