#!/usr/bin/perl

require "config.idx";

$long = $ENV{'QUERY_STRING'};
if ($long) {
	@pairs=split(/&/,$long);
	foreach $item(@pairs) {
		($name,$content)=split (/=/,$item,2);
		$content=~tr/+/ /;
		$content=~ s/%(..)/pack("c",hex($1))/ge;
		if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$content; }
		else { $INPUT{$name} = $content; }
	}
}
else {
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
	@pairs = split(/&/, $buffer);
	foreach $pair (@pairs) {
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
		else { $INPUT{$name} = $value; }
	}
}

&checklogin;

if ($INPUT{action} eq "show_flyer") { &show_flyer; }
else { &main; }

sub main {

### RUN CHECKS SET DEFAULTS

if ($INPUT{dis_photos} =~ "1") { $dis_photos_1 = "selected"; }
if ($INPUT{dis_photos} =~ "2") { $dis_photos_2 = "selected"; }
if ($INPUT{dis_photos} =~ "3") { $dis_photos_3 = "selected"; }
if ($INPUT{dis_photos} =~ "4") { $dis_photos_4 = "selected"; }
if ($INPUT{dis_photos} =~ "5") { $dis_photos_5 = "selected"; }
if ($INPUT{dis_photos} =~ "6") { $dis_photos_6 = "selected"; }
if ($INPUT{dis_photos} =~ "7") { $dis_photos_7 = "selected"; }
if ($INPUT{dis_photos} =~ "8") { $dis_photos_8 = "selected"; }
if ($INPUT{dis_photos} =~ "9") { $dis_photos_9 = "selected"; }
if ($INPUT{dis_photos} =~ "10") { $dis_photos_10 = "selected"; }
if ($INPUT{dis_photos} =~ "11") { $dis_photos_11 = "selected"; }
if ($INPUT{dis_photos} =~ "12") { $dis_photos_12 = "selected"; }
if ($INPUT{dis_photos} =~ "13") { $dis_photos_13 = "selected"; }
if ($INPUT{dis_photos} =~ "14") { $dis_photos_14 = "selected"; }
if ($INPUT{dis_photos} =~ "15") { $dis_photos_15 = "selected"; }
if ($INPUT{dis_photos} =~ "16") { $dis_photos_16 = "selected"; }
if ($INPUT{dis_photos} =~ "17") { $dis_photos_17 = "selected"; }
if ($INPUT{dis_photos} =~ "18") { $dis_photos_18 = "selected"; }
if ($INPUT{dis_photos} =~ "19") { $dis_photos_19 = "selected"; }
if ($INPUT{dis_photos} =~ "20") { $dis_photos_20 = "selected"; }
if ($INPUT{dis_photos} =~ "21") { $dis_photos_21 = "selected"; }
if ($INPUT{dis_photos} =~ "22") { $dis_photos_22 = "selected"; }
if ($INPUT{dis_photos} =~ "23") { $dis_photos_23 = "selected"; }
if ($INPUT{dis_photos} =~ "24") { $dis_photos_24 = "selected"; }
if ($INPUT{dis_photos} =~ "25") { $dis_photos_25 = "selected"; }
if ($INPUT{dis_photos} =~ "26") { $dis_photos_26 = "selected"; }
if ($INPUT{dis_photos} =~ "27") { $dis_photos_27 = "selected"; }
if ($INPUT{dis_photos} =~ "28") { $dis_photos_28 = "selected"; }
if ($INPUT{dis_photos} =~ "29") { $dis_photos_29 = "selected"; }
if ($INPUT{dis_photos} =~ "30") { $dis_photos_30 = "selected"; }


unless ($INPUT{dis_banner}) { $INPUT{dis_banner} = "NO BANNER"; }
if ($INPUT{dis_banner}) { $get_dis_banner = "<option value=\"$INPUT{dis_banner}\">$INPUT{dis_banner}</option><option value=\"$INPUT{dis_banner}\"> - - </option>"; }
if ($INPUT{remark_size}) { $get_remark_size = "<option value=\"$INPUT{remark_size}\">$INPUT{remark_size}</option><option value=\"$INPUT{remark_size}\"> - - </option>"; }

if ($INPUT{hotline_msg}) { } else { $INPUT{hotline_msg} = "FOR MORE INFO CALL 1-866-643-4111 EXT: ";}
if ($INPUT{hotline_code}) { } else { $INPUT{hotline_code} = "XXXX"; }



unless ($INPUT{remark_size}) { $INPUT{hotline_display} = "on"; $INPUT{show_price} = "on"; $INPUT{show_payment} = "on"; $INPUT{show_taxes} = "on"; }

if ($INPUT{hotline_display}) { $get_hotline_display = "checked"; }
if ($INPUT{show_price}) { $get_show_price = "checked"; }
if ($INPUT{show_payment}) { $get_show_payment = "checked"; }
if ($INPUT{show_taxes}) { $get_show_taxes = "checked"; }
if ($INPUT{hide_roommeasurements}) { $get_hide_roommeasurements = "checked"; }
print qq~
<link rel="stylesheet" href="hide.css" type="text/css" media="print">
<div class="hide">
<center>
<table width="751" border="0" cellpadding="2" cellspacing="0">
<tr>
<td colspan="5" valign="top" bgcolor="#999999"><b>FLYER DESIGN OPTIONS</b> <i>( Preview below )</i><br></td>
</tr>
<tr>
<form method="get" action="flyers_Residential_print.idx">
<input type="hidden" name="mlsnumber" value="$INPUT{mlsnumber}">
<td>
<b>Choose Banner</b><br>
	<select name="dis_banner" class="form">
	$get_dis_banner
	<option value="NO BANNER">NO BANNER</option>
	<option value="NEW LISTING">NEW LISTING</option>
	<option value="NEW PRICE">NEW PRICE</option>
	<option value="REDUCED">REDUCED</option>
	<option value="MUST SEE!">MUST SEE!</option>
	<option value="POOL">POOL</option>
	</select><br>
<b>Remarks Size</b><br>
<select name="remark_size" class="form">
$get_remark_size
<option value="8px">8px</option>
<option value="9px">9px</option>
<option value="10px">10px</option>
<option value="11px">11px</option>
<option value="12px">12px</option>
<option value="13px">13px</option>
<option value="14px">14px</option>
<option value="15px">15px</option>
<option value="16px">16px</option>
<option value="17px">17px</option>
<option value="18px">18px</option>
<option value="19px">19px</option>
<option value="20px">20px</option>
<option value="21px">21px</option>
<option value="22px">22px</option>
<option value="23px">23px</option>
<option value="24px">24px</option>
</select><br>
</td>
<td><b><a href="http://$INPUT{mlsnumber}.ORRHomes.com" target="_blank">Select Which Photos to Display</a> (30)</b><br>
	<select multiple size="6" name="dis_photos" class="form">
	<option value="1" $dis_photos_1>1</option>
	<option value="2" $dis_photos_2>2</option>
	<option value="3" $dis_photos_3>3</option>
	<option value="4" $dis_photos_4>4</option>
	<option value="5" $dis_photos_5>5</option>
	<option value="6" $dis_photos_6>6</option>
	</select>
	<select multiple size="6" name="dis_photos" class="form">
	<option value="7" $dis_photos_7>7</option>
	<option value="8" $dis_photos_8>8</option>
	<option value="9" $dis_photos_9>9</option>
	<option value="10" $dis_photos_10>10</option>
	<option value="11" $dis_photos_11>11</option>
	<option value="12" $dis_photos_12>12</option>
	</select>
	<select multiple size="6" name="dis_photos" class="form">
	<option value="13" $dis_photos_13>13</option>
	<option value="14" $dis_photos_14>14</option>
	<option value="15" $dis_photos_15>15</option>
	<option value="16" $dis_photos_16>16</option>
	<option value="17" $dis_photos_17>17</option>
	<option value="18" $dis_photos_18>18</option>
	</select>
	<select multiple size="6" name="dis_photos" class="form">
	<option value="19" $dis_photos_19>19</option>
	<option value="20" $dis_photos_20>20</option>
	<option value="21" $dis_photos_21>21</option>
	<option value="22" $dis_photos_22>22</option>
	<option value="23" $dis_photos_23>23</option>
	<option value="24" $dis_photos_24>24</option>
	</select>
	<select multiple size="6" name="dis_photos" class="form">
	<option value="25" $dis_photos_25>25</option>
	<option value="26" $dis_photos_26>26</option>
	<option value="27" $dis_photos_27>27</option>
	<option value="28" $dis_photos_28>28</option>
	<option value="29" $dis_photos_29>29</option>
	<option value="30" $dis_photos_30>30</option>
	</select>
</td>
<td>
<b>Message or Proquest 800#</b><br>
<input type="text" size="25" name="hotline_msg" value="$INPUT{hotline_msg}" class="form"><br>
<b>Proquest 800# Hotline</b><br>
Enter Code:<input type="text" size="5" name="hotline_code" value="$INPUT{hotline_code}" class="form"> <input type="checkbox" name="hotline_display" class="form" $get_hotline_display> <b><u>Show</u></b><br>

</td>
<td><b>Display</b><br>
<input type="checkbox" name="show_price" class="form" $get_show_price> <b><u>Price</u></b><br>
<input type="checkbox" name="show_payment" class="form" $get_show_payment> <b><u>Payment</u></b><br>
<input type="checkbox" name="show_taxes" class="form" $get_show_taxes> <b><u>Taxes</u></b><br>
<b>HIDE</b><br>
<input type="checkbox" name="hide_roommeasurements" class="form" $get_hide_roommeasurements> <b><u>Rooms</u></b><br>
</td>
<td valign="middle">
	<input type="checkbox" name="print_preview" class="form"> <b><u>Print Preview</u></b><br><br>
	<input type="submit" value="Update Flyer" class="form">
</td>
</form>
</tr>
</table>
</center>
<hr color="gray">
</div>
~;
&show_flyer;
}


sub show_flyer {

use DBI;
my $dsn = "DBI:mysql:database=$d_name;host=localhost";
my $dbh = DBI->connect($dsn, $d_username, $d_pass, {RaiseError => 1}) || die $DBI::errstr;

$oasth = $dbh->prepare("select * from listings_res3 where MLSNUM = ?");
$oasth->execute($INPUT{mlsnumber});

while ($data_ref = $oasth->fetchrow_hashref()) {
%db = %$data_ref;

$TotalSqFt = &commas($db{TotalSqFt});

unless ($INPUT{remark_size}) { $remark_size = "10px"; } else { $remark_size = "$INPUT{remark_size}"; }

($LivingRoomLength,$LivingRoomWidth) = split(/X/i,$db{LivingRoomSize});
($GreatRoomLength,$GreatRoomWidth) = split(/X/i,$db{GreatRoomSize});
($FamilyRoomLength,$FamilyRoomWidth) = split(/X/i,$db{FamilyRoomSize});
($KitchenLength,$KitchenWidth) = split(/X/i,$db{KitchenSize});
($DiningRoomLength,$DiningRoomWidth) = split(/X/i,$db{DiningRoomSize});
($DenStudyLength,$DenStudyWidth) = split(/X/i,$db{DenStudySize});
($Bedroom1Length,$Bedroom1Width) = split(/X/i,$db{Bedroom1Size});
($Bedroom2Length,$Bedroom2Width) = split(/X/i,$db{Bedroom2Size});
($Bedroom3Length,$Bedroom3Width) = split(/X/i,$db{Bedroom3Size});
($Bedroom4Length,$Bedroom4Width) = split(/X/i,$db{Bedroom4Size});
($Bedroom5Length,$Bedroom5Width) = split(/X/i,$db{Bedroom5Size});
($Bathroom1Length,$Bathroom1Width) = split(/X/i,$db{Bathroom1Size});
($Bathroom2Length,$Bathroom2Width) = split(/X/i,$db{Bathroom2Size});
($UtilityRoomLength,$UtilityRoomWidth) = split(/X/i,$db{UtilityRoomSize});
($OtherRoom1Length,$OtherRoom1Width) = split(/X/i,$db{OtherRoom1Size});
($OtherRoom2Length,$OtherRoom2Width) = split(/X/i,$db{OtherRoom2Size});
($OtherRoom3Length,$OtherRoom3Width) = split(/X/i,$db{OtherRoom3Size});
($Outbuilding1Length,$Outbuilding1Width) = split(/X/i,$db{Outbuilding1Size});



unless ($db{GreatRoomLevel}) {
$db{GreatRoomLevel} = "-";
}
unless ($db{FamilyRoomLevel}) {
$db{FamilyRoomLevel} = "-";
}
unless ($db{KitchenLevel}) {
$db{KitchenLevel} = "-";
}
unless ($db{DiningRoomLevel}) {
$db{DiningRoomLevel} = "-";
}
unless ($db{DenStudyLevel}) {
$db{DenStudyLevel} = "-";
}
unless ($db{Bedroom1Level}) {
$db{Bedroom1Level} = "-";
}
unless ($db{Bedroom2Level}) {
$db{Bedroom2Level} = "-";
}
unless ($db{Bedroom3Level}) {
$db{Bedroom3Level} = "-";
}
unless ($db{Bedroom4Level}) {
$db{Bedroom4Level} = "-";
}
unless ($db{Bedroom5Level}) {
$db{Bedroom5Level} = "-";
}
unless ($db{Bathroom1Level}) {
$db{Bathroom1Level} = "-";
}
unless ($db{Bathroom2Level}) {
$db{Bathroom2Level} = "-";
}
unless ($db{OtherRoom1Level}) {
$db{OtherRoom1Level} = "-";
}
unless ($db{OtherRoom2Level}) {
$db{OtherRoom2Level} = "-";
}
unless ($db{UtilityRoomLevel}) {
$db{UtilityRoomLevel} = "-";
}

unless ($db{LivingRoomLevel}) {
$db{LivingRoomLevel} = "-";
}

unless ($LivingRoomLength) {
$LivingRoomLength = "-";
}
unless ($LivingRoomWidth) {
$LivingRoomWidth = "-";
}
unless ($GreatRoomLength) {
$GreatRoomLength = "-";
}
unless ($GreatRoomWidth) {
$GreatRoomWidth = "-";
}
unless ($FamilyRoomLength) {
$FamilyRoomLength = "-";
}
unless ($FamilyRoomWidth) {
$FamilyRoomWidth = "-";
}
unless ($KitchenLength) {
$KitchenLength = "-";
}
unless ($KitchenWidth) {
$KitchenWidth = "-";
}
unless ($DiningRoomLength) {
$DiningRoomLength = "-";
}
unless ($DiningRoomWidth) {
$DiningRoomWidth = "-";
}
unless ($DenStudyLength) {
$DenStudyLength = "-";
}
unless ($DenStudyWidth) {
$DenStudyWidth = "-";
}
unless ($Bedroom1Length) {
$Bedroom1Length = "-";
}
unless ($Bedroom1Width) {
$Bedroom1Width = "-";
}
unless ($Bedroom2Length) {
$Bedroom2Length = "-";
}
unless ($Bedroom2Width) {
$Bedroom2Width = "-";
}
unless ($Bedroom3Length) {
$Bedroom3Length = "-";
}
unless ($Bedroom3Width) {
$Bedroom3Width = "-";
}
unless ($Bedroom4Length) {
$Bedroom4Length = "-";
}
unless ($Bedroom4Width) {
$Bedroom4Width = "-";
}
unless ($Bedroom5Length) {
$Bedroom5Length = "-";
}
unless ($Bedroom5Width) {
$Bedroom5Width = "-";
}
unless ($Bathroom1Length) {
$Bathroom1Length = "-";
}
unless ($Bathroom1Width) {
$Bathroom1Width = "-";
}
unless ($Bathroom2Length) {
$Bathroom2Length = "-";
}
unless ($Bathroom2Width) {
$Bathroom2Width = "-";
}
unless ($OtherRoom1Length) {
$OtherRoom1Length = "-";
}
unless ($OtherRoom1Width) {
$OtherRoom1Width = "-";
}
unless ($OtherRoom2Length) {
$OtherRoom2Length = "-";
}
unless ($OtherRoom2Width) {
$OtherRoom2Width = "-";
}
unless ($UtilityRoomLength) {
$UtilityRoomLength = "-";
}
unless ($UtilityRoomWidth) {
$UtilityRoomWidth = "-";
}

$LivingRoomLength =~ s/CHR1/\'/gi;
$LivingRoomWidth =~ s/CHR1/\'/gi;
$GreatRoomLength =~ s/CHR1/\'/gi;
$GreatRoomWidth =~ s/CHR1/\'/gi;
$FamilyRoomLength =~ s/CHR1/\'/gi;
$FamilyRoomWidth =~ s/CHR1/\'/gi;
$KitchenLength =~ s/CHR1/\'/gi;
$KitchenWidth =~ s/CHR1/\'/gi;
$DiningRoomLength =~ s/CHR1/\'/gi;
$DiningRoomWidth =~ s/CHR1/\'/gi;
$DenStudyLength =~ s/CHR1/\'/gi;
$DenStudyWidth =~ s/CHR1/\'/gi;
$Bedroom1Length =~ s/CHR1/\'/gi;
$Bedroom1Width =~ s/CHR1/\'/gi;
$Bedroom2Length =~ s/CHR1/\'/gi;
$Bedroom2Width =~ s/CHR1/\'/gi;
$Bedroom3Length =~ s/CHR1/\'/gi;
$Bedroom3Width =~ s/CHR1/\'/gi;
$Bedroom4Length =~ s/CHR1/\'/gi;
$Bedroom4Width =~ s/CHR1/\'/gi;
$Bedroom5Length =~ s/CHR1/\'/gi;
$Bedroom5Width =~ s/CHR1/\'/gi;
$Bathroom1Length =~ s/CHR1/\'/gi;
$Bathroom1Width =~ s/CHR1/\'/gi;
$Bathroom2Length =~ s/CHR1/\'/gi;
$Bathroom2Width =~ s/CHR1/\'/gi;
$OtherRoom1Length =~ s/CHR1/\'/gi;
$OtherRoom1Width =~ s/CHR1/\'/gi;
$OtherRoom2Length =~ s/CHR1/\'/gi;
$OtherRoom2Width =~ s/CHR1/\'/gi;
$UtilityRoomLength =~ s/CHR1/\'/gi;
$UtilityRoomWidth =~ s/CHR1/\'/gi;
$LivingRoomLength =~ s/CHR2/\"/gi;
$LivingRoomWidth =~ s/CHR2/\"/gi;
$GreatRoomLength =~ s/CHR2/\"/gi;
$GreatRoomWidth =~ s/CHR2/\"/gi;
$FamilyRoomLength =~ s/CHR2/\"/gi;
$FamilyRoomWidth =~ s/CHR2/\"/gi;
$KitchenLength =~ s/CHR2/\"/gi;
$KitchenWidth =~ s/CHR2/\"/gi;
$DiningRoomLength =~ s/CHR2/\"/gi;
$DiningRoomWidth =~ s/CHR2/\"/gi;
$DenStudyLength =~ s/CHR2/\"/gi;
$DenStudyWidth =~ s/CHR2/\"/gi;
$Bedroom1Length =~ s/CHR2/\"/gi;
$Bedroom1Width =~ s/CHR2/\"/gi;
$Bedroom2Length =~ s/CHR2/\"/gi;
$Bedroom2Width =~ s/CHR2/\"/gi;
$Bedroom3Length =~ s/CHR2/\"/gi;
$Bedroom3Width =~ s/CHR2/\"/gi;
$Bedroom4Length =~ s/CHR2/\"/gi;
$Bedroom4Width =~ s/CHR2/\"/gi;
$Bedroom5Length =~ s/CHR2/\"/gi;
$Bedroom5Width =~ s/CHR2/\"/gi;
$Bathroom1Length =~ s/CHR2/\"/gi;
$Bathroom1Width =~ s/CHR2/\"/gi;
$Bathroom2Length =~ s/CHR2/\"/gi;
$Bathroom2Width =~ s/CHR2/\"/gi;
$OtherRoom1Length =~ s/CHR2/\"/gi;
$OtherRoom1Width =~ s/CHR2/\"/gi;
$OtherRoom2Length =~ s/CHR2/\"/gi;
$OtherRoom2Width =~ s/CHR2/\"/gi;
$UtilityRoomLength =~ s/CHR2/\"/gi;
$UtilityRoomWidth =~ s/CHR2/\"/gi;

################ MORTGAGE CALCULATOR ### UPDATED 01/10/2010 ###########################

	$preprice = $db{Price};

	$principal = $db{Price}*0.965;
    $pmiupfront = $principal*0.0125;
    $principal = $principal+$pmiupfront;

	$interest = 4.0;
	$monthlyinterest = ($interest)/1200;
	$termyear = 30;
	$numberofmonths = $termyear*12;
	
	$temp = 1 + $monthlyinterest;
	
	$expon = 1;
	for ($p = 0; $p < $numberofmonths; $p++)
	{
		$expon = $temp * $expon;
	}
	
	$expon = 1 / $expon;
	$expon = 1 - $expon;
	$expon = $monthlyinterest / $expon;

	$mtax = $db{EstimatedAnnualTax};
	$mtax = $mtax / 12;	
	$mtax=sprintf("%.2f",$mtax);
	$mtax = &commas($mtax);

	$hyrinsurance = 500;
	$hyrinsurance=sprintf("%.2f",$hyrinsurance);
	$hyrinsurance = &commas($hyrinsurance);

	$hmoinsurance = $hyrinsurance / 12;

	$pmiyr = $principal*0.0066;
	$pmiyr=sprintf("%.2f",$pmiyr);
	$pmiyr = &commas($pmiyr);

	$pmimo = $pmiyr/12;	

	$monthlypayment = $principal * $expon;
	$monthlypayment = $monthlypayment + $mtax + $hmoinsurance + $pmimo;

	$monthlypayment=sprintf("%.2f",$monthlypayment);
	$monthlypayment = &commas($monthlypayment);

	$downpaymentrequired = $db{Price}*0.035;
	$downpaymentrequired=sprintf("%.2f",$downpaymentrequired);
	$downpaymentrequired = &commas($downpaymentrequired);

	$principal=sprintf("%.2f",$principal);
	$principal = &commas($principal);

##############################################################################

	$db{Price} = &commas($db{Price});
	$monthlypayment = &commas($monthlypayment);
	$mortgagetax = $db{EstimatedAnnualTax};
	$db{EstimatedAnnualTax} = &commas($db{EstimatedAnnualTax});


	$paymentdisclosure =qq~
	* Payment estimated on excellent credit and job history including: \$$db{Price} sales price with \$$principal loan amount (including upfront pmi and \$$downpaymentrequired downpayment, $interest% interest rate and \$$db{EstimatedAnnualTax} annual taxes, \$$hyrinsurance annual homeowners insurance and \$$pmiyr annual PMI insurance. Based on <b>estimated</b> FHA rates and loan terms as of August 13th, 2012.   For an exact payment on this property and to see if you may qualify please contact your lender.
	~;

if ($db{SaleRent} eq "S") {
$db{SaleRent} = "For Sale";
}
else {
$db{SaleRent} = "For Rent";
}

if ($db{Address2}) {
$db{Address2} = "$db{Address2}<br>";
}
else {
}

$printoffice =qq~

<table border="0" cellpadding="1" cellspacing="0">
<tr>
<td valign="top">
<img src="images/eagle_showlogo.gif" alt="Eagle Real Estate, Inc." width="57" height="55">
</td>
<td valign="middle">
<b><center><font face="Tahoma"><font size="3" color="navy"><b>For More Information Contact<br>The ORR Home Selling Team</b></font><br><font size="2" face="Arial">765-212-1111 Patrick  /  765-744-9500 Ryan</font></font></center></b>
</td>
</tr>
</table>
~;

$realoffice = "Listing Office; $db{ListingOffice1Name}, Listing Agent; $db{AgentName}";

@thefeatures = split(/\|/,$db{UsesFeaturesDataToChoose});

$startcount = "0";
foreach $one (@thefeatures) {

$yasth = $dbh->prepare("select featurename,categoryname from features where codenum = ?");
$yasth->execute($one);

while (($featurename,$categoryname) = $yasth->fetchrow_array()) {

$categoryname = lc($categoryname);
$featurename = lc($featurename);

$realname =~ s/CHR1/\'/gi;
$realname =~ s/CHR2/\"/gi;
$categoryname =~ s/CHR1/\'/gi;
$categoryname =~ s/CHR2/\"/gi;

$featurename = substr($featurename,0,13); if (length($featurename) >= 13) { $featurename .= ".."; }

$showfeaturestable .= "<td nowrap><img src=\"images/dot.gif\" height=\"7\" width=\"15\" alt=\"\">$categoryname <b>$featurename</b></td>\n";

if ($startcount eq "1") {
$showfeaturestable .= "</tr><tr>\n";
$startcount = "0";
}
else {
$startcount++;
}

}
}

### make sure values are not to long to mess up the display 01/18/2010 ####
$db{TaxIDNUM} = substr($db{TaxIDNUM},0,16); if (length($db{TaxIDNUM}) >= 16) { $db{TaxIDNUM} .= ".."; }
$db{ElementarySchool} = substr($db{ElementarySchool},0,12); if (length($db{ElementarySchool}) >= 12) { $db{ElementarySchool} .= ".."; }
$db{MiddleSchool} = substr($db{MiddleSchool},0,12); if (length($db{MiddleSchool}) >= 12) { $db{MiddleSchool} .= ".."; }
$db{HighSchool} = substr($db{HighSchool},0,12); if (length($db{HighSchool}) >= 12) { $db{HighSchool} .= ".."; }


$db{LandValue} = &commas($db{LandValue});
$db{ImproveValue} = &commas($db{ImproveValue});

if ($db{Zoning} eq "") {
$db{Zoning} = "Not Listed";
}

if ($db{Garage} eq "") {
$db{Garage} = "Not Listed";
}


if ($db{OutbuildingType} eq "") {
$db{OutbuildingType} = "Not Listed";
}

if ($db{TotalSqFt} eq "") {
$db{TotalSqFt} = "Not Listed";
}
else {
$db{TotalSqFt} = &commas($db{TotalSqFt});
}

if ($db{Reserved} eq "") {
$db{Reserved} = "Nothing Listed";
}

if ($db{ElementarySchool} eq "Pleasant View / Yorktown") {
$db{ElementarySchool} = "Pl. View/Yorktown";
}

&pull_photo_data_for_property_details_page_print($db{MLSNUM},1);  # routine at the bottom of config.idx


if ($totalpictures > 2) {
	   $showgallery = "<table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" bgcolor=\"#CCCCFF\"><tr>$showthumbs</tr></table><br>";
}
else {
   $showgallery = "";
}

if ($ENV{QUERY_STRING} =~ /City/) {
$showresultsback =qq~<a href="javascript:history.back()"><IMG SRC="images/display/top_returnsearch.gif" WIDTH=136 HEIGHT=32 ALT="" border="0"></a>~;
}
else {
$showresultsback =qq~<a href="propertysearch.idx?type=Residential"><IMG SRC="images/display/top_returnsearchcriteria.gif" WIDTH=136 HEIGHT=32 ALT="" border="0"></a>~;
}

$searchstrings = "City=$INPUT{City}&County=$INPUT{County}&MinPrice=$INPUT{MinPrice}&MaxPrice=$INPUT{MaxPrice}&MinBed=$INPUT{MinBed}&MinBath=$INPUT{MinBath}&Acreage=$INPUT{Acreage}&YBuilt=$INPUT{YBuilt}&MinSF=$INPUT{MinSF}&MaxSF=$INPUT{MaxSF}&elementaryschool=$INPUT{elementaryschool}&middleschool=$INPUT{middleschool}&highschool=$INPUT{highschool}&Address=$INPUT{Address}&Remarks=$INPUT{Remarks}&Show=$INPUT{Show}&sortby=$INPUT{sortby}&orderby=$INPUT{orderby}&Page=$INPUT{Page}";


if ($INPUT{print_preview} eq "on") {
print qq~
<script> 
function printpr()
{
var OLECMDID = 7;
/* OLECMDID values:
* 6 - print
* 7 - print preview
* 1 - open window
* 4 - Save As
*/
 
var PROMPT = 1; // 2 DONTPROMPTUSER
var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
 
WebBrowser1.ExecWB(OLECMDID, PROMPT);
WebBrowser1.outerHTML = "";
}
</script>
<SCRIPT language="JavaScript"> 
<!-- 
function closynoshowsme() 
{ 
window.opener='X'; 
window.open('','_parent',''); 
window.close();
} 
//--> 
</SCRIPT> 
~;
}

$db{Price} = "\$$db{Price}";
unless ($INPUT{show_price} eq "on") { $db{Price} = ""; }

print qq~
<html>
<head>
<title>The ORR Home Selling Team > $db{City} Real Estate Search > $db{AddressNumber} $db{AddressDirection} $db{AddressStreet}, $db{City}</title>
<script Language="JavaScript">
testurl = new Array($bigcount);

$buildscript



			function showupdate(photoIndex, photoDisplayType)
			{
			document['picture'].src = testurl[photoIndex];
			
			return;
			}
			
</script>
<link rel="stylesheet" TYPE="text/css" href="http://www.orrhomes.com/includes/style.css">
<script language="JavaScript" src="http://www.orrhomes.com/mm_menu.js"></script>

<style>
.image {
	position:relative;
}
.image .text {
	position:absolute;
	top:254px; /* in conjunction with left property, decides the text position */
	left:0px;
	width:368px; /* optional, though better have one */
    background: red;
    height: 18px;
    font-size: 13px;
    color: white;
    font-weight: bold;
}

.banner_holder {
	position:relative;
}

.banner {
position: absolute;
	top: 0px;
    left: 0px;
	padding-top: 5px;
    padding-right: 2px;
    padding-left: 2px;
	padding-bottom: 5px;
    background: red;
    font-size: 14px;
    color: white;
    font-weight: bold;
}
</style>

</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINwidth=0 MARGINheight=0>
<div align="center" style="position: relative;">
<div style="position: relative; width: 751px;">
<table width="751" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top" width="751">
			<img src="images/flyers/orrteam_flyers.jpg" width="751" height="105" alt=""><br></td>
		</td>
	</tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="751">
	<tr>
		<td valign="top" width="751">
<TABLE WIDTH=749 BORDER=0 CELLPADDING=0 CELLSPACING=0>
	<TR>
		<TD ROWSPAN=3>
			<IMG SRC="http://www.orrhomes.com/images/display/top_left_fill.gif" WIDTH=8 HEIGHT=69 ALT=""></TD>
		<TD COLSPAN=3 background="http://www.orrhomes.com/images/display/fill_address.gif" height="37" width="741">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
				<td valign="top" width="60%" nowrap>
					<div class="banner_holder">~;if ($INPUT{dis_banner} ne "NO BANNER") { print qq~<div class="banner">$INPUT{dis_banner}</div>~; } print qq~<font face="Arial Narrow" size="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$db{AddressNumber} $db{AddressDirection} $db{AddressStreet}, $db{City}</font><br></div>
				</td>
				<td valign="middle" width="25%" align="right">~; if ($INPUT{show_payment} eq "on") { print qq~<font color="navy"><b>estimated payment as <br>low as \$$monthlypayment / month*</b></font>~; } print qq~<br></td>
				<td valign="top" width="15%"><center><font face="Arial Narrow" size="5">$db{Price}</font><br></center></td>
				</td>
				</tr>
			</table>
		</TD>
	</TR>
	<TR>
		<TD ROWSPAN=2>
			<a href="javascript:history.back()"><IMG SRC="http://www.orrhomes.com/images/display/top_returnsearch_print.gif" WIDTH=136 HEIGHT=32 ALT="Print" border="0"></a><br>
		</TD>
		<TD ROWSPAN=2>
			<IMG SRC="http://www.orrhomes.com/images/display/top_residentialoverview.gif" WIDTH=400 HEIGHT=32 ALT=""></TD>
		<TD valign="top" background="http://www.orrhomes.com/images/display/fill_address.gif" height="22" width="205">
			<font size="3" face="Arial"><b>http://$db{MLSNUM}.<font face="Arial Narrow">ORRHomes</font>.com</b></font><br></TD>
	</TR>
	<TR>
		<TD>
			<IMG SRC="http://www.orrhomes.com/images/display/top_urlbottom.gif" WIDTH=205 HEIGHT=10 ALT=""></TD>
	</TR>
</TABLE>
<br>
<table border="0" cellpadding="0" cellspacing="0" width="751">
<tr>
<td width="375" valign="top">
	<table border="0" cellpadding="0" cellspacing="0" width="375">
	<tr>
		<td width="375" valign="top">
			<center>

<div class="image">
<img src="$showpicture" name=picture width="368" height="272"><br>
~;
if ($INPUT{hotline_display} eq "on") {
print qq~
  <div class="text">
    <p>$INPUT{hotline_msg}$INPUT{hotline_code}</p>
  </div>
</div>
~;
}
print qq~
			$showgallery</center>
		</td>
	</tr>
	</table>
</td>
<td width="1" valign="top">
	<img src="images/line_spacer.gif" height="1" width="1"><br>
</td>
<td width="375" valign="top" bgcolor="white">
<div style="font-size:$remark_size">$db{Remarks}</div><br>
<table border="0" cellpadding="1" cellspacing="0" width="375" bgcolor="#FFFF99">
	<tr>
		<td valign="top" width="100%" bgcolor="#000099" colspan="3"><font face="Tahoma" size="2" color="white"><b>General Information</b></font></td>
	</tr>
	<tr>
		<td valign="top" nowrap>
			<img src="images/dot.gif" height="7" width="15" alt="">Total Rooms <b>$db{Rooms}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Bedrooms <b>$db{Bedrooms}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Full Bathrooms <b>$db{FullBaths}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Half Bathrooms <b>$db{HalfBaths}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Square Feet <b>$db{TotalSqFt}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Year Built <b>$db{YearBuilt}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Acres <b>$db{Acres}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">County <b>$db{County}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Township <b>$db{Township}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Subdivision <b>$db{Subdivision}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Zoning <b>$db{Zoning}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
		</td>
		<td valign="top" width="1"><img src="iamges/line_spacer.gif" height="1" width="1"><br></td>
		<td valign="top" nowrap>
			<img src="images/dot.gif" height="7" width="15" alt="">Garage <b>$db{Garage}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Outbuilding <b>$db{OutbuildingType}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Tax ID <b>\#$db{TaxIDNUM}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Land Value <b>\$$db{LandValue}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Improv. Value <b>\$$db{ImproveValue}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Subdivision <b>$db{Subdivision}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Elem. School <b>$db{ElementarySchool}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">Middle School <b>$db{MiddleSchool}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif" height="7" width="15" alt="">High School <b>$db{HighSchool}</b><br><img src=images/line_spacer.gif height=1 width=1><br>
			~; if ($INPUT{show_taxes} eq "on") { print qq~ <img src="images/dot.gif" height="7" width="15" alt="">Est. Annual Taxes <b>\$$db{EstimatedAnnualTax}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br> ~; } print qq~
		</td>
	</tr>
	<tr>
		<td valign="top" colspan="3" width="100%">
		<table border="0" cellpadding="0" cellspacing="0" width="100%">
		<tr>
			<td valign="top" width="15"><img src="images/dot.gif" height="7" width="15" alt=""></td>
			<td valign="top" width="100%">Legal Description: <b>$db{Legal}</b><br></td>
		</tr>
		<tr>
			<td valign="top" width="15"><img src="images/dot.gif" height="7" width="15" alt=""></td>
			<td valign="top" width="100%">Reserved Items: <b>$db{Reserved}</b><br></td>
		</tr>
		<tr>
			<td valign="top" width="15"><img src="images/dot.gif" height="7" width="15" alt=""></td>
			<td valign="top" width="100%">Directions: <b>$db{Directions}</b><br></td>
		</tr>
		</table>
		</td>
	</tr>
</table>
<img src="images/line_spacer.gif" height="3" width="1"><br>
<table border="0" cellpadding="1" cellspacing="0" width="375" bgcolor="#FFFF99">
	<tr>
		<td valign="top" width="100%" bgcolor="#000099" colspan="3"><font face="Tahoma" size="2" color="white"><b>Property Features</b></font></td>
	</tr>
	$showfeaturestable
</table>
~;

if ($INPUT{hide_roommeasurements} eq "on") { } else {
print qq~
<img src="images/line_spacer.gif" height="3" width="1"><br>
<table border="0" cellpadding="1" cellspacing="0" width="375" bgcolor="#FFFF99">
	<tr>
		<td valign="top" width="100%" bgcolor="#000099" colspan="3"><font face="Tahoma" size="2" color="white"><b>Room Measurements</b></font></td>
	</tr>
	<tr>
		<td valign="top" width="100%">
    <table border="0" cellpadding="1" cellspacing="0" width="375">
              <tr bgcolor="CCCCFF"> 
                <td valign="top"><font color="#000099"><b>Room</b></font></td>
                <td valign="top"><div align="center"><font color="#000099"><b></b></font></div></td>
                <td valign="top">&nbsp;</td>
                <td valign="top"><div align="center"><font color="#000099"><b></b></font></div></td>
                <td valign="top"><div align="center"><font color="#000099"><b>Level</b></font></div></td>
                <td valign="top"><strong><font color="#000099">Room</font></strong></td>
                <td valign="top"><div align="center"><font color="#000099"><b></b></font></div></td>
                <td valign="top">&nbsp;</td>
                <td valign="top"><div align="center"><font color="#000099"><b></b></font></strong></div></td>
                <td valign="top"><div align="center"><font color="#000099"><b>Level</b></font></strong></div></td>
              </tr>
              <tr> 
                <td valign="top"><b>Bedroom 1</b></td>
                <td valign="top"><div align="center"><b>$Bedroom1Length</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$Bedroom1Width</b></div></td>
                <td valign="top"><div align="center"><b>$db{Bedroom1Level}</b></div></td>
                <td valign="top"><b>Kitchen</b></td>
                <td valign="top"><div align="center"><b>$KitchenLength</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$KitchenWidth</b></div></td>
                <td valign="top"><div align="center"><b>$db{KitchenLevel}</b></div></td>
              </tr>
              <tr bgcolor="#FFFFCC"> 
                <td valign="top"><b>Bedroom 2</b></td>
                <td valign="top"><div align="center"><b>$Bedroom2Length</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$Bedroom2Width</b></div></td>
                <td valign="top"><div align="center"><b>$db{Bedroom2Level}</b></div></td>
                <td valign="top"><b>Dining Room</b></td>
                <td valign="top"><div align="center"><b>$DiningRoomLength</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$DiningRoomWidth</b></div></td>
                <td valign="top"><div align="center"><b>$db{DiningRoomLevel}</b></div></td>
              </tr>
              <tr> 
                <td valign="top"><b>Bedroom 3</b></td>
                <td valign="top"><div align="center"><b>$Bedroom3Length</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$Bedroom3Width</b></div></td>
                <td valign="top"><div align="center"><b>$Bedroom3Level</b></div></td>
                <td valign="top"><b>Family Room</b></td>
                <td valign="top"><div align="center"><b>$FamilyRoomLength</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$FamilyRoomWidth</b></div></td>
                <td valign="top"><div align="center"><b>$db{FamilyRoomLevel}</b></div></td>
              </tr>
              <tr bgcolor="#FFFFCC"> 
                <td valign="top"><b>Bedroom 4</b></td>
                <td valign="top"><div align="center"><b>$Bedroom4Length</font></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$Bedroom4Width</b></div></td>
                <td valign="top"><div align="center"><b>$db{Bedroom4Level}</b></div></td>
                <td valign="top"><b>Den / Study</b></td>
                <td valign="top"><div align="center"><b>$DenStudyLength</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$DenStudyWidth</b></div></td>
                <td valign="top"><div align="center"><b>$db{DenStudyLevel}</b></div></td>
              </tr>
              <tr> 
                <td valign="top"><b>Bedroom 5</b></td>
                <td valign="top"><div align="center"><b>$Bedroom5Length</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$Bedroom5Width</b></div></td>
                <td valign="top"><div align="center"><b>$db{Bedroom5Level}</b></div></td>
                <td valign="top"><b>Other Room</b></td>
                <td valign="top"><div align="center"><b>$OtherRoom1Length</b></div></td>
                <td valign="top"><div align="center"><b>x</B></div></td>
                <td valign="top"><div align="center"><b>$OtherRoom1Width</b></div></td>
                <td valign="top"><div align="center"><b>$db{OtherRoom1Level}</b></div></td>
              </tr>
              <tr bgcolor="#FFFFCC"> 
                <td valign="top"><b>Bathroom 1</b></td>
                <td valign="top" colspan="4"><div align="center"><b>$Bathroom1Size</b></div></td>
                <td valign="top"><b>Other Room</b></td>
                <td valign="top"><div align="center"><b>$OtherRoom2Length</font></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$OtherRoom2Width</b></div></td>
                <td valign="top"><div align="center"><b>$db{OtherRoom2Level}</b></div></td>
              </tr>
              <tr> 
                <td valign="top"><b>Bathroom 2</b></td>
                <td valign="top" colspan="4"><div align="Center"><b>$Bathroom2Size</b></div></td>
	        <td valign="top"><b>Other Room</b></td>
                <td valign="top"><div align="center"><b>$OtherRoom3Length</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$OtherRoom3Width</b></div></td>
                <td valign="top"><div align="center"><b>$db{OtherRoom3Level}</b></div></td>
              </tr>
              <tr bgcolor="#FFFFCC"> 
                <td valign="top"><b>Living Room</font></td>
                <td valign="top"><div align="center"><b>$LivingRoomLength</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$LivingRoomWidth</b></div></td>
                <td valign="top"><div align="center"><b>$db{LivingRoomLevel}</b></div></td>
                <td valign="top"><b>Utility Room</b></td>
                <td valign="top"><div align="center"><b>$UtilityRoomLength</b></div></td>
                <td valign="top"><div align="center"><b>x</font></b></td>
                <td valign="top"><div align="center"><b>$UtilityRoomWidth</b></div></td>
                <td valign="top"><div align="center"><b>$db{UtilityRoomLevel}</b></div></td>
              </tr>
              <tr> 
                <td valign="top"><b>Great Room</font></td>
                <td valign="top"><div align="center"><b>$GreatRoomLength</b></div></td>
                <td valign="top"><div align="center"><b>x</b></div></td>
                <td valign="top"><div align="center"><b>$GreatRoomWidth</b></div></td>
                <td valign="top"><div align="center"><b>$db{GreatRoomLevel}</b></div></td>
                <td valign="top" colspan="5">&nbsp;</td>
              </tr>
            </table>
		</td>
	</tr>
</table>
~;
}
print qq~
</td>
</tr>
</table>
The information herein is believed to be accurate and timely, but no warranty as such is expressed or implied. IDX Information is provided for consumers' personal, non-commercial use.  <i><font color="#CCCCCC">$realoffice</i></font><br> ~;
if ($INPUT{show_payment} eq "on") { print qq~ $paymentdisclosure ~; }

$dbh->disconnect;
print qq~
</div>
</div>
~;
	if ($INPUT{print_preview} eq "on") {
		print qq~
		<script language="JavaScript" type="text/javascript"> 
		<!--
		printpr();
		 // -->
		</script>
		~;
		}
print qq~	
</body>
</html>
~;

}

}

sub commas {
	local($_)=@_;
	1 while s/(.*\d)(\d\d\d)/$1,$2/;
	$_;
}



