/**************************************************************************************************

NetPolls - The web poll engine
Copyright (c) 2007 Data Illusion (http://www.dataillusion.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

************************************************************************************************/
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using DataIllusion.NetPolls.WebControls;
using DataIllusion.NetPolls.WebAdmin.UserControls;

namespace DataIllusion.NetPolls.WebAdmin
{
	/// <summary>
	/// Summary description for PollStats.
	/// </summary>
	public partial class PollCode : PageBase
	{
		protected HeaderControl PollHeader;

		protected void Page_Load(object sender, System.EventArgs e)
		{
			CodeHyperLink.NavigateUrl = ResolveUrl("~/polldisplay.aspx?pollid=" + PollId);

			if (Request.ServerVariables["SERVER_PORT"] != null && Request.ServerVariables["SERVER_PORT"] != "80")
			{
				if (HttpContext.Current.Request.ApplicationPath != "/")
				{
					CodeHyperLink.NavigateUrl = string.Format("http://{0}:{1}{2}/polldisplay.aspx?pollid={3}",
						Request.ServerVariables["SERVER_NAME"], Request.ServerVariables["SERVER_PORT"], HttpContext.Current.Request.ApplicationPath, PollId);
				}
				else
				{
					CodeHyperLink.NavigateUrl = string.Format("http://{0}:{1}/polldisplay.aspx?pollid={2}",
						Request.ServerVariables["SERVER_NAME"], Request.ServerVariables["SERVER_PORT"], PollId);
				}
			}
			else
			{
				if (HttpContext.Current.Request.ApplicationPath != "/")
				{
					CodeHyperLink.NavigateUrl = string.Format("http://{0}{1}/polldisplay.aspx?pollid={2}",
						Request.ServerVariables["SERVER_NAME"], HttpContext.Current.Request.ApplicationPath, PollId);
				}
				else
				{
					CodeHyperLink.NavigateUrl = string.Format("http://{0}/polldisplay.aspx?pollid={1}",
						Request.ServerVariables["SERVER_NAME"], PollId);
				}
			}

			CodeHyperLink.Font.Size = FontUnit.Point(15);

			CodeHyperLink.Text = Request.IsSecureConnection ?
				CodeHyperLink.NavigateUrl.Replace("http:", "https:") : CodeHyperLink.NavigateUrl;
			
			MessageLabel.Visible = false;
			PollPreview.PollId = PollId;
			tbNetSource.Text = "<vts:PollBox\r\n" +
				" ID = \"myPoll" +PollId.ToString()+ "\"\r\n" +
				" Width=\"150\"\r\n" +
				" BarColor = \"red\"\r\n" +
				" BackColor = \"black\"\r\n" +
				" PollId = \"" + PollId.ToString() + "\"\r\n" +
				" CellSpacing = \"1\"\r\n" +
				" CellPadding = \"0\"\r\n" +
				" IPBlocking = \"false\"\r\n" +
				" IPReleaseTimeOut = \"120\"\r\n" +
				" CookieBlocking = \"false\"\r\n" +
				" CookieReleaseTimeOut = \"120\"\r\n" +
				" ShowTotalVotesPreview = \"true\"\r\n" +
				" DisplayViewResults = \"true\"\r\n" +
				" runat = \"server\">\r\n" +
				"		<HeadStyle Font-Names=\"Arial\" Font-Size=\"10pt\" Font-Bold=\"True\" ForeColor=\"White\" BackColor=\"#333399\"></HeadStyle>\r\n" +
				"		<QuestionStyle Font-Names=\"Arial\" Font-Size=\"10pt\" Font-Bold=\"True\" ForeColor=\"black\" BackColor=\"#E0E7EC\"></QuestionStyle>\r\n" +
				"		<AnswerStyle Font-Names=\"Arial\" Font-Size=\"10pt\" BackColor=\"#C2C9DA\"></AnswerStyle>\r\n" +
				"		<ButtonStyle Font-Size=\"12px\" Font-Names=\"Verdana,Arial\" Font-Bold=\"True\"></ButtonStyle>\r\n" +
				"		<FootStyle Font-Names=\"Arial\" Font-Size=\"10pt\" Font-Bold=\"True\" ForeColor=\"White\" BackColor=\"#333399\"></FootStyle>\r\n" +
				"</vts:PollBox>";
			
			ResultsPreview.PollId = PollId;
			tbResultsNetSource.Text = "<vts:ResultsBox\r\n" +
				" ID = \"myPollResults" +PollId.ToString()+ "\"\r\n" +
				" Width = \"150\"\r\n" +
				" BackColor = \"black\"\r\n" +
				" BarColor = \"red\"\r\n" +
				" PollId = \"" + PollId.ToString() + "\"\r\n" +
				" CellSpacing = \"1\"\r\n" +
				" CellPadding = \"0\"\r\n" +
				" runat = \"server\">\r\n" +
				"		<HeadStyle Font-Names=\"Arial\" Font-Size=\"10pt\" Font-Bold=\"True\" ForeColor=\"White\" BackColor=\"#333399\"></HeadStyle>\r\n" +
				"		<QuestionStyle Font-Names=\"Arial\" Font-Size=\"10pt\" Font-Bold=\"True\" ForeColor=\"black\" BackColor=\"#E0E7EC\"></QuestionStyle>\r\n" +
				"		<AnswerStyle Font-Names=\"Arial\" Font-Size=\"10pt\" BackColor=\"#C2C9DA\"></AnswerStyle>\r\n" +
				"		<FootStyle Font-Names=\"Arial\" Font-Size=\"10pt\" Font-Bold=\"True\" ForeColor=\"White\" BackColor=\"#333399\"></FootStyle>\r\n" +
				"</vts:ResultsBox>";

			PollHeader.PollId = PollId;
		}


		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion


	}
}
