function viewGLPhoto(theurl) {
	var NewWinHeight = 480;
	var NewWinWidth  = 600;
	glPhotoWindow = window.open(theurl,'glPhoto','toolbar=no,location=no,directories=no,'+'status=no,menubar=no,scrollbars=yes,'+'resizable=no,width=' + NewWinWidth+',height='+NewWinHeight+'');
	if (! document.all) {
		glPhotoWindow.moveTo(screen.width/2 - NewWinWidth/2, screen.height/2 - NewWinHeight/2)
	}
	glPhotoWindow.focus();
}

function checkall() {
	if (document.results.check_all_auctions.checked) {
		for(i=0;i<document.results.auctionId.length;i++) {
			document.results.auctionId[i].checked = true;
		}
	} else {
		for(i=0;i<document.results.auctionId.length;i++) {
			document.results.auctionId[i].checked = false;
		}
	}
}

function handleWatchList(secure_dyn_srvr,categoryId) {

	var watch_url = '';

	if (document.results.auctionId.length > 1) {

		for(i=0; i < document.results.auctionId.length; i++) {

			if (document.results.auctionId[i].checked == true) {

				if (watch_url == '') {

					watch_url = document.results.auctionId[i].value;

				} else {

					watch_url = watch_url + ',' + document.results.auctionId[i].value;

				}

			}

		}

		window.open(secure_dyn_srvr + '/login?watchList=add&auctions=' + watch_url + '&categoryId=' + categoryId,'WatchList','width=300,height=200,scrollbars=no,location=no');

	}	else {

		window.open(secure_dyn_srvr + '/login?watchList=add&auctions=' + document.results.auctionId.value + '&categoryId=' + categoryId,'WatchList','width=300,height=200,scrollbars=no,location=no');

	}

}

function write_current_bid(id,current_bid)
{
	current_bid = current_bid_hash[id] || current_bid
	current_bid = formatNumber(current_bid, 2);
	document.write(current_bid)
}

function write_close_time(id,close_date,close_minutes)
{
	close_minutes = close_minutes_hash[id] || close_minutes
	var close_time = formatDateTime(close_date,close_minutes);
	document.write(close_time)
}

function write_number_of_bids(id,number_of_bids)
{
	number_of_bids = number_of_bids_hash[id] || number_of_bids
	document.write(number_of_bids)
}

function ImgError(source){
	source.src = "/images/spacer.gif";
	source.border = 0;
	source.onerror = "";
	return true;
}

function write_thumbnail_image(id,lsi_image_id,event_id,lot_number,auction_title)
{
	lsi_image_id = lsi_image_id_hash[id] || lsi_image_id;
	auction_title = (auction_title)?auction_title+"":"Lot Photo";
	if (lsi_image_id == 0) return '&nbsp;';
	//var subdir = Math.ceil(lsi_image_id/1000);
	var subdir = (Math.floor(lsi_image_id/1000) + 1);
	document.write("<BR><BR><A HREF=\"javascript:viewGLPhoto('/auction/view_photo?eventId=" + event_id + "&lotNumber=" + lot_number + "&picNumber=1');\"><IMG SRC='/aucimg/photos/" + subdir + "/small_thumb/" + lsi_image_id + "_sm_thumb.jpg' BORDER=1 ALT='" + auction_title + "' title='" + auction_title + "' onerror='ImgError(this)'></A>");
}

//RC - Same as previous but less space between link and image
//RC - 09/16/2004 - Passing auction_id for link to Page Details view.
function write_thumbnail_image_for_hotlot(id,lsi_image_id,event_id,lot_number,auction_id,auction_title)
{
	lsi_image_id = lsi_image_id_hash[id] || lsi_image_id
	if (lsi_image_id == 0) return '&nbsp;';
	var subdir = (Math.floor(lsi_image_id/1000) + 1);
	//RC - 09/16/2004 - Clicking on the image shall link to the "Details Page" instead of the slide show.
	//document.write("<A HREF=\"javascript:viewGLPhoto('/auction/view_photo?eventId=" + event_id + "&lotNumber=" + lot_number + "&picNumber=1');\"><IMG SRC='/aucimg/photos/" + subdir + "/small_thumb/" + lsi_image_id + "_sm_thumb.jpg' BORDER=1 ALT='Lot Photo'></A>");
	document.write("<A HREF=\"/auction/view?id=" + auction_id + "\"><IMG SRC='/aucimg/photos/" + subdir + "/small_thumb/" + lsi_image_id + "_sm_thumb.jpg' BORDER=1 ALT='" + auction_title + "' title='" + auction_title + "'></A>");
}

function formatDateTime(date,time) {

	var ampm = "PM";
	var hours = Math.floor(time/60);
	var minutes = "" + (time - (hours * 60));
	if (hours < 12) ampm = "AM";
	if (hours > 12) hours -= 12;
	hours = "" + hours;
	if (hours.length == 1) hours = "0" + hours;
	if (minutes.length == 1) minutes = "0" + minutes;

	date = "" + date;
	var year = date.substr(0,4);
	var month = date.substr(4,2);
	var day = date.substr(6,2);

	var formatted = month + '/' + day + '/' + year + '<BR>' + hours + ":" + minutes + " " + ampm + " ET";

	if (date == current_date || date == tomorrow_date && time < current_time) {
		return ("<font color='red'>" + formatted + "</font>");
	} else {
		return (formatted);
	}
}

function formatNumber(num, decplaces) {
	num = parseFloat(num);
	if (!isNaN(num)) {
		var str = "" + Math.round (eval(num) * Math.pow(10,decplaces));
		while (str.length <= decplaces) {
			str = "0" + str;
		}
		var decpoint = str.length - decplaces;
		return formatCommas(str.substring(0,decpoint)) + "." +
			str.substring(decpoint,str.length);
	} else {
		return "NaN";
	}
}

function formatCommas(numString) {
	var re = /(\d+)(\d{3})/;
	while (re.test(numString)) {
		numString = numString.replace(re, "$1,$2");
	}
	return numString;
}

// COMMON FUNCTIONS AMONG RESULTS AND HOTLOTS PAGES

// Open NSN info window
function handle_nsn_info(nsn) {
  window.open('[NORMAL_DYNAMIC_SERVER]/auction/view_nsn?nsn=' + nsn, 'NSN_INFO', 'width=600,height=400,scrollbars=yes,location=no');
}

function gotosite(site) {
  if (site != "") {
    self.location=site;
  }
}


/*****************************************************
* JavaScript used to show/hide tooltips              *
* in the search/result pages and the list/... pages. *
*****************************************************/
// Example:
// onMouseOver="toolTip('tool tip text here')";
// onMouseOut="toolTip()";
// -or-
// onMouseOver="toolTip('tooltip text to display', '#FFFF00', 'orange')";
// onMouseOut="toolTip()";
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 5;
offsetY = 5;
var toolTipSTYLE="";
function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) toolTipSTYLE = document.toolTipLayer;
    else if(ns6) toolTipSTYLE = document.getElementById("toolTipLayer").style;
    else if(ie4) toolTipSTYLE = document.all.toolTipLayer.style;
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      toolTipSTYLE.visibility = "visible";
      toolTipSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}
function toolTip(msg, fg, bg)
{
	initToolTips();
  if(toolTip.arguments.length < 1) // hide
  {
    if(ns4) toolTipSTYLE.visibility = "hidden";
    else toolTipSTYLE.display = "none";
  }
  else // show
  {
    if(!fg) fg = "#000000";
    if(!bg) bg = "#FFFFCC";
    var content =
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '">' +
		  '<tr>' +
		    '<td>' +
          '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + bg + '">' +
		        '<tr>' +
		          '<td align="center" style="font-family:Arial, Helvetica, sans-serif; font-size:11px; font-weight:bold; color:' + fg + ';">' +
		            '&nbsp\;' + msg + '&nbsp\;' +
		          '</td>' +
		        '</tr>' +
		      '</table>' +
		    '</td>' +
		  '</tr>' +
		'</table>';
    if(ns4)
    {
      toolTipSTYLE.document.write(content);
      toolTipSTYLE.document.close();
      toolTipSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("toolTipLayer").innerHTML = content;
      toolTipSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("toolTipLayer").innerHTML=content;
      toolTipSTYLE.display='block'
    }
  }
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }
  toolTipSTYLE.left = x + offsetX;
  toolTipSTYLE.top = y + offsetY;
  return true;
}

//End of tooltip code -->


/****************************************************/
/* Allow users to expand or shrink lot descriptions */
/* in the current lots and search results pages     */
/****************************************************/
function doDescriptions ( action ) {

  var lotsTableObj = document.getElementById('lots_table');
  var divs = lotsTableObj.getElementsByTagName("div");

  for (var i = 0; i < divs.length; i++) {
    if ( divs[i].getAttribute("title") == "description" ) {
      divs[i].style.height = ( action == "expand") ? "auto" : "40px";
    }
    if ( divs[i].getAttribute("title") == "read_more" ) {
      divs[i].style.display = ( action == "expand") ? "none" : "block";
    }
    if ( divs[i].getAttribute("title") == "brake" ) {
      divs[i].style.display = ( action == "expand") ? "block" : "none";
    }
  }

  if ( action == "expand" ) {
    document.getElementById('lnkShrinkDescriptions').style.display = 'block';
    document.getElementById('lnkExpandDescriptions').style.display = 'none';
  } else {
    document.getElementById('lnkShrinkDescriptions').style.display = 'none';
    document.getElementById('lnkExpandDescriptions').style.display = 'block';
  }
}
/****************************************************/
