<%@Language="VBScript" %>
<%
'###########################################################
'# Author:  Jesper Stocholm                                #
'# Date:    2003-06-18                                     #
'# Contact: dev@stocholm.dk                                #
'# Version: 0.9                                            #
'#                                                         #
'# Comments:                                               #
'# The purpose of this function is to enable blurring of   #
'# email adrresses on the web. Given an email address      #
'# as input it will generate a Hex-version of the address  #
'# - making it impossible to retrieve for some malicious   #
'# address spiders on the web.                             #
'#                                                         #
'#                                                         #
'# Disclaimer:                                             #
'# This code is provided "as is" and is to be used at your #
'# own risk. You can use this code as you wish as long as  #
'# you don't claim you wrote it. Should you decide to use  #
'# it, I would be greateful if you would send me an email  #
'# using the address above.                                #
'###########################################################

dim emailAddress,displayName,cssClass,onclickEvent	' as string

'# Creates anchor element to launch email application
'# Only mandatory value is emailAddress
private function BlurEmail(emailAddress,displayName,cssClass)
	dim sOut	' as string
	dim i		' as integer
	sOut = "<a href=" & chr(34) & "mailto:" & Hexify(emailAddress) & chr(34) 
	
	'# if css class is specified, add this to a-element attributes
	if not isNull(cssClass) then
		sOut = sOut & " class=" & chr(34) & Hexify(cssClass) & chr(34)
	end if
	
	sOut = sOut & ">"
	
	'# if display name is specified, add this to a-element value
	if isNull(displayName) then
		sOut = sOut & Hexify(emailAddress) & "</a>"
	else
		sOut = sOut & Hexify(displayName) & "</a>"
	end if
	
	'# Return and assign sOut to function
	BlurEmail = sOut
end function

'# Returns hexified value of input
private function Hexify(text)
	dim sOut	' as string
	dim i		' as integer
	for i = 1 to Len(text)
		sOut = sOut & "&#x" & Hex(Asc(Mid(text,i,1))) & ";"
	next
	Hexify = sOut
end function

'# Possible calls of the function
	'BlurEmail("youremail@domain.invalid","Your name","b")
	'BlurEmail("youremail@domain.invalid",null,"b")
	'BlurEmail("youremail@domain.invalid","Your Name",null)

%>
<html>
	<head>
		<style type="text/css">
			.b {font-size: 2.0em;}
		</style>
	</head>
	<body>
		<% = BlurEmail("youremail@domain.invalid","Your name","b") %>
		<br>
		<a href="../viewsource.asp?file=bluremail/bluremail.asp">View source</a>
	</body>
</html>