Imports EDSL.Entities
Imports EDSL.DAL
Partial Public Class NewsletterSignup
    Inherits System.Web.UI.UserControl
    Dim objGlobals As New TheGlobals
    Dim strUserID As String ' = Session("uid").ToString
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim objMessage As New dbMainMessage
        divThankYou.InnerHtml = objMessage.GetMessage(objGlobals.Messages.Emailreceived)
		txtEmail.Attributes.Add("onfocus","selectclear('ctl00_rightcol1_ucNewsletter_txtEmail', 'Email Address');")
        txtEmail.Attributes.Add("onblur", "selectpopulate('ctl00_rightcol1_ucNewsletter_txtEmail', 'Email Address');")
        Dim test As String = Request.RawUrl.ToString()
        lnkButton.PostBackUrl = test
        'form1.Action = Request.RawUrl;  
        'divNLSignUpText.InnerHtml = objMessage.GetMessage(objGlobals.Messages.Newslettersubscription)
    End Sub
    Protected Sub btnSave_click(ByVal sender As Object, ByVal e As EventArgs) 'Handles btnSignUp.Click
        If Page.IsValid Then
            Dim objMain As New dbMainNLR
            Dim intResultFromSave As Integer
            intResultFromSave = objMain.SaveItem(0, txtEmail.Text, txtEmail.Text, strUserID)
            Select Case intResultFromSave
                Case 0
                    divFields.Visible = False
                    divErrorPanel.Visible = False
                    divThankYou.Visible = True
                Case 1
                    divErrorPanel.InnerHtml = "Error saving request"
            End Select

        End If
    End Sub

    Protected Sub CustomValidator1_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
        Dim objMain As New dbMainNLR
        Dim emailExists As New Boolean
        args.IsValid = True
        emailExists = objMain.CheckEmailAddressExists(txtEmail.Text)
        If emailExists Then
            args.IsValid = False
        End If

    End Sub
End Class
