protected void Timer1_Tick(object sender, EventArgs e)
    {
        try
        {
            HttpCookie cookie = Request.Cookies["BrowserDate"];
            Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));

            if (Session["AD4Count"] == null || Session["AD4DV"] == null)
                dat.GetAdSet(4, false);

            DataView dvAds = (DataView)Session["AD4DV"];
            int currentAdIndex = int.Parse(Session["AD4Count"].ToString());

            if (currentAdIndex < dvAds.Count - 1)
            {
                currentAdIndex++;
            }
            else
            {
                currentAdIndex = 0;
            }

            //Draw the next ad
            DrawAd(currentAdIndex, dvAds);
            Session["AD4Count"] = currentAdIndex;
            //Only count the ad when user is logged in.
            //If user not logged in, can't charge for the ads.

            //WE DONT NEED TO COUNT THE AD HERE, AD1 COUNTS ALL THE ADS FOR US

            //if (Session["User"] != null)
            //{
            //    dat.CountAd(false);
            //}
        }
        catch (Exception ex)
        {
            BodyLabel.Text = ex.ToString();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //Response.Cache.SetCacheability(HttpCacheability.NoCache);
        HttpCookie cookie = Request.Cookies["BrowserDate"];
        Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));

        try
        {
            if (!IsPostBack)
            {
                if (Session["User"] != null)
                {
                    if (Session["AD4Count"] == null || Session["AD4DV"] == null)
                        dat.GetAdSet(4, false);
                    else
                    {
                        if (Application[Session["User"].ToString() + "_Normal"] != null)
                        {
                            if (Application[Session["User"].ToString() + "_Normal"].ToString() == "set")
                            {
                                dat.GetAdSet(4, false);
                                Application[Session["User"].ToString() + "_Normal"] = null;
                            }
                        }
                    }
                }
                else
                {
                    if (Session["AD4Count"] == null || Session["AD4DV"] == null)
                        dat.GetAdSet(4, false);
                }

                DataBind2((DataView)Session["AD4DV"]);
            }
        }
        catch (Exception ex)
        {
            BodyLabel.Text = ex.ToString();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //Response.Cache.SetCacheability(HttpCacheability.NoCache);

        try
        {
            if (!IsPostBack)
            {
                HttpCookie cookie = Request.Cookies["BrowserDate"];
                Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));
                DateTime timeNow = DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":"));

                DataView dvUserAds;
                int lastSeen = 0;
                if (Request.Url.AbsolutePath.ToLower() == "/group.aspx")
                {
                    //If we are in the group, all we need to do is get
                    //ads that are in this location and in the groups categories
                    //plus ads that are only in the location and have displayToAll = 'True'
                    string commandStr = "";

                    dvUserAds = dat.GetGroupAds(Request.QueryString["ID"].ToString(), ref commandStr, ref lastSeen);
                }
                else
                {
                    dvUserAds = dat.GetAdSet(1, true);
                }

                DataBind2(dvUserAds, lastSeen);
            }
        }
        catch (Exception ex)
        {
            Errorlabel.Text = ex.ToString() + "<br/><br/>" + Request.Url.AbsolutePath.ToLower();
        }
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["BrowserDate"];
        try
        {
            Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));

            int currentAdIndex = 0;
            DataView dvAds = new DataView();
            if (Request.Url.AbsolutePath.ToLower() == "/group.aspx")
            {
                string commandStr = "";
                int lastSeen = 0;
                dvAds = dat.GetGroupAds(Request.QueryString["ID"].ToString(), ref commandStr, ref lastSeen);

                DataView dv = dat.GetDataDV("SELECT * FROM BigAdStatistics_Anonymous WHERE isGroup='True' AND SessionNum = '" +
                    Session["BigAnonymousGroupSession"].ToString() + "'");
                if (int.Parse(dv[0]["LastSeenIndex"].ToString()) == dat.NUMB_TOTAL_BIG_ADS - 1)
                    currentAdIndex = 0;
                else
                    currentAdIndex = int.Parse(dv[0]["LastSeenIndex"].ToString()) + 1;
            }
            else
            {
                if (Session["ADBigDV"] == null || Session["ADBigCount"] == null)
                    dat.GetAdSet(1, true);

                dvAds = (DataView)Session["ADBigDV"];
                currentAdIndex = int.Parse(Session["ADBigCount"].ToString());

                if (currentAdIndex < dvAds.Count - 1)
                {
                    currentAdIndex++;
                }
                else
                {
                    currentAdIndex = 0;
                }
            }

            //Draw the next ad
            DrawAd(currentAdIndex, dvAds);
            Session["ADBigCount"] = currentAdIndex;
        }
        catch (Exception ex)
        {
            Errorlabel.Text = ex.ToString();
        }
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies["BrowserDate"];
        try
        {
            Data dat = new Data(DateTime.Parse(cookie.Value.ToString().Replace("%20", " ").Replace("%3A", ":")));

            if (Session["AD1Count"] == null || Session["AD1DV"] == null)
                dat.GetAdSet(1, false);

            DataView dvAds = (DataView)Session["AD1DV"];

            int currentAdIndex = int.Parse(Session["AD1Count"].ToString());

            if (currentAdIndex < dvAds.Count - 1)
            {
                currentAdIndex++;
            }
            else
            {
                currentAdIndex = 0;
            }

            //Draw the next ad
            DrawAd(currentAdIndex, dvAds);
            Session["AD1Count"] = currentAdIndex;
            //Only count the ad when user is logged in.
            //If user not logged in, can't charge for the ads.

            if (Session["User"] != null)
            {
                dat.CountAd(false, dvAds);
            }
            else
            {
                dat.CountAdAnonymous(false, dvAds);
            }
        }
        catch (Exception ex)
        {

            BodyLabel.Text = ex.ToString();
            if (Session["testmessage"] != null)
            {
                BodyLabel.Text += Session["testmessage"].ToString();
            }
        }
    }