$results .= '<div class="red">(x) remove</div>';
                 $results .= '</div>';
             }
         } else {
             $results .= '';
         }
         $visible = count($links[$type]) < $maxlinks[$type] ? '' : 'style="display:none;"';
         $addlink = sprintf($addlink, $visible, $type);
         $results .= $addlink;
         return $results;
     }
     $products_id = tep_db_prepare_input($_POST['products_id']);
     $addlink = '<div class="pladd" %1$s><a href="?open=sp-products-links-popup&amp;products_id=' . $products_id . '&amp;type=%2$s&amp;jng_sp_id=' . $jng_sp_id . '&amp;hidemenu=true" class="view_webpage" title="Add new product"></a>';
     $addlink .= '<input type="button" name="pladd" value="Add" /></div>';
     $links_type = array('C', 'U', 'A', 'D');
     $links = $class_pl->retrieveList($products_id, true, $jng_sp_id);
     foreach ($links as $l) {
         $links_type[$l['type']][] = $l;
     }
     //$results  = '<tr class="'.$row_class.'">';
     $results .= '<td class="img"></td>';
     $results .= '<td class="cl-c">' . drawThumbs($links_type, 'C', $addlink) . '</td>';
     $results .= '<td class="cl-u">' . drawThumbs($links_type, 'U', $addlink) . '</td>';
     $results .= '<td class="cl-a">' . drawThumbs($links_type, 'A', $addlink) . '</td>';
     $results .= '<td class="cl-d">' . drawThumbs($links_type, 'D', $addlink) . '</td>';
     //$results .= '</tr>';
     echo utf8_encode($results);
     exit;
 } elseif ($_POST['me_action'] == 'REMOVEPRODUCTLINKS') {
     $products_linking_id = tep_db_prepare_input($_POST['links_id']);
     $class_pl->remove($products_linking_id, true);
        $l .= '<div title="Click to remove this product" class="red">(x) remove</div>';
    }
    $l .= '</div>';
    return $l;
}
//AJAX ACTION
if (isset($_POST['me_action'])) {
    if ($_POST['me_action'] == 'PRODUCTLINKING') {
        $result = '';
        switch ($_POST['act']) {
            case 'LOAD':
                if (isset($_POST['plid']) && $_POST['plid'] != '') {
                    $pl = $class_pl->retrieveDetail($_POST['plid']);
                    $result .= drawPLthumb($pl['products_linking_id'], $pl['links_id'], true, true);
                } else {
                    $pl_load = $class_pl->retrieveList($products_id);
                    $pl_load_auto = $class_pl->getProductsCrossSelling($products_id);
                    $links = array();
                    foreach ($pl_load as $row) {
                        if (!isset($links[$row['type']])) {
                            $links[$row['type']] = array();
                        }
                        $links[$row['type']][] = drawPLthumb($row['products_linking_id'], $row['links_id'], false, true);
                    }
                    $nolink = '<div class="red">No links for this type</div>';
                    $addfield = '<div id="pat-%1$s" class="addbox" style="margin-bottom:10px;">';
                    $addfield .= 'Product ID/Code <input type="text" name="pladd" /> ';
                    $addfield .= '<input type="button" name="pladdbtn" value="Add" /> or ';
                    $addfield .= '<span><a href="?open=product-detail-links-style&amp;products_id=' . $products_id . '&amp;type=%2$s&amp;hidemenu=true" class="view_webpage" title="Add new product based on style"></a>';
                    $addfield .= '<input type="button" name="pladd2btn" value="Add from Style" />';
                    $addfield .= '</span>';