protected void Save_Click(object sender, EventArgs e)
 {
     Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
     if(AppName.Value.Length == 0)
     {
         Message.Text = "Enter an App Name";
         return;
     }
     else if (PageName.Value.Length == 0)
     {
         Message.Text = "Enter an Page Name";
         return;
     }
     else if (!Check.ValidateObjectName(Message, AppName.Value.Trim()))
     {
         return;
     }
     else if (!Check.ValidateObjectName(Message, PageName.Value.Trim()))
     {
         return;
     }
     Util util = new Util();
     if(util.DoesAppExist(State,AppName.Value))
     {
         Message.Text = "The New App Name has already been used. Try another name";
         return;
     }
     Message.Text = "Saved.";
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        Init init = new Init();
        try
        {
            if (util.CheckSessionTimeout(State,Response,"Default.aspx")) return;
            if ( HttpRuntime.Cache["TechSupportEmail"] != null)
            {
                util.AddEmailToButton(SupportButton,  HttpRuntime.Cache["TechSupportEmail"].ToString(), "Email To Tech Support");
            }
            util.UpdateSessionLog(State, "post", "TabDesignWeb");

            ClearMessages();

            if (!IsPostBack)
            {
                CopyRight.InnerText = HttpRuntime.Cache["CopyRight"].ToString();
                UserLabel.Text = State["Username"].ToString();

                if (CurrentApp.Items.Count == 0 || CurrentApp.SelectedValue.Contains("->") ||
                              State["SelectedApp"] == null)
                {
                    init.InitAppsList(State, CurrentApp);
                }

                State["SelectedAppType"] = Constants.WEB_APP_TYPE;
                AppType.Text = Constants.WEB_APP_TYPE;
                State["UrlAccountIdentifier"] = util.GetUrlAccountIdentifier(State);
                UrlAccountIdentifier.Text = State["UrlAccountIdentifier"].ToString();

                if (State["SelectedApp"] == null || !util.DoesAppExist(State) || CurrentApp.SelectedIndex == 0)
                {
                    InitCurrentApp("->");
                    State["SelectedDeviceType"] = Constants.IPHONE;
                    DeviceType.Text = State["SelectedDeviceType"].ToString();
                }
                else if (State["SelectedApp"] != null)
                {
                    InitCurrentApp(State["SelectedApp"].ToString());
                }
            }
            DeletePage.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this page?');");

            if (State["ResetConfigApps"] != null)
            {
                State["SelectedApp"] = null;
                init.InitAppsList(State, CurrentApp);
                State["ResetConfigApps"] = null;
            }

            State["WebServiceValidated"] = null;
            if (State["SelectedDeviceType"] == null)
            {
                State["SelectedDeviceType"] = Constants.IPHONE;
                DeviceType.Text = State["SelectedDeviceType"].ToString();
             }
            SetAllAppNames();
        }
        catch (Exception ex)
        {
            util.ProcessMainExceptions(State, Response, ex);
        }
    }
    protected void SaveApp_Click(object sender, EventArgs e)
    {
        try
        {
            ClearMessages();
            if (SavedCanvasHtml.Text.Length > 0)
                SavePage();

            Util util = new Util();
            Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
            if ( State["SelectedApp"] == null ||
                !util.DoesAppExist(State) ||
                CurrentApp.SelectedIndex == 0)
            {
                return;
            }

            if ( State["CreatePageMessage"] != null)
            {
                StringBuilder sb = (StringBuilder) State["CreatePageMessage"];
                Message.Text += sb.ToString();
                InitAppPages();
            }
        }
        catch (Exception ex)
        {
            Util util = new Util();
            Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
            util.LogError(State, ex);
            Message.Text = "Internal Error: " + ex.Message + ": " + ex.StackTrace;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Init init = new Init();
        Util util = new Util();

        try
        {
            Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
            if (util.CheckSessionTimeout(State,Response,"Default.aspx")) return;

            if ( HttpRuntime.Cache["TechSupportEmail"] != null)
            {
                util.AddEmailToButton(SupportButton,  HttpRuntime.Cache["TechSupportEmail"].ToString(), "Email To Tech Support");
            }

            util.UpdateSessionLog(State, "post", "TabDesign");

            ClearMessages();

            if (!IsPostBack)
            {
                CopyRight.InnerText = HttpRuntime.Cache["CopyRight"].ToString();
                string attr = "javascript: NamedPopUp('ManageData.aspx', 'ManageDataPopup','height=800, width=1000, left=50, top=50, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=yes');return false;";
                ManageData.Attributes.Add("onclick", attr);

                UserLabel.Text = State["Username"].ToString();

                if (CurrentApp.Items.Count == 0 || CurrentApp.SelectedValue.Contains("->") ||
                              State["SelectedApp"] == null)
                {
                    init.InitAppsList(State, CurrentApp);
                }

                State["SelectedAppType"] = Constants.NATIVE_APP_TYPE;

                if (State["SelectedApp"] == null || !util.DoesAppExist(State) || CurrentApp.SelectedIndex == 0)
                {
                    InitCurrentApp("->");
                    State["SelectedDeviceType"] = Constants.IPHONE;
                    DeviceType.Text = State["SelectedDeviceType"].ToString();
                }
                else if (State["SelectedApp"] != null)
                {
                    InitCurrentApp(State["SelectedApp"].ToString());
                }
            }

            DeletePage.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this page?');");

            if (State["ResetConfigApps"] != null)
            {
                State["SelectedApp"] = null;
                init.InitAppsList(State, CurrentApp);
                State["ResetConfigApps"] = null;
            }

            State["WebServiceValidated"] = null;
            if (State["SelectedDeviceType"] == null)
            {
                State["SelectedDeviceType"] = Constants.IPHONE;
                DeviceType.Text = State["SelectedDeviceType"].ToString();
            }
            SetAllAppNames();
        }
        catch (Exception ex)
        {
            Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
            util.ProcessMainExceptions(State, Response, ex);
        }
    }