function openAuctionListingDialog(event)
{
	$("#auctionListingDialog").show();
	var auctionId = event.data.auctionId;
	$.ajax({
	    url: '/auction/auctionListing.htm?modal=true',
	    type: 'GET',
	    data: ({auctionId:auctionId}),
	    dataType: "html",	
	    success: function(result){
			$('#auctionListingContent').html(result);
	    },
	    error: function(){
	    	$('#auctionListingContent').html('Unable to get the auction listing at the moment.');
	    }
	});
	$('#auctionListingDialog').dialog('open');
	return false;  
}

function initAuctionListingDialog()
{
	$("#auctionListingDialog").dialog({
		modal: true,
		draggable: true,
		resizable: true,
		autoOpen: false,
		width:  700,
		height: 600,
		buttons: {
			'Show selected items': function() {
				var auctionId = $('#auctionIdContainer').html();
				var selectedListings = '';
				$('input:checkbox').each(
				  	function() {
				   		if (this.checked === true)
						{
							selectedListings += this.value + ' ';
						}
				  	}
				);
	    		var url = '/auction/lotsForAuction.htm?auctionId=' + auctionId + '&selectedListings=' + selectedListings;
				window.location.replace(url);
			}
		},
		close: function() {
		}
	});		
}

$(document).ready(function ()
{
	var auctionId = $('#auctionIdContainer').html();
	$('#auctionListingDialogOpener').bind("click", {auctionId: auctionId}, openAuctionListingDialog);
	initAuctionListingDialog();
});