var dot=0;
var elapsedtime=0;

// start loading the image right away so there is no lag when the form is submitted
//var spinImage = document.createElement('img');
//spinImage.src = "/images/shared/spinner_16px_bluebg.gif";

function shield(button_id, cancel_id, poll_btn_text, poll_btn_text_2) {
  $('#'+button_id).attr('disabled', 'true');
  $('#'+button_id).attr('value', poll_btn_text);
  $('#'+button_id).removeClass('enabled');
  
  if( $('#searchspinner').length ) $('#spearchspinner').remove(); // delete any previous ones just in case
  
  var position = $('#'+button_id).offset();
  var bh = $('#'+button_id).height();
  var working = $('<div id="searchspinner" style="display:none;"><img src="/images/shared/spinner_24px_whitebg_trans.gif"></div>');
  working.insertAfter('#'+button_id);  
  // set the top as the top of the button plus half the button height minus half the spinner height = middle of button
  working.css({position:'fixed',top:position.top+(bh/2)-10,left:position.left-28});
  working.fadeIn('fast', function(){
    $('#searchspinner img').attr('src', '/images/shared/spinner_24px_whitebg_trans.gif' ); // reset the src attribute fixes some FF issues on secondary loads
  });
  	
	return setInterval("polling('"+button_id+"', '"+cancel_id+"', '"+poll_btn_text_2+"')",850);
}

function polling(button_id, cancel_id, poll_btn_text) {
  /*
	if (dot>3) dot=0;
	dots='';
	for (i=0; i<dot; i++) dots += '.';
	for (i=0; i<(3-dot); i++) dots += ' ';
	$('#'+button_id).attr('value', poll_btn_text+dots);
	dot++;
	*/
	elapsedtime += 850;
	if (elapsedtime > 30000 && cancel_id) $('#'+cancel_id).show();
}

