'EMAIL - routines for using email addresses in MRC

external  fentrybox() messboxwait() chkstr() _GEMS_Input()
' "EMAIL ADDRESS","Enter or update",$emailaddr,50,0,"")

public    ptstr

global    ChkEmail() $email e x y


MAIN
local j r i n
	$email=""
	while true
  		$email=_GEMS_Input("EMAIL ADDRESS","Enter or update",$email,50,6,"")
message "$email is:"&str($email)

' 		x = fentrybox(" Enter email address (max 50 characters) ",50,$email,"")
' 		if x = -1
' 			continue while
' 		end if
' 		$email = ptstr

		if left($email,1)="@"
			messboxwait(" Invalid email address - 1st char is @ ",0,0,1)
			continue while
		end if
		if right($email,1)="."
			messboxwait(" Invalid email address - last char is .  ",0,0,1)
			continue while
		end if

		if right($email,1)="@"
			messboxwait(" Invalid email address - last char is @  ",0,0,1)
			continue while
		end if

		for j=1 to len($email)
			r = mid($email,j,1)			'
message "r is:"&str(r)
			if r=chr(64)
				exit while
			end if
		end for
		messboxwait(" Invalid email address format - no @ sign ",0,0,1)

	end while


' 	return (e)
END MAIN


FUNCTION ChkEmail(e)
local #e r j m

if left(e,1)="@"
	messboxwait(" Invalid email address - 1st char is @ ",0,0,1)
	return(1)
end if

if right(e,1)="."
	messboxwait(" Invalid email address - last char is .  ",0,0,1)
	return(1)
end if

message "e) is:"&str(e)

while true				'check that there is an @ sign
	for j=1 to len(e)
		r = mid(e,j,1)
		if r="@"
			exit while
		end if
	end for
	messboxwait(" Invalid email address format - no @ sign ",0,0,1)
	return(1)
end while

m=""
for j=1 to len(e)
	r = mid(e,j,1)
	if r = "@"
		for j=1 to len(e)-j
			r = mid(e,j,1)
message "r) is:"&str(r)
			m = m|r
message "m) is:"&str(m)
		end for
	end if
message "m) is:"&str(m)
'     m = m|r
  end for

END FUNCTION 'ChkEmail()


