<?php echo $header; ?>
<div id="content">
  <div class="breadcrumb">
    <?php foreach ($breadcrumbs as $breadcrumb) { ?>
    <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
    <?php } ?>
  </div>
  <?php if ($error_warning) { ?>
  <div class="warning"><?php echo $error_warning; ?></div>
  <?php } ?>
  <?php if ($success) { ?>
  <div class="success"><?php echo $success; ?></div>
  <?php } ?>
  <div class="box">
    <div class="heading">
      <h1><img src="view/image/auction-status.png" alt="" /> <?php echo $heading_title; ?></h1>
      <div class="buttons"><a onclick="$('form').submit();" class="button"><?php echo $button_delete; ?></a></div>
    </div>
    <div class="content">
      <form action="<?php echo $delete; ?>" method="post" enctype="multipart/form-data" id="form">
        <table class="list">
          <thead>
            <tr>
              <td width="1" style="text-align: center;"><input type="checkbox" onclick="$('input[name*=\'selected\']').attr('checked', this.checked);" /></td>
              <td class="center"><?php echo $column_product; ?></td>
              <td class="left"><?php if ($sort == 'pa.auction_name') { ?>
                <a href="<?php echo $sort_auction_name; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_auction_name; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_auction_name; ?>"><?php echo $column_auction_name; ?></a>
                <?php } ?></td>
              <td class="left"><?php if ($sort == 'pa.starting_time') { ?>
                <a href="<?php echo $sort_starting_time; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_starting_time; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_starting_time; ?>"><?php echo $column_starting_time; ?></a>
                <?php } ?></td>
              <td class="right"><?php if ($sort == 'a.highest_bid_amount') { ?>
                <a href="<?php echo $sort_highest_bid; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_highest_bid; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_highest_bid; ?>"><?php echo $column_highest_bid; ?></a>
                <?php } ?></td>
              <td class="right"><?php if ($sort == 'a.total_no_of_bid') { ?>
                <a href="<?php echo $sort_total_no_of_bid; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_total_no_of_bid; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_total_no_of_bid; ?>"><?php echo $column_total_no_of_bid; ?></a>
                <?php } ?></td>
              <td class="right"><?php if ($sort == 'auction_status') { ?>
                <a href="<?php echo $sort_auction_status; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_auction_status; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_auction_status; ?>"><?php echo $column_auction_status; ?></a>
                <?php } ?></td>
              <td class="right"><?php if ($sort == 'a.real_ending_time') { ?>
                <a href="<?php echo $sort_time_left; ?>" class="<?php echo strtolower($order); ?>"><?php echo $column_time_left; ?></a>
                <?php } else { ?>
                <a href="<?php echo $sort_time_left; ?>"><?php echo $column_time_left; ?></a>
                <?php } ?></td>
              <td class="right"><?php echo $column_action; ?></td>
            </tr>
          </thead>
          <tbody>
            <tr class="filter">
              <td></td>
              <td></td>
              <td><input type="text" name="filter_auction_name" value="<?php echo $filter_auction_name; ?>" /></td>
              <td><input type="text" name="filter_starting_time" value="<?php echo $filter_starting_time; ?>" class="datetime" /></td>
              <td align="right"><input type="text" name="filter_highest_bid" value="<?php echo $filter_highest_bid; ?>" size="8" style="text-align: right;"/></td>
              <td align="right"><input type="text" name="filter_total_no_of_bid" value="<?php echo $filter_total_no_of_bid; ?>" size="8" style="text-align: right;" /></td>
              <td align="right"><select name="filter_auction_status_id">
                  <option value="*"></option>
                  <?php foreach ($auction_statuses as $key => $value) { ?>
                  <?php if ($key == $filter_auction_status_id) { ?>
                  <option value="<?php echo $key; ?>" selected="selected"><?php echo $value; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $key; ?>"><?php echo $value; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select></td>
              <td align="right"><input type="text" name="filter_real_ending_time" value="<?php echo $filter_real_ending_time; ?>" class="datetime" /></td>
              <td align="right"><a onclick="filter();" class="button"><?php echo $button_filter; ?></a></td>
            </tr>
            <?php if ($auctions) { ?>
            <?php foreach ($auctions as $auction) { ?>
            <tr>
              <td style="text-align: center;"><?php if ($auction['selected']) { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $auction['auction_id']; ?>" checked="checked" />
                <?php } else { ?>
                <input type="checkbox" name="selected[]" value="<?php echo $auction['auction_id']; ?>" />
                <?php } ?></td>
              <td class="center"><img src="<?php echo $auction['product_image']; ?>" alt="<?php echo $auction['reserved_quantity']; ?> &times; <?php echo $auction['product_name']; ?>" title="<?php echo $auction['reserved_quantity']; ?> &times; <?php echo $auction['product_name']; ?>" style="padding: 1px; border: 1px solid #DDDDDD;" /></td>
              <td class="left"<?php if (isset($error_delete[$auction['auction_id']])) { ?> style="color: #FF0000; font-weight: bold;"<?php } ?>><?php echo $auction['auction_name']; ?></td>
              <td class="left"><?php echo $auction['starting_time_text']; ?></td>
              <td class="right"><span id="highest-bid-<?php echo $auction['auction_id']; ?>"><?php echo $auction['highest_bid_amount_text']; ?></span></td>
              <td class="right"><span id="total-bid-<?php echo $auction['auction_id']; ?>"><?php echo $auction['total_no_of_bid']; ?></span></td>
              <td class="right"><span id="auction-status-<?php echo $auction['auction_id']; ?>"><?php echo $auction['auction_status']; ?></span></td>
              <td class="right"><?php if ($auction['auction_active']) { ?>
			    <span id="auction-timeleft-<?php echo $auction['auction_id']; ?>" style="color: #B00000;"></span>
                <?php } else { ?>
			    <?php echo $auction['real_ending_time_text']; ?>
                <?php } ?></td>
              <td class="right"><?php foreach ($auction['action'] as $action) { ?>
                [ <a href="<?php echo $action['href']; ?>"><?php echo $action['text']; ?></a> ]
                <?php } ?></td>
            </tr>
            <?php } ?>
            <?php } else { ?>
            <tr>
              <td class="center" colspan="9"><?php echo $text_no_results; ?></td>
            </tr>
            <?php } ?>
          </tbody>
        </table>
      </form>
      <div class="pagination"><?php echo $pagination; ?></div>
    </div>
  </div>
</div>
<script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=sale/auction&token=<?php echo $token; ?>';
	
	var filter_auction_name = $('input[name=\'filter_auction_name\']').attr('value');
	
	if (filter_auction_name) {
		url += '&filter_auction_name=' + encodeURIComponent(filter_auction_name);
	}
	
	var filter_starting_time = $('input[name=\'filter_starting_time\']').attr('value');
	
	if (filter_starting_time) {
		url += '&filter_starting_time=' + encodeURIComponent(filter_starting_time);
	}
	
	var filter_highest_bid = $('input[name=\'filter_highest_bid\']').attr('value');
	
	if (filter_highest_bid) {
		url += '&filter_highest_bid=' + encodeURIComponent(filter_highest_bid);
	}
	
	var filter_total_no_of_bid = $('input[name=\'filter_total_no_of_bid\']').attr('value');
	
	if (filter_total_no_of_bid) {
		url += '&filter_total_no_of_bid=' + encodeURIComponent(filter_total_no_of_bid);
	}
	
	var filter_auction_status_id = $('select[name=\'filter_auction_status_id\']').attr('value');
	
	if (filter_auction_status_id != '*') {
		url += '&filter_auction_status_id=' + encodeURIComponent(filter_auction_status_id);
	}	

	var filter_real_ending_time = $('input[name=\'filter_real_ending_time\']').attr('value');
	
	if (filter_real_ending_time) {
		url += '&filter_real_ending_time=' + encodeURIComponent(filter_real_ending_time);
	}
	
	location = url;
}
//--></script> 
<script type="text/javascript" src="view/javascript/jquery/ui/jquery-ui-timepicker-addon.js"></script> 
<script type="text/javascript"><!--
$(document).ready(function() {
	$('.datetime').datetimepicker({
		dateFormat: 'yy-mm-dd',
		timeFormat: 'hh:mm'
	});
});
//--></script> 
<script type="text/javascript"><!--
$('#form input').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});
//--></script> 
<script type="text/javascript"><!--
$.widget('custom.catcomplete', $.ui.autocomplete, {
	_renderMenu: function(ul, items) {
		var self = this, currentCategory = '';
		
		$.each(items, function(index, item) {
			if (item.category != currentCategory) {
				ul.append('<li class="ui-autocomplete-category">' + item.category + '</li>');
				
				currentCategory = item.category;
			}
			
			self._renderItem(ul, item);
		});
	}
});

$('input[name=\'filter_auction_name\']').catcomplete({
	delay: 0,
	source: function(request, response) {
		$.ajax({
			url: 'index.php?route=sale/auction/autocomplete&token=<?php echo $token; ?>&filter_auction_name=' +  encodeURIComponent(request.term),
			dataType: 'json',
			success: function(json) {		
				response($.map(json, function(item) {
					return {
						category: item.product_name,
						label: item.auction_name,
						value: item.auction_id
					}
				}));
			}
		});
	}, 
	select: function(event, ui) {
		$('input[name=\'filter_auction_name\']').val(ui.item.label);
						
		return false;
	},
	focus: function(event, ui) {
      	return false;
   	}
});
//--></script> 
<script src="view/javascript/sha1.hash.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript"><!--
var defaultCurrencyPrefix        = '<?php echo $symbol_left; ?>';
var defaultCurrencySuffix        = '<?php echo $symbol_right; ?>';
var defaultCurrencyDecimalPlace  = parseInt(<?php echo $decimal_place; ?>);
var defaultCurrencyDecimalPoint  = '<?php echo $decimal_point; ?>';
var defaultCurrencyThousandPoint = '<?php echo $thousand_point; ?>';
var statusAuctionStarting   = parseInt(<?php echo $auction_status_ids['starting']; ?>);
var statusAuctionRelisting  = parseInt(<?php echo $auction_status_ids['relisting']; ?>);
var statusAuctionInProgress = parseInt(<?php echo $auction_status_ids['inprogress']; ?>);
var statusAuctionExtended   = parseInt(<?php echo $auction_status_ids['extended']; ?>);
var statusAuctionWon        = parseInt(<?php echo $auction_status_ids['won']; ?>);
var statusAuctionExpired    = parseInt(<?php echo $auction_status_ids['expired']; ?>);
var statusAuctionSold       = parseInt(<?php echo $auction_status_ids['sold']; ?>);
var statusAuctionVoided     = parseInt(<?php echo $auction_status_ids['voided']; ?>);
var textAuctionDay          = '<?php echo $text_day; ?>';
var textAuctionHour         = '<?php echo $text_hour; ?>';
var textAuctionMinute       = '<?php echo $text_minute; ?>';
var textAuctionSecond       = '<?php echo $text_second; ?>';
var textAuctionStarting     = '<?php echo $text_auction_statuses['starting']; ?>';
var textAuctionRelisting    = '<?php echo $text_auction_statuses['relisting']; ?>';
var textAuctionInProgress   = '<?php echo $text_auction_statuses['inprogress']; ?>';
var textAuctionExtended     = '<?php echo $text_auction_statuses['extended']; ?>';
var textAuctionWon          = '<?php echo $text_auction_statuses['won']; ?>';
var textAuctionExpired      = '<?php echo $text_auction_statuses['expired']; ?>';
var textAuctionSold         = '<?php echo $text_auction_statuses['sold']; ?>';
var textAuctionVoided       = '<?php echo $text_auction_statuses['voided']; ?>';
var textAuctionGetStarted   = '<?php echo $text_getstarted; ?>';
var textAuctionGoingGoing   = '<?php echo $text_goinggoing; ?>';
var serverTimeNow           = parseInt(<?php echo time(); ?>);
var clientTimeNow           = parseInt(Math.floor(new Date().getTime() / 1000));
var serverClientTimeDiff    = parseInt(serverTimeNow - clientTimeNow);
var lastPollingTime         = parseInt(clientTimeNow + serverClientTimeDiff);
var countDownTimer          = new Array();
var lastSetInterval         = new Array();
var pollAuctionData         = new Array();
var defaultPollingInterval  = 1000;
var defaultPollingTimeout   = 300000;
var defaultIntervalTime     = 1000;
var defaultRecallTime       = 500;
var defaultAnimationTime    = 1000;
var defaultAnimationFast    = 500;
var defaultCountDownTime    = 15;
var defaultCountDownFast    = 3;
function setDateTimeFormatShort(no_of_seconds) {
	var no_of_milliseconds = parseInt(no_of_seconds) * 1000;
	var ms_convert_to_date = new Date();
	if (no_of_milliseconds > 0) {
		ms_convert_to_date.setTime(no_of_milliseconds);
		// 20/10/2012 12:00:00 AM
		return Right('0' + String(ms_convert_to_date.getDate()), 2) + '/' + Right('0' + String(ms_convert_to_date.getMonth() + 1), 2) + '/' + Right('0' + String(ms_convert_to_date.getFullYear()), 4) + ' ' + Right('0' + String(ms_convert_to_date.getHours() > 12 ? ms_convert_to_date.getHours() - 12 : ms_convert_to_date.getHours() == 0 ? 12 : ms_convert_to_date.getHours()), 2) + ':' + Right('0' + String(ms_convert_to_date.getMinutes()), 2) + ':' + Right('0' + String(ms_convert_to_date.getSeconds()), 2) + ' ' + Right(String(ms_convert_to_date.toLocaleString()), 2);
	}
}
function countDownTimeBreaker(no_of_seconds) {
	var time_remaining_d = 0;
	var time_remaining_h = 0;
	var time_remaining_m = 0;
	var time_remaining_s = 0;
	time_remaining_d = Math.floor(no_of_seconds / 60 / 60 / 24);
	time_remaining_h = Math.floor(no_of_seconds / 60 / 60) - (time_remaining_d * 24);
	time_remaining_m = Math.floor(no_of_seconds / 60) - (time_remaining_h * 60) - (time_remaining_d * 24 * 60);
	time_remaining_s = Math.floor(no_of_seconds) - (time_remaining_m * 60) - (time_remaining_h * 60 * 60) - (time_remaining_d * 24 * 60 * 60);
	return String(time_remaining_d) + textAuctionDay + ' ' + Right('0' + String(time_remaining_h), 2) + textAuctionHour + ' ' + Right('0' + String(time_remaining_m), 2) + textAuctionMinute + ' ' + Right('0' + String(time_remaining_s), 2) + textAuctionSecond;
}
function Right(str, n) {
	if (n <= 0) { return ''; }
	else if (n > String(str).length) { return str; }
	else { return String(str).substring(String(str).length, String(str).length - n); }
}
function formatNumber(number, decimals, dec_point, thousands_sep) {
	number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
	var n = !isFinite(+number) ? 0 : +number;
	var prec = !isFinite(+decimals) ? 0 : Math.abs(decimals);
	var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
	var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;
	var s = '';
	toFixedFix = function(n, prec) {
		var k = Math.pow(10, prec);
		return '' + Math.round(n * k) / k;
	};
	s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
	if (s[0].length > 3) {
		s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
	}
	if ((s[1] || '').length < prec) {
		s[1] = s[1] || '';
		s[1] += new Array(prec - s[1].length + 1).join('0');
	}
	return s.join(dec);
}
function formatCurrency(amount) {
	return '' + defaultCurrencyPrefix + '' + formatNumber(amount, defaultCurrencyDecimalPlace, defaultCurrencyDecimalPoint, defaultCurrencyThousandPoint) + '' + defaultCurrencySuffix + '';
}
function clearCountDownTimer(auction_id) {
	clearInterval(countDownTimer[auction_id]);
	countDownTimer[auction_id] = null;
	lastSetInterval[auction_id] = null;
}
function countDownAuction(recall, auction_id, starting_time, highest_bid_amount, total_no_of_bid, real_ending_time, auction_status_id) {
	var script_time_to_use = parseInt(Math.floor(new Date().getTime() / 1000) + serverClientTimeDiff);
	var is_active_auction = 0;
	var display_countdown = '';
	var time_difference = 0;
	if (recall) {
		// void current timer immediately to prevent function overlap with recall
		clearCountDownTimer(auction_id);
		// do an almost-immediate function recall for latest display updates
		countDownTimer[auction_id] = setInterval(function(){countDownAuction(0, auction_id, starting_time, highest_bid_amount, total_no_of_bid, real_ending_time, auction_status_id)}, defaultRecallTime);
		lastSetInterval[auction_id] = defaultRecallTime;
	} else {
		if ($('#highest-bid-' + auction_id).html() != formatCurrency(highest_bid_amount)) {
			$('#highest-bid-' + auction_id).html(formatCurrency(highest_bid_amount));
			$('#highest-bid-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		}
		if ($('#total-bid-' + auction_id).html() != total_no_of_bid) {
			$('#total-bid-' + auction_id).html(total_no_of_bid);
			$('#total-bid-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		}
		if (auction_status_id == statusAuctionVoided && $('#auction-status-' + auction_id).html() != textAuctionVoided) {
			$('#auction-status-' + auction_id).html(textAuctionVoided);
			$('#auction-status-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		} else if (auction_status_id == statusAuctionSold && $('#auction-status-' + auction_id).html() != textAuctionSold) {
			$('#auction-status-' + auction_id).html(textAuctionSold);
			$('#auction-status-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		} else if (auction_status_id == statusAuctionExpired && $('#auction-status-' + auction_id).html() != textAuctionExpired) {
			$('#auction-status-' + auction_id).html(textAuctionExpired);
			$('#auction-status-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		} else if (auction_status_id == statusAuctionWon && $('#auction-status-' + auction_id).html() != textAuctionWon) {
			$('#auction-status-' + auction_id).html(textAuctionWon);
			$('#auction-status-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		} else if (auction_status_id == statusAuctionExtended && $('#auction-status-' + auction_id).html() != textAuctionExtended) {
			$('#auction-status-' + auction_id).html(textAuctionExtended);
			$('#auction-status-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		} else if (auction_status_id == statusAuctionInProgress && $('#auction-status-' + auction_id).html() != textAuctionInProgress) {
			$('#auction-status-' + auction_id).html(textAuctionInProgress);
			$('#auction-status-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		} else if (auction_status_id == statusAuctionRelisting && $('#auction-status-' + auction_id).html() != textAuctionRelisting) {
			$('#auction-status-' + auction_id).html(textAuctionRelisting);
			$('#auction-status-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		} else if (auction_status_id == statusAuctionStarting && $('#auction-status-' + auction_id).html() != textAuctionStarting) {
			$('#auction-status-' + auction_id).html(textAuctionStarting);
			$('#auction-status-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
		}
		if (auction_status_id == statusAuctionInProgress || auction_status_id == statusAuctionExtended) {
			time_difference = parseInt(real_ending_time - script_time_to_use);
			if (time_difference > 0) {
				display_countdown = countDownTimeBreaker(time_difference);
			} else {
				display_countdown = textAuctionGoingGoing;
			}
			is_active_auction++;
		} else if (auction_status_id == statusAuctionStarting || auction_status_id == statusAuctionRelisting) {
			time_difference = parseInt(starting_time - script_time_to_use);
			if (time_difference > 0) {
				display_countdown = '-' + countDownTimeBreaker(time_difference);
			} else {
				display_countdown = textAuctionGetStarted;
			}
			is_active_auction++;
		}
		if (is_active_auction) {
			$('#auction-timeleft-' + auction_id).html(display_countdown);
			if (time_difference <= defaultCountDownFast && time_difference >= 0 && (auction_status_id == statusAuctionStarting || auction_status_id == statusAuctionRelisting || auction_status_id == statusAuctionInProgress || auction_status_id == statusAuctionExtended)) {
				$('#auction-timeleft-' + auction_id).stop(true, true).queue(function(){$(this).effect('pulsate', {times: 2}, defaultAnimationFast); $(this).dequeue();});
			} else if (time_difference <= defaultCountDownTime && time_difference >= 0 && (auction_status_id == statusAuctionStarting || auction_status_id == statusAuctionRelisting || auction_status_id == statusAuctionInProgress || auction_status_id == statusAuctionExtended)) {
				$('#auction-timeleft-' + auction_id).stop(true, true).queue(function(){$(this).effect('pulsate', {times: 1}, defaultAnimationTime); $(this).dequeue();});
			} else {
				$('#auction-timeleft-' + auction_id).stop(true, true);
			}
			// helps resetting timer to normal state after a function recall
			if (lastSetInterval[auction_id] != defaultIntervalTime) {
				clearCountDownTimer(auction_id);
				countDownTimer[auction_id] = setInterval(function(){countDownAuction(0, auction_id, starting_time, highest_bid_amount, total_no_of_bid, real_ending_time, auction_status_id)}, defaultIntervalTime);
				lastSetInterval[auction_id] = defaultIntervalTime;
			}
		} else {
			$('#auction-timeleft-' + auction_id).stop(true, true).css('color', '').html(setDateTimeFormatShort(real_ending_time));
			$('#auction-timeleft-' + auction_id).parent().stop(true, true).queue(function(){$(this).effect('highlight', {}, defaultAnimationTime); $(this).dequeue();});
			clearCountDownTimer(auction_id);
		}
	}
}
function pollAuctionGlobal(auction_ids) {
	var auth = encodeURIComponent(Sha1.hash(String(parseInt(Math.floor(new Date().getTime() / 1000) + serverClientTimeDiff))));
	var curl = '../index.php?route=product/auction/auctionglobalpoll&auth=' + auth + '&auction_ids=' + auction_ids + '&last_polled=' + lastPollingTime + '&admin=1';
	lastPollingTime = parseInt(Math.floor(new Date().getTime() / 1000) + serverClientTimeDiff);
	$.ajax({
		url: curl,
		dataType: 'json',
		cache: false,
		success: function(auctions) {
			if (auctions instanceof Array && auctions.length > 0) {
				for (var auction_record = 0; auction_record < auctions.length; auction_record++) {
					var auction_id = parseInt(auctions[auction_record].auction_id);
					var highest_bid_amount = parseFloat(auctions[auction_record].highest_bid_amount);
					var total_no_of_bid = parseInt(auctions[auction_record].total_no_of_bid);
					var real_ending_time = parseInt(auctions[auction_record].real_ending_time);
					var auction_status_id = parseInt(auctions[auction_record].auction_status_id);
					if (auction_id) {
						var starting_time = parseInt(pollAuctionData[auction_id].starting_time);
						countDownAuction(1, auction_id, starting_time, highest_bid_amount, total_no_of_bid, real_ending_time, auction_status_id);
					}
				}
			}
		}
	});
}
<?php $auction_ids = array(); ?>
<?php foreach ($auctions as $auction) { ?>
<?php if ($auction['auction_status_id'] == $auction_status_ids['starting'] || $auction['auction_status_id'] == $auction_status_ids['relisting'] || $auction['auction_status_id'] == $auction_status_ids['inprogress'] || $auction['auction_status_id'] == $auction_status_ids['extended']) { ?>
<?php $auction_ids[] = $auction['auction_id']; ?>
countDownTimer[<?php echo $auction['auction_id']; ?>] = setInterval(function(){countDownAuction(0, <?php echo $auction['auction_id']; ?>, <?php echo $auction['starting_time']; ?>, <?php echo $auction['highest_bid_amount']; ?>, <?php echo $auction['total_no_of_bid']; ?>, <?php echo $auction['real_ending_time']; ?>, <?php echo $auction['auction_status_id']; ?>)}, defaultIntervalTime);
lastSetInterval[<?php echo $auction['auction_id']; ?>] = defaultIntervalTime;
pollAuctionData[<?php echo $auction['auction_id']; ?>] = {auction_id: <?php echo $auction['auction_id']; ?>, starting_time: <?php echo $auction['starting_time']; ?>};
<?php } ?>
<?php } ?>
<?php if ($auction_ids) { ?>
setInterval(function(){pollAuctionGlobal('<?php echo implode(',', $auction_ids); ?>')}, defaultPollingInterval);
setTimeout(function(){location.reload(true)}, defaultPollingTimeout);
<?php } ?>
//--></script>
<?php echo $footer; ?>