using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace WS2Client {
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class FormProxy : System.Windows.Forms.Form {
		private System.Windows.Forms.CheckBox chbUseProxy;
		private System.Windows.Forms.GroupBox grpProxy;
		private System.Windows.Forms.TextBox txtProxyAddr;
		private System.Windows.Forms.Label lblProxyAddr;
		private System.Windows.Forms.Label lblProxyPort;
		private System.Windows.Forms.TextBox txtProxyPort;
		private System.Windows.Forms.Label lblProxyUsr;
		private System.Windows.Forms.TextBox txtProxyUsr;
		private System.Windows.Forms.Label lblProxyPass;
		private System.Windows.Forms.TextBox txtProxyPass;
		private System.Windows.Forms.Button btnProxyOK;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public FormProxy() {
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing ) {
			if( disposing ) {
				if(components != null) {
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent() {
			this.chbUseProxy = new System.Windows.Forms.CheckBox();
			this.grpProxy = new System.Windows.Forms.GroupBox();
			this.txtProxyPass = new System.Windows.Forms.TextBox();
			this.lblProxyPass = new System.Windows.Forms.Label();
			this.lblProxyUsr = new System.Windows.Forms.Label();
			this.txtProxyUsr = new System.Windows.Forms.TextBox();
			this.lblProxyPort = new System.Windows.Forms.Label();
			this.txtProxyPort = new System.Windows.Forms.TextBox();
			this.lblProxyAddr = new System.Windows.Forms.Label();
			this.txtProxyAddr = new System.Windows.Forms.TextBox();
			this.btnProxyOK = new System.Windows.Forms.Button();
			this.grpProxy.SuspendLayout();
			this.SuspendLayout();
			// 
			// chbUseProxy
			// 
			this.chbUseProxy.Location = new System.Drawing.Point(8, 8);
			this.chbUseProxy.Name = "chbUseProxy";
			this.chbUseProxy.TabIndex = 0;
			this.chbUseProxy.Text = "Use Proxy";
			this.chbUseProxy.CheckedChanged += new System.EventHandler(this.chbUseProxy_CheckedChanged);
			// 
			// grpProxy
			// 
			this.grpProxy.Controls.Add(this.txtProxyPass);
			this.grpProxy.Controls.Add(this.lblProxyPass);
			this.grpProxy.Controls.Add(this.lblProxyUsr);
			this.grpProxy.Controls.Add(this.txtProxyUsr);
			this.grpProxy.Controls.Add(this.lblProxyPort);
			this.grpProxy.Controls.Add(this.txtProxyPort);
			this.grpProxy.Controls.Add(this.lblProxyAddr);
			this.grpProxy.Controls.Add(this.txtProxyAddr);
			this.grpProxy.Enabled = false;
			this.grpProxy.Location = new System.Drawing.Point(8, 40);
			this.grpProxy.Name = "grpProxy";
			this.grpProxy.Size = new System.Drawing.Size(224, 120);
			this.grpProxy.TabIndex = 1;
			this.grpProxy.TabStop = false;
			this.grpProxy.Text = "Proxy Configuration";
			// 
			// txtProxyPass
			// 
			this.txtProxyPass.Location = new System.Drawing.Point(112, 88);
			this.txtProxyPass.Name = "txtProxyPass";
			this.txtProxyPass.PasswordChar = '*';
			this.txtProxyPass.Size = new System.Drawing.Size(104, 20);
			this.txtProxyPass.TabIndex = 7;
			this.txtProxyPass.Text = "";
			this.txtProxyPass.TextChanged += new System.EventHandler(this.txtProxyPass_TextChanged);
			// 
			// lblProxyPass
			// 
			this.lblProxyPass.Location = new System.Drawing.Point(8, 96);
			this.lblProxyPass.Name = "lblProxyPass";
			this.lblProxyPass.Size = new System.Drawing.Size(96, 12);
			this.lblProxyPass.TabIndex = 6;
			this.lblProxyPass.Text = "Password";
			// 
			// lblProxyUsr
			// 
			this.lblProxyUsr.Location = new System.Drawing.Point(8, 72);
			this.lblProxyUsr.Name = "lblProxyUsr";
			this.lblProxyUsr.Size = new System.Drawing.Size(96, 12);
			this.lblProxyUsr.TabIndex = 5;
			this.lblProxyUsr.Text = "Username";
			// 
			// txtProxyUsr
			// 
			this.txtProxyUsr.Location = new System.Drawing.Point(112, 64);
			this.txtProxyUsr.Name = "txtProxyUsr";
			this.txtProxyUsr.Size = new System.Drawing.Size(104, 20);
			this.txtProxyUsr.TabIndex = 4;
			this.txtProxyUsr.Text = "";
			this.txtProxyUsr.TextChanged += new System.EventHandler(this.txtProxyUsr_TextChanged);
			// 
			// lblProxyPort
			// 
			this.lblProxyPort.Location = new System.Drawing.Point(8, 48);
			this.lblProxyPort.Name = "lblProxyPort";
			this.lblProxyPort.Size = new System.Drawing.Size(96, 12);
			this.lblProxyPort.TabIndex = 3;
			this.lblProxyPort.Text = "Port";
			// 
			// txtProxyPort
			// 
			this.txtProxyPort.Location = new System.Drawing.Point(112, 40);
			this.txtProxyPort.Name = "txtProxyPort";
			this.txtProxyPort.Size = new System.Drawing.Size(104, 20);
			this.txtProxyPort.TabIndex = 2;
			this.txtProxyPort.Text = "";
			this.txtProxyPort.TextChanged += new System.EventHandler(this.txtProxyPort_TextChanged);
			// 
			// lblProxyAddr
			// 
			this.lblProxyAddr.Location = new System.Drawing.Point(8, 24);
			this.lblProxyAddr.Name = "lblProxyAddr";
			this.lblProxyAddr.Size = new System.Drawing.Size(96, 12);
			this.lblProxyAddr.TabIndex = 1;
			this.lblProxyAddr.Text = "Address";
			// 
			// txtProxyAddr
			// 
			this.txtProxyAddr.Location = new System.Drawing.Point(112, 16);
			this.txtProxyAddr.Name = "txtProxyAddr";
			this.txtProxyAddr.Size = new System.Drawing.Size(104, 20);
			this.txtProxyAddr.TabIndex = 0;
			this.txtProxyAddr.Text = "http://";
			this.txtProxyAddr.TextChanged += new System.EventHandler(this.txtProxyAddr_TextChanged);
			// 
			// btnProxyOK
			// 
			this.btnProxyOK.Location = new System.Drawing.Point(80, 168);
			this.btnProxyOK.Name = "btnProxyOK";
			this.btnProxyOK.TabIndex = 2;
			this.btnProxyOK.Text = "OK";
			this.btnProxyOK.Click += new System.EventHandler(this.btnProxyOK_Click);
			// 
			// FormProxy
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(240, 205);
			this.Controls.Add(this.btnProxyOK);
			this.Controls.Add(this.grpProxy);
			this.Controls.Add(this.chbUseProxy);
			this.Name = "FormProxy";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Proxy Configuration";
			this.grpProxy.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void chbUseProxy_CheckedChanged(object sender, System.EventArgs e) {
			grpProxy.Enabled = chbUseProxy.Checked;
			ProxyConfiguration.UseProxy = chbUseProxy.Checked;
		}

		private void txtProxyAddr_TextChanged(object sender, System.EventArgs e) {
			ProxyConfiguration.Address = txtProxyAddr.Text;
		}

		private void txtProxyPort_TextChanged(object sender, System.EventArgs e) {
			ProxyConfiguration.Port = txtProxyPort.Text;
		}

		private void txtProxyUsr_TextChanged(object sender, System.EventArgs e) {
			ProxyConfiguration.Username = txtProxyUsr.Text;
		}

		private void txtProxyPass_TextChanged(object sender, System.EventArgs e) {
			ProxyConfiguration.Password = txtProxyPass.Text;
		}

		private void btnProxyOK_Click(object sender, System.EventArgs e) {
			this.Hide();
		}
	}

	public class ProxyConfiguration {
		private static bool useProxy;
		private static string proxyPath;
		private static string proxyPort;
		private static string proxyUsr;
		private static string proxyPass;

		public static bool UseProxy {
			get { 
				return useProxy;
			}
			set {
				useProxy = value;
			}
		}

		public static string Address {
			get { 
				return proxyPath;
			}
			set {
				proxyPath = value;
			}
		}

		public static string Port {
			get { 
				return proxyPort;
			}
			set {
				proxyPort = value;
			}
		}

		public static string Username {
			get { 
				return proxyUsr;
			}
			set {
				proxyUsr = value;
			}
		}

		public static string Password {
			get { 
				return proxyPass;
			}
			set {
				proxyPass = value;
			}
		}
	}
}
