$(function(){
    $('#calculate').mouseover(function(){ $(this).css({'cursor':'pointer'}); });
		$('#calculate').click(function(){
		    var gameId = $('#gameId').val();
		    var levelLabelId = $('#levelLabelId').val();
		    var levelTypeId = $('#levelTypeId').val();
				var start = parseInt($('#start').val());
				var desired = parseInt($('#desired').val());
				
				if(start >= desired){
				    alert('Desired level must be more than start level.');
						return false;
				}
				
				$.ajax({
				    timeout: 10000,
						type: 'POST',
						url: 'ajax/fit.powerleveling.retail.ajax.php',
						data: {'gameId':gameId, 'levelLabelId':levelLabelId, 'levelTypeId':levelTypeId, 'start':start, 'desired':desired},
						dataType: 'json',
						error: function(a, b){
						    alert('Sorry, request timeout, click confirm to reload this page.');
								window.location.reload(document.URL);
						},
						//beforeSend: function(){},
						success: function(data){
						    $('#days').val(data['days']);
						    $('#hours').val(data['hours']);
						    $('#price').val(data['price'].toFixed(2));
						    $('#rmb').val(data['rmb']);
						}
				});
		});
});
