var formatResult;

$(document).ready(function(e) {
//	alert(document.getElementById("searchvalue").value);
	formatResult = function(data) {
    return  data.text ;
  }
  
 $(".getFinalProductsWithProductionRate").select2({
			  placeholder: "إسم المنتج",
			   minimumInputLength:document.getElementById("searchvalue").value ,
		 //minimumInputLength: 3,
			  multiple: false,
			  quietMillis: 100,
			  ajax: {
				url: "sellbillAjaxController.php?do=getFinalProductsWithProductionRate",
				dataType: 'json',
				data: function(term, page) {
					return {
						term: term, //search term
						page_limit: 10 // page size
					};  
				},
				results: function(data) {
				  return {results: data};
				}
			  },
			  formatResult: formatResult,
			  initSelection: function(element, callback) {
				var item = element.val().split(':');
				var data = {id: item[0], text: item[1]};
				callback(data);
			  }
		});
		$("#productId").change(function() {
			
			

            var theselectedvalue = $(this).val();
          //alert('damagedProductAjaxController.php?do=units&productid='+theselectedvalue);
			$('#unitDiv').load('damagedProductAjaxController.php?do=units&productid='+theselectedvalue+'',function() {
						//reload the dropdownlist and jquery files	
						//$('select').chosen();
					});
					
					});
  
});
