<table class ="tablefixed" width="93%" border="0">
  <tr class="tr20">
    <td valign="top" class="tdauto">
	<div class="ui-layout-content ui-widget-content-panel" style="padding-top:1px;padding-bottom:1px">
			<table width="947" border="0">
			  <tr>
				<td width="440" valign="top">
					<table width="440" border="0">
					  <tr>
						<td width="69">DOC NO \ DATE</td>
						<td width="3"><div align="center">:</div></td>
						<td width="242"><input tabindex="1" id="ms_prod_car_line_edit_doc_no" name="ms_prod_car_line_edit_doc_no"  style="width:95%;margin-bottom:2px"   type="text" /></td>
						<td width="10"><div align="center">\</div></td>
						<td width="94"><input  tabindex="1" id="ms_prod_car_line_edit_doc_date" name="ms_prod_car_line_edit_doc_date"   style="width:90px;margin-bottom:2px"   type="text" /></td>
					  </tr>
					  <tr>
					    <td>PROSSES</td>
					    <td>&nbsp;</td>
					    <td colspan="3"><input  tabindex="2" id="ms_prod_car_line_edit_type_proccess" name="ms_prod_car_line_edit_type_proccess" type="text" style="width:100%;margin-bottom:2px;background-color:#FFFF00" /></td>
				      </tr>
					  <tr>
					    <td>CAR LINE</td>
					    <td><div align="center">:</div></td>
					    <td colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td width="11%"><input  tabindex="3" id="ms_prod_car_line_edit_type_car_line_no" name="ms_prod_car_line_edit_type_car_line_no"   style="width:40px;margin-bottom:2px"  type="text" /></td>
                            <td width="3%">&nbsp;</td>
                            <td width="86%"><input id="ms_prod_car_line_edit_type_car_line_name" name="ms_prod_car_line_edit_type_car_line_name"   style="width:100%;margin-bottom:2px" disabled type="text" /></td>
                          </tr>
                        </table>				        </td>
				      </tr>
					</table>
				</td>
				<td width="10">&nbsp;</td>
		  <td width="366" valign="top">
<table width="366" border="0">
<tr>
							<td width="96">TECHNICIAN</td>
							<td width="10"><div align="center">:</div></td>
				  <td width="246">
				  <hidden tabindex="4" id="ms_prod_car_line_edit_teknisi_id" name="ms_prod_car_line_edit_teknisi_id"  style="width:95%;margin-bottom:2px"   type="text" /><input tabindex="4" id="ms_prod_car_line_edit_teknisi" name="ms_prod_car_line_edit_teknisi"  style="width:95%;margin-bottom:2px"   type="text" /></td>
			    </tr>
						  <tr>
							<td>INFO</td>
							<td><div align="center">:</div></td>
							<td rowspan="2"><textarea rows="2"  tabindex="5" id="ms_prod_car_line_edit_doc_info" name="ms_prod_car_line_edit_doc_info"   style="resize: none;overflow:auto;width:100%;margin-bottom:2px"  type="text" /></td>
						  </tr>
						  <tr>
						    <td>&nbsp;</td>
						    <td>&nbsp;</td>
			    </tr>
						</table>
				</td>
				<td width="10" valign="top">&nbsp;</td>
				<td width="99" valign="top"><button  tabindex="6" type="button" id="ms_prod_car_line_edit_save_header" >Save Header</button></td>
			  </tr>
			</table> 
	  </div>
	</td> 
</tr>
 <tr class="trauto"> 
    <td class="tdauto" valign="top" id="container_ms_prod_car_line_edit_tab"> 
			<div   tabindex="8"  id="ms_prod_car_line_edit_tab" class="tabs-nohdr" >
				<ul >
					<li><a  tabindex="9" id="ms_prod_car_line_edit_tab_list" href="#ms_prod_car_line_edit_tab_list_f" >LIST ITEM</a></li>
					<li><a  tabindex="10" id="ms_prod_car_line_edit_tab_supply" href="#ms_prod_car_line_edit_tab_supply_f">LIST SUPPLY</a></li>
				</ul>  
				<div id="ms_prod_car_line_edit_tab_list_f">
					<table id="ms_prod_car_line_tbl_detail"></table> <div id="pms_prod_car_line_tbl_detail"></div>
				   <div id="ms_prod_car_line_edit_panel_action" class="ui-layout-content ui-widget-content-panel">
					  <table width="100%" border="0">
						<tr>
						  <td width="43">PART NO</td>
						  <td width="3"><div align="center">:</div></td>
						  <td width="155"><input   tabindex="11"  id="ms_prod_car_line_edit_dtl_part_no" name="ms_memo_prod_car_line_edit_dtl_part_no"   style="width:150px;margin-bottom:2px"  type="text" /></td>
						  <td width="1">&nbsp;</td>
						  <td width="47">PART NAME</td>
						  <td width="9"><div align="center">:</div></td>
						  <td width="310"><input id="ms_prod_car_line_edit_dtl_part_name" name="ms_prod_car_line_edit_dtl_part_name"   style="width:100%;margin-bottom:2px"  type="text" disabled="disabled" /></td>
						  <td width="15">&nbsp;</td>
						  <td width="45" align="right">BASE NO</td>
						  <td width="6"><div align="center">:</div></td>
						  <td width="172"><input id="ms_prod_car_line_edit_dtl_part_base_no" name="ms_memo_prod_car_line_edit_dtl_part_base_no"   style="width:100%"  type="text" disabled="disabled" /></td>
						  <td width="19">&nbsp;</td>
						  <td width="37">UOM</td>
						  <td width="3"><div align="center">:</div></td>
						  <td width="60"><input id="ms_prod_car_line_edit_dtl_part_uom" name="ms_prod_car_line_edit_dtl_part_uom"   style="width:100%;margin-bottom:2px"  type="text" disabled="disabled" /></td>
						</tr>
						<tr>
						  <td>QTY</td>
						  <td><div align="center">:</div></td>
						  <td><input  tabindex="11"  id="ms_prod_car_line_edit_dtl_part_qty" name="ms_prod_car_line_edit_dtl_part_qty"   class="numeric" style="width:150px;text-align:right;;margin-bottom:2px;padding-right:5px"  type="text" /></td>
						  <td>&nbsp;</td>
						  <td>INFO</td>
						  <td><div align="center">:</div></td>
						  <td colspan="5"><input    tabindex="12"  id="ms_prod_car_line_edit_dtl_info" name="ms_prod_car_line_edit_dtl_info"   style="resize: none;width:100%;margin-bottom:2px"  type="text" /></td>
						  <td width="19">&nbsp;</td>
						  <td width="37">RACK</td>
						  <td width="3"><div align="center">:</div></td>
						  <td width="60" colspan="2"><input id="ms_prod_car_line_edit_dtl_rack" name="ms_prod_car_line_edit_dtl_rack"   style="width:100%;margin-bottom:2px"  type="text" disabled="disabled" /></td>
						</tr>
					  </table>
				  </div> 
					 
					<div  id="ms_prod_car_line_edit_panel_action_result" class="pane-header ui-state-active"> 
							<button  class="ms_prod_car_line_action_item" tabindex="13" type="button" id="ms_prod_car_line_edit_dtl_new">New</button>
							<button  class="ms_prod_car_line_action_item" tabindex="14" type="button" id="ms_prod_car_line_edit_dtl_edit">Edit</button>
							<button  class="ms_prod_car_line_action_item" tabindex="15" type="button" id="ms_prod_car_line_edit_dtl_delete">Delete</button>
							<button  class="ms_prod_car_line_action_item_result" tabindex="16" type="button" id="ms_prod_car_line_edit_dtl_save">Save</button>
							<button  class="ms_prod_car_line_action_item_result" tabindex="17" type="button" id="ms_prod_car_line_edit_dtl_cancel">Cancel</button>
							
							<input id="ms_prod_car_line_edit_dtl_ms_item_id" name="ms_prod_car_line_edit_dtl_ms_item_id"    type="hidden" />
					</div>
				</div>    
				<div id="ms_prod_car_line_edit_tab_supply_f">
				
					<table class ="tablefixed" width="100%" border="0">
					  <tr class="trauto">
					   <td width="11%" class="tdauto">
	      <table class ="tablefixed" width="89%" border="0">
								<tr class="trauto">
									<td valign="top" class="tdauto"> 
								<table id="ms_prod_car_line_tbl_stock" ></table> <div id="pms_prod_car_line_tbl_stock"></div>
									</td>
								</tr> 
								<tr class="tr150">
									<td valign="top" class="tdauto"> 
										<table id="ms_prod_car_line_tbl_supply" ></table> <div id="pms_prod_car_line_tbl_supply"></div>
									</td>
								</tr>
							</table> 
					  </td>
					  <td width="89%"  class="td280"> 
			<table class ="tablefixed" width="100%" border="0">
							  <tr class="trauto">
							   <td class="tdauto">
									   <div class="pane-header ui-state-active" >.: INFO</div>
										<div class="ui-layout-content ui-widget-content-panel" style="padding-top:10px;padding-bottom:10px">
										<table width="100%" border="0">
										  <tr>
                                            <td>Quantity</td>
										    <td><div align="center">:</div></td>
										    <td><input  tabindex="12"  id="ms_prod_car_line_edit_supply_total_qty"   class="numeric" style="width:140px;text-align:right;;margin-bottom:2px"  type="text"  readonly="readonly"  /></td>
										    <td><input  class="ms_prod_car_line_edit_supply_total_uom"    style="width:100%;margin-bottom:2px"  type="text" readonly="readonly" /></td>
									      </tr>
										  <tr>
                                            <td>Supply</td>
										    <td><div align="center">:</div></td>
										    <td><input  tabindex="12"  id="ms_prod_car_line_edit_supply_total_supply"  class="numeric" style="width:140px;text-align:right;;margin-bottom:2px;padding-right:5px"  type="text" readonly="readonly"  /></td>
										    <td><input class="ms_prod_car_line_edit_supply_total_uom"  style="width:100%;margin-bottom:2px"  type="text" readonly="readonly"   /></td>
									      </tr>
										  <tr>
											<td  style="width:60px">Available</td>
											<td  style="width:5px" ><div align="center">:</div></td>
											<td style="width:auto" ><input  tabindex="12"  id="ms_prod_car_line_edit_supply_total_available" class="numeric" style="width:140px;text-align:right;margin-bottom:2px;padding-right:5px"  type="text"  readonly  /></td>
								 			<td  style="width:40px"><input class="ms_prod_car_line_edit_supply_total_uom"  style="width:100%;margin-bottom:2px"  type="text" readonly /></td>
										  </tr>
										  <tr>
											<td>Less</td>
											<td><div align="center">:</div></td>
											<td><input  tabindex="12"  id="ms_prod_car_line_edit_supply_total_less"  class="numeric" style="width:140px;text-align:right;;margin-bottom:2px;padding-right:5px"  type="text" readonly  /></td>
									 		<td><input class="ms_prod_car_line_edit_supply_total_uom"   style="width:100%;margin-bottom:2px"  type="text" readonly /></td>
										  </tr>
										</table> 
								 </div>
									<div  class="pane-header ui-state-active"> 
										<button  class="ms_prod_car_line_action_supply" tabindex="13" type="button" id="ms_prod_car_line_action_supply_fifo">Fifo</button>
										<button  class="ms_prod_car_line_action_supply" tabindex="13" type="button" id="ms_prod_car_line_action_supply_lifo">Lifo</button>
									</div>
								</td>
							  </tr>
							  <tr class="tr150">
							   <td class="tdauto">
									   <div class="pane-header ui-state-active" >.: SUPPLY PROCCESS</div>
										<div class="ui-layout-content ui-widget-content-panel" style="padding-top:10px;padding-bottom:10px">
										<table width="100%" border="0">
										  <tr>
											<td width="81" style="width:60px">From
										    <input type="hidden"  id="ms_prod_car_line_edit_supply_ms_item_out_detail_id" />
                                            <input type="hidden"  id="ms_prod_car_line_edit_supply_ms_item_in_detail_id" /></td>
											<td width="5" style="width:5px"><div align="center">:</div></td>
											<td colspan="2" style="width:auto" ><input  tabindex="12"  id="ms_prod_car_line_edit_supply_source_name"  style="width:100%;margin-bottom:2px"  type="text" readonly   /></td>
										  </tr>
										  <tr>
											<td>Doc No</td>
											<td><div align="center">:</div></td>
											<td colspan="2" style="width:auto"><input  tabindex="12"  id="ms_prod_car_line_edit_supply_source_doc_no" style="width:100%;margin-bottom:2px"  type="text" readonly  /></td>
										  </tr>
										  <tr>
											<td>Doc Date</td>
											<td><div align="center">:</div></td>
											<td colspan="2" style="width:auto"><input  tabindex="12"  id="ms_prod_car_line_edit_supply_source_doc_date"  style="width:100%;margin-bottom:2px"  type="text" readonly  /></td>
										  </tr>
										  <tr>
											<td>Receive No</td>
											<td><div align="center">:</div></td>
											<td colspan="2" style="width:auto"><input  tabindex="12"  id="ms_prod_car_line_edit_supply_source_receive_no" style="width:100%;margin-bottom:2px"  type="text" readonly  /></td>
										  </tr>
										  <tr>
											<td>Receive Date</td>
											<td><div align="center">:</div></td>
											<td colspan="2" style="width:auto"><input  tabindex="12"  id="ms_prod_car_line_edit_supply_source_receive_date"  style="width:100%;margin-bottom:2px"  type="text" readonly  /></td>
										  </tr>
										  <tr>
										    <td><span style="width:60px">Available</span></td>
										    <td><div align="center">:</div></td>
										    <td colspan="2" style="width:auto"><input  tabindex="12"  id="ms_prod_car_line_edit_supply_source_available" class="numeric" style="width:100%;margin-bottom:2px"  type="text" readonly="readonly"  /></td>
									      </tr>
										  <tr>
											<td  style="width:60px">Qty Supply</td>
											<td  style="width:5px"><div align="center">:</div></td>
											<td width="532"  style="width:auto"><input  tabindex="12"  id="ms_prod_car_line_edit_supply_total_edit" class="numeric" style="width:140px;text-align:right;;margin-bottom:2px;padding-right:5px"  type="text"  /></td>
										    <td width="231"  style="width:auto"><input class="ms_prod_car_line_edit_supply_total_uom"   style="width:100%;margin-bottom:2px"  type="text" readonly="readonly" /></td>
										  </tr>
										  <tr>
										    <td  style="width:60px">&nbsp;</td>
										    <td  style="width:5px">&nbsp;</td>
										    <td colspan="2"  style="width:auto"><button  class="ms_prod_car_line_action_supply" tabindex="13" type="button" id="ms_prod_car_line_action_supply_equal_less" disabled="disabled">auto fill</button></td>
									      </tr>
										</table> 
								 </div>
									<div  class="pane-header ui-state-active"> 
										<button  class="ms_prod_car_line_action_supply" tabindex="13" type="button" id="ms_prod_car_line_action_supply_save" disabled="disabled" >Add</button>
										<button  class="ms_prod_car_line_action_supply" tabindex="13" type="button" id="ms_prod_car_line_action_supply_delete" disabled="disabled" >Delete</button>
									</div>
								</td>
							  </tr>
							</table> 
								
							
						</td> 
					 </tr>
					 </table>
					
			  </div>   
				
			</div>	
		</td>
  </tr>
</table>


  
<script type="text/javascript">

$(document).ready(function(){
	
	$(window).bind('resize', function () {
		$("#ms_prod_car_line_edit_tab").css("height", $("#container_ms_prod_car_line_edit_tab").height() - 10);
		setGridHight(jQuery("#ms_prod_car_line_tbl_detail"),jQuery("#container_ms_prod_car_line_edit_tab"),jQuery("#ms_prod_car_line_edit_panel_action"),jQuery("#ms_prod_car_line_edit_panel_action_result").height() +  jQuery("#container_ms_prod_car_line_edit_tab ul").first().height() +30)
	});
	

	$("input.numeric").numeric();
	var ms_prod_car_line_edit_row_detail_edit;
	var ms_prod_car_line_edit_row_detail_select;
	var ms_prod_car_line_edit_after_supply_action=false;
	
	var ms_prod_car_line_edit_row_stock_select;
	var ms_prod_car_line_edit_row_supply_select;
	
	var ms_prod_car_line_edit_row_detail_mode_aktifitas=-1;
    var ms_prod_car_line_edit_row_header<?php echo isset($row_data)?'='.json_encode($row_data):'=null';  ?>;  

	console.log(ms_prod_car_line_edit_row_header);
	 $( ".date_edit" ).datepicker({
		changeMonth: true
			,changeYear: true
			,showButtonPanel: true
			,dateFormat: 'dd/mm/yy'
			,onClose: function(dateText, inst){
					var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
					var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
					var day = $("#ui-datepicker-div .ui-datepicker-day :selected").val();
					}
			, onSelect: function (){
				$(this).focus();
			}
		}).keyup(function(e) {
			 
		}).on("input change", function (e) {
			 
		}); 
  
	
	$( "#ms_prod_car_line_edit_doc_date" ).datepicker({
			changeMonth: true
			,changeYear: true
			,showButtonPanel: true
			,dateFormat: 'dd/mm/yy'
			,onClose: function(dateText, inst){
					var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
					var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
					var day = $("#ui-datepicker-div .ui-datepicker-day :selected").val();
					}
			, onSelect: function (){
				$(this).focus();
			}
		}).keyup(function(e) {
			 
		}).on("input change", function (e) {
			 
		}); 
  

	if (!ms_prod_car_line_edit_row_header)
	{ 		  
		$('#ms_prod_car_line_edit_dtl_new').button( "option", "disabled",true );  
		
	}else{
		$('#ms_prod_car_line_edit_doc_no').val(ms_prod_car_line_edit_row_header.r2);     
		$('#ms_prod_car_line_edit_doc_date').val(ms_prod_car_line_edit_row_header.r3);     
		$('#ms_prod_car_line_edit_teknisi').val(ms_prod_car_line_edit_row_header.r20);    
		$('#ms_prod_car_line_edit_doc_info').val(ms_prod_car_line_edit_row_header.r4);    
		$('#ms_prod_car_line_edit_type_proccess').val(ms_prod_car_line_edit_row_header.r5);     
		$('#ms_prod_car_line_edit_type_car_line_no').val(ms_prod_car_line_edit_row_header.r6);  
		$('#ms_prod_car_line_edit_teknisi_id').val(ms_prod_car_line_edit_row_header.r19);  
		$('#ms_prod_car_line_edit_type_car_line_name').val(ms_prod_car_line_edit_row_header.r7);   
		
	
	   
	}
	
	
	$( "#ms_prod_car_line_edit_tab" ).tabs();
	$("#ms_prod_car_line_edit_tab" ).tabs("select", 0); 
    $("#ms_prod_car_line_edit_tab").css("height", $("#container_ms_prod_car_line_edit_tab").height() - 10);
 
	 
	 
	function ms_prod_car_line_edit_header_check(){
		
		if (!ms_prod_car_line_edit_row_header){
		    $('#ms_prod_car_line_edit_dtl_new').button( "option", "disabled",true );
		    $('#ms_prod_car_line_edit_dtl_edit').button( "option", "disabled",true );
		    $('#ms_prod_car_line_edit_dtl_delete').button( "option", "disabled",true ); 
			
			$( "#ms_prod_car_line_edit_save_header" ).find('span').text("SAVE HEADER"); 
			$('#ms_prod_car_line_edit_approve').button( "option", "disabled",true );
			$( "#ms_prod_car_line_edit_tab" ).tabs( "option", "disabled", [ 1] ) 
			}
		else {
			$('#ms_prod_car_line_edit_dtl_new').button( "option", "disabled",false );
			
			$( "#ms_prod_car_line_edit_save_header" ).find('span').text("UPDATE HEADER");
			$('#ms_prod_car_line_edit_approve').button( "option", "disabled", false );
			ms_prod_car_line_edit_row_detail_check_row(ms_prod_car_line_edit_row_detail_select);
		} 
	}
	
	function ms_prod_car_line_edit_row_detail_readonly(value)
	{  
		$('#ms_prod_car_line_edit_dtl_part_qty').attr('readonly', value);
		$('#ms_prod_car_line_edit_dtl_part_no').attr('readonly', value);  
		$('#ms_prod_car_line_edit_dtl_part_name').attr('readonly', value);  
		$('#ms_prod_car_line_edit_dtl_part_uom').attr('readonly', value);   
		$('#ms_prod_car_line_edit_dtl_part_base_no').attr('readonly', value);   
		$('#ms_prod_car_line_edit_dtl_info').attr('readonly', value);   
		
	};  		
 
	function ms_prod_car_line_edit_row_detail_check_row(value)
	{
		if (value){
			$('#ms_prod_car_line_edit_dtl_edit').button( "option", "disabled", false );
			$('#ms_prod_car_line_edit_dtl_delete').button( "option", "disabled", false ); 
			
			$("#ms_prod_car_line_edit_dtl_ms_item_id").val(value.r1); 
			$("#ms_prod_car_line_edit_dtl_part_no").val(value.r2); 
			$("#ms_prod_car_line_edit_dtl_part_name").val(value.r3); 
			$("#ms_prod_car_line_edit_dtl_part_uom").val(value.r4); 
			$("#ms_prod_car_line_edit_dtl_part_base_no").val(value.r3i);  
			$("#ms_prod_car_line_edit_dtl_part_qty").val(value.r5);
			$("#ms_prod_car_line_edit_dtl_info").val(value.r6);
			$("#ms_prod_car_line_edit_dtl_rack").val(value.r6r);
			
			
			var postData={
				 ms_item_id					: value.r1
				,ms_car_line_out_detail_id	: value.rID 
			} 
			
			$( "#ms_prod_car_line_edit_tab" ).tabs( "option", "disabled", [] ) 
	
			$("#ms_prod_car_line_tbl_supply").jqGrid('setGridParam',{postData, datatype:'json'}); 
			$("#ms_prod_car_line_tbl_stock").jqGrid('setGridParam',{postData, datatype:'json'}); 
		 
		}else{
			$( "#ms_prod_car_line_edit_tab" ).tabs( "option", "disabled", [ 1] ) 
		 
			   $('#ms_prod_car_line_edit_dtl_edit').button( "option", "disabled",true );
			   $('#ms_prod_car_line_edit_dtl_delete').button( "option", "disabled",true );
			   
			   $("#ms_prod_car_line_edit_dtl_ms_item_id").val(""); 
			   $("#ms_prod_car_line_edit_dtl_part_no").val(""); 
			   $("#ms_prod_car_line_edit_dtl_part_name").val(""); 
			   $("#ms_prod_car_line_edit_dtl_part_uom").val("");
			   $("#ms_prod_car_line_edit_dtl_part_qty").val("");
			   $("#ms_prod_car_line_edit_dtl_part_base_no").val("");
			   $("#ms_prod_car_line_edit_dtl_info").val('');
			   $("#ms_prod_car_line_edit_dtl_rack").val('');
			   
		}
		 
	};	
		 
	  $('#ms_prod_car_line_edit_tab').bind('tabsselect', function(event, ui) { 
			  selected=ui.index; 
			  if(selected==1)
			  { 
					$('#ms_prod_car_line_tbl_stock').trigger('reloadGrid');  
					$('#ms_prod_car_line_tbl_supply').trigger('reloadGrid'); 
				 	$(".ms_prod_car_line_edit_supply_total_uom").val(ms_prod_car_line_edit_row_detail_select.r4);  
					$('#ms_prod_car_line_dialog_info').show();
							  }  
			  else if (selected==0){ 
					$('#ms_prod_car_line_dialog_info').hide();
					ms_prod_car_line_edit_row_stock_select=null;
					ms_prod_car_line_edit_row_supply_select=null; 
					$("#ms_prod_car_line_edit_supply_source_name").val('');  
					$("#ms_prod_car_line_edit_supply_source_doc_no").val(''); 
					$("#ms_prod_car_line_edit_supply_source_doc_date").val(''); 
					$("#ms_prod_car_line_edit_supply_source_receive_no").val(''); 
					$("#ms_prod_car_line_edit_supply_source_receive_date").val(''); 
					$("#ms_prod_car_line_edit_supply_source_available").val(''); 
					$("#ms_prod_car_line_edit_supply_total_edit").val('');
					$("#ms_prod_car_line_edit_supply_ms_item_in_detail_id").val('-1');  
				    $("#ms_prod_car_line_edit_supply_ms_item_out_detail_id").val('-1');  
					$( "#ms_prod_car_line_action_supply_save" ).button( "option", "disabled",true );
					$( "#ms_prod_car_line_action_supply_delete" ).button( "option", "disabled",true );
					$( "#ms_prod_car_line_action_supply_equal_less" ).button( "option", "disabled",true );	
					if (ms_prod_car_line_edit_after_supply_action==true){
						
						$('#ms_prod_car_line_tbl_detail').trigger('reloadGrid');  
					}
					ms_prod_car_line_edit_after_supply_action=false;
			  }
	  });
  
	function ms_prod_car_line_edit_row_detail_action(value)
	{  
		ms_prod_car_line_edit_row_detail_mode_aktifitas=value; 
		if (ms_prod_car_line_edit_row_detail_mode_aktifitas==0){ 
			$("#ms_prod_car_line_supply_lifo").addClass('ui-state-disabled');
			$("#ms_prod_car_line_supply_fifo").addClass('ui-state-disabled');  

			$( "#ms_prod_car_line_edit_tab" ).tabs( "option", "disabled", [ 1] ) 
	
			$(".ms_prod_car_line_action_item").hide();
			$(".ms_prod_car_line_action_item_result").show() ;
			ms_prod_car_line_edit_row_detail_edit=null;
			ms_prod_car_line_edit_row_detail_readonly(false);   
			ms_prod_car_line_edit_row_detail_check_row(ms_prod_car_line_edit_row_detail_edit);  
			
			$('#ms_prod_car_line_edit_dtl_part_no').focus();
		}else if ( ms_prod_car_line_edit_row_detail_mode_aktifitas==1){
			$("#ms_prod_car_line_supply_lifo").addClass('ui-state-disabled');
			$("#ms_prod_car_line_supply_fifo").addClass('ui-state-disabled');  
			
			$( "#ms_prod_car_line_edit_tab" ).tabs( "option", "disabled", [ 1] ) 
	
			$(".ms_prod_car_line_action_item").hide();
			$(".ms_prod_car_line_action_item_result").show() ;
			ms_prod_car_line_edit_row_detail_readonly(false);   
			ms_prod_car_line_edit_row_detail_edit=ms_prod_car_line_edit_row_detail_select; 
			ms_prod_car_line_edit_row_detail_check_row(ms_prod_car_line_edit_row_detail_edit);  
			
			$('#ms_prod_car_line_edit_dtl_part_no').focus();
		}else if ( ms_prod_car_line_edit_row_detail_mode_aktifitas==-1){
			$(".ms_prod_car_line_action_item").show();
			$(".ms_prod_car_line_action_item_result").hide();  
			ms_prod_car_line_edit_row_detail_readonly(true); 
			if (ms_prod_car_line_edit_row_detail_select){
				ms_prod_car_line_edit_row_detail_check_row(ms_prod_car_line_edit_row_detail_select);
			}	
		} 
	};
	
  
	  
		$('#ms_prod_car_line_edit_dtl_new').button().click(function () { 
		   ms_prod_car_line_edit_row_detail_action(0); 
		}); 
		$('#ms_prod_car_line_edit_dtl_edit').button().click(function () { 
			if (ms_prod_car_line_edit_row_detail_select) {
					ms_prod_car_line_edit_row_detail_action(1);  
			}else{ 
				alert('Pilih Item yang akan di edit');
				return false;
			}
		});
		
		$('#ms_prod_car_line_edit_dtl_cancel').button().click(function () { 
			ms_prod_car_line_edit_row_detail_action(-1);
		});
		
		$('#ms_prod_car_line_edit_dtl_delete').button().click(function () {  
				var form_edit = {
				 	     detail_id		:ms_prod_car_line_edit_row_detail_select.rID 
 				}; 
				
				var _url_target='<?php echo base_url().'ms_production/ct_ms_prod_car_line/delete_detail'; ?>';
 						
				 $('#ms_prod_car_line_edit_dtl_delete').button( "option", "disabled",true );;
					$.ajax({    
					url:_url_target,
					type : 'POST',
						data : form_edit,
						dataType: 'json',
						success: function(msg){
							if (msg.valid){  
									 ms_prod_car_line_edit_row_detail_action(-1); 
									 ms_prod_car_line_edit_row_detail_select=null;	
									 ms_prod_car_line_edit_row_detail_check_row(ms_prod_car_line_edit_row_detail_select);									 
									$('#ms_prod_car_line_tbl_detail').trigger('reloadGrid'); 
							} else { 
								alert(msg.stsno+msg.stsmsg);    
							}
						} 
					}).always(function() {
					});  
		});
 
 
		jQuery("#ms_prod_car_line_edit_dtl_save").button().click(function(){   
				var form_edit = {
						 header_id		:(!ms_prod_car_line_edit_row_header)?'-1':ms_prod_car_line_edit_row_header.rID 
					    ,detail_id		:ms_prod_car_line_edit_row_detail_mode_aktifitas==0 ?'-1':ms_prod_car_line_edit_row_detail_edit.rID 
						,ms_item_id		:$('#ms_prod_car_line_edit_dtl_ms_item_id').val()
						,part_no		:$('#ms_prod_car_line_edit_dtl_part_no').val()
					    ,qty			:$('#ms_prod_car_line_edit_dtl_part_qty').val()
					    ,info			:$('#ms_prod_car_line_edit_dtl_info').val()
				}; 
				
				var _url_target='<?php echo base_url().'ms_production/ct_ms_prod_car_line/save_detail'; ?>';
 						
				 $('#ms_prod_car_line_edit_dtl_save').button( "option", "disabled",true );;
					$.ajax({    
					url:_url_target,
					type : 'POST',
						data : form_edit,
						dataType: 'json',
						success: function(msg){
							if (msg.valid){ 
								if (ms_prod_car_line_edit_row_detail_mode_aktifitas==1){
									 ms_prod_car_line_edit_row_detail_action(-1); 
									 ms_prod_car_line_edit_row_detail_select=ms_prod_car_line_edit_row_detail_edit;							 
								}else if (ms_prod_car_line_edit_row_detail_mode_aktifitas==0){
									 ms_prod_car_line_edit_row_detail_action(ms_prod_car_line_edit_row_detail_mode_aktifitas); 
								} 
								$('#ms_prod_car_line_tbl_detail').trigger('reloadGrid'); 
							} else { 
								alert(msg.stsno+msg.stsmsg);    
							}
						} 
					}).always(function() {
						$('#ms_prod_car_line_edit_dtl_save').button( "option", "disabled", false );;
					});  
	});
	 
	jQuery("#ms_prod_car_line_edit_save_header").button().click(function(){   
		var form_edit = {
				header_id		:(!ms_prod_car_line_edit_row_header)?'-1':ms_prod_car_line_edit_row_header.rID
				,doc_no			:$('#ms_prod_car_line_edit_doc_no').val()
				,doc_date		:getValueDate($("#ms_prod_car_line_edit_doc_date"),'yymmdd') 
				,doc_info		:$('#ms_prod_car_line_edit_doc_info').val()
				,teknisi		:$('#ms_prod_car_line_edit_teknisi').val()
				,teknisi_id		:$('#ms_prod_car_line_edit_teknisi_id').val()
				,car_line		:$('#ms_prod_car_line_edit_type_car_line_no').val()
				,car_line_name	:$('#ms_prod_car_line_edit_type_car_line_name').val()
				,type_prosses	:$('#ms_prod_car_line_edit_type_proccess').val()
		};  
	 		var	_url_target='<?php echo base_url().'ms_production/ct_ms_prod_car_line/save_header'; ?>';
 
			$('#ms_prod_car_line_edit_save_header').button( "option", "disabled",true );;
			$.ajax({    
			url:_url_target,
			type : 'POST',
			data : form_edit,
			dataType: 'json',
			success: function(msg){
					if (msg.valid){ 
							if (!ms_prod_car_line_edit_row_header) {
								$("#ms_prod_car_line_edit_tab" ).tabs("select", 1); 
							}else{ 
								alert(msg.stsmsg);
							}
							ms_prod_car_line_edit_row_header=msg.detail; 
							jQuery('span.ui-dialog-title').text('EDIT CAR LINE (' +ms_prod_car_line_edit_row_header.r2 + ' - ' + ms_prod_car_line_edit_row_header.r3 + ')');
						 	$("#ms_prod_car_line_tbl_detail").jqGrid('setGridParam',{postData:{header_id:ms_prod_car_line_edit_row_header.rID},datatype:'json'});
							$("#ms_prod_car_line_tbl_detail").trigger("reloadGrid"); 
							$('#ms_prod_car_line_tbl_stock_info').html('    !!!   MAX RECEIVE DATE : ' + ms_prod_car_line_edit_row_header.r3)

							ms_prod_car_line_edit_header_check(); 
					} else { 
						alert(msg.stsno+msg.stsmsg);    
					}
				} 
			}).always(function() {
				$('#ms_prod_car_line_edit_save_header').button( "option", "disabled", false );;
			});  
	}); 
  
	
	$("#ms_prod_car_line_edit_teknisi").mcautocomplete({
			// These next two options are what this plugin adds to the autocomplete widget.
			showHeader: true,
			 classes: {
						"ui-autocomplete": "highlight"
						},
			columns: [{name: 'ID', width: '50px',hidden:true, valueField: 'rID'},
				{name: 'Code', width:'120px',  valueField: 'r1'},
				{name: 'Name', width:'220px',  valueField: 'r2'}],
			
			// Event handler for when a list item is selected.
			select: function(event, ui) {
				this.value = (ui.item ? ui.item.r1 : '');
				$("#ms_prod_car_line_edit_teknisi_id").val((ui.item ? ui.item.rID : '-1'));  
				$("#ms_prod_car_line_edit_teknisi_name").val((ui.item ? ui.item.r2 : 'None'));  
			//	$('#results').text(ui.item ? 'Selected: ' + ui.item.rID + ', ' + ui.item.r1  + this.value);
				return false;
			},
			 change: function( event, ui ) { 
			 }, 
			minLength: 1,
			delay: 500,
			source: function(request, response) {
				$.ajax({
					url: '<?php echo base_url().'ms_master/ct_ms_find/find_teknisi'; ?>',
					dataType: 'json',
					data: {
						limit: 15,
						findtext: request.term,
					},
					// The success event handler will display "No match found" if no items are returned.
					success: function(data) {
						var result;
						if (!data || data.length === 0 || !data.rows || data.rows.length === 0) {
							result = [{label: 'No match found.'}];
							this.value = '';
							$("#ms_prod_car_line_edit_teknisi_id").val('-1');  
							$("#ms_prod_car_line_edit_teknisi_name").val('None');  
						}
						else {
							result = data.rows;
						}
						response(result);
					}
				});
			}
		});		
	 
	  
	$("#ms_prod_car_line_edit_type_car_line_no").mcautocomplete({
			// These next two options are what this plugin adds to the autocomplete widget.
			showHeader: true,
			 classes: {
						"ui-autocomplete": "highlight"
						},
			columns: [{name: 'ID', width: '50px', valueField: 'rID'},
				{name: 'Name', width:'120px',  valueField: 'r1'}],
			
			// Event handler for when a list item is selected.
			select: function(event, ui) {
				this.value = (ui.item ? ui.item.rID : '');
				$("#ms_prod_car_line_edit_type_car_line_name").val((ui.item ? ui.item.r1 : ''));  
			//	$('#results').text(ui.item ? 'Selected: ' + ui.item.rID + ', ' + ui.item.r1  + this.value);
				return false;
			},
			 change: function( event, ui ) { 
			 }, 
			minLength: 1,
			delay: 500,
			source: function(request, response) {
				$.ajax({
					url: '<?php echo base_url().'ms_master/ct_ms_car_line/find_car_line'; ?>',
					dataType: 'json',
					data: {
						limit: 15,
						findtext: request.term,
					},
					// The success event handler will display "No match found" if no items are returned.
					success: function(data) {
						var result;
						if (!data || data.length === 0 || !data.rows || data.rows.length === 0) {
							result = [{label: 'No match found.'}];
							this.value = '';
							$("#ms_prod_car_line_edit_type_car_line_name").val('');  
						}
						else {
							result = data.rows;
						}
						response(result);
					}
				});
			}
		});		
	 
	  
	
 $("#ms_prod_car_line_edit_type_proccess").mcautocomplete({
			// These next two options are what this plugin adds to the autocomplete widget.
			showHeader: true,
			 classes: {
						"ui-autocomplete": "highlight"
						},
			columns: [{name: 'Name', width:'120px',  valueField: 'r1'}],
			
			// Event handler for when a list item is selected.
			select: function(event, ui) {
				this.value = (ui.item ? ui.item.r1 : '');
				$("#ms_prod_car_line_edit_type_proccess").val((ui.item ? ui.item.r1 : ''));  
			return false;
			},
			 change: function( event, ui ) {
			 }, 
			minLength: 1,
			delay: 500,
			source: function(request, response) {
				$.ajax({
					url: '<?php echo base_url().'ms_master/ct_ms_type_prosses/find_prosses'; ?>',
					dataType: 'json',
					data: {
						limit: 15,
						findtext: request.term,
					},
					// The success event handler will display "No match found" if no items are returned.
					success: function(data) {
						var result;
						if (!data || data.length === 0 || !data.rows || data.rows.length === 0) {
							result = [{label: 'No match found.'}];
							this.value = '';
							$("#ms_prod_car_line_edit_type_proccess").val('');  
						}
						else {
							result = data.rows;
						}
						response(result);
					}
				});
			}
		});		
	
 
	jQuery("#ms_prod_car_line_tbl_detail").jqGrid({
			url:'<?php echo base_url().'ms_production/ct_ms_prod_car_line/loaddata_detail'; ?>',
			mtype : "post",
			postData:{'a':'a'},
			datatype: "local",
			colNames:[
				'id','ms_item_id','PART NO','PART NAME','UOM','RACK','QUANTITY','SUPPLY','BASE NO'
				,'INFO','CREATE DATE','CREATE BY','MODIFY DATE','MODIFY BY'
				,'dt_ms_car_line_out_detail_ms_car_line_out_header_id','r_s'
				]
				,colModel:[
				 {name:'rID',index:'rID', width:80, hidden:true, align :'right', key:true}
				,{name:'r1',index:'r1', width:80, hidden:true, align :'right'}
				,{name:'r2',index:'r2', width:120, hidden:false, align :'left'}
				,{name:'r3',index:'r3', width:220, hidden:false, align :'left'}
				,{name:'r4',index:'r4', width:50, hidden:false, align :'left'}
				,{name:'r6r',index:'r6r', width:200, hidden:false, align :'left'}
				,{name:'r5',index:'r5', width:120, hidden:false, align :'right'} 
				,{name:'r5s',index:'r5s', width:120, hidden:false, align :'right'} 
				,{name:'r3i',index:'r3i', width:250, hidden:false, align :'left'}
				
				,{name:'r6',index:'r6', width:200, hidden:false, align :'left'}
				,{name:'r7',index:'r7', width:120, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_prod_car_line_tbl_detail")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
				,{name:'r8',index:'r8', width:80, hidden:false, align :'left'}
				,{name:'r9',index:'r9', width:120, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_prod_car_line_tbl_detail")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
				,{name:'r10',index:'r10', width:80, hidden:false, align :'left'}

				,{name:'r11',index:'r11', width:80, hidden:true, align :'right'}
				,{name:'r_s',index:'r_s', width:80, hidden:true, align :'right'}

				],
				rowNum:100,
				rowList:[10,20,30,50,100,200,500],
				pager: '#pms_prod_car_line_tbl_detail',
				sortname: 'r1',
				viewrecords: true,
				rownumbers: false,
				sortorder: "desc",
				width: '',
				height: 240, 
				//height:300,
				jsonReader: { repeatitems : false },
				rownumbers: true,
				loadonce: false,
				shrinkToFit: false,
				multiselect: false,
				scrollrows:true,
				ondblClickRow: function (rowid) {
					ms_prod_car_line_edit_row_detail_select=$("#ms_prod_car_line_tbl_detail").getRowData(rowid);
						if (rowid){ 
							if  (ms_prod_car_line_edit_row_detail_mode_aktifitas==-1){
								ms_prod_car_line_edit_row_detail_check_row(ms_prod_car_line_edit_row_detail_select); 
								if (rowid){
											$("#ms_prod_car_line_supply_lifo").removeClass('ui-state-disabled');
											$("#ms_prod_car_line_supply_fifo").removeClass('ui-state-disabled'); 
								}
							}else{  
								ms_prod_car_line_edit_row_detail_action(-1);
								$("#ms_prod_car_line_supply_lifo").removeClass('ui-state-disabled');
								$("#ms_prod_car_line_supply_fifo").removeClass('ui-state-disabled'); 
							
							}	
						 		$("#ms_prod_car_line_edit_tab" ).tabs("select", 1);   
						}
						else
						{
							$("#ms_prod_car_line_supply_lifo").addClass('ui-state-disabled');
							$("#ms_prod_car_line_supply_fifo").addClass('ui-state-disabled');  
						}
				},
				onSelectRow: function (rowid) { 
					ms_prod_car_line_edit_row_detail_select=$("#ms_prod_car_line_tbl_detail").getRowData(rowid);
					if  (ms_prod_car_line_edit_row_detail_mode_aktifitas==-1){
						ms_prod_car_line_edit_row_detail_check_row(ms_prod_car_line_edit_row_detail_select); 
						if (rowid){
									$("#ms_prod_car_line_supply_lifo").removeClass('ui-state-disabled');
									$("#ms_prod_car_line_supply_fifo").removeClass('ui-state-disabled'); 
						}else{
										$("#ms_prod_car_line_supply_lifo").addClass('ui-state-disabled');
										$("#ms_prod_car_line_supply_fifo").addClass('ui-state-disabled');  
						}
					}
				
			
				},
				loadComplete: function () {
				
					},
				gridComplete: function () {
						if (ms_prod_car_line_edit_row_detail_select ){
							jQuery('#ms_prod_car_line_tbl_detail').jqGrid('setSelection',''+ ms_prod_car_line_edit_row_detail_select.rID + '');
						}
							 
						var rowIDs = jQuery("#ms_prod_car_line_tbl_detail").getDataIDs(); 
						var rowData = $("#ms_prod_car_line_tbl_detail").getRowData(); 
						for (var i = 0; i < rowData.length; i++) 
						{
						   var trElement = jQuery("#"+ rowIDs[i],jQuery('#ms_prod_car_line_tbl_detail'));
						   
							switch (rowData[i].r_s) {
								case '1':
								   trElement.css({"color":"red"});
								break;
								case '2':
								   trElement.css({"color":"blue"});
								break;
								
							}
						}
					 

					// var objRows = $("#ms_prod_car_line_tbl_detail tr"); 
					// var objHeader = $("#ms_prod_car_line_tbl_detail .jqgfirstrow td"); 

					// if (objRows.length > 1) { 
					// var objFirstRowColumns = $(objRows[1]).children("td"); 
					// for (i = 0; i < objFirstRowColumns.length; i++) { 
					// $(objFirstRowColumns[i]).css("width", $(objHeader[i]).css("width")); 
					// } 
					// } 
				},
				
		});
		jQuery("#ms_prod_car_line_tbl_detail").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		jQuery("#ms_prod_car_line_tbl_detail").jqGrid('navGrid','#pms_prod_car_line_tbl_detail',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false})
 		.navSeparatorAdd('#pms_prod_car_line_tbl_detail',{
		   caption:"<b>ALL</b>", 
		   buttonicon:"none",
		   position:"last"
		}).navButtonAdd('#pms_prod_car_line_tbl_detail',{
		   caption:"<b>FIFO</b>", 
		   buttonicon:"none", 
		   id :"ms_prod_car_line_supply_fifo",
		   onClickButton: function(){ 
				
			 var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				Auto supply FIFO ? <br /><br />\
				<label><input name="ms_prod_car_line_auto_supply_renew" type="checkbox" id="ms_prod_car_line_auto_supply_renew" value=\'Yes\' offval=\'No\' />\
								 Renew Supply ?</label><br />\
				</div>')
				 .dialog({
					modal:true,
					width : 500,
					height : 200,
					title :'AUTO SUPPLY (FIFO)',
					buttons: {
						"CLOSE": function(){
							$dialog.dialog("close");  
						} ,
						
						"SUPPLY": function(){ 
						
								var form_edit = {      
										detail_id		:ms_prod_car_line_edit_row_detail_select.rID ,
										mode_supply  : 0 , 
							 			renew_supply 	: $('#ms_prod_car_line_auto_supply_renew').is(':checked')==true?'1':'0'
 									};  
								
								$.ajax({    
								url:'<?php echo base_url().'ms_production/ct_ms_prod_car_line//auto_supply'; ?>',
								type : 'POST',
									data : form_edit,
									dataType: 'json',
									success: function(msg){
										if (msg.valid){
											alert(msg.stsmsg);  
											$dialog.dialog("close");  
											$('#ms_prod_car_line_tbl_detail').trigger('reloadGrid');
										} else { alert(msg.stsno+msg.stsmsg);  }
										} 
								});
								 
						} , 
					},
					close : function(){
						$dialog.dialog('destroy').remove();
					},
					open: function(){  
					 
						$("body").unblock(); 
					}
				}); 
		   }, 
		   position:"last"
		}).navSeparatorAdd('#pms_prod_car_line_tbl_detail',{
		   caption:"<b>ALL</b>", 
		   buttonicon:"none",
		   position:"last"
		}).navButtonAdd('#pms_prod_car_line_tbl_detail',{
		   caption:"<b>LIFO</b>", 
		   buttonicon:"none", 
		   id :"ms_prod_car_line_supply_lifo",
		   onClickButton: function(){ 
				
			 var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				Auto supply LIFO ? <br /><br />\
				<label><input name="ms_prod_car_line_auto_supply_renew" type="checkbox" id="ms_prod_car_line_auto_supply_renew" value=\'Yes\' offval=\'No\' />\
								 Renew Supply ?</label><br />\
				</div>')
				 .dialog({
					modal:true,
					width : 500,
					height : 200,
					title :'AUTO SUPPLY (LIFO)',
					buttons: {
						"CLOSE": function(){
							$dialog.dialog("close");  
						} ,
						
						"SUPPLY": function(){ 
						
								var form_edit = {      
										detail_id		:ms_prod_car_line_edit_row_detail_select.rID ,
										mode_supply  : 1 , 
							 			renew_supply 	: $('#ms_prod_car_line_auto_supply_renew').is(':checked')==true?'1':'0'
 									};  
								
								$.ajax({    
								url:'<?php echo base_url().'ms_production/ct_ms_prod_car_line//auto_supply'; ?>',
								type : 'POST',
									data : form_edit,
									dataType: 'json',
									success: function(msg){
										if (msg.valid){
											alert(msg.stsmsg);  
											$dialog.dialog("close");  
											$('#ms_prod_car_line_tbl_detail').trigger('reloadGrid');
										} else { alert(msg.stsno+msg.stsmsg);  }
										} 
								});
								 
						} , 
					},
					close : function(){
						$dialog.dialog('destroy').remove();
					},
					open: function(){  
					 
						$("body").unblock(); 
					}
				}); 
		   }, 
		   position:"last"
		}).navSeparatorAdd('#pms_prod_car_line_tbl_detail',{
		   caption:"<b>ALL</b>", 
		   buttonicon:"none",
		   position:"last"
		}).navButtonAdd('#pms_prod_car_line_tbl_detail',{
		   caption:"<b>FIFO ALL</b>", 
		   buttonicon:"none", 
		   onClickButton: function(){ 
			 
			 var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				Auto supply FIFO ? <br /><br />\
				<label><input name="ms_prod_car_line_auto_supply_renew" type="checkbox" id="ms_prod_car_line_auto_supply_renew" value=\'Yes\' offval=\'No\' />\
								 Renew Supply ?</label><br />\
				</div>')
				 .dialog({
					modal:true,
					width : 500,
					height : 200,
					title :'AUTO SUPPLY ALL (FIFO)',
					buttons: {
						"CLOSE": function(){
							$dialog.dialog("close");  
						} ,
						
						"SUPPLY": function(){ 
						
								var form_edit = {      
										header_id		:(!ms_prod_car_line_edit_row_header)?'-1':ms_prod_car_line_edit_row_header.rID, 
					 					mode_supply  : 0 , 
							 			renew_supply 	: $('#ms_prod_car_line_auto_supply_renew').is(':checked')==true?'1':'0'
 									};  
								
								$.ajax({    
								url:'<?php echo base_url().'ms_production/ct_ms_prod_car_line//auto_supply_all'; ?>',
								type : 'POST',
									data : form_edit,
									dataType: 'json',
									success: function(msg){
										if (msg.valid){
											alert(msg.stsmsg);  
											$dialog.dialog("close");  
											$('#ms_prod_car_line_tbl_detail').trigger('reloadGrid');
										} else { alert(msg.stsno+msg.stsmsg);  }
										} 
								});
								 
						} , 
					},
					close : function(){
						$dialog.dialog('destroy').remove();
					},
					open: function(){  
					 
						$("body").unblock(); 
					}
				}); 
		   }, 
		   position:"last"
		}).navSeparatorAdd('#pms_prod_car_line_tbl_detail',{
		   caption:"<b>ALL</b>", 
		   buttonicon:"none",
		   position:"last"
		}).navButtonAdd('#pms_prod_car_line_tbl_detail',{
		   caption:"<b>LIFO ALL</b>", 
		   buttonicon:"none", 
		   onClickButton: function(){ 
				
			 var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				Auto supply FIFO ? <br /><br />\
				<label><input name="ms_prod_car_line_auto_supply_renew" type="checkbox" id="ms_prod_car_line_auto_supply_renew" value=\'Yes\' offval=\'No\' />\
								 Renew Supply ?</label><br />\
				</div>')
				 .dialog({
					modal:true,
					width : 500,
					height : 200,
					title :'AUTO SUPPLY ALL (LIFO)',
					buttons: {
						"CLOSE": function(){
							$dialog.dialog("close");  
						} ,
						
						"SUPPLY": function(){ 
						
								var form_edit = {      
										header_id		:(!ms_prod_car_line_edit_row_header)?'-1':ms_prod_car_line_edit_row_header.rID, 
					 					mode_supply  : 1 , 
							 			renew_supply 	: $('#ms_prod_car_line_auto_supply_renew').is(':checked')==true?'1':'0'
 									};  
								
								$.ajax({    
								url:'<?php echo base_url().'ms_production/ct_ms_prod_car_line//auto_supply_all'; ?>',
								type : 'POST',
									data : form_edit,
									dataType: 'json',
									success: function(msg){
										if (msg.valid){
											alert(msg.stsmsg);  
											$dialog.dialog("close");  
											$('#ms_prod_car_line_tbl_detail').trigger('reloadGrid');
										} else { alert(msg.stsno+msg.stsmsg);  }
										} 
								});
								 
						} , 
					},
					close : function(){
						$dialog.dialog('destroy').remove();
					},
					open: function(){  
					 
						$("body").unblock(); 
					}
				}); 
		   }, 
		   position:"last"
		}).navSeparatorAdd('#pms_prod_car_line_tbl_detail',{
		   caption:"<b>ALL</b>", 
		   buttonicon:"none",
		   position:"last"
		});
		 
		 
	    refreshPagger("ms_prod_car_line_tbl_detail","pms_prod_car_line_tbl_detail");
		setGridHight(jQuery("#ms_prod_car_line_tbl_detail"),jQuery("#container_ms_prod_car_line_edit_tab"),jQuery("#ms_prod_car_line_edit_panel_action"),jQuery("#ms_prod_car_line_edit_panel_action_result").height() +  jQuery("#container_ms_prod_car_line_edit_tab ul").first().height() +30)
	 
	
	    // $("#ms_prod_car_line_supply_lifo").removeClass('ui-state-disabled');
		// $("#ms_prod_car_line_supply_fifo").removeClass('ui-state-disabled');
		  $("#ms_prod_car_line_supply_lifo").addClass('ui-state-disabled');
		  $("#ms_prod_car_line_supply_fifo").addClass('ui-state-disabled');

		var ms_prod_car_line_trigger_from_stock=0;
		var ms_prod_car_line_trigger_from_supply=0;
		
	
		function check_data_ms_prod_car_line_tbl_stock(rowid){ 
					ms_prod_car_line_trigger_from_stock=1; 
					if (rowid){
						ms_prod_car_line_edit_row_stock_select=$("#ms_prod_car_line_tbl_stock").getRowData(rowid); 
						
						if (ms_prod_car_line_trigger_from_supply==0){
								    jQuery("#ms_prod_car_line_tbl_supply").jqGrid('resetSelection');
									jQuery("#ms_prod_car_line_tbl_supply").jqGrid('setSelection', ms_prod_car_line_edit_row_stock_select.r_uid);
 						}
						
						check_data_ms_prod_car_line_tbl_stock2(ms_prod_car_line_edit_row_stock_select);
						
					}
					
					ms_prod_car_line_trigger_from_stock=0;
		};
		
		function check_data_ms_prod_car_line_tbl_stock2(row){ 
			if(row){ 
			   $("#ms_prod_car_line_edit_supply_ms_item_in_detail_id").val(row.rID);  
			   $("#ms_prod_car_line_edit_supply_source_name").val(row.r4);  
			   $("#ms_prod_car_line_edit_supply_source_doc_no").val(row.r6); 
			   $("#ms_prod_car_line_edit_supply_source_doc_date").val(row.r7); 
			   $("#ms_prod_car_line_edit_supply_source_receive_no").val(row.r8); 
			   $("#ms_prod_car_line_edit_supply_source_receive_date").val(row.r9); 
			    $( "#ms_prod_car_line_action_supply_save" ).button( "option", "disabled",false );
		    	$( "#ms_prod_car_line_action_supply_delete" ).button( "option", "disabled",false );			
				$( "#ms_prod_car_line_action_supply_equal_less" ).button( "option", "disabled",false );	
			   if (row.r_u=='1'){  
					$("#ms_prod_car_line_edit_supply_ms_item_out_detail_id").val(row.r_uid); 
					$( "#ms_prod_car_line_action_supply_save" ).find('span').text("Update");  
					$("#ms_prod_car_line_edit_supply_total_edit").val(row.r_uq); 
					$("#ms_prod_car_line_edit_supply_source_available").val(row.r_ua ); 
				}else{ 
					$( "#ms_prod_car_line_action_supply_save" ).find('span').text("Add"); 
					$("#ms_prod_car_line_edit_supply_total_edit").val(row.r12); 
					$("#ms_prod_car_line_edit_supply_source_available").val(row.r12); 
					$("#ms_prod_car_line_edit_supply_ms_item_out_detail_id").val('-1'); 
				  } 
			}else{
				 $("#ms_prod_car_line_edit_supply_ms_item_in_detail_id").val('-1');  
				 $("#ms_prod_car_line_edit_supply_ms_item_out_detail_id").val('-1'); ;
			} 
		};
		
		
		jQuery("#ms_prod_car_line_tbl_stock").jqGrid({
			url:'<?php echo base_url().'ms_production/ct_ms_prod_car_line/loaddata_source_available'; ?>',
			mtype : "post",
			postData:{'a':'a'},
			datatype: "local",
			colNames:[
			'dt_ms_item_in_detail_ms_in_item_detail_id','dt_ms_item_in_detail_mode_source','mode_source_name','mode_source_2','FROM','RECEIVE NO' ,'RECEIVE DATE','DOC NO'
			,'DOC DATE','UOM','QTY','CAR \\ INFO','status_id'
			,'dt_ms_item_in_detail_quantity_pakai','qty_out','qty_plan','car_line_out'
			,'memo_out','car_line_plan','memo_plan','dt_ms_item_ms_type_id','dt_ms_item_ms_item_custom_no'
			,'dt_ms_item_ms_item_base_no','dt_ms_item_part_no','dt_ms_item_part_name','dt_ms_item_in_detail_ori_ms_in_item_detail_id'
			,'dt_ms_item_in_detail_id_source_header','r_s','r_u','r_uq','r_ua','r_uid'
			]
			,colModel:[
			{name:'rID',index:'rID', width:80, hidden:true, align :'right', key:true}
			,{name:'r1',index:'r1', width:80, hidden:true, align :'right'}
			,{name:'r2',index:'r2', width:80, hidden:true, align :'right'}
			,{name:'r3',index:'r3', width:80, hidden:true, align :'right'}
			,{name:'r4',index:'r4', width:80, hidden:false, align :'left'}
	 		,{name:'r8',index:'r8', width:150, hidden:false, align :'left'}
			
			,{name:'r9',index:'r9', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_prod_car_line_tbl_stock")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
			,{name:'r6',index:'r6', width:80, hidden:false, align :'left'}
			
			,{name:'r7',index:'r7', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_prod_car_line_tbl_stock")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
			,{name:'r24',index:'r24', width:40, hidden:false, align :'left'}
			,{name:'r12',index:'r12', width:80, hidden:false, align :'right'}
			,{name:'r5',index:'r5', width:300, hidden:false, align :'left'}
			,{name:'r10',index:'r10', width:80, hidden:true, align :'right'}

			,{name:'r11',index:'r11', width:80, hidden:true, align :'right'}
			,{name:'r13',index:'r13', width:80, hidden:true, align :'right'}
			,{name:'r14',index:'r14', width:80, hidden:true, align :'right'}
			,{name:'r15',index:'r15', width:80, hidden:true, align :'right'}

			,{name:'r16',index:'r16', width:80, hidden:true, align :'right'}
			,{name:'r17',index:'r17', width:80, hidden:true, align :'right'}
			,{name:'r18',index:'r18', width:80, hidden:true, align :'right'}
			,{name:'r19',index:'r19', width:80, hidden:true, align :'right'}
			,{name:'r20',index:'r20', width:80, hidden:true, align :'right'}

			,{name:'r21',index:'r21', width:80, hidden:true, align :'right'}
			,{name:'r22',index:'r22', width:80, hidden:true, align :'right'}
			,{name:'r23',index:'r23', width:80, hidden:true, align :'right'}
			,{name:'r25',index:'r25', width:80, hidden:true, align :'right'}

			,{name:'r26',index:'r26', width:80, hidden:true, align :'right'}
			,{name:'r_s',index:'r_s', width:80, hidden:true, align :'right'}
			,{name:'r_u',index:'r_u', width:80, hidden:true, align :'right'}
			,{name:'r_uq',index:'r_uq', width:80, hidden:true, align :'right'}
			,{name:'r_ua',index:'r_ua', width:80, hidden:true, align :'right'}
			,{name:'r_uid',index:'r_uid', width:80, hidden:true, align :'right'}

			],
				rowNum:100,
				rowList:[10,20,30,50,100,200,500],
				pager: '#pms_prod_car_line_tbl_stock',
				sortname: 'r1',
				viewrecords: true,
				sortorder: "desc",
				width: '',
				height: 130,
				//width: 950,
				//height:300,
				caption:'.: SOURCE AVAILABE   <span id=\'ms_prod_car_line_tbl_stock_info\' style=\'color:blue\'></span>',
				rownumbers: true,
				jsonReader: { repeatitems : false },
				rownumbers: true,
				//loadonce: true,
				shrinkToFit: false,
				multiselect: false,
				//scrollrows:true,
				ondblClickRow: function (rowid) {
						check_data_ms_prod_car_line_tbl_stock(rowid)
						// if  (ms_prod_car_line_edit_row_detail_mode_aktifitas==-1){
						// ms_prod_car_line_edit_row_detail_check_row(ms_prod_car_line_edit_row_stock_select); 
					// } 
				},
				onSelectRow: function (rowid) { 
						check_data_ms_prod_car_line_tbl_stock(rowid)
				},
				loadComplete: function (data) {
								var udata = $("#ms_prod_car_line_tbl_stock").getGridParam('userData'); 
								$("#ms_prod_car_line_edit_supply_total_available").val(udata.total_avialable==null?'0':udata.total_avialable);  
								$("#ms_prod_car_line_edit_supply_total_qty").val(udata.total_quantity==null?'0':udata.total_quantity );  
								$("#ms_prod_car_line_edit_supply_total_supply").val(udata.total_supply==null?'0':udata.total_supply);    
								$("#ms_prod_car_line_edit_supply_total_less").val(udata.total_less==null?'0':udata.total_less);    
								
								if (jQuery("#ms_prod_car_line_tbl_stock").jqGrid('getGridParam', 'data').length==0){
									ms_prod_car_line_edit_row_stock_select=null;
								}
							
				},
				gridComplete: function () {
						if (ms_prod_car_line_edit_row_stock_select ){
							jQuery('#ms_prod_car_line_tbl_stock').jqGrid('setSelection',''+ ms_prod_car_line_edit_row_stock_select.rID + '');
						}
						
						var rowIDs = jQuery("#ms_prod_car_line_tbl_stock").getDataIDs(); 
						var rowData = $("#ms_prod_car_line_tbl_stock").getRowData(); 
						for (var i = 0; i < rowData.length; i++) 
						{
						   var trElement = jQuery("#"+ rowIDs[i],jQuery('#ms_prod_car_line_tbl_stock'));
						   
							switch (rowData[i].r_s) {
								case '0':
								   trElement.css({"color":"red"});
								break;
								
							}
						}
				},
		}); 
	        
			
		jQuery("#ms_prod_car_line_tbl_stock").jqGrid('navGrid','#pms_prod_car_line_tbl_stock',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#ms_prod_car_line_tbl_stock").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
		
		
		 	    
		 	   
		$('#ms_prod_car_line_action_supply_fifo').button().click(function () { 
		
			 var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				Auto supply FIFO ? <br /><br />\
				<label><input name="ms_prod_car_line_auto_supply_renew" type="checkbox" id="ms_prod_car_line_auto_supply_renew" value=\'Yes\' offval=\'No\' />\
								 Renew Supply ?</label><br />\
				</div>')
				 .dialog({
					modal:true,
					width : 500,
					height : 200,
					title :'AUTO SUPPLY ALL (LIFO)',
					buttons: {
						"CLOSE": function(){
							$dialog.dialog("close");  
						} ,
						
						"SUPPLY": function(){ 
						
								var form_edit = {      
										header_id		:(!ms_prod_car_line_edit_row_header)?'-1':ms_prod_car_line_edit_row_header.rID, 
					 					mode_supply  : 0 , 
							 			renew_supply 	: $('#ms_prod_car_line_auto_supply_renew').is(':checked')==true?'1':'0'
 									};  
								
								$.ajax({    
								url:'<?php echo base_url().'ms_production/ct_ms_prod_car_line//auto_supply_all'; ?>',
								type : 'POST',
									data : form_edit,
									dataType: 'json',
									success: function(msg){
										if (msg.valid){
											alert(msg.stsmsg);  
											$dialog.dialog("close");  
										$("#ms_prod_car_line_tbl_supply").trigger("reloadGrid"); 
										$("#ms_prod_car_line_tbl_stock").trigger("reloadGrid");
									} else { alert(msg.stsno+msg.stsmsg);  }
										} 
								});
								 
						} , 
					},
					close : function(){
						$dialog.dialog('destroy').remove();
					},
					open: function(){  
					 
						$("body").unblock(); 
					}
				}); 
		}); 

		$('#ms_prod_car_line_action_supply_lifo').button().click(function () { 
		
			 var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				Auto supply FIFO ? <br /><br />\
				<label><input name="ms_prod_car_line_auto_supply_renew" type="checkbox" id="ms_prod_car_line_auto_supply_renew" value=\'Yes\' offval=\'No\' />\
								 Renew Supply ?</label><br />\
				</div>')
				 .dialog({
					modal:true,
					width : 500,
					height : 200,
					title :'AUTO SUPPLY ALL (LIFO)',
					buttons: {
						"CLOSE": function(){
							$dialog.dialog("close");  
						} ,
						
						"SUPPLY": function(){ 
						
								var form_edit = {      
										header_id		:(!ms_prod_car_line_edit_row_header)?'-1':ms_prod_car_line_edit_row_header.rID, 
					 					mode_supply  : 1 , 
							 			renew_supply 	: $('#ms_prod_car_line_auto_supply_renew').is(':checked')==true?'1':'0'
 									};  
								
								$.ajax({    
								url:'<?php echo base_url().'ms_production/ct_ms_prod_car_line//auto_supply_all'; ?>',
								type : 'POST',
									data : form_edit,
									dataType: 'json',
									success: function(msg){
										if (msg.valid){
											alert(msg.stsmsg);  
											$dialog.dialog("close");  
									$("#ms_prod_car_line_tbl_supply").trigger("reloadGrid"); 
									$("#ms_prod_car_line_tbl_stock").trigger("reloadGrid");
										} else { alert(msg.stsno+msg.stsmsg);  }
										} 
								});
								 
						} , 
					},
					close : function(){
						$dialog.dialog('destroy').remove();
					},
					open: function(){  
					 
						$("body").unblock(); 
					}
				}); 
		}); 

		$('#ms_prod_car_line_action_supply_save').button().click(function () {  
	 
					var form_edit = {
							 ms_car_line_out_detail_id		:(!ms_prod_car_line_edit_row_detail_select)?'-1':ms_prod_car_line_edit_row_detail_select.rID
							,ms_item_out_detail_id			:$('#ms_prod_car_line_edit_supply_ms_item_out_detail_id').val()
							,ms_in_item_detail_id		: $('#ms_prod_car_line_edit_supply_ms_item_in_detail_id').val()
							,qty		:$('#ms_prod_car_line_edit_supply_total_edit').val() 
					};  
					var	_url_target='<?php echo base_url().'ms_production/ct_ms_prod_car_line/save_supply'; ?>';
		 
					$('#ms_prod_car_line_action_supply_save').button( "option", "disabled",true );;
					$.ajax({    
					url:_url_target,
					type : 'POST',
					data : form_edit,
					dataType: 'json',
					success: function(msg){
							if (msg.valid){  
									$("#ms_prod_car_line_tbl_supply").trigger("reloadGrid"); 
									$("#ms_prod_car_line_tbl_stock").trigger("reloadGrid");
									ms_prod_car_line_edit_after_supply_action=true;
									
							} else { 
								alert(msg.stsno+msg.stsmsg);    
							}
						} 
					}).always(function() {
						$('#ms_prod_car_line_action_supply_save').button( "option", "disabled", false );;
					});  
		
		
		}); 

		$('#ms_prod_car_line_action_supply_delete').button().click(function () {  
				if(!ms_prod_car_line_edit_row_supply_select){ alert("Pililh supply yang akan di hapus");exit;}    
				
					var $dialog =  $('<div />')
				.html(' <div class="ui-layout-content ui-widget-content-panel" style="margin-top:10px"> \
				Hapus Supply? <br /><br />\
 				</div>')
			  .dialog({
				modal:true,
				width : 500,
				height : 200,
				title :'HAPUS SUPPLY ',
				buttons: {
					"CLOSE": function(){
						$dialog.dialog("close");  
					} ,
					
					"HAPUS": function(){  
				 			var form_edit = {
							 ms_car_line_out_detail_id		:(!ms_prod_car_line_edit_row_detail_select)?'-1':ms_prod_car_line_edit_row_detail_select.rID
							,ms_item_out_detail_id			: ms_prod_car_line_edit_row_supply_select.rID
							,ms_in_item_detail_id		: $('#ms_prod_car_line_edit_supply_ms_item_in_detail_id').val() 
							};  
							var	_url_target='<?php echo base_url().'ms_production/ct_ms_prod_car_line/delete_supply'; ?>';
				 
							$('#ms_prod_car_line_action_supply_delete').button( "option", "disabled",true ); 
							$.ajax({    
							url:_url_target,
							type : 'POST',
							data : form_edit,
							dataType: 'json',
							success: function(msg){
									if (msg.valid){  
											ms_prod_car_line_edit_after_supply_action=true;
											ms_prod_car_line_edit_row_supply_select=null; 
											$("#ms_prod_car_line_edit_supply_ms_item_in_detail_id").val('-1');  
											$("#ms_prod_car_line_edit_supply_ms_item_out_detail_id").val('-1');  
											$("#ms_prod_car_line_tbl_supply").trigger("reloadGrid"); 
											$("#ms_prod_car_line_tbl_stock").trigger("reloadGrid"); 
 						
										   $('#ms_prod_car_line_edit_dtl_edit').button( "option", "disabled",true );
										   $('#ms_prod_car_line_edit_dtl_delete').button( "option", "disabled",true );
										   
										   $("#ms_prod_car_line_edit_dtl_ms_item_id").val(""); 
										   $("#ms_prod_car_line_edit_dtl_part_no").val(""); 
										   $("#ms_prod_car_line_edit_dtl_part_name").val(""); 
										   $("#ms_prod_car_line_edit_dtl_part_uom").val(""); 
										   $("#ms_prod_car_line_edit_dtl_rack").val("");
										   $("#ms_prod_car_line_edit_dtl_part_qty").val("");
										   $("#ms_prod_car_line_edit_dtl_part_base_no").val("");
										   
											 check_data_ms_prod_car_line_tbl_stock2(ms_prod_car_line_edit_row_stock_select);
										 
											$dialog.dialog("close");  
								
									} else { 
										alert(msg.stsno+msg.stsmsg);    
										$dialog.dialog("close");  
									}
								} 
							}).always(function() {
								$('#ms_prod_car_line_action_supply_delete').button( "option", "disabled", false );;
							});  
							 
					} , 
				},
				close : function(){
					$dialog.dialog('destroy').remove();
			 	},
				open: function(){  
					$("body").unblock(); 
				}
			}); 
		
		
		
		}); 
		$('#ms_prod_car_line_action_supply_equal_less').button().click(function () { 
		
				var sisa_bahan		= parseFloat($('#ms_prod_car_line_edit_supply_source_available').val());
				var kurang_bahan 	= parseFloat($('#ms_prod_car_line_edit_supply_total_less').val()); 
				console.log(sisa_bahan);
				if ( kurang_bahan > 0)
				{ 
					if (kurang_bahan>=sisa_bahan){
							$("#ms_prod_car_line_edit_supply_total_edit").val(sisa_bahan);	
					}else{
							$("#ms_prod_car_line_edit_supply_total_edit").val(kurang_bahan);	
					}
				}	  
				else
				{
					alert ('Supply sudah penuh');
				}
				
				
				
				return false;
			
		}); 
		
			
		function check_data_ms_prod_car_line_tbl_supply(rowid){ 
					ms_prod_car_line_trigger_from_supply=1; 
					if (rowid){
						ms_prod_car_line_edit_row_supply_select=$("#ms_prod_car_line_tbl_supply").getRowData(rowid); 
						
						if (ms_prod_car_line_trigger_from_stock==0){    
									jQuery("#ms_prod_car_line_tbl_stock").jqGrid('resetSelection'); 
									jQuery("#ms_prod_car_line_tbl_stock").jqGrid('setSelection', ms_prod_car_line_edit_row_supply_select.r_in);
 						}
						
						check_data_ms_prod_car_line_tbl_supply2(ms_prod_car_line_edit_row_supply_select)
						
						
					}
					ms_prod_car_line_trigger_from_supply=0;
		};
		
		function check_data_ms_prod_car_line_tbl_supply2(row){ 
		
					if(row){ 
					$("#ms_prod_car_line_edit_supply_ms_item_in_detail_id").val(row.r_in);  
					$("#ms_prod_car_line_edit_supply_source_name").val(row.r4);  
					$("#ms_prod_car_line_edit_supply_source_doc_no").val(row.r6); 
					$("#ms_prod_car_line_edit_supply_source_doc_date").val(row.r7); 
					$("#ms_prod_car_line_edit_supply_source_receive_no").val(row.r8); 
					$("#ms_prod_car_line_edit_supply_source_receive_date").val(row.r9);  
					$("#ms_prod_car_line_edit_supply_ms_item_out_detail_id").val(row.rID); 
					$("#ms_prod_car_line_edit_supply_source_available").val(row.r_ua ); 
					$( "#ms_prod_car_line_action_supply_save" ).find('span').text("Update");  
					$("#ms_prod_car_line_edit_supply_total_edit").val(row.r11);  
					$( "#ms_prod_car_line_action_supply_save" ).button( "option", "disabled",false );
					$( "#ms_prod_car_line_action_supply_delete" ).button( "option", "disabled",false );	
					$( "#ms_prod_car_line_action_supply_equal_less" ).button( "option", "disabled",false );	
				
					}else{
						 $("#ms_prod_car_line_edit_supply_ms_item_in_detail_id").val('-1');  
						 $("#ms_prod_car_line_edit_supply_ms_item_out_detail_id").val('-1');  
					} 
		}
		
		jQuery("#ms_prod_car_line_tbl_supply").jqGrid({
			url:'<?php echo base_url().'ms_production/ct_ms_prod_car_line/loaddata_detail_supply'; ?>',
			mtype : "post",
			postData:{'a':'a'},
			datatype: "local",
			colNames:[
			'FROM','RECEIVE NO','RECEIVE DATE','DOC NO'
			,'DOC DATE','UOM','QTY','CAR \\ INFO','status_id'
			,'dt_ms_item_ms_type_id','dt_ms_item_ms_item_custom_no','dt_ms_item_ms_item_base_no','dt_ms_item_part_no'
			,'dt_ms_item_part_name','dt_ms_item_in_detail_ori_ms_in_item_detail_id','dt_ms_item_in_detail_id_source_header_in','dt_ms_item_out_detail_id_source_header_out'
			,'dt_ms_item_in_detail_ms_item_id','ms_in_item_detail_id',
			'dt_ms_item_out_detail_ms_item_out_detail_id','dt_ms_item_in_detail_mode_source','enum_ms_mode_source_item_in_detail_mode_source_name','mode_source_2','r_ua','r_s'
			]
			
			
			,colModel:[
			{name:'r4',index:'r4', width:80, hidden:false, align :'left'} 
			,{name:'r8',index:'r8', width:150, hidden:false, align :'left'}
			
			,{name:'r9',index:'r9', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_prod_car_line_tbl_supply")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
			,{name:'r6',index:'r6', width:80, hidden:false, align :'left'}
			
			,{name:'r7',index:'r7', width:80, hidden:false, align :'left', searchoptions:{searchhidden: true,dataInit:function(el){$(el).datepicker({onSelect: function(date){jQuery("#ms_prod_car_line_tbl_supply")[0].triggerToolbar();},changeMonth: true,changeYear: true,dateFormat:'dd/mm/yy', showButtonPanel: true, beforeShow: function(input) {  setTimeout(function() { var buttonPane = $(input).datepicker("widget").find( ".ui-datepicker-buttonpane" );   var btn = $('<button class="ui-datepicker-current ui-state-default ui-priority-secondary ui-corner-all" type="button">Clear</button>');   btn.unbind("click").bind("click", function () {   $.datepicker._clearDate( input );   });   btn.appendTo( buttonPane );  }, 1 );  }  });}}}
			,{name:'r17',index:'r17', width:40, hidden:false, align :'right'} 
			
			,{name:'r11',index:'r11', width:80, hidden:false, align :'right'}
			,{name:'r5',index:'r5', width:300, hidden:false, align :'right'}
			,{name:'r10',index:'r10', width:80, hidden:true, align :'right'} 
			,{name:'r12',index:'r12', width:80, hidden:true, align :'right'}
			,{name:'r13',index:'r13', width:80, hidden:true, align :'right'}
			,{name:'r14',index:'r14', width:80, hidden:true, align :'right'}
			,{name:'r15',index:'r15', width:80, hidden:true, align :'right'}

			,{name:'r16',index:'r16', width:80, hidden:true, align :'right'}
			,{name:'r18',index:'r18', width:80, hidden:true, align :'right'}
			,{name:'r19',index:'r19', width:80, hidden:true, align :'right'}
			,{name:'r20',index:'r20', width:80, hidden:true, align :'right'}

			,{name:'r21',index:'r21', width:80, hidden:true, align :'right'}
			,{name:'r_in',index:'r_in', width:80, hidden:true, align :'right'}
			,{name:'rID',index:'rID', width:80, hidden:true, align :'right', key:true}
			,{name:'r1',index:'r1', width:80, hidden:true, align :'right'}
			,{name:'r2',index:'r2', width:80, hidden:true, align :'right'}
			,{name:'r3',index:'r3', width:80, hidden:true, align :'right'}
			,{name:'r_ua',index:'r_ua', width:80, hidden:true, align :'right'}
			,{name:'r_s',index:'r_s', width:80, hidden:true, align :'right'}
			,
			],
			rowNum:100,
			rowList:[10,20,30,50,100,200,500],
			pager: '#pms_prod_car_line_tbl_supply',
			sortname: 'r1',
			viewrecords: true,
			sortorder: "desc",
			width: '',
			height: 85,
			//width: 950,
			//height:300,
			caption:".: SUPPLY LIST",
			jsonReader: { repeatitems : false },
			rownumbers: true,
			//loadonce: true,
			shrinkToFit: false,
			multiselect: false,
			//scrollrows:true,
			ondblClickRow: function (rowid) {
			 	check_data_ms_prod_car_line_tbl_supply(rowid);
					 
			},
			onSelectRow: function (rowid) { 
				check_data_ms_prod_car_line_tbl_supply(rowid);
			},
			loadComplete: function (data) { 
								if (jQuery("#ms_prod_car_line_tbl_supply").jqGrid('getGridParam', 'records')==0){
									ms_prod_car_line_edit_row_supply_select=null;
								}
			},
			gridComplete: function () {
					if (ms_prod_car_line_edit_row_supply_select ){
						jQuery('#ms_prod_car_line_tbl_supply').jqGrid('setSelection',''+ ms_prod_car_line_edit_row_supply_select.rID + '');
					}	
					var rowIDs = jQuery("#ms_prod_car_line_tbl_supply").getDataIDs(); 
					
					var rowData = $("#ms_prod_car_line_tbl_supply").getRowData(); 
					for (var i = 0; i < rowData.length; i++) 
					{
					   var trElement = jQuery("#"+ rowIDs[i],jQuery('#ms_prod_car_line_tbl_supply'));
					   
						switch (rowData[i].r_s) {
							case '0':
							   trElement.css({"color":"red"});
							break;
							
						}
					}
			},
		}); 
	        
		 
		jQuery("#ms_prod_car_line_tbl_supply").jqGrid('navGrid','#pms_prod_car_line_tbl_supply',{del:false,add:false,edit:false},{},{},{},{multipleSearch:false});
		jQuery("#ms_prod_car_line_tbl_supply").jqGrid('filterToolbar',{stringResult: true,searchOnEnter : true, defaultSearch: 'cn', ignoreCase: true});
	
		 
		 
	$("#ms_prod_car_line_edit_dtl_part_no").mcautocomplete({
			// These next two options are what this plugin adds to the autocomplete widget.
			showHeader: true,
			 classes: {
						"ui-autocomplete": "highlight"
						},
			columns: [	{name: 'Part No', width: '150px', valueField: 'r1'},
						{name: 'Part Name', width: '250px', valueField: 'r2'},
						{name: 'Base No', width: '150px', valueField: 'r3'},
						{name: 'Uom', width:'60px',  valueField: 'r5'},
						{name: 'Rack', width:'150px',  valueField: 'r6'}],
			
			// Event handler for when a list item is selected.
			select: function(event, ui) {
				this.value = (ui.item ? ui.item.rID : '');
				$("#ms_prod_car_line_edit_dtl_ms_item_id").val((ui.item ? ui.item.rID : '')); 
				$("#ms_prod_car_line_edit_dtl_part_no").val((ui.item ? ui.item.r1 : '')); 
				$("#ms_prod_car_line_edit_dtl_part_name").val((ui.item ? ui.item.r2 : '')); 
				$("#ms_prod_car_line_edit_dtl_part_base_no").val((ui.item ? ui.item.r3 : '')); 
				$("#ms_prod_car_line_edit_dtl_part_uom").val((ui.item ? ui.item.r5 : ''));   
				$("#ms_prod_car_line_edit_dtl_rack").val((ui.item ? ui.item.r6 : ''));  
				return false;
			},
			 change: function( event, ui ) { 
			 }, 
			minLength: 2,
			delay: 500,
			position: { my : "left bottom"
					  , at: "left top" },
			source: function(request, response) {
				$.ajax({
					url: '<?php echo base_url().'ms_master/ct_ms_find/find_item_to_production'; ?>',
					dataType: 'json',
					data: {
						limit: 15,
						findtext: request.term,
					},
					// The success event handler will display "No match found" if no items are returned.
					success: function(data) {
						var result;
						if (!data || data.length === 0 || !data.rows || data.rows.length === 0) {
							result = [{label: 'No match found.'}];
							this.value = '';
							$("#ms_prod_car_line_edit_dtl_ms_item_id").val('');  
							// $("#ms_prod_car_line_edit_dtl_part_no").val('');  
							$("#ms_prod_car_line_edit_dtl_part_name").val('');  
							$("#ms_prod_car_line_edit_dtl_part_base_no").val('');  
							$("#ms_prod_car_line_edit_dtl_part_uom").val('');    
							$("#ms_prod_car_line_edit_dtl_rack").val('');  
						}
						else {
							result = data.rows;
						}
						response(result);
					}
				});
			}
		});		
	  
		ms_prod_car_line_edit_header_check();
		ms_prod_car_line_edit_row_detail_action(-1)

		setCaptionToPanelMode("ms_prod_car_line_tbl_stock"); 
		setCaptionToPanelMode("ms_prod_car_line_tbl_supply");
		
		if (!ms_prod_car_line_edit_row_header){
			$('#ms_prod_car_line_tbl_stock_info').html('') 
		} else 
		{ 	 
			$("#ms_prod_car_line_tbl_detail").jqGrid('setGridParam', {postData: {header_id:ms_prod_car_line_edit_row_header.rID}, datatype: 'json'});
			$('#ms_prod_car_line_tbl_detail').trigger('reloadGrid'); 
			$('#ms_prod_car_line_tbl_stock_info').html('    !!!   MAX RECEIVE DATE : ' + ms_prod_car_line_edit_row_header.r3)
		}   
	
		$( "#ms_prod_car_line_action_supply_save" ).button( "option", "disabled",true );
		$( "#ms_prod_car_line_action_supply_delete" ).button( "option", "disabled",true );	
		
		$( "#ms_prod_car_line_edit_doc_no" ).focus();
		
});
		  	
    </script>
