<style type="text/css">
<!--
.style2 {
	font-size: 11px;
	font-weight: bold;
	font-family: Arial, Helvetica, sans-serif;
}
.style3 {font-family: Arial, Helvetica, sans-serif}
a:link {
	color: #000000;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #000000;
}
a:hover {
	text-decoration: underline;
	color: #000000;
}
a:active {
	text-decoration: none;
	color: #000000;
}
.style6 {font-size: 11px; font-weight: bold; font-family: Arial, Helvetica, sans-serif; color: #FF0000; }
body {
	background-color: #CCCCCC;
}
.style7 {color: #000000}
-->
</style>
<title>ENVIE A MAT&Eacute;RIA</title>
<H3 class="style3">ENVIE A MATÉRIA:</H3>
<span class="style6">
<%
Dim objCDONTS                 ' Email object
Dim strFromName               ' From persons' real name
Dim strFromEmail, strToEmail  ' Email addresses
Dim strSubject, strBody       ' Message
Dim strThisPage               ' This page's URL
Dim strReferringPage          ' The referring page's URL
Dim bValidInput               ' A boolean indicating valid parameters

' Retrieve this page name and referring page name
strThisPage      = Request.ServerVariables("SCRIPT_NAME")
strReferringPage = Request.ServerVariables("HTTP_REFERER")

' Debugging lines:
'Response.Write strThisPage & "<BR>" & vbCrLf
'Response.Write strReferringPage & "<BR>" & vbCrLf

' Read in and set the initial values of our message parameters
strFromName  = Trim(Request.Form("txtFromName"))
strFromEmail = Trim(Request.Form("txtFromEmail"))
strToEmail   = Trim(Request.Form("txtToEmail"))
strSubject   = "www.contee.org.br"
strBody      = Trim(Request.Form("txtMessage"))


' I set the body message to a message that referenced the page the
' user arrived from.  This makes it great if you place a link to it
' from your different articles, but can be weird if people link in
' from other web sites.
If strBody = "" Then
	If strReferringPage = "" Or InStr(1, strReferringPage, "www.contee.org.br", 1) = 0 Then
		strBody = ""
		strBody = strBody & "O link abaixo é uma sugestão de leitura: Legalização dará às seis centrais sindicais cerca de R$ 56 mi" & vbCrLf
		strBody = strBody & vbCrLf
		strBody = strBody & "http://www.contee.org.br/noticias/msoc/nmsoc373.asp" & vbCrLf
	Else
		strBody = ""
		strBody = strBody & "Gostaria que você le-se esse artigo:" & vbCrLf
		strBody = strBody & vbCrLf
		strBody = strBody & "   " & strReferringPage & vbCrLf
	End If
End If
	
' Quick validation just to make sure our parameters are somewhat valid
bValidInput = True
bValidInput = bValidInput And strFromName <> ""
bValidInput = bValidInput And IsValidEmail(strFromEmail)
bValidInput = bValidInput And IsValidEmail(strToEmail)

' If valid send email and show thanks, o/w show form
If bValidInput Then
	' Set up our email object and send the message
	Set objCDONTS = Server.CreateObject("CDONTS.NewMail")
	objCDONTS.From    = strFromName & " <" & strFromEmail & ">"
	objCDONTS.To      = strToEmail
	objCDONTS.Subject = strSubject
	objCDONTS.Body    = strBody
	objCDONTS.Send
	Set objCDONTS = Nothing

	' Show our thank you message
	ShowThanksMsg
Else
	If "http://" & Request.ServerVariables("HTTP_HOST") & strThisPage = strReferringPage Then
		Response.Write "Foi encontrado erro no preenchimento.  Por favor confira os dados:" & "<BR>" & vbCrLf
	End If
	' Show our information retrieval form
	ShowReferralForm strThisPage, strFromName, strFromEmail, strToEmail, strBody
End If
' End of page logic... subs and functions follow! 
%>
</span>


<%
' Subroutines and Functions that encapsulate some functionality
' and make the above code easier to write... and read.

' A quick email syntax checker.  It's not perfect,
' but it's quick and easy and will catch most of
' the bad addresses than people type in.
Function IsValidEmail(strEmail)
	Dim bIsValid
	bIsValid = True
	
	If Len(strEmail) < 5 Then
		bIsValid = False
	Else
		If Instr(1, strEmail, " ") <> 0 Then
			bIsValid = False
		Else
			If InStr(1, strEmail, "@", 1) < 2 Then
				bIsValid = False
			Else
				If InStrRev(strEmail, ".") < InStr(1, strEmail, "@", 1) + 2 Then
					bIsValid = False
				End If
			End If
		End If
	End If

	IsValidEmail = bIsValid
End Function

' I made this a function just to get it out of the
' logic and make it easier to read.  It just shows the
' form that asks for the input
Sub ShowReferralForm(strPageName, strFromName, strFromEmail, strToEmail, strBody)
	' I use script_name so users can rename this script witout having to change the code.
	%>
	<FORM ACTION="<%= strPageName %>" METHOD="post" name=frmReferral>
	<TABLE BORDER="0">
	<TR>
		<TD VALIGN="top" ALIGN="right"><span class="style2">Seu nome:</span></TD>
		<TD><INPUT TYPE="text" NAME="txtFromName" VALUE="<%= strFromName %>" SIZE="30"></TD>
	</TR>
	<TR>
		<TD VALIGN="top" ALIGN="right"><span class="style2">Seu e-mail:</span></TD>
		<TD><INPUT TYPE="text" NAME="txtFromEmail" VALUE="<%= strFromEmail %>" SIZE="30"></TD>
	</TR>
	<TR>
		<TD VALIGN="top" ALIGN="right"><span class="style2">Email a ser enviado:</span></TD>
		<TD><INPUT TYPE="text" NAME="txtToEmail" VALUE="<%= strToEmail %>" SIZE="30"></TD>
	</TR>
	<TR>
		<TD VALIGN="top" ALIGN="right"><span class="style2">Mensagem:</span></TD>
	  <TD><TEXTAREA NAME="txtMessage" COLS="40" ROWS="5" WRAP="virtual" READONLY><%= strBody %></TEXTAREA>	
	  </TR>
	<TR>
		<TD></TD>
		<TD><INPUT TYPE="reset" VALUE="Limpar" name=rstReferral>
		&nbsp;&nbsp;<INPUT TYPE="submit" VALUE="Enviar" name=subReferral></TD>
	</TR>
	</TABLE>
	</FORM>
<span class="style7">
<%
	'<P>The Message to be sent:</P>
	'<P><B>Subject:</B> < %= strSubject % ></P>
	'<P><B>Body:</B> < %= strBody % ></P>
End Sub

' This just shows our thank you message... probably didn't need to
' be a function, but since I made the form one I figured I'd do this
' for consistency.
Sub ShowThanksMsg()
	%>
</span>
	<P class="style2">Sua mensagem foi enviada com sucesso.
	  <span class="style7">
	  <%
End Sub
%>
</span>