#!/usr/bin/perl

print "Content-type: text/html\n\n";

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; }
	}
}


@rawCookies = split(/;/,$ENV{'HTTP_COOKIE'});
foreach (@rawCookies) {
	($cookieName, $cookieValue) = split(/=/,$_);
	$cookieName =~ s/ //gi;
	$Cookies{$cookieName}=$cookieValue;
}


$sql_query = qq~select MLSNUM from listings_res3 where Status = '1' ~;

@search_vars = ();

$INPUT{Show} = "10" unless $INPUT{Show};
$INPUT{Show} = "50" if ($INPUT{Show} > '50');

$INPUT{MinPrice} =~ s/\,//gi;
$INPUT{MaxPrice} =~ s/\,//gi;
$INPUT{MinPrice} =~ s/\$//gi;
$INPUT{MaxPrice} =~ s/\$//gi;

if ($INPUT{City}) {
$sql_query .= "AND (";
	(@City) = split(/\,/, $INPUT{City});
	foreach $cit (@City) {
	$sql_query .= "City = ? OR ";
	push @search_vars, $cit;
	}
$sql_query .= "ENDOFFIELD";
$sql_query =~ s/ OR ENDOFFIELD//gi;
$sql_query .= ") ";
}

#if ($INPUT{County}) {
#$sql_query .= "AND (";
#	(@County) = split(/\,/, $INPUT{County});
#	foreach $county (@County) {
#	$sql_query .= "County = ? OR ";
#	push @search_vars, $county;
#	}
#$sql_query .= "ENDOFFIELD";
#$sql_query =~ s/ OR ENDOFFIELD//gi;
#$sql_query .= ") ";
#}


if ($INPUT{MinPrice}) {
$sql_query .= "AND Price >= ? ";
push @search_vars, $INPUT{MinPrice};
}

if ($INPUT{MaxPrice}) {
$sql_query .= "AND Price <= ? ";
push @search_vars, $INPUT{MaxPrice};
}

if ($INPUT{MinBed}) {
$sql_query .= "AND Bedrooms >= ? ";
push @search_vars, $INPUT{MinBed};
}

if ($INPUT{MinBath}) {
$sql_query .= "AND FullBaths >= ? ";
push @search_vars, $INPUT{MinBath};
}

if ($INPUT{Acreage}) {
$sql_query .= "AND Acres >= ? ";
push @search_vars, $INPUT{Acreage};
}

if ($INPUT{YBuilt}) {
$sql_query .= "AND YearBuilt >= ? ";
push @search_vars, $INPUT{YBuilt};
}

if ($INPUT{MinSF}) {
$sql_query .= "AND TotalSqFt >= ? ";
push @search_vars, $INPUT{MinSF};
}

if ($INPUT{MaxSF}) {
$sql_query .= "AND TotalSqFt <= ? ";
push @search_vars, $INPUT{MaxSF};
}

if ($INPUT{elementaryschool}) {
$sql_query .= "AND (";
	(@elementaryschool) = split(/\,/, $INPUT{elementaryschool});
	foreach $elemschool (@elementaryschool) {
	$sql_query .= "ElementarySchool = ? OR ";
	push @search_vars, $elemschool;
	}
$sql_query .= "ENDOFFIELD";
$sql_query =~ s/ OR ENDOFFIELD//gi;
$sql_query .= ") ";
}

if ($INPUT{middleschool}) {
$sql_query .= "AND (";
	(@middleschool) = split(/\,/, $INPUT{middleschool});
	foreach $school (@middleschool) {
	$sql_query .= "MiddleSchool = ? OR ";
	push @search_vars, $school;
	}
$sql_query .= "ENDOFFIELD";
$sql_query =~ s/ OR ENDOFFIELD//gi;
$sql_query .= ") ";
}

if ($INPUT{highschool}) {
$sql_query .= "AND (";
	(@highschool) = split(/\,/, $INPUT{highschool});
	foreach $school (@highschool) {
	$sql_query .= "HighSchool = ? OR ";
	push @search_vars, $school;
	}
$sql_query .= "ENDOFFIELD";
$sql_query =~ s/ OR ENDOFFIELD//gi;
$sql_query .= ") ";
}

if ($INPUT{Address}) {
$sql_query .= "AND AddressStreet LIKE ? ";
push @search_vars, '%' . $INPUT{Address} . '%';
}

if ($INPUT{Remarks}) {
$sql_query .= "AND Remarks LIKE ? ";
push @search_vars, '%' . $INPUT{Remarks} . '%';
}

if ($INPUT{sortby}) {
$sql_query .= "ORDER BY $INPUT{sortby}";
#push @search_vars, $INPUT{sortby};
}

if ($INPUT{orderby}) {
$sql_query .= " $INPUT{orderby}";
#push @search_vars, $INPUT{orderby};
}


if ($sql_query =~ / AND /i) {

   $qqsth = $dbh->prepare($sql_query);
   $qqsth->execute(@search_vars);

   while (my($ml_num) = $qqsth->fetchrow_array()) {
      $total_count++;
      $listing_order_number{$ml_num} = $total_count;
      $previous_listing{$ml_num} = $previous_mls_number;
      $next_listing{$previous_mls_number} = $ml_num;
      $previous_mls_number = $ml_num;
   }

}



$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});




($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 #####################################

	$preprice = $db{Price};

	$principal = "$db{Price}";
	$interest = 6.5;
	$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;	

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

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



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

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


	$paymentdisclosure =qq~
	* Payment based on $db{Price} sales price at 6.5% interest rate and $db{EstimatedAnnualTax} annual taxes.  Payment does not include homeowners insurance, possible PMI insurance.   For an exact payment on this property you will want to seek a mortgage officer.
	~;

if ($db{VirtualTourURL} =~ /http|www|visualtour/i) { $toururl =qq~<a href="$db{VirtualTourURL}" target="_blank"><img src="images/viewvirtualtour.jpg" height="30" width="368" alt="Click to View Virtual Tour" border="0"></a><br><br>~; }

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

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

if ($db{ListingOffice1ID} eq "48") {
	if ($db{CoAgentID} eq "") {
	$db{CoAgentID} = "";
	}
	else {
	$db{CoAgentID} = "<a href=agents.idx?action=showagent&agent=$db{CoAgentID}>$db{CoAgentName}</a><br>";
	}	
$AgentName = "<a href=agents.idx?action=showagent&agent=$db{AgentID}>$db{AgentName}</a>";
$printoffice = qq~
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td>
<img src=images/era_showlogo.gif>
</td>
<td valign="top">
<font size="3"><b>Offered By:</b><br><a href="http://www.munciemls.com/agents.idx?action=showagent&agent=$db{AgentID}">$db{AgentName}</a><br>$db{CoAgentID}$db{ListingOffice1Name}</font><br>
</td>
<td>
<img src=images/era_showlogo.gif>
</td>
</tr>
</table>
~;
}
else {
	if ($db{CoAgentID} eq "") {
	$db{CoAgentID} = "";
	}
	else {
	$db{CoAgentID} = "$db{CoAgentName}<br>";
	}

$printoffice =qq~

<table border="0" cellpadding="1" cellspacing="0">
<tr>
<td valign="top">
<img src="images/remax_showlogo.gif" alt="RE/MAX Real Estate Groups Muncie" 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><br><font size="4">765-212-1111 Office</font></font></center></b>
</td>
</tr>
</table>
~;

$realoffice =qq~<font size="2"><b>Property Information Provided by:</b><br>Listing Office; $db{ListingOffice1Name}<br>Listing Agent; $db{AgentName}<br>Source; Mid-Eastern Indiana Assoc. of REALTORS<br></font>~;
}




@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;


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

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

}
}







if ($db{Garage}) {
$fGarage = "<img src=images/dot.gif>Garage <b>$db{Garage}</b><img src=images/line_spacer.gif height=1 width=1><br>";
}
else {
}



if ($db{YearBuilt}) {
$fYearBuilt = "<img src=images/dot.gif>Year Built <b>$db{YearBuilt}</b><br>";
}
else {
}

if ($db{OutbuildingType}) {
$fOutbuildingType = "<img src=images/dot.gif>Outbuilding <b>$db{OutbuildingType}</b><img src=images/line_spacer.gif height=1 width=1><br>";
}
else {
}



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



if (-e "/home/muncieml/public_html/pdf/$db{MLSNUM}\.pdf") {
$showpdf = "
<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\">
<tr>
<td valign=\"top\">
<a href=\"pdf/$db{MLSNUM}.pdf\" target=\"_blank\"><img src=\"images/pdficon.gif\" border=\"0\"></a><br>
</td>
<td valign=\"middle\">
<a href=\"pdf/$db{MLSNUM}.pdf\" target=\"_blank\" class=\"pdf\">View Full Color PDF Brochure</a><br>
</td>
</tr>
</table>
";
}


if (-e "/home/muncieml/public_html/pdf/$db{MLSNUM}a\.pdf") {
$showpdf .= "
<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\">
<tr>
<td valign=\"top\">
<a href=\"pdf/$db{MLSNUM}a.pdf\" target=\"_blank\"><img src=\"images/pdficon.gif\" border=\"0\"></a><br>
</td>
<td valign=\"middle\">
<a href=\"pdf/$db{MLSNUM}a.pdf\" target=\"_blank\" class=\"pdf\">View Full Color PDF Brochure</a><br>
</td>
</tr>
</table>
";
}

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

if ($ENV{QUERY_STRING} =~ /City/) {
$check_back =qq~<a href="javascript:history.back()"><img src="images/top_pn_back.gif" width="49" height="27" alt="" border="0"></a>~;
}
else {
$check_back =qq~<a href="propertysearch.idx?type=Residential"><img src="images/top_pn_back.gif" width="49" height="27" 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 ($listing_order_number{$db{MLSNUM}} eq "1" || $listing_order_number{$db{MLSNUM}} eq "") {
$check_prev =qq~<img src="images/top_pn_prev_na.gif" width="44" height="13" alt="">~;
$listing_order_number{$db{MLSNUM}} = "1";
}
else {
$check_prev =qq~<a href="?$searchstrings&mlsnumber=$previous_listing{$db{MLSNUM}}"><img src="images/top_pn_prev.gif" width="44" height="13" alt="Go To Previous Listing" border="0"></a>~;
}



if ($listing_order_number{$db{MLSNUM}} eq $total_count || $total_count eq "") {
$check_next =qq~<img src="images/top_pn_next_na.gif" width="43" height="13" alt="">~;
$total_count = "1";
}
else {
$check_next =qq~<a href="?$searchstrings&mlsnumber=$next_listing{$db{MLSNUM}}"><img src="images/top_pn_next.gif" width="43" height="13" alt="Go To Next Listing" border="0"></a>~;
}

if ($INPUT{gate} eq "email") {
$checksave = "";
}
else {
$checksave = "<a href=\"javascript:save=window.open('save.idx?mlsnumber=$db{MLSNUM}&type=res','save','width=320, height=325, scrollbars=no'); save.focus();\"><img src=\"images/actions/savethishome.gif\" border=0></a><br>";
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<title>$db{City} Real Estate Search > $db{AddressNumber} $db{AddressDirection} $db{AddressStreet}, $db{City} > Patrick & Ryan Orr  The ORR Home Selling Team RE/MAX Real Estate Groups</title>
<script Language="JavaScript">
testurl = new Array($bigcount);

$buildscript



			function showupdate(photoIndex, photoDisplayType)
			{
			document['picture'].src = testurl[photoIndex];
			
			return;
			}
			
</script>



STARTOFTHEPAGE

&header_listings;




print qq~
<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="images/display/top_left_fill.gif" WIDTH=8 HEIGHT=69 ALT=""></TD>
		<TD COLSPAN=3 background="images/display/fill_address.gif" height="37" width="741">
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr>
				<td valign="top" width="60%">
					<font face="Arial Narrow" size="5">$db{AddressNumber} $db{AddressDirection} $db{AddressStreet}, $db{City}</font><br>
				</td>
				<td valign="middle" width="25%" align="right"><font color="navy"><b>payments as low<br><a href="javascript:mortgagechange=window.open('mortgagechange.idx?price=$preprice&mlsnum=$db{MLSNUM}&mortgagetax=$db{EstimatedAnnualTax}','mortgagechange','width=384, height=385, scrollbars=yes'); mortgagechange.focus();">[Change]</a> as \$$monthlypayment*</b></font><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>
			<table border="0" cellpadding="0" cellspacing="0" width="136">
				<tr>
					<td valign="top" colspan="3" width="136">
						<img src="images/top_pn_top.gif" width="136" height="5" alt=""><br>
					</td>
				</tr>
				<tr>
					<td valign="top" rowspan="4" width="49">
						$check_back<br>
					</td>
					<td valign="top" width="44">
						$check_prev<br>
					</td>
					<td valign="top" width="43">
						$check_next<br>
					</td>
				</tr>
				<tr>
					<td valign="top" colspan="2" width="87">
						<img src="images/top_pn_divider.gif" width="87" height="3" alt=""><br>
					</td>
				</tr>
				<tr>
					<td valign="top" width="87" colspan="2">
						<table border="0" cellpadding="0" cellspacing="0" width="87">
							<tr>
								<td valign="top" width="35" align="right" class="pn">
									$listing_order_number{$db{MLSNUM}}&nbsp;<br>
								</td>
								<td valign="top" width="18">
									<img src="images/top_pn_of.gif" width="18" height="11" alt=""><br>
								</td>
								<td valign="top" width="34" align="left" class="pn">
									&nbsp;$total_count<br>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</TD>
		<TD ROWSPAN=2>
			<IMG SRC="images/display/top_residentialoverview.gif" WIDTH=400 HEIGHT=32 ALT=""></TD>
		<TD valign="top" background="images/display/fill_address.gif" height="22" width="205">
			<font size="3" face="Arial"><b>http://$db{MLSNUM}.<font face="Arial Narrow">MuncieMLS</font>.com</b></font><br></TD>
	</TR>
	<TR>
		<TD>
			<IMG SRC="images/display/top_urlbottom.gif" WIDTH=205 HEIGHT=10 ALT=""></TD>
	</TR>
</TABLE>
<img src="images/line_spacer.gif" height="5" width="1"><br>
<center>
<table border="0" cellpadding="0" cellspacing="0" bgcolor="white" width="751">
<tr>
<td align="center" valign="top"><a href="http://www.orrhomes.com/loan.idx" target="_blank"><img src="images/actions/apply_for_a_mortgage.gif" width="160" alt="Apply For A Mortgage" height="30" border="0"></a><br></td>
<td align="center" valign="top"><img src="images/actions/divider_line.gif" width="1" height="30" alt=""><br></td>
<td align="center" valign="top"><a href="javascript:email=window.open('email.idx?action=listingmain&mlsnumber=$db{MLSNUM}&type=','email','width=375, height=450, scrollbars=no'); email.focus();"><img src="images/actions/email_listing.gif" alt="Email This Listing" width="105" height="30" border="0"></a><br></td>
<td align="center" valign="top"><img src="images/actions/divider_line.gif" width="1" height="30" alt=""><br></td>
<td align="center" valign="top"><a href="http://maps.google.com/maps?q=$db{AddressNumber} $db{AddressDirection} $db{AddressStreet}, $ShowCity{$db{City}}, IN $db{Zip}" target="_new"><img src="images/actions/view_on_map.gif" width="110" alt="View On Map" height="30" border="0"></a><br></td>
<td align="center" valign="top"><img src="images/actions/divider_line.gif" width="1" height="30" alt=""><br></td>
<td align="center" valign="top"><a href="javascript:save=window.open('save.idx?mlsnumber=$db{MLSNUM}&type=res','save','width=320, height=325, scrollbars=no'); save.focus();"><img src="images/actions/save_to_myhomes.gif" alt="Save To MyHomes Account" width="132" height="30" border="0"></a><br></td>
<td align="center" valign="top"><img src="images/actions/divider_line.gif" width="1" height="30" alt=""><br></td>
<td align="center" valign="top"><a href="javascript:printversion=window.open('showdetails_print.idx?mlsnumber=$db{MLSNUM}','printversion','width=755, height=700, scrollbars=yes'); printversion.focus();"><img src="images/actions/print_flyer.gif" alt="Print Flyer" width="97" height="30" border="0"></a><br></td>
<td align="center" valign="top"><img src="images/actions/divider_line.gif" width="1" height="30" alt=""><br></td>
<td align="center" valign="top"><a href="#requestshowing"><img src="images/actions/request_showing.gif" alt="Request A Showing" width="142" height="30" border="0"></a><br></td>
</tr>
</table>
</center>
<img src="images/line_spacer.gif" height="5" width="1"><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">
	<table border="0" cellpadding="0" cellspacing="0" width="375">
	<tr>
		<td width="375" valign="top">
			<center>
			<img src="$showpicture" name=picture width="368" height="272"><br>
			$showgallery$toururl<br></center>
			<center>
				<table border="0" cellpadding="1" cellspacing="1" width="368" bgcolor="navy">
					<tr>
					<td width="100%" bgcolor="white">$printoffice<a href="javascript:live_agent=window.open('live_agent.html','live_agent','width=230, height=85, scrollbars=no'); live_agent.focus();"><img src="images/live_agent.gif" border='0' width="360" height="35"></a><br></td>
					</tr>
				</table>
			</center>
		</td>
	</tr>
	</table>
			<img src="images/line_spacer.gif" height="5" width="1"><br>
<center>
<table border="0" cellpadding="0" cellspacing="0" width="368" bgcolor="white">
	<tr>
		<td valign="top" width="368" bgcolor="#000099">
			<table border="0" cellpadding="3" cellspacing="1" width="368" bgcolor="white">
				<tr>
					<td valign="top" width="364" bgcolor="#000099">
						<font face="Tahoma" size="4" color="white" id="requestshowing"><b>Request A Showing / Ask a Question</b></font>
					</td>
				</tr>
			</table>
		</td>
	</tr>
	<tr>
		<td valign="top" width="368">
		<iframe src="showing_setup.idx?proptype=Residential&mlsnumber=$db{MLSNUM}&address=$db{AddressNumber} $db{AddressDirection} $db{AddressStreet}&City=$db{City}" width="368" height="355" noresize="noresize" scrolling ="no" frameborder="0" marginwidth="1" marginheight="1"></iframe>
		</td>
	</tr>
</table>
</center>
</td>
</tr>
</table>
</center>
</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">
<img src="images/line_spacer.gif" height="1" width="11"><font face="Tahoma" size="2">$db{Remarks}</font><br>$showpdf
<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>General Information</b></font></td>
	</tr>
	<tr>
		<td valign="top" nowrap>
			<img src="images/dot.gif">Total Rooms <b>$db{Rooms}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Bedrooms <b>$db{Bedrooms}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Full Bathrooms <b>$db{FullBaths}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Half Bathrooms <b>$db{HalfBaths}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Square Feet $db{TotalSqFt}<a href="javascript:sqftdetails=window.open('sqdetails.idx?mlsnumber=$db{MLSNUM}','sqftdetails','width=384, height=385, scrollbars=yes'); sqftdetails.focus();">[D]</a></b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Est. Annual Taxes <b>$db{EstimatedAnnualTax}</b><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Year Built <b>$db{YearBuilt}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Acres <b>$db{Acres}</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>
			$fGarage
			$fOutbuildingType
			<img src="images/dot.gif">Township <b>$db{Township}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Area <b>$db{Area}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Subdivision <b>$db{Subdivision}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Elem. School <b>$db{ElementarySchool}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">Middle School <b>$db{MiddleSchool}</b><br><img src="images/line_spacer.gif" height="1" width="1"><br>
			<img src="images/dot.gif">High School <b>$db{HighSchool}</b><br><img src=images/line_spacer.gif height=1 width=1><br>
		</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"></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>
<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="#999999"> 
                <td valign="top"><font color="#FFFFFF"><b>Room</b></font></td>
                <td valign="top"><div align="center"><font color="#FFFFFF"><b></b></font></div></td>
                <td valign="top">&nbsp;</td>
                <td valign="top"><div align="center"><font color="#FFFFFF"><b></b></font></div></td>
                <td valign="top"><div align="center"><font color="#FFFFFF"><b>Level</b></font></div></td>
                <td valign="top"><strong><font color="#FFFFFF">Room</font></strong></td>
                <td valign="top"><div align="center"><font color="#FFFFFF"><b></b></font></div></td>
                <td valign="top">&nbsp;</td>
                <td valign="top"><div align="center"><font color="#FFFFFF"><b></b></font></strong></div></td>
                <td valign="top"><div align="center"><font color="#FFFFFF"><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="#EAE7E7"> 
                <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="#EAE7E7"> 
                <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="#EAE7E7"> 
                <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="#EAE7E7"> 
                <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>
<br>$realoffice<br>$paymentdisclosure




</td>
</tr>
</table>




<br>

~;
unless ($INPUT{send} eq "1") {

@variables = ($Cook{userid},$INPUT{mlsnumber});
$sql_query = "INSERT INTO hits values (?,?,'res',now())";
my $zzaasth = $dbh->do($sql_query, undef, @variables);

my $uasth = $dbh->do("update users set lastlogin = now() where userid = '$Cook{userid}'");

}

$dbh->disconnect;

&footer;

}


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



