
function UpdateItem(item) {

	// Update time left to item end
	$('#time-left').html(item.time_left);

	// Update end time
	$('#date-end').html(item.date_end);

	// Update current price
	$('#current-price').html(item.current_price);

	// Update item quantity
	$('#quantity-left').html(item.quantity_left);
	$('#quantity-left-2').html(item.quantity_left);

	if (item.is_running == true) {

		// Update current price in bidform
		$('#current-price-bid').html(item.current_price);

		// Update current bid in bidform
		$('#current-bid').attr('value', item.maximum_bid);
		$('#current-bid-2').attr('value', item.maximum_bid);

		$('#current-bid-txt').html(item.maximum_bid);

		// Update bid step in bidform
		$('#bid-increment').attr('value', item.bid_increment);

	} else {

		// Hide bid form
		$('#itembids').css('display', 'none');
		$('#itembids-2').css('display', 'none');
	}

	// Hide buynow button, price, form and label
	if (item.buynow_allowed == false) {

		$('#buynowform').css('display', 'none');
		$('#buynowform-2').html('');
	}

	// Hide reserve price label
	if (item.reserve_met == true) {

		$('#lbl-reserve-price').css('visibility', 'hidden');
		$('#lbl-reserve-price').css('position', 'absolute');
	}

	// Update bid step
	$('#lbl-increment-by').html(item.increment_by);

	// Update bidcount
	$('#bidcount').html(item.current_bids);

	// Update bidder
	if ($('#bidder-name') && item.bidder != '')
		$('#bidder-name').html(item.bidder);
}

var q_open = null;
function toggleQuestion(element) {

	$(element).toggle();
	
	if (q_open)
		$(q_open).toggle();

	q_open = element;
}

function toggleCategory(element, element2) {

	$(element).toggle();
	$(element2).toggle();
}



function updateCategory(elem, cat_id) {

	var category = document.getElementById(elem);

	if (!category)
		return;

	category.options.length = 1;
	if (cat_id > 0 && categories[cat_id]) {
		for (i = 1; i <= categories[cat_id].length; i++) {
			category.options[i] = new Option(categories[cat_id][i-1][0], categories[cat_id][i-1][1])
		}
	}
}

function selectCategory(elem, val) {

	var cat = document.getElementById(elem);

	if (!cat)
		return;

	if (val > 0) {
		for (i = 1; i <= cat.options.length; i++) {
			if (cat.options[i].value == val) {
				cat.options[i].selected = 'selected';
				break;
			}
		}
	}
}
