using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;

namespace VKontakte
{
	public class VKClient
	{
		public VKClient(string email, string pass)
		{
			if (!this.Authorize(email, pass))
			{
				throw new AuthorizationFailed("Ошибка авторизации: пары логин/пароль не существует!");
			}
		}

		public VKClient(string email, string pass, WebProxy proxy)
		{
			this.Proxy = proxy;
			if (!this.Authorize(email, pass))
			{
				throw new AuthorizationFailed("Ошибка авторизации: пары логин/пароль не существует!");
			}
		}

		public bool Authorize(string email, string pass)
		{
			string text = null;
			string text2 = null;
			string text3 = null;
			string text4 = null;
			string text5 = null;
			string text6 = null;
			string text7 = null;
			string text8 = null;
			do
			{
				HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/login.php") as HttpWebRequest;
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.Method = "POST";
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				Stream requestStream = httpWebRequest.GetRequestStream();
				StreamWriter streamWriter = new StreamWriter(requestStream);
				streamWriter.Write("op=a_login_attempt&email={0}&pass={1}", VKClient.EncodeStringToHTTP(email), VKClient.EncodeStringToHTTP(pass));
				if (text2 != null)
				{
					streamWriter.Write("&captcha_sid={0}&captcha_key={1}", text, text2);
				}
				streamWriter.Close();
				streamWriter.Dispose();
				requestStream.Dispose();
				HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
				text2 = null;
				text = null;
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				string[] values = httpWebResponse.Headers.GetValues("Set-Cookie");
				if (values != null)
				{
					foreach (string text9 in values)
					{
						int num = text9.IndexOf(';');
						if (text9.StartsWith("remixchk"))
						{
							text4 = text9.Substring("remixchk".Length + 1, num - "remixchk".Length - 1);
						}
						else if (text9.StartsWith("remixlang"))
						{
							text3 = text9.Substring("remixlang".Length + 1, num - "remixlang".Length - 1);
						}
						else if (text9.StartsWith("remixemail"))
						{
							text6 = text9.Substring("remixemail".Length + 1, num - "remixemail".Length - 1);
						}
						else if (text9.StartsWith("remixmid"))
						{
							text5 = text9.Substring("remixmid".Length + 1, num - "remixmid".Length - 1);
						}
						else if (text9.StartsWith("remixpass"))
						{
							text7 = text9.Substring("remixpass".Length + 1, num - "remixpass".Length - 1);
						}
						else if (text9.StartsWith("remixsid"))
						{
							text8 = text9.Substring("remixsid".Length + 1, num - "remixsid".Length - 1);
						}
					}
				}
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				try
				{
					text = null;
					do
					{
						string src = streamReader.ReadLine();
						if (text != null)
						{
							break;
						}
						text = VKClient.Parse(src, "\"captcha_sid\":\"", "\"", 0);
					}
					while (!streamReader.EndOfStream);
				}
				finally
				{
					streamReader.Close();
					streamReader.Dispose();
					requestStream.Dispose();
				}
				if (text != null)
				{
					text2 = CaptchaDialog.Show("Капча - Авторизация", text, this.Proxy, "");
				}
			}
			while (text2 != null);
			if (text2 == null && text != null)
			{
				return false;
			}
			if (text5 == null || text5.Contains("deleted"))
			{
				return false;
			}
			this.cookies = string.Format("{0}={6}; {1}={7}; {2}={8}; {3}={9}; {4}={10}; {5}={11}", new object[]
			{
				"remixlang",
				"remixchk",
				"remixmid",
				"remixemail",
				"remixpass",
				"remixsid",
				text3,
				text4,
				text5,
				text6,
				text7,
				text8
			});
			this.MyID = int.Parse(text5);
			return true;
		}

		public string GetPersonName(int person_id)
		{
			HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/search.php?id=" + person_id) as HttpWebRequest;
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
			Stream responseStream = httpWebResponse.GetResponseStream();
			StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
			string text = streamReader.ReadToEnd();
			streamReader.Close();
			streamReader.Dispose();
			responseStream.Dispose();
			bool flag = false;
			int num = text.IndexOf("<div style=\"overflow: hidden;\"><a href=\"");
			if (num == -1)
			{
				flag = true;
			}
			if (!flag)
			{
				num = text.IndexOf('>', num + "<div style=\"overflow: hidden;\"><a href=\"".Length) + 1;
			}
			else
			{
				num = text.IndexOf("<div style=\"overflow: hidden;\">");
				if (num == -1)
				{
					return null;
				}
				num += "<div style=\"overflow: hidden;\">".Length;
			}
			return VKClient.DecodeHTMLString(text.Substring(num, text.IndexOf('<', num) - num));
		}

		public int[] Get10RandomPeople()
		{
			HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/people.php") as HttpWebRequest;
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
			Stream responseStream = httpWebResponse.GetResponseStream();
			StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
			List<int> list = new List<int>();
			do
			{
				string text = VKClient.Parse(streamReader.ReadLine(), "<dd><div style=\"width: 140px; overflow: hidden;\"><a href=\"/id", "\"", 0);
				if (text != null)
				{
					list.Add(int.Parse(text));
				}
			}
			while (!streamReader.EndOfStream);
			streamReader.Close();
			streamReader.Dispose();
			responseStream.Dispose();
			return list.ToArray();
		}

		public int[] GetPersonGroups(int person_id)
		{
			HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/groups.php?id=" + person_id) as HttpWebRequest;
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
			string text = httpWebResponse.Headers["Location"];
			if (text != null && text.Contains("blank.php"))
			{
				httpWebResponse.Close();
				throw new NotAvailableException("Список групп не доступен!");
			}
			Stream responseStream = httpWebResponse.GetResponseStream();
			StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
			List<int> list = new List<int>();
			do
			{
				string text2 = VKClient.Parse(streamReader.ReadLine(), "<div style=\"width: 300px; overflow: hidden;\"><a id=\"groupName", "\"", 0);
				if (text2 != null)
				{
					list.Add(-int.Parse(text2));
				}
			}
			while (!streamReader.EndOfStream);
			streamReader.Close();
			streamReader.Dispose();
			responseStream.Dispose();
			return list.ToArray();
		}

		public string GetGroupName(int group_id)
		{
			if (group_id > 0)
			{
				throw new InvalidIDException("ID группы неверный!");
			}
			group_id = Math.Abs(group_id);
			HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/club" + group_id) as HttpWebRequest;
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
			Stream responseStream = httpWebResponse.GetResponseStream();
			StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
			string text = null;
			while (text == null)
			{
				text = VKClient.Parse(streamReader.ReadLine(), "<td><div class=\"dataWrap\"><b>", "<", 0);
				if (streamReader.EndOfStream)
				{
					break;
				}
			}
			streamReader.Close();
			streamReader.Dispose();
			responseStream.Dispose();
			return VKClient.DecodeHTMLString(text);
		}

		public AlbumInfo[] GetGroupAlbums(int group_id, int count)
		{
			if (group_id > 0)
			{
				throw new InvalidIDException("ID группы неверный!");
			}
			group_id = Math.Abs(group_id);
			List<AlbumInfo> list = new List<AlbumInfo>();
			int num = -1;
			int num2 = 0;
			HttpWebResponse httpWebResponse;
			string text;
			for (;;)
			{
				int num3 = num2 * 50;
				HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/photos.php?gid=" + group_id + ((num3 == 0) ? string.Empty : ("&act=getpages&offset=" + num3))) as HttpWebRequest;
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				text = httpWebResponse.Headers["Location"];
				if (text != null && text.Contains("blank.php"))
				{
					break;
				}
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				string text2 = null;
				do
				{
					string text3 = streamReader.ReadLine();
					int num4;
					if (num == -1 && int.TryParse(VKClient.Parse(text3, "<div class=\"summary\">", " ", 0), out num4))
					{
						num = num4;
						if (count == 0)
						{
							count = num;
						}
						else if (count > num)
						{
							count = num;
						}
					}
					if (text2 == null)
					{
						text2 = VKClient.Parse(text3, "<div class=\"aname\"><a href=\"album-" + group_id + "_", "\"", 0);
					}
					if (text2 != null)
					{
						string s = VKClient.Parse(text3, text2 + "\">", "</a>", 0);
						string s2 = VKClient.Parse(streamReader.ReadLine(), "<div class=\"ainfo\">", " ", 0);
						string s3 = VKClient.Parse(streamReader.ReadLine(), "<div class=\"adesc\">", "</div>", 0);
						text3 = streamReader.ReadLine();
						string s4;
						string s5;
						if (text3.Contains("<br />"))
						{
							s4 = VKClient.Parse(text3, "<div class=\"ainfo\">Обновлён ", "<", 0);
							s5 = VKClient.Parse(text3, "<br />Создан ", "<", 0);
						}
						else
						{
							s4 = null;
							s5 = VKClient.Parse(text3, "<div class=\"ainfo\">Создан ", "<", 0);
						}
						list.Add(new AlbumInfo
						{
							ID = int.Parse(text2),
							Name = VKClient.DecodeHTMLString(s),
							Description = VKClient.DecodeHTMLString(s3),
							CreationDate = VKClient.ParseDate(s5),
							LastChangeDate = VKClient.ParseDate(s4),
							OwnerID = -group_id,
							PhotosCount = int.Parse(s2)
						});
						text2 = null;
						if (list.Count == count)
						{
							break;
						}
					}
				}
				while (!streamReader.EndOfStream);
				streamReader.Close();
				streamReader.Dispose();
				responseStream.Dispose();
				num2++;
				if (list.Count >= count)
				{
					goto Block_13;
				}
			}
			httpWebResponse.Close();
			throw BlankErrorException.GetBlankErrorException(text);
			Block_13:
			return list.ToArray();
		}

		public bool AddFriend(int friend_id, string message)
		{
			if (friend_id <= 0)
			{
				throw new InvalidIDException("Неверный ID!");
			}
			HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/friend.php") as HttpWebRequest;
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.Method = "POST";
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			Stream requestStream = httpWebRequest.GetRequestStream();
			StreamWriter streamWriter = new StreamWriter(requestStream, VKClient.encoding);
			streamWriter.Write("act=a_add_form&fid={0}", friend_id);
			streamWriter.Close();
			streamWriter.Dispose();
			requestStream.Dispose();
			HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
			Stream responseStream = httpWebResponse.GetResponseStream();
			StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
			string text = null;
			string text2 = null;
			string text3 = null;
			do
			{
				string src = streamReader.ReadLine();
				if (text == null)
				{
					text = VKClient.Parse(src, "<input type=\\\"hidden\\\" name=\\\"h\\\" id=\\\"h\\\" value=\\\"", "\\", 0);
				}
				if (text2 == null)
				{
					text2 = VKClient.Parse(src, "<input type=\\\"hidden\\\" name=\\\"first_name\\\" id=\\\"first_name\\\" value=\\\"", "\\", 0);
				}
				if (text3 == null)
				{
					text3 = VKClient.Parse(src, "<input type=\\\"hidden\\\" name=\\\"last_name\\\" id=\\\"last_name\\\" value=\\\"", "\\", 0);
				}
			}
			while (!streamReader.EndOfStream);
			text2 = VKClient.DecodeHTMLString(text2);
			text3 = VKClient.DecodeHTMLString(text3);
			streamReader.Close();
			streamReader.Dispose();
			responseStream.Dispose();
			string text4 = null;
			string text5 = null;
			for (;;)
			{
				httpWebRequest = (WebRequest.Create("http://vkontakte.ru/friend.php") as HttpWebRequest);
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.Method = "POST";
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				streamWriter = new StreamWriter(httpWebRequest.GetRequestStream());
				streamWriter.Write("act=addFriend&fid={0}&h={1}&first_name={2}&last_name={3}&sex=&message={4}", new object[]
				{
					friend_id,
					text,
					VKClient.EncodeStringToHTTP(text2),
					VKClient.EncodeStringToHTTP(text3),
					VKClient.EncodeStringToHTTP(message)
				});
				if (text5 != null)
				{
					streamWriter.Write("&captcha_sid={0}&captcha_key={1}", text4, text5);
				}
				streamWriter.Close();
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				string text6 = httpWebResponse.Headers["Location"];
				if (text6 != null && text6.Contains("blank.php"))
				{
					break;
				}
				responseStream = httpWebResponse.GetResponseStream();
				streamReader = new StreamReader(responseStream, VKClient.encoding);
				string text7 = streamReader.ReadToEnd();
				streamReader.Close();
				streamReader.Dispose();
				responseStream.Dispose();
				text5 = null;
				text4 = null;
				if (text7.Contains("подтвердит, что Вы"))
				{
					return true;
				}
				if (text7.Contains("\"captcha_sid\":\""))
				{
					text4 = VKClient.Parse(text7, "\"captcha_sid\":\"", "\"", 0);
					text5 = CaptchaDialog.Show("Капча - Добавление в друзья", text4, this.Proxy, this.cookies);
				}
				if (text5 == null)
				{
					return false;
				}
			}
			httpWebResponse.Close();
			throw new NotAvailableException("Добавление в друзья невозможно!");
		}

		public bool EnterGroup(int group_id)
		{
			if (group_id > 0)
			{
				throw new InvalidIDException("ID группы неверный!");
			}
			group_id = Math.Abs(group_id);
			HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/groups.php?act=ajax&n=1&gid=" + group_id) as HttpWebRequest;
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
			httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
			Stream responseStream = httpWebResponse.GetResponseStream();
			StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
			string text = streamReader.ReadToEnd();
			streamReader.Close();
			streamReader.Dispose();
			responseStream.Dispose();
			return text.Contains("Приглашение принято");
		}

		public bool WriteToWall(int id, string message)
		{
			if (id == 0)
			{
				throw new InvalidIDException("Значение ID не может быть 0!");
			}
			if (id != this.write_wall_prev_id || this.write_wall_hash == null)
			{
				this.write_wall_hash = null;
				this.write_wall_to_id = null;
				this.write_wall_prev_id = id;
				this.write_wall_extra_id = null;
				HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/wall.php?" + ((id > 0) ? "id=" : "gid=") + Math.Abs(id)) as HttpWebRequest;
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				while (this.write_wall_extra_id == null)
				{
					this.write_wall_extra_id = VKClient.Parse(streamReader.ReadLine(), "</span><a href=\"wall.php?act=write&", "\"", 0);
					if (streamReader.EndOfStream)
					{
						break;
					}
				}
				streamReader.Close();
				streamReader.Dispose();
				responseStream.Dispose();
				if (this.write_wall_extra_id == null)
				{
					throw new NotAvailableException("Стена не доступна!");
				}
				httpWebRequest = (WebRequest.Create("http://vkontakte.ru/wall.php?act=write&" + this.write_wall_extra_id) as HttpWebRequest);
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				responseStream = httpWebResponse.GetResponseStream();
				streamReader = new StreamReader(responseStream, VKClient.encoding);
				string text = null;
				string text2 = null;
				string text3 = null;
				do
				{
					string src = streamReader.ReadLine();
					if (text == null)
					{
						text = VKClient.Parse(src, "<script>function", "</script>", 0);
					}
					else if (text2 == null)
					{
						text2 = VKClient.Parse(src, "wall_hash: ", " ", 0);
					}
					else if (this.write_wall_to_id == null)
					{
						this.write_wall_to_id = VKClient.Parse(src, "<input type=\"hidden\" id=\"to_id\" name=\"to_id\" value=\"", "\"", 0);
					}
					else
					{
						if (text3 != null)
						{
							break;
						}
						text3 = VKClient.Parse(src, "<input type=\"hidden\" id=\"wall_hash\" name=\"wall_hash\" value=\"", "\"", 0);
					}
				}
				while (!streamReader.EndOfStream);
				streamReader.Close();
				streamReader.Dispose();
				responseStream.Dispose();
				int num = text.IndexOf(text2);
				num = text.IndexOf('=', num) + 1;
				num = text.IndexOf("=\"", num) + 2;
				char c = text.Substring(num, 1)[0];
				for (int i = 0; i < 4; i++)
				{
					num = text.IndexOf('+', num) + 1;
				}
				int num2 = int.Parse(text.Substring(num, text.IndexOf('-', num) - num));
				string str = string.Empty;
				for (int j = 0; j < text3.Length; j++)
				{
					int k;
					for (k = (int)c + num2 - (int)text3[j]; k < 48; k += 75)
					{
					}
					while (k > 122)
					{
						k -= 75;
					}
					str += char.ConvertFromUtf32(k);
					c = text3[j];
				}
				this.write_wall_hash = str;
			}
			if (this.write_wall_hash == null)
			{
				return false;
			}
			string text4 = null;
			string text5 = null;
			do
			{
				HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/wall.php") as HttpWebRequest;
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.Method = "POST";
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				Stream requestStream = httpWebRequest.GetRequestStream();
				StreamWriter streamWriter = new StreamWriter(requestStream);
				streamWriter.Write(string.Format("to_id={0}&act=sent&wall_hash={1}&message={2}", this.write_wall_to_id, this.write_wall_hash, VKClient.EncodeStringToHTTP(message)));
				if (text5 != null)
				{
					streamWriter.Write("&captcha_sid={0}&captcha_key={1}", text4, text5);
				}
				streamWriter.Close();
				text5 = null;
				text4 = null;
				HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				try
				{
					text4 = null;
					string text6;
					for (;;)
					{
						text6 = streamReader.ReadLine();
						if (text6 == null || text6.Contains("blank.php"))
						{
							break;
						}
						if (text6.Contains("\"captcha_sid\":\""))
						{
							goto Block_25;
						}
						if (streamReader.EndOfStream)
						{
							goto IL_53B;
						}
					}
					throw new NotAvailableException("Стена не доступна!");
					Block_25:
					text4 = VKClient.Parse(text6, "\"captcha_sid\":\"", "\"", 0);
					IL_53B:;
				}
				finally
				{
					streamReader.Close();
					streamReader.Dispose();
					requestStream.Dispose();
				}
				if (text4 != null)
				{
					text5 = CaptchaDialog.Show("Капча - Стена", text4, this.Proxy, this.cookies);
				}
			}
			while (text5 != null);
			return text5 != null || text4 == null;
		}

		public bool SendGraffitiToWall(int id, byte[] img_data)
		{
			if (id == 0)
			{
				throw new InvalidIDException("Значение ID не может быть 0!");
			}
			HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/" + string.Format("graffiti.php?to_id={0}&group_id={1}", (id > 0) ? id : 0, (id < 0) ? id : 0)) as HttpWebRequest;
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.Method = "POST";
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "multipart/form-data; boundary=--OLEG-ANDREEV-PAVEL-DUROV-GRAFFITI-POST";
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			byte[] array = new byte[1024];
			VKClient.encoding.GetBytes(Convert.ToBase64String(img_data), 0, 1024, array, 0);
			MD5 md = MD5.Create();
			string text = string.Empty;
			foreach (byte b in md.ComputeHash(array))
			{
				text += b.ToString("x2");
			}
			Stream requestStream = httpWebRequest.GetRequestStream();
			array = VKClient.encoding.GetBytes(string.Format("--{0}\r\nContent-Disposition: form-data; name=\"Signature\"\r\n\r\n{1}\r\n--{0}\r\nContent-Disposition: form-data; name=\"Filedata\"; filename=\"graffiti.png\"\r\nContent-Type: image/png\r\n\r\n", "--OLEG-ANDREEV-PAVEL-DUROV-GRAFFITI-POST", text));
			requestStream.Write(array, 0, array.Length);
			requestStream.Write(img_data, 0, img_data.Length);
			array = VKClient.encoding.GetBytes(string.Format("--{0}\r\nContent-Disposition: form-data; name=\"Upload\"\r\n\r\nSubmit Query\r\n--{0}--", "--OLEG-ANDREEV-PAVEL-DUROV-GRAFFITI-POST"));
			requestStream.Write(array, 0, array.Length);
			requestStream.Close();
			requestStream.Dispose();
			HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
			string str = httpWebResponse.Headers["Location"];
			httpWebResponse.Close();
			httpWebRequest = (WebRequest.Create("http://vkontakte.ru/" + str) as HttpWebRequest);
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
			str = httpWebResponse.Headers["Location"];
			httpWebResponse.Close();
			httpWebRequest = (WebRequest.Create("http://vkontakte.ru/" + str) as HttpWebRequest);
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
			Stream responseStream = httpWebResponse.GetResponseStream();
			StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
			string text2 = null;
			string text3 = null;
			string text4 = null;
			do
			{
				string text5 = streamReader.ReadLine();
				if (text2 == null)
				{
					text2 = VKClient.Parse(text5, "grid: '", "'", 0);
				}
				if (text4 == null)
				{
					text4 = VKClient.Parse(text5, "to_id: '", "'", 0);
				}
				if (text3 == null)
				{
					text3 = VKClient.Parse(text5, "wall_hash: '", "'", 0);
				}
			}
			while (!streamReader.EndOfStream);
			streamReader.Close();
			streamReader.Dispose();
			responseStream.Dispose();
			string text6 = null;
			string text7 = null;
			do
			{
				string text8 = string.Format("?act=sent&grid={0}&to_id={1}&wall_hash={2}&message={0}", text2, text4, text3);
				if (text7 != null)
				{
					text8 += string.Format("&captcha_sid={0}&captcha_key={1}", text6, text7);
				}
				httpWebRequest = (WebRequest.Create("http://vkontakte.ru/wall.php" + text8) as HttpWebRequest);
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				text7 = null;
				text6 = null;
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				responseStream = httpWebResponse.GetResponseStream();
				streamReader = new StreamReader(responseStream, VKClient.encoding);
				try
				{
					string text5;
					for (;;)
					{
						text5 = streamReader.ReadLine();
						if (text5 == null || text5.Contains("blank.php"))
						{
							break;
						}
						if (text5.Contains("\"captcha_sid\":\""))
						{
							goto Block_19;
						}
						if (streamReader.EndOfStream)
						{
							goto IL_4A4;
						}
					}
					throw new NotAvailableException("Стена не доступна!");
					Block_19:
					text6 = VKClient.Parse(text5, "\"captcha_sid\":\"", "\"", 0);
					IL_4A4:;
				}
				finally
				{
					streamReader.Close();
					streamReader.Dispose();
					requestStream.Dispose();
				}
				if (text6 != null)
				{
					text7 = CaptchaDialog.Show("Капча - Стена", text6, this.Proxy, this.cookies);
				}
			}
			while (text7 != null);
			return text7 != null || text6 == null;
		}

		public int AddGroupDiscussion(int group_id, string title, string post)
		{
			if (group_id > 0)
			{
				throw new InvalidIDException("ID группы неверный!");
			}
			group_id = Math.Abs(group_id);
			if (group_id != this.add_discussion_prev_gid || this.add_discussion_hash == null)
			{
				this.add_discussion_prev_gid = group_id;
				this.add_discussion_hash = null;
				HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/board.php?act=newtopic&id=" + group_id.ToString()) as HttpWebRequest;
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
				string text = httpWebResponse.Headers["Location"];
				if (text != null && text.Contains("blank.php"))
				{
					httpWebResponse.Close();
					throw new NotAvailableException("Обсуждения не дуступны!");
				}
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				while (this.add_discussion_hash == null)
				{
					this.add_discussion_hash = VKClient.Parse(streamReader.ReadLine(), "<input type=\"hidden\" id=\"hash\" name=\"hash\" value=\"", "\"", 0);
					if (streamReader.EndOfStream)
					{
						break;
					}
				}
				streamReader.Close();
				streamReader.Dispose();
				responseStream.Dispose();
				if (this.add_discussion_hash == null)
				{
					return 0;
				}
			}
			string text2 = null;
			string text3 = null;
			string text4 = null;
			do
			{
				HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/board.php ") as HttpWebRequest;
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.Method = "POST";
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.Headers.Add("X-Requested-With", "XMLHttpRequest");
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				Stream requestStream = httpWebRequest.GetRequestStream();
				StreamWriter streamWriter = new StreamWriter(requestStream);
				streamWriter.Write(string.Format("act=a_new_topic&gid={0}&hash={1}&title={2}&post={3}", new object[]
				{
					group_id,
					this.add_discussion_hash,
					VKClient.EncodeStringToHTTP(title),
					VKClient.EncodeStringToHTTP(post)
				}));
				if (text3 != null)
				{
					streamWriter.Write("&captcha_sid={0}&captcha_key={1}", text2, text3);
				}
				streamWriter.Close();
				streamWriter.Dispose();
				requestStream.Dispose();
				HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				text3 = null;
				text2 = null;
				try
				{
					for (;;)
					{
						string text5 = streamReader.ReadLine();
						if (text5.Contains("blank.php"))
						{
							break;
						}
						if (text4 != null)
						{
							goto IL_33C;
						}
						text4 = VKClient.Parse(text5, "rtopic-" + group_id + "_", null, 0);
						if (text2 != null)
						{
							goto IL_33C;
						}
						text2 = VKClient.Parse(text5, "\"captcha_sid\":\"", "\"", 0);
						if (streamReader.EndOfStream)
						{
							goto IL_33C;
						}
					}
					throw new NotAvailableException("Обсуждения не доступны!");
					IL_33C:;
				}
				finally
				{
					streamReader.Close();
					streamReader.Dispose();
					responseStream.Dispose();
				}
				if (text2 != null)
				{
					text3 = CaptchaDialog.Show("Капча - Обсуждения", text2, this.Proxy, this.cookies);
				}
			}
			while (text3 != null);
			if (text4 != null)
			{
				return int.Parse(text4);
			}
			return 0;
		}

		public int AddGroupPhotoAlbum(int group_id, string name, string description)
		{
			if (group_id > 0)
			{
				throw new InvalidIDException("ID группы неверный!");
			}
			group_id = Math.Abs(group_id);
			HttpWebRequest httpWebRequest;
			HttpWebResponse httpWebResponse;
			if (group_id != this.add_album_prev_gid || this.add_album_hash == null)
			{
				this.add_album_hash = null;
				httpWebRequest = (WebRequest.Create("http://vkontakte.ru/photos.php?act=new&gid=" + group_id) as HttpWebRequest);
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				while (this.add_album_hash == null)
				{
					this.add_album_hash = VKClient.Parse(streamReader.ReadLine(), "<input type=\"hidden\" id=\"hash\" name=\"hash\" value=\"", "\"", 0);
					if (streamReader.EndOfStream)
					{
						break;
					}
				}
				streamReader.Close();
				streamReader.Dispose();
				responseStream.Dispose();
				if (this.add_album_hash == null)
				{
					throw new Exception("Ошибка чтения хэш кода");
				}
			}
			httpWebRequest = (WebRequest.Create("http://vkontakte.ru/photos.php") as HttpWebRequest);
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.Method = "POST";
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			Stream requestStream = httpWebRequest.GetRequestStream();
			StreamWriter streamWriter = new StreamWriter(requestStream, VKClient.encoding);
			streamWriter.Write("act=create&hash={0}&gid={1}&name={2}&desc={3}&access_level=0", new object[]
			{
				this.add_album_hash,
				group_id,
				VKClient.EncodeStringToHTTP(name),
				VKClient.EncodeStringToHTTP(description)
			});
			streamWriter.Close();
			streamWriter.Dispose();
			requestStream.Dispose();
			httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
			string text = httpWebResponse.Headers["Location"];
			httpWebResponse.Close();
			if (text.Contains("blank.php"))
			{
				throw BlankErrorException.GetBlankErrorException(text);
			}
			string text2 = VKClient.Parse(text, "id=", "&oid=", 0);
			if (text2 != null)
			{
				return int.Parse(text2);
			}
			return 0;
		}

		public string UploadPhotoToAlbum(AlbumInfo album, List<byte[]> images_data)
		{
			if (album.ID <= 0)
			{
				throw new InvalidIDException("ID фотоальбома неверный!");
			}
			HttpWebRequest httpWebRequest;
			HttpWebResponse httpWebResponse;
			if (album.ID != this.add_photo_prev_aid || this.add_photo_gid == null)
			{
				this.add_photo_upload_url = null;
				this.add_photo_gid = null;
				this.add_photo_hash = null;
				this.add_photo_rhash = null;
				this.add_photo_prev_aid = album.ID;
				httpWebRequest = (WebRequest.Create(string.Concat(new object[]
				{
					"http://vkontakte.ru/photos.php?act=add&id=",
					album.ID,
					"&oid=",
					album.OwnerID
				})) as HttpWebRequest);
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				string text = httpWebResponse.Headers["Location"];
				if (text != null && text.Contains("blank.php"))
				{
					httpWebResponse.Close();
					throw BlankErrorException.GetBlankErrorException(text);
				}
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				do
				{
					string src = streamReader.ReadLine();
					if (this.add_photo_upload_url == null)
					{
						this.add_photo_upload_url = VKClient.Parse(src, "<form id=\"upload\" name=\"upload\" action=\"", "\"", 0);
					}
					else if (this.add_photo_gid == null)
					{
						this.add_photo_gid = VKClient.Parse(src, "<input type=\"hidden\" id=\"gid\" name=\"gid\" value=\"", "\"", 0);
					}
					else if (this.add_photo_hash == null)
					{
						this.add_photo_hash = VKClient.Parse(src, "<input type=\"hidden\" id=\"hash\" name=\"hash\" value=\"", "\"", 0);
					}
					else
					{
						if (this.add_photo_rhash != null)
						{
							break;
						}
						this.add_photo_rhash = VKClient.Parse(src, "<input type=\"hidden\" id=\"rhash\" name=\"rhash\" value=\"", "\"", 0);
					}
				}
				while (!streamReader.EndOfStream);
				streamReader.Close();
				responseStream.Dispose();
				if (this.add_photo_gid == null)
				{
					return null;
				}
			}
			httpWebRequest = (WebRequest.Create(this.add_photo_upload_url) as HttpWebRequest);
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.Method = "POST";
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "multipart/form-data; boundary=---------------------------45293212730795";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			Stream requestStream = httpWebRequest.GetRequestStream();
			byte[] bytes = VKClient.encoding.GetBytes(string.Format("--{0}\r\nContent-Disposition: form-data; name=\"act\"\r\n\r\ndo_add\r\n--{0}\r\nContent-Disposition: form-data; name=\"id\"\r\n\r\n{1}\r\n--{0}\r\nContent-Disposition: form-data; name=\"aid\"\r\n\r\n{1}\r\n--{0}\r\nContent-Disposition: form-data; name=\"gid\"\r\n\r\n{2}\r\n--{0}\r\nContent-Disposition: form-data; name=\"mid\"\r\n\r\n{3}\r\n--{0}\r\nContent-Disposition: form-data; name=\"hash\"\r\n\r\n{4}\r\n--{0}\r\nContent-Disposition: form-data; name=\"rhash\"\r\n\r\n{5}", new object[]
			{
				"---------------------------45293212730795",
				album.ID,
				this.add_photo_gid,
				this.MyID,
				this.add_photo_hash,
				this.add_photo_rhash
			}));
			requestStream.Write(bytes, 0, bytes.Length);
			for (int i = 0; i < images_data.Count; i++)
			{
				bytes = VKClient.encoding.GetBytes(string.Format("\r\n--{0}\r\nContent-Disposition: form-data; name=\"file{1}\"; filename=\"image{1}.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n", "---------------------------45293212730795", i + 1));
				requestStream.Write(bytes, 0, bytes.Length);
				requestStream.Write(images_data[i], 0, images_data[i].Length);
			}
			bytes = VKClient.encoding.GetBytes(string.Format("\r\n--{0}--", "---------------------------45293212730795"));
			requestStream.Write(bytes, 0, bytes.Length);
			requestStream.Close();
			httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
			string result = httpWebResponse.Headers["Location"];
			httpWebResponse.Close();
			return result;
		}

		public bool AddPhotoToAlbum(string confirm_url)
		{
			if (confirm_url == null)
			{
				return false;
			}
			string text = "act=a_done_add" + VKClient.Parse(confirm_url, "photos.php?act=done_add", null, 0);
			string text2 = null;
			string text3 = null;
			HttpWebResponse httpWebResponse;
			string text5;
			for (;;)
			{
				string text4 = text;
				if (text3 != null)
				{
					text4 += string.Format("&captcha_sid={0}&captcha_key={1}", text2, text3);
				}
				HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/photos.php?" + text4) as HttpWebRequest;
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				text5 = httpWebResponse.Headers["Location"];
				if (text5 != null && text5.Contains("blank.php"))
				{
					break;
				}
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				while (text2 == null)
				{
					text2 = VKClient.Parse(streamReader.ReadLine(), "\"captcha_sid\":\"", "\"", 0);
					if (streamReader.EndOfStream)
					{
						break;
					}
				}
				streamReader.Close();
				streamReader.Dispose();
				responseStream.Dispose();
				text2 = null;
				text3 = null;
				if (text2 != null)
				{
					text3 = CaptchaDialog.Show("Капча - Альбомы", text2, this.Proxy, this.cookies);
				}
				if (text3 == null)
				{
					goto Block_8;
				}
			}
			httpWebResponse.Close();
			throw BlankErrorException.GetBlankErrorException(text5);
			Block_8:
			return text3 != null || text2 == null;
		}

		public string UploadAudioToGroup(int group_id, byte[] audio, out int aid)
		{
			if (group_id > 0)
			{
				throw new InvalidIDException("ID группы неверный!");
			}
			group_id = Math.Abs(group_id);
			HttpWebRequest httpWebRequest;
			HttpWebResponse httpWebResponse;
			if (group_id != this.add_album_prev_gid || this.add_audio_aid == null)
			{
				httpWebRequest = (WebRequest.Create("http://vkontakte.ru/audio.php?act=new&gid=" + group_id) as HttpWebRequest);
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				string text = httpWebResponse.Headers["Location"];
				if (text != null && text.Contains("blank.php"))
				{
					httpWebResponse.Close();
					throw BlankErrorException.GetBlankErrorException(text);
				}
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				do
				{
					string src = streamReader.ReadLine();
					if (this.add_audio_upload_url == null)
					{
						this.add_audio_upload_url = VKClient.Parse(src, "<form action=\"", "\"", 0);
					}
					else if (this.add_audio_aid == null)
					{
						this.add_audio_aid = VKClient.Parse(src, "<input type=\"hidden\" id=\"aid\" name=\"aid\" value=\"", "\"", 0);
					}
					else if (this.add_audio_hash == null)
					{
						this.add_audio_hash = VKClient.Parse(src, "<input type=\"hidden\" id=\"hash\" name=\"hash\" value=\"", "\"", 0);
					}
					else
					{
						if (this.add_audio_rhash != null)
						{
							break;
						}
						this.add_audio_rhash = VKClient.Parse(src, "<input type=\"hidden\" id=\"rhash\" name=\"rhash\" value=\"", "\"", 0);
					}
				}
				while (!streamReader.EndOfStream);
				streamReader.Close();
				responseStream.Dispose();
				if (this.add_audio_aid == null)
				{
					aid = 0;
					return null;
				}
			}
			httpWebRequest = (WebRequest.Create(this.add_audio_upload_url) as HttpWebRequest);
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.Method = "POST";
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "multipart/form-data; boundary=----------EAbAj3oB5VD4zCJ0pxbKbQ";
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			Stream requestStream = httpWebRequest.GetRequestStream();
			byte[] bytes = VKClient.encoding.GetBytes(string.Format("--{0}\r\nContent-Disposition: form-data; name=\"file\"; filename=\"audio.mp3\"\r\nContent-Type: audio/mpeg\r\n\r\n", "----------EAbAj3oB5VD4zCJ0pxbKbQ"));
			requestStream.Write(bytes, 0, bytes.Length);
			requestStream.Write(audio, 0, audio.Length);
			bytes = VKClient.encoding.GetBytes(string.Format("\r\n--{0}\r\nContent-Disposition: form-data; name=\"act\"\r\n\r\nadd_audio\r\n--{0}\r\nContent-Disposition: form-data; name=\"aid\"\r\n\r\n{1}\r\n--{0}\r\nContent-Disposition: form-data; name=\"gid\"\r\n\r\n{2}\r\n--{0}\r\nContent-Disposition: form-data; name=\"mid\"\r\n\r\n{3}\r\n--{0}\r\nContent-Disposition: form-data; name=\"hash\"\r\n\r\n{4}\r\n--{0}\r\nContent-Disposition: form-data; name=\"rhash\"\r\n\r\n{5}\r\n--{0}--", new object[]
			{
				"----------EAbAj3oB5VD4zCJ0pxbKbQ",
				this.add_audio_aid,
				group_id,
				this.MyID,
				this.add_audio_hash,
				this.add_audio_rhash
			}));
			requestStream.Write(bytes, 0, bytes.Length);
			requestStream.Close();
			requestStream.Dispose();
			httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
			string text2 = httpWebResponse.Headers["Location"];
			httpWebResponse.Close();
			if (text2 != null)
			{
				aid = int.Parse(VKClient.Parse(text2, "aid=", "&", 0));
			}
			else
			{
				aid = 0;
			}
			return text2;
		}

		public bool AddAudioToGroup(string confirm_url)
		{
			if (confirm_url == null)
			{
				return false;
			}
			string text = null;
			string text2 = null;
			HttpWebResponse httpWebResponse;
			for (;;)
			{
				if (text2 != null)
				{
					confirm_url += string.Format("&captcha_sid={0}&captcha_key={1}", text, text2);
				}
				HttpWebRequest httpWebRequest = WebRequest.Create(confirm_url) as HttpWebRequest;
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.ContentType = "application/x-www-form-urlencoded";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				text2 = null;
				text = null;
				httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				if (httpWebResponse.Headers["Location"] == null)
				{
					break;
				}
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				try
				{
					string text3;
					for (;;)
					{
						text3 = streamReader.ReadLine();
						if (text3 != null)
						{
							if (text3.Contains("blank.php"))
							{
								break;
							}
							if (text == null)
							{
								goto Block_11;
							}
						}
						if (streamReader.EndOfStream)
						{
							goto IL_13E;
						}
					}
					throw new Exception("Ошибка добавления аудио");
					Block_11:
					text = VKClient.Parse(text3, "\"captcha_sid\":\"", "\"", 0);
					IL_13E:;
				}
				finally
				{
					streamReader.Close();
					streamReader.Dispose();
					responseStream.Dispose();
				}
				if (text != null)
				{
					text2 = CaptchaDialog.Show("Капча - Аудио", text, this.Proxy, this.cookies);
				}
				if (text2 == null)
				{
					goto Block_7;
				}
			}
			httpWebResponse.Close();
			return false;
			Block_7:
			return text2 != null || text == null;
		}

		public VideoInfo UploadVideo(int group_id, string name, string description, byte[] video_data)
		{
			if (group_id > 0)
			{
				throw new InvalidIDException("Неверный ID группы");
			}
			group_id = Math.Abs(group_id);
			HttpWebRequest httpWebRequest = WebRequest.Create("http://vkontakte.ru/video.php") as HttpWebRequest;
			httpWebRequest.Method = "POST";
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			string value = string.Empty;
			if (group_id == 0)
			{
				value = string.Format("act=upload&name={0}&desc={1}&privacy=0", name, description);
			}
			else
			{
				value = string.Format("act=upload&gid={0}&name={1}&desc={2}", group_id, name, description);
			}
			Stream requestStream = httpWebRequest.GetRequestStream();
			StreamWriter streamWriter = new StreamWriter(requestStream);
			streamWriter.Write(value);
			streamWriter.Close();
			streamWriter.Dispose();
			requestStream.Dispose();
			HttpWebResponse httpWebResponse = httpWebRequest.GetResponse() as HttpWebResponse;
			string text = httpWebResponse.Headers["Location"];
			Stream responseStream = httpWebResponse.GetResponseStream();
			StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
			string text2 = null;
			string text3 = null;
			string arg = null;
			string src;
			for (;;)
			{
				src = streamReader.ReadLine();
				if (text2 == null)
				{
					text2 = VKClient.Parse(src, "'upload_url': '", "'", 0);
				}
				else
				{
					if (text3 == null)
					{
						text3 = VKClient.Parse(src, "&export_info=", "&signature", 0);
					}
					if (text3 != null)
					{
						break;
					}
				}
				if (streamReader.EndOfStream)
				{
					goto IL_1A6;
				}
			}
			arg = VKClient.Parse(src, "&signature=", "'", 0);
			IL_1A6:
			streamReader.Close();
			streamReader.Dispose();
			responseStream.Dispose();
			if (text == "/club" + group_id)
			{
				throw new NotAvailableException("Добавление видео невозможно!");
			}
			httpWebRequest = (WebRequest.Create(text2) as HttpWebRequest);
			httpWebRequest.Method = "POST";
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "multipart/form-data; boundary=----------HqhJq1KsxxNePXJqOQH5Yw";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			requestStream = httpWebRequest.GetRequestStream();
			byte[] bytes = VKClient.encoding.GetBytes(string.Format("--{0}\r\nContent-Disposition: form-data; name=\"video_file\"; filename=\"video_file.wmv\"\r\nContent-Type: video/x-ms-wmv\r\n\r\n", "----------HqhJq1KsxxNePXJqOQH5Yw"));
			requestStream.Write(bytes, 0, bytes.Length);
			requestStream.Write(video_data, 0, video_data.Length);
			bytes = VKClient.encoding.GetBytes(string.Format("\r\n--{0}\r\nContent-Disposition: form-data; name=\"export_info\"\r\n\r\n{1}\r\n--{0}\r\nContent-Disposition: form-data; name=\"signature\"\r\n\r\n{2}\r\n--{0}--", "----------HqhJq1KsxxNePXJqOQH5Yw", text3, arg));
			requestStream.Write(bytes, 0, bytes.Length);
			requestStream.Close();
			requestStream.Dispose();
			string text4 = null;
			httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
			text = httpWebResponse.Headers["Location"];
			httpWebResponse.Close();
			if (text == null || text == "http://vkontakte.ru/")
			{
				return default(VideoInfo);
			}
			if (text != null && text.Contains("blank.php"))
			{
				throw BlankErrorException.GetBlankErrorException(text);
			}
			string s = VKClient.Parse(text, "id=", "&", 0);
			string s2 = VKClient.Parse(text, "oid=", "&", 0);
			httpWebRequest = (WebRequest.Create(text + "&add=1&gid=" + group_id) as HttpWebRequest);
			if (this.Proxy != null)
			{
				httpWebRequest.Proxy = this.Proxy;
			}
			httpWebRequest.AllowAutoRedirect = false;
			httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
			httpWebRequest.ContentType = "application/x-www-form-urlencoded";
			httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
			httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
			httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
			httpWebRequest.Headers.Add("Cookie", this.cookies);
			httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
			httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
			responseStream = httpWebResponse.GetResponseStream();
			streamReader = new StreamReader(responseStream);
			while (text4 == null)
			{
				text4 = VKClient.Parse(streamReader.ReadLine(), "hash:'", "'", 0);
				if (streamReader.EndOfStream)
				{
					break;
				}
			}
			streamReader.Close();
			streamReader.Dispose();
			responseStream.Dispose();
			return new VideoInfo
			{
				ID = int.Parse(s),
				OwnerID = int.Parse(s2),
				AddHash = text4,
				AddID = group_id
			};
		}

		public bool AddVideoToGroup(VideoInfo video, bool ajax)
		{
			HttpWebResponse httpWebResponse = null;
			string text = null;
			string text2 = null;
			for (;;)
			{
				string text3 = "http://vkontakte.ru/" + string.Format("video.php?act={0}add&vid={1}&oid={2}&gid={3}&hash={4}", new object[]
				{
					ajax ? "a_" : string.Empty,
					video.ID,
					video.OwnerID,
					video.AddID,
					video.AddHash
				});
				if (text2 != null)
				{
					text3 += string.Format("&captcha_sid={0}&captcha_key={1}", text, text2);
				}
				HttpWebRequest httpWebRequest = WebRequest.Create(text3) as HttpWebRequest;
				if (this.Proxy != null)
				{
					httpWebRequest.Proxy = this.Proxy;
				}
				httpWebRequest.AllowAutoRedirect = false;
				httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";
				httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
				httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.7");
				httpWebRequest.Headers.Add("Accept-Language", "ru,en-us;q=0.7,en;q=0.3");
				httpWebRequest.Headers.Add("Cookie", this.cookies);
				httpWebRequest.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
				try
				{
					httpWebResponse = (httpWebRequest.GetResponse() as HttpWebResponse);
				}
				catch (WebException ex)
				{
					if (ex.Message.Contains("400"))
					{
						return false;
					}
				}
				string text4 = httpWebResponse.Headers["Location"];
				Stream responseStream = httpWebResponse.GetResponseStream();
				StreamReader streamReader = new StreamReader(responseStream, VKClient.encoding);
				string text5 = streamReader.ReadToEnd();
				streamReader.Close();
				streamReader.Dispose();
				if (ajax)
				{
					if (text5.Contains("Ошибка"))
					{
						break;
					}
					if (text5.Contains("добавлен"))
					{
						return true;
					}
				}
				else
				{
					if (text4.Contains("blank.php"))
					{
						return false;
					}
					if (text4.Contains("video.php"))
					{
						return true;
					}
				}
				text2 = null;
				text = VKClient.Parse(text5, "\"captcha_sid\":\"", "\"", 0);
				if (text != null)
				{
					text2 = CaptchaDialog.Show("Капча - Видео", text, this.Proxy, this.cookies);
				}
				if (text2 == null)
				{
					return false;
				}
			}
			return false;
		}

		public WebProxy Proxy { get; set; }

		public int MyID { get; private set; }

		private static DateTime ParseDate(string s)
		{
			if (s == null)
			{
				return DateTime.MinValue;
			}
			s = s.ToLower();
			if (s.Contains("сегодня"))
			{
				return DateTime.Today;
			}
			if (s.Contains("вчера"))
			{
				return DateTime.Today.AddDays(-1.0);
			}
			return DateTime.Parse(s);
		}

		private static string EncodeStringToHTTP(string s)
		{
			if (s == null)
			{
				return null;
			}
			StringBuilder stringBuilder = new StringBuilder();
			foreach (char c in s)
			{
				stringBuilder.Append(char.IsLetter(c) ? c.ToString() : string.Format("%{0}", ((byte)c).ToString("X2")));
			}
			return stringBuilder.ToString();
		}

		public static string DecodeHTMLString(string s)
		{
			if (s == null)
			{
				return null;
			}
			s = s.Replace("&gt;", ">").Replace("&lt;", "<").Replace("&amp;", "&").Replace("&quot;", "\"").Replace("<br />", "\n").Replace("<br/>", "\n").Replace("<br>", "\n");
			StringBuilder stringBuilder = new StringBuilder();
			int i = 0;
			while (i < s.Length)
			{
				if (i >= s.Length - 3 || s[i] != '&' || s[i + 1] != '#')
				{
					goto IL_CF;
				}
				int num = s.IndexOf(';', i);
				if (num == -1)
				{
					goto IL_CF;
				}
				stringBuilder.Append(char.ConvertFromUtf32(int.Parse(s.Substring(i + 2, num - i - 2))));
				i = num;
				IL_DD:
				i++;
				continue;
				IL_CF:
				stringBuilder.Append(s[i]);
				goto IL_DD;
			}
			return stringBuilder.ToString();
		}

		internal static string Parse(string src, string find1, string find2, int offset)
		{
			if (src == null)
			{
				return null;
			}
			int num = src.IndexOf(find1, offset);
			if (num == -1)
			{
				return null;
			}
			num += find1.Length;
			int num2 = 0;
			if (find2 != null)
			{
				num2 = src.IndexOf(find2, num);
				if (num2 == -1)
				{
					return null;
				}
			}
			int length = (find2 != null) ? (num2 - num) : (src.Length - num);
			return src.Substring(num, length);
		}

		private static string GetCookies(HttpWebResponse response)
		{
			List<string> list = new List<string>();
			string[] values = response.Headers.GetValues("Set-Cookie");
			if (values == null)
			{
				return null;
			}
			foreach (string text in values)
			{
				int num = text.IndexOf('=');
				int num2 = text.IndexOf(';');
				if (num != -1 && num2 != -1 && num < num2)
				{
					list.Add(text.Substring(0, num2));
				}
			}
			return string.Join(";", list.ToArray());
		}

		internal const string HOST = "http://vkontakte.ru/";

		internal const string USER_AGENT = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.6) Gecko/2009011913 Firefox/3.0.6";

		internal const string ACCEPT = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";

		internal const string CONTENT_TYPE_URLENCODED = "application/x-www-form-urlencoded";

		internal const string CONTENT_TYPE_MULTIPART = "multipart/form-data; boundary=";

		internal const string ACCEPT_LANGUAGE_HEADER = "Accept-Language";

		internal const string ACCEPT_LANGUAGE = "ru,en-us;q=0.7,en;q=0.3";

		internal const string ACCEPT_CHARSET_HEADER = "Accept-Charset";

		internal const string ACCEPT_CHARSET = "windows-1251,utf-8;q=0.7,*;q=0.7";

		internal const string X_REQUEST_WITH_HEADER = "X-Requested-With";

		internal const string X_REQUEST_WITH = "XMLHttpRequest";

		internal const string COOKIE_HEADER = "Cookie";

		internal const string LOCATION_HEADER = "Location";

		private const string s_parse_captha_id = "\"captcha_sid\":\"";

		private const string s_captcha_data = "&captcha_sid={0}&captcha_key={1}";

		private const string blank_url = "blank.php";

		private string cookies;

		internal static Encoding encoding = Encoding.GetEncoding(1251);

		private int add_discussion_prev_gid;

		private string add_discussion_hash;

		private int add_album_prev_gid;

		private string add_album_hash;

		private int add_photo_prev_aid;

		private string add_photo_gid;

		private string add_photo_hash;

		private string add_photo_rhash;

		private string add_photo_upload_url;

		private int write_wall_prev_id;

		private string write_wall_extra_id;

		private string write_wall_hash;

		private string write_wall_to_id;

		private int add_audio_prev_gid;

		private string add_audio_aid;

		private string add_audio_hash;

		private string add_audio_rhash;

		private string add_audio_upload_url;
	}
}
