<script type="text/javascript">
var mydata = new Array();

$(document).ready(function() {
    $("button").button();
});

</script>
<!--GET PRODUCT FROM PRODUCT'S TABLE-->
<style>
.ui-autocomplete-loading { background: white url('<?= site_url() ?>public/images/ui-anim_basic_16x16.gif') right center no-repeat; }
</style>
<script type="text/javascript">
    var fields="";
$(function() {
    $( "#product" ).autocomplete({
        source: function(event, ui)  {
            $.ajax({ url: "<?php echo site_url('inventory/prodlabel/productautocomplete'); ?>",
                data: { term: $("#product").val()},
                dataType: "json",
                type: "POST",
                success: function(data){
                    ui(data);
                }
            });
        },
        minLength: 1,
            focus: function( event, ui ) {
                $( '#product').val( ui.item.label );
                return false;
            },
            select: function( event, ui ) {
                $( '#product').val( ui.item.label );
                $( '#productid' ).val(ui.item.value);
                return false;
            }
    });
});

function productChanged()
    {
        oForm = document.forms[0];
                pname = oForm.elements["prodlabel"];

        $.ajax({ url: "<?php echo site_url('inventory/prodlabel/getproductdetails'); ?>",
             data:{productid: productid.value},
            dataType: "json",
            type: "POST",
            success: function(data){
                fields="";
        $("#fields").empty();        
        for (var k in data) {
                    if (data.hasOwnProperty(k)) {
                if(k=="pricesell")       
                fields= fields+"<tr><th align='right'>"+k+"</th><td style='vertical-align:middle'><input id='"+ k +"' name='"+ k +"' type='text' class='inp-form' value='"+ Encode(data[k])+"'/></td></tr>";
            else
                fields= fields+"<tr><th align='right'>"+k+"</th><td style='vertical-align:middle'><input id='"+ k +"' name='"+ k +"' type='text' class='inp-form' value='"+ data[k]+"'/></td></tr>";
                    }
                }
                
            $("#fields").append(fields);
                

                
            }
        });
        
    }
    
    function Encode(message)
    {
        var alphabet, coded, i, ch, index;
        //012..9
        key = 'ABCDEFGHIJK'
        alphabet = "0123456789";

        coded = "";                                      
        for (i = 0; i < message.length; i++) {        
            ch = message.charAt(i);                   
            index = alphabet.indexOf(ch);             
            if (index == -1) {                        
                coded = coded + ch;                   
            }                                         
            else {                                    
                coded = coded + key.charAt(index);    
            }
        }
        return coded;
    }
</script>
<div class="main content clearfix">
<div class="page-heading">
            <h2>Product Label</h2>
</div>
        <table border="0" width="100%" cellpadding="0" cellspacing="0" id="content-table">
            <tr>
                <th rowspan="3" class="sized"><img src="<?= site_url() ?>images/shared/side_shadowleft.jpg" width="20" height="300" alt="" /></th>
                <th class="topleft"></th>
                <td id="tbl-border-top">&nbsp;</td>
                <th class="topright"></th>
                <th rowspan="3" class="sized"><img src="<?= site_url() ?>images/shared/side_shadowright.jpg" width="20" height="300" alt="" /></th>
            </tr>
            <tr>
                <td id="tbl-border-left"></td>
                <td>
                    <!--  start content-table-inner -->
                    <div id="content-table-inner">
                    <?php
                    if (@$message) {
                        echo '
                              start message-green 
                            <div id="message-green">
                            <table border="0" width="100%" cellpadding="0" cellspacing="0">
                            <tr>
                                    <td class="green-left">' . $message . ' <a href="' . site_url() . 'inventory/products/warehouses">Go to warehouse list.</a></td>
                                    <td class="green-right"><a class="close-green"><img src="' . site_url() . 'images/table/icon_close_green.gif"   alt="" /></a></td>
                            </tr>
                            </table>
                            </div>
                              end message-green 

    ';
                    }
                    ?>
                    <?= validation_errors('<div id="message-red"><table border="0" width="100%" cellpadding="0" cellspacing="0"><tr><td class="red-left">', '</td><td class="red-right"><a class="close-red"><img src="' . site_url() . '/images/table/icon_close_red.gif" alt="" /></a></td></tr></table></div>'); ?>
                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tr valign="top">
                            <td>

<!--                                 start id-form -->
                                <div class="myform-outer">
                                    <div class="myform">
                                        <form action="<?= site_url() . 'inventory/prodlabel/printlabel'; ?>" method="post" name="prodlabel" >
                                            <div class="myform-controls">
                                                <table border="0" cellpadding="0" cellspacing="0"  id="id-form">
                                                <tr>
                                                <th align="right">Product</th>
                                                    <td><input id="product" name="product" type="text" class="inp-form" onblur='productChanged(this.form)'/>
                                                        <input id="productid" name="productid" type="hidden"/>
                                                </td>
                                                 </tr>    
                                                 <tr>
                                                     <th align="right"></th>
                                                     <td>
                                                         <table><tr<div id="fields"></div></table>
                                                         </td>
                                                 </tr>
                                                   
                                                
                                            <tr>
                                                <th>&nbsp;</th>
                                                <td>
                                                   <div align="left"><br>
                                                    <button type="submit" value="0" name="submit">Submit</button>
                                                         </div></td> </tr>
                                                </table>

                                            </div>

                                        </form>
                                    </div></div></td>
                        </tr>

                    </table>
                        <div class="clear"></div>


                    </div>
                    <!--  end content-table-inner  -->
                </td>
                <td id="tbl-border-right"></td>
            </tr>
            <tr>
                <th class="sized bottomleft"></th>
                <td id="tbl-border-bottom">&nbsp;</td>
                <th class="sized bottomright"></th>
            </tr>
        </table>

<div class="clear">&nbsp;</div>
</div>
