function trim(str) { 
	return str.replace(/^\s+|\s+$/, ''); 
}

function prs4(p) {
	return parseInt(p.replace(/(\w+)-(\w+)-(\w+)-([0-9]+)/g, "$4"));
}	

function prs3(p) {
	return parseInt(p.replace(/(\w+)-(\w+)-([0-9]+)/g, "$3"));
}

//--------------------------------------------------------------------

$().ready(function() {
	$('.ajax').ajaxStart(function() {
		$(this).show();
	}).ajaxStop(function() {
		$(this).hide();
	});
      	
      	$(".letter").click(function () {      		
      		var aid = prs3($(this).attr('id'));
      		$.get('/ajax/getauthors.php?l='+aid, function(data) {        		
        		$('#author-result').empty(); 		        		        		
        		$('#author-result').append(data);        		
        	});      		
      		return false;	
      	});
      	
      	$("#purchase").click(function () {
      		var bid = $('#book_id').val();
        	$.get('/ajax/purchase.php?bid='+bid, function(data) { 
        		location.replace(data);			
        		return false;
        		//$('#purchase_result').empty(); 		        		        		
        		//$('#purchase_result').append(data);        		
        	});
        	return false;
	});
	
	
});

