$(function() {
	$.fn.inputFilter = function(inputFilter) {
	    return this.on("input keydown keyup mousedown mouseup select contextmenu drop", function() {
	      if (inputFilter(this.value)) {
	        this.oldValue = this.value;
	        this.oldSelectionStart = this.selectionStart;
	        this.oldSelectionEnd = this.selectionEnd;
	      } else if (this.hasOwnProperty("oldValue")) {
	        this.value = this.oldValue;
	        this.setSelectionRange(this.oldSelectionStart, this.oldSelectionEnd);
	      } else {
	        this.value = "";
	      }
	    });
	  };
	
	$("#cur_page").inputFilter(function(value) {
		  return /^-?\d*$/.test(value); });
	
	var currentPage = parseInt($("#cur_page").val())
	
	if(currentPage == 1)
		$("#btnPrevPage").hide()
	
	$('#btnPrevPage').click(function() {
		$('#type').val('search');
				
		if((currentPage - 1) < 1)
			return;
			
		$("#cur_page").val(currentPage - 1)
		
		submitForm();
	});
	
	$('#btnNextPage').click(function() {
		$('#type').val('search');
		
		var maximumPage = parseInt($("#max_page").val())
		
		if((currentPage + 1) > maximumPage)
			return;
			
		$("#cur_page").val(currentPage + 1)
			
		submitForm();
	});
	
	$('#dispPage').click(function(){
		$('#type').val('search');
		
		var maximumPage = parseInt($("#max_page").val())
		var selectedPage = parseInt($("#cur_page").val())
		
		if($("#cur_page").val().trim().length == 0)
			return;		
		
		if(selectedPage > maximumPage || selectedPage < 1)
			return;
		
		submitForm();
	})
	
	$('#btnSearch').click(function() {
		$('#type').val('search');
		submitForm();
	});

    $('#btnExport').click(function() {
		$('#type').val('export_common');
		submitForm();
	});

	$('#from').datepicker({
		// カレンダーの設定
		dateFormat	: 'yy/mm/dd'
	});

	$('#to').datepicker({
		// カレンダーの設定
		dateFormat	: 'yy/mm/dd'
	});

	if($('#from').val() == '') {
		$('#from:text').datepicker().datepicker('setDate','2014/01/01');
	}

	if($('#to').val() == '') {
		$('#to:text').datepicker().datepicker('setDate','today');
	}
});
