var globalImageStr = "";
//var mySuffix = "";
var linkFound = 0;
var findLinkStr = "ViewItem";
var findStr = "item=";
var findOurString = "xclick-auction";
var thisItemNumber = "";
var countLeaveFeedbackShow = 0;
var countBetterSeller = 0;
var countListItemForSaleShow = 0;
var countPoundReserve = 0;
var countMotorsLinks = 0;
var auctionIsClosed = "";
var auctionHasBids = "";
var auctionClosedMotors = "";
var auctionIsReserve = "";
var auctionIsMotors = "";
var whichLogo = "";
var imgString1 = "\<IMG SRC=\"http:\/\/images.paypal.com\/images\/lgo\/";
var imgString2 = "\" BORDER=0 ALT=";
var imgStringsArray = new Array(
																"",
																"\"Click here to pay with PayPal!\"\>",
																"\"I prefer PayPal, the #1 payment service in online auctions!\"\>",
																"\"Winning bidder, click here to pay with PayPal!\"\>"
																);


function CheckAuctionStatus() {

		if (countLeaveFeedbackShow > 0) {
			return true;
		} else {
			return false;
		}

}

function CheckAuctionBids () {

		if (countLeaveFeedbackShow > 2) {
			return true;
		} else {
			return false;
		}

}

function CheckAuctionClosedMotors () {

		if ((countBetterSeller > 0) || (countListItemForSaleShow > 0)) {
			return true;
		} else {
			return false;
		}

}

function CheckAuctionIsMotors () {

		if (countMotorsLinks > 0) {
			return true;
		} else {
			return false;
		}

}

function CheckAuctionIsReserve () {

		if (countPoundReserve > 0) {
			return true;
		} else {
			return false;
		}

}

function GetOldVars() {
		for(i=0; i<document.links.length; i++) {
				if((document.links[i].search).indexOf("LeaveFeedbackShow") >= 0) {
						countLeaveFeedbackShow++;
				} else if((document.links[i].search).indexOf("BetterSeller") >= 0) {
						countBetterSeller++;
				} else if((document.links[i].search).indexOf("ListItemForSaleShow") >= 0) {
						countListItemForSaleShow++;
				} else if((document.links[i].search).indexOf("ListItemForSaleAutosShow") >= 0) {
						countListItemForSaleShow++;
				} else if((document.links[i].hash).indexOf("reserve") >= 0) {
						countPoundReserve++;
				} else if((document.links[i].pathname).indexOf("motors") >= 0) {
						countMotorsLinks++;
				}
		}
}

function GetItemNumber() {
		for (i=0; i<document.links.length; i++) {
				if (document.links[i].search.indexOf(findLinkStr) > 0) {
						if (linkFound == 0) {
								var linkStr = document.links[i].search;
								var idx = linkStr.indexOf(findStr);
								if (idx > 0) {
										linkStr = linkStr.slice((idx + (findStr.length)));
										for (k=0; k < (linkStr.length); k++) {
												if(isNaN(linkStr.charAt(k))) {
														idx = k;
														break;
												}
										}
								}
								linkStr = linkStr.slice(0,idx);
								thisItemNumber = linkStr;
								linkFound = 1;
								break;
						}
				}
		}
}

function RewriteLink() {
		if (linkFound) {
				for (i=0; i < (document.links.length); i++) {
						if ((document.links[i].pathname.indexOf(findOurString)) >= 0) {
								document.links[i].href = ((document.links[i].href) + "&jitem_id=" + thisItemNumber + "&jmagic=1");
						}
				}
		}
}

function DrawLogo() {
		whichLogo = 2;

		auctionIsMotors = CheckAuctionIsMotors();
		if (auctionIsMotors) {
				auctionClosedMotors = CheckAuctionClosedMotors();
				if (auctionClosedMotors) {
						auctionIsReserve = CheckAuctionIsReserve();
						if (auctionIsReserve) {
								// is reserve, put in reserve checks later
								whichLogo = 2;
						} else {
								// is closed, and not reserve, show pay
								whichLogo = 3;
						}
				} else {
						whichLogo = 2;
				}
		} else {
				auctionIsClosed = CheckAuctionStatus();
				if (auctionIsClosed) {
						auctionHasBids = CheckAuctionBids();
						if (auctionHasBids) {
								auctionIsReserve = CheckAuctionIsReserve();
								if (auctionIsReserve) {
										whichLogo = 2;
								} else {
										whichLogo = 3;
								}
						} else {
								whichLogo = 2;
						}
				} else {
						whichLogo = 2;
				}
		}
		
		WriteLogo(whichLogo);
}

function WriteLogo(whichLogo) {
		globalImageStr = imgString1 + "ppsl" + mySuffix + whichLogo + ".gif" + imgString2 + imgStringsArray[whichLogo];
}

GetOldVars();
GetItemNumber();
RewriteLink();
DrawLogo();
document.write(globalImageStr);

