<script type="text/javascript">

var psearchresult='';
         $(document).ready(function() {
        $("button").button();

$( "#dialog-form" ).dialog({
			autoOpen: false,
			height: 500,
			width: 1100,
			modal: true
                        ,
                        open: function(event, ui){
        control_name = $(this).data('control_name');

                        },
            beforeClose: function(event, ui) {
        $(this).data('control_name').val(psearchresult);
        }
		});

        $( "#psearchicon" ).button({
            icons: {
                primary: "ui-icon-search"
            },
            text: false
        });

        $('#barcode').bind('keypress', function(e) {
                alert('test');
        if(e.keyCode==13){
                alert('sfd');
        }
});

    });


$(function() {
$("#psearchicon").click(function(){
//showpsearchpanel();

$( "#dialog-form" ).dialog( "open" );

    });


    $("#spsearchbtn").click(function(){
    loadpsearchgrid();

        });

$("#spclosebtn").click(function(){

    $("#0_PRODUCT","#lines").val('22222222');
    $("#dialog-form").dialog( "close" );

        });

	});

//function showpsearchpanel() {
//$("#psearchpanel").show("blind", { direction: "vertical" }, 300);
//}
//
//function hidepsearchpanel()
//{
//$("#psearchpanel").hide("fade", { direction: "vertical" }, 150);
//}


//function spupdatecategories()
//{
//var cp = document.getElementById('spcheckp');
//var cm = document.getElementById('spcheckm');
//var ca = document.getElementById('spchecka');
//
//var catselect = document.getElementById('spcategory');
//
//for (i=0; i<somevariable; i++){
//var anOption = document.createElement("OPTION")
//document.form1.select1.options.add(anOption)
//anOption.innerText = "Two"
//anOption.Value = "2"
//
//}
//}

function loadpsearchgrid()
{
var bc = document.getElementById('spbarcode');
var pname = document.getElementById('spproduct');
//var cat = document.getElementById('spcategory');
var buyparam = document.getElementById('spbuyparam');
var buyprice = document.getElementById('spbuyprice');
var sellparam = document.getElementById('spsellparam');
var sellprice = document.getElementById('spsellprice');
var cp = document.getElementById('spcheckp');
var cm = document.getElementById('spcheckm');
var ca = document.getElementById('spchecka');

//var cp = '';
//var cm = '';
//var ca = '';

$("#psearchgrid").GridUnload();

jQuery("#psearchgrid").jqGrid({
url:'<?=site_url()?>inventory/productsearch/getproductsbyparam',
postData: {BARCODE: bc.value, PRODUCT: pname.value, BUYPARAM: buyparam.value,
BUYPRICE: buyprice.value, SELLPARAM: sellparam.value, SELLPRICE: sellprice.value, CP: cp.value, CM: cm.value, CA: ca.value},
datatype: "json",
mtype : "post",
colNames:['NAME','BUY', 'SELL', 'STOCK'],
colModel:[
{name:'PRODUCT',index:'PRODUCT', width:150},
{name:'PRICEBUY',index:'PRICEBUY', width:50, align:"right",formatter:'currency', formatoptions: {thousandsSeparator:','}},
{name:'PRICESELL',index:'PRICESELL', width:50, align:"right",formatter:'currency', formatoptions: {thousandsSeparator:','}},
{name:'UNITS',index:'UNITS', width:50, align:"center"}
],
rowNum:10,
rowList:[10,20,30],
rownumbers: true,
key: true,
rownumWidth: 40,
height: 200 ,
autowidth: true,
pager: '#psearchgridtoolbar',
sortname: 'NAME',
viewrecords: true,
sortorder: "asc",
onSelectRow: function(ids) {
psearchresult = jQuery("#psearchgrid").jqGrid('getCell', ids, 'PRODUCT');

}
//,loadError: function(xhr, textStatus, errorThrown)  {
//alert(errorThrown);
//}
});


}

</script>


<div id="dialog-form" title="Search Item">
<div class="myform-outer">
<div class="myform myform-search" style="width: 93%;">


<table>
<tr>
    <td><label>Barcode</label><br><input name="spbarcode" id="spbarcode" type="text"  /></td>
    <td><label>Name</label><br><input name="spproduct" id="spproduct" type="text"  /></td>
 <td><label>Product Category</label><br><select id="spcheckp" name="spcheckp">
<?= $cp ?>
</select></td>
 <td><label>Material Category</label><br><select id="spcheckm" name="spcheckm">
<?= $cm ?>
</select></td>
 <td><label>Asset Category</label><br><select id="spchecka" name="spchecka">
<?= $ca ?>
</select></td>
<td>
    <button id="spsearchbtn" name="spsearchbtn">Search</button>
                        <button id="spclosebtn" name="spclosebtn">Close</button>
</td>
</tr>
<tr>
    <td>&nbsp;</td>
</tr>

<tr>
<td>
    <label>Buy Price</label><br>
    <select id="spbuyparam" name="spbuyparam" >
<option value="" selected=’selected’>None</option>
<option value="=">Equals</option>
<option value="<>">Distinct</option>
<option value=">">Greater</option>
<option value="<">Less</option>
<option value=">=">Greater or Equal</option>
<option value="<=">Less or Equal</option>
</select><br>
<input name="spbuyprice" id="spbuyprice"  type="text" /></td>

<td>
    <label>Sell Price</label><br>
    <select id="spsellparam" name="spsellparam" >
<option value="" selected=’selected’>None</option>
<option value="=">Equals</option>
<option value="<>">Distinct</option>
<option value=">">Greater</option>
<option value="<">Less</option>
<option value=">=">Greater or Equal</option>
<option value="<=">Less or Equal</option>
</select><br>
<input name="spsellprice" id="spsellprice" type="text" /></td>
</tr>
</table>
</div>
<table id="psearchgrid"></table>
<div id="psearchgridtoolbar"></div>
</div>

</div>
