function lhg_insert_overview_table($products)
{
    //echo "<br>Num Prod:".count($products);
    //echo "<br>ID: ".$products[0]["shop_id"];
    //print_r($products);
    //only amazon, then skip
    //$region == get_region();
    global $region;
    //echo "<br>REG: $region";
    if ($region == "de") {
        $amazon_shop_id = 4;
    }
    //echo "ASID: $amazon_shop_id";
    if (count($products) == 1 && $products[0]["shop_id"] == $amazon_shop_id) {
        //only Amazon
        //skip
    } elseif (count($products) == 0) {
        //nothing found
        //skip
    } elseif (count($products) == 1) {
        //only one found, which is already shown as main square
        //skip
    } elseif (count($products) == 1 && $products[0]["shop_id"] == -1) {
        //something strange e.g. only Amazon on .com sites
        //skip
    } else {
        $price_meta = "USD";
        if ($region == "de") {
            $price_meta = "EUR";
        }
        if ($region == "it") {
            $price_meta = "EUR";
        }
        if ($region == "fr") {
            $price_meta = "EUR";
        }
        if ($region == "es") {
            $price_meta = "EUR";
        }
        if ($region == "com") {
            $price_meta = "USD";
        }
        if ($region == "co.uk") {
            $price_meta = "GBP";
        }
        if ($region == "co.jp") {
            $price_meta = "JPY";
        }
        if ($region == "cn") {
            $price_meta = "CNY";
        }
        if ($region == "ca") {
            $price_meta = "CAD";
        }
        if ($region == "in") {
            $price_meta = "INR";
        }
        $vspacer = '<div class="spacer" style="border-top: 1px solid #2b8fc3; height: 0px; margin-top: 9px; margin-bottom: 9px;"></div>';
        echo $vspacer;
        global $txt_lhgdb_overview;
        global $txt_lhgdb_exclporto;
        global $txt_lhgdb_inclporto;
        echo "<b>{$txt_lhgdb_overview}:</b>";
        echo "<br />\n                <table>";
        for ($i = 0; $i < count($products); $i++) {
            $shop_img = lhg_get_shop_small_icon($products[$i]["shop_id"]);
            $shop_name = lhg_get_shop_name($products[$i]["shop_id"]);
            $shop_name_long = lhg_get_shop_long_name($products[$i]["shop_id"]);
            //print "$i: ".$products[$i]["shop_id"]."<br>";
            // print "$i: ".$products[$i]["last_update"]."<br>";
            if (strpos($shop_name, "mazon") > 0 or strpos($products[$i]["shipping"], "ULL") > 0) {
                // no shipping costs available
                echo '<tr><td>EUR&nbsp;' . lhg_float_to_currency_string($products[$i]["price"] + $products[$i]["shipping"], $region) . '<br /><div class="portoline">' . $txt_lhgdb_exclporto . '</div>
                                </td><td valign="middle"><a href="' . $products[$i]["url"] . '" rel="nofollow">
        	                <img src="' . $shop_img . '" style="border: 1px solid #2B8FC3;" title="' . $shop_name_long . '" alt="' . $shop_name_long . '" /></a></td>';
                #<td>
                #<a href="'.$products[$i]["url"].'" rel="nofollow">'.$shop_name.'</a></td></tr>';
            } else {
                echo '<tr><td>EUR&nbsp;' . lhg_float_to_currency_string($products[$i]["price"] + $products[$i]["shipping"], $region) . '<br /><div class="portoline">' . $txt_lhgdb_inclporto . ': ' . lhg_float_to_currency_string($products[$i]["shipping"], $region) . '&nbsp;EUR</div></td><td valign="middle"><a href="' . $products[$i]["url"] . '" rel="nofollow">
        	                <img src="' . $shop_img . '" style="border: 1px solid #2B8FC3;" title="' . $shop_name_long . '"></a></td>';
                #<td>
                #<a href="'.$products[$i]["url"].'" rel="nofollow">'.$shop_name.'</a></td></tr>';
            }
        }
        echo "</table>";
    }
}
function lhg_country_row($p_region, $URLC, $URLD, $posturlcom, $posturlde)
{
    # store url to be available globally (e.g. by wp-one-post-widget)
    global $posturlcom_glob;
    global $posturlde_glob;
    $posturlcom = $posturlcom_glob;
    $posturlde = $posturlde_glob;
    global $post;
    global $txt_out_of_stock;
    global $region;
    $selected = "";
    if ($region == $p_region) {
        $selected = 'class="ct_pricetop" ';
    }
    #print "URLD: $URLD -- $posturlde<br>";
    print "<tr {$selected}>";
    #print "PID: $post->ID";
    # get the correct postid for .com and .de server
    $relevant_postid = $post->ID;
    if ($lang == "de") {
        $relevant_postid = lhg_get_postid_de_from_com($post->ID);
    }
    $price = lhg_db_get_cheapest_price_by_region($relevant_postid, $p_region);
    $price = lhg_float_to_currency_string($price, $p_region);
    if ($price == 0) {
        $price = $txt_out_of_stock;
        $txt_currency = "";
    } else {
        $txt_currency = lhg_get_currency_symbol($p_region);
        $price = $price;
    }
    #if ($p_region == "de"){
    #
    #        print "PRI: $price<br>";
    #        # ToDo: need access to .de database or Amazon prices to be stored on priceDB
    #        $price = "-";
    #        $txt_currency = "";
    #}
    echo '<td class="ct_country">&nbsp;&nbsp;';
    if ($p_region == "de") {
        $URL_add = '/';
        $flag = "de";
        $country = "Germany";
    }
    if ($p_region == "ca") {
        $URL_add = '/ca/';
        $flag = "ca";
        $country = "Canada";
    }
    if ($p_region == "com") {
        $URL_add = '/';
        $flag = "us";
        $country = "USA";
    }
    if ($p_region == "co.uk") {
        $URL_add = '/uk/';
        $flag = "uk";
        $country = "United Kingdom";
    }
    if ($p_region == "fr") {
        $URL_add = '/fr/';
        $flag = "fr";
        $country = "France";
    }
    if ($p_region == "es") {
        $URL_add = '/es/';
        $flag = "es";
        $country = "Espana";
    }
    if ($p_region == "it") {
        $URL_add = '/it/';
        $flag = "it";
        $country = "Italia";
    }
    if ($p_region == "nl") {
        $URL_add = '/nl/';
        $flag = "nl";
        $country = "Netherlands";
    }
    if ($p_region == "in") {
        $URL_add = '/in/';
        $flag = "in";
        $country = "India";
    }
    if ($p_region == "co.jp") {
        $URL_add = '/ja/';
        $flag = "jp";
        $country = "Japan";
    }
    if ($p_region == "cn") {
        $URL_add = '/zh/';
        $flag = "cn";
        $country = "China";
    }
    if ($p_region == "de") {
        $URL = $URLD . $URL_add . $posturlde;
    }
    if ($p_region != "de") {
        $URL = $URLC . $URL_add . $posturlcom;
    }
    echo '<a href="' . $URL . '"><img src="/wp-content/plugins/qtranslate/flags/' . $flag . '.png" alt="' . $country . '" /> ' . $country . '</a></td>';
    echo '<td class="ct_price">' . $price . '</td>';
    echo '<td class="ct_currency">' . $txt_currency . '</td>';
    echo '<td class="ct_comment">';
    # comment number
    #not yet implemented for "de"
    #if ($p_region == "de"){
    #        echo "-";
    #}else{
    lhg_comments_number_language($p_region, $p_region, 0, $post->ID, "shortversion");
    #}
    echo '</td></tr>';
}
function lhg_get_shop_button($postid)
{
    global $region;
    global $txt_on_stock;
    global $txt_out_of_stock;
    global $txt_shipping;
    global $txt_tooltip2;
    global $txt_button;
    global $txt_not_avail_at;
    global $txt_price;
    global $txt_search_at;
    global $txt_preorder;
    global $txt_buy_from;
    global $txt_shipping_costs;
    $tooltip = $txt_tooltip2;
    //"Die von Amazon zur Verf&uuml;gung gestellten Preise sind exklusive m&ouml;glicherweise zus&auml;tzlich anfallender Versandkosten (abh&auml;ngig vom jeweiligen Anbieter des Amazon-Marketplace).";
    //$button .= "PID: $postid<br>";
    $shopid = lhg_db_get_cheapest_supplier_id($postid);
    $products = lhg_get_sorted_products($shopid, $postid, false);
    $url = $products[0]["url"];
    $price = $products[0]["price"];
    #+$products[0]["shipping"];
    #$price_total = $products[0]["price"]+$products[0]["shipping"];
    $shipping = $products[0]["shipping"];
    $shipping = lhg_float_to_currency_string($shipping, $region);
    $price = lhg_float_to_currency_string($price, $region);
    $name = lhg_get_shop_long_name($shopid);
    $txt_currency = lhg_get_currency_symbol($region);
    //format button depending on availability
    if ($shopid != "") {
        //product available at a shop
        $price_meta = "USD";
        if ($region == "de") {
            $price_meta = "EUR";
        }
        if ($region == "it") {
            $price_meta = "EUR";
        }
        if ($region == "fr") {
            $price_meta = "EUR";
        }
        if ($region == "nl") {
            $price_meta = "EUR";
        }
        if ($region == "es") {
            $price_meta = "EUR";
        }
        if ($region == "com") {
            $price_meta = "USD";
        }
        if ($region == "co.uk") {
            $price_meta = "GBP";
        }
        if ($region == "co.jp") {
            $price_meta = "JPY";
        }
        if ($region == "cn") {
            $price_meta = "CNY";
        }
        if ($region == "ca") {
            $price_meta = "CAD";
        }
        if ($region == "in") {
            $price_meta = "INR";
        }
        $schema_start = '<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">';
        $schema_end = '</div>';
        $button_string = '<i class="icon-shopping-cart icon-large3"></i>&nbsp;' . $txt_buy_from . ' ' . $name;
        $price_string = $txt_price . ':&nbsp;' . $txt_currency . ' <span itemprop="price">' . $price . '</span>

		        	<meta itemprop="priceCurrency" content="' . $price_meta . '" />

  				<span itemprop="availability" itemtype="http://schema.org/InStock" class="instock">
				    (' . $txt_on_stock . ')
			        </span>';
        $shipping_string = '<span class="shippingcosts">
                			(+ ' . $txt_shipping_costs . ': ' . $txt_currency . '&nbsp;' . $shipping . ')
				    </span>';
        //unknown shipping costs for Amazon, add warning
        if (strpos($name, "mazon") > 0) {
            $shipping_string = '<font size="1">
					(' . $txt_shipping . ')</font>
				       <span class="tooltip">' . tooltip($tooltip) . '</span>
				     ';
        }
        //no shipping costs in DB
        if (strpos($products[0]["shipping"], "ULL") > 0) {
            $shipping_string = '<font size="1">
					(' . $txt_shipping . ')
				     </font>';
        }
    } elseif ($region == "nl") {
        //currently no Amazon.de shown
    } else {
        // see if we have "Check Amazon for pricing"
        $meta = "price-amazon." . $region;
        $aprice = get_post_meta($postid, $meta, true);
        #print "AP: $aprice";
        if ($aprice != "Check Amazon For Pricing") {
            $aid = get_id();
            //nowhere available! not even in Amazon catalog
            //
            $region_tmp = $region;
            if ($region == "nl") {
                $region_tmp = "de";
            }
            $price_string = '<span class="outofstock">(' . $txt_out_of_stock . ')</span>
                                <br /><div class="amazon-cr"></div>' . $txt_never_avail_at . '
                                <a target="_blank" href="http://www.amazon.' . $region_tmp . '/?_encoding=UTF8&amp;camp=15121&amp;creative=390961&amp;linkCode=ur2&amp;tag=' . $aid . '" rel="nofollow">
                                  Amazon.' . $region_tmp . '
                                </a>
                                <div class="amazon-cr"></div>';
            $button_string = '<i class="icon-search icon-large3"></i>&nbsp;' . $txt_search_at . ' Amazon.' . $region_tmp;
            $url = 'http://www.amazon.' . $region_tmp . '/?_encoding=UTF8&amp;camp=15121&amp;creative=390961&amp;linkCode=ur2&amp;tag=' . $aid;
            $shipping_string = "";
            #'<font size="1">('.$txt_shipping.')
            #<span class="tooltip">'.tooltip($tooltip).'<span>
            #</font>';
            // Check if at least a Amazon URL exists?!
            //
            $meta = "url-amazon." . $region;
            $pageurl = get_post_meta($postid, $meta, true);
            if ($pageurl != "") {
                // not possible because we have no price ...
                //$schema_start = '<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">';
                //$schema_end   = '</div>';
                $region_tmp = $region;
                if ($region == "nl") {
                    $region_tmp = "de";
                }
                //$price_string = '<span itemprop="availability" itemtype="http://schema.org/OutOfStock" class="outofstock">('.$txt_out_of_stock.')</span>
                $price_string = '<span class="outofstock">(' . $txt_out_of_stock . ')</span>
                        	        <br /><div class="amazon-cr"></div>' . $txt_not_avail_at . '
                                	<a target="_blank" href="http://www.amazon.' . $region_tmp . '/?_encoding=UTF8&amp;camp=15121&amp;creative=390961&amp;linkCode=ur2&amp;tag=' . $aid . '" rel="nofollow">
	                                  Amazon.' . $region_tmp . '
        	                        </a>
                	                <div class="amazon-cr"></div>';
                $button_string = '<i class="icon-search icon-large3"></i>&nbsp;' . $txt_preorder . ' Amazon.' . $region_tmp;
                $url = $pageurl;
            }
            $do_not_show = 1;
        } else {
            //echo "AAA";
            $schema_start = '<div itemprop="offers" itemscope itemtype="http://schema.org/Offer">';
            $schema_end = '</div>';
            //Check Amazon for pricing returned
            $meta = "url-amazon." . $region;
            $pageurl = get_post_meta($postid, $meta, true);
            $price_string = '
                                <span itemprop="availability" itemtype="http://schema.org/InStock" class="instock">
				    ' . $txt_on_stock . ' at <a href="' . $pageurl . '">Amazon.com</a>
			        </span>';
            $region_tmp = $region;
            if ($region == "nl") {
                $region_tmp = "de";
            }
            $button_string = '<i class="icon-search icon-large3"></i>&nbsp;Check Price at Amazon.' . $region_tmp;
            $url = $pageurl;
        }
    }
    $button .= '
<div class="amaz-grey-box" style="border: 0px solid #eee; background-color: #eee;">
' . $schema_start . $price_string . '
  <br />';
    if ($shipping_string != "") {
        $button .= '
  <div class="shipping">' . $shipping_string . '
  </div>

  <br />';
    }
    $button .= '

  <a href="' . $url . '" class="css_btn_class" rel="nofollow">' . $button_string . '
  </a>
' . $schema_end . '
</div>

<br />
';
    if ($region == "nl" and $shopid == "") {
        $button = "";
    }
    if ($do_not_show == 1) {
        $button = "";
    }
    return $button;
}