<?php
$height = 0;
$jum = count($this->data->form);
foreach($this->data->form as $no => $row){
	if($height < $row['row']){
		$height = $row['row'];
	}
	$no++;
	if($no == $jum){
		if($row['input']['type'] == 'textarea'){
			$tambah = 100;
		}else{
			$tambah = 50;
		}
	}
}
$height = $height + $tambah;

$login = $this->session;
$login = $_SESSION[$login]['login'];
?>
<script type="text/javascript">
$(document).ready(function(){
	makeFunction = function(_func, _lastNo, _display){
		_ex  = _func.split("(");
		_var = str_ireplace('"', '', _ex[1]);
		_var = str_ireplace("'", '', _var);
		_var = str_ireplace(")", '', _var);
		_name = _ex[0];
		return makeCallFunction(_name, _var, _lastNo, _display);
	}
	funct = function(_funt){
		makeFungsiControl(_funt);
	}
	makeCallFunction = function(_name, _var, _lastNo, _display){
		if(_name === 'select'){
			return select(_var, _lastNo);
		}else
		if(_name === 'notNull'){
			return notNull(_var, _lastNo);
		}else
		if(_name === 'display'){
			return display(_var, _lastNo, _display);
		}else
		if(_name === 'disDef'){
			return disDef(_var, _lastNo, _display);
		}else
		if(_name === 'load'){
			return load(_var, _lastNo, _display);
		}else{
			return display(_var, _lastNo, _display);
		}
	}
	makeFungsiControl = function(_funt){
		display(_funt);
	}
	display = function(_func, _lastNo){
		if(_func === 'loadDisplay'){
			loadDisplay(_lastNo);
		}else{
			makeFunctionModul(_func, _lastNo);
		}
	}
	displayFunction = function(_func, key){
		if(_func === 'selectDisplay'){
			_selectDisplay(key);
		}else if(_func === 'loadDisplay'){
			loadDisplay(key);
		}else{
			display(_func, key);
		}
	}
	
	var _loadDisDef = [];
	disDef = function(_no){
		if(_loadDisDef[_no] != undefined){
			_loadDisDef[_no].abort();
		}
		
		_after  = $('#'+_no).attr("after");
		_target = $('#'+_no).attr("target");
		_col 	= $('#'+_no).attr("col");
		if(_col != undefined){
			_target+= '_'+_col;
		}
		
		_atf = _after.split(",");
		_atf = _atf[0].split("(");
		_atf = _atf[1];
		_atf = str_ireplace("'", "", _atf);
		_atf = str_ireplace('"', "", _atf);
		
		_val = $('#'+_no).val();
		_val = str_ireplace('&', '_and_', _val);
		_val = str_ireplace("+", "___", _val);
		
		_loadDisDef[_no] = $.ajax( {	
			type : "GET",
			url: $('#defaultBaseUrl').val()+_atf+"/disDef/&idRef="+_val+'&target='+_target,
			dataType : "json",	
			data : $(this).serializeArray(),
			success : function(obj,status,xhr) {
				
				_target = obj.target;
				_target = _target.split(",");
				if(_target.length > 1){
					for(_iTar = 0; _iTar < _target.length; _iTar++){
						_idT = _target[_iTar];
						$('#'+_idT).val(obj.val[_idT]);
					}
				}else{
					$('#'+obj.target).val(obj.nama);
				}
				
				makeFocusTarget(obj.target);
			},
		})
	}
	
	loadDisplay = function(_lastNo){
		_after 	= $('#'+_lastNo).attr('after');
		_col 	= $('#'+_lastNo).attr('col');
		_loadAf = $('#'+_lastNo).attr('loadAfter');
		_loadAc = $('#'+_lastNo).attr('loadAct');
		_ctrl	= '';
		_target	= '';
		_var	= '';
		_key    = _lastNo;

		if(_after != undefined){
			_after 	= _after.split('"');
			_target = $('#'+_lastNo).attr('target');
			_ctrl 	= _after[1];
		}
		
		// _load = $('#'+_lastNo).attr('load');
		// _loadT = "";
		// if(_load !== undefined){
			// _load = _load.split(",");
			// for(_i = 0; _i < _load.length; _i++){
				// _loadT+= "&"+_load[_i]+'='+$('#'+_load[_i]).val();
			// }
		// }
		
		_load = $('#'+_lastNo).attr('load');
		_loadT = "";
		if(_load !== undefined){
			_load = _load.split(",");
			for(_i = 0; _i < _load.length; _i++){
				
				_cekIdDet = $('#'+_load[_i]).attr('name');
				if(_cekIdDet === undefined){
					_loadT+= "&"+_load[_i]+'='+$('#'+_load[_i]+'_'+_col).val();
				}else{
					_loadT+= "&"+_load[_i]+'='+$('#'+_load[_i]).val();
				}
				
			}
		}
		
		_val = $('#'+_key).val();
		_val = str_ireplace('&', '_and_', _val);
		_val = str_ireplace("+", "___", _val);
		
		if(_ctrl != ''){
			_loadCek = true;
			
			if(_loadAc != undefined){
				
				_act 		= $('#_prosesAction').val();
				_loadAc 	= _loadAc.split(',');
				_loadCek 	= false;
				
				for(_iLA = 0; _iLA < _loadAc.length; _iLA++){
					_act2 = _loadAc[_iLA];
					if(_act2 != undefined){
						_act2 = _act2.trim();
						_act2 = _act2.toLowerCase();
						if(_act2 === _act){
							_loadCek = true;
						}
					}
				}
				
			}
			
			if(_loadCek === true){
				
				if(_target != undefined & _target != ''){
					_exTarget = _target.split(',');
					for(_i = 0; _i < _exTarget.length; _i++){
						_idK = _exTarget[_i];
						_idK = _idK.split('=>');
						$('#'+_idK[0]).val('Load...');
					}
				}
				
				_loadDisplay = $.ajax( { 
				  type : "GET",
				  url: $('#defaultBaseUrl').val()+_ctrl+"/loadDisplay/&idRef="+_val+'&_idIn='+_key+'&target='+_target+'&col='+_col+'&_loadAf='+_loadAf+_loadT,
				  dataType : "json",  
				  data : $(this).serializeArray(),
				  success : function(obj,status,xhr) {
					_jum = parseInt(obj.jum);
					if(_jum > 0){
						for(_i = 0; _i < _jum; _i++){
							$('#'+obj.res[_i].atr).val(obj.res[_i].var)
						}
					}
					  
					if(obj.after != 'undefined'){
						display(obj.after, obj.id);
					}
					  
					setDec();
				  },
				})
			}
		}
	}
	
	$('._buttonLoad, ._buttonLoadD').live("click", (function(){
		_idd = $(this).attr('_idd');
		_nno = $(this).attr('_nno');
		_ttb = $(this).attr('_ttb');
		_dis = $('#'+_idd).attr('display');
		_lod = $('#'+_idd).attr('load');
		_col = $('#'+_idd).attr('col');
		_atf = $('#'+_idd).attr('after');
		_atf = _atf.split(",");
		_atf = _atf[0].split("(");
		_atf = _atf[1];
		_atf = str_ireplace("'", "", _atf);
		_atf = str_ireplace('"', "", _atf);
		
		_loadT = "";
		if(_lod !== undefined){
			
			_dCol = '';
			if(_col != undefined){
				_dCol = '_'+_col
			}
			
			_load = _lod.split(",");
			for(_i = 0; _i < _load.length; _i++){
				_loadT+= "&"+_load[_i]+'='+$('#'+_load[_i]+_dCol).val();
			}
		}
		
		$('#modelLoadPopUp').val(_atf);
		makePopUpTop(1000, 70, $('#defaultBaseUrl').val()+_atf+"/popUp/&urut="+_nno+'&dis='+_dis+'&param='+_loadT+_ttb);
	}))
	
	_loader = false;
	load = function(_var, _lastNo){
		if(_loader !== false){
			_loader = _loader.abort();
		}
		
		_idDet = $('#'+_lastNo).attr('name');
		if(_idDet === undefined){
			_nul = $('.urut_'+_lastNo).attr("notNull");
			_val2 = $('.urut_'+_lastNo).val();
			_val = $('.urut_'+_lastNo).val();
			
			_load = $('.urut_'+_lastNo).attr('load');
			_loadT = "";
			if(_load !== undefined){
				_load = _load.split(",");
				for(_i = 0; _i < _load.length; _i++){
					_loadT+= "&"+_load[_i]+'='+$('#'+_load[_i]).val();
				}
			}
		}else{
			_nul = $('#'+_lastNo).attr("notNull");
			_val2 = $('#'+_lastNo).val();
			_val = $('#'+_lastNo).val()+'&idtext='+_lastNo;
			
			_idCol = $('#'+_lastNo).attr('col');
			_load = $('#'+_lastNo).attr('load');
			_loadT = "";
			if(_load !== undefined){
				_load = _load.split(",");
				for(_i = 0; _i < _load.length; _i++){
					idDName = $('#'+_load[_i]).attr('name');
					if(idDName === undefined){
						_loadT+= "&"+_load[_i]+'='+$('#'+_load[_i]+'_'+_idCol).val();
					}else{
						_loadT+= "&"+_load[_i]+'='+$('#'+_load[_i]).val();
					}
				}
			}
		}
		
		if(_nul === undefined & _val2 === ''){
			makeNextFocusTrue(_lastNo, 0);
			return true;
		}else{
			_ex = _var.split(',');
			_ctr = _ex[0].trim();
			_wrn = _ex[1].trim();
			var _dis = _ex[2].trim();
			
			_nVal = str_ireplace("+", "___", _val);
			
			
			_loader = $.ajax({
			type: "GET",
				url: $('#defaultBaseUrl').val()+_ctr+"/load/&idRef="+_nVal+_loadT,
				dataType : "json",	
				data : $(this).serializeArray(),
				success : function(obj,status,xhr) {
					if(obj.hasil !== undefined){
						if(obj.idtext === null){
							data = str_ireplace("||", "", obj.hasil);
							$('.urut_'+_lastNo).val(data);
							if(_mode === 'enter'){
								makeNextFocusTrue(_lastNo, 0);
							}
							if(_dis !== ''){
								_idIt = $('.urut_'+_lastNo).attr('id');
								displayFunction(_dis, _idIt);
							}
							return true;
						}else{
							data = str_ireplace("||", "", obj.hasil);
							$('#'+obj.idtext).val(data);
							if(_dis !== ''){
								_idIt = $('#'+_lastNo).attr('id');
								displayFunction(_dis, _idIt);
							}
							return true;
						}
					}else{
						
						_idTemp = $('.urut_'+_lastNo).attr('id');
						_vlTemp = $('.urut_'+_lastNo).val();

						if(obj.idtext != null){
							_idTemp = obj.idtext;
							_vlTemp = $('#'+obj.idtext).val();
							$('#'+obj.idtext).val('');
						}
						_param = obj.param;
						_param = str_ireplace("(", "_-_", _param);
						_param = str_ireplace(")", "-_-", _param);
						_param = str_ireplace("'", "***", _param);
						_param = str_ireplace("=", "___", _param);
						_param = str_ireplace(" ", ";;;", _param);
						_param = obj.getUrl;
						_param = _param+'&get_def='+_vlTemp;
						makeLoadPop(_param);
					}
				}
			})	
			makeLoadPop = function(_param){
				if(_wrn === 'true'){
					function showDiv() {
						$("#apankFormConfirm").removeAttr("style");
						$('._buttonConfirm1').focus().select();
						clearInterval(timer);
					}
					var timer = setInterval( showDiv, 300);
					$('._buttonConfirm1').keyup(function(e){
						if(e.which === 13){
							$('.urut_'+_lastNo).val('');
							makeCekNotNull(_lastNo);
						}
					})
					$('._buttonConfirm2').keyup(function(e){
						if(e.which === 13){
							makePopUp(_param);
						}
					})
				}else{
					makePopUp(_param);
				}
			}
			makePopUp = function(_param){
				$('#modelLoadPopUp').val(_ctr);
				$('.urut_'+_lastNo).val('');
				makePopUpTop(1000, 70, $('#defaultBaseUrl').val()+_ctr+"/popUp/&urut="+_lastNo+'&dis='+_dis+'&param='+_param);
			}
			
			$('._buttonConfirm1, #apankFormCloseButton_confirm').live('click', (function(){
				$('.urut_'+_lastNo).val('');
				makeCekNotNull(_lastNo);
			}))
		}
		
		if(_mode === 'enter'){
			return false;
		}else{
			return true;
		}
	}
	
	//----------------Start Load Select DB-------------------//
	makeCekId = function(_key){
		_no = $('#'+_key).attr('no');
		if(_no === undefined){
			_no = _key;
		}
		_ut = $('.urut_'+_no).attr("_urut");
		_vl = $('.urut_'+_no).val();
		_nVal = str_ireplace("+", "___", _vl);
			
		res = {
				_ut: _ut,
				_vl: _vl,
				_nVal: _nVal,
			}
		return res;
	}
	
	selectLoadDb = function(_ctrl, _select, _no, _refresh){
		_val = $('#select'+_select).val();
		
		if(_val != undefined){
			_val =  _val.toUpperCase();
		}
		
		_loadDbSelect = true;
		if(_refresh === false){
			if(_val != ''){
				_loadDbSelect = false;
			}
		}
		if(_loadDbSelect === true){
			res = makeCekId(_no);
			$.ajax( {	
				type : "GET",
				url: $('#defaultBaseUrl').val()+_ctrl+"/select/&idDiv="+_select+'&idRef='+res._nVal+'&urut='+res._ut,
				dataType : "json",	
				data : $(this).serializeArray(),
				success : function(obj,status,xhr) {
					if(obj.jum > 0){
						_ketS = '';
						for(_i = 0; _i < obj.jum; _i++){
							if(_ketS != ''){
								_ketS+= ';';
							}
							_ketS+= obj.data[_i].kode+'=>'+obj.data[_i].nama;
						}
						$('#select'+obj.div).val(_ketS);
					}
					
				},
			})
		}
		
	}
	
	//----------------End Select -------------------//
	
	$('._buttonSelect').live("click", (function(){
		select('apankOke', $(this).attr('_nno'));
	}))
	$('._buttonSelectD').live("click", (function(){
		select('apankOke', $(this).attr('idd'));
	}))
	
	select = function(_var, _lastNo){
		_mode = $('#'+_lastNo).attr("select_mode");
		_roww = $('#'+_lastNo).attr("row");

		if(_mode === 'D' || _mode === 'd' || _roww != undefined){
			_idCls = '#'+_lastNo;
		}else{
			_idCls = '.urut_'+_lastNo;
		}
		
		_nul 	= $(_idCls).attr("notNull");
		_valS 	= $(_idCls).val().toUpperCase();
		_sel 	= $(_idCls).attr("select").toUpperCase();
		_idF 	= $(_idCls).attr("id");
		_lastVal = $(_idCls).attr("value").toUpperCase();
		_val 	= $('#select'+_sel).val().toUpperCase();
		_disp 	= $(_idCls).attr('display');
		_change = $(_idCls).attr('change');
		_width 	= $(_idCls).attr('select_width');
		_height = $(_idCls).attr('select_height');
		_label 	= $(_idCls).attr('select_label');
		_warning= $(_idCls).attr('select_warning');

		if(_val === ''){
			makeNextFocusTrue(_lastNo, 0);
			return true;
		}else{

			if(_nul === undefined & _valS === '' & _var != 'apankOke'){
				makeNextFocusTrue(_lastNo, 0);
				return true;
			}else{
				_wFormSelect = 200;
				if(_width != undefined){
					_wFormSelect = parseInt(_width) + 60;
				}
				
				_style = '';
				if(_width != undefined){
					_width = _width + 40;
					_style+= "; width: "+_width+"px";
				}
				if(_height != undefined){
					_style+= "; overflow: auto; height: "+_height+"px";
				}
				
				_select = '';
				if(_label != undefined){
					_labelD = _label.split(";");
					_select+= "<div>";
					_select+= '<input type="text" value="" style="text-align: center; font-weight: bold; width: 26px; border: none; background-color: #fff" readonly>';
					for(_iLS = 0; _iLS < _labelD.length; _iLS++){
						_atr = _labelD[_iLS].split("=>");
						_select+= '<input type="text" value="'+_atr[0]+'" style="text-align: center; font-weight: bold; width: '+_atr[1]+'px" readonly>';
					}
					_select+= "</div>";
					
					_val = _val.split(";");
					_cekVal = false;
					_select+= "<div style='"+_style+"'>";
					for(_i = 0; _i < _val.length; _i++){
						_select+= "<div>";
						_vVal = _val[_i].split('=>');
						_vLab = _vVal[1].split("___");
						if(_lastVal === _vVal[0]){
							_cekVal = true;
						}
						_select+= '<input type="button" value=" " val="'+_vVal[0]+'" class="_btnPilSelect" style="width: 30px">';
						for(_iLS = 0; _iLS < _labelD.length; _iLS++){
							_atr = _labelD[_iLS].split("=>");
							_idOps = '';
							if(_iLS === 0){
								_idOps = 'id="option_'+_i+'"';
							}
							_select+= '<input type="text" '+_idOps+' class="_option" no="'+_i+'" val="'+_vVal[0]+'" style="width: '+_atr[1]+'px" value="'+_vLab[_iLS]+'" readonly>';
						}
						_select+= "</div>";
					}
					_select+= "</div>";
				}else{
					_val = _val.split(";");
					
					_select = "<div>";
					_cekVal = false;
					for(_i = 0; _i < _val.length; _i++){
						_vVal = _val[_i].split('=>');
						if(_lastVal === _vVal[0]){
							_cekVal = true;
						}
						_select+= '<input type="text" id="option_'+_i+'" no="'+_i+'" val="'+_vVal[0]+'" class="_option" style="width: 130px" value="'+_vVal[1]+'" readonly>';
					}
					_select+= "</div>";
				}

				if(_var === 'apankOke'){
					_cekVal = false;
				}
				
				if(_cekVal === true){
					$('#'+_idF).val(_valS);
					makeNextFocusTrue(_lastNo, 0);
					if(_disp !== undefined){
						_kkey = $('.urut_'+_lastNo).attr("id");
						displayFunction(_disp, _kkey);
					}
					return true;
				}else{
					_wFormSelect = _wFormSelect + 40;
					makePopUpDefaultDisplay(_wFormSelect, 100, _select, "apankFormSelect", 'select');
					$('#apankFormSelect').removeAttr("style");
					$('#option_0').focus().select();
					$('._btnPilSelect').click(function(){
						_id = $(this).attr("val");
						$('#'+_idF).val(_id).focus().select();
						$("#apankFormSelect").html("");
						makeNextFocusTrue(_lastNo, 0);
						if(_disp !== undefined){
							_kkey = $('.urut_'+_lastNo).attr("id");
							displayFunction(_disp, _kkey);
						}
						return true;
					})
					$('._option').dblclick(function(){
						_id = $(this).attr("val");
						$('#'+_idF).val(_id).focus().select();
						$("#apankFormSelect").html("");
						makeNextFocusTrue(_lastNo, 0);
						if(_disp !== undefined){
							_kkey = $('.urut_'+_lastNo).attr("id");
							displayFunction(_disp, _kkey);
						}
						return true;
					})
					$('._option').keyup(function(e){
						if(e.which === 38 || e.which === 40){
							_no = parseInt($(this).attr("no"));
							if(e.which === 38){
								_no = _no - 1;
							}
							if(e.which === 40){
								_no = _no + 1;
							}
							$('#option_'+_no).focus().select();
						}
						if(e.which === 13){
							_id = $(this).attr("val");
							$('#'+_idF).val(_id).focus().select();
							$("#apankFormSelect").html("");
							makeNextFocusTrue(_lastNo, 0);
							if(_disp !== undefined){
								_kkey = $('.urut_'+_lastNo).attr("id");
								displayFunction(_disp, _kkey);
							}
							return true;
						}
						if(e.which === 27){
							$('#'+_idF).focus().select();
							$("#apankFormSelect").html("");
							return true;
						}
					})
				}
			}
		}
		return false;
	}
	
	_selectDisplay = function(_sel){
		_trg = $('#'+_sel).attr('select_target');
		_aft = $('#'+_sel).attr('select_after');
		_label = $('#'+_sel).attr('select_label');

		if(_trg != undefined){
			_id  = _sel;
			_sel = $('#'+_id).attr("select").toUpperCase();
			_val = $('#select'+_sel).val().toUpperCase();
			
			_target = _trg;
			_trg = _trg.split("=>");
			_atr = _trg[0].toUpperCase().trim();
			
			_idAtr = '';
			_vlAtr = '';
			if(_val != ''){
				_vlI = $('#'+_id).val();
				_val = _val.split(";");
				
				for(_i = 0; _i < _val.length; _i++){
					_vVal = _val[_i].split('=>');
					if(_vVal[0] === _vlI){
						
						if(_label === undefined){
							_vValIsi = _vValIsi[1];
							$('#'+_dis).val(_vValIsi);
						}else{
							_vValIsi = _vVal[1].split("___");
							_labelD = _label.split(";");
							
							for(_iLS = 0; _iLS < _labelD.length; _iLS++){
								_atrLS = _labelD[_iLS].split("=>");
								_idDis = _atrLS[0].toUpperCase().trim();
								
								if(_atr === _idDis){
									
									_act = $('#_prosesAction').val();
									if(_act === 'simpan' || _act === 'update'){
										_atrSelSplit = _target.split(';');
										for(_iSelSplit = 0; _iSelSplit < _atrSelSplit.length; _iSelSplit++){
											_idSplitAtr = _atrSelSplit[_iSelSplit];
											_idSplitAtr = _idSplitAtr.split('=>');
											_idSplitAtr = _idSplitAtr[1];
											_iSelSplit2 = _iSelSplit + 1;
											$('#'+_idSplitAtr).val(_vValIsi[_iSelSplit2]);
										}
									}
									
									_idAtr = str_ireplace(";", "", _trg[1]);
									_vlAtr = _vValIsi[_iLS];
								}
							}
						}
					}
				}
			}

			if(_idAtr != ''){
				$('#'+_idAtr).val(_vlAtr);
			}
		}else{
			_selV = $('#'+_sel).val();
			_selC = $('#'+_sel).attr("select");
			_selC = _selC.toUpperCase();
			_selT = $('#'+_sel).attr("target");
			_selA = $('#select'+_selC).val();
			_selA = _selA.split(";");
			for(_i = 0; _i < _selA.length; _i++){
				_selA2 = _selA[_i].split("=>");
				if(_selA2[0] === _selV){
					$('#'+_selT).val(_selA2[1]);
				}
			}
		}
		
		if(_aft != undefined){
			display(_aft);
		}
	}

	makeFocusTarget = function(_target){
		_row = $('#'+_target).attr("row");
		if(_row != undefined){
			$('#'+_target).focus();
		}
	}
	
})
</script>
<?php
$func = $this->basePath.'app/'.$this->modul.'/func.php';
require_once($func);
?>

<style>
#_closePopUp:focus{
	background-color: yellow;
}
#_rasioForm{
	height: <?php echo $height ?>px;
	-webkit-border-radius: 0px 0px 6px 6px; 
	-moz-border-radius: 0px 0px 6px 6px; 
	-khtml-border-radius: 0px 0px 6px 6px; 
	border-radius: 0px 0px 6px 6px;
	border-left: 2px double #99bcd7;
	border-right: 2px double #99bcd7;
	border-bottom: 2px double #99bcd7;
	padding-left: 25px;
	padding-top: 25px;
}
#_rasioForm #background{
	position: absolute;
}
#_rasioForm ._input{
	position: absolute;
}
#_rasioForm ._input input:focus{
	background-color: yellow;
}
#_rasioForm ._input ._label{
	font-size: 12px;
	float: left;
}
.tombol0{
	-webkit-border-radius: 8px 0px 0px 8px; 
	-moz-border-radius: 8px 0px 0px 8px; 
	-khtml-border-radius: 8px 0px 0px 8px; 
	border-radius: 5px 0px 0px 0px;
}
.tabButton2 {
    padding: 10px;
    text-align: left;
	-webkit-border-radius: 0px; 
	-moz-border-radius: 0px; 
	-khtml-border-radius: 0px; 
	border-radius: 0px;
	border-left: 2px double #99bcd7;
	border-right: 2px double #99bcd7;
	border-bottom: 1px dashed #99bcd7;
}
#_gridDetail tbody {
	height: <?php echo $this->data->detail->height ?>px;
    overflow: auto;
}
.apankFormLoadingProgres{
	position: absolute;
	left: 0;
	top: 0;
	width: 100%;
	height: 100%;
	z-index: 999;
	text-align: center;
}
.apankFormLoadingProgresImages{
	margin-top: 200px;
}
._errorEmpty{
	background-color: #ffcccc;
}
._errorUtf8{
	background-color: #f904c4;
}
._imgCari{
	background:url("<?php echo $this->baseUrl.'assets/images/cari_icon.png' ?>") no-repeat left;
	background-position: 35% 35%; 
	margin-top: 2px;
	margin-left: -20px;
	border: none;
	height: 12px;
	width: 20px;
}
._imgCariD{
	background:url("<?php echo $this->baseUrl.'assets/images/cari_icon.png' ?>") no-repeat left;
	background-position: 35% 35%; 
	border: none;
	margin-top: 5px;
	width: 20px;
	height: 12px;
	margin-left: -20px;
}

<?php 
$kode = new Kode;
$browser = $kode->getting_browser();
if($browser == 'CHROME'){ 
?>
#_rasioForm input{
	font-size: 11px;
	height: 16px;
}
<?php } ?>
</style>

<input type="hidden" id="_pageActive" value="1">
<input type="hidden" id="_jenisPopUpLoad">
<input type="hidden" id="_urutPopUp">
<input type="hidden" id="_lastBarisDet" value="1">
<input type="hidden" id="_lastNoUrutDet" value="1">
<input type="hidden" id="_lastNoUrutLeft" value="1">
<input type="hidden" id="_pageToken" value="<?php echo date("ymdHis").rand(10000, 99999) ?>">

<div id="apankFormLoadingProgres" class="apankFormLoadingProgres" style="display: none">
	<img src="<?php echo $this->baseUrl ?>assets/images/ajax-loader.gif" class="apankFormLoadingProgresImages">
</div>

<div id="apankFormBar" class="_popUpDef"></div>
<div id="apankFormBarAct" class="_popUpDef"></div>
<div id="apankFormSelect" class="_popUpDef"></div>
<div id="apankFormFilter" class="_popUpDef"></div>
<div id="apankFormConfirm" class="_popUpDef"></div>
<div id="apankFormUrutUlang" class="_popUpDef"></div>
<div id="apankFormBarcode" class="_popUpDef"></div>
<form id="formAjaxDefault" action="#" method="post">
	<input type="hidden" name="_prosesAction" id="_prosesAction">
	<div id="apankFormDefDisplay" class="_popUpDef"></div>
	<input type="hidden" name="_pk" id="_pk">
	<input type="hidden" name="_nodb" id="_nodb">
	<div class="tabButton2">
		<?php
		$loadDataNavigator = false;
		$loadAdd 	= false;
		$loadEdit 	= false;
		$loadView 	= false;
		$loadDel 	= false;
		$loadPending= false;
		$loadBrowse = false;
		$loadPrint 	= false;
		
		foreach($this->data->button as $key => $row):
			if(strtoupper($row) == strtoupper('First') or strtoupper($row) == strtoupper('Prev') or strtoupper($row) == strtoupper('Last') or strtoupper($row) == strtoupper('Next')){
				$loadDataNavigator = true;
			}
			if(strtoupper($row) == strtoupper('Add')){
				$loadAdd = true;
			}
			if(strtoupper($row) == strtoupper('Edit')){
				$loadEdit = true;
			}
			if(strtoupper($row) == strtoupper('view')){
				$loadView = true;
			}
			if(strtoupper($row) == strtoupper('Del')){
				$loadDel = true;
			}
			if(strtoupper($row) == strtoupper('Pending')){
				$loadPending = true;
			}
			if(strtoupper($row) == strtoupper('Browse')){
				$loadBrowse = true;
			}
			if(strtoupper($row) == strtoupper('print')){
				$loadPrint = true;
			}
			if(strtoupper($row) == strtoupper('barcode')){
				$loadBarcode = true;
			}
			if(strtoupper($row) == strtoupper('calc')){
				$loadCalc = true;
			}
			if(strtoupper($row) == strtoupper('Save')){
				$loadSave = true;
			}
		?>
			<input type="button" id="<?php echo $this->getParameter['controller'].$row ?>" name="<?php echo $row ?>" class="submit submitApankForm button<?php echo $row ?> tombol<?php echo $key ?>" value="<?php echo $row ?>">
		<?php endforeach; ?>
	</div>
	<input type="hidden" id="_noUrut">
	<div id="_rasioForm" >
		<?php 
		$select = array();
		if(!empty($this->data->detail)){ 
			$divDet = $this->getParameter['controller'].'Detail';
			$col = $this->data->detail->col;
			$row = $this->data->detail->row;
			$wid = $this->data->detail->width;
			$heg = $this->data->detail->height;
			foreach($this->data->detail->attr as $k => $r){
				if(!empty($r['select'])){
					$idSel = $r['select'];
					$select[$idSel] = $idSel;
				}
			}
		?>
			<div style="margin-left: <?php echo $col ?>px; margin-top: <?php echo $row ?>px; width: <?php echo $wid ?>px; height: <?php echo $heg ?>px" id="<?php echo $divDet ?>" class="_input _rasioDet">
			&nbsp;
			</div>
		<?php } ?>
		<div id="background"><?php echo $this->data->background ?></div>
		<?php
		$no = 0;
		$loadSimpan = array();
		$loadUpdate = array();
		$hideSimpan = array();
		$hideUpdate = array();
		$idSelect 	= array();
		$idLoad 	= array();
		foreach($this->data->form as $kNo => $row):
		?>
		<div class="_input" style="margin-left: <?php echo $row['col'] ?>px; margin-top: <?php echo $row['row'] ?>px">
			<?php 
			if(!empty($row['label']) and $row['label'] != false){ 
				$width = 100;
				if(!empty($row['label']['width'])){
					$width = $row['label']['width'];
				}
			?>
				<div class="_label" style="width: <?php echo $width ?>px">
					<?php echo $row['label']['name'] ?>
				</div>
			<?php } ?>
			<?php 
			if(!empty($row['input'])){ 
				$input = $row['input'];
				$jenis = $input['type'];
				$idInp = $input['attr']['name'];
				if(!empty($input['attr']['select'])){
					$select[] = $input['attr']['select'];
					$idSelect[$idInp] = $no;
				}
				if(!empty($input['attr']['loadAct'])){
					$_loadAct = explode(",", $input['attr']['loadAct']);
					foreach($_loadAct as $rAct){
						$rAct  = trim(strtolower($rAct));
						if($rAct == 'simpan'){
							$loadSimpan[$idInp] = $idInp;
						}
						if($rAct == 'update'){
							$loadUpdate[$idInp] = $idInp;
						}
					}
				}
				if(!empty($input['attr']['loadHide'])){
					$_loadAct = explode(",", $input['attr']['loadHide']);
					foreach($_loadAct as $rAct){
						$rAct  = trim(strtolower($rAct));
						if($rAct == 'simpan'){
							$hideSimpan[$idInp] = $idInp;
						}
						if($rAct == 'update'){
							$hideUpdate[$idInp] = $idInp;
						}
					}
				}
				
				$after = $input['attr']['after'];
				$after = explode("(", $after);
				$after = trim(strtolower($after[0]));
				if($after == 'load'){
					$idLoad[$idInp] = $no;
				}
			?>
				<div style="float: left">
					<?php 
					echo $this->form->$jenis($jenis, $input['attr'], $input['attr']['name'], $no, $row['label']['name']);
					$no++;
					?>
				</div>
			<?php } ?>
		</div>
		<?php 
		endforeach;
		?>
	</div>
	
	<?php 
	$selAp = "SELECT_APP_".strtoupper($this->modul);
	$sel = new Select;
	$selApp = new $selAp;
	foreach($select as $row){ 
		$row = strtoupper($row);
		$dataSel = $selApp->$row();
		$dataSel = $sel->serialize($dataSel);
	?>
		<input type="hidden" id="select<?php echo $row ?>" value="<?php echo $dataSel ?>">
	<?php } ?>
	
</form>
<div id="errorDisplay"><div>
<?php
$login = $this->session;
$login = $_SESSION[$login]['login'];
$kode = new Kode;
?>
<script type="text/javascript">
$(document).ready(function(){

	<?php foreach($idSelect as $k => $r){ ?>
		_imgLoad = '<input type="button" disabled _nno="<?php echo $r ?>" class="_imgCari _buttonSelect">';
		$('#<?php echo $k ?>').after(_imgLoad);
	<?php } ?>
	<?php foreach($idLoad as $k => $r){ ?>
		_imgLoad = '<input type="button" disabled _idd="<?php echo $k ?>" _ttb="" _nno="<?php echo $r ?>" class="_imgCari _buttonLoad">';
		$('#<?php echo $k ?>').after(_imgLoad);
	<?php } ?>

	<?php if(!empty($this->data->detail)){ ?>
	
		_listLoadDetailRun = false;
		_listLoadDetail = function(_ctrl, _funct){
			if(_listLoadDetailRun != false){
				_listLoadDetailRun.abort();
			}
			_listLoadDetailRun = $.ajax({
			type: "GET",
				url: "<?php echo $this->baseUrl ?>Basic/loadListDetail/&ctrl="+_ctrl+'&funct='+_funct,
				data: $(this).serialize(),
				success: function(data) {
					$("#errorDisplay").html(data);
				}
			})	
		}
	
		$('#_lastNoUrutDet').val('<?php echo $no ?>');
		makeFocusDetail = function(_no){
			_nom = 0;
			for(_i = 1; _i <= 25; _i++){
				_nom = _nom + 1;
				_id = '_detTd_'+_nom+'_1';
				_nama = $('.'+_id).attr('name');
				if(_nama != undefined){
					$('.'+_id).focus().select();
					return;
				}
			}
		}
		
		_cekIsiDet = function(_id){
			_val = $('#'+_id).val();
			_length = _val.length;
			if(_length === 0){
				return true;
			}
			_urut = cekPosisiPointer(_id);
			if(_urut === 0){
				return true;
			}
			if(_urut === _length){
				return true;
			}
			return false;
		}
		
		_cekBarisDet = function(_id, _jen){
			_col = parseInt($('#'+_id).attr('col'));
			_row = parseInt($('#'+_id).attr('row'));
			for(_i = 1; _i <= 25; _i++){
				if(_jen === 'min'){
					_col = _col - 1; 
				}else{
					_col = _col + 1; 
				}
				_name = $('._detTd_'+_col+'_'+_row).attr("id");
				if(_name != undefined){
					return _col;
				}
			}
			return _col;
		}
		
		_makeTambahDet = function(){
			_mode = $('#_gridDetail').attr("mode");
			if(_mode !== 'VIEW'){
				_lastBaris = parseInt($('#_lastBarisDet').val());
				
				_tabDet = '<tr id="barisDet_'+_lastBaris+'">';
				
				<?php if($this->data->detail->autoNo == true){ ?>
					_tabDet+= '<td style="width: 30px;" class="_detTdItem"><input type="text" class="_detTd" style="width:30px" name="no['+_lastBaris+']" id="_no_'+_lastBaris+'" readonly autocomplete="off"></td>';
				<?php } ?>
				
				<?php 
				$rows = 1;
				foreach($this->data->detail->attr as $keyD => $row){ 
					$idDet = $row['attr'];
					$type = "text";
					if(!empty($row['type'])){
						$type = $row['type'];
					}
					$dis = '';
					if(strtoupper($type) == strtoupper('hidden')){
						$dis = '; display: none';
					}else{
						$tambah = $kode->setAttrDetail($row, $baris);
					}
					$_imgSel = false;
					if(!empty($row['select'])){
						$_imgSel = true;
					}
					
					$after = $row['after'];
					$after = explode("(", $after);
					$after = trim(strtolower($after[0]));
					$_imgLod = false;
					if($after == 'load'){
						$_imgLod = true;
					}
				?>
					_btnSel = '';
					<?php if($_imgSel == true){ ?>
						_btnSel = '<input row="<?php echo $rows ?>" col="'+_lastBaris+'" idd="<?php echo $idDet.'_' ?>'+_lastBaris+'"  class="_imgCariD _buttonSelectD" value="" type="button">';
					<?php } ?>
					<?php if($_imgLod == true){ ?>
						_btnSel = '<input row="<?php echo $rows ?>" col="'+_lastBaris+'" _idd="<?php echo $idDet.'_' ?>'+_lastBaris+'" _nno="<?php echo $idDet.'_' ?>'+_lastBaris+'" class="_imgCariD _buttonLoadD" value="" _ttb="&pkBrowse=&get_def=&get_def=undefined" type="button">';
					<?php } ?>
					_tabDet+= '<td style="width: <?php echo $row['width'] ?>px; <?php echo $dis ?>" class="_detTdItem"><input type="<?php echo $type ?>" row="<?php echo $rows ?>" col="'+_lastBaris+'" class="text _detTd _detTd_'+_lastBaris+'_<?php echo $rows ?> <?php echo $row['class'] ?>" style="width:<?php echo ($row['width']) ?>px" name="<?php echo $idDet ?>['+_lastBaris+']" id="<?php echo $idDet.'_' ?>'+_lastBaris+'" autocomplete="off" value="<?php echo $r->$idDet ?>" _mode="cursor" <?php echo $tambah ?>>'+_btnSel+'</td>';
				<?php 
					$rows++;
				} 
				?>
				_tabDet+= '<tr>';

				_lastBarisSblm = _lastBaris - 1;
				$('#barisDet_'+_lastBarisSblm).after(_tabDet);
				_lastBarisNew = _lastBaris + 1;
				$('#_lastBarisDet').val(_lastBarisNew);
				makeUrutNoDet();
			}
		}
		
		makeUrutNoDet = function(){
			<?php if($this->data->detail->autoNo == true){ ?>
				_lastBaris = parseInt($('#_lastBarisDet').val());
				_noUrutNewDet = 1;
				for(_iNoUrut = 1; _iNoUrut <= _lastBaris; _iNoUrut++){
					_cek = $('#_no_'+_iNoUrut).attr("name");
					if(_cek != undefined){
						$('#_no_'+_iNoUrut).val(_noUrutNewDet);
						_noUrutNewDet = _noUrutNewDet + 1;
					}
				}
			<?php } ?>
		}

		_cekAvailDet = function(_awal, _akhir){
			for(_iA = _awal; _iA < _akhir; _iA++){
				_cekAvail = $('._detTd_'+_iA+'_1').attr('id');
				if(_cekAvail !== undefined){
					return true;
				}
			}
			return false;
		}
		_setLastNoDet2 = function(){
			_lastNo = parseInt($('#_lastBarisDet').val());
			for(_iA = _lastNo; _iA > 0; _iA--){
				_cekAvail = $('._detTd_'+_iA+'_1').attr('id');
				if(_cekAvail !== undefined){
					return _iA + 1;
				}
			}
			return 1;
		}
		_setLastNoDet = function(){
			_lastNo = _setLastNoDet2();
			$('#_lastBarisDet').val(_lastNo);
		}
		
		cekAvaliLR = function(_no, _row, _jen){
			if(_jen === 'min'){
				_no = _no - 1;
			}else{
				_no = _no + 1;
			}
			
			_cekAvailLR = "_detTd_"+_row+"_"+_no;
			_cekAvailLR = $('.'+_cekAvailLR).attr("type");
			if(_cekAvailLR === 'text'){
				return _no;
			}else{
				return cekAvaliLR(_no, _col, _jen);
			}
			
		}
		
		$('._detTd').live("keyup", (function(e){
			_row = parseInt($(this).attr('row'));
			_col = parseInt($(this).attr('col'));
			_idR = this.id;
			_cek = false;
			
			if(e.which === 46){	//delete
				var answer = confirm("Yakin Menghapus Detail Ini?")
				if (answer){
					$('#barisDet_'+_col).remove();
					makeUrutNoDet();
					
					_col2 = _col;
					for(_i = 1; _i < 25; _i++){
						_col2 = _col2 - 1;
						_name = $('._detTd_'+_col2+'_1').attr("name");
						if(_name !== undefined){
							$('._detTd_'+_col2+'_1').focus().select();
							return;
						}
					}
					_col2 = _col;
					for(_i = 1; _i < 25; _i++){
						_col2 = _col2 + 1;
						_name = $('._detTd_'+_col2+'_1').attr("name");
						if(_name !== undefined){
							$('._detTd_'+_col2+'_1').focus().select();
							return;
						}
					}
					
				}else{
					$('#'+this.id).focus();
				}
			}
			if(e.which === 37){ // Right
				_cek = _cekIsiDet(this.id);
				if(_cek === true){
					_row = cekAvaliLR(_row, _col, 'min');
					// _row = _row - 1;
				}
			}
			if(e.which === 38){ // Top
				_col = _cekBarisDet(this.id, 'min');
				_cek = true;
			}
			if(e.which === 39){ // Left
				_cek = _cekIsiDet(this.id);
				if(_cek === true){
					_row = cekAvaliLR(_row, _col, 'max');
					// _row = _row + 1;
				}
			}
			if(e.which === 40){ // Bottom
				_col = _cekBarisDet(this.id, 'max');
				_cek = true;
			}
			if(e.which === 27){ // Esc
				$("#apankFormDefDisplay").removeAttr("style");
				$("#_displayErrorPopUp").html("");
				function showDiv() {
					$('._buttonNewNom1').focus().select();
					clearInterval(timer);
				}
				var timer = setInterval( showDiv, 100);
			}
			if(e.which === 13){ // Enter
				_nNull = $(this).attr('notnull');
				_after = $(this).attr("after");
				_dVal = $(this).val();
				_nNext = false;
				if(_after != undefined){
					if(_dVal === ''){
						_nNext = true;
					}else{
						_cekAfter = makeFunction(_after, this.id, false);
					}
				}else if(_nNull === undefined){
					_nNext = true;
				}else{
					_val  = $(this).val();
					if(_val.length > 0){
						_nNext = true;
					}
				}

				if(_nNext === true){
					_leftMax = parseInt($('#_lastNoUrutLeft').val());
					_bottomMax = parseInt($('#_lastBarisDet').val());
					_nextBottomMax = _col + 1;

					if(_col < _bottomMax & _row < _leftMax){
						_row = cekAvaliLR(_row, _col, 'max');
				
					}else if(_nextBottomMax < _bottomMax & _row >= _leftMax){
						_col = _cekBarisDet(this.id, 'max');
						_row = 1;
						_cek = true;
						
						_cekAvail = $('._detTd_'+_nextBottomMax+'_1').attr('id');
						if(_cekAvail === undefined){
							_cekAvail = _cekAvailDet(_nextBottomMax, _bottomMax);
							if(_cekAvail === false){
								_setLastNoDet();
								_makeTambahDet();
							}
						}

					}else if(_nextBottomMax >= _bottomMax & _row >= _leftMax){
						_makeTambahDet();
						// alert(_nextBottomMax+' => '+_bottomMax+' => '+_row+' => '+_leftMax);
					}
				}
			}
			if(_cek === true){
				if(_col < 1){
					_noUrutLast = parseInt($('#_lastNoUrutDet').val());
					_nom = _noUrutLast;
					for(_i = 1; _i <= _noUrutLast; _i++){
						_nom = _nom - 1;
						_dis = $('.urut_'+_nom).attr("readonly");
						if(_dis === undefined){
							$('.urut_'+_nom).focus().select();
							return;
						}
					}
				}else{
					_next = '._detTd_'+_col+'_'+_row;
					$(_next).focus().select();
				}
			}
		}))
	
		_div = '<?php echo $divDet ?>';
		_tabDet = '<table id="_gridDetail" class="_gridDetail" cellspacing="0" cellpadding="0" mode="<?php echo strtoupper($this->data->detail->mode) ?>">';
		_tabDet+= '<thead>';
		_tabDet+= '<tr>';
		
		<?php if($this->data->detail->autoNo == true){ ?>
			_tabDet+= '<th style="width: 30px"><input disabled type="text" class="_detHead" style="width: 30px" value="No"></th>';
		<?php } ?>
		
		<?php 
		$lastNoLeft = 0;
		foreach($this->data->detail->attr as $row){ 
			if(strtoupper($row['type']) != strtoupper('hidden')){
		?>
			_tabDet+= '<th style="width: <?php echo $row['width'] ?>px"><input disabled type="text" class="_detHead" style="width: <?php echo $row['width'] ?>px" value="<?php echo $row['label'] ?>"></th>';
		<?php 
			}
			$lastNoLeft++;
		} 
		$barisDet = 1;
		?>
		$('#_lastNoUrutLeft').val('<?php echo $lastNoLeft ?>');
		_tabDet+= '</tr>';
		_tabDet+= '</thead>';
		_tabDet+= '<tbody id="_detBody">';

		_tabDet+= '<tr id="barisDet_<?php echo $barisDet ?>">';
		<?php 
		foreach($this->data->detail->attr as $keyD => $row){ 
			$idDet = $row['attr'];
		?>
			_tabDet+= '<td style="width: <?php echo $row['width'] ?>px" class="_detTdItem"><input type="text" no="<?php echo $no ?>" class="text urut_<?php echo $no ?> _detTd detHeadBaris_<?php echo $barisDet ?>" style="width:<?php echo ($row['width']) ?>px" name="<?php echo $idDet ?>[<?php echo $barisDet ?>]" id="<?php echo $idDet.'_'.$no ?>" autocomplete="off" baris="<?php echo $barisDet ?>"></td>';
		<?php 
			$no++;
		} 
		?>
		_tabDet+= '</tr>';
		_tabDet+= '</tbody>';
		_tabDet+= '</table>';
		$('#'+_div).html(_tabDet);
	<?php } ?>



	var _notNull = [];
	<?php 
	if(!empty($this->data->notNull)){
		foreach($this->data->notNull as $key => $row){ 
	?>
		_notNull[<?php echo $key ?>] = '<?php echo $row ?>';
		$('#<?php echo $row ?>').attr("notNull", true);
	<?php 
		}
	} 
	?>
	makeCalculate = function(){
		<?php if($loadCalc == true){ ?>
			makeLoadCalculate("<?php echo $this->getParameter['controller'] ?>");
		<?php } ?>
	}

	makeFormBarcode = function(){
		<?php if($loadBarcode == true){ ?>
			$('#apankFormBarcode').removeAttr("style");
			makeLoadBarcodeDefault("<?php echo $this->getParameter['controller'] ?>");
			$('#barcodeAwal').focus().select();
		<?php } ?>
	}
	makeDisFormBarcode = function(){
		_button = "<div style='text-align: center'>";
		_button+= "No. <input type='text' size='10' id='barcodeAwal' notnull='true' class='textFilter filter_10000001 urut_10000001' no='10000001'>";
		_button+= " s/d &nbsp; <input type='text' size='10' id='barcodeAkhir' notnull='true' class='textFilter filter_10000002' no='10000002'>";
		_button+= "<div style='padding-top: 10px'>";
		_button+= "<input type='button' id='_tampilCetakBarcode' class='textFilter filter_10000003' no='10000003' value='Cetak Barcode'>";
		_button+= "<input type='button' id='_closeCetakBarcode' class='textFilter filter_10000004' no='10000004' value='Close'>";
		_button+= "</div>";
		_button+= "</div>";
		
		makePopUpDefaultDisplay(330, 200, _button, "apankFormBarcode", 'urutUlang');
	}
	$('#barcodeAwal, #barcodeAkhir').live("keyup", (function(e){
		if(e.which === 13){
			// load($(this).attr("_var"), $(this).attr("no"));
		}
	}))
	makeDisFormBarcode();
	$('#apankFormBarcode').css("display", "none");
	$('#_closeCetakBarcode').click(function(){
		$('#apankFormBarcode').css("display", "none");
	})
	$('#_tampilCetakBarcode').click(function(){
		cetakBarcode();
	})
	$('#_tampilCetakBarcode').keyup(function(e){
		if(e.which === 13){
			cetakBarcode();
		}
	})
	cetakBarcode = function(){
		_awal 	= $('#barcodeAwal').val();
		_akhir 	= $('#barcodeAkhir').val();
		if(_awal === '' || _akhir === ''){
			$('#barcodeAwal').focus().select();
			alert("No. awal atau Akhir tidak boleh kosong!");
		}else{
			_kode = "<?php echo $this->baseUrl.$this->getParameter['asliGetCotroller'] ?>/Barcode/&awal="+_awal+"&akhir="+_akhir;
			window.open(_kode);
		}
	}
	
	$('.textFilter').keyup(function(e){
		if(e.which === 27){
			makeTimeFocus();
			$('._popUpDef').css("display", "none");
		}
	});
	
	makeUrutUlang = function(){
		_button = "<div style='text-align: center'>";
		_button+= "<input id='<?php echo $this->getParameter['controller'] ?>UrutUlang' type='button' value='Urut Ulang'>";
		_button+= "<input id='<?php echo $this->getParameter['controller'] ?>UrutClose' type='button' value='Close'>";
		_button+= "<div id='prosesUrutUlang' style='margin-top: 10px'></div>";
		_button+= "</div>";
		
		makePopUpDefaultDisplay(300, 200, _button, "apankFormUrutUlang", 'urutUlang');
	}
	makeUrutUlang();
	$('#apankFormUrutUlang').css("display", "none");
	$('#<?php echo $this->getParameter['controller'] ?>UrutClose').live("click", (function(){
		$('#apankFormUrutUlang').css("display", "none");
	}))
	makeUrutUlang();
	$('#<?php echo $this->getParameter['controller'] ?>UrutUlang').click(function(){
		if(_loadJson !== false){
			_loadJson.abort();
		}
		$('#prosesUrutUlang').html("Proses.....");
		_loadJson = $.ajax( {	
			type : "GET",
			url: $('#defaultbaseUrl').val()+"Basic/Urut/&idRef=<?php echo $this->getParameter['controller'] ?>",
			data: $(this).serialize(),
			success: function(data) {
				$('#prosesUrutUlang').html(data);
			},
		})
	})
	$.Shortcuts.add({
		type: "down",
		mask: "alt+f11",
		handler: function() {
			$('#prosesUrutUlang').empty();
			$('#apankFormUrutUlang').removeAttr("style");
		}
	}).start();
	
	
	makeConfirm = function(){
		_button = "<div style='text-align: center'>";
		_button+= "<input id='<?php echo $this->getParameter['controller'] ?>ClosePopUp' type='text' class='textConfirm _buttonConfirm1' nom='1' readonly value='Tutup'>";
		_button+= "<input id='<?php echo $this->getParameter['controller'] ?>LoadPopUp' type='text' class='textConfirm _buttonConfirm2' nom='2' readonly value='Tampil'>";
		_button+= "</div>";
		
		makePopUpDefaultDisplay(300, 200, _button, "apankFormConfirm", 'confirm');
	}
	makeConfirm();
	$('.textConfirm').keyup(function(e){
		if(e.which === 37 || e.which === 39){
			_nom = $(this).attr("nom");
			_nom = parseInt(_nom);
			if(e.which == 37){
				_nom = _nom - 1;
			}
			if(e.which == 39){
				_nom = _nom + 1;
			}
			$("._buttonConfirm"+_nom).focus().select();
		}
		if(e.which === 13){
			$("#apankFormConfirm").css("display", "none");
			$('.urut_'+_focus).focus().select();
		}
	})
	$("#apankFormConfirm").css("display", "none");
	
	$('#apankFormCloseButton').live('click', (function(){
		$("._popUpDef").css("display", "none");
	}))
	$('.textFilter, #_tampilPrinter').live('keyup', (function(e){
		if(e.which === 27){
			$("#apankFormFilter").css("display", "none");
		}
	}))
	makeFilter = function(){
		_button = "<div style='text-align: center'>";
		_button+= "<table>";
		<?php 
		if($this->data->cetak != false){
			$no = 0;
			foreach($this->data->cetak->attr as $kF => $row){ 
				if($row['filter'] == true){
					$size = 20;
					if(!empty($row['filter']['size'])){
						$size = $row['filter']['size'];
					}
		?>
			_button+= "<tr>";
			_button+= "<td width='100px'><?php echo $row['label'] ?></td>";
			_button+= "<td><input type='text' size='<?php echo $size ?>' id='filPrint<?php echo str_ireplace(".", "", $row['attr']) ?>' class='textFilter filter_<?php echo $no?> <?php echo $row['class'] ?>' no='<?php echo $no ?>'  default='<?php echo $row['default'] ?>'></td>";
			_button+= "</tr>";
		<?php 
					$no++;
				}
			}
		} 
		?>
		_button+= "<tr>";
		_button+= "<td width='100px'></td>";
		_button+= "<td><input type='button' id='_tampilPrinter' class='textFilter filter_<?php echo ($no) ?>' no='<?php echo ($no) ?>' value='Tampil'></td>";
		_button+= "</tr>";
		_button+= "</table>";
		_button+= "</div>";
		makePopUpDefaultDisplay(500, 100, _button, "apankFormFilter", 'filter');
	}
	$("#apankFormFilter").css("display", "none");
	makeFilter();
	$('.textFilter').keyup(function(e){
		if(e.which === 40 || e.which === 13 || e.which === 38){
			_no = parseInt($(this).attr('no'));
			if(e.which === 40 || e.which === 13){
				_no = _no + 1;
			}
			if(e.which === 38){
				_no = _no - 1;
			}
			$('.filter_'+_no).focus().select();
			
			if(e.which === 27){
				$("#apankFormFilter").css("display", "none");
			}
		}
	})
	
	makeDisplay = function(){
		<?php
		if($this->data->push == true){
		?>
			_kode = "<?php echo $this->baseUrl.$this->getParameter['asliGetCotroller'] ?>/push/";
			<?php 
			if($this->data->cetak != false){
				foreach($this->data->cetak->attr as $no => $row){ 
					if($row['filter'] == true){
						$key = 'filPrint'.str_ireplace(".", "", $row['attr']);
			?>
				_kode+= '&<?php echo $key ?>='+str_ireplace("%", "||", str_ireplace("+", "___", $('#<?php echo $key ?>').val()));
			<?php 
					}
				} 
			}
			?>
			if(_loader !== false){
				_loader.abort();
			}
			$('#apankFormLoadingProgres').removeAttr("style");
			_loader = $.ajax({
			type: "GET",
				url: _kode,
				data: $(this).serialize(),
				success: function(data) {
					$("#errorDisplay").html(data);
					$('#apankFormLoadingProgres').css("display", "none");
				}
			})	
		<?php }else{ ?>
			_kode = "<?php echo $this->baseUrl.$this->getParameter['asliGetCotroller'] ?>/cetak/";
			<?php 
			if($this->data->cetak != false){
				foreach($this->data->cetak->attr as $no => $row){ 
					if($row['filter'] == true){
						$key = 'filPrint'.str_ireplace(".", "", $row['attr']);
			?>
				_kode+= '&<?php echo $key ?>='+str_ireplace("%", "||", str_ireplace("+", "___", $('#<?php echo $key ?>').val()));
			<?php 
					}
				} 
			}
			?>
			window.open(_kode);
		<?php } ?>
	}
	$('#_tampilPrinter').click(function(){
		makeDisplay();
		$("#apankFormFilter").css("display", "none");
	})
	$('#_tampilPrinter').keyup(function(e){
		if(e.which === 13){
			makeDisplay();
			$("#apankFormFilter").css("display", "none");
		}
	})
	
	makeButton = function(){
		_button = "<div style='text-align: center'>";
		_button+= "<div style='text-align: center; margin-top: -10px; margin-bottom: 10px' id='_displayErrorPopUp'></div>";
		_button+= "<input id='<?php echo $this->getParameter['controller'] ?>EditButton' type='text' class='inputButton textButtonNew _buttonNewNom1' nom='1' readonly value='Edit'>";
		_button+= "<input id='<?php echo $this->getParameter['controller'] ?>prosesButton' type='submit' class='textButtonNew submitApankForm _buttonNewNom2' nom='2' value='Ok'>";
		_button+= "<input id='<?php echo $this->getParameter['controller'] ?>CancelButton' type='text' class='inputButton textButtonNew _buttonNewNom3' nom='3' readonly value='Cancel'>";
		_button+= "</div>";
		
		makePopUpDefaultDisplay(300, 200, _button, "apankFormDefDisplay", "button");
	}
	makeButton();
	
	makeBarcodePost = function(_id, _label, _title, _isi){
		_bar = '<div style="text-align: center; width: 100%; font-weight: bold">';
		_bar+= '<p style="margin: 0px">'+_title+'<p>';
		_bar+= _isi;
		_bar+= '<p style="margin: 0px" id="_errMsg"><p>';
		_bar+= '</div>';
		makePopUpDefaultDisplay(300, 100, _bar, "apankFormBar", 'barcode');
		$('#'+_id).focus().select();
	}
	
	$("#apankFormDefDisplay, #apankFormBarAct").css("display", "none");
	$(".textButtonNew").live("keyup", (function(e){
		if(e.which === 37 || e.which === 39){
			_nom = $(this).attr("nom");
			_nom = parseInt(_nom);
			if(e.which == 37){
				_nom = _nom - 1;
			}
			if(e.which == 39){
				_nom = _nom + 1;
			}
			$("._buttonNewNom"+_nom).focus().select();
		}
	}))
	makeButtonBar = function(){
		_button = "<div style='text-align: center'>";
		_button+= "<div style='text-align: center; margin-top: -10px; margin-bottom: 10px' id='_displayErrorPopUpBar'></div>";
		_button+= "<input id='barEditButton' type='text' class='inputButtonBar textButtonNewBar barButtonNewNom1' nom='1' readonly value='Edit'>";
		_button+= "<input id='barProsesButton' type='submit' class='textButtonNewBar barButtonNewNom2' nom='2' value='Ok'>";
		_button+= "</div>";
		
		makePopUpDefaultDisplay(300, 200, _button, "apankFormBarAct", "button");
	}
	makeButtonBar();
	$('._barcodePost').live("keyup", (function(e){
		_no = parseInt($(this).attr("no"));
		_ac = false;
		if(e.which === 13 || e.which === 40){
			_no = _no + 1;
			_id = $('.bar_'+_no).attr('id');
			if(_id !== undefined){
				_ac = false;
			}else{
				$('#apankFormBarAct').removeAttr("style");
				function showDiv() {
					$('#barEditButton').focus().select();
					clearInterval(timer);
				}
				var timer = setInterval( showDiv, 100);
			}
		}else if(e.which === 38){
			_no = _no - 1;
		}else if(e.which === 27){
			$('#apankFormBar').empty();
		}
		if(e.which === 13 || e.which === 40 || e.which === 38){
			if(_ac === false){
				_foc = 'bar_'+_no;
				$('.'+_foc).focus().select();
				
			}
		}
			// $('#tob').val($(this).val().toUpperCase());
			// makeAutoSave('F');
	}))
	$('.textButtonNewBar').live("keyup", function(e){
		_no = parseInt($(this).attr("nom"));
		_ac = false;
		if(e.which === 37){
			_no = _no - 1;
		}	
		if(e.which === 39){
			_no = _no + 1;
		}
		if(e.which === 13){
			$('#apankFormBarAct').css("display", 'none');
			_ac = true;
			if(_no === 1){
				$('.bar_1').focus().select();
			}else{
				makeActionBarcodePost();
			}
		}
		if(_ac === false){
			$('.barButtonNewNom'+_no).focus().select();
		}
	})
	makeMustFunctList = function(_id, _attr){
		_at = _attr.split(",");
		_va = $("#"+_id).val().toUpperCase();

		_res = false;
		for(_i = 0; _i < _at.length; _i++){
			_ni = _at[_i].toUpperCase();
			_ni = _ni.trim();
			if(_va === _ni){
				$("#"+_id).val(_va);
				_res = true;
			}
		}

		if(_res === false){
			$('#'+_id).val("").focus().select();
		}
	}
	mustFunct = function(_id, _attr){
		$('#'+_id).live("change", (function(){
			_res = makeMustFunctList(_id, _attr);
		}))
		$('#'+_id).live("keyup", (function(e){
			if(e.which === 13 || e.which === 37 || e.which === 38 || e.which === 39 || e.which === 40){
				_res = makeMustFunctList(_id, _attr);
			}
		}))
	}
	
	$("#<?php echo $this->getParameter['controller'] ?>EditButton").live("keyup", (function(e){
		if(e.which === 13){
			makeEditNewForm();
		}
	}))
	$("#<?php echo $this->getParameter['controller'] ?>EditButton").live("click", (function(){
		makeEditNewForm();
	}))
	makeEditNewForm = function(){
		$("#apankFormDefDisplay").css("display", "none");
		$(".urut_"+_focus).focus().select();
	}
	$("#<?php echo $this->getParameter['controller'] ?>CancelButton").live("keyup", (function(e){
		if(e.which === 13){
			makeCancelNewForm();
		}
	}))
	$("#<?php echo $this->getParameter['controller'] ?>CancelButton").live("click", (function(){
		makeCancelNewForm();
	}))
	makeCancelNewForm = function(){
		$(".text, .select, .textarea, .checkbox, ._imgCari, ._imgCariD").attr("disabled", "true").val('');
		$("#apankFormDefDisplay").css("display", "none");
		$("#_prosesAction").val('');
		// makeLoadData("First");
	}
	makeSuccesNewForm = function(_no){
		if(_loadPopUpPilih !== false){
			_loadPopUpPilih.abort();
		}
		
		_loadPopUpPilih = $.ajax({
			type: 'POST',
			url: '<?php echo $this->baseUrl ?>Basic/findNo/&idRef='+$('#_pk').val()+'&id='+_no,
			data: $(this).serialize(),
			success: function(data) {
				$('#errorDisplay').html(data);
				$('#apankForm').empty();
			},
		 });
		makeCancelNewForm();
	}
	makeOnSucees = function(_funct){
		makeSuccesNewForm(_funct);
	}
	makeSuccesDel = function(){
		makeSuccesNewForm(0);
		makeLoadData("Next");
	}
	
	
	$("#formAjaxDefault").postForm(
		{
			act: true,
			submitUrl: [
							["<?php echo $this->getParameter['controller'] ?>prosesButton", "errorDisplay", "<?php echo $this->baseUrl.$this->getParameter['asliGetCotroller'] ?>/proses/"],
						],
		}
	);
	
	
	
	$('#formAjaxDefault').submit(function(e){
		e.preventDefault();
	})

	
	$('#<?php echo $this->getParameter['controller'] ?>Prev').attr("urut", 0);
	$('#<?php echo $this->getParameter['controller'] ?>Next').attr("urut", 1);
	
	<?php if($this->data->add != true){ ?>
		$('.text, .textarea').attr('disabled', true);
	<?php } ?>
	$('.text').attr("autocomplete", 'off');
	var _jumI = "<?php echo $jum ?>";
	var _focus = 0;
	cekReadDis = function(_cls){
		_red = $(_cls).attr('readonly');
		_dis = $(_cls).attr('disabled');
		if(_red !== 'readonly' & _dis !== 'disabled'){
			return false;
		}
		return true;
	}
	makeFocusTrue = function(_cls, _no){
		$(_cls).focus().select();
		_focus = _no;
		return;
	}
	makeFocus = function(){
		for(_i = 0; _i < _jumI; _i++){
			_cls = ".urut_"+_i;
			_cek = cekReadDis(_cls);
			if(_cek === false){
				makeFocusTrue(_cls, _i);
				return;
			}
		}
	}
	makeFocus();
	
	makeDef = function(){
		$(".text, .select, .textarea, .checkbox, .radio").attr("disabled", true);
		$('#<?php echo $this->getParameter['controller'] ?>First').focus().select();
		makeLoadData("First");
	}
	
	cekDetTFFocus = function(_no){
		for(_iDet = 1; _iDet < 30; _iDet++){
			_nomBok = parseInt(_no) + parseInt(_iDet);
			_cekDet = $('.urut_'+_nomBok).attr("id");
			if(_cekDet != undefined){
				return _nomBok;
			}
		}
		return false;
	}
	
	makeFocusUrut = function(_no, _mode, _lastNo, _jumlh){
		if(_mode  === 27){
			_reportMode = $('#_reportMode').val();
			if(_reportMode === undefined){
				$("#apankFormDefDisplay").removeAttr("style");
				$("#_displayErrorPopUp").html("");
				function showDiv() {
					$('._buttonNewNom1').focus().select();
					clearInterval(timer);
				}
				var timer = setInterval( showDiv, 100);
			}
		}
	
		if(_jumlh <= 50){
			if(_mode === 13 || _mode === 38 || _mode === 40){
				_after = undefined;
				if(_mode === 13 || _mode === 40){
					_after = $('.urut_'+_lastNo).attr("after");
					_no = _no + 1;
				}
				if(_mode === 38){
					_no = _no - 1;
				}
				_cls = ".urut_"+_no;
				_before = $(_cls).attr("before");
				if(_before === undefined){
					_foc = true;
				}else{
					_foc = makeFunction(_before, _lastNo, false);
				}
				if(_foc === true){
					
					if(_after === undefined){
						_cekAfter = true;
					}else{
						_cekAfter = makeFunction(_after, _lastNo, false);
						if(_cekAfter !== false){
							// _display = $('.urut_'+_lastNo).attr("display");
							// if(_display !== undefined){
								// makeFunction(_display, _lastNo, _cekAfter);
							// }
						}
					}

					if(_cekAfter !== false){
						_cekKode = $('.urut_'+_no).attr("name");
						if(_cekKode === undefined){
							if(_mode === 13 || _mode === 40){
							
								<?php if(!empty($this->data->detail)){ ?>
									makeFocusDetail(_no);
								<?php }else{ ?>
									_reportMode = $('#_reportMode').val();
									if(_reportMode === undefined){
										$("#apankFormDefDisplay").removeAttr("style");
										$("#_displayErrorPopUp").html("");
										function showDiv() {
											$('._buttonNewNom1').focus().select();
											clearInterval(timer);
										}
										var timer = setInterval( showDiv, 100);
									}
								<?php } ?>
							}
						}else{
							if(_mode === 13 || _mode === 40){
								_nomm = _no - 1;
							}else{
								_nomm = _no;
							}
							_idNm = $('.urut_'+_nomm).attr('id');
							_next = true;
							for(_iN = 0; _iN < _notNull.length; _iN++){
								_jj = _notNull[_iN];
								if(_jj === _idNm){
									_vVal = $('#'+_idNm).val();
									if(_vVal === ''){
										_next = false;
									}
								}
							}
							// if(_mode === 38){
								// alert(_next+' => '+_idNm);
							// }
							if(_next === true){
								_cek = cekReadDis(_cls);
								if(_cek === false){
									makeFocusTrue(_cls, _no);
								}else{
									makeFocusUrut(_no, _mode, _lastNo, _jumlh + 1);
								}
							}
						}
					}
				}
				return;
			}else{
				makeFocusUrut(_no, _mode, _lastNo, _jumlh + 1);
			}
		}
	}
	_mode = false;
	functEnter = function(){
		$('.text, .textarea').keyup(function(e){
			_popUp = $('#_typeBrowse').val();
			if(_popUp === undefined){
				_mode = 'enter';
				if(e.which === 27 || e.which === 13 || e.which === 38 || e.which === 40){
					_no = parseInt($(this).attr('no'));
					makeFocusUrut(_no, e.which, _no, 0);
				}
				_tgl = false;
				_cls = $(this).attr("class");
				_cls = _cls.split(" ");
				for(_i = 0; _i < _cls.length; _i++){
					_md = _cls[_i];
					if(_md === 'tanggal'){
						_tgl = true;
					}
				}
				if(_tgl === false){
					$('#ui-datepicker-div').empty();
				}
			}
		})
	}
	functEnter();
	
	cekNull = function(_idNm){
		for(_iN = 0; _iN < _notNull.length; _iN++){
			_jj = _notNull[_iN];
			if(_jj === _idNm){
				_vVal = $('#'+_idNm).val();
				if(_vVal === ''){
					return false;
				}
			}
		}
		return true;
	}
	functClick = function(){
		$('.text, .textarea').click(function(){
			_mode = 'click';
			_key 	= $('.urut_'+_focus).attr('id');
			_after 	= $('#'+_key).attr("after");
			
			_res = true;
			if(_after !== undefined){
				_no 	= $('#'+_key).attr("no");
				_display= $('#'+_key).attr("display");
				_res = makeFunction(_after, _no, _display);
			}
			if(_res === true){
				_res = cekNull(_key);
				if(_res === true){
					_before = $(this).attr("before");
					_no 	= $(this).attr("no");
					_display= $(this).attr("display");
					if(_before !== undefined){
						_res = makeFunction(_before, _no, _display);
					}
				}
			}

			if(_res === true){
				_cls = '#'+this.id;
				_no = $(this).attr('no');
				makeFocusTrue(_cls, _no);
			}else{
				$('.urut_'+_focus).focus().select();
			}
		})
	}
	functClick();
	
	makeTimeFocus = function(){
		function showDiv() {
			$('.urut_'+_focus).focus().select();
			clearInterval(timer);
		}
		
		var timer = setInterval( showDiv, 300);
	}
	$('#_closePopUp').live('keypress', (function(e){
		makeTimeFocus();
	}))
	$('#_closePopUp, #apankFormCloseButton').live('click', (function(e){
		makeTimeFocus();
	}))
	makeNextFocusTrue = function(_no, _jum){
		if(_jum < 100){
			_no = parseInt(_no) + 1;
			_cls = '.urut_'+_no;
			_cek = cekReadDis(_cls);
			if(_cek === false){
				makeFocusTrue(_cls, _no);
			}else{
				makeNextFocusTrue(_no, _jum+1);
			}
		}
	}
	makeKiriKanan = function(_no, _jen){
		_no = parseInt(_no);
		if(_jen === 'min'){
			_no = _no - 1;
		}else{
			_no = _no + 1;
		}
		$('._urut_'+_no).focus().select();
	}
	makeAtasBawah = function(_no, _jen){
		_no = parseInt(_no);
		if(_jen === 'min'){
			_no = _no - 1;
		}else{
			_no = _no + 1;
		}
		if(_no === 0){
			$('._urut_0').focus().select();
		}else{
			$('._noGrid_'+_no).focus().select();
		}
	}
	$('._linkPopUp').live('keyup', (function(e){
		if(e.which === 37){
			makeKiriKanan($(this).attr('urut'), 'min');
		}
		if(e.which === 39){
			makeKiriKanan($(this).attr('urut'), 'plus');
		}
		if(e.which === 38){
			makeAtasBawah($(this).attr('nomor'), 'min');
		}
		if(e.which === 40){
			makeAtasBawah($(this).attr('nomor'), 'plus');
		}
		if(e.which === 27){
			$('#apankForm').empty();
		}
	}))
	
	
	var _loader = false;
	var _urut = 0;
	makeLoadData = function(_type){
		<?php if($loadDataNavigator == true){ ?>
			_type = _type.toLowerCase();
			$("#kodegrup").val("Load...");
			
			if(_loader !== false){
				_loader.abort();
			}
			$('#apankFormLoadingProgres').removeAttr("style");
			_loader = $.ajax({
			type: "GET",
				url: "<?php echo $this->baseUrl.$this->getParameter['asliGetCotroller'] ?>/Find/&no="+_urut+"&jenis="+_type+"&idRef="+$('#_pk').val()+"&nojnl=<?php echo $_GET['nojnl'] ?>",
				data: $(this).serialize(),
				success: function(data) {
					$("#errorDisplay").html(data);
					$('#apankFormLoadingProgres').css("display", "none");
				}
			})	
		<?php } ?>
	}
	
	makeLoadData('First');

	makeAdd = function(){
		<?php if($loadAdd == true){ ?>
			<?php foreach($loadSimpan as $r){ ?>
				$('#<?php echo $r ?>').removeAttr('readonly');
			<?php } ?>
			<?php foreach($hideSimpan as $r){ ?>
				$('#<?php echo $r ?>').attr('readonly', true);
			<?php } ?>
			<?php if($this->data->addClear == false){ ?>
				$(".text, .select, .textarea, ._imgCari, ._imgCariD").removeAttr("disabled");
				$(".checkbox").removeAttr("disabled");
				makeFocus();
			<?php }else{ ?>
				$(".text, .select, .textarea, ._imgCari, ._imgCariD").val("").removeAttr("disabled");
				$(".checkbox").removeAttr("checked").removeAttr("disabled");
				makeFocus();
			<?php } ?>
			$("#_prosesAction").val("simpan");
		<?php } ?>
	}
	
	makeEdit = function(){
		<?php if($loadEdit == true){ ?>
			<?php foreach($loadUpdate as $r){ ?>
				$('#<?php echo $r ?>').removeAttr('readonly');
			<?php } ?>
			<?php foreach($hideUpdate as $r){ ?>
				$('#<?php echo $r ?>').attr('readonly', true);
			<?php } ?>
			$(".text, .select, .textarea, ._imgCari, ._imgCariD").removeAttr("disabled");
			$(".checkbox").removeAttr("disabled");
			makeFocus();
			$("#_prosesAction").val("update");
		<?php } ?>
	}
	makeView = function(){
		<?php if($loadView == true){ ?>
			$(".text, .select, .textarea").removeAttr("disabled");
			$(".checkbox").removeAttr("disabled");
			makeFocus();
			$("#_prosesAction").val("update");
		<?php } ?>
	}
	
	makePrintTrue = function(){
		<?php 
		if($loadPrint == true){
			if($this->data->cetak != false){ ?>
			$('#apankFormFilter').removeAttr("style");
			$('.filter_0').focus().select();
			
			<?php 
			if($this->data->cetak != false){
				foreach($this->data->cetak->attr as $kF => $row){ 
					if($row['filter'] == true){
						$id = "filPrint".str_ireplace(".", "", $row['attr']);

				?>
					_defFil = $('#<?php echo $id ?>').attr("default");
					$('#<?php echo $id ?>').val($('#'+_defFil).val());
			<?php 
					}
				}
			} 
			?>
		<?php 
			}
		} 
		?>
	}
	
	$.Shortcuts.add({
		type: "down",
		mask: "F",
		handler: function() {
			_urut = 0;
			makeLoadData("First");
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "L",
		handler: function() {
			_urut = 0;
			makeLoadData("Last");
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "N",
		handler: function() {
			_urut = $('#<?php echo $this->getParameter['controller'] ?>Next').attr("urut");
			makeLoadData("Next");
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "P",
		handler: function() {
			_urut = $('#<?php echo $this->getParameter['controller'] ?>Prev').attr("urut");
			makeLoadData("Prev");
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "B",
		handler: function() {
			<?php if($loadBrowse == true){ ?>
				makePopUpTop(1000, 70, "<?php echo $this->baseUrl.$this->getParameter['asliGetCotroller'].'/data/' ?>&page="+$('#_pageActive').val()+'&pkBrowse='+$('#_pk').val());
			<?php } ?>
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "C",
		handler: function() {
			makeFormBarcode();
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "f3",
		handler: function() {
			makeCalculate();
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "A",
		handler: function() {
			_add = $('#<?php echo $this->getParameter['controller'].'Add' ?>').attr("id");
			if(_add !== undefined){
				makeAdd();
			}
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "E",
		handler: function() {
			<?php if($loadEdit == true){ ?>
				_add = $('#<?php echo $this->getParameter['controller'].'Edit' ?>').attr("id");
				if(_add !== undefined){
					makeEdit();
				}
			<?php } ?>
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "V",
		handler: function() {
			<?php if($loadView == true){ ?>
				_add = $('#<?php echo $this->getParameter['controller'].'View' ?>').attr("id");
				if(_add !== undefined){
					makeView();
				}
			<?php } ?>
		}
	}).start();
	// $.Shortcuts.add({
		// type: "down",
		// mask: "Esc",
		// handler: function() {
			// makeDef();
			// $("#apankForm").empty();
			// $("#apankFormDefDisplay").css("display", "none");
		// }
	// }).start();
	$.Shortcuts.add({
		type: "down",
		mask: "D",
		handler: function() {
			makeDel();
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "G",
		handler: function() {
			makePending();
		}
	}).start();
	$.Shortcuts.add({
		type: "down",
		mask: "T",
		handler: function() {
			makePrintTrue();
		}
	}).start();
	
	makeDel = function(){
		<?php if($loadDel == true){ ?>
			$("#tempGridFocus").focus().select();
			if(confirm("Yakin menghapus?")){          
				
				_url = '<?php echo $this->baseUrl.$this->getParameter['asliGetCotroller'].'/delete/&del=true' ?>';
				<?php foreach($this->data->dBasePk as $row){ ?>
					_url2= "&<?php echo $row ?>="+str_ireplace("+", "___", $('#<?php echo $row?>').val());
					_url2= str_ireplace("/", "__--__", _url2);
					_url+= _url2;
				<?php } ?>
				
				$.ajax({
				type: "POST",
					url: _url,
					data: $(this).serialize(),
					success: function(data) {
						$("#errorDisplay").html(data);
					}
				})
			}
		<?php } ?>
	}
	
	makePending = function(){
		<?php if($loadPending == true){ ?>
			$("#tempGridFocus").focus().select();
			if(confirm("Yakin Pending Transaksi ini?")){          
				
				_url = '<?php echo $this->baseUrl.$this->getParameter['asliGetCotroller'].'/pending/' ?>';
				<?php foreach($this->data->dBasePk as $row){ ?>
					_url2= "&<?php echo $row ?>="+str_ireplace("+", "___", $('#<?php echo $row?>').val());
					_url2= str_ireplace("/", "__--__", _url2);
					_url+= _url2;
				<?php } ?>
				
				$.ajax({
				type: "POST",
					url: _url,
					data: $(this).serialize(),
					success: function(data) {
						$("#errorDisplay").html(data);
					}
				})
			}
		<?php } ?>
	}
	
	$('#<?php echo $this->getParameter['controller'] ?>Save').click(function(){
		_act = $('#_prosesAction').val();
		if(_act === 'simpan' || _act === 'update'){
			$("#apankFormDefDisplay").removeAttr("style");
			$("#_displayErrorPopUp").html("");
			function showDiv() {
				$('._buttonNewNom1').focus().select();
				clearInterval(timer);
			}
			var timer = setInterval( showDiv, 100);
		}
	})
	$('#<?php echo $this->getParameter['controller'] ?>First').click(function(){
		_urut = 0;
		makeLoadData("First");
	})
	$('#<?php echo $this->getParameter['controller'] ?>Last').click(function(){
		_urut = 0;
		makeLoadData("Last");
	})
	$('#<?php echo $this->getParameter['controller'] ?>Next').click(function(){
		_urut = $(this).attr("urut");
		makeLoadData("Next");
	})
	$('#<?php echo $this->getParameter['controller'] ?>Prev').click(function(){
		_urut = $(this).attr("urut");
		makeLoadData("Prev");
	})
	$('#<?php echo $this->getParameter['controller'] ?>Browse').click(function(){
		<?php if($loadBrowse == true){ ?>
			makePopUpTop(1000, 70, "<?php echo $this->baseUrl.$this->getParameter['asliGetCotroller'].'/data/' ?>&page="+$('#_pageActive').val()+'&pkBrowse='+$('#_pk').val());
		<?php } ?>
	})
	$('#<?php echo $this->getParameter['controller'] ?>Add').click(function(){
		makeAdd();
	})
	$('#<?php echo $this->getParameter['controller'] ?>Edit').click(function(){
		makeEdit();
	})
	$('#<?php echo $this->getParameter['controller'] ?>View').click(function(){
		makeView();
	})
	$('#<?php echo $this->getParameter['controller'] ?>Del').click(function(){
		makeDel();
	})
	$('#<?php echo $this->getParameter['controller'] ?>pendinG').click(function(){
		makePending();
	})
	$('#<?php echo $this->getParameter['controller'] ?>barCode').click(function(){
		makeFormBarcode();
	})
	$('#<?php echo $this->getParameter['controller'] ?>calc').click(function(){
		makeCalculate();
	})
	$('#<?php echo $this->getParameter['controller'] ?>prinT').click(function(){
		makePrintTrue();
	})
	
	
	// _loadPopUp = false;
	// $('#<?php echo $this->getParameter['controller'] ?>Data .inputGrid').live("keyup", (function(e){
		// if(e.which === 13){
			// if(_loadPopUp !== false){
				// _loadPopUp.abort();
			// }
			
			// _loadPopUp = $.ajax({
				// type: 'POST',
				// url: '<?php echo $this->baseUrl.'Basic/cariData/&modul='.$this->getParameter['controller'] ?>',
				// data: $(this).serialize(),
				// success: function(data) {
					// $('#apankFormContent').html(data);
					// _focus = $('#setFocus').val();
					// $('#'+_focus).focus().select();
				// },
			 // });
		// }
	// }))
	_loadPopUpPilih = false;
	makePilihPopUp = function(_val, _kode){
		_val = parseInt(_val);
		_val = _val - 1;
		_p = _val - 1;
		_n = _val + 1;
		if(_p <= 0){
			_p = 0;
		}
		
		$('#apankFormLoadingProgres').removeAttr("style");
		if(_loadPopUpPilih !== false){
			_loadPopUpPilih.abort();
		}
		_loadPopUpPilih = $.ajax({
			type: 'POST',
			url: '<?php echo $this->baseUrl.'Basic/pilih/&modul='.$this->getParameter['controller'] ?>&id='+_kode+'&p='+_p+'&n='+_n,
			data: $(this).serialize(),
			success: function(data) {
				$('#errorDisplay').html(data);
				$('#apankForm').empty();
				$('#apankFormLoadingProgres').css("display", "none");
			},
		 });
	}
	$('#<?php echo $this->getParameter['controller'] ?>Data ._inputPilih').live("keypress", (function(e){
		if(e.which === 13){
			if(_loadPopUp !== false){
				_loadPopUp.abort();
			}
			$('#apankForm').empty();
			makePilihPopUp($(this).val(), $(this).attr('kode'));
		}
	}))
	$('#<?php echo $this->getParameter['controller'] ?>Data tbody tr').live("dblclick", (function(e){
		_id = this.id;
		_id = _id.split('_');
		_id = _id[1];
		_id = _id.split('|||||');
		_id = _id[0];
		makePilihPopUp(1, _id);
	}))
	
	makeNextFocus = function(_no, _jum){
		if(_jum <= 50){
			_no = parseInt(_no);
			_no = _no + 1;
			
			_idS = '.urut_'+_no;
			_idN = $(_idS).attr('id');
			if(_idN !== undefined){
				_red = $(_idS).attr('disabled');
				_dis = $(_idS).attr('readonly');

				if(_red === undefined & _dis === undefined){
					makeFocusTrue('.urut_'+_no, _no);
				}else{
					makeNextFocus(_no, _jum+1);
				}
				
			}
		}
	}
	makeCekNotNull = function(_no){
		_idNm = $('.urut_'+_no).attr('id');
		_next = true;
		for(_iN = 0; _iN < _notNull.length; _iN++){
			_jj = _notNull[_iN];
			if(_jj === _idNm){
				_vVal = $('#'+_idNm).val();
				if(_vVal === ''){
					_next = false;
				}
			}
		}

		if(_next === true){
			makeNextFocus(_no, 1);
		}
		$("._popUpDef").css("display", "none");
	}
	$('.meioMask').setMask();
	$('.tanggal').change(function(){
		_cekTgl(this.id);
	})
	$(".tanggal").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: 'dd/mm/yy', 
		yearRange: '1900:<?php echo ( date("Y") + 5)  ?>',
		showOn: 'button',
		buttonImage: '<?php echo $this->baseUrl ?>assets/images/date.png',
	});
	$("#tglDefault,#tglDefaultAw,#tglDefaultAk").datepicker({
		changeMonth: true,
		changeYear: true,
		dateFormat: 'dd/mm/yy', 
		yearRange: '1900:<?php echo ( date("Y") + 5)  ?>',
	});
	$("#tglDefault").change(function(){
		$('#tglDefault').load("<?php echo $this->baseUrl ?>Basic/defDate/&idDate="+$('#tglDefault').val());
	});
	$("#tglDefaultAw,#tglDefaultAk").change(function(){
		$('#tglDefault').load("<?php echo $this->baseUrl ?>Basic/defDate2/&tglaw="+$('#tglDefaultAw').val()+"&tglak="+$('#tglDefaultAk').val());
	});
	$('.ui-widget-content').css('display', 'none');
	<?php if(!empty($this->data->funct)){ ?>
		makeFungsiControl("<?php echo $this->data->funct ?>");
	<?php } ?>

	loadAutoNumber = false;
	<?php
	if(!empty($this->data->autoNumber)){
		foreach($this->data->autoNumber as $key => $row){
			$id = "";
			$get = "";
			foreach($row['attr'] as $row2){
				if(!empty($id)){
					$id.= ", ";
				}
				$id.= "#$row2";
				$get.= '&$row2="+$("#$row2").val()';
			}
	?>	
		makeGenAutoNumber = function(){
			_act = $('#_prosesAction').attr('value');
			if(_act === 'simpan'){
				if(loadAutoNumber != false){
					loadAutoNumber.abort();
				}
				
				_url = "<?php echo $this->baseUrl.$this->getParameter['controller'].'/'.$row["act"].'/' ?>";
				<?php 
				foreach($row['attr'] as $row2){
				?>
					_url+= "&<?php echo $row2 ?>="+str_ireplace("+", "||", str_ireplace("/", "___", $('#<?php echo $row2 ?>').val()));
				<?php } ?>
				
				$('#<?php echo $key ?>').val("Generate...");
				loadAutoNumber = $.ajax({
				type: "GET",
					url: _url,
					data: $(this).serialize(),
					success: function(data) {
						$('#<?php echo $key ?>').val(data);
					}
				})
			}
		}
	
		$("<?php echo $id ?>").change(function(){
			makeGenAutoNumber();
		})
	<?php
		}
	}
	?>
	
	$.Shortcuts.add({
		type: "down",
		mask: "Ctrl+Q",
		handler: function() {
			$('#head_left').focus().select();
		}
	}).start();
	$('.inManGrid').live("keyup", (function(e){
		_baris = parseInt($(this).attr("baris"));
		_kolom = parseInt($(this).attr("kolom"));
		
		if(e.which == 37){
			_kolom = _kolom - 1;
		}
		if(e.which == 39){
			_kolom = _kolom + 1;
		}
		if(e.which == 38){
			_baris = _baris - 1;
		}
		if(e.which == 40){
			_baris = _baris + 1;
		}
		_id = '#_td_'+_baris+'_'+_kolom;
		$(_id).focus().select();
	}))
	
	_maxHeightContent = parseInt('<?php echo $height ?>');
	if(_maxHeightContent > 400){
		_maxHeightContent = _maxHeightContent + 170;
		$('#apankTema2016Right').css("height", _maxHeightContent+'px');
		$('#apankTema2016Line').css("height", _maxHeightContent+'px');
		$('#apankTema2016Left').css("height", _maxHeightContent+'px');
	}
})

</script>