var roomAreaNum = 0;

function addAnotherRoomArea(num) {
	
	//if(roomAreaNum == 0) { roomAreaNum = num; }
	//roomAreaNum++;
	
	roomAreaNum = $('input[id^="sellerAddPropertyForm_room_name_"]').length;
	
	var html = $("#sellerAddPropertyForm_addArea").html();
	
	var newhtml = html.replace(/X/g,roomAreaNum,html);
	
	$("#sellerAddPropertyForm_addAnotherRoomArea").before(newhtml);
	
}

function getUploadImageId(image_id,num,filename) {
	$("#sellerAddPropertyForm_imageId_"+num).val(image_id);
	$("#sellerAddPropertyForm_imageFilename_"+num).val(filename);
	var src = $("#sellerAddPropertyForm_imageUploadIframe_"+num).attr("src");
	$("#sellerAddPropertyForm_imageUploadIframe_"+num).attr("src",src.replace(/image_id=0/,"image_id="+image_id));
	console.log("#sellerAddPropertyForm_imageUploadIframe_"+num);
}
/*
function auctionCountdown(year,month,day,hour,minute,id) {
	
	var toDate = new Date(year,month-1,day,hour,minute); 
		
	$('#countdown_'+id).countdown({
		labels: ['years', 'months', 'weeks', 'days', 'hrs', 'mins', 'secs'], 
		labels1: ['year', 'month', 'week', 'day', 'hr', 'min', 'sec'], 
		format: 'DHMS',
		onExpiry: hideAuctionItem,
		until: toDate
	}); 
}
*/
function hideAuctionItem() {
	$(this).parent().parent().find("div.countdown_wrapper").hide();
	$(this).parent().parent().find("p:last").show();
}

var prev_bid_amount = 0;

// Synchronous ajax calls interrupt keystrokes, see asynchronous implementation further down.

/*function updateCurrentBidAmount(item_id) {
	var current_bid = $.ajax({
		url: "/acms/modules/auction/client/ajax.php",
		async: false,
		data: "action=updateCurrentBidAmount&item_id="+item_id
	}).responseText.split("|");
	var current_bid_amount = current_bid[0];
	var current_bid_count = current_bid[1];
	if(current_bid_amount.replace(/\,/g,'') != prev_bid_amount) {
		$("#currentBidAmount").html(current_bid_amount);
		$("#numBids").html(current_bid_count);
		prev_bid_amount = current_bid_amount.replace(/\,/g,'');
	}
}*/

function updateCurrentBidAmount(item_id) {
	
	$.ajax({
		url: "/acms/modules/auction/client/ajax.php",
		data: "action=updateCurrentBidAmount&item_id="+item_id,
		success: function(current_bid){
			
			if(current_bid != "ENDED") {
				current_bid = current_bid.split("|");
				
				var current_bid_amount = current_bid[0];
				var current_bid_count = current_bid[1];
				var minimum_bid_amount = current_bid[2];
				var bidder_notification = current_bid[3];
				var reserve_met = current_bid[4];
				
				if(parseFloat(current_bid_amount) > 0){
					$("#currentBidAmount").html(current_bid_amount);
					$("#numBids").html(current_bid_count);
					if(bidder_notification == 'highest') {
						$("#highestBidderNotification").show();
						$("#outbidNotification").hide();
					}
					else if(bidder_notification == 'outbid') {
						$("#highestBidderNotification").hide();
						$("#outbidNotification").show();
					}
					else {
						$("#highestBidderNotification").hide();
						$("#outbidNotification").hide();
					}
					if(reserve_met == 'met') {
						$("#reserveNotMetMsg").attr("id","reserveMetMsg").html("Reserve met");
					}
					prev_bid_amount = current_bid_amount.replace(/\,/g,'');
				}
				
				$("#minimumBidAmount").html(minimum_bid_amount);
				
				setTimeout("updateCurrentBidAmount("+item_id+")",2000);
			}
		}
	});
	
}

