#!/usr/bin/perl
use CGI;
use DBI;
use IO::Socket;
$query = new CGI;
$|++;


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

# prep
OutputPrep();

# header  ---------------------------

OutputHeader();

# left-side   ---------------------------
# cities only 
OutputLeftSide(); 

# right-side  --------------------------- 
# story or no story?
# news (tax, buz, ??) .. once a week?
# static text??
# weather ?
# other cities not in database
OutputRightSide();
 
 
# footer   ---------------------------
OutputFooter();  
GetGoogle();
GetGoogleRight();

print "<head><title>$statename $stateinitials hotels</title><p>";
print $header;
print $googleline;
print $leftside1;
print $leftside;
print $rightside;
print "</td><td width=15>&nbsp;</td><td valign=top>".$googleright."</td>";
print $footer;

exit;


sub OutputPrep()
{
 #get statename and intials
 
 $statename = $query->param("statename");
 $stateinitials = $query->param("stateinitials");
 

 unless ($stateinitials )
   {$stateinitials = "MI";}
 
#    {
     GetStateName();
 #    }

}

 
sub GetStateName()
{
 

@arrayStateinitials=(
 "AL",
 "AK",
 "AR",
 "AZ",
 "CA",
 "CO",
 "CT",
 "DE",
 "DC",
 "FL",
 "GA",
 "HI",
 "ID",
 "IL",
 "IN",
 "IA",
 "KS",
 "KY",
 "LA",
 "ME",
"MD",
"MA",
"MI",
"MN",
"MS",
"MO",
"MT",
"NE",
"NV",
"NH",
"NJ",
"NM",
"NY",
"NC",
"ND",
"OH",
"OK",
"OR",
"PA",
"PR",
"RI",
"SC",
"SD",
"TN",
"TX",
"UT",
"VT",
"VI",
"VA",
"WA",
"WV",
"WI",
"WY"
);


@arrayStatename=(
 "Alabama",
 "Alaska",
 "Arkansa",
 "Arizona",
 "California",
 "Colorado",
 "Conneticut",
 "Delaware",
 "WashingtonDC",
 "Florida",
 "Georgia",
 "Hawaii",
 "Idaho",
 "Illinois",
 "Indiana",
 "Iowa",
 "Kansas",
 "Kentucky",
 "Louisiana",
 "Maine",
"Maryland",
"Massachusetts",
"Michigan",
"Minnesota",
"Mississippi",
"Missouri",
"Montana",
"Nebraska",
"Nevada",
"New Hampshire",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
"North Dakato",
"Ohio",
"Oklahoma",
"Oregon",
"Pennsylvania",
"Puerto Rico",
"Rhode Island",
"South Carolina",
"South Dakata",
"Tennessee",
"Texas",
"Utah",
"Vermont",
"Virgin Islands",
"Virginia",
"Washington State",
"West Viginia",
"Wisconsin",
"Wyoming"
);

 
 
 
  for ($i=0; $i < $#arrayStateinitials; $i++)
  {
   $temps = $arrayStateinitials[$i];
   if ( $stateinitials EQ $temps)
     {
     $statename = $arrayStatename[$i];
 
      }
  
  }
 
 
}#end of sub

sub OutputLeftSide()
{
 $leftside = "<table><tr><td valign=top width=8>&nbsp;</td><td valign=top width=300><b>Cities 
 with Hotels in $stateinitials<br>- $statename</b><p>";

 StateUS();

}

# story or no story?
# news (tax, buz, ??) .. once a week?
# static text??
# weather ?
# other cities not in database
sub OutputRightSide()
{
$articlefile = "articles/$stateinitials.txt";
$rightside = "</td><td valign=top width=10>&nbsp;</td><td valign=top width=550><b>$statename Information</b><br>";

# stories

if (-e $articlefile)
 {
   
  open(READ3,$articlefile) || die "$!";
  while ($temp3 = <READ3>)
     {$r1 = $r1.$temp3;
      }
  close(READ3);
 }
else 
  { $r1 = "No specific information about traveling in the state of $statename yet.";}

$rightside .= $r1; 
$rightside .= " <p>

Surfy Hotels offers a real-time online ordering to thousands hotels in $statename. 
Upon making a discount hotel reservation, you will immediately receive 
an email confirmation for your each hotel reservation. Surfy wishes you well on your business or 
vacation trip. Enjoy yourself and make others smile. 
<p>
For Europeans, all states including $statename offer lower 
price gasoline than most if not all european countries.
Currency is also in your favor with rates in excess of $1.30 for every Euro  in exchange. 
As of May 2007, the rates were near $1.35 for every Euro which makes shopping and traveling cheaper for
Europeans.
<p>
<b>$statename Restaurants:</b><br>

<FORM action=\"http://www.surfy.com/cgi-bin/searchhotel\" method=\"POST\" name=\"frm_Search\">
Name:  <INPUT type=\"text\" name=\"key\" size=\"16\" maxlength=\"60\"  >   optional<p> 
 <INPUT type=\"hidden\" name=\"reste\" size=\"4\"  value=\"yes\">   
<input type=\"hidden\" name=\"sitesearch\" value=\"restaurants\"></input>

Food type: <SELECT NAME=\"cat\">
<OPTION VALUE=\"\">*All Types*
<OPTION VALUE=\"pizza\">Pizza
<OPTION VALUE=\"chinese\">Chinese
<OPTION VALUE=\"french\">French
<OPTION VALUE=\"breakfast\">Breakfast
<OPTION VALUE=\"tavern\">Tavern
<OPTION VALUE=\"seafood\">Seafood
<OPTION VALUE=\"sandwich\">Sandwich
<OPTION VALUE=\"family\">Family
<OPTION VALUE=\"salads\">Salads
<OPTION VALUE=\"general\">General
<OPTION VALUE=\"chicken\">Chicken
</SELECT>
<p>
City:  <INPUT type=\"text\" name=\"city\" size=\"16\" maxlength=\"60\"  value=\"\">   optional<p> 

 <input name=\"state\" value=\"$stateinitials\" type=hidden> 

 <INPUT type=\"submit\" value=\"Surfy!\"><p>

</form>

"; 
$rightside .= "</td>";
}




sub OutputHeader() {
   
   # if (-e $filename)
   
   $filename = "header.html";
   open(FILEH, $filename);
   while ($record = <FILEH>) {
      $header=$header.$record;
   }
   close(FILEH);
   
   $titlestring1="TITLECHANGE";
   $titlestring2="SUBCHANGE";
   $newtitle1 = $statename." Discount Hotels - ".$stateinitials;
   $newtitle2 = "and ".$statename." Travel Information";
   $_=$header;
   s/$titlestring1/$newtitle1/eg;
   s/$titlestring2/$newtitle2/eg;
   $header=$_;
}

sub OutputFooter() {
   $footer = "";
   open(FILEF, "footer.html");
   while ($record = <FILEF>) {
      $footer=$footer.$record;
   }
   close(FILEF);
}

sub MakeStates() 
{


print "<head><title>$buildstate hotels</title><p>";
print "<table><tr><td valign=top width=8>&nbsp;</td><td valign=top width=260>";
PrintStateUS();
print "</td><td valign=top width=10>&nbsp;</td><td valign=top width=550>";

$parsefile = "articles/$buildstate.txt";
if (-e $parsefile)

 {
  open(READ3,$parsefile) || die "$!";
  while ($temp3 = <READ3>)
     {$r1 = $r1.$temp3;
      }
  close(READ3);
 }
else 
  { $r1 = $parsefile;}
  
print "<font size=\"2.5\">$r1</font> </td><td valign=top>";
GoogleSide();
print " </td></tr></table>";
print "Copyright <a href=\"/\">Surfy.com</a> hotels.<p>";

}



sub StateUS()
{
$thestate = $mode_state;
$thelong = $mode_city;

my $database = "lex";my $data_source = "DBI:mysql:database=$database;host=localhost"; my $username = "surfy"; my $password = "lex2846";
$dbh = DBI->connect($data_source,$username,$password);

$sth = $dbh->prepare("SELECT *  FROM mhotels 
                    WHERE (stateprovince = \"$stateinitials\") order by City ;");

$sth->execute();
$filetemp = "$thedir/$sCity $sState.html";
$opencity = ">/home2/surfy/www/$filetemp";
$delopencity = "/home2/surfy/www/$filetemp";
$test_long = 0;  # x
$test_lat = 0;    #y
$valid_long_lat =0;
 
$oldcity = "fsdsdf";
while (my $ref = $sth->fetchrow_hashref())
   {
     
           $sCity = $ref->{'City'};
           $_ = $sCity;
           if (/$oldcity/)
             { 
            ;  
              }
           else {
           
           #$url = $sCity." ".$statename."-".$stateinitials;
           $url = $sCity." ".$stateinitials;
           $url =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
           
            $oldcity = $sCity;
           
            $lon = $ref->{'Longitude'};
            $lat = $ref->{'Latitude'};
          
           # $leftside = $leftside."<a href =\"http://www.surfy.com/hotels-in/$url.html\">$sCity hotels</a><br>
           $leftside = $leftside."<a href =\"http://www.surfy.com/hotels/$url.html\">$sCity,$stateinitials hotels</a><br>
            <font size=\"1\"><font color=\"#909090\">longitude=$lon, latitude=$lat</font></font>";
            $leftside = $leftside."<br>";

            } # if
   } # while
} #subroutine



 

sub Quad()
{




print OPEN2 <<EOM;
<table width><tr>

<td valign=top width=30>&nbsp;
</td><td valign=top>

<table cellspacing=0 cellpadding=3 width=500>
<tr>
<td bgcolor=#fbfbde >
<table width=100%><tr><td bgcolor=#3868d0><font color=white>Northwest of city</font></td></tr></table>
EOM

FindNearbyHotelsNW();
print OPEN2 <<EOM;
</td>
<td width=15 bgcolor=#fbfbde>&nbsp;</td>

<td bgcolor=#fbfbde>
<table width=100%><tr><td bgcolor=#3868d0><font color=white>Northeast of city</font></td></tr></table>
EOM

FindNearbyHotelsNE();
print OPEN2 <<EOM;
</td>
</tr>
<tr>
<td bgcolor=#fbfbde></td>
<Td width=15 align=center bgcolor=lightblue><!img src="compass.jpg" width=15 align=center>
</td>
<td bgcolor=#fbfbde></td>
</tr>
<tr><td bgcolor=#fbfbde>

<table width=100%><tr><td bgcolor=#3868d0><font color=white>Southwest of city</font></td></tr></table>
EOM

FindNearbyHotelsSW();
print OPEN2 <<EOM;
</td>
<td width=15 bgcolor=#fbfbde>&nbsp;</td>


<td bgcolor=#fbfbde>
<table width=100%><tr><td bgcolor=#3868d0><font color=white>Southeast of city</font></td></tr></table>
EOM

FindNearbyHotelsSE();
print OPEN2 <<EOM;
</td>
</tr>
</table>

<p>

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

}


sub FindNearbyHotelsSE()
{
#.95 offset for US
$fth = $dbh->prepare("SELECT hotelid,name,latitude,longitude, (latitude-$test_lat)*(latitude-$test_lat)*(longitude-$test_long)*(longitude-$test_long) as JEFF,city,numberofrooms,stateprovince,country,highrate,lowrate FROM hotels 
                    WHERE (latitude < $test_lat  AND latitude > $test_lat-.95 AND
                           longitude < $test_long+.95  AND longitude > $test_long AND
                               city != \"$mode_city\" )
		    order by JEFF LIMIT 20;");
$fth->execute();
while (my $ref = $fth->fetchrow_hashref())
       {
           $sHotelID = $ref->{'hotelid'};
           $sName = $ref->{'name'};
	   $sCity = $ref->{'city'};
	   $sHigh = $ref->{'highrate'};
	   $sLow = $ref->{'lowrate'};
           OutputHotelNear($sHotelID, $sName, $sCity,$ref->{'stateprovince'},$ref->{'country'}, $sLow, $sHigh);
       }
$fth->finish();
}

sub FindNearbyHotelsAll()
{
 
my $commandCity = $nextcity;

# print OPEN2 "<p>scity = $commandCity, $sCy";

#  country == \"US\"

$allth = $dbh->prepare("SELECT hotelid,name,latitude,longitude, (latitude-$test_lat)*(latitude-$test_lat)*(longitude-$test_long)*(longitude-$test_long) as GEORGE,city,numberofrooms,stateprovince,country,highrate,lowrate FROM hotels 
                    WHERE (latitude < $test_lat + 1.35  AND latitude > $test_lat - 1.35 AND
                           longitude < $test_long + 1.35 AND longitude > $test_long - 1.35 AND
                               city != \"$commandCity\" AND country = \"US\" )
		    order by GEORGE LIMIT 9;");

$allth->execute();

 

while (my $allref = $allth->fetchrow_hashref())
       {
      
           $allHotelID = $allref->{'hotelid'};
           $allName = $allref->{'name'};
	   $allCity = $allref->{'city'};
	   $allHigh = $allref->{'highrate'};
	   $allLow = $allref->{'lowrate'};
           OutputHotel($allHotelID, $allName, $allCity,$allref->{'stateprovince'},
                    $allref->{'country'}, $allLow, $allHigh);
           ### print OPEN2 "<br>$allref->{'latitude'}, $allref->{'longitude'}";
       }
$allth->finish();
}



sub FindNearbyHotelsSE()
{
#.95 offset for US
$fth = $dbh->prepare("SELECT hotelid,name,latitude,longitude, (latitude-$test_lat)*(latitude-$test_lat)*(longitude-$test_long)*(longitude-$test_long) as JEFF,city,numberofrooms,stateprovince,country,highrate,lowrate FROM hotels 
                    WHERE (latitude < $test_lat  AND latitude > $test_lat - .95 AND
                           longitude < $test_long+.95  AND longitude > $test_long AND
                               city != \"$mode_city\" )
		    order by JEFF LIMIT 20;");
$fth->execute();
while (my $ref = $fth->fetchrow_hashref())
       {
           $sHotelID = $ref->{'hotelid'};
           $sName = $ref->{'name'};
	   $sCity = $ref->{'city'};
	   $sHigh = $ref->{'highrate'};
	   $sLow = $ref->{'lowrate'};
           OutputHotelNear($sHotelID, $sName, $sCity,$ref->{'stateprovince'},$ref->{'country'}, $sLow, $sHigh);
       }
$fth->finish();
}

sub FindNearbyHotelsSW()
{
#.75 offset for US
$fth = $dbh->prepare("SELECT hotelid,name,latitude,longitude, (latitude-$test_lat)*(latitude-$test_lat)*(longitude-$test_long)*(longitude-$test_long) as JEFF,city,numberofrooms,stateprovince,country,highrate,lowrate FROM hotels 
                    WHERE (latitude < $test_lat  AND latitude > $test_lat-1.35 AND
                           longitude < $test_long  AND longitude > $test_long-1.35 AND
                               city != \"$mode_city\" )
		    order by JEFF LIMIT 20;");
$fth->execute();
while (my $ref = $fth->fetchrow_hashref())
       {
           $sHotelID = $ref->{'hotelid'};
           $sName = $ref->{'name'};
	   $sCity = $ref->{'city'};
	   $sHigh = $ref->{'highrate'};
	   $sLow = $ref->{'lowrate'};
           OutputHotelNear($sHotelID, $sName, $sCity,$ref->{'stateprovince'},$ref->{'country'}, $sLow, $sHigh);
       }
$fth->finish();
}

sub FindNearbyHotelsNE()
{
#.75 offset for US
$fth = $dbh->prepare("SELECT hotelid,name,latitude,longitude, (latitude-$test_lat)*(latitude-$test_lat)*(longitude-$test_long)*(longitude-$test_long) as JEFF,city,numberofrooms,stateprovince,country,highrate,lowrate FROM hotels 
                    WHERE (latitude < $test_lat +.95 AND latitude > $test_lat AND
                           longitude < $test_long +.95 AND longitude > $test_long AND
                               city != \"$mode_city\" )
		    order by JEFF LIMIT 20;");
$fth->execute();
while (my $ref = $fth->fetchrow_hashref())
       {
           $sHotelID = $ref->{'hotelid'};
           $sName = $ref->{'name'};
	   $sCity = $ref->{'city'};
	   $sHigh = $ref->{'highrate'};
	   $sLow = $ref->{'lowrate'};
           OutputHotelNear($sHotelID, $sName, $sCity,$ref->{'stateprovince'},$ref->{'country'}, $sLow, $sHigh);
       }
$fth->finish();
}

sub FindNearbyHotelsNW()
{
#.75 offset for US
$fth = $dbh->prepare("SELECT hotelid,name,latitude,longitude, (latitude-$test_lat)*(latitude-$test_lat)*(longitude-$test_long)*(longitude-$test_long) as JEFF,city,numberofrooms,stateprovince,country,highrate,lowrate FROM hotels 
                    WHERE (latitude < $test_lat+.95 AND latitude > $test_lat AND
                           longitude < $test_long  AND longitude > $test_long-.95 AND
                               city != \"$mode_city\" )
		    order by JEFF LIMIT 20;");
$fth->execute();
while (my $ref = $fth->fetchrow_hashref())
       {
           $sHotelID = $ref->{'hotelid'};
           $sName = $ref->{'name'};
	   $sCity = $ref->{'city'};
	   $sHigh = $ref->{'highrate'};
	   $sLow = $ref->{'lowrate'};
           OutputHotelNear($sHotelID, $sName, $sCity,$ref->{'stateprovince'},$ref->{'country'}, $sLow, $sHigh);
       }
$fth->finish();
}


sub FindNearbyCities()
{
#1.55 offset for US

$tempycitz = "werere";

@tags = "";
$Ncth = $dbh->prepare("SELECT hotelid,name,latitude,longitude,city,stateprovince,country,10000000.0*(latitude-$test_lat)*(latitude-$test_lat)*(longitude-$test_long)*(longitude-$test_long) as TIMMY
                    FROM hotels 
                    WHERE (latitude < $test_lat + 1.35  AND latitude > $test_lat - 1.35 AND
                           longitude < $test_long + 1.35  AND longitude > $test_long - 1.35 AND
  			        latitude != 0.0 AND
                               city != \"$nextcity\" AND country = \"US\" )
		    order by TIMMY LIMIT 25;");
$Ncth->execute();



while (my $theref = $Ncth->fetchrow_hashref())
       {
           $NcHotelID = $theref->{'hotelid'};
           $NcName = $theref->{'name'};
	   $NcCity = $theref->{'city'};
	   $NcState = $theref->{'stateprovince'};
	   $NcCy = $theref->{'country'};
	   $ntagflag = 0;

     

       if ($nextcity NE $NcCity && $NcCity NE $tempycitz) {

               

    for ($i=0; $i < $#tags; $i++)
 	{
 	 ### print OPEN2 "<br>$i-> $tags[$i], $NcCity = ";
 
 	  $_ =$tags[$i];
 	  s/\s/'_'/eg;
  	  $comp2 = $_;
 	  
 	  $_ = $NcCity;
 	  s/\s/'_'/eg;
 
 
                  if (/$comp2/)
                      { $ntagflag = 8; 
                        ### print OPEN2 "yes"; 
                      }
   	  else { 
                   # print OPEN2 "no";
                }
              }
 
              if ($ntagflag < 8 ) 
                  { 
	      	$_  = "$NcCity%20$NcState.html";
	      	$exch1 = "%20";
	      	s/\s/$exch1/eg;
	      	$filetemp = $_;
              	print OPEN2 "<img src=$littlelogo border=0> <a href=http://$domain/$linkdir/$filetemp>$NcCity,$NcState,$NcCy $nearhotels</a> <p>";

########## $elain = 10000000.0*($theref->{'latitude'}-$test_lat)*($theref->{'latitude'}-$test_lat)*($theref->{'longitude'}-$test_long)*($theref->{'longitude'}-$test_long);
##########print OPEN2 "Elain = $elain, $test_long, $test_lat <br> ";

push(@tags, $NcCity); 
 		}
              }  # END if not same as last city
          $tempycitz = $NcCity;

       }


   $Ncth->finish();
}


sub BuildCountries()
{

$thestate = $array[$anum];
$thelong = $arrayLong[$anum];



print "\nAdding $thestate, $thelong $thedir \n";

my $database = "lex";
my $data_source = "DBI:mysql:database=$database;host=localhost";
my $username = "surfy";
my $password = "lex2846";
$dbh = DBI->connect($data_source,$username,$password);

$sth = $dbh->prepare("SELECT hotelid,name,city,numberofrooms,stateprovince,country,highrate,lowrate 
                FROM hotels WHERE (country = \"$thestate\") order by city;");
$sth->execute();

$nextcity = "wer";

$open1 = ">/home2/surfy/www/$thedir/$thelong.html";
$filepossible1 = "/home2/surfy/www/$thedir/$thelong%20hotels.html";
$filepossible2  = "/home2/surfy/www/$thedir/$thelong.html";

unlink($filepossible1);
unlink($filepossible2);

open(OPEN1, $open1) || print "problems writing file state $open1<p>";
LayoutPageLeft();

$citycount = 0;

while (my $ref = $sth->fetchrow_hashref())
       {
           $sHotelID = $ref->{'hotelid'};
           $sName = $ref->{'name'};
	   $sCity = $ref->{'city'};
	   $sHigh = $ref->{'highrate'};
	   $sLow = $ref->{'lowrate'};
           $NumberOfRooms = $ref->{'numberofrooms'};
 	    if ($nextcity ne $sCity)
               {
		if ($citycount > 0)
		{ LayoutPageRight2();
		 TheFoot2();
		  close(OPEN2);
 		}
                $citypage = "http://www.surfy.com/$thedir/$sCity $thelong.html";
		$_ = $citypage;
		$exch1 = "%20";
		s/\s/$exch1/eg;
		$citypage = $_;
                print OPEN1 "<p><a href=$citypage>$sCity, $thelong Hotels</a>";
                $nextcity = $sCity;

		$_ = $sCity;
		s/\s/'+'/eg;
		$sCityz = $_;
		$sCity = $nextcity ;

  		 #open citypage
                 $opencity = ">/home2/surfy/www/$thedir/$sCity $thelong.html";
                 $del_opencity = "/home2/surfy/www/$thedir/$sCity $thelong.html";
		 unlink($del_opencity);
	 	 open(OPEN2, $opencity) || print "problems writing file state $open1<p>";
		 LayoutPageLeft2();

               }
	 $citycount++;

         OutputHotel($sHotelID, $sName, $sCity,$ref->{'stateprovince'},$ref->{'country'}, $sLow, $sHigh);
}

$sth->finish();
$dbh->disconnect();

LayoutPageRight2();
 TheFoot2();
close(OPEN2);
LayoutPageRight();
close(OPEN1);

}


sub OldBuildSurfyStatesByCity()
{
$thestate = $array[$anum];

my $database = "lex";
my $data_source = "DBI:mysql:database=$database;host=localhost";
my $username = "surfy";
my $password = "lex2846";
$dbh = DBI->connect($data_source,$username,$password);

$stateth = $dbh->prepare("SELECT city,stateprovince,country FROM hotels  WHERE (stateprovince = \"$gostate\" and country = \"US\")  order by city;");
$stateth->execute();
$nextcity = "wer";

$open1 = ">/home2/surfy/www/$thedir/$gostate.html";
print "\nfile = $open1, $gostate";

$citycount = 0;
while (my $mystate = $stateth->fetchrow_hashref())
       {
         $sHotelID = $mystate->{'hotelid'};
         $sName = $mystate->{'name'};
	 $mode_city = $mystate->{'city'};
         print "\n city = $mode_city, $mode_state";
	 $citycount++;
       } 

print "\nfile = end";

$stateth->finish();
$dbh->disconnect();

}


sub OldBuildSurfyStates()
{

$thestate = $array[$anum];

print "\n Test $thestate";

my $database = "lex";
my $data_source = "DBI:mysql:database=$database;host=localhost";
my $username = "surfy";
my $password = "lex2846";
$dbh = DBI->connect($data_source,$username,$password);

$bsth = $dbh->prepare("SELECT hotelid,name,city,numberofrooms,stateprovince,country,longitude,latitude,highrate,lowrate FROM hotels WHERE (stateprovince = \"$gostate\" and country = \"US\") ORDER by city;");
$bsth->execute();

$nextcity = "somewrongcity";

$open1 = ">/home2/surfy/www/$thedir/$gostate.html";
unlink($open1);
print "\n$open1";
open(OPEN1, $open1) || print "problems writing file state $open1<p>";
LayoutPageLeft();

$hotels_per_city = 0;
$test_long = 0;  # x
$test_lat = 0;    #y
$valid_long_lat =0;

while (my $bsref = $bsth->fetchrow_hashref())
   {
        $sHotelID = $bsref->{'hotelid'};
        $sName = $bsref->{'name'};
	$sCity = $bsref->{'city'};
	$sCy = $bsref->{'country'};
	$sHigh = $bsref->{'highrate'};
	$sLow = $bsref->{'lowrate'};
        $NumberOfRooms = $bsref->{'numberofrooms'};
        $lo = $bsref->{'longitude'};
        $la = $bsref->{'latitude'};
    
 	if ($nextcity NE $sCity)
            {
	    if ($hotels_per_city > 0)
	       { 
		 ###  -------------------- complete, move to next one
	       if ( $valid_long_lat != 0.0 ) {
	          $test_long = $test_long / $valid_long_lat;
	          $test_lat = $test_lat / $valid_long_lat;
	          }   
	       if ( $hotels_per_city < 20) {



 

		     print OPEN2 "<p><font face=verdana><b>Others Nearby Hotels</b></font><p>";
		     ######### print OPEN2 "<p> summary long, lat: $test_long, $test_lat";
		     FindNearbyHotelsAll(); 
		     }
	       LayoutPageRight2();
	       TheFoot2();
	       close(OPEN2);
	         
	       $test_long = 0;  # x
	       $test_lat = 0;    #y
	       $valid_long_lat = 0;
	       $hotels_per_city = 0;
	    }

	    $citypage = "http://$domain/$linkdir/$sCity $gostate.html";
	    $_ = $citypage;
	    $exch1 = "%20";
	    s/\s/$exch1/eg;
	    $citypage = $_;
 	    print OPEN1 "<p><a href=$citypage>$sCity, $gostate HOTELS</a>";
            $nextcity = $sCity;

	    $_ = $sCity;
	    s/\s/'+'/eg;
	    $sCityz = $_;
	    ## $sCity = $nextcity ;

  	    #open citypage
	    $opencity = ">/home2/surfy/www/$thedir/$sCity $gostate.html";
	    unlink($opencity);
	    print "\n$opencity";
	    open(OPEN2, $opencity) || print "problems writing file state $open1<p>";
	    LayoutPageLeft2();
            }

        if ( ($lo > 0.0 || $lo < 0.0) && ($la > 0.0 || $la < 0.0) )    {
            $test_long = $test_long +  $bsref->{'longitude'};  # x
            $test_lat = $test_lat +  $bsref->{'latitude'};;    #y
            $valid_long_lat++;
            print "\nlong. = $lo, $valid_long_lat";
            }
        else {
            print "\n long/lat $lo, $la  : $valid_long_lat";
 	    }

	 $hotels_per_city++;
         OutputHotel($sHotelID, $sName, $sCity,$ref->{'stateprovince'},$bsref->{'country'}, $sLow, $sHigh);
        ##### print OPEN2 "<br>$lo, $la, hotels = $valid_long_lat";
   }



LayoutPageRight2();
TheFoot2();

$bsth->finish();
$dbh->disconnect();


close(OPEN2);
LayoutPageRight();
close(OPEN1);

}


sub ErgovaStates()
{

$thestate = $array[$anum];

print "\n Test $thestate";

my $database = "lex";
my $data_source = "DBI:mysql:database=$database;host=localhost";
my $username = "surfy";
my $password = "lex2846";
$dbh = DBI->connect($data_source,$username,$password);

$bsth = $dbh->prepare("SELECT hotelid,name,city,numberofrooms,stateprovince,country,longitude,latitude,highrate,lowrate FROM hotels WHERE (stateprovince = \"$gostate\" and country = \"US\") ORDER by city;");
$bsth->execute();

$nextcity = "somewrongcity";

$open1 = ">/home2/surfy/www/$thedir/$gostate.html";
unlink($open1);
print "\n$open1";
open(OPEN1, $open1) || print "problems writing file state $open1<p>";
LayoutPageLeft();

$hotels_per_city = 0;
$test_long = 0;  # x
$test_lat = 0;    #y
$valid_long_lat =0;

while (my $bsref = $bsth->fetchrow_hashref())
   {
        $sHotelID = $bsref->{'hotelid'};
        $sName = $bsref->{'name'};
	$sCity = $bsref->{'city'};
	$sCy = $bsref->{'country'};
	$sHigh = $bsref->{'highrate'};
	$sLow = $bsref->{'lowrate'};
        $NumberOfRooms = $bsref->{'numberofrooms'};
        $lo = $bsref->{'longitude'};
        $la = $bsref->{'latitude'};
    
 	if ($nextcity NE $sCity)
            {
	    if ($hotels_per_city > 0)
	       { 
		 ###  -------------------- complete, move to next one
	       if ( $valid_long_lat != 0.0 ) {
	          $test_long = $test_long / $valid_long_lat;
	          $test_lat = $test_lat / $valid_long_lat;
	          } 
               
	       ##if ( $hotels_per_city < 20) {
	  	##     print OPEN2 "<p><font face=verdana><b>Others Nearby Hotels</b></font><p>";
		##     ######### print OPEN2 "<p> summary long, lat: $test_long, $test_lat";
		##     FindNearbyHotelsAll(); 
		##     }
	       LayoutPageRight2();
               
	       TheFoot2();
	       close(OPEN2);
	         
	       $test_long = 0;  # x
	       $test_lat = 0;    #y
	       $valid_long_lat = 0;
	       $hotels_per_city = 0;
	    }

	    $citypage = "http://$domain/$linkdir/$sCity $gostate.html";
	    $_ = $citypage;
	    $exch1 = "%20";
	    s/\s/$exch1/eg;
	    $citypage = $_;
 	    print OPEN1 "<p><a href=$citypage>$sCity, $gostate HOTELS</a>";
            $nextcity = $sCity;

	    $_ = $sCity;
	    s/\s/'+'/eg;
	    $sCityz = $_;
	    ## $sCity = $nextcity ;

  	    #open citypage
	    $opencity = ">/home2/surfy/www/$thedir/$sCity $gostate.html";
	    unlink($opencity);
	    print "\n$opencity";
	    open(OPEN2, $opencity) || print "problems writing file state $open1<p>";
	    LayoutPageLeft2();
            }

        if ( ($lo > 0.0 || $lo < 0.0) && ($la > 0.0 || $la < 0.0) )    {
            $test_long = $test_long +  $bsref->{'longitude'};  # x
            $test_lat = $test_lat +  $bsref->{'latitude'};;    #y
            $valid_long_lat++;
            print "\nlong. = $lo, $valid_long_lat";
            }
        else {
            print "\n long/lat $lo, $la  : $valid_long_lat";
 	    }

	 $hotels_per_city++;
         OutputHotel($sHotelID, $sName, $sCity,$ref->{'stateprovince'},$bsref->{'country'}, $sLow, $sHigh);
        ##### print OPEN2 "<br>$lo, $la, hotels = $valid_long_lat";
   }

 if ( $valid_long_lat != 0.0 ) {
	      $test_long = $test_long / $valid_long_lat;
	    $test_lat = $test_lat / $valid_long_lat;
	 } 

LayoutPageRight2();
 
TheFoot2();

$bsth->finish();
$dbh->disconnect();


close(OPEN2);
LayoutPageRight();
close(OPEN1);

}


sub LayoutPageLeft()
{
 # header
 Header();

print OPEN1 <<EOM;
<table width=100% bgcolor=#F0e030 cellpadding=4>
<tr><td align=left width=36%> &nbsp;<font face="verdana,helvetica,sans-serif" size="4" color="#000000">
<b>$hotelintro $thestatelong</b></font></td>
<td width=64% align=right>
. 
 
</tr>
</table>
<p>
EOM

 print OPEN1 "<table><tr><td width=40 bgcolor=#F0e030>&nbsp;</td><td valign=_top>";

}




sub LayoutPageRight2()
{

 # right side = related
print OPEN2 <<EOM;

</td><td valign=top width=40>&nbsp;
</td><td valign=top width=360>
EOM

  

#### bgcolor=#fbfbde

if ( $valid_long_lat != 0.0) {
    print OPEN2 <<EOM;
 <font color=green face=verdana>
$sitename offers a real-time online ordering to most hotels in $nextcity, $mode_state - $thestatelongz. 
Upon making a discount hotel reservation, you will immediately receive an email confirmation for your each 
hotel reservation. Search for $sCity hotels by selecting a hotel. 
You may search for hotels outside of $nextcity by using the hotel search box above. 
Have fun at in $nextcity $mode_state - $thestatelongz.
</font><p>
    <font color=black face=verdana><b>Nearby Cities</b></font> <p>
EOM

   FindNearbyCities();
   }  # of if related cites
 
print OPEN2 <<EOM;
</td><td valign=_top width=50>&nbsp;</td>

<td valign=_top width=410>
EOM

   if ($sitename NE "Ergova") { 
          ProcessOverture2();
        }
    else 
       {
       Amazon();  
       }
 print OPEN2 "</td></tr></table>";

}








sub HotelGoSQL()
{

my $database = "lex";
my $data_source = "DBI:mysql:database=$database;host=localhost";
my $username = "surfy";
my $password = "lex2846";
$dbh = DBI->connect($data_source,$username,$password);

#$sth = $dbh->prepare("SELECT hotelid,name,city,numberofrooms,stateprovince,country,highrate,lowrate FROM hotels WHERE name like \"\%$thestatelong\%\" order by name;");

$sth = $dbh->prepare("SELECT hotelid,name,city,numberofrooms,stateprovince,country,highrate,lowrate FROM hotels WHERE (city like \"\%$thestatelong\%\" and country like \"\%$cy\%\") or (name like \"\%$thestatelong\%\" and country like \"\%$cy\%\")order by name;");
$sth->execute();



while (my $ref = $sth->fetchrow_hashref())
       {

           $sHotelID = $ref->{'hotelid'};
           $sName = $ref->{'name'};
	   $sCity = $ref->{'city'};
	    $sHigh = $ref->{'highrate'};
	    $sLow = $ref->{'lowrate'};
           $NumberOfRooms = $ref->{'numberofrooms'};
           OutputHotel($sHotelID, $sName, $sCity,$ref->{'stateprovince'},$ref->{'country'}, $sLow, $sHigh);
       }

$sth->finish();
$dbh->disconnect();
}

sub OutputHotel()
{
my $mHotelID = $_[0];
my $mName    = $_[1];

$_ = $mName;
s/\s/'+'/eg;
$pName = $_;
 
print OPEN2 <<EOM;

<table  width=290 cellpadding=1 cellspacing=0 border=0 bgcolor=#ffa162><tr><td>
<table width=100% cellpadding=4 cellspacing=0 border=0 bgcolor=#fbfbde><tr valign=top>
<td><img src="$littlelogo"  border=0 alt=""></td>
<td>
<a href ="http://$domain/$sendto$mHotelID/en-$pName.html">$mName</a><br>
$_[2], $_[3],$_[4]<br>Rates from $_[5] to $_[6]
</b></font></td>
</tr></table></td></tr></table>
<br>
EOM
}

sub OutputHotelNear()
{
my $mHotelID = $_[0];
my $mName    = $_[1];

print OPEN2 <<EOM;
<font size=-1>
<a href ="http://www.surfy.com/cgi-bin/sendto?&hotelID=$mHotelID&hotnetrates=true&requestKey=&isCondos=false&isHotels=true&mode=1&location=&star=null&showInfo=true">$mName</a><br>
$_[2], $_[3],$_[4]<br>Rates from $_[5] to $_[6]</font>
<br>
EOM
}







sub ProcessOverture()
{
print OPEN1 "<font face=verdana><b>Popular in $thelong</b></font>";

$test = "inventory.overture.com";
$document = "/d/searchinventory/suggestion/?term=$thestatelongz";

$remote = IO::Socket::INET->new( Proto => "tcp",
    PeerAddr => $test,
   PeerPort => "http(80)" );
unless($remote) { die "Surfy is Broken"; }
$remote->autoflush(1);
print $remote "GET $document HTTP/1.0\n\n";

$bigstring = "";
while ( <$remote> ) {
  $bigstring = $bigstring . $_; }
-close $remote;
$_ = $bigstring;

#  print _;

/Count/;
$_ = $';

/<\/table>/;
$_ = $`;



while (/nbsp;/)
{
   $_ = $';

   /</;
   $overcount = $`;
   $_ = $';

   /term=/;
   $_ = $';

 #  /">/;
   /\&mkt/;

   $overname = $`;
   $_ = $';
   $savespot = $';


     $le_space= "%20";
     $_ = $overname;
     s/$le_space/' '/eg;
     $le_screen = $_;

     $_ = $overname;
     s/\s/'+'/eg;
     s/$le_space/'+'/eg;
     $le_link = $_;
   
   if ($sitename EQ "Ergova") {
           print OPEN1 "<p><a href=http://www.surfy.com/cgi-bin/search?key=$le_link>$le_screen</a>";
           }
   else
       {
        print "<p>$le_screen";
       }
  $_ = $savespot;
}




}  # end Overture







sub ProcessOverture2()
{
print OPEN2 "<font face=verdana><b>Popular Searches</b></font>";

$test = "inventory.overture.com";
$document = "/d/searchinventory/suggestion/?term=$sCityz";

$remote = IO::Socket::INET->new( Proto => "tcp",
    PeerAddr => $test,
   PeerPort => "http(80)" );
unless($remote) { die "Surfy is Broken"; }
$remote->autoflush(1);
print $remote "GET $document HTTP/1.0\n\n";

$bigstring = "";
while ( <$remote> ) {
  $bigstring = $bigstring . $_; }
-close $remote;
$_ = $bigstring;

#  print _;

/Count/;
$_ = $';

/<\/table>/;
$_ = $`;



while (/nbsp;/)
{
   $_ = $';

   /</;
   $overcount = $`;
   $_ = $';

   /term=/;
   $_ = $';

 #  /">/;
   /\&mkt/;

   $overname = $`;
   $_ = $';
   $savespot = $';


     $le_space= "%20";
     $_ = $overname;
     s/$le_space/' '/eg;
     $le_screen = $_;

     $_ = $overname;
     s/\s/'+'/eg;
     s/$le_space/'+'/eg;
     $le_link = $_;

   print OPEN2 "<p><a href=http://www.surfy.com/cgi-bin/search?key=$le_link>$le_screen</a>";

  $_ = $savespot;
}



}  # end Overture











sub GoogleSide()
{
print <<EOM;
<script type="text/javascript"><!--
google_ad_client = "pub-8903494280852184";
google_ad_width = 160;
google_ad_height = 600;
google_ad_format = "160x600_as";
google_ad_type = "text_image";
google_ad_channel ="1440094777";
google_color_border = "6699CC";
google_color_bg = "3D81EE";
google_color_link = "FFFFFF";
google_color_text = "FFFFFF";
google_color_url = "AECCEB";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
EOM
} #end GoogleSide





sub OldJunk()
{
# DEFINE Surfy, Ergova, etc.
# --------------------------- 

$thedir = "ztest";  # hotel=international, hotels or ztest directory
$state_focus = 3;  # if blank, do all??????
$cid = "48696"; # surfy  

if ( $cid eq "48696") #Surfy!
 {  
    $sitename = "Surfy!";  #Surfy!
    $hcolor = "#D3DCE3";
    $linkdir = "hotels";  # change to hotels to hotel for international
    
    $hotelintro = "Hotels for"; #surfy
    $biglogo = "http://www.surfy.com/gif/surfy6.gif";
    $littlelogo = "http://www.surfy.com/gif/surfyguy.gif";
    $cid = "48696"; # surfy  
    $domain = "www.surfy.com";
    $nearhotel = "Near Discount Hotel"; # used?
    $img1 = "/gif/surfy6.gif";  #surfy
    $sendto = "/hotel-discount/key/en.html"; #surfy
    $titletext = "Hotels - Discount & Resort Hotels in ";
    $header3 = "Discount, Deals, & Resort";
    $h1text = "Hotes to Cheap";   
   }
else            #ergova 
   {
    $sitename = "Ergova";  
    $hcolor = "#D3DCE3";
    $littlelogo = "http://www.ergova.com/pin.gif";
    $biglogo = "http://www.ergova.com/ergova.jpg";
    $header3 = "Cheap, Discount & Luxury";
    $domain = "www.ergova.com";

    $linkdir = "hotel";  # check if hotel or hotels

    $cid = "72790"; # ergova 
    $nearhotel = "hotel"; # for ergova

    $hotelintro = "A hotel in  ";
    $img1 = "http://www.ergova.com/ergova.jpg";
    $h1text = "Discount and Deals";  # Discount, Deals, & Low Price
    $titletext = "Hotels - Discounted - Cheap, Motels & Hotels in ";
    $sendto = "scgi-bin/buy-hotel.cgi";  # ergova
   }

# ---------------------------- mode A stuff, command line / deleted
 
                                       

# ---------------------------- mode B stuff, US or World .. not used
$thestatelong = $query->param("search");
unless ($thestatelong) { $thestatelong = $query->param("key"); }
$cy = $query->param("cy");
unless ($cy) { $cy = "US"; }
$world = $query->param("country");
unless ($world) { $world = "us"; }

 


$_ = $thestatelong;
s/\s/'+'/eg;
$thestatelongz = $_;


@array=(
"AD",
"AE",
"AG",
"AI",
"AL",
"AM",
"AN",
"AR",
"AS",
"AT",
"AU",
"AW",
"AZ",
"BA",
"BB",
"BE",
"BF",
"BG",
"BH",
"BI",
"BM",
"BN",
"BO",
"BR",
"BS",
"BT",
"BV",
"BY",
"BZ",
"CA",
"CG",
"CH",
"CI",
"CK",
"CL",
"CM",
"CN",
"CO",
"CR",
"CY",
"CZ",
"DE",
"DK",
"DM",
"DO",
"DZ",
"EC",
"EE",
"EG",
"ER",
"ES",
"ET",
"FI",
"FJ",
"FM",
"FR",
"GA",
"GB",
"GD",
"GE",
"GF",
"GH",
"GI",
"GL",
"GM",
"GN",
"GP",
"GR",
"GT",
"GU",
"GY",
"HK",
"HN",
"HR",
"HT",
"HU",
"ID",
"IE",
"IL",
"IN",
"IS",
"IT",
"JM",
"JO",
"JP",
"KE",
"KG",
"KH",
"KN",
"KR",
"KW",
"KY",
"KZ",
"LA",
"LB",
"LC",
"LK",
"LS",
"LT",
"LU",
"LV",
"MA",
"MC",
"MD",
"MG",
"MK",
"ML",
"MO",
"MQ",
"MR",
"MT",
"MU",
"MV",
"MW",
"MX",
"MY",
"MZ",
"NA",
"NC",
"NI",
"NL",
"NO",
"NP",
"NZ",
"OM",
"PA",
"PE",
"PF",
"PG",
"PH",
"PK",
"PL",
"PR",
"PT",
"PW",
"PY",
"QA",
"RE",
"RO",
"RU",
"RW",
"SA",
"SC",
"SE",
"SG",
"SI",
"SK",
"SN",
"ST",
"SV",
"SY",
"SZ",
"TC",
"TD",
"TF",
"TH",
"TJ",
"TK",
"TM",
"TN",
"TR",
"TT",
"TW",
"TZ",
"UA",
"UY",
"UZ",
"VA",
"VC",
"VE",
"VG",
"VI",
"VN",
"VU",
"YE",
"ZA",
"ZM",
"ZW"
);

@arrayLong=(
"Andorra",
"United Arab Emirates",
"Antingua and Barbuda",
"Anguilla",
"Albania",
"Armenia",
"AN",
"Argentina",
"American Samoa",
"Austria",
"Australia",
"Aruba",
"Azerbaijan",
"Bonsia and Herzegovina",
"Barbados",
"Belgium",
"Burkina Fasa",
"Bulgaria",
"Bahrain",
"Burundi",
"Bermuda",
"Bruni Darussalam",
"Bolivia",
"Brasil",
"Bahamas",
"Bhutan",
"Bouvet Islands",
"Belarus",
"Belize",
"Canada",
"Congo",
"Switzerland",
"Cote D Ivoire (Ivory Coast)",
"Cook Islands",
"Chile",
"Cameroon",
"China",
"Columbia",
"Costa Rica",
"Cyprus",
"Czech Repulic",
"Germany",
"Denmark",
"Dominca",
"Dominican Republic",
"Algeria",
"Ecuador",
"Estonia",
"Egpyt",
"Eritrea",
"Spain",
"Ethiopia",
"Finland",
"Fiji",
"Micronesia",
"France",
"Gabon",
"UK",
"Gredneda",
"Georgia",
"French Guiana",
"Ghana",
"Gibraltar",
"Greenland",
"Gambia",
"Guinea",
"Equatorial Guinea",
"Greece",
"Guatemala",
"Guam",
"Guyana",
"Hong Kong",
"Honduras",
"Crotia / Hrvatska",
"Haiti",
"Hungary",
"Indonesia",
"Ireland",
"Isreal",
"India",
"Iceland",
"Italy",
"Jamaica",
"Jordan",
"Japan",
"Kenya",
"Krygyzstan",
"Cambodia",
"Saint Kitts and Nevis",
"Korea",
"Kuwait",
"Cayman Islands",
"Kazakhstan",
"Laos",
"Lebanon",
"Saint Luca",
"Sri Lanka",
"Lesotho",
"Lithuania",
"Luxembourg",
"Latvia",
"Morocco",
"Monaco",
"Moldova",
"Madagasar",
"Macedonia",
"Mali",
"Macau",
"Martinique",
"Muritania",
"Malta",
"Mauritius",
"Malvdives",
"Malawi",
"Mexico",
"Malaysia",
"Mozambique",
"Nambia",
"New Caledonia",
"Nicaragua",
"Netherlands",
"Norway",
"Nepal",
"New Zealand",
"Oman",
"Panama",
"Peru",
"French Polynesia",
"Papua New Guinea",
"Philippines",
"Pakistan",
"Poland",
"Puerto Rico",
"Portugal",
"Palau",
"Paraguay",
"Qatra",
"Reunion",
"Romania",
"Russia",
"Rwanda",
"SA",
"Saudi Arabia",
"Sweeden",
"Singapore",
"Slovenia",
"Slovak Republic",
"Senegal",
"Sae Tome and Principe",
"El Salvador",
"Syria",
"Swaziland",
"Turks and Caicos Islands",
"Chad",
"French Southern Territory",
"Thailand",
"Tajikstan",
"Tokelau",
"Turkmenistan",
"Tunisia",
"Turkey",
"Trinidad and Tobago",
"Taiwan",
"Tanzania",
"Ukraine",
"Uruguay",
"Uzbekistan",
"Vactican City State (Holy See)",
"Saint Vicent and the Grenadines",
"Venezuela",
"British Virgin Islands",
"U.S. Virgin Islands",
"Vietnam",
"Vanuatu",
"Yemen",
"South Africa",
"Zambia",
"Zimbabwe"
);



@array=(
 "AL",
 "AK",
 "AR",
 "AZ",
 "CA",
 "CO",
 "CT",
 "DE",
 "DC",
 "FL",
 "GA",
 "HI",
 "ID",
 "IL",
 "IN",
 "IA",
 "KS",
 "KY",
 "LA",
 "ME",
"MD",
"MA",
"MI",
"MN",
"MS",
"MO",
"MT",
"NE",
"NV",
"NH",
"NJ",
"NM",
"NY",
"NC",
"ND",
"OH",
"OK",
"OR",
"PA",
"PR",
"RI",
"SC",
"SD",
"TN",
"TX",
"UT",
"VT",
"VI",
"VA",
"WA",
"WV",
"WI",
"WY"
);


@arrayLong=(
 "Alabama",
 "Alaska",
 "Arkansa",
 "Arizona",
 "California",
 "Colorado",
 "Conneticut",
 "Delaware",
 "WashingtonDC",
 "Florida",
 "Georgia",
 "Hawaii",
 "Idaho",
 "Illinois",
 "Indiana",
 "Iowa",
 "Kansas",
 "Kentucky",
 "Louisiana",
 "Maine",
"Maryland",
"Massachusetts",
"Michigan",
"Minnesota",
"Mississippi",
"Missouri",
"Montana",
"Nebraska",
"Nevada",
"New Hampshire",
"New Jersey",
"New Mexico",
"New York",
"North Carolina",
"North Dakato",
"Ohio",
"Oklahoma",
"Oregon",
"Pennsylvania",
"Puerto Rico",
"Rhode Island",
"South Carolina",
"South Dakata",
"Tennessee",
"Texas",
"Utah",
"Vermont",
"Virgin Islands",
"Virginia",
"Washington State",
"West Viginia",
"Wisconsin",
"Wyoming"
);

$buildstate = "AZ";
$buildstatetext = "Arizona";

$buildstate = $query->param("st");
$buildstatetext  = $query->param("state");

$buildcy = "US";
MakeStates();

# dont do this now
if ($joemillionaire > 99 )  { 
   $anum = 0;
    
   foreach (@array) {
      $_ = $array[$anum];   # state or country code
      $gostate = $_;
      $_ = $arrayLong[$anum];
      $thestatelong = $_;
      s/\s/'+'/eg;
      $thestatelongz = $_;
      $mode_state = $gostate;

      ##      if ( $anum == 46 ) {  
        if ( $anum == $state_focus ) {  
             ErgovaStates();
       	}  #if
     $anum++;

      } #for
 }


 } # end of old
 
sub GetGoogle()
 {
 $googleline = "
 <script type=\"text/javascript\"><!--
google_ad_client = \"pub-8903494280852184\";
google_ad_width = 728;
google_ad_height = 15;
google_ad_format = \"728x15_0ads_al_s\";
//2007-04-30: hotels
google_ad_channel = \"1440094777\";
google_color_border = \"341473\";
google_color_bg = \"FFFFFF\";
google_color_link = \"333333\";
google_color_text = \"FFFFFF\";
google_color_url = \"AECCEB\";
//-->
</script>
<script type=\"text/javascript\"
  src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script>
";

 }
 
 sub GetGoogleRight()
 {
 $googleright = "
<script type=\"text/javascript\"><!--
google_ad_client = \"pub-8903494280852184\";
google_ad_width = 120;
google_ad_height = 600;
google_ad_format = \"120x600_as\";
google_ad_type = \"text_image\";
//2007-04-30: hotels
google_ad_channel = \"1440094777\";
google_color_border = \"6F3C1B\";
google_color_bg = \"000000\";
google_color_link = \"B47B10\";
google_color_text = \"FFFFFF\";
google_color_url = \"7F7F7F\";
//-->
</script>
<script type=\"text/javascript\"
  src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script>
";

 }