function valuationForm()
{
    global $db, $CONFIG;
    if (!$_POST) {
        $render = '
<form action="" method="post">
<div class="row">
<label>Department:</label>
<select name="dept">
<option value="sales">Sales</option>
<option value="lettings">Lettings</option>
</select>
</div>
<div class="row">
<label>Name:</label>
<input type="text" name="name" class="text" />
</div>
<div class="row">
<label>Email:</label>
<input type="text" name="email" class="text" />
</div>
<div class="row">
<label>Telephone:</label>
<input type="text" name="tel" class="text" />
</div>
<div class="row">
<label>Full address:</label>
<textarea name="address"></textarea>
</div>
<div class="row">
<label>Type of property:</label>
<select name="type">
<option value="house">House</option>
<option value="apartment">Apartment</option>
<option value="other">Other</option>
</select>
</div>
<div class="row">
<label>Prefered Date/Time:</label>
<textarea name="datetime"></textarea>
</div>

<div class="row">
<input type="submit" value="Send" class="submit" />
</div>
</form>
';
    } else {
        if (!clean_input($_POST['name'])) {
            $errors[] = 'Name';
        } else {
            $name = clean_input($_POST['name']);
        }
        if (!check_email($_POST['email'])) {
            $errors[] = 'Email (must be valid)';
        } else {
            $email = clean_input($_POST['email']);
        }
        if (!clean_input($_POST['tel'])) {
            $errors[] = 'Telephone';
        } else {
            $tel = clean_input($_POST['tel']);
        }
        if (!clean_input($_POST['address'])) {
            $errors[] = 'Address';
        } else {
            $address = clean_input($_POST['address']);
        }
        if (!clean_input($_POST['datetime'])) {
            $errors[] = 'Prefered Date/Time';
        } else {
            $datetime = clean_input($_POST['datetime']);
        }
        if ($errors) {
            $render = '<h3>Error</h3><p>The following fields are mandatory:</p>' . "\n<ul>";
            foreach ($errors as $error) {
                $render .= "<li>{$error}</li>\n";
            }
            $render .= "</ul>\n<p>Please <a href=\"javascript:goback();\">go back</a> and try again</p>";
        } else {
            if ($_POST['dept'] == "lettings") {
                $recipient = "*****@*****.**";
            } else {
                $recipient = "*****@*****.**";
            }
            $EmailSubject = "Valuation Request";
            // Message to Client
            $html_body = '<html>
<head></head>
<body>
<span style="font-family:Arial, Helvetica, sans-serif; font-size:13px; color:#000000">
<p>Hi ' . $name . ',</p>
<p>Many thanks for your valuation request. We will be in touch shortly to book an appointment.</p>
</span>
' . email_footer("html", $email, $name);
            $text_body = '
Hi ' . $strName . ',

Many thanks for your valuation request. We will be in touch shortly to book an appointment.

' . email_footer("text", $email, $name);
            $text = $text_body;
            $html = $html_body;
            $crlf = "\r\n";
            $hdrs = array('From' => $recipient, 'Subject' => $EmailSubject);
            $mime = new Mail_mime($crlf);
            $mime->setTXTBody($text);
            $mime->setHTMLBody($html);
            $body = $mime->get();
            $hdrs = $mime->headers($hdrs);
            $mail =& Mail::factory('mail');
            $mail->send($email, $hdrs, $body);
            // Message to Office
            $EmailBody = 'Name:			' . $name . '
Address:		' . $address . '
Tel:			' . $tel . '
Email:			' . $email . '
Property Type:	' . $type . '
Date/Time:		' . $datetime . '

Sent:			' . date('r') . '
';
            $text = $EmailBody;
            $crlf = "\r\n";
            $hdrs = array('From' => $email, 'Subject' => $EmailSubject);
            $mime = new Mail_mime($crlf);
            $mime->setTXTBody($text);
            $body = $mime->get();
            $hdrs = $mime->headers($hdrs);
            $mail =& Mail::factory('mail');
            $mail->send($recipient, $hdrs, $body);
            $render = '<p>Thank you for your message</p>';
        }
    }
    return $render;
}
    foreach ($_GET["dea_id"] as $dea) {
        $sql = "SELECT\n\tCONCAT(pro_addr3,' ',LEFT(pro_postcode,4)) AS pro_addr,\n\tdea_id,dea_type,dea_strapline,dea_marketprice,bra_title,bra_tel\n\tFROM deal\n\tLEFT JOIN property ON deal.dea_prop = property.pro_id\n\tLEFT JOIN branch ON deal.dea_branch = branch.bra_id\n\tWHERE deal.dea_id = {$dea} AND (dea_status = 'Available' OR dea_status = 'Under Offer' OR dea_status = 'Under Offer with Other' OR dea_status = 'Exchanged')\n\tGROUP BY dea_id\n\t";
        $q = $db->query($sql);
        if (DB::isError($q)) {
            die("db error: " . $q->getMessage() . $sql);
        }
        $numRows = $q->numRows();
        if ($numRows !== 0) {
            while ($row = $q->fetchRow()) {
                $props .= $row["dea_strapline"] . "\n" . $row["pro_addr"] . "\n" . number_format($row["dea_marketprice"]) . " (GBP)\n";
                //				$props .= "http://www.woosterstock.co.uk/Detail.php?id=" . $row["dea_id"] . "\n\n";
                $props .= "http://www.woosterstock.co.uk/details/" . $row["dea_id"] . ".html\n\n";
            }
        }
    }
    if ($results['Results']['cli_name']) {
        $render = 'Dear ' . $results['Results']['cli_name'] . ",\n\n";
    }
    if ($results['Results']['body']) {
        $render .= $results['Results']['body'] . "\n\n";
    }
    $render .= $props;
    $render .= "Regards,\n\n" . $_SESSION["auth"]["use_fname"] . ' ' . $_SESSION["auth"]["use_sname"] . "\n\n";
    $render .= email_footer('text', $results['Results']['cli_email'], $results['Results']['cli_name']);
    $headers = "From: " . $_SESSION["auth"]["use_fname"] . " " . $_SESSION["auth"]["use_sname"] . "<" . $_SESSION["auth"]["use_email"] . ">\r\n";
    $headers .= "BCC: " . $_SESSION["auth"]["use_email"] . "\r\n";
    mail($results['Results']['cli_email'], "Wooster & Stock", $render, $headers);
    //	header("Location:" . urldecode($_GET["searchLink"]));
    header("Location:" . WS_YII_URL . 'site/emailSentSuccess');
    exit;
}