#!/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; }
	}
}

if ($Cook{userid}) {
$buttoncode = "<input class=\"form\" type=\"button\" value=\"Search Properties\" name=\"Search\" onclick=\"return OnSearch();\">   <input class=\"form\" type=\"button\" value=\"Save Search\" name=\"Save\" onclick=\"return OnSave();\">";
}
else {
$buttoncode = "<b>You Must Be Logged Into Your MyHomes Account To Access The Search</b><br><a href=\"myhomes.idx\">Click Here To Login Or Create A Free Account</a><br>";
}

if ($INPUT{type} eq "Residential") { &Residential; }
elsif ($INPUT{type} eq "Commercial") { &Commercial; }
elsif ($INPUT{type} eq "Investment") { &Investment; }
elsif ($INPUT{type} eq "Land") { &Land; }
elsif ($INPUT{type} eq "MobileHomes") { &MobileHomes; }
else { &Residential; }


sub Commercial {

## CHECK TOS

my $iasth = $dbh->prepare("select tos_agreement from users where userid = '$Cook{userid}'");
$iasth->execute;
while (($usr_tos) = $iasth->fetchrow_array()) {
	if ($usr_tos eq "0000-00-00 00:00:00") {
	print qq~
	<html>
	<head>
	<title>Loading TOS...</title>
	<meta http-equiv="Refresh" content="3; URL=http://www.MuncieMLS.com/tos.idx">
	</head>
	<body>
	<br><br><br><br><br>
	<center>
	<table border="0" cellpadding="12" cellspacing="1" bgcolor="navy">
	<tr>
	<td valign="middle" bgcolor="white">
	<br>
	<center>
	<img src="images/StatusBar4.gif" alt="Loading"><br>
	<img src="images/LoadingMyHomes.gif"><br>
	</center>
	</td>
	</tr>
	</table>
	</center>
	</body>
	</html>
	~;
	exit 0;
	}
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="images/eaglerealestate.ico">
<title>MuncieMLS.com - Your best source for homes located throughout East Central Indiana!</title>

STARTOFTHEPAGE

&header;


print <<"ALLTHISSTUFF";
</td>
<td width="581" valign="top">
<img src="images/headers/commercial_propertysearch.gif" height="33" width="581" alt="Commercial Property Search"><Br>
<table border="0" cellpadding="6" width="581" cellspacing="0">
<tr>
<td valign="top" width="461">
ALLTHISSTUFF

&commercialsearchcriteria;

print <<"ALLTHISSTUFF2";
</td>
<td valign="top" width="120">
ALLTHISSTUFF2


&advertising;


print <<"ALLTHISSTUFF3";
</td>
</tr>
</td>
</html>
ALLTHISSTUFF3


&footer;

}


sub MobileHomes {

## CHECK TOS

my $iasth = $dbh->prepare("select tos_agreement from users where userid = '$Cook{userid}'");
$iasth->execute;
while (($usr_tos) = $iasth->fetchrow_array()) {
	if ($usr_tos eq "0000-00-00 00:00:00") {
	print qq~
	<html>
	<head>
	<title>Loading TOS...</title>
	<meta http-equiv="Refresh" content="3; URL=http://www.MuncieMLS.com/tos.idx">
	</head>
	<body>
	<br><br><br><br><br>
	<center>
	<table border="0" cellpadding="12" cellspacing="1" bgcolor="navy">
	<tr>
	<td valign="middle" bgcolor="white">
	<br>
	<center>
	<img src="images/StatusBar4.gif" alt="Loading"><br>
	<img src="images/LoadingMyHomes.gif"><br>
	</center>
	</td>
	</tr>
	</table>
	</center>
	</body>
	</html>
	~;
	exit 0;
	}
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="images/eaglerealestate.ico">
<title>MuncieMLS.com - Your best source for homes located throughout East Central Indiana!</title>

STARTOFTHEPAGE

&header;


print <<"ALLTHISSTUFF";
</td>
<td width="581" valign="top">
<img src="images/headers/mobilehome_propertysearch.gif" height="33" width="581" alt="Home Home Property Search"><Br>
<table border="0" cellpadding="6" width="581" cellspacing="0">
<tr>
<td valign="top" width="461">
ALLTHISSTUFF

&mobilehomessearchcriteria;

print <<"ALLTHISSTUFF2";
</td>
<td valign="top" width="120">
ALLTHISSTUFF2


&advertising;


print <<"ALLTHISSTUFF3";
</td>
</tr>
</td>
</html>
ALLTHISSTUFF3


&footer;

}

sub Land {

## CHECK TOS

my $iasth = $dbh->prepare("select tos_agreement from users where userid = '$Cook{userid}'");
$iasth->execute;
while (($usr_tos) = $iasth->fetchrow_array()) {
	if ($usr_tos eq "0000-00-00 00:00:00") {
	print qq~
	<html>
	<head>
	<title>Loading TOS...</title>
	<meta http-equiv="Refresh" content="3; URL=http://www.MuncieMLS.com/tos.idx">
	</head>
	<body>
	<br><br><br><br><br>
	<center>
	<table border="0" cellpadding="12" cellspacing="1" bgcolor="navy">
	<tr>
	<td valign="middle" bgcolor="white">
	<br>
	<center>
	<img src="images/StatusBar4.gif" alt="Loading"><br>
	<img src="images/LoadingMyHomes.gif"><br>
	</center>
	</td>
	</tr>
	</table>
	</center>
	</body>
	</html>
	~;
	exit 0;
	}
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="images/eaglerealestate.ico">
<title>MuncieMLS.com - Your best source for homes located throughout East Central Indiana!</title>

STARTOFTHEPAGE

&header;


print <<"ALLTHISSTUFF";
</td>
<td width="581" valign="top">
<img src="images/headers/lotsandland_propertysearch.gif" height="33" width="581" alt="Lots & Land Property Search"><Br>
<table border="0" cellpadding="6" width="581" cellspacing="0">
<tr>
<td valign="top" width="461">
ALLTHISSTUFF

&landsearchcriteria;

print <<"ALLTHISSTUFF2";
</td>
<td valign="top" width="120">
ALLTHISSTUFF2


&advertising;


print <<"ALLTHISSTUFF3";
</td>
</tr>
</td>
</html>
ALLTHISSTUFF3


&footer;

}

sub Investment {

## CHECK TOS

my $iasth = $dbh->prepare("select tos_agreement from users where userid = '$Cook{userid}'");
$iasth->execute;
while (($usr_tos) = $iasth->fetchrow_array()) {
	if ($usr_tos eq "0000-00-00 00:00:00") {
	print qq~
	<html>
	<head>
	<title>Loading TOS...</title>
	<meta http-equiv="Refresh" content="3; URL=http://www.MuncieMLS.com/tos.idx">
	</head>
	<body>
	<br><br><br><br><br>
	<center>
	<table border="0" cellpadding="12" cellspacing="1" bgcolor="navy">
	<tr>
	<td valign="middle" bgcolor="white">
	<br>
	<center>
	<img src="images/StatusBar4.gif" alt="Loading"><br>
	<img src="images/LoadingMyHomes.gif"><br>
	</center>
	</td>
	</tr>
	</table>
	</center>
	</body>
	</html>
	~;
	exit 0;
	}
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="images/eaglerealestate.ico">
<title>MuncieMLS.com - Your best source for homes located throughout East Central Indiana!</title>

STARTOFTHEPAGE

&header;


print <<"ALLTHISSTUFF";
</td>
<td width="581" valign="top">
<img src="images/headers/investment_propertysearch.gif" height="33" width="581" alt="Investment Property Search"><Br>
<table border="0" cellpadding="6" width="581" cellspacing="0">
<tr>
<td valign="top" width="461">
ALLTHISSTUFF

&investmentsearchcriteria;

print <<"ALLTHISSTUFF2";
</td>
<td valign="top" width="120">
ALLTHISSTUFF2


&advertising;


print <<"ALLTHISSTUFF3";
</td>
</tr>
</td>
</html>
ALLTHISSTUFF3


&footer;


}

sub Residential {

## CHECK TOS

my $iasth = $dbh->prepare("select tos_agreement from users where userid = '$Cook{userid}'");
$iasth->execute;
while (($usr_tos) = $iasth->fetchrow_array()) {
	if ($usr_tos eq "0000-00-00 00:00:00") {
	print qq~
	<html>
	<head>
	<title>Loading TOS...</title>
	<meta http-equiv="Refresh" content="3; URL=http://www.MuncieMLS.com/tos.idx">
	</head>
	<body>
	<br><br><br><br><br>
	<center>
	<table border="0" cellpadding="12" cellspacing="1" bgcolor="navy">
	<tr>
	<td valign="middle" bgcolor="white">
	<br>
	<center>
	<img src="images/StatusBar4.gif" alt="Loading"><br>
	<img src="images/LoadingMyHomes.gif"><br>
	</center>
	</td>
	</tr>
	</table>
	</center>
	</body>
	</html>
	~;
	exit 0;
	}
}

print <<"STARTOFTHEPAGE";

<html>
<head>
<LINK REL="SHORTCUT ICON" HREF="images/eaglerealestate.ico">
<title>MuncieMLS.com - Your best source for homes located throughout East Central Indiana!</title>

STARTOFTHEPAGE

&header;


print <<"ALLTHISSTUFF";
</td>
<td width="581" valign="top">
<img src="images/headers/residential_propertysearch.gif" height="33" width="581" alt="Residential Property Search"><Br>
<table border="0" cellpadding="6" width="581" cellspacing="0">
<tr>
<td valign="top" width="461">
ALLTHISSTUFF

&residentialsearchcriteria;

print <<"ALLTHISSTUFF2";
</td>
<td valign="top" width="120">
ALLTHISSTUFF2


&advertising;


print <<"ALLTHISSTUFF3";
</td>
</tr>
</td>
</html>
ALLTHISSTUFF3


&footer;


}






sub residentialsearchcriteria {

open(RESSEARCHCRITERIA,"includes/searchcriteria.txt");
@ressearchcriteria = <RESSEARCHCRITERIA>;
close(RESSEARCHCRITERIA);

foreach $line (@ressearchcriteria) {
$line =~ s/<!--INSERTBUTTONS-->/$buttoncode/gi;
print "$line";
}


}

sub commercialsearchcriteria {

open(COMSEARCHCRITERIA,"includes/commercialsearchcriteria.txt");
@comsearchcriteria = <COMSEARCHCRITERIA>;
close(COMSEARCHCRITERIA);

foreach $line (@comsearchcriteria) {
$line =~ s/<!--INSERTBUTTONS-->/$buttoncode/gi;
print "$line";
}


}

sub investmentsearchcriteria {

open(INVSEARCHCRITERIA,"includes/investmentsearchcriteria.txt");
@invsearchcriteria = <INVSEARCHCRITERIA>;
close(INVSEARCHCRITERIA);

foreach $line (@invsearchcriteria) {
$line =~ s/<!--INSERTBUTTONS-->/$buttoncode/gi;
print "$line";
}

}

sub landsearchcriteria {

open(LANSEARCHCRITERIA,"includes/landsearchcriteria.txt");
@lansearchcriteria = <LANSEARCHCRITERIA>;
close(LANSEARCHCRITERIA);

foreach $line (@lansearchcriteria) {
$line =~ s/<!--INSERTBUTTONS-->/$buttoncode/gi;
print "$line";
}


}

sub mobilehomessearchcriteria {

open(MOBSEARCHCRITERIA,"includes/mobilehomessearchcriteria.txt");
@mobsearchcriteria = <MOBSEARCHCRITERIA>;
close(MOBSEARCHCRITERIA);

foreach $line (@mobsearchcriteria) {
$line =~ s/<!--INSERTBUTTONS-->/$buttoncode/gi;
print "$line";
}

}


sub advertising {

open(ADVERTISING,"includes/advertising.txt");
@advertising = <ADVERTISING>;
close(ADVERTISING);

foreach $line (@advertising) {
print "$line";
}


}

