<?php
/*
	Freeway eCommerce
	http://www.openfreeway.org
	Copyright (c) 2007 ZacWare

	Released under the GNU General Public License 
*/	
// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
 echo tep_draw_form('contact_us', tep_href_link(FILENAME_CONTACT_US, 'action=send')); ?>
<table class="main-table">

      <h3><?php echo HEADING_TITLE; ?></h3>

<?php
  if ($messageStack->size('contact') > 0) {
?>
      <tr>
        <td><?php echo $messageStack->output('contact'); ?></td>
      </tr>
<?php
  }

  if (($FREQUEST->getvalue('action') == 'success')) {
?>
      <tr>
        <td class="main" align="center"><?php echo TEXT_SUCCESS; ?></td>
      </tr>
      <tr>
        <td><table width="100%" cellspacing="1" cellpadding="2" class="infoBox">
          <tr class="infoBoxContents">
            <td><table width="100%" cellpadding="2">
              <tr>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
                <td align="right"><?php echo '<div style="float:right"><a href="' . tep_href_link(FILENAME_DEFAULT) . '">' . tep_template_image_button('button_continue.gif', IMAGE_BUTTON_CONTINUE) . '</a></div>'; ?></td>
                <td width="10"><?php echo tep_draw_separator('pixel_trans.gif', '10', '1'); ?></td>
              </tr>
            </table></td>
          </tr>
        </table></td>
      </tr>
<?php
  } else {
?>
<?php   // cms_contact starting

$address =str_replace("\n","<br>",STORE_NAME_ADDRESS);
$query = "select * from email_messages where message_type = 'CON'";
$query = tep_db_query($query);
$result = tep_db_fetch_array($query);
$name = tep_draw_input_field('name','','').'<br>';
$mail = tep_draw_input_field('email','','') . '<br>';
$enquiry = tep_draw_textarea_field('enquiry', 'soft', 45, 15,'','');
$continue = tep_template_image_submit('button_send.gif', IMAGE_BUTTON_SEND);
$reset = tep_template_image_button_reset('button_reset.gif', IMAGE_BUTTON_RESET);
//text placeholders
$firstname = '<b>'.ENTRY_NAME.'</b>';
$lastname = '<b>'.ENTRY_LASTNAME.'</b>';
$message = '<b>'.ENTRY_MESSAGE.'</b>';
$email = '<b>'.ENTRY_EMAIL.'</b>';
//$replace_array = array('%%Name_Box%%'=>$name,'%%Email_Box%%'=>$mail,'%%Message_Box%%'=>$enquiry,'%%Continue_Button%%'=>$continue,'%%Reset_Button%%'=>$reset);
$replace_array = array(TEXT_TN1=>$name,TEXT_TN2=>$mail,TEXT_TN3=>$enquiry,TEXT_BT1=>$continue,TEXT_BT2=>$reset,TEXT_TM=>$message,TEXT_FN=>$firstname,TEXT_LN=>$lastname,TEXT_EM=>$email);
$body='<body>';
$body1='</body>';
//$messages=html_entity_decode($result['message_text']);
if(strpos($messages,html_entity_decode($body),0)!==false){
	$pos1=strpos($messages,html_entity_decode($body),0)+6;
	$messages=substr($messages,$pos1);
	$pos2=strpos($messages,html_entity_decode($body1),$pos1);
	$messages=substr($messages,0,$pos2);
} else $messages=$result['message_text'];

foreach($replace_array as $key=>$value){ 
	$messages = str_replace('%%'.$key.'%%',$value,$messages);
}
?>
      <tr>
        <td>
<!--cartzone contact details-->
<div class="main controls">
<?php 
 ?>
<?php echo $address; ?><br />
<a href="mailto:<?php echo STORE_OWNER_EMAIL_ADDRESS; ?>"><?php echo STORE_OWNER_EMAIL_ADDRESS; ?>
</a></div>        
</td>
  <tr>
     <td><?php echo $messages; ?></td>
  </tr>

<?php
  }
?>

    </table></form>
	<script type="text/javascript">
		function reset_form(){
			document.contact_us.reset();
		}
	</script>