<?
include("before.php");
?>
<?
include("menu.php");
?>

<div id="content">

<?

$CONTACT_EMAIL = "lomartink@earthlink.net";

if(isset($_POST) and isset($_POST["posted"]))
	{
	
	$ip = $_SERVER['REMOTE_ADDR'];
	$httpref = $_SERVER['HTTP_REFERER'];
	$httpagent = $_SERVER['HTTP_USER_AGENT'];

	$visitorname = $_POST['visitorname']; 
	$visitorphone = $_POST['visitorphone']; 
	$visitoremail = $_POST['visitoremail']; 
	$message = $_POST['message'];

	/*
	if(eregi('http:', $message))
	{
		die("Do NOT try that! ! ");
	}
	*/
	
	if(empty($visitorname) || (empty($visitoremail) && empty($visitorphone)) || empty($message))
	{
		$warning = "Please provide a name, phone number or email address, and message and try again";
		print_contact_form($warning, $visitorname, $visitorphone, $visitoremail, $message);
	}
	else if(!$visitoremail == "" && (!strstr($visitoremail,"@") || !strstr($visitoremail,"."))) 
	{
		$warning = "Please enter a valid e-mail address and try again";
		print_contact_form($warning, $visitorname, $visitorphone, $visitoremail, $message);
	}
	else
	{
		// LOOKS GOOD!
		$todayis = date("l, F j, Y, g:i a") ;

		$subject = "Website Email query"; 

		$message = stripcslashes($message); 

		$emailmessage = " Submitted through the web site \n
$todayis [EST] 
From: $visitorname ($visitoremail)
Phone Number: $visitorphone
Message:

$message

Additional Info : IP = $ip 
Browser Info: $httpagent 
Referral : $httpref 
";

		$from = "From: $visitoremail\r\n";

		$ret = mail($CONTACT_EMAIL, $subject, $emailmessage, $from);
		//print "ret: $ret<br/>";
		if($ret == FALSE)
		{
			print_address();
			print "There was an error sending a message through this form.  Please contact our office via telephone, email, or post. We're sorry for the inconvenience.  Thank you for understanding.";
		}
		else
		{
			print_address();
			print "Thank you for contacting us.  We will get back to you shortly.";
		}
	}
}
else
{
	//print_contact_form("warning","a","b","c");
	print_contact_form("","","","","");
}

function print_address()
{
	print <<<EOF
<h1>Contact Us</h1>

<p>
100 Franklin Street, Third Floor<br/>
Boston, Massachusetts 02110<br/>
Telephone: 617-426-3050<br/>
Fax: 617-426-3640<br/>
</p>
EOF;
}

function print_contact_form($warning, $visitorname, $visitorphone, $visitoremail, $message)
{
	print_address();

	if(!$warning == "")
	{
		$warningtext = "<br/><font color=\"red\"><b>$warning</b></font><br/><br/>";
	}

	print <<<EOF
Please send us a message by filling out this form:<br/>

$warningtext

<form method="post" action="contact.php">

Your Name: <br/>
<input type="text" name="visitorname" size="35" value="$visitorname"/><br />
Your Phone Number:<br />
<input type="text" name="visitorphone" size="35" value="$visitorphone"/><br />
Your Email:<br />
<input type="text" name="visitoremail" size="35" value="$visitoremail"/><br />
Your Message:<br />
<textarea name="message" rows="4" cols="40">$message</textarea><br />

<input type="hidden" name="posted" value="true">

<input type="submit" value="Send Message" />
</form>
EOF;
}

?>

</div>

<?
include("after.php");
?>
