function templateElementsUsed($submit_action = '')
 {
     $products_id = isset($_POST['products_id']) ? $_POST['products_id'] : tep_db_prepare_input($_GET['products_id']);
     $act = isset($_POST['act']) ? $_POST['act'] : tep_db_prepare_input($_GET['act']);
     switch ($act) {
         case 'UPDATE_MATEXP_MANUAL':
             $matexp = tep_db_prepare_input($_POST['new_matexp']);
             $p = new Product($products_id);
             $p->updateMaterialExpense($matexp);
             $result = $matexp;
             break;
         case 'LOAD':
             $product = $this->retrieveDetail($products_id, 'p,pnc,pc');
             $p = $product['p'];
             $pc = $product['pc'];
             $pnc = $product['pnc'];
             $result = '';
             //ELEMENTS USED
             if ($pc !== false) {
                 //For Customized Products:
                 //CHECK FOR IMAGES OF CUSTOMIZED ELEMENTS
                 $pe_image = array();
                 $pci_query = "SELECT phe.elements_id, pci.*";
                 $pci_query .= " FROM products_has_elements phe";
                 $pci_query .= " INNER JOIN phe_custom_image pci ON pci.products_has_elements_id=phe.products_has_elements_id";
                 $pci_query .= " WHERE phe.products_id={$products_id}";
                 $pci_query .= " ORDER BY orientation ASC, position ASC";
                 $pci_result = tep_db_query($pci_query);
                 if (tep_db_num_rows($pci_result) > 0) {
                     while ($row = tep_db_fetch_array($pci_result)) {
                         if (!isset($pe_image[$row['elements_id']])) {
                             $pe_image[$row['elements_id']] = array();
                         }
                         $pe_image[$row['elements_id']][] = '<a href="?open=pe-uploaded-image&amp;id=' . $row['elements_custom_image_uploaded_id'] . '&amp;hidemenu=true" class="view_webpage" title="View uploaded image and comment">Image</a>';
                     }
                 }
                 //CHECK FOR TEXT OF CUSTOMIZED ELEMENTS
                 $pe_text = array();
                 $pct_query = "SELECT phe.elements_id, pct.*";
                 $pct_query .= " FROM products_has_elements phe";
                 $pct_query .= " INNER JOIN phe_custom_text pct ON pct.products_has_elements_id=phe.products_has_elements_id";
                 $pct_query .= " WHERE phe.products_id={$products_id}";
                 $pct_query .= " ORDER BY orientation ASC, position ASC";
                 $pct_result = tep_db_query($pct_query);
                 if (tep_db_num_rows($pct_result) > 0) {
                     $fulltext = array();
                     while ($textrow = tep_db_fetch_array($pct_result)) {
                         if (!isset($fulltext[$textrow['elements_id']])) {
                             $fulltext[$textrow['elements_id']] = array();
                         }
                         $fulltext[$textrow['elements_id']][] = $textrow['entry_text'];
                     }
                     foreach ($fulltext as $elements_id => $elements_text) {
                         $elements_fulltext = implode('\\n', $elements_text);
                         $pe_text[$elements_id] = '<a href="javascript:alert(\'' . $elements_fulltext . '\')">Text</a>';
                     }
                 }
                 //QUERY ELEMENTS
                 $phe_query = "SELECT phe.elements_id, COUNT(phe.elements_id) AS quantity, e.elements_code";
                 $phe_query .= ", ed.name, ei.image_path, ei.image_filename, (etes.elements_price/etes.pieces_per_qty_type) AS price, etes.price_currency";
                 $phe_query .= " FROM products_has_elements phe";
                 $phe_query .= " LEFT JOIN elements e ON e.elements_id=phe.elements_id";
                 $phe_query .= " LEFT JOIN elements_description ed ON ed.elements_id=e.elements_id AND ed.languages_id=1";
                 $phe_query .= " LEFT JOIN elements_images ei ON ei.elements_id=phe.elements_id AND elements_sample_name='EC1'";
                 $phe_query .= " LEFT JOIN elements_to_elements_suppliers etes ON etes.elements_id=phe.elements_id AND etes.is_default='1'";
                 $phe_query .= " WHERE phe.products_id={$products_id}";
                 $phe_query .= " GROUP BY phe.elements_id";
                 $phe_result = tep_db_query($phe_query);
                 if (tep_db_num_rows($phe_result) > 0) {
                     $result .= '<div class="draw-table">';
                     $result .= '<table class="el-used" border="0" cellpadding="0" cellspacing="0">';
                     //Header
                     $result .= '<tr><th>Image</th><th>ID</th>';
                     //$result .= '<th>Code</th>';
                     $result .= '<th>Info</th><th>Qty</th><th>Unit</th><th><abbr title="Material Expenses">Mat.Exp.</abbr></th></tr>';
                     $counter = 0;
                     while ($phe = tep_db_fetch_array($phe_result)) {
                         if ($phe['elements_code'] != '07-0001BS') {
                             $counter++;
                             $rowclass = $counter % 2 == 0 ? 'e' : 'o';
                             $qty_type = 'piece';
                             if ($phe['quantity'] > 1 && $qty_type == 'piece') {
                                 $qty_type .= 's';
                             }
                             $el_img = 'elements/' . $phe['image_path'] . $phe['image_filename'];
                             $el_img_src = webImageSource($el_img);
                             $el_img_link = '<a href="' . $el_img_src . '" class="view_image" title="Element ID ' . $phe['elements_id'] . '">';
                             $result .= '<tr class="' . $rowclass . '">';
                             $result .= '<td>' . $el_img_link . webImage($el_img, '80', '80') . '</a></td>';
                             $result .= '<td><strong>' . $phe['elements_id'] . '</strong></td>';
                             //$result .= '<td><strong>'.$phe['elements_code'].'</strong></td>';
                             $result .= '<td style="width:300px;text-align:left;">';
                             $result .= $phe['name'];
                             if (isset($pe_image[$phe['elements_id']]) || isset($pe_text[$phe['elements_id']])) {
                                 $result .= '<br /><br /><span class="red">Personized Elements:</span><br />';
                                 if (isset($pe_image[$phe['elements_id']])) {
                                     $result .= implode(' &bull; ', $pe_image[$phe['elements_id']]);
                                 }
                                 if (isset($pe_text[$phe['elements_id']])) {
                                     $result .= $pe_text[$phe['elements_id']];
                                 }
                             }
                             $result .= '</td>';
                             $result .= '<td>' . $phe['quantity'] . '</td>';
                             $result .= '<td>' . $qty_type . '</td>';
                             $result .= '<td style="text-align:right;"><a href="?open=elements-suppliers&id=' . $phe['elements_id'] . '&hidemenu=true" class="view_webpage" title="View elements suppliers detail">';
                             $matexp = calculateCurrency($phe['quantity'] * $phe['price'], $phe['price_currency']);
                             $result .= displayCurrency('EUR', $matexp);
                             $result .= '</a></td>';
                             $result .= '</tr>';
                         }
                     }
                     $result .= '</table>';
                     $result .= '</div>';
                 }
             } else {
                 //ELEMENTS USED
                 //For standard Products:
                 $result .= '<div id="add_el_used_form" style="display:none;">';
                 $submit_action = $submit_action == '' ? '?open=product-detail&amp;products_id=' . $products_id . '#prodet-tab2' : $submit_action;
                 $result .= '<form name="elements_used_add" action="' . $submit_action . '" method="post">';
                 $result .= '<input type="hidden" name="me_action" value="ELEMENTSUSEDADD" />';
                 $result .= '<input type="hidden" name="products_id" value="' . $products_id . '" />';
                 $result .= '<div class="form"><table border="0" cellpadding="0" cellspacing="0">';
                 $result .= '<tr><td class="label">Element ID/Code</td><td><input type="text" name="add_id" value="" /></td>';
                 $result .= '<tr><td>Element Qty</td><td><input type="text" name="add_qty" value="1" onfocus="$(this).select();" /></td>';
                 $result .= '</table></div>';
                 $result .= '<div class="buttons"><input type="submit" name="submit" value="Add Element" /></div>';
                 $result .= '</form>';
                 $result .= '</div>';
                 //OVERRIDE FORMS
                 $result .= '<div id="ovr_el_used_form" style="display:none;">';
                 $result .= '<form name="elements_used_add" action="' . $submit_action . '" method="post">';
                 $result .= '<input type="hidden" name="me_action" value="ELEMENTSUSEDOVR" />';
                 $result .= '<input type="hidden" id="pid" name="products_id" value="' . $products_id . '" />';
                 $result .= '<input type="hidden" id="ovr_pean" name="ovr_pean" value=""/>';
                 $result .= '<input type="hidden" id="ovr_paid" name="ovr_paid" value=""/>';
                 $result .= '<input type="hidden" id="ovr_pueid" name="ovr_pueid" value=""/>';
                 $result .= '<input type="hidden" id="ovr_elid_def" name="ovr_elid_def" value=""/>';
                 $result .= '<input type="hidden" id="ovr_qty_def" name="ovr_qty_def" value=""/>';
                 $result .= '<input type="hidden" id="ovr_elid_old" name="ovr_elid_old" value=""/>';
                 $result .= '<input type="hidden" id="ovr_qty_old" name="ovr_qty_old" value=""/>';
                 $result .= '<input type="hidden" id="type" name="ovr_type" value=""/>';
                 $result .= '<div class="form"><table border="0" cellpadding="0" cellspacing="0">';
                 $result .= '<tr><td class="label">Element ID/Code</td><td><input type="text" id="ovr_id" name="ovr_id" value="" onfocus="$(this).select();" /></td>';
                 $result .= '<tr><td>Element Qty</td><td><input type="text" id="ovr_qty" name="ovr_qty" value="1" onfocus="$(this).select();" /></td>';
                 $result .= '</table></div>';
                 $result .= '<div class="buttons"><input type="button" class="submit" value="Override Element" /></div>';
                 $result .= '</form>';
                 $result .= '</div>';
                 //QUESTION FORMS
                 $result .= '<div id="confirm_form" style="display:none;">';
                 $result .= '<div class="form"><table border="0" cellpadding="0" cellspacing="0">';
                 $result .= '<tr><td>There element ID overridden on Additional Lengths, do you want to also replace with element <span id="el_id" class="bold"></span>?</td></tr>';
                 $result .= '</table></div>';
                 $result .= '<div class="buttons"><button name="act_yes" id="act_yes">Yes</button><button name="act_no" id="act_no">No</button></div>';
                 $result .= '</div>';
                 $form_width = 845;
                 $result .= '<form name="elements_used_update" action="' . $submit_action . '" method="post">';
                 $result .= '<input type="hidden" name="me_action" value="ELEMENTSUSEDUPDATE" />';
                 $result .= '<input type="hidden" name="products_id" value="' . $products_id . '" />';
                 if ($elements_use_msg != '') {
                     $result .= '<div style="margin:10px 0px;font-weight:bold;" class="red">' . $elements_use_msg . '</div>';
                 }
                 $pue_query = "SELECT pue.*, e.elements_code, e.elements_name, e.elements_image, e.elements_price, e.stars, e.elements_description";
                 $pue_query .= " FROM products_use_elements pue";
                 $pue_query .= " LEFT JOIN element e ON e.elements_id=pue.elements_id";
                 //$pue_query .= " LEFT JOIN `products_non_configurator` pnc ON pue.`products_id` = pnc.`products_id`";
                 //$pue_query .= " LEFT JOIN elements e ON e.elements_id=pue.elements_id";
                 //$pue_query .= " LEFT JOIN elements_description ed ON ed.elements_id=e.elements_id AND ed.languages_id=1";
                 //$pue_query .= " LEFT JOIN elements_images ei ON ei.elements_id=pue.elements_id AND elements_sample_name='EC1'";
                 //$pue_query .= " LEFT JOIN elements_to_elements_suppliers etes ON etes.elements_id=pue.elements_id AND etes.is_default='1'";
                 $pue_query .= " WHERE pue.products_id={$products_id}";
                 $pue_query .= " GROUP BY pue.elements_id";
                 $pue_result = tep_db_query($pue_query);
                 $products_length = $pnc['products_length'];
                 $form_footer = '<div class="pro-button" style="width:' . ($form_width + 5) . 'px;">';
                 $form_footer .= '<a href="?open=products-add-elements&amp;pid=' . $products_id . '&amp;hidemenu=true" class="view_webpage"></a>';
                 $form_footer .= '<input type="button" id="add_el_used" value="Add Element" />';
                 $form_footer .= '<input type="submit" name="submit" value="Save Changes" {BTNUPDDIS} />';
                 $form_footer .= '</div>';
                 $form_footer .= '</form>';
                 if (tep_db_num_rows($pue_result) == 0) {
                     //No Elements attached to product
                     $dis = SERVER_IS_LOCAL ? ' disabled="disabled"' : '';
                     $dis_note = SERVER_IS_LOCAL ? '<br /><span class="smallText notice">* can only' . ' be updated in Manobo Central!</span>' : '';
                     $result .= '<div class="box w500" style="margin-bottom:20px;">' . 'Material Expense (set manually in ' . CURRENCY_CODE_EURO . '): &nbsp; <input type="text"' . ' id="p-matexp-manual" class="w080 tar" value="' . $p['material_expenses'] . '"' . $dis . ' />' . $dis_note . '</div>';
                     $result .= '<h3 class="red bold">No Element is attached to this product</h3>';
                     $result .= str_replace('{BTNUPDDIS}', 'disabled="disabled"', $form_footer);
                 } else {
                     $complexity_manual = array_keys(productComplexityName(null, 2));
                     $title_complexity = 'This complexity sets ';
                     $title_complexity .= '<strong>' . (in_array($p['complexity'], $complexity_manual) ? 'manually by user' : 'automatically by manobo') . '</strong>';
                     $title_complexity .= ', if you need to change this,<br/>please do as explained below:<ol><li>Click on complexity</li><li>Select new complexity from displayed list</li></ol>Done, should be complexity will updated to the new values';
                     $complexity = drawIconInfo($title_complexity, true, 'float-left', 'margin-right:5px;') . '<span id="elused-complexity" class="pointer" title="Click to set complexity manually">' . productComplexityName($p['complexity']) . '</span><select id="elused-complexity-manual" style="display:none;"><option value="">Please select complexity</option>' . loadComboListFromArray(productComplexityName(null, 2)) . '</select> Complexity &laquo;';
                     $deflength = $products_length <= 0 ? '&nbsp;' : '&raquo; Default Length ' . textLength($products_length);
                     $result .= '<div style="margin-top:10px;width:' . $form_width . 'px;"><h2 style="float:right;">' . $complexity . '</h2><h2>' . $deflength . '</h2></div>';
                     $result .= '<div class="smallText notice" style="margin-bottom:2px;">* Remove elements by updating Qty to 0 (zero). To save all changes you MUST click on button "Save Changes"</div>';
                     $result .= '<div class="draw-table">';
                     $result .= '<table class="proman" border="0" cellpadding="0" cellspacing="0">';
                     //Header
                     $result .= '<tr>';
                     $result .= '<th>Image</th><th>ID</th><th class="w100">Main&nbsp;Element<br> <a href="javascript:void(0)" id="clear-main-image">Clear</a></th>';
                     $result .= '<th>Name</th><th>Qty</th>';
                     $result .= '<th>Finishing</th>';
                     $result .= '<th><abbr title="Material Expenses">Mat.Exp.</abbr></th>';
                     $result .= '<th>Action</th>';
                     $result .= '</tr>';
                     $counter = 0;
                     $matexp_total = 0;
                     while ($pue = tep_db_fetch_array($pue_result)) {
                         $products_analysis_link = '';
                         $counter++;
                         $rowclass = $counter % 2 == 0 ? 'e' : 'o';
                         $pueid = $pue['products_use_elements_id'];
                         $elid = $pue['elements_id'];
                         $qty = $pue['quantity'];
                         $is_main_el = $pue['is_main'];
                         $lr_check = $pue['length_relevance'] == '1' ? 'checked="checked"' : '';
                         $is_main_el_check = $pue['is_main'] == '1' ? 'checked="checked"' : '';
                         $is_main_el_result = '<input type="radio" id="' . $elid . '" class="is_main" name="is_main[' . $pue['elements_id'] . ']" value="1"' . $is_main_el_check . '/>';
                         $el_img = webImageWithDetailLink($pue['elements_image'], '80', '80', 'Element ' . $pue['elements_id']);
                         $quantity = '<input type="text" name="upd_qty[' . $pue['elements_id'] . ']" value="' . $pue['quantity'] . '" style="width:50px;text-align:center;" onfocus="this.select();" />';
                         $fin_gp = $pue['finishing_goldplate'] == '1' ? 'checked="checked"' : '';
                         $fin_hm = $pue['finishing_hammer'] == '1' ? 'checked="checked"' : '';
                         $fin_br = $pue['finishing_brush'] == '1' ? 'checked="checked"' : '';
                         $fin_ox = $pue['finishing_oxid'] == '1' ? 'checked="checked"' : '';
                         $fin_rg = $pue['finishing_rosegoldplate'] == '1' ? 'checked="checked"' : '';
                         $finishing = '<div style="margin-left:15px;"><table border="0" cellpadding="0" cellspacing="0">';
                         $finishing .= '<tr><td style="width:20px;"><input type="checkbox" id="fin_gp_' . $counter . '" class="fin" name="finishing_goldplate[' . $pue['elements_id'] . ']" value="1"' . $fin_gp . ' /></td><td class="load"><label for="fin_gp_' . $counter . '">Yellow Goldplate</label></td></tr>';
                         $finishing .= '<tr><td style="width:20px;"><input type="checkbox" id="fin_rg_' . $counter . '" class="fin" name="finishing_rosegoldplate[' . $pue['elements_id'] . ']" value="1"' . $fin_rg . ' /></td><td class="load"><label for="fin_rg_' . $counter . '">Rose Goldplate</label></td></tr>';
                         $finishing .= '<tr><td style="width:20px;"><input type="checkbox" id="fin_hm_' . $counter . '" class="fin" name="finishing_hammer[' . $pue['elements_id'] . ']" value="1"' . $fin_hm . ' /></td><td class="load"><label for="fin_hm_' . $counter . '">Hammer</label></td></tr>';
                         $finishing .= '<tr><td style="width:20px;"><input type="checkbox" id="fin_br_' . $counter . '" class="fin" name="finishing_brush[' . $pue['elements_id'] . ']" value="1"' . $fin_br . ' /></td><td class="load"><label for="fin_br_' . $counter . '">Brush</label></td></tr>';
                         $finishing .= '<tr><td style="width:20px;"><input type="checkbox" id="fin_ox_' . $counter . '" class="fin" name="finishing_oxid[' . $pue['elements_id'] . ']" value="1"' . $fin_ox . ' /></td><td class="load"><label for="fin_ox_' . $counter . '">Oxid</label></td></tr>';
                         $finishing .= '</table></div>';
                         //$matexp = $pue['quantity'] * $pue['elements_price'];
                         $matexp = $this->elementMaterialExpenses($pue['quantity'], $pue['elements_price']);
                         if ($pue['finishing_goldplate'] == '1') {
                             $matexp += FINISHING_PRICE_YELLOWGOLD;
                         }
                         if ($pue['finishing_hammer'] == '1') {
                             $matexp += FINISHING_PRICE_HAMMER;
                         }
                         if ($pue['finishing_brush'] == '1') {
                             $matexp += FINISHING_PRICE_BRUSH;
                         }
                         if ($pue['finishing_oxid'] == '1') {
                             $matexp += FINISHING_PRICE_OXID;
                         }
                         if ($pue['finishing_rosegoldplate'] == '1') {
                             $matexp += FINISHING_PRICE_ROSEGOLD;
                         }
                         $matexp_total += $matexp;
                         $matexp_link = '<a href="?open=elements-suppliers&id=' . $pue['elements_id'] . '&hidemenu=true" class="view_webpage" title="View elements suppliers detail">' . displayCurrency('EUR', $matexp) . '</a>';
                         //$products_analysis_link = '<a href="?open=products-analysis&sp=allsp&filter=el-used&sign=e&value='.$pue['elements_id'].'" target="_blank">Show all Products using this element</a>';
                         $products_analysis_link = '<a href="?open=products-analysis&sp=allsp&filter=el-used&sign=e&value=' . $pue['elements_id'] . '" target="_blank" title="Show all Products using Element ' . $pue['elements_id'] . '">&laquo; Show All Products &raquo;</a>';
                         $result .= '<tr class="' . $rowclass . '">';
                         $result .= '<td>' . $el_img . '</td>';
                         $result .= '<td><a class="view_webpage" href="?open=element&amp;id=' . $pue['elements_id'] . '&amp;hidemenu=true" title="Manage Element Detail">' . $pue['elements_id'] . '</a></td>';
                         $result .= '<td>' . $is_main_el_result . '</td>';
                         $result .= '<td class="name">' . $pue['elements_description'] . '<br />' . drawStars($pue['stars']) . '<br />' . $products_analysis_link . '</td>';
                         $result .= '<td>' . $quantity . '</td>';
                         $result .= '<td style="width:120;">' . $finishing . '</td>';
                         $result .= '<td class="pri">' . $matexp_link . '</td>';
                         $btn_o_def = '<input class="btn_ovr_def" type="button" value="Replace" title="Replace this element" />';
                         $h_pueid = '<input type="hidden" id="d_pueid" value="' . $pueid . '"/>';
                         $h_elid_def = '<input type="hidden" id="d_elid" value="' . $elid . '"/>';
                         $h_qty_def = '<input type="hidden" id="d_qty" value="' . $qty . '"/>';
                         $result .= '<td>' . $btn_o_def . $h_pueid . $h_elid_def . $h_qty_def . '</td>';
                         $result .= '</tr>';
                     }
                     $products_finishing = array();
                     $products_finishing_styles = $this->productHaveStylePrice('PF', $products_id);
                     $products_finishing_cost = 0;
                     if (count($products_finishing_styles) > 0) {
                         foreach ($products_finishing_styles as $styles_id) {
                             $products_finishing_cost = $this->getStylePrice($styles_id);
                             $matexp_total += $products_finishing_cost;
                             //not use class styles related to php5 issues for J&G webshop
                             $f_r = tep_db_query("SELECT name FROM styles_description WHERE styles_id = {$styles_id} AND languages_id = 2");
                             $f_row = tep_db_fetch_array($f_r);
                             $products_finishing[$f_row['name']] = $products_finishing_cost;
                         }
                     }
                     //$result .= '<tr><td colspan=""></td></tr>';
                     $result .= '</table></div>';
                     $chk_partial_plated = $product['p']['is_partial_plated'] == '1' ? 'checked="checked"' : '';
                     $title_product_is_partial_plated = 'Check this when product plated partially';
                     $result .= '<div style="margin:10px 0;float:left;" title="' . $title_product_is_partial_plated . '"><input type="checkbox" id="is_pp" value="1" name="is_partial_plated" ' . $chk_partial_plated . '>' . '<label for="is_pp"> Product is Partially Plated</label></div>';
                     if (count($products_finishing) > 0) {
                         $result .= '<div style="margin:10px 0;width:' . $form_width . 'px;text-align:right;">';
                         foreach ($products_finishing as $pfin_name => $pfin_cost) {
                             $result .= 'Product Finishing ' . $pfin_name . ': ' . displayCurrency('EUR', $pfin_cost) . '<br/>';
                         }
                         $result .= '</div>';
                     }
                     $result .= '<h3 style="margin:10px 0;width:' . $form_width . 'px;text-align:right;">Total Material Expenses: ' . displayCurrency('EUR', $matexp_total) . '</h3>';
                     $result .= str_replace('{BTNUPDDIS}', '', $form_footer);
                     //ARTICLES (ADDITIONAL LENGTH) TABLES
                     use_class('products_articles');
                     $class_pa = new products_articles();
                     $articles = $class_pa->retrieveList($products_id);
                     if (count($articles) > 0) {
                         $result .= '<div style="margin-top:30px;"><h2>Additional Length</h2></div>';
                         foreach ($articles as $key => $article) {
                             $p_aid = $article['products_articles_id'];
                             $qaue = "SELECT pa.*, pue.`quantity`,pue.`elements_id`, pue.`products_use_elements_id`, e.elements_image\n                                        FROM  products_articles pa\n                                        INNER JOIN `products_use_elements` pue ON pue.`products_id` = pa.`products_id`\n                                        LEFT JOIN element e ON e.`elements_id` = pue.`elements_id`\n                                        WHERE pa.`products_articles_id` = {$p_aid}";
                             $dbqaue = tep_db_query($qaue);
                             $p_ean = '';
                             $result .= '<div style="border:solid 1px #ababab;float:left;margin:0 20px 20px 0;background:#fff;">';
                             $articles_data = array();
                             while ($row = tep_db_fetch_array($dbqaue)) {
                                 $articles_data[$p_aid][] = $row;
                             }
                             foreach ($articles_data as $paid => $dt) {
                                 $p_ean = $dt[0]['products_ean'];
                                 $p_length = textLength($dt[0]['length']);
                                 $result .= '<h3 style="margin:5px;">Length ' . $p_length . '</h3>';
                                 $result .= '<table class="paid" border="0" celpadding="0" cellspacing="0"><tr><th>Image</th><th>ID</th><th>Qty.</th><th>Action</th></tr>';
                                 $n = 0;
                                 foreach ($dt as $key => $rd) {
                                     $el_img = $dt[$n]['elements_image'];
                                     $elid_def = $rd['elements_id'];
                                     $qty_def = $rd['quantity'];
                                     $qty_ovr = '0';
                                     $elid_ovr = '0';
                                     $pueid = $rd['products_use_elements_id'];
                                     $q_check = "SELECT paue.*, e.elements_image FROM products_articles_use_elements paue LEFT JOIN element e ON e.`elements_id` = paue.`elements_id` WHERE products_articles_id = {$p_aid} AND products_use_elements_id = {$pueid}";
                                     $dbqc = tep_db_query($q_check);
                                     if (tep_db_num_rows($dbqc) > 0) {
                                         while ($rc = tep_db_fetch_array($dbqc)) {
                                             $elid_ovr = $rc['elements_id'];
                                             $qty_ovr = $rc['quantity'];
                                             if ($elid_ovr != '' && $elid_ovr != '0') {
                                                 $el_img = $rc['elements_image'];
                                             }
                                         }
                                     }
                                     $style_elid = $elid_ovr != '0' && $elid_ovr != $elid_def ? ' bold' : '';
                                     $style_qty = $qty_ovr != '0' && $qty_ovr != $qty_def ? ' bold' : '';
                                     $elid = $elid_ovr != '0' ? $elid_ovr : $elid_def;
                                     $qty = $qty_ovr != '0' ? $qty_ovr : $qty_def;
                                     $result .= "<div>";
                                     $result .= '<tr id="' . $p_aid . $elid_def . '"' . ($style_elid != '' || $style_qty != '' ? 'style="background:#fbff96;"' : "") . ">";
                                     $result .= '<td class="img">' . webImage($el_img, '80', '80') . '</td>';
                                     $result .= '<td class="id' . $style_elid . '">' . ($style_elid != '' ? '<a href="?open=element&amp;id=' . $elid . '&amp;hidemenu=true" class="view_webpage">' . $elid . '</a>' : $elid) . '</td>';
                                     $result .= '<td class="qty' . $style_qty . '">' . $qty . '</td>';
                                     $h_paid = '<input type="hidden" id="h_paid" value="' . $p_aid . '"/>';
                                     $h_pean = '<input type="hidden" id="h_pean" value="' . $p_ean . '"/>';
                                     $h_pueid = '<input type="hidden" id="h_pueid" value="' . $pueid . '"/>';
                                     $h_elid_def = '<input type="hidden" id="h_elid_def" value="' . $elid_def . '"/>';
                                     $h_qty_def = '<input type="hidden" id="h_qty_def" value="' . $qty_def . '"/>';
                                     $h_elid = '<input type="hidden" id="h_elid" value="' . $elid . '"/>';
                                     $h_qty = '<input type="hidden" id="h_qty" value="' . $qty . '"/>';
                                     $btn_o = '<input class="btn_ovr" type="button" style="font-size:10;color:blue;margin:0;padding:0;" value="O" title="Override this element" />';
                                     $btn_r = $elid_ovr != 0 && $elid_ovr != $elid_def || $qty_ovr != 0 && $qty_ovr != $qty_def ? '<input class="btn_ovr_r" type="button" style="font-size:10;color:red;margin:0;padding:0;" value="R" title="Reset this element to ' . $elid_def . ' / ' . $qty_def . '"/>' : '<input class="btn_ovr_r" type="button" style="font-size:10;margin:0;padding:0;color:grey;" value="R" title="Reset this element to ' . $elid_def . ' / ' . $qty_def . '" disabled="disabled"/>';
                                     $result .= "<td>{$btn_o} {$btn_r} {$h_paid} {$h_pean} {$h_pueid} {$h_elid_def} {$h_qty_def} {$h_elid} {$h_qty}</td>";
                                     $result .= "</tr>";
                                     $n++;
                                 }
                                 $result .= '</table>';
                             }
                             $result .= '</div>';
                         }
                     }
                 }
                 $result .= '<div style="clear:both;"></div>';
             }
             $result = utf8_encode($result);
             break;
         case 'UPDATE':
             break;
         case 'ADD':
             break;
     }
     return $result;
 }