﻿// START - DOCUMENT READY CODE *********************************************************
$j = (jQuery);
(function($){
	$(document).ready(function() {
		var incTableHTML = '<div class="incTable"><div>' + $('#incTable').html() + '</div></div>';
		var incTableTimeout;
		var incTableID = 0;
		
		var $maxBidMessageDialog = $('<div></div>')
				.html('Due to the nature of a live auction webcast your maximum bid will be exposed to the auctioneer once the lot enters the ring. We monitor auction company activity to ensure bids are fairly represented.')
				.dialog({
					autoOpen: false,
					title: "Important Message",
					resizable: false,
					draggable: false
					});
					
		$("#MaxBidMessage").click(function() {
				this.blur();
				$maxBidMessageDialog.dialog('open');
				return false;
			});
		
		$('.incrementIcon').parent().click(function() {
			incTable(this);
		}).click(function() {
			return false;
		});

		var incTable = function(el)
		{
			if($('#incTable').length == 0)
			{
				return;
			}
		
			var incTable = $(el).siblings('.incTable:first');
			
			var tableWidth;
			var tableHeight;
			
			if(incTable.length == 0)
			{
				var position = $(el).position();
				
				incTable = $(el).after(incTableHTML).next();
				
				tableWidth = $(incTable).outerWidth();
				tableHeight = $(incTable).outerHeight();
				
				var isLotDetail = getIsLotDetail();
				if (isLotDetail){
					$(incTable).css({
						top: position.bottom + 'px',
						left: position.left - $(incTable).outerWidth() + 'px',
						width: tableWidth + 'px',
						height: tableHeight + 'px',
						overflow: 'hidden'
					}).children('div').css({
						width: '0px',
						height: '0px',
						left: tableWidth + 'px',
						bottom: tableWidth + 'px'
					});
				} else {
					$(incTable).css({
						top: '35px',
						left: position.left + 5 + 'px',
						width: tableWidth + 'px',
						height: tableHeight + 'px',
						overflow: 'hidden'
					}).children('div').css({
						width: '0px',
						height: '0px',
						right: tableWidth + 'px',
						bottom: tableWidth + 'px'
					});
				};
			}
			
			//Keep table visible if already displayed
			if(incTableID == incTable[0])
			{
				clearTimeout(incTableTimeout);
			}
			
			incTableID = incTable[0];
			
			//Wait after mouse off the icon before hiding the table
			$(el).mouseleave(function() {
				incTableTimeout = setTimeout(function() {
					//hideTable();
					//this.hide();
					$(incTable[0]).hide();
				}, 500);
				$(el).unbind('mouseleave');
			});
			
			$(incTable).show()
			//If mouse over the increment table, display until mouse out
			.mouseenter(function() {
				clearTimeout(incTableTimeout);
			})
			.mouseleave(function() {
				//hideTable();
				//this.hide();
				$(incTable[0]).hide();
			})
			.children('div')
			.animate({
				width: tableWidth - 22 + 'px',
				height: tableHeight - 22 + 'px',
				left: '0px',
				bottom: '0px'
			}, 175);
			
			this.hide = function() {
				$(incTable).hide().children('div').css({
					width: '0px',
					height: '0px',
					left: tableWidth + 'px',
					bottom: tableHeight + 'px'
				});
			};		

		}

		$('.BidWidget .incrementChoice .button').click(function() {
			var lotID = getLotID(this);
			var currencySymbol = document.getElementById('Symbol:' + lotID).innerHTML;
			
			var bidAmount = $(this).html().split(currencySymbol,2);
			if(bidAmount.length == 2)
			{
				document.getElementById('BidAmount:' + lotID).value = bidAmount[1].substr(0, bidAmount[1].length);
				if(mIsLotDetail){
					checkIncrement2(auctionGuardAuction,lotID,true);
				}else{
					checkIncrement(auctionGuardAuction,lotID);
				}
			}
			return false;
		});
		$('.BidWidget .minBid').click(function(){
			if ($('.BidWidget .minBid').hasClass('disabled') == false){
				var lotID = getLotID(this);
				var textBox = $j('#BidWidget'+lotID).find('input.bidWidgetTextbox');
				var elMinBid = $j('#BidWidget'+lotID).find('a.minBid');
				elMinBid = elMinBid[0];
				var currentHTML = $j(elMinBid).html();
				
				var re = new RegExp( /\D+([\d.,]+)/ );
				var match = re.exec(currentHTML);
				
				if(textBox.length > 0){
					textBox[0].value = match[1];
				}
			}
			return false;
		});

		$('.BidWidget .switchBid').click(function(){
			if ($('.BidWidget .switchBid').hasClass('disabled') == false){
				var lotID = getLotID(this);
				
				if ($("#placeInstaBid" + lotID).css("display") == "none"){
					$("#placeBid" + lotID).hide();
					//$("#minimumBid" + lotID).hide();
					$("#placeInstaBid" + lotID).show();
					
					$("#switchBidText" + lotID).text(MAXBID_TEXT);
					$("#switchBidIcon" + lotID).removeClass(INSTABID_ICON);
					$("#switchBidIcon" + lotID).addClass(MAXBID_ICON);
				}else{
					$("#placeInstaBid" + lotID).hide();
					//document.getElementById('BidAmount:' + lotID).value  = "Raise your bid...";
					
					$("#placeBid" + lotID).show();
					//$("#minimumBid" + lotID).show();
					$("#switchBidText" + lotID).text(INSTABID_TEXT);
					$("#switchBidIcon" + lotID).removeClass(MAXBID_ICON);
					$("#switchBidIcon" + lotID).addClass(INSTABID_ICON);
				}
			}
			return false;
		});
		
		
		var elBidderLoggedIn = $('#bidderLoggedIn')[0];
		$('.BidWidget form').submit(function() {
			var lotID = getLotID(this);
			var auctionID = getAuctionID(this);
			
			var isLotDetail = getIsLotDetail();
			
			if(isLotDetail && elBidderLoggedIn.value == "1")
			{
				checkIncrement2(auctionID, lotID, true);
			}
			else if(elBidderLoggedIn.value == "1")
			{
				//Check bid if logged in
				checkIncrement(auctionID, lotID);
			}
			else
			{
				//redirect to login if not logged in
				redirectToLogin(lotID);
			}
				return false;
		});
		
		$('.BidWidget .cancelBid').click(function() {
			cancelBid(getLotID(this));
			return false;
		});

		$('a#lnkConfirmBid.button').click(function() {
			if (!($("a#lnkConfirmBid.button").hasClass("disabled"))) {
//				var ccID = "" + $j("#ConfirmCCID").val();
//				var ccLastFour = "" + $j("#ConfirmCCLastFour").val();
//				var ccTypeName = "" + $j("#ConfirmCCTypeName").val();
//				var ccToken = "" + $j("#ConfirmCCToken").val();
				slideUp();
				$('.termsMessage').hide();
				
				if ($j("#AllowInstaBid" + getLotID(this)).val() == "1"){
					$j("#placeInstaBid" + getLotID(this)).show();
					$j("#switchBidType" + getLotID(this)).show();
				}else{
					$j('.placeBid').hide();
					$('.minimumBid').show();
					showButtons(getLotID(this), "placeBid");
				}
				
				//document.getElementById("BidAmount:" + getLotID(this)).value = "";
				placeBid(auctionGuardAuction, getLotID(this));
				//continueCheckIncrement(getLotID(this));
//				cc.addCardToReg(ccID, ccToken, addDefaultCCCallBack);
			}
			return false;
		});
		
		$('p.lotDesc > a').click(function() {
			if ($(this).text() == '...more' || $(this).text() == 'View description...'){
				$(this).hide().next().css('display', 'inline');
				$(this).parent().next().show()
				return false;
			};
		});
		
		$('p.lotDescLess > a').click(function() {
			if ($(this).text() == 'less...' || $(this).text() == 'Hide description'){
				$(this).parent().hide().prev().children('span').css('display', 'none');
				$(this).parent().prev().children('a').show()
				return false;
			};
		});
		
		$('#SpecialTermsSizer').click(function() {
			if ($(this).text() == 'more'){
				$('#SpecialTermsContent').height(250);
				$(this).text('less');
				
				return false;
			}else{
				$('#SpecialTermsContent').height(100);
				$(this).text('more');
				
				return false;
			};
		});
		
		//Catalog Toolbar
		var elFrmGoToLot = $('.navGoToLot');
		var elFrmGoToLot2;
		if(elFrmGoToLot.length > 0)
		{
			elFrmGoToLot2 = elFrmGoToLot[1];
			elFrmGoToLot = elFrmGoToLot[0];
			$(elFrmGoToLot).submit(function() {
				this.action = this.action + document.getElementById('txtGoToLot').value;
				//return false;
			}).find('.catNav.cnGo').click(function() {
				$(elFrmGoToLot).submit();
				return false;
			});
			$(elFrmGoToLot2).submit(function() {
				this.action = this.action + document.getElementById('txtGoToLot').value;
				//return false;
			}).find('.catNav.cnGo').click(function() {
				$(elFrmGoToLot2).submit();
				return false;
			});
		}
		
		var elFrmGoToPage = $('.navGoToPage');
		var elFrmGoToPage2;
		if(elFrmGoToPage.length > 0)
		{
			elFrmGoToPage2 = elFrmGoToPage[1];
			elFrmGoToPage = elFrmGoToPage[0];
			$(elFrmGoToPage).submit(function() {
				//this.action = this.action + document.getElementById('txtGoToLot').value;
				//return false;
			}).find('.catNav.cnGo').click(function() {
				$(elFrmGoToPage).submit();
				return false;
			});
			$(elFrmGoToPage2).submit(function() {
				//this.action = this.action + document.getElementById('txtGoToLot').value;
				//return false;
			}).find('.catNav.cnGo').click(function() {
				$(elFrmGoToPage2).submit();
				return false;
			});
		}
		
		bindStatusMsgHandlers();
		
		//Wait until page is visible then run AG
		$(window).load(function() {
			var elRunAG = $('#runAGCheck');
			if(elRunAG.length > 0) {
				elRunAG = elRunAG[0].value;
				if(elRunAG == 1) {
					var auctionID = $j('#statusAuctionID').val();
					submitApplication(auctionID);
				}
			}
		});
	});
})(jQuery);
// END - DOCUMENT READY CODE ***********************************************************

function bindStatusMsgHandlers() {
	//Bidder Approval Status Header Messages
	var elBidderLoggedIn = $j('#bidderLoggedIn')[0];
	$j('#submitApplication').click(function() {
		var retVal = false;
		
		if(elBidderLoggedIn.value == "1") {
			//If logged in, call AuctionGuard
			var auctionID = $j('#statusAuctionID').val();
			submitApplication(auctionID);
		}
		else {
			//Allow link to follow to login page if not logged in
			retVal = (confirm('You must login to apply to bid.'));
		}
		
		return retVal;
	});
}

function goToByScroll(id){
	  $('html,body').animate({scrollTop: $("#"+id).offset().top},'slow');
}

function addDefaultCCCallBack( error ) {
//TO DO: should probably add checks here in case cc was not added to registration row.
/*
	if (error != true){
		slideUp();
		$('.BigBidWidget .termsMessage').hide();
		$('.BigBidWidget .minimumBid').show();
		showButtons(getLotID(this), "placeBid");
		//document.getElementById("BidAmount:" + getLotID(this)).value = "";
		continueCheckIncrement(getLotID(this));
	}else{
		alert("something went wrong adding default cc to bidder registration");
	}
*/
}

// START - GLOBAL VARIABLES ************************************************************
var BID_AMOUNT_DEFAULT = [
	"",
	"Enter max bid...",
	"Raise your bid..."
];
var BidWidgetMessageMap = {};
var DELIMITER = "~";
var currentBids = [];
var BIDWIDGET_LEADING = 0;
var BIDWIDGET_OUTBID = 1;
var BIDWIDGET_NOTACCEPTED = 2;
var BIDWIDGET_CLOSED = 3;
var BIDWIDGET_SELECTINCREMENT = 4;
var BIDWIDGET_NORMAL = 100;

var INSTABID_TEXT = "Switch to InstaBid mode";
var INSTABID_ICON = "instaBidIcon";
var MAXBID_TEXT = "Enter a maximum bid";
var MAXBID_ICON = "maxBidIcon";


var auctionGuardAuction;
var auctionGuardLot;
var profileCompleteCallBack;
var mIsLotDetail = false;
var mbInstaBid = false;

// END - GLOBAL VARIABLES **************************************************************

// START - UI CODE *********************************************************************
function redirectToLogin(lotID) {
	if(lotID) {
		window.location = $j(document.getElementById('linkBidAmount:' + lotID)).attr('href') + encodeURI(document.getElementById('BidAmount:' + lotID).value);
	}
	else {
		//window.location = $j(document.getElementById('linkBidAmount:' + lotID)).attr('href') + encodeURI(document.getElementById('BidAmount:' + lotID).value);
	}
	return false;
}

function getLotID(element)
{
	return $j(element).parents('.BidWidget:first')[0].id.split('BidWidget')[1];
}

function getAuctionID(element)
{
	return $j(element).parents('.BidWidget:first').find('.auctionID:first')[0].value;
}

function getIsLotDetail()
{
	var retVal;
	if($j('#isLotDetail').length != 0)
	{
		retVal = true;
	}
	else
	{
		retVal = false;
	}
	return retVal;
}

function switchBidWidgetClass(classID, lotID, lotStatus) {
	var classList = switchBidWidgetClass.classList

	var elWidget = $j('#BidWidget' + lotID);

	if (elWidget.length != 0) {
		//Remove other classes
		for (i = 0; i < classList.length; i++) {
			var className = classList[i];
			if (classID == 100 || className != classList[classID]) {
				$j(elWidget).removeClass(className);
			}
		}
		if (classID != 100) {
			$j(elWidget).addClass(classList[classID]);
		}

		if (classID == 4 || lotStatus == 3 || lotStatus == 4){
			$j("#placeBid" + lotID).hide();
			$j("#minimumBid" + lotID).hide();
			$j("#placeInstaBid" + lotID).hide();
			$j("#switchBidType" + lotID).hide();
			
			if (document.getElementById("lotWatchContainer:" + lotID)){
				document.getElementById("lotWatchContainer:" + lotID).style.display = "none";
			}
		}else{
			//if (mIsLotDetail){
				//if ($j("#IsTimedOnly").val() == "1" && $j("#UseInstaBid").val() == "True" && $j("#AllowInstaBid" + lotID).val() == "1"){   //REMOVED TO TURN ON INSTABID FOR LIVE & TIMED
				if ($j("#UseInstaBid").val() == "True" && $j("#AllowInstaBid" + lotID).val() == "1"){
					$j("#placeBid" + lotID).hide();
					$j("#minimumBid" + lotID).hide();
					$j("#placeInstaBid" + lotID).show();
					$j("#switchBidType" + lotID).show();
				}else{
					$j("#placeInstaBid" + lotID).hide();
					$j("#switchBidType" + lotID).hide();
					$j("#placeBid" + lotID).show();
					if ($j("#highBidOpenBid" + lotID).val() > 0){ 
						$j("#minimumBid" + lotID).show();
					}
					//$j(".placeBid").show();
				}
			//}else{
			//	document.getElementById("placeBid" + lotID).style.Display = "block";
			//}
		}
	}
}
switchBidWidgetClass.classList = [
		'leading',
		'outbid',
		'bidNotAccepted',
		'lotClosed',
		'selectIncrement'
	];

function getBidWidgetClass(lotID) {
	var classList = switchBidWidgetClass.classList
	var retVal = -1;
	
	var elWidget = $j('#BidWidget' + lotID);
	if (elWidget.length != 0) {
		var cssClass = $j(elWidget).attr('class');
		for (i = 0; i < classList.length; i++) {
			var className = classList[i];
			if (cssClass.search(className) != -1) {
				retVal = i;
				i = classList.length + 1;
			}
		}
	}
	
	return retVal;
}

var bidNotAcceptedMsg = {
	show: function (lotId) {
		switchBidWidgetClass(BIDWIDGET_NOTACCEPTED, lotId);
		//$("bidNotAccepted:" + lotId).style.display = "block";
		//$("additionalMessage:" + lotId).style.color = "#EE0000"
	},
	hide: function (lotId) {
		switchBidWidgetClass(BIDWIDGET_NORMAL, lotId);
		//$("bidNotAccepted:" + lotId).style.display = "none";
		//$("additionalMessage:" + lotId).style.color = "";
	}
};

var bidAcceptedMsg = {
	show: function (lotId) {
		switchBidWidgetClass(BIDWIDGET_LEADING, lotId);
		//$("bidAccepted:" + lotId).style.display = "block";
	},
	hide: function (lotId) {
		switchBidWidgetClass(BIDWIDGET_NORMAL, lotId);
		//$("bidAccepted:" + lotId).style.display = "none";
	}
};

var bidOutbidMsg = {
	show: function (lotId) {
		switchBidWidgetClass(BIDWIDGET_OUTBID, lotId);
		//$("bidOutbid:" + lotId).style.display = "block";
	},
	hide: function (lotId) {
		switchBidWidgetClass(BIDWIDGET_NORMAL, lotId);
		//$("bidOutbid:" + lotId).style.display = "none";
	}
};


function ShowHotLotDialog() {
	switch (sMDResponse) {
		case "na":
			var sTitle = "Hot Lot";
			var sDescription = 'Hot Lot: A Hot Lot is an item that has received bidding from 5 or more unique bidders since the auction was created.  You may hover your mouse over the "Hot Lot" icon to see the total number of pre-bids.  Use the sort function located at the top of the catalog to view all of the hot lots for a particular auction catalog.';
			var sButtons = "ok";
			ShowDialog(sTitle, sDescription, sButtons, "info");
			setTimeout("ConfirmAuctioneer()", 500);
			break;
		case "waiting":
			setTimeout("ConfirmAuctioneer()", 500);
			break;
		case "ok":
			sMDResponse = 'na';
			break;
	}
}

function bidAmountFocus(lotID, messageID) {
	if (BidWidgetMessageMap[lotID] != messageID) {
		BidWidgetMessageMap[lotID] = messageID;
	}
	var i;
	for (i = 0; i < BID_AMOUNT_DEFAULT.length; i++) {
		if (document.getElementById("BidAmount:" + lotID).value == BID_AMOUNT_DEFAULT[i]) {
			document.getElementById("BidAmount:" + lotID).value = ""
		}
	}
}
function bidAmountBlur(lotID) {
	if (document.getElementById("BidAmount:" + lotID).value == "") {
		if (BID_AMOUNT_DEFAULT[BidWidgetMessageMap[lotID]] != undefined) {
			document.getElementById("BidAmount:" + lotID).value = BID_AMOUNT_DEFAULT[BidWidgetMessageMap[lotID]];
		} else {
			document.getElementById("BidAmount:" + lotID).value = "";
		}
	}
}


function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g, '');
	if (isNaN(num)) {
		num = "0";
	}
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num * 100 + 0.50000000001);
	cents = num % 100;
	num = Math.floor(num / 100).toString();

	if (cents < 10) {
		cents = "0" + cents;
	}

	for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++) {
		num = num.substring(0, num.length - (4 * i + 3)) + ',' + num.substring(num.length - (4 * i + 3));
	}
	return (((sign) ? '' : '-') + num + '.' + cents);
}

function updateApprovalStatusMsg(scrollToMsg, callBack) {

	var auctionID = $j('#statusAuctionID').val();
	var loginLink = encodeURIComponent($j('#regNoticeLink').val());
	
	var statusCode = -1;
	var el = $j('#bidderStatusCode');
	if(el.length > 0){
		statusCode = el[0].value - 0;
	}

	if(statusCode != 1) {
		var prevMsgID = document.getElementById('bidderStatusMsgID').value;
		$j.ajax({
			url: "/asp/ajax/ApprovalStatusMsgAJAX.asp?aid=" + auctionID + "&loginLink=" + loginLink,
			success: function (data) {
				$j('#registrationNotice').replaceWith(data);
				var msgChanged;
				
				msgChanged = true;
				
				//Rebind event handlers
				bindStatusMsgHandlers();
				
				if (scrollToMsg) {
					scrollToStatusMsg(msgChanged);
				}
				
				if(callBack) {
					callBack();
				}
			}
		});
	}
}

function scrollToStatusMsg(msgChanged) {
	if(msgChanged) {
		$j('html,body').animate({ scrollTop: $j('#registrationNotice').offset().top }, 'slow');
	}
}

function showButtons(lotID, buttonToShow) {
	//var button = "placeBid,confirmBid,placingBid".split(",");
	var button = "confirmBid,placingBid".split(",");
	for (var i = 0; i < button.length-1; i++) {
		document.getElementById(button[i] + lotID).style.display = "none";
	}
	if (buttonToShow != "") {
		document.getElementById(buttonToShow + lotID).style.display = "block";
	}
}

function incrementLink(lotID, bidAmount) {
	return "<span style='cursor:pointer;border-bottom:1px dotted #2f99ce;color:#2f99ce;' onclick='document.getElementById(\"BidAmount:" + lotID + "\").value=\"" + bidAmount + "\"'>" + bidAmount + "</span>"
}

function setLotStatus(lotID, bid, bidder, reserveMet, msg, lotStatus, timeRemaining, minBidAmt) {

	//console.log(lotID + " : " + bid + " : " + bidder + " : " + reserveMet + " : " + msg + " : " + lotStatus + " : " + timeRemaining)
	//NOTE lotStatus and timeRemaining only come through in timed auctions when remaining time is updated... 
	var bidLabel = "High Bid:";
	var currentUser = document.getElementById("BidderUserName").value;

	
	//if ($j("#IsTimedOnly").val() == "1" && $j("#UseInstaBid").val() == "True" && $j("#AllowInstaBid" + lotID).val() == "0" && bid > 0 ){   //REMOVED TO TURN ON INSTABID FOR LIVE & TIMED
	if ($j("#UseInstaBid").val() == "True" && $j("#AllowInstaBid" + lotID).val() == "0" && bid > 0 ){
		$j("#AllowInstaBid" + lotID).val("1") ;
		$j("#placeBid" + lotID).hide();
		$j("#placeInstaBid" + lotID).show();
		$j("#minimumBid" + lotID).hide();
		$j("#switchBidType" + lotID).show();		
		document.getElementById("additionalMessage:" + lotID).style.display = "none";
	}
	
	if (document.getElementById("placeInstaBid" + lotID).style.display != "none"){
		$j("#switchBidText" + lotID).text(MAXBID_TEXT);
		$j("#switchBidIcon" + lotID).removeClass(INSTABID_ICON);
		$j("#switchBidIcon" + lotID).addClass(MAXBID_ICON);
		$j("#switchBidType" + lotID).show();		
	}else{
		if ((parseFloat(bid) > 0 || parseFloat(minBidAmt) > .01) && ($j("#UseInstaBid").val() == "False" || $j("#AllowInstaBid" + lotID).val() == "0") && ($j("#confirmBid" + lotID).is(":visible") == false)){
			$j("#minimumBid" + lotID).show();
		}else{
			$j("#minimumBid" + lotID).hide();
		}
	}
	
	if(document.getElementById("ConfirmHighBid:" + lotID)){
		document.getElementById("ConfirmHighBid:" + lotID).value = bid;
	}
	if(document.getElementById("ConfirmHighBidder:" + lotID)){
		document.getElementById("ConfirmHighBidder:" + lotID).value = bidder;
	}

	if (!lotStatus) {
		lotStatus = 0;
	}
	if (minBidAmt && minBidAmt != -1) {
		updateMinBid(formatCurrency(minBidAmt), lotID);
	}
	
	if (lotStatus == 3 || lotStatus > 4) {
		bidLabel = "Sold for: ";
		msg = "";

		if (document.getElementById("isLotDetail")){
			if (document.getElementById("isLotDetail").value == "1"){
				window.location.reload();
			}
		}else{
			if (document.getElementById("TimeRemaining:" + lotID)) {
				document.getElementById("TimeRemaining:" + lotID).style.display = "none";
			}
			if (document.getElementById("lotWatchContainer:" + lotID)) {
				document.getElementById("lotWatchContainer:" + lotID).style.display = "none";
			}
			if (document.getElementById("timesTheMoneyMsg" + lotID)){
				document.getElementById("timesTheMoneyMsg" + lotID).style.display = "none";
			}
			if (document.getElementById("soldQuantity" + lotID)){
				document.getElementById("soldQuantity" + lotID).style.display = "block";
			}
		}

		switchBidWidgetClass(BIDWIDGET_CLOSED, lotID, lotStatus);
	}
	else if (lotStatus == 4) {
		bidLabel = "PASSED";
		
		if(msg != "~dnd~"){
			msg = "";
		}
		bid = "";
		// if(document.getElementById("Bid:" + lotID)){
		// document.getElementById("Bid:" + lotID).style.display = "none";
		// }
		
		if (document.getElementById("isLotDetail")){
			if (document.getElementById("isLotDetail").value = "1"){
				if (document.getElementById("TimedArea")){
					document.getElementById("TimedArea").style.display = "none";
				}
				if (document.getElementById("LotPassed:" + lotID)){
					document.getElementById("LotPassed:" + lotID).style.display = "block";
				}
			}
		}else{
			if (document.getElementById("TimeRemaining:" + lotID)) {
				document.getElementById("TimeRemaining:" + lotID).style.display = "none";
			}
			if (document.getElementById("minimumBid" + lotID)) {
				document.getElementById("minimumBid" + lotID).style.display = "none";
			}
			if (document.getElementById("Symbol:" + lotID)) {
				document.getElementById("Symbol:" + lotID).style.display = "none";
			}
			if (document.getElementById("Bid:" + lotID)) {
				document.getElementById("Bid:" + lotID).style.display = "none";
			}
			if (document.getElementById("lotWatchContainer:" + lotID)) {
				document.getElementById("lotWatchContainer:" + lotID).style.display = "none";
			}
			if (document.getElementById("timesTheMoneyMsg" + lotID)){
				document.getElementById("timesTheMoneyMsg" + lotID).style.display = "none";
			}
			if (document.getElementById("soldQuantity" + lotID)){
				document.getElementById("soldQuantity" + lotID).style.display = "none";
			}
		}
		
		switchBidWidgetClass(BIDWIDGET_NORMAL, lotID, lotStatus);
	}

	if (bidder == null || bidder.toLowerCase() == "onsite" || bidder.toLowerCase() == "no bids") {
		bidder = "";
	}
	else if (bidder.toLowerCase() == "none") {
		bidder = getBidder(lotID);
	}
	else if (lotStatus != 0) {
		bidder = "";
	}else{
		bidder = "by " + bidder;
	}

	if (lotStatus == 0 && (bid == 0 || bid.toLowerCase() == "none")) {
		var tmpBid = getBid(lotID);
		if (tmpBid) {
			bid = tmpBid
			if (document.getElementById("Bid:" + lotID)) {
				document.getElementById("Bid:" + lotID).innerHTML = bid;
			}
		}
		var tmpBidLabel = getBidLabel(lotID);
		if (tmpBidLabel) {
			bidLabel = tmpBidLabel
			if (document.getElementById("statusLabel:" + lotID)) {
				document.getElementById("statusLabel:" + lotID).innerHTML = bidLabel;
			}
		}

		//bid = getBid(lotID);
		//bidLabel = getBidLabel(lotID);
		////bidLabel = "No bids placed";
		if (bidLabel == "Current Bid:" || bidLabel == "No bids placed") {
			bidder = "";
			if (!msg) {
				msg = getExtraMessage(lotID);
			}
			if (bidLabel == "No bids placed") {
				if (document.getElementById("Bid:" + lotID)) {
					document.getElementById("Bid:" + lotID).style.display = "none";
				}
				if (document.getElementById("Symbol:" + lotID)) {
					document.getElementById("Symbol:" + lotID).style.display = "none";
				}
			}
		}
	} else {
		if (document.getElementById("statusLabel:" + lotID)) {
			document.getElementById("statusLabel:" + lotID).innerHTML = bidLabel;
		}
	}
	
	if (bidLabel != "No bids placed"){
		document.getElementById("statusLabel:" + lotID).style.left = "0";
	}
	//document.getElementById("statusLabel:" + lotID).innerHTML = bidLabel;
	//document.getElementById("Bid:" + lotID).innerHTML = bid;
	if (isNaN(bid.toString().replace(/-|\+|\$|\,/g, '')) || bid <= 0) {
		// this code commented out to prevent the automatic updater from overwriting the Current Bid text.
		// now when the bid is zero. it just leaves the text as is.
		//document.getElementById("Symbol:" + lotID).style.display = "none";
		//document.getElementById("Bid:" + lotID).style.display = "none";
		//document.getElementById("Bid:" + lotID).innerHTML = "";
	} else {
		if (document.getElementById("Bid:" + lotID)) {
			document.getElementById("Bid:" + lotID).innerHTML = bid;
			document.getElementById("Bid:" + lotID).style.display = "inline";
		}
		if (document.getElementById("Symbol:" + lotID)) {
			document.getElementById("Symbol:" + lotID).style.display = "inline";
		}
	}

	if (document.getElementById("reserveNotMet:" + lotID)) {
		var elReserveIcon = document.getElementById("reserveNotMet:" + lotID);
		if(lotStatus >= 3 && lotStatus != 4){
			//Hide if passed or closed
			$j(elReserveIcon).hide();
		}
		else if (reserveMet == "0") {
			$j(elReserveIcon).show();
			if (document.getElementById("reserveNotMet:" + lotID) && lotStatus == 4) {
				document.getElementById("reserveText:" + lotID).style.color = "#999999";
			}
			
		}
		else if (reserveMet == "1") {
			$j(elReserveIcon).hide();
		}
		else if (reserveMet == "2") {
			//Do nothing here because there is no reserve for this lot
		}
		else if (reserveMet != "none" && reserveMet != "") {// "" means leave alone. "none" will only be here if there was an error of some sort
			$j(elReserveIcon).hide();
		}
	}

	if (document.getElementById("additionalMessage:" + lotID)) {
		if (msg != "" && msg != "~dnd~") {
			// Check to see if bid is accepted and then show the header that says Bid Successful!
			if (msg.match("Congrats!") != null) {
				//bidNotAcceptedMsg.hide(lotID);
				//bidOutbidMsg.hide(lotID);
				bidAcceptedMsg.show(lotID);
				msg = "You lead!";
				bidder = "by " + currentUser + "!";
				//document.getElementById('BidAmount:' + lotID).value = "";
			} else if (msg.match("Bid raised") != null) {
				switchBidWidgetClass(BIDWIDGET_LEADING, lotID);

			} else if (msg.match("Sorry.") != null) {
				$j('#BidWidget' + lotID + ' .placeBid').hide();
				bidNotAcceptedMsg.show(lotID);
				if(document.getElementById("IsTimedOnly").value != "1"){
					$j('#enterLiveAuctionButton' + lotID).show();
					msg = 'The live auction is about to begin.  Click "Enter Live Auction" to continue bidding.';
				}
				//bidAcceptedMsg.hide(lotID);
				//bidOutbidMsg.hide(lotID);
				//				bidNotAcceptedMsg.show(lotID);
			} else if (msg.match("has already outbid you") != null) {
				//bidNotAcceptedMsg.hide(lotID);
				//bidAcceptedMsg.hide(lotID);
				bidOutbidMsg.show(lotID);
				msg = "";
			} else if (msg.match("between increments") != null) {
				switchBidWidgetClass(BIDWIDGET_SELECTINCREMENT, lotID);
				msg = "";
			} else if (msg.match("auction is LIVE") != null) {
				$j('#BidWidget' + lotID + ' .placeBid').hide();
				bidNotAcceptedMsg.show(lotID);
			} else {
				bidNotAcceptedMsg.show(lotID);
				updateApprovalStatusMsg(false);
				// bidAcceptedMsg.hide(lotID);
				// bidOutbidMsg.hide(lotID);
			}
		}
		
		var currentBidder = "";
		if (document.getElementById("Bidder:" + lotID) && bidder != "") {
			currentBidder = jQuery.trim(document.getElementById("Bidder:" + lotID).innerHTML);
		}
		
		//Message checks to fix certain conditions with timed auctions
		var bidNoCommas = bid.toString().replace(/\,/g,'');
		if(msg == "~dnd~") {
			if(bidder == "by " + currentUser) {
			
				//Only update widget message if bidder changed to "by You!"
				//	Prevents id error messages from being hidden
				if(bidder != currentBidder){
					msg = "You lead!";
					bidAcceptedMsg.show(lotID);
				}
			}
			else if(!isNaN(bidNoCommas) && bidNoCommas > 0) {
				if(getBidWidgetClass(lotID) == BIDWIDGET_LEADING || currentBidder == "by " + currentUser || currentBidder == "by " + currentUser + "!") {
					bidOutbidMsg.show(lotID);
					msg = "";
				}
			}
			
			if(lotStatus == 4) {
				msg = "This lot was not sold"
			}
		}

		if (msg != "" && msg != "~dnd~") {

			$j(document.getElementById("additionalMessage:" + lotID)).removeClass('hideMessage');
			document.getElementById("additionalMessage:" + lotID).innerHTML = msg
			//document.getElementById("additionalMessage:" + lotID).style.display = "block";
		}
		else if (msg != "~dnd~") {
			$j(document.getElementById("additionalMessage:" + lotID)).addClass('hideMessage');
			//document.getElementById("additionalMessage:" + lotID).style.display = "none";
			document.getElementById("additionalMessage:" + lotID).innerHTML = "";
		}
	}

	
	if (document.getElementById("widgetlotQuantityInfo:" + lotID) && document.getElementById("widgetlotLotTypeInfo:" + lotID)) {
		var lotQuantity = document.getElementById("widgetlotQuantityInfo:" + lotID).value;
		var lotType = document.getElementById("widgetlotLotTypeInfo:" + lotID).value;
		if (lotQuantity > 1 && lotType == 2) {
			var bidAmount = bid.toString().replace(/\$|\,/g, '');
			var bidTotal = formatCurrency((bidAmount * lotQuantity));
			//.var dispBidAmount = document.getElementById("TimesTheMoneyBidAmount:" + lotID).value;
			
			//if (bidAmount > dispBidAmount){
			
			var bOkToUpdate = true;

			if (document.getElementById("modalFixed")){
				bOkToUpdate = false;
			}
			
			if (document.getElementById("Bid:" + lotID)){
				if (parseFloat(document.getElementById("Bid:" + lotID).innerHTML) > parseFloat(bidAmount)){
					bOkToUpdate = false;
				}
			}

			if (document.getElementById("confirmBid" + lotID)){
				if (document.getElementById("confirmBid" + lotID).style.display == "block"){
					bOkToUpdate = false;
				}
			}

			if (bOkToUpdate){
				document.getElementById("TimesTheMoneyBidAmount:" + lotID).innerHTML = formatCurrency(bidAmount);
				document.getElementById("TimesTheMoneyBidTotal:" + lotID).innerHTML = bidTotal;
				document.getElementById("TimesTheMoneyBidTotalAmt:" + lotID).innerHTML = bidTotal;
				
				if (!(document.getElementById("isLotDetail"))){
					document.getElementById("TimesTheMoneyBidAmountSold:" + lotID).innerHTML = formatCurrency(bidAmount);
					document.getElementById("TimesTheMoneyBidTotalSold:" + lotID).innerHTML = bidTotal;
				}
			}
			//}
		}
	}


	if (document.getElementById("Bidder:" + lotID) && bidder != "") {
		document.getElementById("Bidder:" + lotID).innerHTML = bidder;
	}

	// Dynamic content for timed auctions if the closed lot area exists.
	if (lotStatus >= 3 && document.getElementById('divClosedLots')) {
		Effect.BlindUp.delay(5, 'LotTable:' + lotID);
		document.getElementById('divClosedLots').innerHTML = "<div id='ClosedTable:" + lotID + "' style='display:none;'>" + document.getElementById('LotTable:' + lotID).innerHTML + "</div>" + document.getElementById('divClosedLots').innerHTML;
		Effect.BlindDown.delay(5, 'ClosedTable:' + lotID);
		var promptRefresh = false;
		var forceRefresh = false;
		var showEndOfAuction = false;
		var itemsPerPage = document.getElementById('hdnItemsPerPage').value * 1;
		var closedLots = document.getElementById('hdnClosedLotsOnPage').value * 1; closedLots++;
		if (itemsPerPage == closedLots) {
			forceRefresh = true;
		} else {
			document.getElementById('hdnClosedLotsOnPage').value = closedLots;
			switch (itemsPerPage) {
				case 50: if (closedLots == 20) { promptRefresh = true; }; break;
				case 25: if (closedLots == 10) { promptRefresh = true; }; break;
				case 10: if (closedLots == 5) { promptRefresh = true; }; break;
				case 5: if (closedLots == 3) { promptRefresh = true; }; break;
				default: break;
			}
		};
		//alert(document.getElementById("hdnExtendedBidding").value);//'true'
		//alert(document.getElementById("hdnClosedAuction").value); //''
		if (document.getElementById("hdnExtendedBidding").value + '' == 'true') { checkForExtended(true); };
		if ((document.getElementById("hdnExtendedBidding").value + '' == '' || document.getElementById("hdnExtendedBidding").value + '' == 'false') && document.getElementById("hdnClosedAuction").value + '' != 'true') {
			if (document.getElementById('closedLotsArea').style.display != 'block') { document.getElementById('closedLotsArea').style.display = 'block'; };
			if (forceRefresh) {
//				var x = confirm('More lots available for bidding.  Refresh page?');
//				if (x == true) { loadMoreLots(); };
				openLoadLotsModal();
			} else {
				if (promptRefresh) {
//					var x = confirm('More lots available for bidding.  Refresh page?');
//					if (x == true) { loadMoreLots(); };
					openLoadLotsModal();
				}
			};
		};
	};

	if (lotStatus >= 3) {
		if (document.getElementById("hdnExtendedBidding").value + '' == 'true') { checkForExtended(true); };
		
		//Close bid confirmation dialog if still open
		var elConfirm = $j('#confirmBidModal:visible');
		if(elConfirm.length > 0){
			if($j(elConfirm).children('.confirmLotID')[0].value == lotID){
				ConfirmBidModal.closeModal(function(){
					
				});
			}
		}
	};
}

function openLoadLotsModal() {
	jQuery("#loadLotsModal").dialog({
		autoOpen: false,
		height: 120,
		width: 370,
		modal: true,
		resizable: false,
		draggable: false,
		buttons: {
			"Yes": function () {
				jQuery("#loadLotsModal").dialog("close");
				loadMoreLots();
			},
			"No": function () {
				jQuery("#loadLotsModal").dialog("close");
			}
		},
		open: function () {
			jQuery(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove();
		}

	});
	document.getElementById("loadLotsModal").innerHTML = '<center>' + 'More lots available for bidding.  Refresh page?' + '</center>';
	jQuery("#loadLotsModal").dialog("open");
}

function loadMoreLots() {
	document.frmCatalogSort1.action = document.frmCatalogSort1.action + "#cnTb";
	document.frmCatalogSort1.submit();
}

function showEndOfAuctionMsg() {
	if (document.getElementById("hdnClosedAuction")){
		if (document.getElementById("hdnClosedAuction").value + "" != "true") {
			document.getElementById('closedLotsArea').style.display = 'none';
			document.getElementById("hdnExtendedBidding").value = '';
			document.getElementById("hdnClosedAuction").value = 'true';
			document.getElementById("urgentIconAuction").className = "";
			var elAuctionStatusMsg = $j('#AuctionStatusClarifier');
			$j(elAuctionStatusMsg[0]).html('Auction closed.');
			openEndOfAuctionModal();
		};
	}
}

function openEndOfAuctionModal() {
	jQuery("#endOfAuctionModal").dialog({
		autoOpen: false,
		height: 120,
		width: 370,
		modal: true,
		resizable: false,
		draggable: false,
		buttons: {
			"OK": function () {
				jQuery("#endOfAuctionModal").dialog("close");
			}
		},
		open: function () {
			jQuery(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove();
		}

	});
	document.getElementById("endOfAuctionModal").innerHTML = '<center>' + 'This concludes the auction. Thank you for bidding.' + '</center>';
	try { jQuery("#loadLotsModal").dialog("close"); } catch (e) { };
	jQuery("#endOfAuctionModal").dialog("open");
}

function updateMinBid(newValue, lotID) {
	var elMinBid = $j('#BidWidget' + lotID).find('div#minimumBid' + lotID + ' > span > a.minBid');
	
	if(elMinBid.length > 0)	{
		elMinBid = elMinBid[0];
		var currentHTML = $j(elMinBid).html();
		//newValue = newValue.replace(/[,]+/, "");
		var newHTML = currentHTML.replace(/[\d.,]+/, newValue);
		
		$j(elMinBid).html(newHTML);
		$j(elMinBid).show();
	}	
	
	//update InstaBid

	newValue = newValue.replace(/[,]+/, "");	
	var currentInstaBidAmt = parseFloat($j("#InstaBidAmount" + lotID).val());
	if (currentInstaBidAmt < parseFloat(newValue)){
		newValue = formatCurrency(newValue);
		$j("#InstaBidButtonText" + lotID).html("BID NOW " + $j("#currencySymbol").val() + newValue);
		$j("#InstaBidAmount" + lotID).val(newValue);
	}
}

function slideDown() {
	slideDown.original = $j('.slideDown > div').css('top');
	$j('#slideDown').css('z-index', 1);
	$j('.slideDown > div').animate({
		top: '1px'
	}, 300);
}

function slideUp(cb) {
	var position = 0; //(slideDown.original ? slideDown.original : 0);
	$j('#slideDown').css('z-index', 0);

	$j('.slideDown > div').animate({
		top: -100 + 'px'
	}, 1, cb);
}

function UpdateConfirmDialogMessage() {
	var auctionReqCC = $j("#AuctionReqCC").val();
	var ccID = "" + $j("#ConfirmCCID").val();
	var ccLastFour = "" + $j("#ConfirmCCLastFour").val();
	var ccTypeName = "" + $j("#ConfirmCCTypeName").val();
	var ccToken = "" + $j("#ConfirmCCToken").val();
	//Payment Messages
	if (typeof cc.ccID == "undefined" || ccID != "") {
		if (auctionReqCC == 0) {
			$j("#lnkConfirmBid").removeClass("disabled");
			PaymentMessage = "&nbsp;&nbsp;Contact Auction Company to arrange payment"
		} else {
			if (ccID == "") { //add select message : should not get here if AG is working correctly
				$j("#lnkConfirmBid").addClass("disabled");
				PaymentMessage = "<a href='#' onclick='cc.launchSelectCCModal(ccCallBack); return false;' style='color:#3079a4;'>&nbsp;&nbsp;Please Add / Select Card</a>";
			} else { //message showing last 4 of CC being used and link to allow changing card.
				$j("#lnkConfirmBid").removeClass("disabled");
				PaymentMessage = "&nbsp;&nbsp;" + ccTypeName + " ending in " + ccLastFour + "<span id='ShowChangeCC'><a href='#' onclick='cc.launchSelectCCModal(ccCallBack); return false;' style='color:#3079a4;'>&nbsp;Change</a>";
			}
		}
	} else {
		if (auctionReqCC == 0) {
			$j("#lnkConfirmBid").removeClass("disabled");
			PaymentMessage = "&nbsp;&nbsp;Contact Auction Company to arrange payment"
		} else {
			if (cc.ccID == 0) { //add select message : should not get here if AG is working correctly
				$j("#lnkConfirmBid").addClass("disabled");
				PaymentMessage = "<a href='#' onclick='cc.launchSelectCCModal(ccCallBack); return false;' style='color:#3079a4;'>&nbsp;&nbsp;Please Add / Select Card</a>";
			} else { //message showing last 4 of CC being used and link to allow changing card.
				$j("#lnkConfirmBid").removeClass("disabled");
				PaymentMessage = "&nbsp;&nbsp;" + cc.ccTypeName + " ending in " + ccLastFour + "<span id='ShowChangeCC'><a href='#' onclick='cc.launchSelectCCModal(ccCallBack); return false;' style='color:#3079a4;'>&nbsp;Change</a>";
			}
		}
	}
	
	if(isWhiteListed()){
		$j("#lnkConfirmBid").removeClass("disabled");
	}

	document.getElementById("PaymentTypeMsg").innerHTML = PaymentMessage;
	if (PaymentMessage.indexOf(ccLastFour) > 0){
		document.getElementById("PaymentType").className = "valid1";
	}
		
	CalculateTimesTheMoney(false);
}

// END - UI CODE ***********************************************************************

function CalculateTimesTheMoney(bCancel){

	if (bCancel){
		//Reset totals if the lot is Times The Money
		if (document.getElementById("widgetlotQuantityInfo:" + auctionGuardLot)) {
			var lotQuantity = document.getElementById("widgetlotQuantityInfo:" + auctionGuardLot).value;
			var currentBid = document.getElementById("Bid:" + auctionGuardLot).innerHTML;
			if (lotQuantity > 1) {
				var bidAmount = currentBid.toString().replace(/\$|\,/g, '');
				var bidTotal = formatCurrency((bidAmount * lotQuantity));
				document.getElementById("TimesTheMoneyBidAmount:" + auctionGuardLot).innerHTML = formatCurrency(bidAmount);
				document.getElementById("TimesTheMoneyBidTotal:" + auctionGuardLot).innerHTML = bidTotal;
				document.getElementById("TimesTheMoneyBidTotalAmt:" + auctionGuardLot).innerHTML = bidTotal;

				if (!(document.getElementById("isLotDetail"))){
					document.getElementById("TimesTheMoneyBidAmountSold:" + auctionGuardLot).innerHTML = formatCurrency(bidAmount);
					document.getElementById("TimesTheMoneyBidTotalSold:" + auctionGuardLot).innerHTML = bidTotal;
				}
			}
		}
	}else{
		//Calculate totals if the lot is Times The Money
		if (document.getElementById("widgetlotQuantityInfo:" + auctionGuardLot)) {
			var lotQuantity = document.getElementById("widgetlotQuantityInfo:" + auctionGuardLot).value;
			var currentBid = document.getElementById("BidAmount:" + auctionGuardLot).value;
			if (lotQuantity > 1) {
				var bidAmount = currentBid.toString().replace(/\$|\,/g, '');
				var bidTotal = formatCurrency((bidAmount * lotQuantity));
				document.getElementById("TimesTheMoneyBidAmount:" + auctionGuardLot).innerHTML = formatCurrency(bidAmount);
				document.getElementById("TimesTheMoneyBidTotal:" + auctionGuardLot).innerHTML = bidTotal;
				document.getElementById("TimesTheMoneyBidTotalAmt:" + auctionGuardLot).innerHTML = bidTotal;

				if (!(document.getElementById("isLotDetail"))){
					document.getElementById("TimesTheMoneyBidAmountSold:" + auctionGuardLot).innerHTML = formatCurrency(bidAmount);
					document.getElementById("TimesTheMoneyBidTotalSold:" + auctionGuardLot).innerHTML = bidTotal;
				}
			}
		}
	}
}

function submitApplication(auctionID) {

	//Load the global AuctionGuard auctionID variable;
	auctionGuardAuction = auctionID;

	profileCompleteCallBack = function(complete){
		if(complete == true){
			getNeedsAGDecision(auctionID, function(needScore) {
				if ("true" == needScore) {
					creditCardCallBackAfterAG = function() {ccCallBack(true);}
					getAuctionGuardScore(0, function(bCanBid) {
						if(isWhiteListed()){
							//Ask for credit card
							whiteListGetCard(function() {
								submitAppAGFinished(bCanBid, auctionID);
							});
						}
						else{
							submitAppAGFinished(bCanBid, auctionID);
						}
						
					}, false, "Cancel");
				} else if ("declined" == needScore) {
					updateApprovalStatusMsg(true);
					//scrollToStatusMsg(true);
				} else if ("approved" == needScore) {
						updateApprovalStatusMsg(true);
				} else if ("loggedOut" == needScore) {
					if(confirm('You must login to apply to bid.')) {
						window.location.href = '/asp/LoginBidder.asp'
					}
				}
			});
		} else {
			updateApprovalStatusMsg(true);
		}
	}
	doProfileCompleteChecks(true, "Cancel");
}

function submitAppAGFinished(bCanBid, auctionID) {

	$j("#progressModal").dialog("close");
	updateApprovalStatusMsg(true, function() {
		if(bCanBid) {
			var ccRequired = ($j('#bidderStatusCCRequired')[0].value == "1") ? true : false;
			var ccid = $j('#bidderStatusCCID')[0].value-0;

			if(ccRequired) {
				if(ccid == -1) {
					cc.launchSelectCCModal(function() {
						ccCallBackInner(false, function(){
							updateApprovalStatusMsg(true);
						});
					});
				}
			}
		}
	});
}


// START - PLACE BID CODE **************************************************************
function checkIncrement(auctionID, lotID) {
	checkIncrement2(auctionID, lotID, false);
}

function checkIncrement2(auctionID, lotID, isLotDetail) {
	auctionGuardAuction = auctionID
	auctionGuardLot = lotID
	mIsLotDetail = isLotDetail
	mbInstaBid = false;
	
	//If the PLACE BID button is disabled, do nothing.
	if ($j("#linkBidAmount:" + lotID).hasClass("disabled")){
		return false;
	}
	
	var bidOrig = document.getElementById("BidAmount:" + lotID).value;
	var bidAmount = bidOrig.toString().replace(/\$|\,/g, '');
	if (!isNaN(bidAmount)) {
		bidAmount = formatCurrency(bidAmount);  //do some clean up
		//set cleanup value back to text for use in placeBid function... only matters if we add some cleanup/error checks
		document.getElementById("BidAmount:" + lotID).value = bidAmount;
	}

	$j("#ConfirmBidQuestion").hide();  //not an instabid, do not allow disabling

	if (amountValidCheck(lotID)) {
		//bid is a number.  Continue to hit auction guard.
		
		profileCompleteCallBack = function(complete){
			if(complete == true){
				getNeedsAGDecision(auctionGuardAuction, function(needScore) {
					if ("true" == needScore) {
						creditCardCallBackAfterAG = function() {ccCallBack(true);};
						getAuctionGuardScore(0, auctionGuardFinished, true, "Cancel");
					} else if ("declined" == needScore) {
						updateApprovalStatusMsg(true);
						//scrollToStatusMsg(true);
					} else if ("approved" == needScore) {
						
								updateApprovalStatusMsg(false);
								continueCheckIncrement(lotID);
						
					} else if ("loggedOut" == needScore) {
						redirectToLogin(lotID);
					}
				});
			} else {
				updateApprovalStatusMsg(true);
			}
		}
		
		doProfileCompleteChecks(true, "Cancel");
	}
}

function placeInstaBid(auctionID, lotID, isLotDetail) {
	auctionGuardAuction = auctionID
	auctionGuardLot = lotID
	mIsLotDetail = isLotDetail
	mbInstaBid = true
	
	//If the PLACE BID button is disabled, do nothing.
	if ($j("#linkBidAmount:" + lotID).hasClass("disabled")){
		return false;
	}
	
	var bidAmount = $j("#InstaBidAmount" + lotID).val();
	var noConfirm = $j("#NoConfirmBid").val();
	
	document.getElementById("BidAmount:" + lotID).value = bidAmount;
	
	if (noConfirm == "1") { //Bidder turned off confirmations.  Place the bid
		placeBid(auctionGuardAuction, lotID);
	}else{ //Bidder still needs to confirm placing the bid
		$j("#ConfirmBidQuestion").show(); //Allow the bidder to turn off confirm dialogs for InstaBid
		document.getElementById("BidAmount:" + lotID).value = bidAmount;
		profileCompleteCallBack = function(complete){
			if(complete == true){
				getNeedsAGDecision(auctionGuardAuction, function(needScore) {
					if ("true" == needScore) {
						creditCardCallBackAfterAG = function() {ccCallBack(true);};
						getAuctionGuardScore(0, auctionGuardFinished, true, "Cancel");
					} else if ("declined" == needScore) {
						updateApprovalStatusMsg(true);
						//scrollToStatusMsg(true);
					} else if ("approved" == needScore) {
						
								updateApprovalStatusMsg(false);
								continueCheckIncrement(lotID);
						
					} else if ("loggedOut" == needScore) {
						redirectToLogin(lotID);
					}
				});
			} else {
				updateApprovalStatusMsg(true);
			}
		}
		
		doProfileCompleteChecks(true, "Cancel");
	}
}

function getNeedsAGDecision(auctionID, successCB) {
	var d = new Date();
	
	$j.ajax({
		url: "/asp/getNeedsAGDecision.asp?nc=" + d.getTime() ,
		data: { auctionID: auctionID },
		success: function(response){
			if(response != "true"){
				$j("#progressModal").dialog("close");
			}
			successCB(response);
		}
	});
	
}

function auctionGuardFinished(bCanBid) {
	$j("#progressModal").dialog("close");
	if (bCanBid == true) {
		continueCheckIncrement(auctionGuardLot);
		// //NEED TO POP CONFIRM DIALOG HERE
		// if (mIsLotDetail) {
			// confirmBidAmountLotDetail(auctionGuardLot);
		// } else {
			// confirmBidAmount(auctionGuardLot);
		// }
		updateApprovalStatusMsg(false);
	}
	else {
		updateApprovalStatusMsg(true);
		//scrollToStatusMsg(true);
	}
}


function confirmBidAmount(lotID) {

	confirmBid(lotID);

	CalculateTimesTheMoney(false);
	
	var cb = ConfirmBidModal;
	cb.launchModal(function () {
		placeBid(auctionGuardAuction, lotID);
	}, lotID);
}

function continueCheckIncrement(lotID) {
	var bidOrig = document.getElementById("BidAmount:" + lotID).value;
	var bidAmount = bidOrig.toString().replace(/\$|\,/g, '');
	bidAmount = formatCurrency(bidAmount);  //do some clean up
	//set cleanup value back to text for use in placeBid function... only matters if we add some cleanup/error checks
	document.getElementById("BidAmount:" + lotID).value = bidAmount;

	if (amountValidCheck(lotID)) {
		if (mIsLotDetail){
			$j(".confirmBid").hide();
		}else{
			document.getElementById("confirmBid" + lotID).style.display = "none";
		}

		$j(document.getElementById('additionalMessage:' + lotID)).addClass('hideMessage');
		switchBidWidgetClass(BIDWIDGET_NORMAL, lotID);
		var d = new Date();
		var RequestURL = "/asp/xml/CheckIncrement.asp?aid=" + auctionGuardAuction + "&lid=" + lotID + "&amt=" + document.getElementById("BidAmount:" + lotID).value.replace(/,/gi, "") + "&cb=" + d.getTime();
		// $j.getJSON(RequestURL, continueCheckIncrementHandler());
		
		$j.ajax({
		  url: RequestURL,
		  dataType: 'json',
		  success: function(data) {
			continueCheckIncrementHandler(data);
		  },
		  error: function(data) {
			alert("error " + data);
		  }
		});		
		//$j.getJSON(RequestURL, continueCheckIncrementHandler);		
		//.success(function() { alert("second success"); })
		//.error(function() { alert("error"); })
		//.complete(function() { alert("complete"); });		
		
/*		
		var wRequest = new Sys.Net.WebRequest();
		wRequest.set_url(RequestURL);
		wRequest.set_httpVerb("GET");

		wRequest.add_completed(continueCheckIncrementHandler);

		var executor = wRequest.get_executor();

		wRequest.invoke();
*/		
	}
}

function continueCheckIncrementHandler(response) {
	var lotID = -1;
	var highBidLabel = "High Bid";
	var message = "";
	var highBidder = "";
	var highBid = 0;
	var reserveMet = 0;
	var nextHigherBid = "0";
	var nextLowerBid = "0";
	var betweenIncMsg = "";
	var bLowerHidden = false;
	var bIncrementChoiceVisible = false;
	var currencySymbol = "";
	var nextBid = "";

	$j.each(response, function(key, val) {
		if (key == "lotid"){
			lotID = val;
		}
		if (key == "highbidder"){
			highBidder = val;
		}
		if (key == "highbid"){
			highBid = val;
		}
		if (key == "reservemet"){
			reserveMet = val;
		}
		if (key == "message"){
			message = val;
		}
		if (key == "nexthigherbid"){
			nextHigherBid = val;
		}
		if (key == "nextlowerbid"){
			nextLowerBid = val;
		}
		if (key == "nextbid"){
			nextBid = val;
		}
	});

	if (lotID > -1) {

		if (document.getElementById("ConfirmHighBid:" + lotID)){
			document.getElementById("ConfirmHighBid:" + lotID).value = highBid;
		}

		if (document.getElementById("BidWidget" + lotID)) {
			currencySymbol = document.getElementById('Symbol:' + lotID).innerHTML;		

			if (nextLowerBid.replace(/,/gi, "") > 0) {
				$j('#BidWidget' + lotID + ' .incrementChoice .downarrow').html(function (index, oldhtml) {
					return oldhtml.replace(/<\/span>.*/i, '</span>' + currencySymbol + nextLowerBid);
				}).show();
				bIncrementChoiceVisible = true;
				betweenIncMsg = " Try "; // + incrementLink(lotID, incTemp);
			}
			else {
				$j('#BidWidget' + lotID + ' .incrementChoice .downarrow').hide();
				bLowerHidden = true;
			}

			if (nextHigherBid.replace(/,/gi, "") > 0) {
				$j('#BidWidget' + lotID + ' .incrementChoice .uparrow').html(function (index, oldhtml) {
					var your = " ";
					if (bLowerHidden) {
						your = " your ";
					}
					return oldhtml.replace(/<\/span>.*/i, '</span>' + currencySymbol + nextHigherBid);
				}).show();
			}
		}
	
		if (message != "" && message != "na") {
			setLotStatus(lotID, highBid, highBidder, reserveMet, message, null, null, nextBid);
			if (mIsLotDetail){
				$j("#minimumBid").hide();
			}
			removeBidInfo(lotID);
			showButtons(lotID, "");
			bidAmountBlur(lotID);
		} else {
			//NEED TO POP CONFIRM DIALOG HERE
			if (mIsLotDetail) {
				UpdateConfirmDialogMessage();
				confirmBidAmountLotDetail(lotID);
			} else {
				confirmBidAmount(lotID);
			}
			
			var ccID = "" + $j("#ConfirmCCID").val();
			var ccToken = "" + $j("#ConfirmCCToken").val();
			var bRequireCC = $j("#AuctionReqCC").val();
			
			if (ccID != ""){
				if(bRequireCC == 1){
					cc.addCardToReg(ccID, ccToken, ccFinishFunction);//addDefaultCCCallBack);
				}
			}
			//placeBid(auctionGuardAuction, lotID);
		}
	}
}

function ccFinishFunction(iRetVal){
//no code needed right now.  only in place for cc.addCardToReg to work.
	if(iRetVal == -1){
		agAlertDialog('There was an error validating your card.  Please try again or call Proxibid Technical Assistance at 877-505-7770.');
	}
}

function confirmBid(lotID) {
	var bidOrig = document.getElementById("BidAmount:" + lotID).value;
	var bidAmount = bidOrig.toString().replace(/\$|\,/g, '');
	bidAmount = formatCurrency(bidAmount);  //do some clean up 
	//set cleanup value back to text for use in placeBid function... only matters if we add some cleanup/error checks
	document.getElementById("BidAmount:" + lotID).value = bidAmount;

	if (amountValidCheck(lotID)) {
		$j("#additionalMessage:" + lotID).addClass('hideMessage');
		//document.getElementById("additionalMessage:" + lotID).style.display = "none";
		storeBidInfo(lotID, document.getElementById("Bid:" + lotID).innerHTML, document.getElementById("Bidder:" + lotID).innerHTML, document.getElementById("statusLabel:" + lotID).innerHTML, document.getElementById("additionalMessage:" + lotID).innerHTML);
		setLotStatus(lotID, bidAmount, "", 2, "Confirm bid amount?", -1);
		document.getElementById("statusLabel:" + lotID).innerHTML = "You Entered";
		showButtons(lotID, "confirmBid");
	}
}

function amountValidCheck(lotID) {
	var bidOrig = document.getElementById("BidAmount:" + lotID).value;
	var bidAmount = bidOrig.toString().replace(/\$|\,/g, '');

	if (isNaN(bidAmount)) {
		bidNotAcceptedMsg.show(lotID);
		//bidAcceptedMsg.hide(lotID);
		//bidOutbidMsg.hide(lotID);
		document.getElementById("additionalMessage:" + lotID).innerHTML = "<span style='font-weight:bold;'>Error.</span> bid amount must be a number.";
		//document.getElementById("additionalMessage:" + lotID).style.display = "block";
		$j(document.getElementById("additionalMessage:" + lotID)).removeClass('hideMessage');
		bidAmountBlur(lotID);
		//document.getElementById("BidAmount:" + lotID).value = BID_AMOUNT_DEFAULT[BidWidgetMessageMap[lotID]];
		return false;
	} else if (bidAmount <= 0.0049999999) {
		bidNotAcceptedMsg.show(lotID);
		//bidAcceptedMsg.hide(lotID);
		//bidOutbidMsg.hide(lotID);
		document.getElementById("additionalMessage:" + lotID).innerHTML = "Nothing in life is free.  Please bid again.";
		//document.getElementById("additionalMessage:" + lotID).style.display = "block";
		$j(document.getElementById("additionalMessage:" + lotID)).removeClass('hideMessage');
		bidAmountBlur(lotID);
		//document.getElementById("BidAmount:" + lotID).value = BID_AMOUNT_DEFAULT[BidWidgetMessageMap[lotID]];
		return false;
	}
	return true;
}

function confirmBidAmountLotDetail(lotID) {
	var bidAmount = document.getElementById("BidAmount:" + lotID).value;

	bidAmount = bidAmount.replace(/\,/g,'');  //do some clean up
	var dBuyersPremium = $j("#BuyersPremium").val();
	var iLotQuantity = $j("#LotQuantity").val();
	var dNetBuyersPremium = (((bidAmount * iLotQuantity) * $j("#NetBuyersPremium").val()) / 100);
	dNetBuyersPremium = new Number(dNetBuyersPremium).toFixed(2);
	var bidEstimatedTotal = formatCurrency((new Number(bidAmount)  * new Number(iLotQuantity)) + new Number(dNetBuyersPremium));
	$j("#slideBuyersPremium").text($j("#currencySymbol").val() + formatCurrency(new Number(dNetBuyersPremium)));
	$j("#slideEstimatedTotal").text($j("#currencySymbol").val() + bidEstimatedTotal + " *");
	bidAmount = formatCurrency(bidAmount);
	switchBidWidgetClass(BIDWIDGET_NORMAL, lotID);

	UpdateConfirmDialogMessage();
	
	//Hide all additional messages
	if ($j("#AllowInstaBid" + lotID).val() == "1"){
		$j("#placeInstaBid" + lotID).hide();
		$j("#switchBidType" + lotID).hide();
	}else{
		$j('.placeBid').hide();
	}

	$j('.minimumBid').hide();
	$j(".extraMessage").addClass('hideMessage');
	$j("#yourBidAmount").text("$" + bidAmount);
	$j('.confirmBid').show();
	$j('.termsMessage').show();

	slideDown();
}

function openBidProgressModal(){
	jQuery( "#progressModal" ).dialog({
		autoOpen: false,
		height: 120,
		width: 370,
		modal: true,
		resizable: false,
		draggable: false,
		buttons: { },
		open: function() {
				jQuery(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove(); 
		}

	});
	document.getElementById("progressModal").innerHTML=
		'<center>' + 'Please wait while we process your bid' + '</center>' +
		'<center><img src="/images/ajax-loader.gif" /></center>';
	jQuery( "#progressModal" ).dialog( "open" );
}

function placeBid(auctionID, lotID) {
	openBidProgressModal();
	//always add the currently selected credit card to bidder registration
	var ccID = "" + $j("#ConfirmCCID").val();
	var ccLastFour = "" + $j("#ConfirmCCLastFour").val();
	var ccTypeName = "" + $j("#ConfirmCCTypeName").val();
	var ccToken = "" + $j("#ConfirmCCToken").val();
	var bRequireCC = $j("#AuctionReqCC").val();
	var bNoConfirmDialog = false;

	// function finishFunction() {
		if (mIsLotDetail){
			$j(".confirmBid").hide();
			$j(".placingBid").show();
			bidAcceptedMsg.hide(lotID);
			bidOutbidMsg.hide(lotID);
		}else{
			document.getElementById("confirmBid" + lotID).style.display = "none";
			document.getElementById("placingBid" + lotID).style.display = "block";
			bidAcceptedMsg.hide(lotID);
			bidOutbidMsg.hide(lotID);
		}
		
		var d = new Date();
		var RequestURL = ""

		if (mbInstaBid){
			if ($j("#chkNoConfirmBid").is(":checked")){
				bNoConfirmDialog = true;
				$j("#NoConfirmBid").val("1");
			}

			RequestURL = "/asp/xml/LotPlaceBid.asp?aid=" + auctionID + "&lid=" + lotID + "&amt=" + document.getElementById("InstaBidAmount" + lotID).value + "&cb=" + d.getTime() + "&nocd=" + bNoConfirmDialog;
		}else{
			RequestURL = "/asp/xml/LotPlaceBid.asp?aid=" + auctionID + "&lid=" + lotID + "&amt=" + document.getElementById("BidAmount:" + lotID).value.replace(/,/gi, "") + "&cb=" + d.getTime() + "&nocd=na";
		}
		var wRequest = new Sys.Net.WebRequest();
		wRequest.set_url(RequestURL);
		wRequest.set_httpVerb("GET");

		wRequest.add_completed(placeBidHandler);

		var executor = wRequest.get_executor();

		wRequest.invoke();
	// }
	
	// if(bRequireCC == 1){
		// cc.addCardToReg(ccID, ccToken, finishFunction);//addDefaultCCCallBack);
	// }
	// else {
		// finishFunction();
	// }
}

function placeBidHandler(response) {
	jQuery( "#progressModal" ).dialog( "close" );
	
	if (response.get_responseAvailable()) {
		var XMLResponse = response.get_xml();
		var lots = XMLResponse.getElementsByTagName("lot");
		var lotID
		var highBidLabel = "High Bid";
		var bIsPlacingBid = false;
		var bIsInstaBid = false;
		
		for (var j = 0; j < lots.length; j++) {
			lotID = lots.item(j).childNodes[0].childNodes[0].nodeValue; //LotID

			if (document.getElementById("placingBid" + lotID).style.display == "block" ) {
				bIsPlacingBid = true;
			}

			if (document.getElementById("placeInstaBid" + lotID).style.display == "block") {
				bIsInstaBid = true;
			}

			if (document.getElementById("BidWidget" + lotID) && (bIsPlacingBid || bIsInstaBid )) {
				// HIGH BIDDER
				var highBidder = lots.item(j).childNodes[1].childNodes[0].nodeValue; //leading bidder/SoldToBidderID

				//HIGH BID
				var highBid = lots.item(j).childNodes[2].childNodes[0].nodeValue; //leading bid/HammerPrice

				//RESERVE
				var reserveMet = lots.item(j).childNodes[3].childNodes[0].nodeValue; // Reserve status 0:not met; 1:met; 2:no reserve (0.00)

				//MESSAGE
				var message = lots.item(j).childNodes[4].childNodes[0].nodeValue; //message to display.

				//BETWEEN INCREMENT MESSAGE
				var betweenIncMsg = "";
				var incTemp;
				if (lots.item(j).childNodes.length >= 6) {
					incTemp = lots.item(j).childNodes[5].childNodes[0].nodeValue;
					if (incTemp.replace(/,/gi, "") > 0) {
						betweenIncMsg = " Try " + incrementLink(lotID, incTemp);
					}

					if (lots.item(j).childNodes.length >= 7) {
						incTemp = lots.item(j).childNodes[6].childNodes[0].nodeValue;
						if (incTemp.replace(/,/gi, "") > 0) {
							if (betweenIncMsg != "") {
								betweenIncMsg += " or " + incrementLink(lotID, incTemp);
							}
							else {
								betweenIncMsg = " Try " + incrementLink(lotID, incTemp);
							}
						}
					}
				}
				if (betweenIncMsg != "") {
					message += betweenIncMsg + "."
				}else{
					//if ($j("#IsTimedOnly").val() == "1" && $j("#UseInstaBid").val() == "True" && highBid > 0){  //REMOVED TO TURN ON INSTABID FOR LIVE & TIMED
					if ($j("#UseInstaBid").val() == "True" && highBid > 0){
						$j("#AllowInstaBid" + lotID).val("1");
					}
				}
				
				
				var minBidAmt = -1;
				if (lots.item(j).childNodes.length >= 8)
				{
					minBidAmt = lots.item(j).childNodes[7].childNodes[0].nodeValue;
				}
			}
			
			document.getElementById("placingBid" + lotID).style.display = "none";
			
			setLotStatus(lotID, highBid, highBidder, reserveMet, message, null, null, minBidAmt);
			removeBidInfo(lotID);
			if (mIsLotDetail) {
				if (betweenIncMsg !=""){
					//if ($j("#IsTimedOnly").val() == "1" && $j("#UseInstaBid").val() == "1" && $j("#AllowInstaBid" + lotID) == "1"){   //REMOVED TO TURN ON INSTABID FOR LIVE & TIMED
					if ($j("#UseInstaBid").val() == "1" && $j("#AllowInstaBid" + lotID) == "1"){
						$j("#placeInstaBid" + lotID).hide();
						$j("#switchBidType" + lotID).hide();
					}else{
						$j('.minimumBid').show();
						$j('.placeBid').show();
					}
					$j('.termsMessage').hide();
				}
				showButtons(lotID, "");
				//document.getElementById("BidAmount:" + lotID).value = "";
			} else {
				showButtons(lotID, "");
				bidAmountBlur(lotID);
				//document.getElementById("BidAmount:" + lotID).value = BID_AMOUNT_DEFAULT[BidWidgetMessageMap[lotID]]
			}
			
			if (betweenIncMsg !=""){
				try{
					refreshLotTimer(lotID,1);
				}catch (e){
					//catch in case refreshLotTimer is not found
				}
			}
		}
	}
}

function cancelBid(lotID) {
	updateApprovalStatusMsg(false);
	if (mIsLotDetail) {
		function finishSlideUp() {
			$j(".confirmBid").hide();
			$j('.termsMessage').hide();
			//if ($j("#IsTimedOnly").val() == "1" && $j("#UseInstaBid").val() == "True" && $j("#AllowInstaBid" + lotID).val() == "1" ){   //REMOVED TO TURN ON INSTABID FOR LIVE & TIMED
			if ($j("#UseInstaBid").val() == "True" && $j("#AllowInstaBid" + lotID).val() == "1" ){
				$j('.minimumBid').hide();
			}else{
				if ($j("highBidOpenBid" + lotID).val() > 0){
					$j('.minimumBid').show();
				}
			}

			CalculateTimesTheMoney(true);
		}
		slideUp(finishSlideUp);
	}
	switchBidWidgetClass(BIDWIDGET_NORMAL, lotID);
	bidAmountBlur(lotID);
		//document.getElementById("BidAmount:" + lotID).value = BID_AMOUNT_DEFAULT[BidWidgetMessageMap[lotID]]

	setLotStatus(lotID, 0, getBidder(lotID), "", "")
	removeBidInfo(lotID);
}

function storeBidInfo(lotID, bid, bidder, statusLabel, extraMessage) {
	bidder = bidder.replace(/by: /gi, "")
	currentBids.push(lotID + DELIMITER + bid + DELIMITER + bidder + DELIMITER + statusLabel + DELIMITER + extraMessage)
}

function getBid(lotID) {
	var bidInfo = findBidInfo(lotID);
	return bidInfo[1];
}

function getBidder(lotID) {
	var bidInfo = findBidInfo(lotID);
	return bidInfo[2];
}

function getBidLabel(lotID) {
	var bidInfo = findBidInfo(lotID);
	return bidInfo[3];
}

function getExtraMessage(lotID) {
	var bidInfo = findBidInfo(lotID);

	if (bidInfo[4].match("between increment")) {
		bidInfo[4] = "";
	}

	return bidInfo[4];
}

function findBidInfo(lotID) {
	var bidInfoMatch = [null, null, null, null, null];
	for (var i = 0; i < currentBids.length; i++) {
		var bidInfo = currentBids[i].split(DELIMITER);
		if (bidInfo[0] == lotID) {
			bidInfoMatch = bidInfo;
			break
		}
	}
	return bidInfoMatch;
}

function removeBidInfo(lotID) {
	var bidInfoIndex;
	for (var i = 0; i < currentBids.length; i++) {
		var bidInfo = currentBids[i].split(DELIMITER);
		if (bidInfo[0] == lotID) {
			currentBids.splice(i, 1);
		}
	}

}

function ccCallBack(callAG) {
	ccCallBackInner(callAG, UpdateConfirmDialogMessage);
}

function ccCallBackInner(callAG, cbFunction) {

	var bRequireCC = $j("#AuctionReqCC").value;
	var sPaymentMessage = "";
	var bDisableConfirmBtn = false;

	var status = cc.ccStatusCode;
	var reason = cc.ccReasonCode;
	var depositMode = cc.bDepositMode;

	//status = 3
	//reason = 0

	function cbUpdateStatus() {
		updateApprovalStatusMsg(true);
	}
	
	if (status == 1 || status == 4) {
		$j("#ConfirmCCID").val(cc.ccID);
		$j("#ConfirmCCLastFour").val(cc.lastFour);
		$j("#ConfirmCCTypeName").val(cc.ccTypeName);
		$j("#ConfirmCCToken").val(cc.ccPaymentToken);
		
		function agCheck(){
			if(callAG) {
				getAuctionGuardScore( 0, callBack, false, "Cancel");
			}
		}
		
		if(depositMode){
			showCardAddMessage("Your deposit was accepted, and you are now approved to bid!", agCheck);
		}
		else{
			agCheck();
		}
		
	} else if(  status == 2){
		//there was an error adding the card
		showCardAddMessage("Your credit card could not be added successfully. Please try the card again or add a different card. Click OK to continue.");
	} else if(  status == 3){
		//card was not added look at reason for why
		if(reason == 0){
			//failed but don't know why
			showCardAddMessage("Currently we can not add your credit card. Please contact Proxibid if you have any questions.", cbUpdateStatus);
			return false;
		} else if(reason== 1){
			//I'm sorry but you are trying to much, please contact proxi
			showCardAddMessage("You have exceeded the maximum number of attempts to add or select a credit card. Please contact Proxibid Customer Support at 877-505-7770 with any questions.", cbUpdateStatus);
			return false;
		} else if(reason == 2){
			//I guess you don't want to bid since you canceled
			cbUpdateStatus();	//TODO: does this line need to be here?
		} else if(reason == 3){
			//CC vendor down
			showCardAddMessage('We are unable to process credit cards at this time. Please contact Proxibid Customer Support at 877.505.7770 for further assistance.', cbUpdateStatus);
		} else {
			showCardAddMessage("Currently we can not add your credit card. Please contact Proxibid if you have any questions.", cbUpdateStatus);
			return false;
		}
	} else if( status == 5){
		showCardAddMessage('Your credit card was declined while processing your deposit. If you would like to supply a deposit with a different credit card please try again.', cbUpdateStatus);
	} else {
		//uh-oh this shouldn't happen
	}
	
	cbFunction();
}

function showCardAddMessage(message, cb){
	var myButtons;
	
	myButtons = [
		{ text: "Okay", click: function(){
				jQuery( "#notificationDialog" ).dialog( "close" );
				if(cb) {
					cb();
				}
			} }
	];


	jQuery( "#notificationDialog" ).dialog({
	autoOpen: false,
	height: 150,
	width: 500,
	modal: true,
	resizable: false,
	draggable: false,
	closeOnEscape: false,
	open: function() {
			jQuery(this).parents(".ui-dialog:first").find(".ui-dialog-titlebar-close").remove(); 
	},
	buttons: myButtons

	});
	//asp/LoginBidder.asp?m=multi&" & Server.URLEncode("d=Catalog.asp?mb=0&multi=1&mbv=f" & embedParams ))
	var injectedHTML = message;
	
	document.getElementById("notificationDialog").innerHTML=
			'<center>' + injectedHTML + '</center>';
	jQuery( "#notificationDialog" ).dialog( "open" );

}
// END - PLACE BID CODE ****************************************************************

// to hide and show other announcements.

function showMore() {
	document.getElementById('otherAnnouncementsMore').style.display = 'none';
	document.getElementById('otherAnnouncementsArea').style.display = 'block';
	document.getElementById('otherAnnouncementsLess').style.display = 'block';
};

function showLess() {
	document.getElementById('otherAnnouncementsMore').style.display = 'block';
	document.getElementById('otherAnnouncementsArea').style.display = 'none';
	document.getElementById('otherAnnouncementsLess').style.display = 'none';
};

function disableLink(e) {
    // cancels the event
    e.preventDefault();

    return false;
}

// For dynamic lot ordering baseed on lots closing or going into extended bidding.

function displayClosedLots() {
	jQuery('#divClosedLots').toggle();
	if (jQuery('#divClosedLots').css('display') == 'none') {
		jQuery('#closedLotsArea').text('Show Closed Lots');
	} else {
		jQuery('#closedLotsArea').text('Closed Lots');
	}
}

