
Partial Class PrintIt_OutSide
    Inherits System.Web.UI.MasterPage

    ''' <summary>
    ''' This Property defines the application path so that pages located in different
    ''' levels of directories can still access various depended parts of the master page
    ''' like top banner and javascript includes.
    ''' </summary>
    ''' <returns>(Modified) Request.ApplicationPath</returns>
    Public ReadOnly Property AppPath() As String
        Get
            If (Request.Equals(DBNull.Value)) Then
                Return "/"
            Else
                If (Request.ApplicationPath.Equals("/")) Then
                    Return "/"
                Else
                    Return Request.ApplicationPath & "/"
                End If                
            End If
        End Get
    End Property

    Protected _selectedLanguage As String = ""

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        'Dim _appPath As String = Request.ApplicationPath
        'Dim _lenStr As Integer = Len(_appPath)
        'If _lenStr > 0 Then
        '    Dim _str As String = Mid(_appPath, _lenStr)
        '    If _str = "/" Then
        '        _appPath = _appPath & "/"
        '    End If
        'End If
        If Request.QueryString("lang") IsNot Nothing Then
            _selectedLanguage = Request.QueryString("lang").ToString
        Else
            If Session("lang") IsNot Nothing Then
                _selectedLanguage = Session("lang").ToString
            Else
                If Request.Cookies("lang") IsNot Nothing Then
                    _selectedLanguage = Request.Cookies("lang").Value.ToString
                End If
            End If
        End If
        If _selectedLanguage.ToString() = "" Then _selectedLanguage = "en"
        Session("lang") = _selectedLanguage
        Response.Cookies("lang").Value = _selectedLanguage
        Response.Cookies("lang").Expires = DateTime.Now.AddYears(50)

        GetStartedImageButton.PostBackUrl = "~/create_user.aspx?lang=" & _selectedLanguage
        ' 
    End Sub


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.ServerVariables("URL") = "home.aspx" Then
            'Dim style As HtmlControl
            'style = CType(Me.Page.FindControl("ScreenStyle"), HtmlControl)
            'style.

            'Me.Page.Header.Controls.Add(

            '            Dim HtmlLink hlink = new HtmlLink();
            'hlink.Href = "Test.css";
            'hlink.Attributes["rel"] = "stylesheet";
            'hlink.Attributes["text"] = "text/css";

            'Header.Controls.Add(hlink ); 

        End If
		
		If (Request.ServerVariables("URL")) = "pbba" Then
			Response.Redirect("http://login.racadtech.com/go.aspx?t=386&discount_code=136")
		End If


        If _selectedLanguage = "en" Then
            EsDiv.Visible = True
            FrDiv.Visible = True
        ElseIf _selectedLanguage = "es" Then
            EnDiv.Visible = True
            FrDiv.Visible = True
        ElseIf _selectedLanguage = "fr" Then
            EnDiv.Visible = True
            EsDiv.Visible = True
        End If


        '
        ' ORDER CENTRE REDIRECT PROCEDURE.
        '
        Dim _subDomain As String = Request.Url.Host.ToString().Split(".")(0)
        If _subDomain.Equals("localhost") Then
            Session("StoreId") = 979 ' DEBUG ONLY.
        End If

        'Dim _domainName As String = Request.Url.Host.ToString()
        'Dim _commandString As Integer = "Select StoreId From PI_DomainName Where DomainName=" & _domainName
        'Dim _ws As New WebWS
        'Dim _storeId As Integer = _ws.GetValue(_commandString)
        'If _storeId <> 0 Then
        '    Session("StoreId") = _storeId
        '    Response.Redirect("~/order_centre/default.aspx")
        'Else
        '    Response.Redirect("https://www.goprint2.com/home.aspx")
        'End If

        If Request.Url.Host.ToString().Split(".").Length > 1 Then
            If Request.Url.Host.ToString().Split(".")(1) = "goprint2" Then
                If Not _subDomain.Equals("www") And Not _subDomain.Equals("") And Not _subDomain.Equals("localhost") And Not _subDomain.Equals("beta") Then
                    If (Session("Subdomain") Is Nothing) Then
                        Dim _storeId As Integer = 0
                        Dim _webWS As New WebWS()
                        _storeId = _webWS.GetStoreIdFromDomainName(_subDomain)

                        If Not _subDomain.Equals("www") Then
                            If _storeId = 0 Then
                                Response.Redirect("https://www.goprint2.com/home.aspx")
                            Else
                                Session("StoreId") = _storeId
                                Session("Subdomain") = _subDomain
				If (_storeId = 2066 Or _storeId = 1891 Or _storeId = 2579) Then
	                        	Response.Redirect("https://" & _subDomain & ".goprint2.com" & Request.ApplicationPath & "order_centre/default.aspx")
				Else
					Response.Redirect("https://" & _subDomain & ".goprint2.com" & Request.ApplicationPath & "webclient/index.aspx?direct=t")
				End If

                            End If
                        End If
                    Else
			If (Session("Subdomain").Equals("heartland") Or Session("Subdomain").Equals("carters") Or Session("Subdomain").Equals("tuffplans") ) Then
		            	Response.Redirect("https://" & Session("Subdomain") & ".goprint2.com" & Request.ApplicationPath & "order_centre/default.aspx")	                        				        
			Else				
				Response.Redirect("https://" & Session("Subdomain") & ".goprint2.com" & Request.ApplicationPath & "webclient/index.aspx?direct=t")
			End If
                    End If
                End If
            Else
                ' For customer own domains (not .goprint2.com)
                Dim _storeId As Integer = 0
                Dim _webWS As New WebWS()
                _storeId = _webWS.GetStoreIdFromDomainName(Request.Url.Host.ToString())
                Session("StoreId") = _storeId
                If _storeId <> 0 Then
                    Session("StoreId") = _storeId
                    Response.Redirect("https://" & Request.Url.Host.ToString() & "/order_centre/default.aspx")
                Else
                    Response.Redirect("https://www.goprint2.com/home.aspx")
                End If
            End If
        Else
            If Not _subDomain.Equals("www") And Not _subDomain.Equals("") And Not _subDomain.Equals("localhost") And Not _subDomain.Equals("beta") Then
                If (Session("Subdomain") Is Nothing) Then
                    Dim _storeId As Integer = 0
                    Dim _webWS As New WebWS()
                    _storeId = _webWS.GetStoreIdFromDomainName(_subDomain)

                    If Not _subDomain.Equals("www") Then
                        If _storeId = 0 Then
                            Response.Redirect("https://www.goprint2.com/home.aspx")
                        Else
                            Session("StoreId") = _storeId
                            Session("Subdomain") = _subDomain
                            Response.Redirect("https://" & _subDomain & ".goprint2.com" & Request.ApplicationPath & "order_centre/default.aspx")
                        End If
                    End If
                Else
                    Response.Redirect("https://" & Session("Subdomain") & ".goprint2.com" & Request.ApplicationPath & "order_centre/default.aspx")
                End If
            End If
        End If

    End Sub

    Protected Sub SpanishButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SpanishButton.Click
        Session("lang") = "es"
        Response.Cookies("lang").Value = "es"
        Response.Cookies("lang").Expires = DateTime.Now.AddYears(50)
        Response.Redirect(Request.Url.ToString)
    End Sub

    Protected Sub EnglishButtonn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles EnglishButton.Click
        Session("lang") = "en"
        Response.Cookies("lang").Value = "en"
        Response.Cookies("lang").Expires = DateTime.Now.AddYears(50)
        Response.Redirect(Request.Url.ToString)
    End Sub

    Protected Sub FrenchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles FrenchButton.Click
        Session("lang") = "fr"
        Response.Cookies("lang").Value = "fr"
        Response.Cookies("lang").Expires = DateTime.Now.AddYears(50)
        Response.Redirect(Request.Url.ToString)
    End Sub
End Class