protected void AddTemplateApp_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return;

        if (AppName.Text.Length == 0)
        {
            Message.Text = "Enter your own name for this app.";
            return;
        }
        string new_app_name = AppName.Text.Trim();
        if (!Check.ValidateObjectName(Message, new_app_name))
        {
            return;
        }

        if(util.DoesAppExistInAccount(State,new_app_name))
        {
            Message.Text = "The app name " + new_app_name + " already exists. Enter a unique app name.";
            return;
        }

         State["NameForTemplateApp"] = new_app_name;
        Ready.Text = "OK";
    }
    protected void rowType_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        Util util = new Util();
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        rowType.SelectedValue = e.Value;
        switch (e.Value)
        {
            case "image1text|image,text":
            case "imagetext|image,text":
            case "2texts|text,text":
            case "1texthidden|text,hidden":
                FieldNameMessage.Text = "Enter 2 Field Names separated by a comma";
                 SectionPages.SelectedIndex = 1;
               break;
            case "image1texthidden|image,text,hidden":
            case "2textshidden|text,text,hidden":
            case "image2texts|image,text,text":
               FieldNameMessage.Text = "Enter 3 Field Names separated by a comma";
               SectionPages.SelectedIndex = 2;
               break;
            case "image2textshidden|image,text,text,hidden":
               FieldNameMessage.Text = "Enter 4 Field Names separated by a comma";
               SectionPages.SelectedIndex = 3;
               break;
            default:
                FieldNameMessage.Text = "Enter the Field Name";
                SectionPages.SelectedIndex = 0;
                break;
        }
    }
 protected void BuyButton_Click(object sender, EventArgs e)
 {
     Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
     Util util = new Util();
     if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;
     Response.Redirect("http://stores.homestead.com/MobiFlexStore/StoreFront.bok", true);
 }
    protected void DesignedForDevice_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        try
        {
            ClearMessages();

            DesignedForDevice.Text = e.Text;
            string device_design = e.Value;
            DeviceType.Text = e.Text;
            XmlUtil x_util = new XmlUtil();
            string previous_device_design = x_util.GetAppDeviceType(State);

            //State["SelectedDeviceView"] = device_design;
            State["SelectedDeviceType"] = device_design;
            if (State["SelectedApp"] == null || State["SelectedApp"].ToString().Contains("->"))
            {
                util.SetDefaultBackgroundForView(State,device_design);
            }

            x_util.SetAppDeviceType(State, previous_device_design, device_design);

            Message.Text = "Main device for App has been set.";
        }
        catch (Exception ex)
        {
            util.LogError(State, ex);
            Message.Text = "Internal Error: " + ex.Message + ": " + ex.StackTrace;
        }
    }
    protected void GetSpreadsheets_Click(object sender, EventArgs e)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        Util util = new Util();
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        ClearMessages();
        if (! State["AccountType"].ToString().Contains("google_apps"))
        {
            if (Username.Text.Length == 0)
            {
                SaveGoogleDocsInfoMessage.Text = "Enter your Google Docs account username.";
                return;
            }
            if (Password.Text.Length == 0)
            {
                SaveGoogleDocsInfoMessage.Text = "Enter your Google Docs account password.";
                return;
            }
            else
                 State["GDocsPassword"] = Password.Text.Trim();
        }
        GDocs gDocs = new GDocs();
        String ret = gDocs.GetSpreadsheets(State, AccountSpreadsheets, Username.Text.Trim(),Password.Text.Trim());
        if (ret != "OK")
            SaveGoogleDocsInfoMessage.Text = "Either the username or password was not valid. "+ ret;
    }
    protected void pickerType_SelectedIndexChanged(object o, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        Util util = new Util();
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        pickerType.SelectedValue = e.Value;
        SectionMessage.Visible = true;
        section_names.Visible = true;
        switch (e.Value)
        {
            case "time":
            case "date":
                SectionMessage.Visible = false;
                section_names.Visible = false;
                SectionPages.SelectedIndex = 0;
                break;
            case "1_section":
                SectionMessage.Text = "Enter the Section Name";
                SectionPages.SelectedIndex = 1;
                break;
            case "2_sections":
                SectionMessage.Text = "Enter 2 Section Names separated by a comma";
                SectionPages.SelectedIndex = 2;
                break;
            case "3_sections":
                SectionMessage.Text = "Enter 3 Section Names separated by commas";
                SectionPages.SelectedIndex = 3;
                break;
            case "4_sections":
                SectionMessage.Text = "Enter 4 Section Names separated by commas";
                SectionPages.SelectedIndex = 4;
                break;
        }
    }
    public void ResetDataResponseMap_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        ClearMessages();
        XmlDocument doc = util.GetStagingAppXml(State);
        XmlNode web_service_data_responses = doc.SelectSingleNode("//web_service_data_responses");
        if (web_service_data_responses != null)
        {
            web_service_data_responses.RemoveAll();
        }

        XmlNode phone_data_requests = doc.SelectSingleNode("//phone_data_requests");
        if (phone_data_requests == null)
            return;
        XmlNodeList event_fields = phone_data_requests.SelectNodes("phone_data_request/event_field");
        foreach (XmlNode event_field in event_fields)
        {
            XmlNode phone_data_request = event_field.ParentNode;
            XmlNodeList output_mappings = phone_data_request.SelectNodes("output_mapping");
            foreach (XmlNode output_mapping in output_mappings)
            {
                phone_data_request.RemoveChild(output_mapping);
            }
        }

        util.UpdateStagingAppXml(State);

        BuildWebServiceDataTrees(WebServiceEvents.SelectedItem.Text);
        ResponseMessage.Text = "Response Map Reset.";
        ResponseTreeEdits.Text = "";
    }
    /***************************************** Common Functions *******************************/
    public void ManageDataApps_SelectedIndexChanged(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        ClearMessages();

         State["ManageDataType"] = null;
        string app_name = Request.Form.Get("ManageDataApps");
        if (!app_name.Contains("->"))
        {
             State["SelectedApp"] = app_name;
            ManageDataApps.SelectedValue = app_name;
            InitDataTrees(app_name);
            ViewStoryBoard.Style.Value = "";
            ManageDataType.Style.Value = "";
            ManageDataTypeLabel.Style.Value = "";
        }
        else
        {
            ManageDataType.Style.Value = "display:none";
            ManageDataTypeLabel.Style.Value = "display:none";
            ViewStoryBoard.Style.Value = "display:none";
            util.ResetAppStateVariables(State);
            ContentMultiPage.SelectedIndex = 0;
            ShouldRefreshStoryBoard.Text = "close";
            Init init = new Init();
            init.InitManageDataAppsList(State);
            DataMultiPage.SelectedIndex = 3;
        }
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return;

        string name = UrlAccountIdentifier.Value.Trim();
        if (name.Length == 0)
        {
            Message.Text = "Enter Account Identifier Name";
            return;
        }
        if (!IsStringAlphaNumericPeriod(name) || name == ".")
        {
            Message.Text = "Domain Name should only use alphanumeric characters or '.'";
            return;
        }
        if (util.DoesUrlAccountIdentifierExist((Hashtable)HttpRuntime.Cache[Session.SessionID], name))
            Message.Text = "Account Identifier " + name + " is not Available.";
        else
        {
            UrlAccountIdentifier.Value = name;
            util.SaveUrlAccountIdentifier((Hashtable)HttpRuntime.Cache[Session.SessionID], name);
             State["UrlAccountIdentifier"] = name;
            Message.Text = "Account Identifier " + name + " has been saved. ";
        }
    }
    // Data members
    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", "TabPublish");

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

         //   SeeAllFields.Attributes.Add("onclick", "javascript: PopUp('../Help/Design/ViewAllNativeFields.htm', 'height=800, width=800, left=200, top=200, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=yes');return false;");
         //   LayoutVideo.Attributes.Add("onclick", "javascript: PopUp('../Help/Design/LayoutVideo.htm', 'height=325, width=570, left=200, top=200, menubar=no, status=no, location=no, toolbar=no, scrollbars=no, resizable=no');return false;");
         //   BasicFieldsVideo.Attributes.Add("onclick", "javascript: PopUp('../Help/Design/BasicFieldsVideo.htm', 'height=325, width=570, left=200, top=200, menubar=no, status=no, location=no, toolbar=no, scrollbars=no, resizable=no');return false;");

        }
        catch (Exception ex)
        {
            System.Diagnostics.Debug.WriteLine(ex.Message.ToString());
            throw;
        }
    }
    protected void EventField_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        Util util = new Util();
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        string selected_event_field = e.Text;
        if (selected_event_field.Contains("->"))
        {
            State["DataSourceEventType"] = null;
            State["DataSourceEventField"] = null;
        }
        else if (selected_event_field.Contains("("))
        {
            State["DataSourceEventType"] = "page";
            State["DataSourceEventField"] = null;
        }
        else
        {
            State["DataSourceEventType"] = "field";
            State["DataSourceEventField"] = selected_event_field;
        }
        State["DBCommands"] = null;

        EventField.FindItemByText(selected_event_field).Selected = true;

         if (selected_event_field.Contains("->"))
             ManageDataPanel.Style.Value = ManageDataPanel.Style.Value.Replace("block", "none");
         else
             ManageDataPanel.Style.Value = ManageDataPanel.Style.Value.Replace("none", "block");
    }
    protected void NumberOfUsers_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        NumberOfUsers.SelectedValue = e.Value;
        NumberOfUsers.Text = e.Text;
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return;

        if (NumberOfUsers.SelectedIndex == 1)
        {
            LimitedUsersPanel.Style.Value = "";
            UploadPublishedUserCredentials.Style.Value = "display:none";
            ViewPublishedUserCredentials.Style.Value = "display:none";
         }
        else
        {
            util.SetLimitedUsersCredentialMethod(State, false, "", "");
            LimitedUsersPanel.Style.Value = "display:none";
            UploadPublishedUserCredentials.Style.Value = "";
            ViewPublishedUserCredentials.Style.Value = "";
            UploadPublishedUserCredentials.Attributes.Add("onclick", PopupHelper.GeneratePopupScript(
         "../../Dialogs/Publish/UploadUserCredentials.aspx", 350, 800, false, false, false, true));
            ViewPublishedUserCredentials.Attributes.Add("onclick", PopupHelper.GeneratePopupScript(
        "../../Dialogs/Publish/ViewUserCredentials.aspx", 800, 350, false, false, false, true));

        }
    }
    protected void CopyApplicationButton_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        if (Applications.Text.IndexOf("->") > 0)
        {
            Message.Text = "Select Application.";
            return;
        }
        if (ToAccounts.Text.IndexOf("->") > 0)
        {
            Message.Text = "Select Destination Account.";
            return;
        }
        if (ToAccounts.Text == FromAccounts.Text)
        {
            Message.Text = "Select a Different Destination Account.";
            return;
        }

        string app_name = Applications.SelectedItem.Text;

        //copy application
        util.CopyAppToAccount(State, app_name);
        Message.Text = "Application Copy is Successful.";
    }
 protected void Credentials_SortCommand(object source, Telerik.Web.UI.GridSortCommandEventArgs e)
 {
     Util util = new Util();
     Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
     if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return;
     ShowCredentials();
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         HelpClick.Attributes.Add("onclick", PopupHelper.GeneratePopupScript(
                    "../../Help/Design/AppTypeHelp.htm", 260, 530, false, false, false, false));
         Util util = new Util();
         Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
         if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;
         XmlUtil x_util = new XmlUtil();
         AppType.Items.Clear();
         AppType.Items.Add(new RadComboBoxItem("Select ->", "->"));
         switch (State["SelectedAppType"].ToString())
         {
             case Constants.NATIVE_APP_TYPE:
                 AppType.Items.Add(new RadComboBoxItem("Web App Type (no accecss to native device resources)", Constants.WEB_APP_TYPE));
                 AppType.Items.Add(new RadComboBoxItem("Hybrid App Type", Constants.HYBRID_APP_TYPE));
                 break;
             case Constants.WEB_APP_TYPE:
                 AppType.Items.Add(new RadComboBoxItem("Native App Type", Constants.NATIVE_APP_TYPE));
                 AppType.Items.Add(new RadComboBoxItem("Hybrid App Type", Constants.HYBRID_APP_TYPE));
                  break;
             case Constants.HYBRID_APP_TYPE:
                  AppType.Items.Add(new RadComboBoxItem("Web App Type (no accecss to native device resources)", Constants.WEB_APP_TYPE));
                  AppType.Items.Add(new RadComboBoxItem("Native App Type", Constants.NATIVE_APP_TYPE));
                 break;
         }
     }
 }
    protected void PageIndexChanged(object source, Telerik.Web.UI.GridPageChangedEventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return;

        LoadData();
    }
    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;

        UploadMessage.Text = "";
    }
    protected void RejectButton_Click(object sender, EventArgs e)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        Util util = new Util();
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        Response.Redirect("Default.aspx", true);
    }
    protected void ManageBillingButton_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        Response.Redirect("http://stores.homestead.com/MobiFlexStore/StoreFront.bok?user="******"Username"].ToString(), true);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        Util util = new Util();
        if (util.CheckSessionTimeout(State,Response,"Default.aspx")) return;

        if (!IsPostBack)
        {

            XmlUtil x_util = new XmlUtil();
            if ( State["PageHtml"] == null) //get html if there is a selected app
                x_util.GetStagingAppXml(State);

            if ( State["PageHtml"] == null) //no selected app
                return;

            int left = 0;
            if (State["SelectedDeviceType"] != null &&
                (State["SelectedDeviceType"].ToString() == Constants.IPAD ||
                 State["SelectedDeviceType"].ToString() == Constants.ANDROID_TABLET))
            {
                State["BackgroundImageUrl"] = null;
                State["BackgroundHtml"] = null;
                     if ( State["BackgroundColor"] == null)
                         State["BackgroundColor"] = "#cccccc";

                    string background_color_div_prefix = null;
                    if (State["SelectedDeviceType"].ToString() == Constants.IPAD)
                        background_color_div_prefix = "<div style=\"border:0px;width:" + Constants.IPAD_SPLASH_PORTRAIT_WIDTH_S + "px;height:" + Constants.IPAD_SPLASH_PORTRAIT_HEIGHT_S + "px;vertical-align:top;background-color:" + State["BackgroundColor"].ToString() + "\" >";
                    else if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_TABLET)
                        background_color_div_prefix = "<div style=\"border:0px;width:" + Constants.ANDROID_TABLET_SPLASH_PORTRAIT_WIDTH_S + "px;height:" + Constants.ANDROID_TABLET_SPLASH_PORTRAIT_HEIGHT_S + "px;vertical-align:top;background-color:" + State["BackgroundColor"].ToString() + "\" >";

                    string background_color_div_suffix = "</div>";
                   html_content.Text = background_color_div_prefix +  State["PageHtml"].ToString() + background_color_div_suffix;

                     if (( State["SelectedAppPage"] == null || x_util.IsFirstAppPage(State,  State["SelectedAppPage"].ToString())) )
                    {
                        left = (State["SelectedDeviceType"].ToString() == Constants.IPAD) ? 731 : 763;
                        string background = "<img src=\"images/editor_images/settings_button.png\" style=\"position:absolute;top:5px;left:" + left.ToString() + "px\"/>";
                        html_content.Text += background;
                    }
            }
            else{
                left = 283;
                 if ( State["BackgroundImageUrl"] == null)
                      State["BackgroundImageUrl"] = "https://s3.amazonaws.com/MobiFlexImages/apps/images/backgrounds/standard_w_header_iphone.jpg";

                  string background = "<img id=\"background_image\" src=\"" + State["BackgroundImageUrl"].ToString() + "\" style=\"position:absolute;top:0px;left:0px;height:100%;width:100%\"/>";
                 if ((State["SelectedAppPage"] == null || x_util.IsFirstAppPage(State, State["SelectedAppPage"].ToString())) && State["SelectedAppType"].ToString() == Constants.NATIVE_APP_TYPE)
                 {
                     background += "<img src=\"images/editor_images/settings_button.png\" style=\"position:absolute;top:5px;left:" + left.ToString() + "px\"/>";
                 }

                 html_content.Text = background +  State["PageHtml"].ToString();
                  State["BackgroundHtml"] = background;
            }
        }
    }
    protected void Clear_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return;

        util.SetCustomHeaderHTML(State, "");
        Header.Text = "";
    }
    protected void PublishMenu_ItemClick(object sender, RadMenuEventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;

        string tab = e.Item.Value;
        Response.Redirect(tab, false);
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        util.SetAppDescription(State, AppDescription.Value);
        Message.Text = "App Description Saved.";
    }
    protected void UploadExcelFileButton_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return;

        if (this.FileUpload1.PostedFile != null)
        {
            // get the file
            HttpPostedFile file = this.FileUpload1.PostedFile;

            // check the length of the file
            if (file.ContentLength > 0)
            {
                string app_name =  ((Hashtable)HttpRuntime.Cache[Session.SessionID])["SelectedApp"].ToString();
                string application_id = util.GetAppID((Hashtable)HttpRuntime.Cache[Session.SessionID]);

                // get the Excel tables
                ExcelUtil excel_util = new ExcelUtil();
                DataTable[] excel_tables = excel_util.GetDataTablesFromExcelStream(file.InputStream);
                if (excel_tables == null || excel_tables.Length == 0)
                {
                    ErrorMessage.Text = "The file: '" + file.FileName + "' could not be processed as an Excel file.";
                    return;
                }

                 DataTable excel_table = excel_tables[0];
                 //string update_type = UploadType.SelectedIndex == 0 ? "add" : "replace";
                 string update_type =  "replace";

                //check on user limit
                 long max_users = util.GetMaxUsers((Hashtable)HttpRuntime.Cache[Session.SessionID]);
                if (max_users == 0 || max_users > 1000L)
                {
                    ErrorMessage.Text = "No paid ViziApps service allows any production credentials";
                    return;
                }

                if (excel_table.Rows.Count - 1 > max_users)
                {
                    ErrorMessage.Text = "The number of credentials in your Credentials File exceed the limit of the paid ViziApps service";
                    return;
                }

                StringBuilder errors = new StringBuilder("The file was successfully uploaded. Close this window.");

                util.UpdateUserCredentials((Hashtable)HttpRuntime.Cache[Session.SessionID], application_id, excel_table.Rows, update_type);

                ErrorMessage.Text = errors.ToString();
            }
            else
            {
                ErrorMessage.Text = "The file: '" + file.FileName + "' is empty.";
            }
        }
    }
    protected void imageList_SelectedIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        ImageList.FindItemByText(e.Text).Selected = true;
        SelectedImage.ImageUrl = e.Value;
        ScaleToFit(e.Value);
    }
    protected void CopyDesignToProduction_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        util.CopyStagingDesignToProduction(State);
        CopyDesignMessage.Text = "Done.";
        ProductionDesignExists.Visible = true;
    }
    protected void RejectButton_Click(object sender, EventArgs e)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        Util util = new Util();
        if (util.CheckSessionTimeout(State, Response, "Default.aspx")) return;
        State["LoggedInFromGoogleApps"] = null;
        Response.Redirect("Default.aspx", true);

        //string javascript = "<script type='text/javascript'>CloseWindow();</script>";
        //AddJavascript(javascript);
    }
    protected void DeleteAppDataSource_Click(object sender, ImageClickEventArgs e)
    {
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        Util util = new Util();
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        DataSources DS = new DataSources();
        string data_source_id = AppDataSources.Text.Substring(0,AppDataSources.Text.IndexOf(" ("));
        DS.DeleteAppDataSource(State, data_source_id);
        LoadData();
    }
    protected void DeleteSplashImage_Click(object sender, ImageClickEventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../../Default.aspx")) return;

        util.DeleteSplashImage(State, State["ApplicationID"].ToString());
        SplashUploadMessage.Text = "Splash Image Deleted.";
        ScreenSplashButton.Visible = false;
        DeleteSplashImage.Visible = false;
    }
    protected void Save_Click(object sender, EventArgs e)
    {
        Util util = new Util();
        Hashtable State = (Hashtable)HttpRuntime.Cache[Session.SessionID];
        if (util.CheckSessionTimeout(State, Response, "../Default.aspx")) return;

        State["BackgroundColor"] = System.Drawing.ColorTranslator.ToHtml(BackgroundColor.SelectedColor);
        XmlUtil x_util = new XmlUtil();
        x_util.SetBackgroundColor((Hashtable)HttpRuntime.Cache[Session.SessionID],  State["BackgroundColor"].ToString());
        Message.Text = "App Background Color has been saved.";
    }