$(document).ready(function() {
	$('.meioMask').setMask();
	
	$('#button_fv_menu_favorite').click(function(){
		classFvMenu = $('#button_fv_menu_favorite').attr('class');
		$('#button_fv_menu_favorite').removeAttr('class');
		if(classFvMenu != 'hide_fv'){
			$('#favorit_menu').slideUp();
			$('#button_fv_menu_favorite').addClass('hide_fv');
		}else{
			$('#favorit_menu').slideDown("slow");
		}
	})
	
    $("a.tab").click(function () {
        $(".active").removeClass("active");
        $(this).addClass("active");
        $(".content").css('display', 'none');
        // $(".content").slideUp();
        var content_show = $(this).attr("title");
        // $("#"+content_show).slideDown();
        $("#"+content_show).removeAttr('style');
    });
    $("a.tab_2").click(function () {
        $(".active_2").removeClass("active_2");
        $(this).addClass("active_2");
        // $(".content_2").slideUp();
        var content_show = $(this).attr("title");
        // $("#"+content_show).slideDown();
    });
	makeEmptyForm = function(){
		$('.text, .textarea, .select').val('');
		$('#simpan').removeAttr('style');
		$('#update').css('display', 'none');
	}
	_loadPopUpTop = false;
	makePopUpTop = function(width, top, url){
		$('#apankForm').html('<div id="apankForm_1" style="width: '+width+'px;"></div>');
		$('#apankForm_1').html('<div id="apankForm_2" style="margin-top: '+top+'px"></div>');
		$('#apankForm_2').html('<div id="apankForm_3"></div>');
		$('#apankForm_3').html('<div id="apankForm_close"></div>');
		$('#apankForm_close').html('<input type="button" id="apankFormCloseButton" title="Close Form"><div id="apankFormContent"></div>');
		$('#apankFormContent').html('<div id="apankFormContentLogin"></div>');
		
		if(_loadPopUpTop != false){
			_loadPopUpTop.abort();
		}
		
		_loadPopUpTop = $.ajax({
		type: 'POST',
			url: url,
			data: $(this).serialize(),
			success: function(data) {
				$('#apankFormContent').html(data);
			}
		})
		
	}
	makePopUpNotLoad = function(width, top, content){
		$('#apankForm').html('<div id="apankForm_1" style="width: '+width+'px;"></div>');
		$('#apankForm_1').html('<div id="apankForm_2" style="margin-top: '+top+'px"></div>');
		$('#apankForm_2').html('<div id="apankForm_3"></div>');
		$('#apankForm_3').html('<div id="apankForm_close"></div>');
		$('#apankForm_close').html('<input type="button" id="apankFormCloseButton" title="Close Form"><div id="apankFormContent"></div>');
		$('#apankFormContent').html('<div id="apankFormContent">'+content+'</div>');
	}
	makePopUpDefaultDisplay = function(width, top, content, _div, _id){
		$('#'+_div).html('<div id="apankForm_1_'+_id+'" class="apankForm_1" style="width: '+width+'px;"></div>');
		$('#apankForm_1_'+_id).html('<div id="apankForm_2_'+_id+'" class="apankForm_2" style="margin-top: '+top+'px"></div>');
		$('#apankForm_2_'+_id).html('<div id="apankForm_3_'+_id+'" class="apankForm_3"></div>');
		$('#apankForm_3_'+_id).html('<div id="apankForm_close_'+_id+'" class="apankForm_close"></div>');
		$('#apankForm_close_'+_id).html('<div id="apankFormContent_'+_id+'" class="apankFormContent"></div>');
		$('#apankFormContent_'+_id).html('<div id="apankFormContent_'+_id+'">'+content+'</div>');
	}
	makePopUpDisplay = function(width, top, content){
		$('#apankForm').html('<div id="apankForm_1" style="width: '+width+'px;"></div>');
		$('#apankForm_1').html('<div id="apankForm_2" style="margin-top: '+top+'px"></div>');
		$('#apankForm_2').html('<div id="apankForm_3"></div>');
		$('#apankForm_3').html('<div id="apankForm_close"></div>');
		$('#apankForm_close').html('<input type="button" id="apankFormCloseButton" title="Close Form"><div id="apankFormContent"></div>');
		$('#apankFormContent').html('<div id="apankFormContent">'+content+'</div>');
	}
	makePopUpTok = function(width, top){
		$('#apankForm').html('<div id="apankForm_1" style="width: '+width+'px;"></div>');
		$('#apankForm_1').html('<div id="apankForm_2" style="margin-top: '+top+'px"></div>');
		$('#apankForm_2').html('<div id="apankForm_3"></div>');
		$('#apankForm_3').html('<div id="apankForm_close"></div>');
		$('#apankForm_close').html('<input type="button" id="apankFormCloseButton" title="Close Form"><div id="apankFormContent"></div>');
		$('#apankFormContent').html('<div id="apankFormContentLogin"></div>');
	}
	
	makePopUpDouble = function(width, top, div, url){
		minimize = '<input type="button" id="'+div+'MinimizeButton" class="apankFormMButton" title="Minimize Form" alt="true">';
		close = '<input type="button" id="'+div+'CloseButton" class="apankFormCloseButton" title="Close Form">';
	
		$('#'+div).html('<div id="'+div+'_1" class="apankForm_1" style="width: '+width+'px;"></div>');
		$('#'+div+'_1').html('<div id="'+div+'_2" class="apankForm_2" style="margin-top: '+top+'px"></div>');
		$('#'+div+'_2').html('<div id="'+div+'_3" class="apankForm_3"></div>');
		$('#'+div+'_3').html('<div id="'+div+'_close" class="apankForm_close"></div>');
		$('#'+div+'_close').html(minimize+close+'<div id="'+div+'Content" class="apankFormContent"></div>');
		$('#'+div+'Content').html('<div id="'+div+'ContentLogin" class="apankFormContentLogin"></div>');
		$('#'+div+'Content').load(url);
		makeCloseButton(div);
		makeMinimizeButton(div);
	}
	makeCloseButton = function(div){
		$('#'+div+'CloseButton').click(function(){
			$('#'+div).empty();
		})
	}
	makeApankFormLoading = function(){
		$('#apankForm').html('<div id="apankConfirm_1" style="width: 100%;"></div>');
		$('#apankConfirm_1').html('<div id="apankConfirm_2" style="width: 200px;"></div>');
		$('#apankConfirm_2').html('<div id="apankFormLoad" style="margin-top: 300px"></div>');
		$('#apankFormLoad').html('<div class="apankFormLoading">&nbsp;</div>');
	}
	
	
	makeActScrol = function(){
		// alert('apank');
	}
	makeScrolItem = function(){
		$('.text, .textarea, .inputGrid').live('keypress', (function(e){
			makeActScrol();
		}))
		$.Shortcuts.add({
			type: 'down',
			mask: 'ctrl',
			handler: function() {
				makeActScrol();
			}
		}).start();
	}
	
	makeActiveBarcode = function(param){
		$('.text, .textarea, .select, .checkbox, .radio').live('keyup', (function(e){
			if(e.keyCode === 112){
				makeLoadBar(param);
			}
		}))
		sortF1(param);
	}
	makeDiskon = function(){
		$('.diskon').attr('maxlength', 5).attr('size', 4).css('text-align', 'right').val('0');

		makeCekNol =  function(_val){
			_exVal = _val.split('');
			_jum   = parseInt(_val.length);
			
			if(_exVal[0] === '0' & _jum > 1){
				if(_exVal[1] !== '.'){
					_nVal  =  '';
					for(i = 1; i < _jum; i++){
						_nVal+= _exVal[i];
					}
				}
			}else if(_exVal[0] === '.'){
				_nVal  =  '0.';
				for(i = 1; i < _jum; i++){
					_nVal+= _exVal[i];
				}
			}else if(_val > 100){
				_nVal  =  '100';
			}else{
				_nVal = _val;
			}
			
			_exVal = _nVal.split('');
			_jum   = parseInt(_nVal.length);
			_nVal  = '';
			_titik = 0;
			
			for(i = 0; i < _jum; i++){
				
				_insT  = true;
				
				if(_exVal[i] === '.'){
					
					if(_titik > 0){
						_insT = false;
					}
					_titik = _titik + 1;
				}
				
				if(_insT === true){
					_nVal+= _exVal[i];
				}
			}
			
			return _nVal;
		}
		
		$('.diskon').live('keyup', (function(e){
			_keyUp = e.which;
			_idIn  = this.id;
			_val   = $('#'+_idIn).val();
			_jum   = parseInt(_val.length);
			
			_exVal = _val.split('');
			_nVal  =  '';
			for(i = 0; i < _jum; i++){
				if(_exVal[i] === '0' || _exVal[i] === '1' || _exVal[i] === '2' || _exVal[i] === '3' || _exVal[i] === '4' || _exVal[i] === '5' || _exVal[i] === '6' || _exVal[i] === '7' || _exVal[i] === '8' || _exVal[i] === '9' || _exVal[i] === '.'){
					_nVal+= _exVal[i];
				}
			}
			
			_nVal = makeCekNol(_nVal);
			
			$('#'+_idIn).val(_nVal);
			
		})).live('change', (function(){
			__idIn  = this.id;
			__val   = $('#'+__idIn).val();
			
			if(__val === ''){
				$('#'+__idIn).val('0');
			}
		}))
	}
	makeDiskon();
	
	makeAngka = function(){
		$('.angka').live('change', (function(e){
			_idIn  = this.id;
			_val   = $('#'+_idIn).val();
			_jum   = parseInt(_val.length);
			
			if(_jum > 0){
				_exVal = _val.split('');
				_nVal  =  '';
				for(i = 0; i < _jum; i++){
					if(_exVal[i] === '0' || _exVal[i] === '1' || _exVal[i] === '2' || _exVal[i] === '3' || _exVal[i] === '4' || _exVal[i] === '5' || _exVal[i] === '6' || _exVal[i] === '7' || _exVal[i] === '8' || _exVal[i] === '9' || _exVal[i] === '.'){
						_nVal+= _exVal[i];
					}
				}
			}else{

			}
			
			if(_val === ''){
				_nVal = '';
			}
			
			_tVal = _nVal.split('.');
			_tValPanjang = _tVal.length;
			_dec = 0;
			if(_tValPanjang > 1){
				_dec = _tVal[1].length;
			}
			
			_nVal = accounting.formatNumber(_nVal, _dec, ',', '.');
			$('#'+_idIn).val(_nVal).removeAttr('style').css('text-align', 'right');
		}));
	}
	makeAngka();
	
	makeTanggal = function(){
		$('.tanggal').live('keyup', (function(e){
			_idIn  = this.id;
			_val   = $('#'+_idIn).val();
			_jum   = parseInt(_val.length);
			__val  = _val.split('');
			_fVal  = '';
				
			no = 0;
			__nVal = [null, null];
			
			for(i = 0; i < _jum; i++){
				nilai = __val[i];
				if(nilai >= 0 & nilai <= 9){
					no = no + 1;
					__nVal[no] = __val[i];
				}
			}
			
			_tgl = 'f';
			_bln = 'f';
			_thn = 'f';
			
			if(no >= 1){
				_tgl = __nVal[1];
			}
			if(no >= 2){
				_tgl+= __nVal[2];
			}
			if(no >= 3){
				_bln = __nVal[3];
			}
			if(no >= 4){
				_bln+= __nVal[4];
			}
			if(no >= 5){
				_thn = __nVal[5];
			}
			if(no >= 6){
				_thn+= __nVal[6];
			}
			if(no >= 7){
				_thn+= __nVal[7];
			}
			if(no >= 8){
				_thn+= __nVal[8];
			}
			
			_iTgl = parseInt(_tgl);
			if(_iTgl > 31){
				$('#errorApank'+_idIn).html("Max bulan 31");
				$('#'+_idIn).val('');
				return;
			}else{
				_fVal = _tgl;
			}
			
			_iBln = parseInt(_bln);
			if(_iBln > 12){
				$('#errorApank'+_idIn).html("Max bulan 12");
				$('#'+_idIn).val(_tgl);
				return;
			}else if(_bln !== 'f'){
				_fVal+= '/'+_bln;
			}
			
			if(_thn !== 'f'){
				_fVal+= '/'+_thn;
			}
			
			if(_fVal === 'f'){
				_fVal = '';
			}
			
			$('#'+_idIn).val(_fVal);
		})).live("change", function(){
			_idIn  = this.id;
			_val   = $('#'+_idIn).val();
			_cekTgl(this.id);
		}).live("keyup", (function(e){
			if(e.which === 40 || e.which === 13 || e.which === 38 || e.which === 39 || e.which === 37){
				_cekTgl(this.id);
			}
		}))
		
		_cekTgl = function(_id){
			_notNull = $('#'+_id).attr("notnull");
			_date = $('#'+_id).val();
			_date = _date.split('/');
			_cDate = true;
			_pesanError = '';
			if(_date.length !== 3){
				_cDate = false;
				_pesanError = 'Format Tanggal dd/mm/yyyy';
			}else{
				if(parseInt(_date[2]) === 0){
					_cDate = false;
					_pesanError = 'Tahun tidak boleh 0';
				}
				if(parseInt(_date[1]) === 0){
					_cDate = false;
					_pesanError = 'Bulan tidak boleh 0';
				}
				if(parseInt(_date[0]) === 0){
					_cDate = false;
					_pesanError = 'Tanggal tidak boleh 0';
				}
				if(parseInt(_date[1]) > 12){
					_cDate = false;
					_pesanError = 'Bulan Max 12';
				}
				if(_date[2].length !== 4){
					_cDate = false;
					_pesanError = 'Tahun harus 4 digit';
				}
				
				if(parseInt(_date[1]) === 1){
					_maxDate = 31;
				}else if(parseInt(_date[1]) === 3){
					_maxDate = 31;
				}else if(parseInt(_date[1]) === 4){
					_maxDate = 30;
				}else if(parseInt(_date[1]) === 5){
					_maxDate = 31;
				}else if(parseInt(_date[1]) === 6){
					_maxDate = 30;
				}else if(parseInt(_date[1]) === 7){
					_maxDate = 31;
				}else if(parseInt(_date[1]) === 8){
					_maxDate = 31;
				}else if(parseInt(_date[1]) === 9){
					_maxDate = 30;
				}else if(parseInt(_date[1]) === 10){
					_maxDate = 31;
				}else if(parseInt(_date[1]) === 11){
					_maxDate = 30;
				}else if(parseInt(_date[1]) === 12){
					_maxDate = 31;
				}else{
					_thn = parseInt(_date[2]);
					_sisa = _thn % 4;
					if(_sisa === 0){
						_maxDate = 29;
					}else{
						_maxDate = 28;
					}
				}
				if(parseInt(_date[0]) > _maxDate){
					_cDate = false;
					_pesanError = 'Max Tanggal di bulan ini '+_maxDate;
				}
			}
			
			if(_cDate === false & _notNull != undefined ){
				function showDiv() {
					makeFocusTrue('#'+_id, $('#'+_id).attr('no'));
					$('#pesanError').remove();
					$('.ui-datepicker-header').before("<div id='pesanError'>"+_pesanError+"</div>");
					clearInterval(timer);
				}
				var timer = setInterval( showDiv, 100);
			}
			return _cDate
		}
	}
	makeTanggal();
	
	makeNullAuto = function(){
		$('.textarea, .text').live('keyup', (function(){
			auto = this.autocomplete;
			if(auto !== 'off'){
				$('.divApankAutocompleteTop').empty();
			}
		}))
	}
	makeNullAuto();
	
	makeEditDetail = function(){
		$('.update').keyup(function(e){
			if (e.which == 13) {
				$('#qty').focus();
			}else if(e.which == 39){
				id = this.alt;
				$('.del_'+id).focus();
			}else if(e.which == 40){
				id = this.alt;
				id = parseInt(id) + 1;
				aktif = $('.up_'+id).attr('id');
				if(aktif !== ''){
					$('.up_'+id).focus();
				}
			}else if(e.which == 38){
				id = this.alt;
				id = parseInt(id) - 1;
				if(id >= 1){
					$('.up_'+id).focus();
				}
			}	
			
			if(e.which === 35){
				makeSaving();
			}else{
				makeNullSaving();
			}
		});			
		$('.delete').keyup(function(e){
			if(e.which == 37){
				id = this.alt;
				$('.up_'+id).focus();
			}else if(e.which == 40){
				id = this.alt;
				id = parseInt(id) + 1;
				aktif = $('.del_'+id).attr('id');
				if(aktif !== ''){
					$('.del_'+id).focus();
				}
			}else if(e.which == 38){
				id = this.alt;
				id = parseInt(id) - 1;
				if(id >= 1){
					$('.del_'+id).focus();
				}
			}	
			
			if(e.which === 35){
				makeSaving();
			}else{
				makeNullSaving();
			}
		});			
		
		$.Shortcuts.add({
			type: 'down',
			mask: 'F2',
			handler: function() {
				$('.up_1').focus();
			}
		}).start();
	}
	
	makeColDetail = function(home, f_2, jArray, nArray){
		$('.hitung').keyup(function(e){
			
			$('#apankForm, .divApankAutocompleteTop').empty();
			kode = e.which;
			nId  = 'off';
			
			if(kode === 36){
				$('#'+home).focus();
			}
			if(kode === 35){
				makeSaving();
			}else{
				makeNullSaving();
			}
			
			i = this.id;
			i = i.split('_');
			c = $('#'+this.id).attr('class');
			c = c.split(' ');
			read = $('#'+this.id).attr('readonly');
			
			if(read === 'readonly'){
				if(kode === 13){
					c[0] = 'inputNone';
					$('#'+this.id).removeAttr('readonly').removeAttr('class').addClass(c[0]+' '+c[1]+' '+c[2]+' '+c[3]);
				}
				if(kode === 39){
					for(nn = 1; nn <= jArray; nn++){
						if(i[0] === nArray[nn+'_id']){
							nNo = nn + 1;
							nId = '.'+nArray[nNo+'_cl']+'_'+i[1];
						}
					}
				}
				if(kode === 37){
					for(nn = 1; nn <= jArray; nn++){
						if(i[0] === nArray[nn+'_id']){
							nNo = nn - 1;
							nId = '.'+nArray[nNo+'_cl']+'_'+i[1];
						}
					}
				}
				if(kode === 40){
					num = parseInt(i[1]);
					num = num+1;
					for(nn = 1; nn <= jArray; nn++){
						if(i[0] === nArray[nn+'_id']){
							nId = '.'+nArray[nn+'_cl']+'_'+num;
						}
					}
				}
				if(kode === 38){
					num = parseInt(i[1]);
					num = num-1;
					for(nn = 1; nn <= jArray; nn++){
						if(i[0] === nArray[nn+'_id']){
							nId = '.'+nArray[nn+'_cl']+'_'+num;
						}
					}
				}
			}else{
				if(kode === 13 || kode === 36){
					c[0] = 'inputGrid';
					$('#'+this.id).attr('readonly', true).removeAttr('class').addClass(c[0]+' '+c[1]+' '+c[2]+' '+c[3]+' readonly');
				}
				if(kode === 13){
					num = parseInt(i[1]);
					num = num+1;
					for(nn = 1; nn <= jArray; nn++){
						if(i[0] === nArray[nn+'_id']){
							nNo = nn + 1;
							nId = '.'+nArray[nNo+'_cl']+'_'+i[1];
						}
					}
					if(i[0] === nArray[jArray+'_id']){
						nId = '.'+nArray['1_cl']+'_'+num;
					}
				}
			}
			
			if(nId !== 'off'){
				$(nId).focus();
			}
		})
		
		$('.hitung').change(function(){
			c = $('#'+this.id).attr('class');
			c = c.split(' ');
			$('#'+this.id).attr('readonly', true).removeAttr('class').addClass(c[0]+' '+c[1]+' '+c[2]+' '+c[3]+' readonly');
		})
		
		$.Shortcuts.add({
			type: 'down',
			mask: 'F2',
			handler: function() {
				$('.'+f_2).focus();
			}
		}).start();
	}
	
	makeGenKode = function(param){
		id  = param['id'];
		dis = param['dis'];
		url = param['url'];
		akt = param['aktif'];
		par = param['param'];
		
		$('#'+id).change(function(){
			aktif = $('#'+akt).attr('style');
			if(aktif === 'display: none' || aktif === 'display: none;' || aktif === 'display: none; color: rgb(255, 255, 255);' || par === false){
				$('#'+dis).val('Generate Kode....');
				$.ajax({
				type: 'POST',
					url: param['url']+$(this).val()+'/',
					data: $(this).serialize(),
					success: function(data) {
						$('#'+dis).val(data);
					}
				})
			}
		})
	}
	
	makeNullSaving = function(){
		$('.buttonSimpan').css('color', '#fff');
		$('.buttonUpdate').css('color', '#fff');
	}
	makeSaving = function(){
		$('.buttonSimpan').css('color', '#fff');
		$('.buttonUpdate').css('color', '#fff');
		up = $('.buttonSimpan').attr('style');
		st = up.split(';');
		st = st[1];
		st = st.split(':');
		st = $.trim(st[0]);
		
		if(st === 'display' || st === 'color'){
			$('.buttonUpdate').focus().css('color', 'blue');
		}else{
			$('.buttonSimpan').focus().css('color', 'blue');
		}
		
	}
		
	makeKeyboard = function(param){
		var param = param;
		__home = param['home'];
		__item = param['f_2'];
			
		makeKeyActive = function(kode, id){
			__kode = kode;
			__id   = id;
			__top  = $('#'+__id).attr('top');
			__bot  = $('#'+__id).attr('bot');
			__key  = $('#'+__id).attr('key');
			__cls  = $('#'+__id).attr('class');
			__prc  = $('#'+__id).attr('process');
			__aft  = $('#'+__id).attr('after');
			__val  = $('#'+__id).val();
			__home = param['home'];
			__item = param['f_2'];

			// if(__kode === 27){
				// makeDef();
				// $("#apankForm").empty();
				// $("#apankFormDefDisplay").css("display", "none");
				// $(".buttonFirst").focus();
			// }
			
			if(__kode === 38){
				$('#'+__top).focus();
			}
			if(__kode === 36){
				$('#'+__home).focus();
			}
			if(__kode === 113){
				$('.'+__item).focus();
			}
			if(__kode === 35){
				makeSaving();
			}else{
				makeNullSaving();
			}
			
			if(__aft === undefined){
				if(__kode === 13 || __kode === 40){
					if(__prc === 't'){
						makeProcess();
					}else{
						$('#'+__bot).focus();
					}
				}
			}
		}
			
		$('.text, .textarea, .select, .submit').live('keyup', (function(e){
			_id = this.id;
			_kode = e.which;
			$('#'+_id).attr("autocomplete", "off");
			makeKeyActive(_kode, this.id);
		}));
		
		$.Shortcuts.add({
			type: 'down',
			mask: 'Home',
			handler: function() {
				$('#'+__home).focus();
			}
		}).start();
		$.Shortcuts.add({
			type: 'down',
			mask: 'F2',
			handler: function() {
				$('.'+__item).focus();
			}
		}).start();
		$.Shortcuts.add({
			type: 'down',
			mask: 'End',
			handler: function() {
				makeSaving();
			}
		}).start();
	}
	
	makeNewPopUp = function(_width, _divLocation, attr, button, _default){
	
		if(_default === ''){
			_default = false;
		}
	
		if(_width === ''){
			_width = 500;
		}
	
		res = '<div class="popUpItem">';
		res+= '<div class="popUpItem_2" style="width: '+_width+'px">';
		res+= '<div class="popUpItem_3">';
		res+= '<div class="popUpItem_4">';
		res+= '<p class="locClose"><a id="_popMinimize" href="" title="MiniMize">_</a><input type="button" title="Close Form" id="apankFormCloseButton"></p>';
		
		if(attr.length > 0){
			_cel = 0;
			for(i = 1; i < attr.length; i++){
				if(attr[i] != ''){
					_nVal = attr[i];
					_nVal = _nVal.split(';');

					_jum = _nVal.length;
					if(_jum > _cel){
						_cel = _jum;
					}
				}
			}

			res+= '<table class="formTable" border="0" id="_tabPopUp">';
			for(i = 1; i < attr.length; i++){
				if(attr[i] != ''){
					_nVal = attr[i];
					_nVal = _nVal.split(';');

					_jum = _nVal.length;
					_jumCel = _jum - 1;
					_colspan = (_cel - _jum) + 1;
					
					res+= '<tr>';
					res+= '<td class="label">'+_nVal[0]+'</td>';
					
					for(_nn = 1; _nn <= _jumCel; _nn++){
						res+= '<td id="div_itemPopUp_'+i+'" colspan="'+_colspan+'">'+_nVal[_nn]+'</td>';
					}
					
					res+= '</tr>';
				}
			}
			res+= '</table>';
		}
		
		res+= '</div>';
		res+= '</div>';
		res+= '</div>';
		res+= '</div>';
		
		$('#'+_divLocation).html(res);
		
		$('#_popMinimize').click(function(e){
			e.preventDefault();
			dis = $('#_tabPopUp').attr('style');
			if(dis === 'display: none;'){
				$('#_tabPopUp').removeAttr('style');
			}else{
				$('#_tabPopUp').css('display', 'none');
			}
		})
		
		$('#apankFormCloseButton').click(function(){
			$('#'+_divLocation).css('display', 'none');
		})
		if(_default === false){
			$('#'+_divLocation).css('display', 'none');
		}
		
		$(button).live('click', (function(){
			$('#'+_divLocation).removeAttr('style');
		}))
	}
	makeAngka = function(){
		$('.decimal').live('change', (function(e){
			_idIn  = this.id;
			_val   = $('#'+_idIn).val();
			_jum   = parseInt(_val.length);
			
			if(_jum > 0){
				_exVal = _val.split('');
				_nVal  =  '';
				for(i = 0; i < _jum; i++){
					if(_exVal[i] === '0' || _exVal[i] === '1' || _exVal[i] === '2' || _exVal[i] === '3' || _exVal[i] === '4' || _exVal[i] === '5' || _exVal[i] === '6' || _exVal[i] === '7' || _exVal[i] === '8' || _exVal[i] === '9' || _exVal[i] === '.' || _exVal[i] === '-'){
						_nVal+= _exVal[i];
					}
				}
			}else{

			}
			
			if(_val === ''){
				_nVal = '';
			}
			
			$('#'+_idIn).val(_nVal);
		})).live('change', (function(){
			makeDecimalFix(this.id);
		})).live('keypress', (function(e){
			if(e.which === 13 || e.which === 37 || e.which === 38 || e.which === 39 || e.which === 40 || e.which === 45){
				makeDecimalFix(this.id);
			}
		}));
		$('.decimal').live('change', (function(){
			makeDecimalFix(this.id);
		}));
		makeDecimal = function(_idIn){
			_val   = $('#'+_idIn).val();
			_jVal  = _val.split('.');
			if(_jVal.length > 1){
				_dec = _jVal[1].length;
				_dec = parseInt(_dec);
				if(_dec > 0){
					_val = accounting.formatNumber(_val, _dec, ',');
				}
			}else{
				_val = accounting.formatNumber(_val, 0, ',');
			}
			
			$('#'+_idIn).val(_val);
			makeSetRight(_idIn);
		}
		makeDecimalFix = function(_idIn){
			_val   = $('#'+_idIn).val();
			_jVal  = _val.split('.');
			if(_jVal.length > 1){
				_dec = _jVal[1].length;
				_dec = parseInt(_dec);
				if(_dec === 0){
					_dec = 0;
				}
				_val = accounting.formatNumber(_val, _dec, ',');
			}else{
				_val = accounting.formatNumber(_val, 0, ',');
			}
			
			$('#'+_idIn).val(_val);
			makeSetRight(_idIn);
		}
		makeSetRight = function(_idIn){
			_style = $('#'+_idIn).attr("style");
			_style = _style+'; text-align: right';
			$('#'+_idIn).attr("style", _style);
		}
	}
	setDec = function(){
		$('.decimal').after(function(){
			makeDecimal(this.id);
		})
	}
	makeAngka();
	$('._past').live('keyup', (function(){
		cls = $(this).attr('class');
		cls = cls.split('_past ');
		cls = cls[1].toUpperCase();
		cls = cls.split('__');
		
		id = this.id;
		vl = $('#'+id).val().toUpperCase();
		
		_cek = false;
		_val = '';
		for(iPast = 0; iPast < cls.length; iPast++ ){
			if(_cek === false){
				if(cls[iPast] === vl){
					_val = vl;
					_cek = true;
				}
			}
		}
		$('#'+id).val(_val);
	}))
	
	$('#apankForm').live('click', (function(){
		_tempGridFocus = $('#tempGridFocus').val();
		if(_tempGridFocus === ''){
			// $('._noGrid_0').focus();
		}else if(_tempGridFocus === '_noGrid_0'){
			// $('._noGrid_0').focus();
		}else{
			$('#'+_tempGridFocus).focus();
		}
	}))
	$('._textGridNone').live('keyup', (function(e){
		_num = parseInt($(this).attr("number"));
		_max = parseInt($(this).attr("max"));
		if(e.which === 38){
			_num = _num - 1;
		}
		if(e.which === 40){
			_num = _num + 1;
		}
		if(_num < 0){
			_num = 0;
		}
		if(_num > _max){
			_num = _max;
		}
		$('._noGrid_'+_num).focus();
		_idTemp = $('._noGrid_'+_num).attr('id');
		$('#tempGridFocus').val(_idTemp);
	}))
	
	
	_makeFormat = function(_id, _no){
		if(_no === false){
			_no = '';
		}
		$('#'+_id).after('<input type="text" readonly="1" class="text readonly" size="4" name="dienumber'+_no+'" id="dienumber'+_no+'">');
		$('#dienumber'+_no).after('<input type="text" readonly="1" class="text readonly" size="1" name="wb'+_no+'" id="wb'+_no+'">');
		$('#wb'+_no).after('<input type="text" readonly="1" class="text readonly" size="3" name="client'+_no+'" id="client'+_no+'">');
		$('#client'+_no).after('<input type="text" readonly="1" class="text readonly" size="2" name="merk'+_no+'" id="merk'+_no+'">');
	}
	$('.upper').keyup(function(){
		$("#"+this.id).val($(this).val().toUpperCase());
	})
}); 

function _goTo(_url){
	window.location = _url;
}
function _openWindow(_url){
	window.open(_url,'_blank');
}

makeTextBarcode = function(){
	content = '<p style="text-align: center; margin-top: -10px; font-weight: bold; font-size: 12px">Active Barcode</p>';
	content+= '<input type="text" id="barcodeId" name="barcode" class="text barcode" style="width: 160px">';
	content+= '<div id="barProses" style="margin-top: 10px; text-align: center; width: 100%"></div>';
	return content;
}

makeLoadBar = function(param){
	makePopUpNotLoad(250, 200, makeTextBarcode());
	$('#barcodeId').focus();
	$('.text').keyup(function(e){
		if(e.keyCode === 27){
			$('#apankForm').empty();
			$('#'+param['id']).focus();
		}
	})
	$.Shortcuts.add({
		type: 'down',
		mask: 'ESC',
		handler: function() {
			$('#apankForm').empty();
			$('#'+param['id']).focus();
		}
	}).start();
	$('#barcodeId').keyup(function(e){
		kode = this.value;
		
		if (e.keyCode == 13) {
			makeEvent(kode);
			
			if(param['sukses'] === 'close'){
				$('#apankForm').empty();
			}
			if(param['sukses'] === 'none'){
				$('#barcodeId').val('');
			}
		}
	})
}
function sortF1(param){
	$.Shortcuts.add({
		type: 'down',
		mask: 'F1',
		handler: function() {
			makeLoadBar(param);
		}
	}).start();
}

function str_ireplace(asli, ubah, value){
	if(value !== undefined){
		_jum = value.split(asli);
		_jum = parseInt(_jum.length) + 1;
		for(__ii = 0; __ii <= _jum; __ii++){
			value = value.replace(asli, ubah);
		}
	}
	return value;
}
function newArray()
{
	return new array('null');
}
function setDecimal(tot)
{
	_tot = tot+'';
	_tmp = str_ireplace('.', ',', _tot);
	_tmp = _tmp.split(',');
	
	if(_tmp.length === 1){
		_tmp[1] = '00';
	}else{
		_tmp[1] = _tmp[1]+'0';
	}
	
	_nEx = _tmp[1].split('');
	_nDec = '';
	for(_nSD = 0; _nSD <= 1; _nSD++){
		_nDec+= _nEx[_nSD];
	}
	
	_nTot = _tmp[0]+'.'+_nDec;
	return _nTot;
}
function min2hour(_minutes)
{
	return parseInt(_minutes) / 60;
}
function setBulan(_bulan)
{
	if(_bulan === 'Jan'){
		return '01';
	}else if(_bulan === 'Feb'){
		return '02';
	}else if(_bulan === 'Mar'){
		return '03';
	}else if(_bulan === 'Apr'){
		return '04';
	}else if(_bulan === 'May'){
		return '05';
	}else if(_bulan === 'Jun'){
		return '06';
	}else if(_bulan === 'Jul'){
		return '07';
	}else if(_bulan === 'Aug'){
		return '08';
	}else if(_bulan === 'Sep'){
		return '09';
	}else if(_bulan === 'Oct'){
		return '10';
	}else if(_bulan === 'Nov'){
		return '11';
	}else if(_bulan === 'Dec'){
		return '12';
	}
}
function setDate(_date)
{
	_date = _date.split('-');
	return _date[2]+'-'+setBulan(_date[1])+'-'+_date[0];
}
function _speed(product, work_time, lost_min, _date)
{
	_work_hour = parseInt(work_time);
	_work_min  = min2hour((work_time - _work_hour)*100)
  
	myDays = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', 'Jum&#39;at', 'Sabtu'];
	_date = setDate(_date);
	var _date = new Date(_date);
	var _day = _date.getDay();
		_day = myDays[_day];
	
	if(_day === 'Sabtu' & _work_hour > 8){
		_work_hour = 8;
	}else if(_day !== 'Sabtu' & _work_hour > 9){
		_work_hour = 9;
	}
	
  _actual = (_work_hour + _work_min) - min2hour(lost_min);    // ( lost_min / 60 )
  _speed = product / _actual;
  return parseInt(_speed);
}
_value = function(_id, _val){
	if(_val !== null & _val !== '' & _val !== undefined){
		$(_id).val(unescape(_val));
	}else{
		$(_id).val('');
	}
}
function cekPosisiPointer(_id){
	return document.getElementById(_id).selectionStart;
}