<?php

$search = $_GET['search'];
$pageOffset = 7;
$anchor = $_GET['wine'];

$happyhourprice = -2;

date_default_timezone_set("America/Belize"); 
if (time() >= strtotime('14:55:00') AND time() <= strtotime('17:00:00')){
$happyhour = True;
}
else{
$happyhour = False;
}

$happyhour = False;   //don't use for now
$tableName="Wines2";
$variable = $_GET['WineID'];
$listType = "byProfile";
$listName = "Beer";
$linkCount = $_GET['linkCount'];

$wineNumber = 0;
$screenWidth = 1000;

if(!empty($search)){
  $listType = "bySearch";
}

$screenWidth = 1000;
$device = "iPad";
$singlePage="single-item/";

if(wonderplugin_is_device('iPhone')){
$screenWidth = 400;
$device = "iPhone";
}
elseif(wonderplugin_is_device('Windows')){
$screenWidth = 1000;
$device = "Windows";
}
elseif(wonderplugin_is_device('iPad')){
$screenWidth = 1000;
$device = "iPad";
}
elseif(wonderplugin_is_device('Mac')){
$screenWidth = 1000;
$device = "Mac";

}
elseif(wonderplugin_is_device('Android')){
$screenWidth = 1000;
$device = "Android";
}


   $con = mysqli_connect('localhost', 'mayabeac_wine', '3]eGo-r(Scru',"mayabeac_WineList");
        if (mysqli_connect_errno()) {
            echo"
                Failed to connect to the MySQL DB:".mysqli_connect_error();
            }
           else{


}
/*
if (wonderplugin_is_device('iPhone')){
$singlePage="single-item/";
}
else{
$singlePage="single-item/";
}

*/
mysqli_query($con, "SET NAMES 'utf8'");


if($listType=="byProfile"){

      if($listName=="Beer"){
            $sql="SELECT * FROM ".$tableName." WHERE WineType = 'Beer' AND OutOfStock=0 AND Archived=0 AND LeaveOffMenu=0 ORDER BY WineCountry, SortOrder";
            $showName="Beer";
            $listTypeName="Beer";
      }
       
}




// Read all wines to determine length of list.
// Need to sort items based on match score (desc) then price (asc). Wines by the glass will appear first as they have 6 added
// to the base score whereas other wines start at 0

       $IDarray=array();
       $wineCount=0;
      $foodWines = array();      //two dimensional array 1= name, 2 = food1, 3 = food2, 4 = food3, 5 = food4, 6 = score, 7 = country, 8 = varietal, 9 = btl or glass, 10 = WineID, 11 = Price. 12 = Desc1, 13 = Desc2, 14= Desc3, 15 = Desc 4, 16 = Image1, 17= Image2, 18 = QtyInStock, 19 = Eyes, 20 = Nose, 21 = Mouth, 22 = Vintage, 23 = Alcohol Content, 24 = Pairing Suggestion , 25=Cases Produced, 26 = WineRegion, 27 = Wine Subregion, 28 = Nationality


       $records1=mysqli_query($con, $sql);
       while ($row1 = mysqli_fetch_assoc($records1)) {
            
      $wineCount = $wineCount+1;

      $foodWines[$wineCount][1] = $row1['WineName'];
      $foodWines[$wineCount][6] = 0;
      $foodWines[$wineCount][7]  = $row1['WineCountry'];
      $foodWines[$wineCount][8] = $row1['WineVarietal'];
      $foodWines[$wineCount][10] = $row1['ID'];
      $foodWines[$wineCount][11] = $row1['WinePrice'];
      //$foodWines[$wineCount][12] = $row1['PairingValue1'];
      //$foodWines[$wineCount][13] = $row1['PairingValue2'];
      //$foodWines[$wineCount][14] = $row1['PairingValue3'];
      //$foodWines[$wineCount][15] = $row1['PairingValue4'];
      $foodWines[$wineCount][32] = $row1['Desc1'];
      $foodWines[$wineCount][33] = $row1['Desc2'];
      $foodWines[$wineCount][34] = $row1['Desc3'];
      $foodWines[$wineCount][35] = $row1['Desc4'];
      $foodWines[$wineCount][16] = $row1['Image1'];
      $foodWines[$wineCount][17] = $row1['Image2'];
      $foodWines[$wineCount][18] = $row1['QtyInStock'];
      $foodWines[$wineCount][19] = $row1['Eyes'];
      $foodWines[$wineCount][20] = $row1['Nose'];
      $foodWines[$wineCount][21] = $row1['Mouth'];
      $foodWines[$wineCount][22] = $row1['WineVintage'];
      $foodWines[$wineCount][23] = $row1['AlcoholContent'];
      $foodWines[$wineCount][24] = $row1['PairingSuggestion'];
      $foodWines[$wineCount][25] = $row1['CasesProduced'];
      $foodWines[$wineCount][26] = $row1['WineRegion'];
      $foodWines[$wineCount][27] = $row1['WineSubregion'];
      $foodWines[$wineCount][28] = $row1['WineNationality'];  
      $foodWines[$wineCount][29] = $row1['WineType']; 
      $foodWines[$wineCount][30] = $row1['WineSize']; 
      $foodWines[$wineCount][67] = $row1['WineSizeUnit']; 
      
      $foodWines[$wineCount][36] = $row1['AvailableToday'];
      $foodWines[$wineCount][37] = $row1['AvailablePremium'];
      $foodWines[$wineCount][38] = $row1['AvailableOnRequest'];  
      $foodWines[$wineCount][39] = $row1['SoldAs'];
       
 //echo "<p>".$row1['SoldAs']."</p>";

      

      $foodWines[$wineCount][51] = $row1['FoodPairing1'];
      $foodWines[$wineCount][52] = $row1['FoodPairing2'];
      $foodWines[$wineCount][53] = $row1['FoodPairing3'];
      $foodWines[$wineCount][54] = $row1['FoodPairing4'];
      $foodWines[$wineCount][55] = $row1['FoodPairing5'];
      $foodWines[$wineCount][56] = $row1['FoodPairing6'];
      $foodWines[$wineCount][57] = $row1['FoodPairing7'];
      $foodWines[$wineCount][58] = $row1['FoodPairing8'];
      $foodWines[$wineCount][59] = $row1['FoodPairing9'];
      $foodWines[$wineCount][60] = $row1['FoodPairing10'];
      $foodWines[$wineCount][61] = $row1['FoodPairing11'];
      $foodWines[$wineCount][62] = $row1['FoodPairing12'];
      $foodWines[$wineCount][63] = $row1['FoodPairing13'];
      $foodWines[$wineCount][64] = $row1['FoodPairing14'];
      $foodWines[$wineCount][65] = $row1['FoodPairing15'];
      $foodWines[$wineCount][66] = $row1['AvailableForSale'];
  

      if( $foodWines[$wineCount][29] == "Glass"){
          $foodWines[$wineCount][6] = 100;
          $foodWines[$wineCount][9] = 0;
          }
      else{
            $foodWines[$wineCount][9] = 1;
            $foodWines[$wineCount][6] = 0;
      }
if($listType=='bySearch'){
for($x = 1; $x <= 40; $x++){
if($x!=16 AND $x!=17){
$foodWines[$wineCount][$x]= preg_replace("/".$search."/i", "<span style='background-color: #FFFF00;'>\$0</span>",$foodWines[$wineCount][$x]);
}
}
}
if($listType == 'byFood'){

// only sort the array if this is a food match selection

$minPairing = 0;

for($x = 1; $x <= 15; $x++){

if($food1!=""){
         if($row1['FoodPairing'.$x]==$food1){
          
          $foodWines[$wineCount][12] = $row1['PairingValue'.$x] * -1 + 6; 
          if($foodWines[$wineCount][12]==6){
           $foodWines[$wineCount][12]=5;
          } 
          if($foodWines[$wineCount][12]==0 OR is_null($foodWines[$wineCount][12])){
             $foodWines[$wineCount][12]=5; 
          }
         $foodWines[$wineCount][6] =$foodWines[$wineCount][6]+$foodWines[$wineCount][12];
         }   
}

if($food2!=""){
         if($row1['FoodPairing'.$x]==$food2){
         $foodWines[$wineCount][13] = $row1['PairingValue'.$x] * -1 + 6; 
         if($foodWines[$wineCount][13]==6){
           $foodWines[$wineCount][13]=5;
          } 
         if($foodWines[$wineCount][13]==0 OR is_null($foodWines[$wineCount][13])){
             $foodWines[$wineCount][13]=1; 
          }
         $foodWines[$wineCount][6] =$foodWines[$wineCount][6]+$foodWines[$wineCount][13];
         }   
}

if($food3!=""){
         if($row1['FoodPairing'.$x]==$food3){
         $foodWines[$wineCount][14] = $row1['PairingValue'.$x] * -1 + 6; 
          if($foodWines[$wineCount][14]==6){
           $foodWines[$wineCount][14]=5;
          } 
         if($foodWines[$wineCount][14]==0 OR is_null($foodWines[$wineCount][14])){
             $foodWines[$wineCount][14]=1; 
          }
        $foodWines[$wineCount][6] =$foodWines[$wineCount][6]+$foodWines[$wineCount][14];
         }   
}

if($food4!=""){
         if($row1['FoodPairing'.$x]==$food4){
         $foodWines[$wineCount][15] = $row1['PairingValue'.$x] * -1 + 6;
          if($foodWines[$wineCount][15]==6){
           $foodWines[$wineCount][15]=5;
          } 
          if($foodWines[$wineCount][15]==0 OR is_null($foodWines[$wineCount][15])){
             $foodWines[$wineCount][15]=1; 
          }
         $foodWines[$wineCount][6] =$foodWines[$wineCount][6]+$foodWines[$wineCount][15];
         }   
   }   

}  


if($foodWines[$wineCount][12] <3  AND  $foodWines[$wineCount][13] < 3 AND $foodWines[$wineCount][14] < 3 AND $foodWines[$wineCount][15] < 3){
$wineCount=$wineCount - 1;

}

}
       
}



//sort Array
if($listType=='byFood'){
foreach ($foodWines as $key => $row) {
    $score[$key]  = $row[6];
    $winePrice[$key] = $row[11];
}

// With the use of the column keys you can now sort entire array by these columns and keep the row index value intact if they are non-numeric. This is good if your using some kind of hashed index.

array_multisort($score, SORT_DESC, $winePrice, SORT_DESC, $foodWines);
}


     // echo $wineCount;
       
if($listType == 'byFood'){
$xstart = 0;
$totalWines = $wineCount-1;
}
else{
$xstart = 1;
$totalWines = $wineCount;

}


if($totalWines!=0){
 for($x = $xstart; $x <= $totalWines; $x++){
if($x<$pageOffset){
$Offset = "";
}
else{
$temp = $x-$pageOffset;
$Offset = "#wine".$temp;
}
if($listType == 'byFood'){
$y=$x+1;
}
else{
$y=$x;
}       

   if($listType=="byCountry"){

               $listTypeName=$foodWines[$x][28];
          

         }
         elseif($listType=="byProfile" AND $listTypeName!=""){


         }
        elseif($listType=="byProfile" AND $listTypeName==""){

          $listTypeName=$listName;
         }
        elseif($listType=="byVarietal"){
          $listTypeName=$listName;
        }

        if($listTypeName=="Rose"){
         $listTypeName="Rosé";
         }

        if($listType=='bySearch'){
        $browsing=$y." of ".$wineCount."&nbsp;<b>Results for '".ucwords($search)."'</b>";
       }
       elseif($listType=='byCountry'){

              $browsing=$y." of ".$wineCount."&nbsp;<a href='/".$listType."/?Listing=".$listName.$Offset."'><b>".$listTypeName." Wines</b></a>";


           
             if($foodWines[$x][29]=='Rose'){
             $showName=$listName."&nbsp;(Rosé)";
             }
             else{
             $showName=$listName."&nbsp;(".$foodWines[$x][29]. " Wines)";
             }
        }
        elseif($listType=='byVarietal'){
                  $browsing=$y." of ".$wineCount."&nbsp;<a href='/".$listType."/?Listing=".$listName.$Offset."'><b>".$listTypeName."</b></a>";

                  $showName=$listName;
         }
         elseif($listType=='byProfile'){
            $browsing=$y." of ".$wineCount."&nbsp;<a href='/".$listType."/?Listing=".$listName.$Offset."'><b>".$listTypeName." </b></a>";

            $showName=$listName;
         }
         elseif($listType=="byGlass"){
         $browsing=$y." of ".$wineCount."&nbsp;<a href='/".$listType."/?Listing=".$listName.$Offset."'><b> Wines By The Glass</b></a>";

         }
         
         elseif($listType=="byFood"){

           $browsing=$y." of ".$wineCount."&nbsp;<a href='/foodmatches/?food1=".$food1."&food2=".$food2."&food3=".$food3."&food4=".$food4."'><b> Food Matches</b></a>";
           
          }

if($browsing==""){

        $browsing=$y." of ".$wineCount."&nbsp;<a href='/".$listType."/?Listing=".$listName.$Offset."'><b>".$listTypeName."</b></a>";
}


       echo "<body>";



echo "<a class='anchor' id='wine".$y."'></a>";       
if($x!=1){
echo "<p>&emsp;</p>";
echo "<p>&emsp;</p>";
echo "<p>&emsp;</p>";
echo "<p>&emsp;</p>";
echo "<p>&emsp;</p>";
echo "<p>&emsp;</p>";
}


//set to 500 now so it does not change - effectively disabling

        if(strlen($foodWines[$x][1]."&emsp".$foodWines[$x][22])>500){
         $nameFont="1.1em";
         }
        else{
        $nameFont="1.35em";
        }

  if($foodWines[$x][29] == 'Beer' OR $foodWines[$x][39] == 1){
        
         if(1 == 1){
                  if($happyhour==True){
                      $newPrice = $foodWines[$x][11] + $happyhourprice;
                      $winePrice = "<b><del>$".$foodWines[$x][11]."</del>&emsp;<font color='red'>$".$newPrice."</font></b>";
                     }
                    else{
                      $winePrice = "<b>$".$foodWines[$x][11]."</b>";
                     }
             
          }
          else{
           $winePrice = "<b>$".$foodWines[$x][11]."/glass (".$foodWines[$x][45]."oz)</b>";
           }
         }        
        else{
        $winePrice= "<b>$".$foodWines[$x][11]."</b>";
        }

      if($foodWines[$x][30]<750 AND $foodWines[$x][30]!=0){

      if($foodWines[$x][30]==375){
        $sizeInfo = " (half bottle)";
       } 
       else{
        $sizeInfo = " (small bottle)";
        }

        }
        else{
         $sizeInfo = "";
         }  
       $sizeInfo = "";  //not using for beer

$browsing="<b><a href='/byBeer'>Back to Beer List</a></b>";


if ($device == 'Windows' OR $device == 'Mac' OR $device == 'Linux'){
        $bodytext="justify";
        
       echo "<table>";
       echo "<colgroup>";
        echo "<col span='1' style='width: 25%;'>";
        echo "<col span='1' style='width: 74%;'>";
        echo "</colgroup>";


  // echo "<a class='anchor' id='wine".$y."'></a>";   


//echo "<tr><td style='text-align: center; font-size: 1.5em;  font-weight: bold;'>".$winePrice."</td></tr>



echo"<tr>";





  echo "<td style='vertical-align: top; text-align: center;'><img style='vertical-align: top; width: 28vw; height: 60vh; object-fit: contain;' src='".$foodWines[$x][16]."' alt='WineImage'></td>";


               echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1].$sizeInfo."&emsp;".$winePrice."</span><br>";


        }

elseif($device == 'iPad' OR $device == 'Android'){
   
  $bodytext="left";

      echo "<table>";

      echo "<colgroup>";
       echo "<col span='1' style='width: 30%;'>";
       echo "<col span='1' style='width: 69%;'>";
       echo "</colgroup>";


  
  //echo "<tr><td style='text-align: center; font-size: 1.5em;  font-weight: normal;'>".$winePrice."</td></tr>";
//echo "<tr><td style='text-align: center; font-size: 1.0em;  font-weight: normal;'>".$browsing."</td></tr>";
//<td style='text-align: left; font-size: 1.0em;  font-weight: normal;'>".$browsing."</td></tr>";

 echo"<tr>";
//if(!empty($foodWines[$x][17])){


//$tempstr = "changeImage(".$foodWines[$x][10].", &#039".$foodWines[$x][16]."&#039, &#039".$foodWines[$x][17]."&#039)";


//echo "<td style='vertical-align: top; text-align: center;'><div style='width:image width px; font-size:80%; text-align:center;'><a href='#' data-featherlight='".$foodWines[$x][17]."'><img id=".$foodWines[$x][10]." style='width: 30vw; object-fit: contain;' src='".$foodWines[$x][16]."' alt='WineImage'>Click Image for Front / Back View</div></td>";

//}
//else{
  echo "<td style='vertical-align: top; text-align: center;'><img style='width: 30vw; object-fit: contain;' src='".$foodWines[$x][16]."' alt='WineImage'></td>";

//}

            

     if($foodWines[$x][22] != 0){
  	         echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1]."&emsp; ".$foodWines[$x][22].$sizeInfo."</span><br>";
        }
        else{
                              echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1].$sizeInfo."&emsp;".$winePrice."</span><br>";
         }


        }

      elseif($device == 'iPhone'){

   $bodytext="left";
   


 
 //echo "<table>";

//echo "<tr><td style='display:block-inline; text-align: center; font-size: 1.1em;  font-weight: normal;'>".do_shortcode($prevWine)."&emsp;".$browsing."&emsp;".do_shortcode($nextWine)."</td></tr></table>";

 
      
      echo "<table>";
       echo "<colgroup>";
        echo "<col span='1' style='width: 35%;'>";
        echo "<col span='1' style='width: 64%;'>";
        echo "</colgroup>";  

 //echo "<tr><td style='text-align: center; font-size: 1.5em;  font-weight: normal;'>".$winePrice."</td></tr>";

//<td style='text-align: left; font-size: 1.0em;  font-weight: normal;'>".$browsing."</td></tr>";
         echo"<tr>";
   
//if(!empty($foodWines[$x][17])){
//$tempstr = "changeImage(".$foodWines[$x][10].", &#039".$foodWines[$x][16]."&#039, &#039".$foodWines[$x][17]."&#039)";

//echo "<td style='vertical-align: top; text-align: center;'><div style='width:image width px; font-size:80%; text-align:center;'><img id=".$foodWines[$x][10]." onclick='".$tempstr."' style='width: 30vw; object-fit: contain;' src='".$foodWines[$x][16]."' alt='WineImage'>Click Image for Front / Back View</div></td>";
//}
//else{
  echo "<td style='vertical-align: top; text-align: center;'><img style='width: 30vw; object-fit: contain;' src='".$foodWines[$x][16]."' alt='WineImage'></td>";

//}
         

     if($foodWines[$x][22] != 0){
  	         echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1]."&emsp; ".$foodWines[$x][22].$sizeInfo."</span><br>";
        }
        else{
                              echo "<td style='vertical-align:top; font-weight: normal; text-align: ".$bodytext."; line-height: 1.25em; padding-right: 20px; font-size: 1.35em'><span style='font-weight: bold'>".$foodWines[$x][1].$sizeInfo."&emsp;".$winePrice."</span><br>";
         }


        }
         

         //  ///Common Code Here
        

         
  	if($listType=="byFood"){

 $foodarray = array($foodWines[$x][51],$foodWines[$x][52],$foodWines[$x][53],$foodWines[$x][54],$foodWines[$x][55],$foodWines[$x][56],$foodWines[$x][57],$foodWines[$x][58],$foodWines[$x][59],$foodWines[$x][60],$foodWines[$x][61],$foodWines[$x][62],$foodWines[$x][63],$foodWines[$x][64],$foodWines[$x][65]);
         $goodfoods = "";
         $badfoods = "";

          if(in_array($food1, $foodarray)) {
           
                $goodfoods = $goodfoods.$xfood1;
           }
           elseif($food1!='none'){
                  $badfoods = $badfoods.", ".$xfood1;
            }

           if(in_array($food2, $foodarray)) {
                if($goodfoods!=""){
                $goodfoods = $goodfoods.", ".$xfood2;
                }
                else{
                $goodfoods = $goodfoods.$xfood2;
                 }
           }
           elseif($food2!='none'){
                  $badfoods = $badfoods.", ".$xfood2;
            }

   if(in_array($food3, $foodarray)) {
                if($goodfoods!=""){
                $goodfoods = $goodfoods.", ".$xfood3;
                }
                else{
                $goodfoods = $goodfoods.$xfood3;
                  }
           }
           elseif($food3!='none'){
                  $badfoods = $badfoods.", ".$xfood3;
            }

   if(in_array($food4, $foodarray)) {
                if($goodfoods!=""){
                $goodfoods = $goodfoods.", ".$xfood4;
                 }
                 else{
                 $goodfoods = $goodfoods.$xfood4;
                 }
           }
           elseif($food4!='none'){
                  $badfoods = $badfoods.", ".$xfood4;
            }
            
       // if($goodfoods!=""){
       // $goodfoods=substr($goodfoods, (strlen($goodfoods)-2)*-1);
        // echo "<font size='+1'><b>We suggest with: </b>".$goodfoods."<br><font>";
        //}

//alternate good food list - show all food listed as pairing with this wine
      





        if($badfoods!=""){
        $badfoods=substr($badfoods, (strlen($badfoods)-2)*-1);
 // leave off for now    echo "<font size='+1'><b>Mabye not so good with: </b>".$badfoods."<br><font>";
        }


          

         }
       
        
        $varietalText=$foodWines[$x][8];
        if ($varietalText != ""){
            if (strpos($foodWines[$x][1], $varietalText) > 0){
                $varietalText="";
            }
        }

            // echo $foodWines[$x][8]."<br>";

         if($varietalText != ""){
               echo "<span style='font-weight: normal font-size: 1.25em'>".$varietalText."</span>";
               echo "<br>";
         }
   
    
 if($foodWines[$x][7] != ""){

    if($foodWines[$x][26] != ""){
        echo "<span style='font-weight: normal font-size: 1.25em'>".$foodWines[$x][7].">".$foodWines[$x][26]."</span><br><br>";
    }
    else{
        echo "<span style='font-weight: normal font-size: 1.25em'>".$foodWines[$x][7]."</span><br><br>";
    }
}
else{
    echo "<br>";
}
// echo "<span style='font-weight: normal font-size: 1.25em'>".$foodWines[$x][7].">".$foodWines[$x][26]."</span><br><br>";
    
//if($foodWines[$x][29]!='Glass' AND $foodWines[$x][18] > 0){   
// echo "<font size='+1'><span style='font-weight: bold'>In our Cellar: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][18]."</span><br><font>";
//}

if ($listType=="byFood"){

       echo "<font size='+1'><span style='font-weight: bold'>Goes with your selections:</span><span style='font-weight: normal'>".$goodfoods."</span><br><font>";


}
    if (!empty($foodWines[$x][19])) {
       echo "<font size='+1'><span style='font-weight: bold'>Eyes: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][19]."</span><br><font>";
      }
  
  	if (!empty($foodWines[$x][20])) {
       echo "<font size='+1'><span style='font-weight: bold'>Nose: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][20]."</span><br><font>";
      }
  
  	if (!empty($foodWines[$x][21])) {
       echo "<font size='+1'><span style='font-weight: bold'>Mouth: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][21]."</span><br><font>";
      }
   
      if (!empty($foodWines[$x][23]) AND $foodWines[$x][23]!=0) {
       echo "<font size='+1'><span style='font-weight: bold'>Alcohol Content: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][23]."%</span><br><font>";
      }

     if (!empty($foodWines[$x][30]) AND !empty($foodWines[$x][67]) AND $foodWines[$x][30]!=0) {


  if($foodWines[$x][39]==0){
        $soldtype="bottle";
        }
        elseif($foodWines[$x][39]==1){
        $soldtype="glass";
        }
        elseif($foodWines[$x][39]==2){
        $soldtype="can";
        }
       echo "<font size='+1'><span style='font-weight: bold'>".$foodWines[$x][30].$foodWines[$x][67]."&nbsp;".$soldtype."</span><br><font>";
      }


  	if (!empty($foodWines[$x][34])) {
       echo "<font size='+1'><span style='font-weight: bold'>Ratings: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][34]."</span><br><font>";
      }
    
  	if (!empty($foodWines[$x][33])) {
       echo "<font size='+1'><text align='justify'><span style='font-weight: bold'>Why we like it: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][33]."</span><br><font>";
      }
   if($screenWidth > 10000){     
  	if (!empty($foodWines[$x][24])) {
       echo "<br><font size='+1'><span style='font-weight: bold'>Pairs with: &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][24]."</span><br><font>";
      }
}

$pairsString="";
   
if($screenWidth > 500){
   
     for($y = 51; $y <= 55; $y++){

      if(!empty($foodWines[$x][$y])){
      
      if($y==51){
            $pairsString = substr($foodWines[$x][$y], (strlen($foodWines[$x][$y])-2)*-1);
      }
      else{
            $pairsString=$pairsString.", ".substr($foodWines[$x][$y], (strlen($foodWines[$x][$y])-2)*-1);
      }
      }      
      }
   if(!empty($pairsString)){
    echo "<br><font size='+1'><span style='font-weight: bold'>Pairs with:&nbsp;</span><span style='font-weight: normal'>".$pairsString."</span><br><font>";
   }
   }

 


//if($screenWidth > 500){    
  	if (!empty($foodWines[$x][32])) {
       echo "<br><font size='+1'><span style='font-weight: bold'>From the Brew Master &nbsp;</span><span style='font-weight: normal'>".$foodWines[$x][32]."</span><br><font>";
      }
//}
      echo "<br><font size='-1'><span style='font-weight: normal'>All prices are in Belize Dollars and include 12.5% GST (Sales Tax). BZ$2 = US$1</span><font>";
      echo "<br><font size='+0'><span style='font-weight: normal'>",$browsing."</span><font>";
     
   if($foodWines[$x][18]<3 AND $foodWines[$x][39]==0){
   if($foodWines[$x][18]==1){
// echo "<br><font size='-1'><span style='font-weight: bold'>Only 1 Bottle Left in Our Cellar</span><font>";
}
else{
   // echo "<br><font size='-1'><span style='font-weight: bold'>Only 2 Bottles Left in Our Cellar</span><font>";
}
}
    echo "</td>";

    // echo "<td valign='top' align='left'>";
    // echo do_shortcode($nextWine);
    // echo "</td>";

  	echo "</tr>";
	echo "</table>";
     //echo "<br><br><br><br>";
}
echo "</body>";
}
else{
echo "<h5>No Matching Results for  '".$search."'</h5>";
}