/* <![CDATA[ */


var _t_ct_time = 0;
var _t_ct_time_plain = 0;
var _t_ct_winner_id = 0;
var _t_ct_winner_name = '';
var _t_ct_price = 0;
var _t_ct_status = 0;
var _t_ct_status_changed = 0;
var _t_ct_last_life_update = 0;
var _t_ct_last_update_skipped = 0;
var _t_force_update = 0;
var _t_max_retries = 5;
var _t_max_wait_time = 30000;
var _t_failed_requests_inc = 0;
var _t_ct_latency_time = 1000;
var _t_ct_last_price = 0;
var _t_ct_force_update_time = 20;
var _t_ct_force_update = 0;
var cent_conv = 100;

var _t_first_t_slot = 120;
var _t_second_t_slot = 20;

var _update_interval = 1000;
var _start_time = 0
var _cached_user_id = 0;

var _intv = '';
var _intv_index = '';
var _intv_special = '';
var _intv_index_rev = '';
var _l_t_keys = Object();
var js_cd_speed_tics = new Object();
var _running_brw = new Object();
var _bid_history = new Array();
var _own_bid_history = new Array();
var _index_ct_prices = new Object();
var _index_rev_ids = new Object();
var _index_seats_available = new Object();
var _bid_out_types = new Array();
var _wording_single_bid = 'Single bid';
var _wording_bid_agent = 'ABE';
var _wording_bid_other = 'Other';
var _last_update_t_time = 0;
var _cds_image_deleted = 0;
_bid_out_types[1] = _wording_single_bid;
_bid_out_types[2] = _wording_bid_agent;
_bid_out_types[3] = _wording_bid_agent;
_bid_out_types[4] = _wording_bid_agent;
_bid_out_types[5] = _wording_bid_agent;
_bid_out_types[6] = _wording_bid_other;

var _ct_reset = 40;
var _default_bid_increment = 10;

var _au_st_future = 30;
var _au_st_future_wo_startdate = 31;
var _au_st_finished = 20;
var _au_st_paused = 10;
var _au_st_live = 1;

var _au_st_seated_not_started = 42;
var _au_st_seated_not_in = 43;
var _au_st_rev_run = 51;
var _au_st_rev_end = 52;

var _overwrite_timeout = 1000;
var _overwrite_timeout_index = 1000;
var _overwrite_timeout_special = 1000;
var _overwrite_timeout_index_rev = 9000;
var _overwrite_timeout_det_rev = 9000;

var _ct_server_prefix = '/';

var _single_auction_verify = '';
var _single_auction_verify_id = 0;
var _multi_auction_verify = '';
var _multi_auction_verify_id = '';
var _special_auction_verify = '';
var _special_auction_verify_id = '';
var _last_bid_placed = 0;

var _ms_diff = 0;

var _requested_aids = new Array();
var _requested_spec_aids = new Array();
var _requested_rev_aids = new Array();
var _requested_rev_det_aids = new Array();
var _a_times = new Array();
var _request_ct_aids = true;
var _request_ct_spec_aids = true;

/*
var _future_ct_running = 0;
var _future_ct_time = 0;
var _future_ct_changed = 0;
*/

var _last_bid_key = -1;

var _bid_history_blocked = 0;

var _ct_changed = 0

var _detail_request_running = 0;

var _last_action_div_displayed = 0;
var _a_d_last_update = 0;
var _index_auctions_ajax_last_update = 0;
var _index_rev_auctions_ajax_last_update = 0;
var _det_rev_auctions_ajax_last_update = 0;
var _special_auctions_ajax_last_update = 0;

var _is_refreshed = 0;
var bidders = new Array();
var bidders_ms_duration = 900000;
var nb_bidders = 0;

var mousex = 0;
var mousey = 0;
var _first_load = 1;

function _set_refreshed_auction(){
  _is_refreshed = 1;
}


var MouseIdleTimeout    = 2700000;
var timeOutEl     = '';

function beginMouseMonitoring() {
	Event.observe(document.body, 'mousemove', resetMouseIdle, true);
	setMouseIdle();
}

function mouseIdle() {
	window.location='/idle.asp';
}

function resetMouseIdle(evt) {
	window.clearTimeout( timeOutEl );
	setMouseIdle();
	mousex = mouseX(evt);
	mousey = mouseY(evt);
}

function setMouseIdle() {
	timeOutEl = window.setTimeout( "mouseIdle()", MouseIdleTimeout );
}

Event.observe(window, 'load', beginMouseMonitoring);

function mouseX(evt) {
if (evt.pageX) return evt.pageX;
else if (evt.clientX)
   return evt.clientX + (document.documentElement.scrollLeft ?
   document.documentElement.scrollLeft :
   document.body.scrollLeft);
else return null;
}
function mouseY(evt) {
if (evt.pageY) return evt.pageY;
else if (evt.clientY)
   return evt.clientY + (document.documentElement.scrollTop ?
   document.documentElement.scrollTop :
   document.body.scrollTop);
else return null;
}


/**
 * void a_det_ajax(int, int, int)
 *   - init counter requests on detail pages
 */
function a_det_ajax(auction_id, au_st, start_time, user_id, verify) {
  if (user_id == undefined || user_id == null) {
    user_id = 0;
  } else {
    if (user_id != 0) {
      _cached_user_id = user_id;
    }
  }

  if (verify == undefined || verify == null) {
    verify = '';
  }

  if (_cached_user_id != 0) {
    user_id = _cached_user_id;
  }

  if (au_st == _au_st_finished) {
    if (_intv != '' || _intv != null) {
      window.clearInterval(_intv);
    }
    return;
  }

  if (start_time > 0) {
    _start_time = start_time;
  }

  if (_l_t_keys['a_det'] == undefined || _l_t_keys['a_det'] == null) {
    _l_t_keys['a_det'] = 0;
  }

  _do_real_ct_request = 1;
  __t_upd_per = 4000;
  if (_t_ct_time_plain != "") {
    if (__t_upd_per > _t_first_t_slot) {
      __t_upd_per = 6000;
    } else if (__t_upd_per > _t_second_t_slot) {
      __t_upd_per = 4000;
    } else {
      __t_upd_per = 3000;
    }

    if (parseInt(_t_ct_time_plain) <= _t_ct_force_update_time) {
      _do_real_ct_request = 1;
      _t_ct_force_update = 1;
    } else {
      _t_ct_force_update = 0;
      if (parseInt(_t_ct_time_plain) > _t_first_t_slot
          && ((new Date()).getTime()-_a_d_last_update) < 5500) {
        _do_real_ct_request = 0;
      } else if (parseInt(_t_ct_time_plain) > _t_second_t_slot
        && ((new Date()).getTime()-_a_d_last_update)<2500) {
        _do_real_ct_request = 0;
      }

      if (_t_ct_time_plain > 1 && _t_failed_requests_inc < _t_max_retries) {
        if (_t_ct_last_life_update == 0
            || ((new Date()).getTime()-_t_ct_last_life_update) > 600) {
          _t_ct_time_plain--;
          _t_ct_time = calc_ct_from_time(_t_ct_time_plain);
          _update_interval = 950;
          _overwrite_timeout = "";
          $('countertime').innerHTML = _t_ct_time;// + "'";
        } else {
          $('countertime').innerHTML = $('countertime').innerHTML;// + ".";
        }
      } else if (_t_ct_time_plain == 1 || _t_failed_requests_inc >= _t_max_retries) {
        __t_ct_connect_image = '<img src="images/connecting_counter.gif" width="170" height="45" />';
        if (_t_ct_last_update_skipped == 1) {
          if ($('countertime')) {
            if ($('countertime').innerHTML != __t_ct_connect_image) {
              $('countertime').innerHTML = __t_ct_connect_image;
            } else {
//              $('countertime').innerHTML = "foo";
            }
          }
        } else {
          _t_ct_last_update_skipped = 1;
        }
      }
    }
  }

  // force update if bid was placed
  if (_t_force_update == 1) {
    _do_real_ct_request = 1;
    _t_force_update = 0;
  }

  // 1. get counter data
  if (_l_t_keys['a_det'] == 0) {
    if (_do_real_ct_request == 1) {
      _a_d_last_update = (new Date()).getTime();
      _l_t_keys['a_det'] = 1;
      do_ct_request(auction_id, user_id, 'a_det', verify);
    }
  } else {
    if (((new Date()).getTime()-_a_d_last_update)>__t_upd_per) {
       _l_t_keys['a_det'] = 0;
    }
  }

  // 2. process auction status
  get_interval_by_status(auction_id);
  // 3. check_status_code
  check_status_code();
  if (_t_ct_status == _au_st_paused) {
  	 if (parseInt(_t_ct_time_plain) > _t_first_t_slot
          && ((new Date()).getTime()-_a_d_last_update) < 5500) {
        _update_interval = 5600;
      } else if (parseInt(_t_ct_time_plain) > _t_second_t_slot
        && ((new Date()).getTime()-_a_d_last_update)<2500) {
        _update_interval = 2600;
      }
  }
  // update start_time
  _start_time -= (_update_interval/1000);

  _single_auction_verify = verify;
  _single_auction_verify_id = auction_id;


  if (_overwrite_timeout != "") {
    _update_interval -= parseInt(_overwrite_timeout);
    if (_update_interval <= 250) {
      _update_interval = 1000;
    } else {
      _update_interval += 30;
    }
  }

  if (_intv != '' || _intv != null) {
    window.clearInterval(_intv);
  }
  _intv = setInterval('a_det_ajax(' + auction_id + ', ' + _t_ct_status + ', ' + _start_time + ', ' + user_id + ', "' + verify + '")', _update_interval);
}


function a_rev_ind_ajax(auction_ids, user_id, verify) {
  if (auction_ids == '' || auction_ids == null) {
    return;
  }
  
  if(_requested_rev_aids == '' || _requested_rev_aids == null){
    _requested_rev_aids = auction_ids.split(',');
  }
  
  if (user_id == undefined || user_id == null) {
    user_id = 0;
  }

  if (verify == undefined || verify == null) {
    verify = '';
  }

  if (_l_t_keys['a_ind_rev'] == undefined || _l_t_keys['a_ind_rev'] == null) {
    _l_t_keys['a_ind_rev'] = 0;
  }
  
  if (_l_t_keys['a_ind_rev'] == 0) {
	 do_st_request_index_rev(auction_ids, user_id, 'a_ind_rev', verify, '0');
	 _index_rev_auctions_ajax_last_update = (new Date()).getTime();
   } else {
    if (((new Date()).getTime()-_index_rev_auctions_ajax_last_update)>9000) {
       _l_t_keys['a_ind_rev'] = 0;
    }
  }
  
  
   update_interval_index = 1000;
  if (parseInt(_overwrite_timeout_index_rev) > 500) {
    update_interval_index = _overwrite_timeout_index_rev;
  }
  if (_intv_index_rev != '') {
    window.clearTimeout(_intv_index_rev);
  }

  _intv_index_rev = setTimeout('a_rev_ind_ajax("' + auction_ids + '", "' + user_id + '", "' + verify + '")', update_interval_index);
}

function a_rev_det_ajax(auction_ids, user_id, verify) {
  if (auction_ids == '' || auction_ids == null) {
    return;
  }
  
  if(_requested_rev_det_aids == '' || _requested_rev_det_aids == null){
    _requested_rev_det_aids = auction_ids.split(',');
  }
  
  if (user_id == undefined || user_id == null) {
    user_id = 0;
  }

  if (verify == undefined || verify == null) {
    verify = '';
  }

  if (_l_t_keys['a_det_rev'] == undefined || _l_t_keys['a_det_rev'] == null) {
    _l_t_keys['a_det_rev'] = 0;
  }
  
  if (_l_t_keys['a_det_rev'] == 0) {
	 do_st_request_index_rev(auction_ids, user_id, 'a_det_rev', verify, '1');
	 _det_rev_auctions_ajax_last_update = (new Date()).getTime();
   } else {
    if (((new Date()).getTime()-_det_rev_auctions_ajax_last_update)>9000) {
       _l_t_keys['a_det_rev'] = 0;
    }
  }
  
  
   update_interval_index = 1000;
  if (parseInt(_overwrite_timeout_det_rev) > 500) {
    update_interval_index = _overwrite_timeout_det_rev;
  }
  if (_intv_index_rev != '') {
    window.clearTimeout(_intv_index_rev);
  }

  _intv = setTimeout('a_rev_det_ajax("' + auction_ids + '", "' + user_id + '", "' + verify + '")', update_interval_index);
}

/**
 * void a_ind_ajax(int, int, int)
 *   - init counter requests on index pages
 */
function a_ind_ajax(auction_ids, user_id, verify) {
  if (auction_ids == '' || auction_ids == null) {
    return;
  }
  
  if(_requested_aids == '' || _requested_aids == null){
    _requested_aids = auction_ids.split(',');
  }
  
  if(_request_ct_aids == false){
   window.clearTimeout(_intv_index);
   return;    
  }

  if (user_id == undefined || user_id == null) {
    user_id = 0;
  }

  if (verify == undefined || verify == null) {
    verify = '';
  }

  
  if (_l_t_keys['a_ind'] == undefined || _l_t_keys['a_ind'] == null) {
    _l_t_keys['a_ind'] = 0;
  }

  if (_l_t_keys['a_ind'] == 0) {
    _multi_auction_verify = verify;
    _multi_auction_verify_id = auction_ids;
    do_ct_request_index(auction_ids, user_id, 'a_ind', verify);
    _index_auctions_ajax_last_update =  (new Date()).getTime();
  } else {
    if (((new Date()).getTime()-_index_auctions_ajax_last_update)>3000) {
       _l_t_keys['a_ind'] = 0;
    }
  }



  update_interval_index = 1000;
  if (parseInt(_overwrite_timeout_index) > 500) {
    update_interval_index = _overwrite_timeout_index;
  }
  if (_intv_index != '') {
    window.clearTimeout(_intv_index);
  }

  _intv_index = setTimeout('a_ind_ajax("' + auction_ids + '", "' + user_id + '", "' + verify + '")', update_interval_index);
}



function a_spec_ajax(special_auction_ids, user_id, verify) {
  if (special_auction_ids == '' || special_auction_ids == null) {
    return;
  }
  
  if(_requested_spec_aids == '' || _requested_spec_aids == null){
    _requested_spec_aids = special_auction_ids.split(',');
  }

  if(_request_ct_spec_aids == false){
   window.clearTimeout(_intv_special);
   return;    
  }

  if (user_id == undefined || user_id == null) {
    user_id = 0;
  }

  if (verify == undefined || verify == null) {
    verify = '';
  }


  if (_l_t_keys['a_spec'] == undefined || _l_t_keys['a_spec'] == null) {
    _l_t_keys['index2'] = 0;
  }

  if (_l_t_keys['a_spec'] == 0) {
    _special_auction_verify = verify;
    _special_auction_verify_id = special_auction_ids;
    do_ct_request_index(special_auction_ids, user_id, 'a_spec', verify);
    _special_auctions_ajax_last_update =  (new Date()).getTime();
  } else {
    if (((new Date()).getTime()-_special_auctions_ajax_last_update)>3000) {
       _l_t_keys['a_spec'] = 0;
    }
  }


  update_interval_special_auctions = 1000;
  if (parseInt(_overwrite_timeout_special) > 500) {
    update_interval_special_auctions = _overwrite_timeout_special;
  }
  if (_intv_special != '') {
    window.clearTimeout(_intv_special);
  }

  _intv_special = setTimeout('a_spec_ajax("' + special_auction_ids + '", "' + user_id + '", "' + verify + '")', update_interval_special_auctions);
}


function parse_ct_response_index(transport, plain) {
  
  if (plain != undefined && plain != null && plain == 1) {
    counters = transport.split('#');
  } else {
    counters = transport.responseText.split('#');
  }
  for (i = 0; i <= counters.length; i++) {
    if (counters[i] == null) continue;
    counter_data = counters[i].split(':');
    auction_id = counter_data[0];
    div_name_counter = 'counter_index_page_' + auction_id;
    div_price_name = 'price_index_page_' + auction_id;
    div_name_winner = 'winner_index_page_' + auction_id;
    div_button_name = 'button_index_page_' + auction_id;
    div_button_name_finished = 'button_finished_index_page_' + auction_id;

    div_name_ct_spec =  'spec_countertime_' + auction_id;
    div_price_name_spec =  'spec_current_price_' + auction_id;
    div_name_winner_spec =  'spec_current_winner_' + auction_id;
	
	var au_st_tmp = 0;
	
    counter = counter_data[1].split('|');
    for (ii = 0; ii < counter.length; ii++) {
      data = counter[ii].split('=');
	  if (data[0] == 'fs') {
	  
	  }	  
	  else if (data[0] == 'as') {
	  
	  	au_st_tmp = data[1];
		
        if (data[1] == _au_st_paused) {
          _cur_time = new Date();
          _cur_secs = (_cur_time.getTime()/1000);
          if (_cur_secs%4 <= 2 && $(div_name_counter)) {
            $(div_name_counter).innerHTML = 'Pause';
          }
          if (_cur_secs%4 <= 2 && $(div_name_ct_spec)) {
            $(div_name_ct_spec).innerHTML = 'Pause';
          }
        } else if (data[1] == _au_st_finished) {

          _requested_aids = removeAuctionFromList(auction_id, _requested_aids);
          _requested_spec_aids = removeAuctionFromList(auction_id, _requested_spec_aids);
          
          if(_requested_aids.length == 0) {
            _request_ct_aids = false;
          }
          
          if(_requested_spec_aids.length == 0) {
            _request_ct_spec_aids = false;
          }

          hidedisplay_show(div_button_name_finished);
          hidedisplay_dis(div_button_name);
          if ($(div_name_counter)) {
            $(div_name_counter).innerHTML = 'Ended';
          }
          if ($(div_name_ct_spec)) {
            $(div_name_ct_spec).innerHTML = 'Ended';
          }
        } else if (data[1] == _au_st_seated_not_started ) {
			el = $(div_name_winner);
        	if (el) {
				el.innerHTML = '';
			}
			el = $(div_button_name);
			if (el) {
				if (el.innerHTML.indexOf('images/buy_seat_button.jpg') == -1) {
					el.innerHTML = '<a href=\"https://www.fscauctions.com/auctionbuyseat.asp?aid=' + auction_id + '\"><img src=\"images/buy_seat_button.jpg\" border=\"0\"></a>';
				}
			}
		} else if (data[1] == _au_st_seated_not_in ) {
			el = $(div_button_name);
			if (el) {
				if (el.innerHTML.indexOf('images/buy_seat_button.jpg') == -1) {
					el.innerHTML = '<a href=\"https://www.fscauctions.com/auctionbuyseat.asp?aid=' + auction_id + '\"><img src=\"images/buy_seat_button.jpg\" border=\"0\"></a>';
				}
			}
		} else if (data[1] == _au_st_live ) {
			
			el = $(div_button_name);
			if (el) {
				// remove buy seat button if they have a seat and this is a seated auction
				if (el.innerHTML.indexOf('images/buy_seat_button.jpg') != -1) {
					//el.innerHTML = '<a href="javascript:place_bid(\'' +  auction_id + '\', \'bid_error_div_' +  auction_id + '\', \'' & Session("iUserID") & "', '0')"><img src="images/bid_button.gif" alt="" border="0" id="bid_button_index_" & rsHomeFeatured("id") & " /></a>'
					window.location.reload();
				}
			}
		} else if (data[1] == _au_st_rev_run ) {
			//reveal auction running
			 if ($(div_name_counter)) {
			 		if (($(div_name_counter)).innerHTML.indexOf('images/SCOOPIT.jpg') == -1) {
						if ($(div_name_counter).style.display != 'none')
			          		$(div_name_counter).style.display = 'none';
					}
				}
		} else if (data[1] == _au_st_rev_end ) {
			_requested_rev_aids = removeAuctionFromList(auction_id, _requested_rev_aids);
			hidedisplay_show(div_button_name_finished);
            hidedisplay_dis(div_button_name);
            if ($(div_name_counter)) {
              $(div_name_counter).innerHTML = 'Ended';
			  $(div_name_counter).style.display = '';
            }
		}
      } 
	  else if (data[0] == 'at') {
	  if (au_st_tmp != _au_st_finished)
	  {
	  		_a_times[auction_id] = data[1];
		    if (au_st_tmp != _au_st_seated_not_started && au_st_tmp != _au_st_rev_run && au_st_tmp != _au_st_rev_end )
			{
		        if (data[1] == '-') {
		          _t_time = '--:--:--';
		        } else {
		          _t_time = calc_ct_from_time(data[1]);
		        }
		        if ($(div_name_counter)) {
		          $(div_name_counter).innerHTML = _t_time;
		          if (parseInt(data[1]) <= 10 && parseInt(data[1]) > 0) {
		            $(div_name_counter).style.color = '#DD0000';
		          } else {
		            $(div_name_counter).style.color = '';
		          }
		        }
		         if ($(div_name_ct_spec)) {
		          $(div_name_ct_spec).innerHTML = _t_time;
		          if (parseInt(data[1]) <= 10 && parseInt(data[1]) > 0) {
		            $(div_name_ct_spec).style.color = '#DD0000';
		          } else {
		            $(div_name_ct_spec).style.color = '';
		          }
		        }
			 } else if (au_st_tmp == _au_st_rev_run) {
			  	// we don't actually want to do anything here. 
				 // maybe eliminate text.
				 if ($(div_name_counter)) {
		          	$(div_name_counter).style.display = 'none';
				}
			 } else if (au_st_tmp == _au_st_rev_end) {
			 	if ($(div_name_counter)) {
	              $(div_name_counter).innerHTML = 'Ended';
				  $(div_name_counter).style.display = '';
	            }
			 }
			 else 
			 {
			  	if ($(div_name_counter)) {
					$(div_name_counter).innerHTML = data[1] 
					$(div_name_counter).style.color = '#66BC29';
				}
				if ($(div_name_ct_spec)) {
					$(div_name_counter).innerHTML = data[1]
				}
				 if (_index_seats_available[auction_id] == null
		            || _index_seats_available[auction_id] == '') {
		          _index_seats_available[auction_id] = data[1];
		        } else {
		          if (_index_seats_available[auction_id] != data[1]) {
		            new Effect.Highlight(div_name_counter, {duration:1,startcolor:'#ff0000', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
		            _index_seats_available[auction_id] = data[1];
		          }
		        }
			 }
		 }
      } 
	  
	  else if (data[0] == 'aw' && data[1] != '') {
	  	//if (au_st_tmp != _au_st_seated_not_started)
		//{
	        el = $(div_name_winner);
	        if (el) {
	          el.innerHTML = data[1];
	        }
	        if($(div_name_winner_spec)){
	          $(div_name_winner_spec).innerHTML = data[1];
	        }
			if (au_st_tmp == _au_st_rev_run) {
				if (_index_rev_ids[auction_id] == null
	            || _index_rev_ids[auction_id] == '') {
					_index_rev_ids[auction_id] = data[1];
				} else {
					if (_index_rev_ids[auction_id] != data[1]) {
						new Effect.Highlight(div_name_winner, {duration:1,startcolor:'#ff0000', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
						_index_rev_ids[auction_id] = data[1];
					}
				
				}
				
			}
		//}
		//else
		//{
		//	if($(div_name_winner)) {
		//		$(div_name_winner).innerHTML = '';
		//		$(div_name_winner).style.display = 'none';
		//	}
		//	if($(div_name_winner_spec)){
		//		$(div_name_winner_spec).innerHTML = '';
		//		$(div_name_winner).style.display = 'none';
		//	}
		//}
      } else if (data[0] == 'ap') {
	   if (au_st_tmp != _au_st_seated_not_started && au_st_tmp != _au_st_seated_not_in && au_st_tmp != _au_st_rev_run) {
		
	        if ($(div_price_name)) {
	          $(div_price_name).innerHTML = format_raw_to_price(data[1]);
	        }
			
	        if ($(div_price_name_spec)) {
	          $(div_price_name_spec).innerHTML = format_raw_to_price(data[1]);
	        }
			
	        if (_index_ct_prices[auction_id] == null
	            || _index_ct_prices[auction_id] == '') {
	          _index_ct_prices[auction_id] = data[1];
	        } else {
	          if (_index_ct_prices[auction_id] != data[1]) {
	            new Effect.Highlight(div_price_name, {duration:1,startcolor:'#ff0000', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
	            _index_ct_prices[auction_id] = data[1];
	          }
	        }
		} else if (au_st_tmp == _au_st_rev_run) {
			if ($(div_price_name)) {
	          $(div_price_name).innerHTML = 'Hidden';
	        }
		} else {
			 if ($(div_price_name)) {
	          $(div_price_name).innerHTML = data[1] + ' Bids';
	        }
			
	        if ($(div_price_name_spec)) {
	          $(div_price_name_spec).innerHTML = data[1] + ' Bids';
	        }
		}
      }
    }
  }
}
function parse_ct_response_det(transport, plain) {
  
  var div_price_name2 = 'a_current_price2';
  
  if (plain != undefined && plain != null && plain == 1) {
    counters = transport.split('#');
  } else {
    counters = transport.responseText.split('#');
  }
  for (i = 0; i <= counters.length; i++) {
    if (counters[i] == null) continue;
    counter_data = counters[i].split(':');
    auction_id = counter_data[0];
	
	div_name_counter = 'countertime';
	div_price_name = 'a_current_price';
	div_price_name2 = 'a_current_price2';
	div_name_winner = 'a_current_winner';
	div_button_name = 'bid_button_div';
	div_button_name_finished = 'auctioninfo_items_box';

    div_name_ct_spec =  'spec_countertime_' + auction_id;
    div_price_name_spec =  'spec_current_price_' + auction_id;
    div_name_winner_spec =  'spec_current_winner_' + auction_id;
	
	var au_st_tmp = 0;
	
    counter = counter_data[1].split('|');
    for (ii = 0; ii < counter.length; ii++) {
      data = counter[ii].split('=');
	  if (data[0] == 'fs') {
	  
	  }	  
	  else if (data[0] == 'as') {
	  
	  	au_st_tmp = data[1];
		
        if (data[1] == _au_st_paused) {
          _cur_time = new Date();
          _cur_secs = (_cur_time.getTime()/1000);
          if (_cur_secs%4 <= 2 && $(div_name_counter)) {
            $(div_name_counter).innerHTML = 'Pause';
          }
          if (_cur_secs%4 <= 2 && $(div_name_ct_spec)) {
            $(div_name_ct_spec).innerHTML = 'Pause';
          }
        } else if (data[1] == _au_st_finished) {

          _requested_aids = removeAuctionFromList(auction_id, _requested_aids);
          _requested_spec_aids = removeAuctionFromList(auction_id, _requested_spec_aids);
          
          if(_requested_aids.length == 0) {
            _request_ct_aids = false;
          }
          
          if(_requested_spec_aids.length == 0) {
            _request_ct_spec_aids = false;
          }

          hidedisplay_show(div_button_name_finished);
          hidedisplay_dis(div_button_name);
          if ($(div_name_counter)) {
            $(div_name_counter).innerHTML = 'Ended';
          }
          if ($(div_name_ct_spec)) {
            $(div_name_ct_spec).innerHTML = 'Ended';
          }
        } else if (data[1] == _au_st_seated_not_started ) {
			el = $(div_name_winner);
        	if (el) {
				el.innerHTML = '';
			}
			el = $(div_button_name);
			if (el) {
				if (el.innerHTML.indexOf('images/buy_seat_button.jpg') == -1) {
					el.innerHTML = '<a href=\"https://www.fscauctions.com/auctionbuyseat.asp?aid=' + auction_id + '\"><img src=\"images/buy_seat_button.jpg\" border=\"0\"></a>';
				}
			}
		} else if (data[1] == _au_st_seated_not_in ) {
			el = $(div_button_name);
			if (el) {
				if (el.innerHTML.indexOf('images/buy_seat_button.jpg') == -1) {
					el.innerHTML = '<a href=\"https://www.fscauctions.com/auctionbuyseat.asp?aid=' + auction_id + '\"><img src=\"images/buy_seat_button.jpg\" border=\"0\"></a>';
				}
			}
		} else if (data[1] == _au_st_live ) {
			
			el = $(div_button_name);
			if (el) {
				// remove buy seat button if they have a seat and this is a seated auction
				if (el.innerHTML.indexOf('images/buy_seat_button.jpg') != -1) {
					//el.innerHTML = '<a href="javascript:place_bid(\'' +  auction_id + '\', \'bid_error_div_' +  auction_id + '\', \'' & Session("iUserID") & "', '0')"><img src="images/bid_button.gif" alt="" border="0" id="bid_button_index_" & rsHomeFeatured("id") & " /></a>'
					window.location.reload();
				}
			}
		} else if (data[1] == _au_st_rev_run ) {
			//reveal auction running
			 if ($(div_name_counter)) {
			 		if (($(div_name_counter)).innerHTML.indexOf('images/SCOOPIT.jpg') == -1) {
						if ($(div_name_counter).style.display != 'none')
			          		$(div_name_counter).style.display = 'none';
					}
				}
		} else if (data[1] == _au_st_rev_end ) {
			_requested_rev_aids = removeAuctionFromList(auction_id, _requested_rev_aids);
			hidedisplay_show(div_button_name_finished);
            hidedisplay_dis(div_button_name);
            if ($(div_name_counter)) {
              $(div_name_counter).innerHTML = 'Ended';
			  $(div_name_counter).style.display = '';
            }
		}
      } 
	  else if (data[0] == 'at') {
	  if (au_st_tmp != _au_st_finished)
	  {
		    if (au_st_tmp != _au_st_seated_not_started && au_st_tmp != _au_st_rev_run && au_st_tmp != _au_st_rev_end )
			{
				_a_times[auction_id] = data[1];
		        if (data[1] == '-') {
		          _t_time = '--:--:--';
		        } else {
		          _t_time = calc_ct_from_time(data[1]);
		        }
		        if ($(div_name_counter)) {
		          $(div_name_counter).innerHTML = _t_time;
		          if (parseInt(data[1]) <= 10 && parseInt(data[1]) > 0) {
		            $(div_name_counter).style.color = '#DD0000';
		          } else {
		            $(div_name_counter).style.color = '';
		          }
		        }
		         if ($(div_name_ct_spec)) {
		          $(div_name_ct_spec).innerHTML = _t_time;
		          if (parseInt(data[1]) <= 10 && parseInt(data[1]) > 0) {
		            $(div_name_ct_spec).style.color = '#DD0000';
		          } else {
		            $(div_name_ct_spec).style.color = '';
		          }
		        }
			 } else if (au_st_tmp == _au_st_rev_run) {
			  	// we don't actually want to do anything here. 
				 // maybe eliminate text.
				 if ($(div_name_counter)) {
		          	$(div_name_counter).style.display = 'none';
				}
			 } else if (au_st_tmp == _au_st_rev_end) {
			 	if ($(div_name_counter)) {
	              $(div_name_counter).innerHTML = 'Ended';
				  $(div_name_counter).style.display = '';
	            }
			 }
			 else 
			 {
			  	if ($(div_name_counter)) {
					$(div_name_counter).innerHTML = data[1] 
					$(div_name_counter).style.color = '#66BC29';
				}
				if ($(div_name_ct_spec)) {
					$(div_name_counter).innerHTML = data[1]
				}
				 if (_index_seats_available[auction_id] == null
		            || _index_seats_available[auction_id] == '') {
		          _index_seats_available[auction_id] = data[1];
		        } else {
		          if (_index_seats_available[auction_id] != data[1]) {
		            new Effect.Highlight(div_name_counter, {duration:1,startcolor:'#ff0000', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
		            _index_seats_available[auction_id] = data[1];
		          }
		        }
			 }
		 }
      } 
	  
	  else if (data[0] == 'aw' && data[1] != '') {
	  	//if (au_st_tmp != _au_st_seated_not_started)
		//{
	        el = $(div_name_winner);
	        if (el) {
	          el.innerHTML = data[1];
	        }
	        if($(div_name_winner_spec)){
	          $(div_name_winner_spec).innerHTML = data[1];
	        }
			if (au_st_tmp == _au_st_rev_run) {
				if (_index_rev_ids[auction_id] == null
	            || _index_rev_ids[auction_id] == '') {
					_index_rev_ids[auction_id] = data[1];
				} else {
					if (_index_rev_ids[auction_id] != data[1]) {
						new Effect.Highlight(div_name_winner, {duration:1,startcolor:'#ff0000', endcolor:'#FFFFFF', restorecolor:'#FFFFFF'});
						_index_rev_ids[auction_id] = data[1];
					}
				
				}
				
			}
		//}
		//else
		//{
		//	if($(div_name_winner)) {
		//		$(div_name_winner).innerHTML = '';
		//		$(div_name_winner).style.display = 'none';
		//	}
		//	if($(div_name_winner_spec)){
		//		$(div_name_winner_spec).innerHTML = '';
		//		$(div_name_winner).style.display = 'none';
		//	}
		//}
      } else if (data[0] == 'ap') {
	   if (au_st_tmp != _au_st_seated_not_started && au_st_tmp != _au_st_seated_not_in && au_st_tmp != _au_st_rev_run) {
		
	        if ($(div_price_name)) {
	          $(div_price_name).innerHTML = format_raw_to_price(data[1]);
	        }
			 if ($(div_price_name2)) {
	          $(div_price_name2).innerHTML = format_raw_to_price(data[1]);
	        }
			
			
	        if ($(div_price_name_spec)) {
	          $(div_price_name_spec).innerHTML = format_raw_to_price(data[1]);
	        }
			
	        if (_index_ct_prices[auction_id] == null
	            || _index_ct_prices[auction_id] == '') {
	          _index_ct_prices[auction_id] = data[1];
	        } else {
	          if (_index_ct_prices[auction_id] != data[1]) {
	            new Effect.Highlight(div_price_name, {duration:1,startcolor:'#ff0000', endcolor:'#FFAB71', restorecolor:'#FFAB71'});
	            _index_ct_prices[auction_id] = data[1];
	          }
	        }
		} else if (au_st_tmp == _au_st_rev_run) {
			if ($(div_price_name)) {
	          $(div_price_name).innerHTML = 'Hidden';
	        }
		} else {
			 if ($(div_price_name)) {
	          $(div_price_name).innerHTML = data[1] + ' Bids';
	        }
			
	        if ($(div_price_name_spec)) {
	          $(div_price_name_spec).innerHTML = data[1] + ' Bids';
	        }
		}
      }
    }
  }
}
var mlastNow = Object();


function refreshDetails(mUpdateURL, script_id) {
  if (mlastNow[script_id] == null || mlastNow[script_id] == undefined) {
    mlastNow[script_id] = 0;
  }

  if (((new Date()).getTime()-mlastNow[script_id])<200) return;

  mlastNow[script_id] = (new Date()).getTime();
  var script = document.createElement('script');

  script.type = 'text/javascript';
  script.src = mUpdateURL + "&now="+(new Date()).getTime();
  script.id = script_id + '_refresh_ajax' + '4';

  // remove old script-node (if there is one..)
  el = document.getElementById(script.id);
  if (el) {
    document.getElementsByTagName('head')[0].removeChild( el );
  }

  // set new script node
  document.getElementsByTagName('head')[0].appendChild(script);
}


var single_updates = new Object();
function force_single_bid_update(auction_id, user_id) {
  if (single_updates[auction_id] == undefined || single_updates[auction_id] == null) {
    single_updates[auction_id] = 0;
  }

  if (single_updates[auction_id] == 1) {
    return;
  }

  script_id = auction_id + '_single';

  url = _ct_server_prefix + 'counter/live.asp?ext=1' + '&aid=' + auction_id;
  if (user_id != undefined && user_id != null && user_id != 0) {
    url += '&uid=' + user_id;
  }

  refreshDetails(url, script_id);
}



/**
 * void do_ct_request(int)
 *   - do counter request and call success function
 */
function do_ct_request(auction_id, user_id, lock_key, verify) {
    url = _ct_server_prefix + 'counter/live.asp?aid=' + auction_id;
  if (user_id != undefined && user_id != null && user_id != 0) {
    url += '&uid=' + user_id;
  }

  if (verify != undefined && verify != null) {
    url += '&val=' + verify;
  }

  if (lock_key == undefined || lock_key == null || lock_key == 0) {
    lock_key = 0;
  }

  if (_last_bid_key > -1) {
    url += '&lbp=' + _last_bid_key;
  }


  options = {method: 'get',
    onSuccess: function(transport) {
                  eval(transport.responseText);
                }
  }
  if (lock_key != 0) {
    if (_l_t_keys[lock_key] == undefined || _l_t_keys[lock_key] == null || _l_t_keys[lock_key] == 0) {
      _l_t_keys[lock_key] = 1;
    }
    options = {method: 'get',
      onSuccess: function(transport) {
                    eval(transport.responseText);
                  },
      onComplete: function(transport) {
                    _l_t_keys[lock_key] = 0;
                  }
    }
  }

  new Ajax.Request(url, options);

}


function _srv_detail(transport, auction_id, reset_ct_time, request_user_time) {
  if (reset_ct_time != null && reset_ct_time != undefined
      && reset_ct_time != '' && reset_ct_time != 0) {
    _overwrite_timeout = (1000-reset_ct_time);
  }

  if (typeof(request_user_time) != "undefined"
      && null != request_user_time
      && parseInt(request_user_time) > 0) {
    if (((new Date()).getTime()-parseInt(request_user_time)) > _t_ct_latency_time) {
      if (_t_ct_force_update == 0) {
        _l_t_keys['a_det'] = 0;
        _t_ct_last_update_skipped = 1;
        _t_failed_requests_inc++;
        return "";
      }
    }
  }

  _t_ct_last_update_skipped = 0;
  _t_failed_requests_inc = 0;

  parse_ct_response(transport, auction_id, 1);
  _l_t_keys['a_det'] = 0;
}



function _srv_ext(transport, auction_id, reset_ct_time) {
  if (reset_ct_time != null && reset_ct_time != undefined
      && reset_ct_time != '' && reset_ct_time != 0) {
    _overwrite_timeout_index = reset_ct_time;
    _overwrite_timeout_special = reset_ct_time;
  }

  parse_ct_response_ext(transport, auction_id);
}

function do_st_request_index_rev(auction_ids, user_id, lock_key, verify, det) {
  if (auction_ids == '' || auction_ids == null) {
    return;
  }
  
  if (det == '' || det == null) {
  	det=0;
  }
  url = _ct_server_prefix + 'counter/reveal.asp?aids=' + auction_ids;
  if (user_id != undefined && user_id != null && user_id != 0) {
    url += '&uid=' + user_id;
  }
  if (verify != undefined && verify != null) {
    url += '&val=' + verify;
  }
  if (det == '1') {
  	url += '&det=' + det;
  }
  if (lock_key == undefined || lock_key == null || lock_key == 0) {
    lock_key = 0;
  }
  if (lock_key != 0) {
    if (_l_t_keys[lock_key] == undefined || _l_t_keys[lock_key] == null || _l_t_keys[lock_key] == 0) {
      _l_t_keys[lock_key] = 1;

  options = {method: 'get',
    onSuccess: function(transport) {

                  eval(transport.responseText)
                }
  }

  if (lock_key != 0) {
    if (_l_t_keys[lock_key] == undefined || _l_t_keys[lock_key] == null || _l_t_keys[lock_key] == 0) {
      _l_t_keys[lock_key] = 1;
    }
    options = {method: 'get',
      onSuccess: function(transport) {
                    eval(transport.responseText)
                  },
      onComplete: function(transport) {
                    _l_t_keys[lock_key] = 0;
                  }
    }
  }

  new Ajax.Request(url, options);


    }
  }

}

function do_ct_request_index(auction_ids, user_id, lock_key, verify) {
  if (auction_ids == '' || auction_ids == null) {
    return;
  }

  url = _ct_server_prefix + 'counter/live1.asp?aids=' + auction_ids;
  if (user_id != undefined && user_id != null && user_id != 0) {
    url += '&uid=' + user_id;
  }
  if (verify != undefined && verify != null) {
    url += '&val=' + verify;
  }
  if (lock_key == undefined || lock_key == null || lock_key == 0) {
    lock_key = 0;
  }
  if (lock_key != 0) {
    if (_l_t_keys[lock_key] == undefined || _l_t_keys[lock_key] == null || _l_t_keys[lock_key] == 0) {
      _l_t_keys[lock_key] = 1;

  options = {method: 'get',
    onSuccess: function(transport) {

                  eval(transport.responseText)
                }
  }

  if (lock_key != 0) {
    if (_l_t_keys[lock_key] == undefined || _l_t_keys[lock_key] == null || _l_t_keys[lock_key] == 0) {
      _l_t_keys[lock_key] = 1;
    }
    options = {method: 'get',
      onSuccess: function(transport) {
                    eval(transport.responseText)
                  },
      onComplete: function(transport) {
                    _l_t_keys[lock_key] = 0;
                  }
    }
  }

  new Ajax.Request(url, options);


    }
  }

}


/**
 * void check_status_code(void)
 *   - get status code specific HTML
 */
function check_status_code() {
  if (_t_ct_status == _au_st_finished) {
    if ($('getbidsbutton')) {
      $('getbidsbutton').innerHTML = '<strong>Auction ended!</strong>';
    }
    if ($('bidagent')) {
      $('bidagent').innerHTML = '';
    }
    window.location.reload();
  }
}

/**
 * void get_interval_by_status(int)
 *   - check for counter status and adapt update interval
 */
function get_interval_by_status(auction_id) {

  // set interval
  if (_t_ct_status_changed == 1
      || _t_ct_status == _au_st_future) {
    if (_t_ct_status != 0) {
      if (_t_ct_status == _au_st_future) {
        // future auction
        _update_interval = 1000;
        if (_start_time > 0) {
          _update_interval = (_start_time*1000);
          if (_start_time < 10) {
            _update_interval = 1000;
          } else if (_update_interval > 5000 || _update_interval < 0) {
            _update_interval = 1000;
          }
        }
      } else if (_t_ct_status == _au_st_paused) {
        _update_interval = 2000;
      } else if (_t_ct_status == _au_st_live) {
        _update_interval = 1000;
      }
    }


    

    if (_t_ct_status == _au_st_live
        || _t_ct_status == _au_st_future) {

      if (parseInt(_overwrite_timeout) > 500) {
        _update_interval = _overwrite_timeout;
      }
    }

    _t_ct_status_changed = 0;
    
  }
}



function parse_ct_response_ext(transport, auction_id) {

  if (transport == undefined || transport == null) {
    return;
  }
  result_array = transport.split("|");

  div_ct_name = 'countertime';
  div_winner = 'a_current_winner';
  div_price_name = 'a_current_price';

  div_ct_name_index = 'counter_index_page_' + auction_id;
  div_price_index = 'price_index_page_' + auction_id;
  div_winner_index = 'winner_index_page_' + auction_id;


  for (i = 0; i < result_array.length; i++) {
    if ('' == result_array[i] || null == result_array[i]) {
      continue;
    }
    data = result_array[i].split("=");
    if (data.length < 2) {
      continue;
    }
    if (data[0] == 'at' && data[1] != '') {
      _t_ct_time = data[1];
      if (_t_ct_time != undefined && _t_ct_time != null && _t_ct_time != '') {
        _t_ct_time = calc_ct_from_time(_t_ct_time);
      } else {
        _t_ct_time = '';
      }
      if (_t_ct_time != '' && _t_ct_time != '-') {
        if ($(div_ct_name)) {
          $(div_ct_name).innerHTML = _t_ct_time;
        } else if ($(div_ct_name_index)) {
          $(div_ct_name_index).innerHTML = _t_ct_time;
        }
      }
    }  else if (data[0] == 'aw' && data[1] != '') {
      if ($(div_winner_index)) {
        $(div_winner_index).innerHTML = data[1];
      } else if ($(div_winner)) {
        $(div_winner).innerHTML = data[1];
      }
    }  else if (data[0] == 'ap' && data[1] != '') {
      if ($(div_price_index)) {
        $(div_price_index).innerHTML = data[1];
//        new Effect.Highlight(div_price_index, {duration:1,startcolor:'#ff0000',endcolor:'#ffffff',restorecolor:'#FFFFFF'});
      } else if ($(div_price_name)) {
        $(div_price_name).innerHTML = data[1];
//        new Effect.Highlight(div_price_name, {duration:1,startcolor:'#ff0000',endcolor:'#ffffff',restorecolor:'#FFFFFF'});
      }
    }
  }
  return;
}

function get_my_placed_bids(div_stats_own, auction_id) {
    if ($(div_stats_own)) {
        new Ajax.Updater(div_stats_own, 'ajax/my_placed_bids.asp?aid=' + auction_id);
    }
}


/**
 * void parse_ct_response(object int)
 *   - parse request from counter server and adapt html
 */
function parse_ct_response(transport, auction_id, plain) {
  if (plain != undefined && plain != null && plain == 1) {
    result_array = transport.split("|");
  } else {
    result_array = transport.responseText.split("|");
  }

  div_ct_name = 'countertime';

  
  has_price_update = 0;
  tmp_counter = 0;
  for (i = 0; i < result_array.length; i++) {
    tmp_data = result_array[i].split("=");
    if (tmp_data.length < 2) {
      continue;
    }
    if (tmp_data[0] == 'at') {
      tmp_counter = tmp_data[1];
    }
    if (tmp_data[0] == 'ap') {
      has_price_update = 1;
    }
    if (tmp_data[0] == 'rl' && tmp_data[1] == 1) {
      if(_is_refreshed == 0){
        // reload if rl
        window.location.reload();
      }
    }
  }

  

  for (i = 0; i < result_array.length; i++) {
    if ('' == result_array[i] || null == result_array[i]) {
      continue;
    }
    data = result_array[i].split("=");
    if (data.length < 2) {
      continue;
    }

    if (_last_bid_key != null) {
      if (js_cd_speed_tics != undefined && js_cd_speed_tics != null) {
        _last_cs_speed_matched = 0;
        _current_speed = 20;
        for (var ii in js_cd_speed_tics) {
          if (_last_cs_speed_matched == 1) {
            _update_ct_speed_image(ii, js_cd_speed_tics[ii], _current_speed);
            _last_cs_speed_matched = 0;
          }
          if (parseInt(_last_bid_key) >= parseInt(js_cd_speed_tics[ii])) {
            _last_cs_speed_matched = 1;
            _current_speed = ii;
          }
        }
        if (_last_cs_speed_matched == 1) {
          _update_ct_speed_image(_current_speed, 1000, _current_speed);
          _delete_ct_speed_image(_current_speed);
          _last_cs_speed_matched = 0;
        }
      }
    }


    if (data[0] == 'at') {
      _t_ct_time = data[1];
      _t_ct_time_plain = data[1];
      _t_ct_last_life_update = (new Date()).getTime();
	  _a_times[auction_id] = data[1];


      if (_t_ct_status == _au_st_future_wo_startdate) {
        _t_ct_time = '-- : -- : -- ';
      } else {
        if (_t_ct_time == '-') {
          _t_ct_time = '-- : -- : --';
        } else if (_t_ct_status == _au_st_live
                   && (_t_ct_time == '0' || _t_ct_time == '')) {
          _t_ct_time = '';
        } else {
          _t_ct_time = calc_ct_from_time(_t_ct_time);
        }
      }

      if ($(div_ct_name) && _t_ct_time != '') {
        $(div_ct_name).innerHTML = _t_ct_time;
        if (parseInt(data[1]) <= 10 && parseInt(data[1]) > 0) {
          $(div_ct_name).style.color = '#DD0000';
          if ($('last_actions_div').style.display == 'none'
              &&  $('last_actions_div').innerHTML != '<img src="images/AuctionAlmostOver_bl.gif" height="20">') {
              $('last_actions_div').innerHTML = '<img src="images/AuctionAlmostOver_bl.gif" height="20">';
            $('last_actions_div').style.display = '';
          }
        } else {
          if (_last_action_div_displayed == 0) {
            $('countertime').style.color = '';
            $('last_actions_div').style.display = 'none';
          }
        }
      } else if ($('counter_index_page_' + auction_id)) {
        $('counter_index_page_' + auction_id).innerHTML = _t_ct_time;
      }


    } else if (data[0] == 'aw' && data[1] != '') {
      _t_ct_winner_name = data[1];
      if ($('a_current_winner')) {
        $('a_current_winner').innerHTML = _t_ct_winner_name;
      }
      if ($('winner_index_page_' + auction_id)) {
        $('winner_index_page_' + auction_id).innerHTML = _t_ct_winner_name;
      }
    } else if (data[0] == 'ap') {
      _t_ct_price = data[1];
      if ($('a_current_price')) {
        $('a_current_price').innerHTML = format_raw_to_price(_t_ct_price);
      }
      if ($('a_current_price2')) {
        $('a_current_price2').innerHTML = format_raw_to_price(_t_ct_price);
      }
      if ($('price_index_page_' + auction_id)) {
        $('price_index_page_' + auction_id).innerHTML = format_raw_to_price(_t_ct_price);
      }

      if (_t_ct_price != _ct_changed) {
        
        if (_last_bid_key != null && _last_bid_key != undefined
            && _last_bid_key > 0) {
          if ($('a_current_price')) {
             $('a_current_price').style.backgroundColor='#FFAB71';
             new Effect.Highlight('a_current_price', {duration:1,startcolor:'#ff0000',endcolor:'#FFAB71',restorecolor:'#FFAB71'});
          } else if ($('price_index_page_' + auction_id)) {
            new Effect.Highlight('price_index_page_' + auction_id, {duration:1,startcolor:'#ff0000',endcolor:'#ffffff',restorecolor:'#FFFFFF'});
          }
        } else if ($('price_index_page_' + auction_id)) {
          new Effect.Highlight('price_index_page_' + auction_id, {duration:1,startcolor:'#ff0000',endcolor:'#ffffff',restorecolor:'#FFFFFF'});
        }
      }

      if (_last_bid_key != -1) {
        // update savings
        update_savings_details(auction_id,0);
      }
      // counter changed
      _ct_changed = _t_ct_price;

    } else if (data[0] == 'as') {
      if (data[1] != _t_ct_status) {
        _t_ct_status_changed = 1;
      }
      _t_ct_status = data[1];

      // display puased if needed
      if (_t_ct_status == _au_st_paused) {
        _cur_time = new Date();
        _cur_secs = _cur_time.getTime();
        if (_cur_time%5 <= 2) {
          $(div_ct_name).innerHTML = 'Pause';
        }
      }
	  else if (_t_ct_status == _au_st_future) {
	  	var el2 = $('bid_button_div');
		if (el2) {
			if (el2.style.display == '') {
				el2.style.display = 'none';
			}
		}
	  } else {
	  	var el2 = $('bid_button_div');
		if (el2) {
			if (el2.style.display == 'none') {
				el2.style.display = '';
			}
		}
	  
	  }
    } else if (data[0] == 'awi') {
      _t_ct_winner_id = data[1];
    } else if (data[0] == 'bh' && data[1] != '') {
      parse_bid_history(data[1], auction_id);

      if($('bid_agent_ov')){
         if($('bid_agent_ov').getElementsByTagName("td") != null
            && $('bid_agent_ov').getElementsByTagName("td") != undefined){
           if($('bid_agent_ov').getElementsByTagName("td").length > 1) {
            update_bid_agent(auction_id);
          }
         }
      }

    } else if (data[0] == 'lui') {
      parse_last_update_info(data[1]);
    }
  }

  refreshBiddersList();

  _detail_request_running = 0;
}


var _lui_running = '';
function parse_last_update_info(lui) {
  lui_data = lui.split('#');
  lui_out = '';
  lui_div = 'last_actions_div';
  if (null == bid_increment || undefined == bid_increment) {
    bid_increment = _default_bid_increment;
  }

  if (lui_data.length == 4) {
    if (lui_data[0] != null && lui_data[0] != undefined
        && lui_data[1] != null && lui_data[1] != undefined) {
      if (lui_data[0] != 0 && lui_data[1] != 0) {
        lui_out += lui_data[1] + ' ';
        lui_out += _wording_single_bid;
        if (lui_data[1] > 1) {
          lui_out += 's';
        }
        lui_out += ' + ' + format_raw_to_price(parseInt(bid_increment)*parseInt(lui_data[1]))
        lui_out += ' + ' + calc_ct_from_time(lui_data[0]);
        lui_out += '<br />';
      }
    }

    if (lui_data[2] != null && lui_data[2] != undefined
        && lui_data[3] != null && lui_data[3] != undefined) {
      if (lui_data[2] != 0 && lui_data[3] != 0) {
        lui_out += lui_data[3] + ' ';
        lui_out += _wording_bid_agent;
        lui_out += ' + ' + format_raw_to_price(parseInt(bid_increment)*parseInt(lui_data[3]))
        lui_out += ' + ' + calc_ct_from_time(lui_data[2]);
      }
    }
  }
  if (lui_data.length == 5) {
  	if (lui_data[4] != null && lui_data[4] != undefined) {
		var tmpbid = parseInt(lui_data[4]);
		if (tmpbid > 0) {
		 	bid_increment = tmpbid;
		}
	}
	
    if (lui_data[0] != null && lui_data[0] != undefined
        && lui_data[1] != null && lui_data[1] != undefined) {
      if (lui_data[0] != 0 && lui_data[1] != 0) {
        lui_out += lui_data[1] + ' ';
        lui_out += _wording_single_bid;
        if (lui_data[1] > 1) {
          lui_out += 's';
        }
        lui_out += ' + ' + format_raw_to_price(parseInt(bid_increment)*parseInt(lui_data[1]))
        lui_out += ' + ' + calc_ct_from_time(lui_data[0]);
        lui_out += '<br />';
      }
    }

    if (lui_data[2] != null && lui_data[2] != undefined
        && lui_data[3] != null && lui_data[3] != undefined) {
      if (lui_data[2] != 0 && lui_data[3] != 0) {
        lui_out += lui_data[3] + ' ';
        lui_out += _wording_bid_agent;
        lui_out += ' + ' + format_raw_to_price(parseInt(bid_increment)*parseInt(lui_data[3]))
        lui_out += ' + ' + calc_ct_from_time(lui_data[2]);
      }
    }
  }

  if (lui_out != "") {
    el = $(lui_div);
    if (el) {
      if (_lui_running) {
        window.clearTimeout(_lui_running);
      }
      el.innerHTML = lui_out;
      _last_action_div_displayed = 1;
      new Effect.BlindDown(el);
      _lui_running = window.setTimeout('new Effect.BlindUp(\'' + lui_div + '\', {duration:1}); _last_action_div_displayed = 0',4500);
    }
  }
}

function parse_bid_history(bh, auction_id) {

  bh_data = bh.split('#');
  history_out = "";
  own_history_out = "";
  tmp_bh = new Array();
  tmp_own_bh = new Array();
  y = 0;
  z = 0;
  tmp_min_bid_key = 9999999;
  div_stats_all = 'stats_test';
  div_stats_own = 'my_placed_bids';
  if (!document.getElementById(div_stats_all)) {
    return;
  }
  var _tmp_array = [];
  for (x = 0; x < bh_data.length; x++) {
    if (null != bh_data[x]) {
      single_entry = bh_data[x].split(':');

      if (null == single_entry || single_entry.length == 0) {
        continue;
      }

      if (single_entry[0] == null || single_entry[0] == "") {
        continue;
      }

      if (parseInt(single_entry[0]) > parseInt(_last_bid_key)) {
        _last_bid_key = single_entry[0];
      }

      var bidder = new Object();
      bidder["bidder_name"] = single_entry[1];
      bidder["bid_time"] = (new Date()).getTime() + _ms_diff;
      bidder["is_bidder"] = 0;

      tmp_bh[y] = new Object();
      tmp_bh[y]["bid_key"] = parseInt(single_entry[0]);
      tmp_bh[y]["user"] = single_entry[1];
      tmp_bh[y]["type"] = single_entry[2];
      tmp_bh[y]["price"] = format_raw_to_price(single_entry[3]);
      tmp_bh[y]["your_bid"] = 0;
      if (undefined != single_entry[4]) {
        tmp_bh[y]["your_bid"] = single_entry[4];
      }
      if (tmp_bh[y]["your_bid"] == 1) {
        tmp_bh[y]["user"] = "<span class=\"bidhistory\">" + tmp_bh[y]["user"] + "</span>";
        tmp_bh[y]["price"] = "<span class=\"bidhistory\">" + tmp_bh[y]["price"] + "</span>";
        bidder["is_bidder"] = 1;
        tmp_own_bh[z] = tmp_bh[y];
        z++;
      }
      _tmp_array.push(bidder);


      y++;

      if (single_entry[0] != "" && tmp_min_bid_key >= single_entry[0]) {
        tmp_min_bid_key = parseInt(single_entry[0]);
      }
    }

  }

  if (_first_load == 0){
    for(l=_tmp_array.length-1;l>=0;l--){
      addBidder(_tmp_array[l]);
    }
  }
  _first_load = 0;

  if (tmp_bh != null) {
    if (_bid_history != null && _bid_history.length > 0) {
      for (x = 0; x < _bid_history.length; x++) {
        if (y >= 10) continue;

        if (_bid_history[x]["bid_key"] < tmp_min_bid_key) {
          tmp_bh[y] = _bid_history[x];
          y++;
        }
      }
      _bid_history = tmp_bh;
    } else {
      _bid_history = tmp_bh;
    }
  }

  get_my_placed_bids(div_stats_own, auction_id);

/*
 *
  if (tmp_own_bh != null) {
    if (_own_bid_history != null && _own_bid_history.length > 0) {
      for (x = 0; x < _own_bid_history.length; x++) {
        if (z >= 10) continue;

        if (_own_bid_history[x]["bid_key"] < tmp_min_bid_key) {
          tmp_own_bh[z] = _own_bid_history[x];
          z++;
        }
      }
      _own_bid_history = tmp_own_bh;
    } else {
      _own_bid_history = tmp_own_bh;
    }
  }
*/
  if (_bid_history != null) {
    history_out += '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
    history_out += '<tr> ' +
                   '  <td class="bidhistory_1"></td>' +
                   '  <td width="bidhistory_2"></TD>' +
                   '  <td width="bidhistory_3"></TD>' +
                   '</tr>';

    for (x = 0; x < _bid_history.length; x++) {
      if (x >= 9) continue;
      if (_bid_out_types[_bid_history[x]["type"]] != null) {
        if(_bid_history[x]["your_bid"] == 1){
        _type = "<span >" + _bid_out_types[_bid_history[x]["type"]] + "</span>";
        } else {
        _type = _bid_out_types[_bid_history[x]["type"]];
        }
      } else {
        _type = 'n/a';
      }

      if(x==0){
        history_out += "<tr class=\"bidhistoryyou\">";
      }else {
        history_out += "<tr class=\"bidhistory\">";
      }
/*
      history_out += "<tr>";
*/
      history_out += "<td align=\"left\">" + _bid_history[x]["price"] + "</td>";
      history_out += "<td class=\"bidhistory bidhistorynw\">" + _bid_history[x]["user"] + "</td>";
      history_out += "<td nowrap>" + _type + "</td>";
      history_out += "</tr>";
/*
      history_out += "type: " + _bid_history[x]["type"];
      history_out += " <br> ";
*/
    }
    history_out += '</table>';
  }

  if (history_out != "") {
    $(div_stats_all).innerHTML = history_out;
  }

/*
  if (_own_bid_history != null) {
    own_history_out += '<table width="220" border="0" cellspacing="0" cellpadding="0">';
    own_history_out += '<tr> ' +
                   '  <td width="60" height="5"></td>' +
                   '  <td width="100"></TD>' +
                   '  <td width="60"></TD>' +
                   '</tr>';

    for (x = 0; x < _own_bid_history.length; x++) {
      if (_bid_out_types[_own_bid_history[x]["type"]] != null) {
        _type = _bid_out_types[_own_bid_history[x]["type"]];
      } else {
        _type = 'n/a';
      }
      own_history_out += "<tr>";
      own_history_out += "<td align=\"center\">" + _own_bid_history[x]["price"] + "</td>";
      own_history_out += "<td>" + _own_bid_history[x]["user"] + "</td>";
      own_history_out += "<td>" + _type + "</td>";
      own_history_out += "</tr>";
    }
    own_history_out += '</table>';
  }


  if (own_history_out != "") {
    $(div_stats_own).innerHTML = own_history_out;
  }
*/
  return;
}


var _last_savings_update = 0;
function update_savings_details(auction_id, force_update) {
  if (auction_id == undefined || auction_id == null) {
    return;
  }

  if(force_update  == undefined || force_update == 0){
    if (((new Date()).getTime()-_last_savings_update)<10000) {
      return;
    }
  }

  _last_savings_update = (new Date()).getTime();

  url = 'ajax/savings.asp?aid=' + auction_id;
  new Ajax.Request(url, {onSuccess: function(transport) {
                                      parse_savings_detail(transport);
                                    }
                        });
}

function _calc_savings_detail_by_params() {
 return;
  div_name_savings = 'user_savings';

  _savings = parseInt(_savings_ajp_price_sale);

  if (_savings_ajp_is_fixed == 1) {
    __current_price = _savings_ajp_current_price;
  } else {
    __current_price = _savings_ajp_current_price;
    if (_t_ct_price != undefined && _t_ct_price != null && _t_ct_price != '') {
      __current_price = parseInt(_t_ct_price);
    }
  }
  _savings -= __current_price;

  if (_savings_ajp_own_bids_num > 0) {
    _savings -= (_savings_ajp_own_bids_num*60);
  }

  if (_savings < 0) {
    _savings = 0;
  }

  if ($(div_name_savings)) {
    $(div_name_savings).innerHTML = format_raw_to_price(_savings);
  }
}


function parse_savings_detail(transport) {
  result_array = transport.responseText.split("|");
  div_name_own_bids = 'a_bid_amount_placed';
  div_name_savings = 'user_savings';
  div_name_savings_num = 'user_savings_num_bids';
  div_name_discount_sum = 'user_discount_sum';
  div_name_buy_price = 'buy_it_now_price';
  div_name_savings_num_bin = 'user_savings_num_bids_bin';
  div_name_buy_price_sum = 'buy_it_now_price_sum';
  div_name_freebids_num = 'user_freebids_line';
  offer = $('bid_block_offer');
  info = $('bid_block_info');
  if (result_array.length == 9) {
    el = $(div_name_own_bids);
    el2 = $(div_name_savings);
    el3 = $(div_name_savings_num);
    el4 = $(div_name_discount_sum);
    el5 = $(div_name_buy_price);
    el6 = $(div_name_savings_num_bin);
    el7 = $(div_name_buy_price_sum);
    el8 = $(div_name_freebids_num);
    num_bids = result_array[1];
    pbids = result_array[8];

    if (el) {
      el.innerHTML = result_array[2]; // own bids
    }
    if (el2) {
      el2.innerHTML = result_array[0]; // savings
    }
    if (el3) {
      _savings_ajp_own_bids_num = pbids;
      el3.innerHTML = result_array[1]; // savings number bids
    }
    if (el4){
      el4.innerHTML = result_array[3]; // discount sum
    }
    if (el5){
      el5.innerHTML = result_array[4]; // retail price
    }
    if (el6){
      el6.innerHTML = result_array[1];
      if(num_bids == "1" && (4==4 || 4==5)){
         window.location.reload();
      }
    }
    if (el7){
      el7.innerHTML = result_array[5];
    }
    if (el8){
      if(result_array[7] > 0) {
        el8.style.display = "inline";
        if($('tip_bin_freebids')){
          $('tip_bin_freebids').style.display = "inline";
        }
        if($('user_num_freebids')){
          $('user_num_freebids').innerHTML = result_array[7];
        }
      }
    }


  } else if (result_array.length == 1) {
    el2 = $(div_name_savings);
    if (el2) {
      el2.innerHTML = result_array[0];
    }
  }
}


var updated_to_cds = 0;
function _update_ct_speed_image(_sec, _num_bids, _current_sec) {
  if (undefined == bid_increment || null == bid_increment) {
    bid_increment = _default_bid_increment;
  }

  if (_last_update_t_time == _current_sec) {
//    return;
  }
  updated_to_cds = _current_sec;

  _last_update_t_time = bid_increment;

  _price = format_raw_to_price(parseInt(_num_bids)*parseInt(bid_increment));
  _text = '' + _sec + ' second countdown<br/>starts at ' + _price;
  _img = 'images/uhr' + _current_sec + '.jpg';
  el = $('CDUMST');
  if (el) {
    el.innerHTML = _text;
  }
  el = $('CDUMST_IMG');
  if (el) {
    el.src = _img;
  }
}
function _srv_index(transport, auction_id, reset_ct_time) {
    if (reset_ct_time != null && reset_ct_time != undefined
      && reset_ct_time != '' && reset_ct_time != 0) {
        _overwrite_timeout_index = (1000 - reset_ct_time);
        _overwrite_timeout_special = (1000 - reset_ct_time);
    }
    parse_ct_response_index(transport, 1);
    _l_t_keys['a_ind'] = 0;
    if (_l_t_keys['a_spec'] != null) {
        _l_t_keys['a_spec'] = 0;
    }
}

function _srv_index_rev(transport, auction_id, reset_ct_time) {
	if (reset_ct_time != null && reset_ct_time != undefined
      && reset_ct_time != '' && reset_ct_time != 0) {
        _overwrite_timeout_index_rev = (9000 - reset_ct_time);
    }
    parse_ct_response_index(transport, 1);
    _l_t_keys['a_ind_rev'] = 0;
    
}

function _srv_det_rev(transport, auction_id, reset_ct_time) {
	if (reset_ct_time != null && reset_ct_time != undefined
      && reset_ct_time != '' && reset_ct_time != 0) {
        _overwrite_timeout_det_rev = (9000 - reset_ct_time);
    }
    parse_ct_response_det(transport, 1);
    _l_t_keys['a_det_rev'] = 0;
    
}

function _delete_ct_speed_image(_current_sec) {
  el = $('CDUMST');
  if (el) {
    el.parentNode.removeChild(el);
  }

  if (_cds_image_deleted == 1) {
    return;
  }
  _cds_image_deleted = 1;
  _img = 'images/uhr' + _current_sec + '.png';
  el = $('CDUMST_IMG');
  if (el) {
    el.src = _img;
  }
}
//]]>
