$(document).ready(function(){

	setPostForm = [ null, null];
	submitForm  = [ null, null];
	nomorSubmit = 0;
	var idPostFormStartApank = false;
	
	(function( $ ) {
		$.fn.postForm = function(option){

			$(this).each(function(){
				idPostForm = this.id;
			})
			
			var defaults = $.extend({
				act: false,
				submitUrl: ['submit' ['divDisplay', 'url']],
			})
			
			setPostForm[idPostForm] = $.extend({}, defaults, option);
			postFormId = 'apankForm'+idPostForm;
			
			for(i = 0; i < setPostForm[idPostForm]['submitUrl'].length; i++){
				submitForm[nomorSubmit] = setPostForm[idPostForm]['submitUrl'][i];
				act = setPostForm[idPostForm]['act'];
				nomorSubmit = nomorSubmit + 1;
				
				idLoading = setPostForm[idPostForm]['submitUrl'][i][0];
				$('#'+idLoading).after('&nbsp;<span id="loadingPosting'+idLoading+'"></span>');
				$('#'+idLoading).after('<input type="button" idTemp="'+idLoading+'" id="abbort'+idLoading+'" class="submit abbortPostForm" value="Batal" style="display: none">');
			}
			
			$('.submitApankForm').click(function(){
				idSubmit = this.id;
				for(i = 0; i < (submitForm.length - 1); i++){
					idLoading = submitForm[i][0];
					if(idSubmit === idLoading){
						idApankForm  = submitForm[i][0];
						divApankForm = submitForm[i][1];
						urlApankForm = submitForm[i][2];
					}
				}
			})

			$('.text, .select, .jenHarga, .checkbox, .inputNone, .inputButton, .textConfirm, .textFilter').live('keypress', (function(e){
				if (e.which == 13) {
					return false;
				}	
			}));			
			// $('.textarea').keydown(function (e) {
				// if (e.which == 13) {
				// }
			// });
			// $('.textarea').keypress(function(e){
				// if (e.which == 13) {
					// return false;
				// }	
			// });			
			$('._linkPopUp').keypress(function(e){
				if (e.which == 13) {
					return false;
				}	
			});			
			
			$('.abbortPostForm').click(function(e){
				idPostFormStartApank.abort();
				_idTempPostForm = $(this).attr('idTemp');
				$('#loadingPosting'+_idTempPostForm).empty();
				$('#abbort'+_idTempPostForm).css('display', 'none');
				
				cl = $('#'+_idTempPostForm).attr('class');
				cl = cl.replace(' _disNonePostForm', '');
				$('#'+_idTempPostForm).removeAttr('disabled');
				$('#'+_idTempPostForm).removeAttr('class').addClass(cl);
			})
			
			$('#'+idPostForm).submit(function(e){
				e.preventDefault();
				$('#loadingPosting'+idApankForm).html('<span class="loadingPostingDisplay">&nbsp;&nbsp;&nbsp;&nbsp;</span>');
				$('#abbort'+idApankForm).removeAttr('style');
				
				cl = $('#'+idApankForm).attr('class');
				$('#'+idApankForm).attr('disabled', true);
				$('#'+idApankForm).removeAttr('class').addClass(cl+' _disNonePostForm');
				
				if(act === true){
					_act = '&act='+$("#_actSubmit").val();
				}else{
					_act = '';
				}
				
				idPostFormStartApank = 	$.ajax({
				type: 'POST',
					url: urlApankForm+_act,
					data: $(this).serialize(),
					success: function(data) {
						$('#loadingPosting'+idApankForm).empty();
						$('#abbort'+idApankForm).css('display', 'none');
						$('#'+idApankForm).removeAttr('disabled');
						$('#'+idApankForm).removeAttr('class').addClass(cl);
						$('#'+divApankForm).html(data);
					}
				})
			});
		};
	})( jQuery );
	
	
})

