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_show_supplier_square($shopid, $postid)
{
    global $region;
    global $txt_buy_from;
    //defined by amazon-product-in-a-post.php
    global $txt_cheapest_supplier;
    global $txt_supplier;
    //get product info
    //needs info in ->id field!
    $shopids[0]->id = $shopid;
    $products = lhg_get_sorted_products($shopids, $postid, false);
    $url = $products[0]["url"];
    $price = $products[0]["price"] + $products[0]["shipping"];
    $img = lhg_get_shop_square_icon($shopid);
    $name = lhg_get_shop_long_name($shopid);
    #if ($postid == 24875) echo "P: ".$products[0]["price"]." - S: ".$products[0]["shipping"]."<br>";
    #if ($postid == 40247 ) print "DEBUG: $url";
    //prices for shipping and product are provided as float values
    $shipping = $products[0]["shipping"];
    $price_net = $products[0]["price"];
    #print "price_net: $price_net<br>";
    //$shipping = lhg_amazon_price_to_float( $shipping , $region );
    //$price_net = lhg_amazon_price_to_float( $price_net , $region );
    #print "price_net2: $price_net<br>";
    $price = $shipping + $price_net;
    #if ($postid == 24875) echo "P: ".$price." - S: ".$shipping."<br>";
    #print "price_sum: $price<br>";
    $txt_button_string = $txt_buy_from . " {$name}";
    $title = translate_title(get_the_title());
    $s = explode("(", $title);
    $short_title = trim($s[0]);
    #echo "Show supplier";
    #echo "<br>URL: $url";
    #echo "<br>img: $img";
    #echo "<br>Name: $name";
    #echo "<br>Price: $price";
    /*
    $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";
    */
    #print "price1: $price<br>";
    $price = lhg_float_to_currency_string($price, $region);
    $currency = lhg_get_currency_symbol($region);
    #print "price2: $price<br>";
    echo "\n" . '<div class="rating" style="border: 0px solid #222; width: 70%; text-align: center; margin: 0 auto;">';
    echo "\n" . '<div style="text-align: center;"><b>' . $txt_supplier . ':</b></div>';
    //echo "\n".'<meta itemprop="priceCurrency" content="'.$price_meta.'" />';
    echo "\n" . '<div class="amazonbutton">
         	      <a href="' . $url . '" rel="nofollow"><img src="' . $img . '" border="0" width="125" height="125" alt="' . $txt_button_string . ': ' . $short_title . '" title="' . $txt_button_string . ': ' . $short_title . '" id="supplier_square" /></a>
                   </div>';
    echo $currency . '&nbsp;' . $price . ' <br />  <a href="' . $url . '" rel="nofollow" >' . $name . '</a>';
    echo "\n" . "</div>";
}
function getSingleAmazonProduct($asin = '', $extratext = '', $extrabutton = 0)
{
    global $public_key, $private_key, $aws_partner_id, $aws_partner_locale, $amazonhiddenmsg, $amazonerrormsg, $apippopennewwindow, $apippnewwindowhtml;
    global $appip_text_lgimage;
    global $appip_text_listprice;
    global $appip_text_newfrom;
    global $appip_text_usedfrom;
    global $appip_text_instock;
    global $appip_text_outofstock;
    global $appip_text_author;
    global $appip_text_starring;
    global $appip_text_director;
    global $appip_text_reldate;
    global $appip_text_preorder;
    global $appip_text_releasedon;
    global $appip_text_notavalarea;
    global $buyamzonbutton;
    global $addestrabuybutton;
    global $encodemode;
    global $post;
    global $amazonRun;
    //text strings
    global $lang;
    global $txt_compat;
    global $txt_Compat;
    global $txt_with;
    global $txt_rating;
    global $txt_ratings;
    global $txt_price;
    global $txt_out_of_stock;
    global $txt_button;
    global $txt_button_width;
    global $siteurl;
    global $txt_pricetrend;
    global $txt_A_preis;
    global $txt_currency;
    global $txt_shipping;
    global $txt_on_stock;
    global $txt_updated;
    global $txt_buy_from;
    global $txt_search_at;
    global $txt_preorder;
    global $txt_not_avail_at;
    global $txt_never_avail;
    $region = get_region();
    $aws_partner_id = get_id();
    $aws_partner_locale = $region;
    //print "PL: $aws_partner_locale";
    //$apippOpenNewWindow = get_post_meta($post->ID,'amazon-product-newwindow',true);
    //if($apippOpenNewWindow!='3'){$apippnewwindowhtml=' target="amazonwin" ';}
    #print "A0: $asin<br>";
    $asinlist = get_post_meta($post->ID, 'amazon-product-asin-list', true);
    #print "CSV: ".str_getcsv($asin.",".$asinlist, ",");
    $data = str_getcsv($asin . "," . $asinlist, ",");
    #var_dump($data);
    #
    # check if DB entries for asins already exist -> create if necessary
    #
    $i = 0;
    while ($i < count($data)) {
        $asin_tmp = $data[$i];
        #print " A: $asin";
        if ($asin_tmp != "") {
            lhg_amazon_create_db_entry($region, $post->ID, $asin_tmp);
        }
        $i++;
    }
    //print "<br>Data0: $data[0] <br>";
    //print "Data1: $data[1] <br>";
    #print "Af: $asin<br>";
    if ($asin != '') {
        #print "count: ".count($data);
        #$i=0;
        #while ( $i< count($data) ){
        # one loop is enough. SQL request looks at all ASINs
        //print "I: $i <br>";
        global $amazonRun;
        $amazonRun = 0;
        // reset loop counter for new asin list element
        $asin = $data[$i];
        // $asin; //valid ASIN
        $ASIN = $asin;
        //valid ASIN
        //print "ASIN: $asin";
        $errors = '';
        #$appip_responsegroup 	= "ItemAttributes,Images,Offers,Reviews";
        #$appip_operation 		= "ItemLookup";
        #$appip_idtype	 		= "ASIN";
        #if ($region != "nl")
        #$pxml = aws_signed_request($aws_partner_locale, array("Operation"=>$appip_operation,"ItemId"=>$ASIN,"ResponseGroup" => $appip_responsegroup,"IdType"=>$appip_idtype,"AssociateTag"=>$aws_partner_id ), $public_key, $private_key);
        //print "<br>PXML: ";var_dump($pxml);
        #if(!is_array($pxml)){
        #	$pxml2=$pxml;
        #	$pxml = array();
        #	$pxml["itemlookuperrorresponse"]["error"]["code"]["message"] = $pxml2;
        #}
        #if(isset($pxml["itemlookuperrorresponse"]["error"]["code"])){
        #	$errors = $pxml["itemlookuperrorresponse"]["error"]["code"]["message"];
        #}
        //print "<br>Article found, checking";
        //Call 1
        $amazonRun += 1;
        //count loops to prevent multiple requests (will be reset for ASIN lists)
        //echo "<hr>Call 1<br>RUN: $amazonRun<br>";
        //if ($run == 2) break;
        #$result = FormatASINResult($pxml,$post->ID);
        $newPrice = lhg_db_get_lowest_amazon_price($post->ID, $region);
        #print "<br>New Price: $newPrice - $asin, $region";
        #if ($newPrice != "" and $newPrice != 0) break;
        #$i++;
        #}
        if ($lang != "de") {
            if ($newPrice == 0) {
                $newPrice = "out of stock";
            }
        }
        if ($lang == "de") {
            if ($newPrice == 0) {
                $newPrice = "nicht lieferbar";
            }
        }
        if ($errors == 'exceeded') {
            #	$hiddenerrors = "<"."!-- HIDDEN AMAZON PRODUCT IN A POST ERROR: Requests Exceeded -->";
            #	$errors = 'Requests Exceeded';
            #	if($extratext!=''){return $hiddenerrors.$extratext;}
            #	return $hiddenerrors;
            #}elseif($errors=='no signature match'){
            #        //echo "HERE A!";
            #	$hiddenerrors = "<"."!-- HIDDEN AMAZON PRODUCT IN A POST ERROR: Signature does not match AWS Signature. Check AWS Keys and Signature method. -->";
            #	$errors = 'Signature does not match';
            #	if($extratext!=''){return $hiddenerrors.$extratext;}
            #	return $hiddenerrors;
            //}elseif($errors=='not valid'){
            //        //echo "HERE B!";
            //	$hiddenerrors = "<"."!-- HIDDEN AMAZON PRODUCT IN A POST ERROR: Item Not Valid. Possibly not available in your locale or you did not enter a correct ASIN. -->";
            //	$errors = 'Not a valid item';
            //	if($extratext!=''){return $hiddenerrors.$extratext;}
            //	return $hiddenerrors;
            //}elseif($errors!=''){
            //	$hiddenerrors = "<"."!-- HIDDEN AMAZON PRODUCT IN A POST ERROR: ". $errors ."-->";
            //	if($extratext!=''){return $hiddenerrors.$extratext;}
            //	return $hiddenerrors;
        } else {
            //global $run;
            //$run += 1;
            //Call 2
            //echo "<hr>Call 2<br>";
            //$result = FormatASINResult($pxml,$post->ID);
            //print_r ($result);
            //echo "<br>WHAT: ".$result['URL'];
            //$returnval  = '	<br /><div class="amazon-box">';
            //$returnval = '                               ';
            //$returnval  .= ' 	 			<div class="amazon-box">';
            //<table cellpadding="0"class="amazon-product-table">'."\n";
            //$returnval .= '		<tr>'."\n";
            //$returnval .= '			<td valign="top">'."\n";
            $returnval .= '				<div class="amazon-image-wrapper">' . "\n";
            //$returnval .= '					<a href="' . $result["URL"] . '" '. $apippnewwindowhtml .'>' . awsImageGrabber($result['MediumImage'],'amazon-image') . '</a><br />'."\n";
            global $txt_cpl_noimage;
            // = "Kein Bild verf&uuml;gbar";
            #
            # ToDo: URL should be stored in DB and not fetched each time
            #
            #$amazon_image = awsImageGrabber($result['MediumImage'],'amazon-image');
            $attr = array('alt' => trim(strip_tags(translate_title(get_the_title($PID)))), 'title' => trim(strip_tags(translate_title(get_the_title($PID)))));
            $amazon_image = get_the_post_thumbnail($artid, array(130, 130), $attr);
            if (strpos($amazon_image, 'src=""')) {
                $amazon_image = '<img src="/wp-uploads/2013/03/noimage130.jpg" alt="' . $txt_cpl_noimage . '" title="' . $txt_cpl_noimage . '">';
            }
            if ($amazon_image == "") {
                $amazon_image = '<img src="/wp-uploads/2013/03/noimage130.jpg" alt="' . $txt_cpl_noimage . '" title="' . $txt_cpl_noimage . '">';
            }
            $returnval .= '					' . $amazon_image . '' . "\n";
            //$returnval .= '					'. awsImageGrabber($result['MediumImage'],'amazon-image') . ''."\n";
            //if($result['LargeImage']!=''){
            //$returnval .= '				<a target="amazon-image" href="javascript: void(0)" onclick="artwindow=window.open(\'' .$result['LargeImage'] .'\',\'art\',\'directories=no, location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no, width=400,height=525\');artwindow.focus();return false;"><span class="amazon-tiny">'.$appip_text_lgimage.'</span></a>'."\n";
            //$returnval .= '					<a rel="appiplightbox" href="'.$result['LargeImage'] .'"><span class="amazon-tiny">'.$appip_text_lgimage.'</span></a>'."\n";
            //$returnval .= '					<span class="amazon-tiny">'.$appip_text_lgimage.'</span>'."\n";
            //}
            $returnval .= '				</div>' . "\n";
            $returnval .= '
<div class="amazon-buying">' . "\n";
            //$returnval .= '					<h2 class="amazon-asin-title"><a href="' . $result["URL"] . '" '. $apippnewwindowhtml .'><span class="asin-title">'.$result["Title"].'</span></a></h2>'."\n";
            //$returnval .= '					<h2 class="amazon-asin-title"><a href="' . $result["URL"] . '" '. $apippnewwindowhtml .'><span class="asin-title">'.$result["Title"].'</span></a></h2>'."\n";
            #if(isset($result["Author"])){
            #$returnval .= '					<span class="amazon-author">'.$appip_text_author.' '.$result["Author"].'</span><br />'."\n";
            #}
            #if(isset($result["Director"])){
            #$returnval .= '					<span class="amazon-director-label">'.$appip_text_director.': </span><span class="amazon-director">'.$result["Director"].'</span><br />'."\n";
            #}
            #if(isset($result["Actors"])){
            #$returnval .= '					<span class="amazon-starring-label">'.$appip_text_starring.': </span><span class="amazon-starring">'.$result["Actors"].'</span><br />'."\n";
            #}
            //if(isset($result["Rating"])){
            //$returnval .= '					<span class="amazon-rating-label">Rating: </span><span class="amazon-rating">'.$result["Rating"].'</span><br />'."\n";
            //}
            ob_start();
            if (function_exists('the_ratings')) {
                $returnval .= the_ratings();
            }
            $out1 = ob_get_contents();
            ob_end_clean();
            //get the correct! rating
            $post_id = $post->ID;
            global $wpdb;
            global $lhg_price_db;
            if ($lang != "de") {
                $ratings = $lhg_price_db->get_results("SELECT * FROM  `lhgtransverse_posts` WHERE postid_com = {$post_id}");
            }
            if ($lang == "de") {
                $ratings = $lhg_price_db->get_results("SELECT * FROM  `lhgtransverse_posts` WHERE postid_de = {$post_id}");
            }
            #$get_rates = $wpdb->get_results("SELECT rating_rating FROM $wpdb->ratings WHERE rating_postid = $post_id");
            $rating_total = 0;
            $rating_total = $ratings[0]->post_ratings_users_com + $ratings[0]->post_ratings_users_de;
            $rating = $ratings[0]->post_ratings_score_com + $ratings[0]->post_ratings_score_de;
            #foreach($get_rates as $get_rate){
            #        $rating += $get_rate->rating_rating;
            #        //print_r($get_rate);
            #        $rating_total++;
            #}
            //$returnval .= '<div class="hreview-aggregate">';
            //$returnval .= '<span class="item">';
            //$returnval .= '<span class="fn"><span class="value-title" title="'.get_the_title().'"/></span>';
            //$returnval .= '<span class="photo"><span class="value-title" title="'.wp_get_attachment_url( get_post_thumbnail_id($post->ID) ).'"/></span>';
            //$returnval .= '</span>';
            //$returnval .= '<span class="rating"><span class="value-title" title="'.($rating/$rating_total).'"/></span>';
            //$returnval .= '<span class="reviewer"><span class="value-title" title="linux-hardware-guide.de"/></span>';
            //$returnval .= '<span class="dtreviewed"><span class="value-title" title="'.get_the_date().'"/></span>';
            //$returnval .= '<span class="votes"><span class="value-title" title="'.$rating_total.'"/></span>';
            //$returnval .= '<span class="count"><span class="value-title" title="'.get_comments_number().'"/></span>';
            //$tooltip= 'Bewertet wird an dieser Stelle einzig die Linux-Kompatibilit&auml;t und nicht die Qualit&auml;t des Produktes.<div style="height: 3px;"></div>Sollten Sie dieses Produkt besitzen, dann helfen Sie bitte auch anderen Linux-Benutzern, indem Sie dessen
            //	   <a href="#comment-box">Linux-Kompatibilit&auml;t bewerten</a>.';
            //set tooltip depending on logged in or not (due to google rating)
            global $txt_tooltip;
            global $txt_amz_tooltip_loggedin;
            global $txt_amz_tooltip_not_loggedin;
            if (is_user_logged_in()) {
                $txt_tooltip = $txt_amz_tooltip_loggedin;
            }
            if (!is_user_logged_in()) {
                $txt_tooltip = $txt_amz_tooltip_not_loggedin;
            }
            $tooltip = $txt_tooltip;
            //'Bewertet wird an dieser Stelle einzig die Linux-Kompatibilit&auml;t und nicht die Qualit&auml;t des Produktes. Sollten Sie dieses Produkt besitzen, dann helfen Sie bitte auch anderen Linux-Benutzern, indem Sie dessen Linux-Kompatibilit&auml;t im Kommentar-Bereich dieser Seite bewerten.';
            $returnval .= "\n\t<b>{$txt_compat}:</b>";
            $returnval .= '
      <span class="tooltip">
        	' . tooltip($tooltip, -118, 380, -178) . '
      </span>';
            $returnval .= '

      <br />

  <div style="border: 0px solid #eee;">

    <div style="border: 0px solid #eee; width:80px; float: left;">
        ' . the_ratings_results($post->ID, 0, 0, 0, 10) . '
    </div>
    ';
            //Rich Snippet start
            //$returnval .= '<div itemscope itemtype="http://data-vocabulary.org/Review">';
            if ($rating_total == 1) {
                $returnval .= '
    <div style="border: 0px solid #eee; white-space: nowrap;">
        &nbsp;&nbsp;(<span class="rating">
          	<span class="value-title" title="' . round($rating / $rating_total, 1) . '">
                                ' . round($rating / $rating_total, 1) . '
                </span>
        </span> ' . $txt_with . '

        <span class="votes">
        	<span class="value-title" title="' . $rating_total . '">
                                ' . $rating_total . '
                </span>
        </span> ' . $txt_rating . ')
    </div>

  </div>' . "\n";
            }
            if ($rating_total == 0) {
                $rate_average_value = 0;
            } else {
                $rate_average_value = round($rating / $rating_total, 1);
            }
            if ($rating_total != 1) {
                $returnval .= '
    <div style="border: 0px solid #eee; white-space: nowrap;">
  	&nbsp;&nbsp;(<span class="rating">
        	<span class="value-title" title="' . $rate_average_value . '">
                                ' . $rate_average_value . '
                </span>
        </span> ' . $txt_with . '

        <span class="votes">
        	<span class="value-title" title="' . $rating_total . '">
                                ' . $rating_total . '
                </span>
        </span> ' . $txt_ratings . ')
    </div>
  </div>' . "\n";
            }
            //Rich Snippet end
            //$returnval .= '</div>';
            $returnval .= '
  <br />
';
            //also store cheapest price - not used. Use central price DB instead
            #$cheapest_price = lhg_db_get_cheapest_price($post->ID);
            #print "<br>Cheapest: $cheapest_price";
            #$meta="cheapest_price_".$region;
            #update_post_meta($post->ID,$meta,$cheapest_price);
            #                                $returnval .= '<div class="amaz-grey-box" style="border: 0px solid #eee; background-color: #eee;">';
            //if ($rating_total != 1) $returnval .= ' ('.$rating_total.' Bewertungen)</div></div><br>'."\n";
            //$returnval .= '				<hr noshade="noshade" size="1" />'."\n";
            //$returnval .= '				<div align="left">'."\n";
            //$returnval .= '					<table class="amazon-product-price" cellpadding="0">'."\n";
            //if($extratext!=''){
            //$returnval .= '						<tr>'."\n";
            //$returnval .= '							<td class="amazon-post-text" colspan="2">'.$extratext.'</td>'."\n";
            //$returnval .= '						</tr>'."\n";
            //}
            //If($result["PriceHidden"]==1 ){
            //	$returnval .= '						<tr>'."\n";
            //	$returnval .= '							<td class="amazon-list-price-label">'.$appip_text_listprice.':</td>'."\n";
            //	$returnval .= '							<td class="amazon-list-price-label">'.$amazonhiddenmsg.'</td>'."\n";
            //	$returnval .= '						</tr>'."\n";
            //}elseif($result["ListPrice"]!='0'){
            //	$returnval .= '						<tr>'."\n";
            //	$returnval .= '							<td class="amazon-list-price-label">Preis: '.$appip_text_listprice.':</td>'."\n";
            //$returnval .= '							Preis: '.$appip_text_listprice.':'."\n";
            //$returnval .= '							'.  mb_convert_encoding($result["ListPrice"], $encodemode, mb_detect_encoding( $result["ListPrice"], "auto" )) .' '."\n";
            //	$returnval .= '							<td class="amazon-list-price">'.  mb_convert_encoding($result["ListPrice"], $encodemode, mb_detect_encoding( $result["ListPrice"], "auto" )) .'</td>'."\n";
            //	$returnval .= '						</tr>'."\n";
            //}
            if (isset($newPrice)) {
                #print "AAH!";
                #$result["LowestNewPrice"])){
                #if($result["LowestNewPrice"]=='Too low to display'){
                #	$newPrice = 'Check Amazon For Pricing';
                #}else{
                #	#$newPrice = $result["LowestNewPrice"];
                #}
                //$returnval .= '						<tr>'."\n";
                //$returnval .= '							<td class="amazon-new-label">'.$appip_text_newfrom.':</td>'."\n";
                #					$returnval .= '							'.$txt_price.':'."\n";
                #if ($result["TotalNew"] == '') $returnval.="Warn \n";
                #if($result["TotalNew"]>0){
                //$ship=scrape($asin);
                //print_r($ship);
                //$returnval .= "Total: ".$SalePrice['FormattedPrice']."-".$result["ListPrice"]."+".$ship[1]."<br>";
                #not needed any longer. Stored in DB
                //$newPrice
                $myFile = "/home/wordpressftp/amazon-{$region}.txt";
                $fh = fopen($myFile, 'a') or die("can't open file");
                $stringData = $post->ID . ";" . $newPrice . "\n";
                fwrite($fh, $stringData);
                fwrite($fh, $stringData);
                fclose($fh);
                # store price - currently disabled
                #                //$newPrice with date
                $myFile = "/home/wordpressftp/amazon_date-{$region}.txt";
                $timeInf = time();
                $fh = fopen($myFile, 'a') or die("can't open file");
                $stringData = $post->ID . ";" . $newPrice . ";" . $timeInf . ";" . $result["URL"] . "\n";
                fwrite($fh, $stringData);
                fclose($fh);
                #lhg_amazon_price_to_db($region, $post->ID, $asin, $newPrice, $result["URL"], $timeInf);
                //remove Amazon string Symbol
                $newPrice = lhg_remove_amazon_currency_symbol($newPrice, $region);
                //add currency symbol
                #                                        $returnval .= lhg_get_currency_symbol ( $region );
                /*
                                                if ($region == "co.uk") $returnval .= "&pound;";
                                                if ($region == "co.jp") $returnval .= "&yen;";
                                                if ($region == "cn") {
                                                	$returnval .= "&yen;";
                                                        $newPrice  = substr($newPrice,2);
                                                }
                                                if ($region == "co.jp") $newPrice  = substr($newPrice,2);
                */
                #                                        $returnval .= '							'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span itemprop="availability" content="in_stock" class="instock"> ('.$txt_on_stock.') </span>'."\n";
                #                                        $returnval .= '<br><div class="shipping"><font size="1">('.$txt_shipping.')';
                global $txt_tooltip2;
                $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).";
                #                	                $returnval .= '<span class="tooltip">'.tooltip($tooltip).'<span>';
                #                                        $returnval .= '</font></div>';
                #
                #					}else{
                #//						$returnval .= '							'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="outofstock">'.$appip_text_outofstock.'</span>'."\n";
                #						$returnval .= 'BB unbekannt							'; //. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="outofstock">'.$appip_text_outofstock.'</span>'."\n";
                #}
                //if($result["TotalNew"]>0){
                //	$returnval .= '							<td class="amazon-new">'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="instock">'.$appip_text_instock.'</span></td>'."\n";
                //}else{
                //	$returnval .= '							<td class="amazon-new">'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="outofstock">'.$appip_text_outofstock.'</span></td>'."\n";
                //}
                //$returnval .= '						</tr>'."\n";
                //				$returnval .= '								</div>'."\n";
                //store in DB
                $meta = "price-amazon." . $region;
                update_post_meta($post->ID, $meta, $newPrice);
                //$meta="url-amazon.".$region;
                //update_post_meta($post->ID,$meta,$result["URL"]);
            } elseif ($region != "pl") {
                #Price tag
                $aid = get_id();
                //if( ($errors!='') && ($region == "en")){
                //   $returnval .='Not available at <a target="_blank" href="http://www.amazon.'.$region.'/b/?_encoding=UTF8&camp=1789&creative=390957&linkCode=ur2&node=2956536011&tag=linuhardguid-20">Amazon.'.$region.'</a><img src="https://www.assoc-amazon.com/e/ir?t=linuhardguid-20&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />';
                //}else{
                //$returnval .= '							'.$txt_price.':'."\n";
                $ProductIsUnavailable = 1;
                if ($result["URL"] == "") {
                    $meta = "url-amazon." . $region;
                    $result["URL"] = get_post_meta($post->ID, $meta, true);
                }
                //still undefined?
                if ($result["URL"] == "") {
                    $region_tmp = $region;
                    if ($region == "nl") {
                        $region_tmp = "de";
                    }
                    $result["URL"] = 'http://www.amazon.' . $region_tmp . '/?_encoding=UTF8&amp;camp=15121&amp;creative=390961&amp;linkCode=ur2&amp;tag=' . $aid;
                    $NoUrlAvailable = 1;
                }
                #                                        $returnval .= '							'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="outofstock">('.$txt_out_of_stock.')</span>'."\n";
                #     					if ($region !== "de") if ($NoUrlAvailable != 1) $returnval .='<br><div class="amazon-cr"></div>'.$txt_not_avail_at.' <a target="_blank" href="http://www.amazon.'.$region.'/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag='.$aid.'" rel="nofollow">Amazon.'.$region.'</a><div class="amazon-cr"></div>';
                #     					if ($region !== "de") if ($NoUrlAvailable == 1) $returnval .='<br><div class="amazon-cr"></div>'.$txt_never_avail.' <a target="_blank" href="http://www.amazon.'.$region.'/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag='.$aid.'" rel="nofollow">Amazon.'.$region.'</a><div class="amazon-cr"></div>';
                #     					if ($region == "de") $returnval .='<br>Nicht lieferbar von <a target="_blank" href="http://www.amazon.'.$region.'/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag='.$aid.'" rel="nofollow">Amazon.'.$region.'</a>';
                //<img src="https://www.assoc-amazon.com/e/ir?t=linuhardguid-20&l=ur2&o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />';
                // $returnval .= '							'. mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' <span class="instock"> (auf Lager) </span>'."\n";
                //}
                #Not needed any longer. Stored in DB
                $myFile = "/home/wordpressftp/amazon-{$region}.txt";
                $fh = fopen($myFile, 'a') or die("can't open file");
                $stringData = $post->ID . ";" . $txt_out_of_stock . "\n";
                fwrite($fh, $stringData);
                fclose($fh);
                # store price to file currently disabled
                #
                #              //print 'Res:'. $result["URL"];
                #               //$newPrice with date
                $myFile = "/home/wordpressftp/amazon_date-{$region}.txt";
                $timeInf = time();
                $fh = fopen($myFile, 'a') or die("can't open file");
                $stringData = $post->ID . ";" . $newPrice . ";" . $timeInf . ";" . $result["URL"] . "\n";
                fwrite($fh, $stringData);
                fclose($fh);
                //store in DB
                $newPrice = "out of stock";
                if ($region === "de") {
                    $newPrice = "nicht lieferbar";
                }
                $meta = "price-amazon." . $region;
                update_post_meta($post->ID, $meta, $newPrice);
                //$meta="url-amazon.".$region;
                //update_post_meta($post->ID,$meta,$result["URL"]);
                #print "BBB<br>";
                #lhg_amazon_price_to_db($region, $post->ID, $asin, $newPrice, $result["URL"], $timeInf);
                //                                $returnval.="Warn \n";
            }
            //if(isset($result["LowestUsedPrice"])){
            //	$returnval .= '						<tr>'."\n";
            //	$returnval .= '							<td class="amazon-used-label">'.$appip_text_usedfrom.':</td>'."\n";
            //	if($result["TotalUsed"]>0){
            //
            //		$returnval .= '						<td class="amazon-used">'. mb_convert_encoding($result["LowestUsedPrice"], $encodemode, mb_detect_encoding( $result["LowestUsedPrice"], "auto" )) .' <span class="instock">'.$appip_text_instock.'</span></td>'."\n";
            //	}else{
            //		$returnval .= '						<td class="amazon-new">'. mb_convert_encoding($result["LowestNewPrice"], $encodemode, mb_detect_encoding( $result["LowestUsedPrice"], "auto" )) . ' <span class="outofstock">'.$appip_text_outofstock.'</span></td>'."\n";
            //	}
            //	$returnval .= '						</tr>'."\n";
            //}
            //$returnval .= '						<tr>'."\n";
            //$returnval .= '							<td valign="top" colspan="2">'."\n";
            //$returnval .= '								<div class="amazon-dates">'."\n";
            //if(isset($result["ReleaseDate"])){
            //	if(strtotime($result["ReleaseDate"]) > strtotime(date("Y-m-d",time()))){
            //$returnval .= '									<span class="amazon-preorder"><br />'.$appip_text_releasedon.' '.date("F j, Y", strtotime($result["ReleaseDate"])).'.</span>'."\n";
            //	}else{
            //$returnval .= '									<span class="amazon-release-date">'.$appip_text_reldate.' '.date("F j, Y", strtotime($result["ReleaseDate"])).'.</span>'."\n";
            //	}
            //}
            //update amazon price first (see above), now show the button with updated price
            $returnval .= lhg_get_shop_button($post->ID);
            if ($errors == '') {
                //product not available at amazon
                if ($result["URL"] == "") {
                    $meta = "url-amazon." . $region;
                    $result["URL"] = get_post_meta($post->ID, $meta, true);
                }
                //still undefined?
                if ($result["URL"] == "") {
                    $result["URL"] = 'http://www.amazon.' . $region . '/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag=' . $aid;
                    $NoUrlAvailable = 1;
                }
                // href="http://www.amazon.'.$region.'/?_encoding=UTF8&camp=15121&creative=390961&linkCode=ur2&tag='.$aid.'">
                //gif for german page
                #                                if ($lang == "de") $returnval .= '<br><a href="' . $result["URL"] .'" rel="nofollow"><img src="'.$txt_button.'" border="0" '.$txt_button_width.'></a>';
                #
                #                                //dynamic button for everyone else
                #        			if ($lang != "de") {
                #
                #                                        global $txt_button_string;
                #
                #                                        if ($ProductIsUnavailable == 1) if ($NoUrlAvailable == 1) {
                ##                                        	$txt_button_string = $txt_search_at.' Amazon.'.$region;
                #                                       	$returnval .= '<br><a href="'. $result["URL"] .'" class="css_btn_class" rel="nofollow"><i class="icon-search icon-large3"></i>&nbsp;'.$txt_button_string.'</a>';
                #                                       }
                #
                #                                       if ($ProductIsUnavailable == 1) if ($NoUrlAvailable != 1) {
                #                                       	$txt_button_string = $txt_preorder.' Amazon.'.$region;
                #                                        	$returnval .= '<br><a href="'. $result["URL"] .'" class="css_btn_class" rel="nofollow"><i class="icon-shopping-cart icon-large3"></i>&nbsp;'.$txt_button_string.'</a>';
                #                                        }
                #
                #                                        if ($ProductIsUnavailable != 1) {
                #                                                $txt_button_string = $txt_buy_from.' Amazon.'.$region;
                #                                                $returnval .= '<br><a href="'. $result["URL"] .'" class="css_btn_class" rel="nofollow"><i class="icon-shopping-cart icon-large3"></i>&nbsp;'.$txt_button_string.'</a>';
                #	                        	}
                #	                        }
            }
            if ($extrabutton == 1 && $aws_partner_locale != '.com') {
                //$returnval .= '									<br /><div><a style="display:block;margin-top:8px;margin-bottom:5px;width:165px;" '. $apippnewwindowhtml .' href="' . $result["URL"] .'"><img src="'.WP_PLUGIN_URL.'/amazon-product-in-a-post-plugin/images/buyamzon-button.png" border="0" style="border:0 none !important;margin:0px !important;background:transparent !important;"/></a></div>'."\n";
            }
            //close amzbox
            $returnval .= '</div>';
            #                                $returnval .= '</div></div>'."\n";
            //$returnval .= '							</td>'."\n";
            //$returnval .= '						</tr>'."\n";
            //If(!isset($result["LowestUsedPrice"]) && !isset($result["LowestNewPrice"]) && !isset($result["ListPrice"])){
            //	$returnval .= '						<tr>'."\n";
            //	$returnval .= '							<td class="amazon-price-save-label" colspan="2">'.$appip_text_notavalarea.'</td>'."\n";
            //	$returnval .= '						</tr>'."\n";
            //}
            //$returnval .= '					</table>'."\n";
            //				$returnval .= '				</div>';
            // <br style="clear:left;">'."\n";
            //$returnval .= '				</div>'."\n";
            //$returnval .= '			</td>'."\n";
            //$returnval .= '		</tr>'."\n";
            //$returnval .= '	</table>'."\n";
            //$siteurl="linux-hardware-guide.com";
            $catlist = category_links();
            global $lhg_is_mobile_mode;
            if ($lhg_is_mobile_mode != 1) {
                $returnval = $returnval . '<div class="amazon-cat-list">' . $catlist . "</div>";
            }
            /*<table class=producttop border=0>
              #<tr class="producttop">
              #<td class="producttop" width=50%>'.
              $returnval
              .'</td>
              <td class="producttop" width=50%>'. $catlist .' </td></tr></table>';
              */
            if ($lhg_is_mobile_mode == 1) {
                $returnval = '<div class="amazon_product_top">' . $returnval . '</div>
                                <div class="amazon-cat-list">' . $catlist . ' </div>
                                <br style="clear:left;" /> ';
            }
            if (is_category()) {
                // is category, not chart output
                // echo "<h2>Cat</h2>";
            } else {
                if ($errors == '') {
                    # creation of chart should be performed on separate machine
                    # currently disabled
                    #
                    #     //echo "Here";
                    start_pricechart($post->ID);
                    //print "lang: $lang";
                    // Pricetrend image alt text:
                    $currency = lhg_get_currency_symbol($region);
                    $imgtext = $txt_pricetrend;
                    if (file_exists("/var/www/charts/" . $post->ID . "-" . $region . ".dat")) {
                        $myFile = "/var/www/charts/" . $post->ID . "-" . $region . ".dat";
                        $file = file($myFile);
                        list($min, $max, $chartdate) = split(";", $file[0]);
                        //echo "Min, Max: $min $max";
                        $title = get_the_title();
                        //echo "T: $title";
                        $sp = strpos($title, "(");
                        //echo "Pos: $sp";
                        if ($sp != "") {
                            $title = substr($title, 0, $sp);
                        }
                        //echo "T: $title";
                        $imgtext = $txt_pricetrend . "\n" . translate_title($title) . "\n-\nMinimum: {$currency} {$min} \nMaximum: {$currency} {$max}  \n{$txt_updated}: {$chartdate}";
                    }
                    if ($lang == "de") {
                        // en has no support for multiple affiliates a.t.m.
                        //if (file_exists("/var/www/charts/".$post->ID."m.png")){
                        if (false) {
                            $returnval .= '<br style="clear:left;" /><img src="http://' . $siteurl . '/wp-uploads/charts/' . $post->ID . 'm.png" alt="' . $imgtext . '" title="' . $imgtext . '" />';
                        } else {
                            if (file_exists("/var/www/charts/" . $post->ID . "-" . $region . ".png")) {
                                if ($charterror == 0) {
                                    $returnval .= '<br style="clear:left;" /><img src="/wp-uploads/charts/' . $post->ID . '-' . $region . '.png" alt="' . $imgtext . '" title="' . $imgtext . '" />';
                                }
                            }
                        }
                    } else {
                        if ($charterror == 0) {
                            if (file_exists("/var/www/charts/" . $post->ID . "-" . $region . ".png")) {
                                $returnval .= '<br style="clear:left;" /><img src="/wp-uploads/charts/' . $post->ID . "-" . $region . '.png" alt="' . $imgtext . '" title="' . $imgtext . '" />';
                            }
                        }
                    }
                    #list known prices
                    #if (file_exists("/var/www/charts/list".$post->ID.".txt")){
                    #$PriceList = file("/var/www/charts/list".$post->ID.".txt");
                    #
                    #$returnval .= '<ul>Preisvergleich
                    #               <li>Amazon.de: '.mb_convert_encoding($newPrice , $encodemode, mb_detect_encoding( $newPrice, "auto" )).' (<a href="' . $result["URL"] .'">bestellen</a>)';
                    #
                    #$returnval .= $PriceList[0];
                    #$returnval .="</ul>";
                    #}
                }
            }
            //List related categories
            //$returnval .= category_links();
            //show CPU table
            #if (in_category('CPU')) $returnval .= cpu_comparison();
            $googlecom = '<script async src="http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5383503261197603"
     data-ad-slot="4611540473"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';
            $googlede = '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Linux-Hardware-Guide.de -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5383503261197603"
     data-ad-slot="3000901678"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>';
            $google_small_mobile = '
<center>
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- Mobile Banner -->
<ins class="adsbygoogle"
     style="display:inline-block;width:320px;height:50px"
     data-ad-client="ca-pub-5383503261197603"
     data-ad-slot="9621646075"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
</center>';
            global $lhg_is_mobile_mode;
            global $lhg_mobile_size;
            if ($lhg_is_mobile_mode != 1) {
                if ($lang == "en") {
                    if (!is_user_logged_in()) {
                        $returnval .= $googlecom;
                    }
                }
            }
            //
            if ($rating_total == 0) {
                $rate_average_value = 0;
            } else {
                $rate_average_value = round($rating / $rating_total, 1);
            }
            //only show in case of low rating
            if ($lhg_is_mobile_mode != 1) {
                if ($lang == "de") {
                    if ($rate_average_value < 5) {
                        if (!is_user_logged_in()) {
                            $returnval .= $googlede;
                        }
                    }
                }
            }
            if ($lhg_is_mobile_mode == 1) {
                if (!is_user_logged_in()) {
                    if ($lhg_mobile_size == "small") {
                        $returnval .= $google_small_mobile;
                    } elseif ($lhg_mobile_size == "large") {
                        $returnval .= $googlecom;
                    } else {
                        $returnval .= $google_small_mobile;
                    }
                }
            }
            //show article header
            //itemprop description is closed in related-post-thumbnails
            $returnval .= '<br /><h2>' . $txt_Compat . '</h2><div itemprop="description"><div class="description">';
            $returnval .= affilinet();
            //article_list();
            return $returnval;
        }
    }
}
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;
}