var repAddClientM = 100, sendAddBidderM = 120, repAddBidderM = 130,
sendSoundM = 200, repSoundM = 210,
sendAddBidLimitM = 300, sendRemBidLimitM = 310, sendChangeBidLimitM = 320,
sendManyBidLimitM = 325, repBidLimitM = 330, bidComingM = 350,
connectM = 400, repConnectM = 410, sendFavM = 540, repFavM = 550,
sendRemindM = 560, repRemindM = 570, sendShowLotM = 470, refreshLotM = 480,
fixedLotM = 1110, bidListM = 1200, loggedOutM = 1300,
soldM = 1500, beepM = 2010, goingM = 2100, announceM = 2110,
currentLotM = 2120, currentLadderM = 2130, fixedLadderM = 2140,
speexM = 2410, superSpeexM = 2420;
var webSocket, auctionPort = 0, clientNumS = 0, lastReceive = 0, myPaddleS = "";
var loggedOnS = false, savedPos = 0, currentLotNumC = ""; hiddenLoginS = false;
var regularThread = 0, backThread = 0, keyHashS, lastLocS = "";
var audioCtx, noAudioS = false, codec, playerActive = false, speexMessNum = 0, lastSample = 0, downThread;
var sampleSize = 0, sampleRate = 0, lastStart = 0, lastClick = -10000;
var isIOS = false, connectMess = null, connectNum = -1, conWord = 0,
lastLengthS = 0, isConnectedS = false;
function gebi(val) {
return document.getElementById(val);
}
function showConnectingS() {
document.getElementById("connectconnect").style.display = "none";
clearInterval(connectInterval);
document.getElementById("connecting").style.display = "block";
}
function animateConnectingS() {
gebi("con1").style.color = (conWord === 0) ? "black" : "gray";
gebi("con2").style.color = (conWord === 1) ? "black" : "gray";
gebi("con3").style.color = (conWord === 2) ? "black" : "gray";
gebi("con4").style.color = (conWord === 3) ? "black" : "gray";
conWord = (conWord < 3) ? conWord + 1 : 0;
}
function openSocketS(aPort){
isIOS = navigator.userAgent.match(/iPad/i) || navigator.userAgent.match(/iPhone/i);
auctionPort = aPort;
gebi("mainladder").style.backgroundColor = "rgb(180,180,180)";
if(webSocket !== undefined && webSocket.readyState !== webSocket.CLOSED){
setStatusC("WebSocket is already opened.");
return;
}
if (typeof AudioContext !== 'undefined')
audioCtx = new AudioContext();
else if (typeof webkitAudioContext !== 'undefined')
audioCtx = new webkitAudioContext();
else {
noAudioS = true;
}
var soundStr = (phoneVersion || noAudioS) ? "off" : "on";
webSocket = new WebSocket("wss://" + serverAddress + ":8443/echoWebsocket/echo?port=" + aPort + "&sound=" + soundStr);
if (!phoneVersion)
startSoundS();
webSocket.onopen = function(event){
lastReceive = new Date().getTime();
if(event.data === undefined) 
return;
};
webSocket.onmessage = function(event){
lastReceive = new Date().getTime();
var inPack = new recPack(event.data);
var packType = inPack.packetType;
if (packType === beepM) {
var sendMess = new sendPack(beepM);
putNum(sendMess, 1, 0);
webSocket.send(retMessage(sendMess, 0, clientNumS, keyHashS));
}
else if (packType === repAddClientM) {
keyHashS = retKey(event.data);
repAddClient(inPack);
}
else if (packType === repConnectM) {
connectRec(inPack);
}
else if (packType === repAddBidderM) 
addBidderRec(inPack);
else if (packType === speexM) 
speexRecS(inPack);
else if (packType === superSpeexM) {
speexRecS(inPack);
setStatusC("Super Speex " + getNum(inPack, 1));
}
else if (packType === repBidLimitM
|| packType === bidListM) 
bidMessageC(inPack);
else if (packType === currentLotM) {
if (inPackC === null) {
inPackC = inPack;
currentLotRecC();
}
else {
inPackC = inPack;
setTimeout(currentLotRecC, 1500);
}
}
else if (packType === fixedLotM) 
fixedLotRecC(inPack);
else if (packType === currentLadderM) 
currentLadderRecL(inPack);
else if (packType === fixedLadderM) 
fixedLadderRecL(inPack);
else if (packType === announceM) 
announceRecC(inPack);
else if (packType === goingM) 
goingRecC(inPack);
else if (packType === soldM) 
soldRecC(inPack);
else if (packType === loggedOutM) 
logout();
else if (packType === repSoundM) 
repSoundS(inPack);
};
 
webSocket.onclose = function(event){
setStatusC("Connection closed.");
gebi("lotnumdiv").innerHTML = "Connection closed.";
gebi("mainladder").style.backgroundColor = "rgb(180,180,180)";
};
}
function regularJobs() {
var millis = new Date().getTime();
if (millis > lastReceive + 65000) {
showMessageC("Connection Problem.", "No messages have", "been received",
"for one minute.", "You may be disconnected.");
}
if (millis > lastReceive + 650000) {
lostFocus = true;
closeDown();
}
if ((millis/5000)%6 < 1) {
var sendMess = new sendPack(beepM);
putNum(sendMess, 1, 0);
webSocket.send(retMessage(sendMess, 0, clientNumS, keyHashS));
}
}
function gotoJobs() {
var lastLocation = lastLocS.search(/#lot/);
var thisLocation = window.location.href.search(/#lot/);
if (lastLocation > 0 && thisLocation <= 0) {
if (window.history.length <= lastLengthS)
picInCatC();
}
lastLocS = window.location.href;
lastLengthS = window.history.length;
}
function closeSocket(){
clearInterval(regularThread);
clearInterval(backThread);
webSocket.close();
}
function reconnect() {
if (!isConnectedS) {
webSocket.send(connectMess);
}
}
function getCookie(cookieName) {
var cookies = document.cookie.split(';');
for(var count = 0; count < cookies.length; count++) {
var c = cookies[count];
while (c.charAt(0) === ' ') {
c = c.substring(1);
}
if (c.indexOf(cookieName + "=") === 0) 
return c.substring(cookieName.length+1, c.length);
}
return "";
}
function showLoginS() {
savedPos = window.pageYOffset;
var makeLogon = false;
gebi("showlog2").style.fontWeight = "normal";
if (phoneVersion)
makeLogon = (gebi("showlog1").value !== "Logout");
else
makeLogon = (gebi("showlog2").value !== "Logout");
if (makeLogon) {
gebi("cattable").style.display = 'none';
gebi("mainclient").style.display = 'none';
if (phoneVersion) 
gebi("topbuttons").style.display = 'none';
else
gebi("biglogo").style.display = 'none';
gebi("logindiv").style.display = 'block';
gebi("logOnPanel").style.display = 'block';
gebi("regpanel").style.display = 'block';
gebi("logonfail").style.display = 'none';
gebi("logongood").style.display = 'none';
gebi("fixedcanvas").style.display = 'none';
if (phoneVersion)
gebi("phonefixedbuttons").style.display = 'none';
else
gebi("bigfixedbuttons").style.display = 'none';
window.scrollTo(0, 0);
if (gebi("emailinput").value.trim() === "") {
var emailAddr = getCookie("ibidemailaddr");
if (emailAddr !== "")
gebi("emailinput").value = emailAddr;
}
}
else {
var logoutDate = new Date();
logoutDate.setTime(logoutDate.getTime() - 10800000);
document.cookie = "ibidloadnumber=; expires=" + logoutDate.toUTCString() + "; path=/;";
logout();
}
}
function loginS(){
gebi("logonfail").style.display = 'none';
var today = new Date();
var sendMess = new sendPack(sendAddBidderM);
putNum(sendMess, 1, today.getTime() % 4294967296);
putNum(sendMess, 2, 1);
putString(sendMess, 1, gebi("passwordinput").value);
putString(sendMess, 2, gebi("emailinput").value.trim());
webSocket.send(retMessage(sendMess, repAddBidderM, clientNumS, keyHashS));
}
function enterLoginS(evt) {
if (evt.keyCode === 13) {
loginS();
}
}
function repAddClient(inPack) {
clientNumS = getNum(inPack, 1);
if (getString(inPack, 1) !== "" && getString(inPack, 1) !== auctionID)
closeSocket();
var dotPos = window.location.href.search(".html");
var endPart = window.location.href.substring(dotPos);
var endPos = window.location.href.search("/client");
var loadURL = window.location.href.substring(0, endPos+7) + getNum(inPack, 45) + endPart;
if (parseInt(programVersion) !== getNum(inPack, 45))
window.open(loadURL, "_self");
OKClickedC();
if (connectNum === -1)
connectNum = Math.floor((Math.random() * 10000) + 1);
var sendMess = new sendPack(connectM);
putNum(sendMess, 1, connectNum);
connectMess = retMessage(sendMess, repConnectM, clientNumS, keyHashS);
webSocket.send(connectMess);
setTimeout(reconnect, 3000);
setTimeout(reconnect, 10000);
setTimeout(reconnect, 20000);
}
function connectRec(inPack) {
if (connectNum === getNum(inPack, 1)) {
isConnectedS = true;
clearTimeout(connectThread);
clearInterval(connectInterval);
gebi("connectconnect").style.display = "none";
gebi("connecting").style.display = "none";
setupScreenL();
gebi("mainladder").style.backgroundColor = "white";
redrawLadderL();
regularThread = setInterval(regularJobs, 5000);
if (stepBack)
backThread = setInterval(gotoJobs, 500);
var destLot = window.location.href.search(/#lot/);
if (destLot > 0) 
gotoLotC(window.location.href.substring(destLot+4));
var emailAddr = getCookie("ibidemailaddr");
if (emailAddr !== "")
gebi("emailinput").value = emailAddr;
var password = getCookie("ibidloadnumber");
if (password !== "") {
gebi("passwordinput").value = password;
hiddenLoginS = true;
loginS();
}
}
}
function addBidderRec(inPack) {
loggedOnS = getNum(inPack, 1) === messageOK;
var mgsValues = getString(inPack, 7);
var userAccountExists = mgsValues.charAt(0) === 'T';
var passwordSuccess = mgsValues.charAt(1) === 'T';
var contactDetailsEntered = mgsValues.charAt(2) === 'T';
if (loggedOnS) {
myPaddleS = getString(inPack, 1);
gebi("paddleID").innerHTML = "You are bidder " + myPaddleS + ".";
gebi("paddleNum").innerHTML = "You are bidder " + myPaddleS;
gebi("paddleNum").style.backgroundColor = "rgb(180,180,240)"; //Deep Blue
var purchaseLimit = getNum(inPack, 2);
if (purchaseLimit > 0) {
gebi("limittext").innerHTML = "The most you can purchase at this auction<br>is "
+ writeCash(purchaseLimit * unitCash) + " worth of goods.";
if (houseName === "abbeys")
gebi("limittext").innerHTML += "<br><br>The buyers premium for this auction is "
+ (Math.floor(buyersPremium/100)) + '.' + (Math.floor(buyersPremium%100)/10) + (buyersPremium%10) + '%';
}
else if (purchaseLimit === -9)
gebi("limittext").innerHTML = "Your purchase limit at this auction<br>is unlimited.";
gebi("regpanel").style.display = "none";
gebi("logonfail").style.display = "none";
gebi("logOnPanel").style.display = "none";
gebi("showlog2").style.fontWeight = "normal";
if (phoneVersion)
gebi("showlog1").value = "Logout";
else
gebi("showlog2").value = "Logout";
unpackAllB(getBytes(inPack, 5), getBytes(inPack, 6));
setBackgroundsB();
if (getString(inPack, 3) === showLotNumC)
myLimitL = getNum(inPack, 4) * unitCash;
if (getString(inPack, 3) === currentLotNumC)
currLimitPriceC = getNum(inPack, 4) * unitCash;
redrawLadderL();
if (getString(inPack, 3) === currentLotNumC && currentLotNumC.length > 0)
gebi("mainladder").style.backgroundColor = "rgb(210,230,255)"; //Skye Blue
if (purchaseLimits && !hiddenLoginS)
gebi("logongood").style.display = "block";
else
closeClickedS();
var expiryDate = new Date();
if (gebi("rememberbox").checked)
expiryDate.setTime(expiryDate.getTime() + 40 * 86400000);
else
expiryDate.setTime(expiryDate.getTime() - 40 * 86400000);
document.cookie = "ibidemailaddr=" + gebi("emailinput").value.trim()
+ "; expires=" + expiryDate.toUTCString() + "; path=/";
var logoutDate = new Date();
if (gebi("staybox").checked)
logoutDate.setTime(logoutDate.getTime() + 14400000);
else
logoutDate.setTime(logoutDate.getTime() - 14400000);
document.cookie = "ibidloadnumber=" + gebi("passwordinput").value.trim()
+ "; expires=" + logoutDate.toUTCString() + "; path=/";
}
else {
if (getNum(inPack, 1) === nameError) {
if (houseName === "arooms") {
gebi("logonfail").innerHTML = '<br>Error in email address or password.<br>'
+ 'Please try again.<br>';
}
else {
gebi("logonfail").innerHTML = '<br>Email address not found.<br>'
+ 'Please try again.<br>';
gebi("emailinput").select();
}
}
else if (houseName === "rosss" && getNum(inPack, 1) === errorCreditCard) {
gebi("logonfail").innerHTML = '<br>Please go to <a href="https://www.auctions.com.au/">'
+ 'Rosss</a> and upgrade<br>your membership to premium.<br>';
}
else if (houseName === "rosss") {
gebi("logonfail").innerHTML = '<br>Error in email address or password.<br>'
+ 'Please try again.<br>';
}
else {
gebi("logonfail").innerHTML = '<br>Email address found but incorrect password.<br>'
+ 'Please try again.<br>';
gebi("passwordinput").select();
}
gebi("logonfail").style.display = "block";
if (houseName === "mgs" && userAccountExists && passwordSuccess) {
if (contactDetailsEntered)
gebi("logonfail").innerHTML = '<br>Please login at <a href="https://www.mgs.net.au">'
+ 'www.mgs.net.au</a> and supply<br>your credit card details.<br>';
else
gebi("logonfail").innerHTML = '<br>Please login at <a href="https://www.mgs.net.au">'
+ 'www.mgs.net.au</a> and supply<br>your contact details.<br>';
}
}
}
function closeClickedS() {
gebi("logindiv").style.display = 'none';
if (phoneVersion)
gebi("topbuttons").style.display = 'block';
else
gebi("biglogo").style.display = 'block';
gebi("mainclient").style.display = 'block';
if (!fixedLotModeC || phoneVersion) 
gebi("cattable").style.display = 'block';
if (!phoneVersion && fixedLotModeC)
showFixedC(showLotIndexC);
window.scrollTo(0, savedPos);
}
function logout() {
loggedOnS = false;
myLimitL = 0;
currLimitPriceC = 0;
confirmingBidL = false;
limitListAddrS = "notLoggedIn";
myPaddleS = "";
redrawLadderL();
gebi("passwordinput").value = "";
setStatusC("You are logged off.");
gebi("mainladder").style.backgroundColor = "white";
gebi("paddleID").innerHTML = "Not logged on.";
gebi("paddleNum").innerHTML = "Not logged on.";
gebi("paddleNum").style.backgroundColor = "white";
gebi("logOnPanel").style.display = "block";
gebi("showlog2").style.fontWeight = "bold";
if (phoneVersion)
gebi("showlog1").value = "Login";
else
gebi("showlog2").value = "Bidder Login";
setBackgroundsB();
}
function closeDown() {
if (lostFocus) {
if (loggedOnS && webSocket.readyState !== webSocket.CLOSED)
logout();
setStatusC("Connection closed!");
gebi("lotnumdiv").innerHTML = "Connection closed!";
gebi("mainladder").style.backgroundColor = "rgb(180,180,180)";
closeSocket();
}
}
function reloadSocketS() {
if (webSocket === undefined || webSocket.readyState === webSocket.CLOSED) {
openSocketS(auctionPort);
if (!phoneVersion)
fastIndexC();
setBackgroundsB();
clearTimeout(downThread);
}
}
function windDownS() {
var switchOn = false;
if (phoneVersion)
switchOn = gebi("audioBox1").checked;
else
switchOn = gebi("audioBox2").checked;
if (!switchOn) 
soundOnS();
downThread = setTimeout(closeDown, 240000);
}
function startSoundS() {
if (noAudioS || isIOS) {
return;
}
gebi("audiobox2").checked = true;
sourceStartS();
}
function sourceStartS() {
sampleRate = audioCtx.sampleRate;
if (safeSound)
sampleSize = audioCtx.sampleRate / 2;
else
sampleSize = audioCtx.sampleRate / 5;
var buffer;
buffer = audioCtx.createBuffer(1, sampleSize, sampleRate);
var source = audioCtx.createBufferSource();
source.buffer = buffer;
source.connect(audioCtx.destination);
if (source.start)
source.start(0); 
else if (source.play)
source.play(0); 
else if (source.noteOn)
source.noteOn(0); 
}
function audioOnS() {
if (noAudioS) {
alert("Sorry this browser does not support sound.");
return;
}
var switchOn = false;
if (phoneVersion)
switchOn = gebi("audiobox1").checked;
else
switchOn = gebi("audiobox2").checked;
if (switchOn) 
sourceStartS();
var sendMess = new sendPack(sendSoundM);
putNum(sendMess, 1, (switchOn ? 1 : 0));
putNum(sendMess, 2, 0);
webSocket.send(retMessage(sendMess, repSoundM, clientNumS, keyHashS));
}
function repSoundS(inPack) {
if (getNum(inPack, 3) !== 0 && getNum(inPack, 1) !== 0) {
showMessageC("  ", "Due to maximum", "connections,", "sound is", "unavailable.");
}
}
function speexRecS(inPack) {
if (typeof Speex === 'undefined')
return;
if (audioCtx === undefined || audioCtx === null)
return;
var messNum = getNum(inPack, 1);
if (messNum < 0 || messNum > speexMessNum || messNum < speexMessNum-100) {
if (!playerActive) {
playerActive = true;
codec = new Speex({ quality: 2 });
}
speexMessNum = messNum;
var soundString = getString(inPack, 1);
if (soundString && soundString.length > 0) {
var newBytes = new Uint8Array(Speex.util.str2ab(soundString));
var inBuffer = codec.decode(newBytes);
var myBuffer;
myBuffer = audioCtx.createBuffer(1, sampleSize, sampleRate);
linInterp(inBuffer, myBuffer.getChannelData(0), sampleSize);
var nowTime = audioCtx.currentTime;
var playTime = nowTime;
if (safeSound) {
if (nowTime > lastStart + 0.5) 
lastClick = nowTime;
else 
playTime = lastStart + 0.5;
}
else {
if (nowTime > lastStart + 0.2) 
lastClick = nowTime;
else 
playTime = lastStart + 0.2;
}
var source = audioCtx.createBufferSource();
source.buffer = myBuffer;
source.connect(audioCtx.destination);
if (!dropPacket(messNum, nowTime)) {
lastStart = playTime;
if (source.start)
source.start(playTime); 
else if (source.play)
source.play(playTime); 
else if (source.noteOn)
source.noteOn(playTime); 
}
}
}
}
function dropPacket(messNum, nowTime) {
var result = false;
var dropTime = 0.4;
var messageTime = 0.2;
if (safeSound) {
dropTime = 0.5;
messageTime = 0.5;
}
if (nowTime < lastStart - dropTime) {
lastClick = nowTime - 130;
result = true;
}
else if (messNum === -1 && nowTime > lastClick + 130 && nowTime < lastStart - messageTime)
result = true;
return result;
}
function linInterp(inClip, outClip, bufferSize) {
var lastIndex = -1;
var messageSize;
if (safeSound)
messageSize = 4000;
else
messageSize = 1600;
for (var count = 0; count < messageSize; count++) {
var directIndex = Math.round((((count+1) * bufferSize) / messageSize) - 1);
var diff = inClip[count] - lastSample;
var numSteps = directIndex - lastIndex;
for (var step = numSteps-1; step >= 0; step--) {
outClip[directIndex - step] = inClip[count] - (diff * step) / numSteps;
}
lastIndex = directIndex;
lastSample = inClip[count];
}
}
var twoToTheThirty = Math.pow(2, 30);
function writeCash(cents, inc) {
inc = inc === undefined ? 1 : inc;
var negSign = cents < 0 ? "-" : "";
var num = cents, count = 0, result = "";
while (count < 3 || num > 0) {
if (count === 2) 
result = cents%100 === 0 ? "" : "." + result;
if (count === 5) 
result = (cents%100000 === 0 && inc >= 1000000) ? "k" : "," + result;
if (count === 8) 
result = "," + result;
result = num%10 + result;
num = Math.floor(num/10);
count++;
}
return "$" + negSign + result;
}
function readCash(cashString) {
var cashSt = cashString.trim();
if (cashSt.length === 0)
return 0;
var num = parseFloat(cashSt.replace(/[^0-9-.]/g, ''));
if (isNaN(num)) 
return num;
if (cashSt.charAt(cashSt.length-1) === 'k')
return Math.round(100000 * num);
else
return Math.round(100 * num);
}
 
function getInc(pri) {
var result = 1;
if (pri < first25) 
result = pri < first10 ? (pri<first5?50:100) : (pri<first20?200:250);
else if (pri < second25) 
result = pri < second10 ? (pri<second5?500:1000) : (pri<second20?2000:2500);
else {
var power = 1;
while (pri >= other25) {
pri /= 10; power *= 10;
}
result = pri < other10 ? (pri<other5?5000:10000) : (pri<other20?20000:25000);
result *= power;
}
return result > initLiveIncs ? result : initLiveIncs;
}
 
function doTwoEight(pri, inc) {
if ((inc.toString().search(/250*$/) >= 0) && (twoEight || inc === 250)) {
if (pri % (4*inc) === inc)
return pri - (Math.floor(inc/5));
else if (pri % (4*inc) === 3*inc)
return pri + (Math.floor(inc/5));
}
return pri;
}
 
function unTwoEight(pri, inc) {
if ((inc.toString().search(/250*$/) >= 0) && (twoEight || inc === 250)) {
var fifthInc = Math.floor(inc/5);
if (pri % (4*inc) === inc - fifthInc)
return 1*pri + fifthInc;
else if (pri % (4*inc) === 3*inc + fifthInc)
return 1*pri - fifthInc;
}
return pri;
}
 
function incPrice(pri, firstInc, fixedIncs, steps) {
firstInc = firstInc || getInc(pri);
var inc = fixedIncs ? getInc(pri) : firstInc;
steps = steps || 1;
return doTwoEight(unTwoEight(pri, inc) + steps*inc, inc);
}
function retShort(dataBytes, pos) {
var result = dataBytes.charCodeAt(pos);
if (dataBytes.charCodeAt(pos) >= 128)
result -= 128;
result = 256 * result + dataBytes.charCodeAt(pos+1);
return (dataBytes.charCodeAt(pos) >= 128) ? -result : result;
}
function retNum(dataBytes, pos){
var result = dataBytes.charCodeAt(pos);
if (dataBytes.charCodeAt(pos) >= 128)
result -= 128;
for (var count = 1; count < 4; count++) {
result = 256 * result + dataBytes.charCodeAt(pos+count);
}
return (dataBytes.charCodeAt(pos) >= 128) ? -result : result;
}
function retKey(packString) {
var packData = atob(packString);
return packData.substring(packData.length - 16, packData.length);
}
function recPack(packString) {
var packData = atob(packString);
this.packetType = retShort(packData, 0);
this.numIntegers = retShort(packData, 2);
this.numStrings = retShort(packData, 4);
this.intArray = new Array(this.numIntegers);
for (var iCount = 0; iCount < this.numIntegers; iCount++) {
this.intArray[iCount] = retNum(packData, 4*iCount+6);
}
this.stringArray = new Array(this.numStrings);
var lengthStart = 4 * this.numIntegers + 6;
var stringStart = lengthStart + 2*this.numStrings;
for (var sCount = 0; sCount < this.numStrings; sCount++) {
var currentLength = retShort(packData, lengthStart + 2*sCount);
if (currentLength > 0) {
this.stringArray[sCount] = packData.substring(stringStart, stringStart + currentLength);
stringStart += currentLength;
}
else if (currentLength === 0)
this.stringArray[sCount] = "";
else
this.stringArray[sCount] = null;
}
}
 
function getNum(pack, pos) {
if (!pack || pos <= 0 || pos > pack.numIntegers || pack.intArray === null)
return null;
else
return pack.intArray[pos-1];
}
 
function getLong(pack, pos) {
if (!pack || pos <= 0 || pos > pack.numIntegers || pack.intArray === null)
return null;
else
return pack.intArray[pos-1] * twoToTheThirty + pack.intArray[pos];
}
 
function getString(pack, pos) {
if (!pack || pos <= 0 || pos > pack.numStrings || pack.stringArray === null)
return null;
else
return pack.stringArray[pos-1];
}
function getBytes(pack, pos) {
if (!pack || pos <= 0 || pos > pack.numStrings || pack.stringArray === null)
return null;
else {
var byteString = pack.stringArray[pos-1];
var bufView = new Int8Array(byteString.length);
for (var count = 0; count < byteString.length; count++) {
bufView[count] = byteString.charCodeAt(count);
}
return bufView;
}
}
function sendPack(packType) {
this.packetType = packType;
this.numIntegers = 0;
this.numStrings = 0;
this.intArray = new Array(10);
this.stringArray = new Array(20);
}
 
function putNum(pack, thisPos, thisNum) {
if (thisPos > pack.numIntegers)
pack.numIntegers = thisPos;
if (typeof thisNum === 'string') 
alert("String found needed Number>" + thisNum + "<");
else
pack.intArray[thisPos-1] = thisNum;
}
 
function putLong(pack, thisPos, thisNum) {
putNum(pack, thisPos, thisNum / twoToTheThirty);
putNum(pack, thisPos+1, thisNum % twoToTheThirty);
}
 
function putString(pack, thisPos, thisString) {
if (thisPos > pack.numStrings)
pack.numStrings = thisPos;
if (typeof thisString === 'number') 
alert("Number found needed String>" + thisString + "<");
else 
pack.stringArray[thisPos-1] = thisString;
}
function putBytes(pack, thisPos, theseBytes) {
if (thisPos > pack.numStrings)
pack.numStrings = thisPos;
var result = "";
for (var count = 0; count < theseBytes.length; count++) {
result += String.fromCharCode(theseBytes[count]);
}
pack.stringArray[thisPos-1] = result;
}
 
function makeShort(num) {
var thisNum = num;
if (num === null || isNaN(num))
thisNum = 0;
var isNeg = thisNum < 0;
if (isNeg)
thisNum = -thisNum;
var firstByte = Math.floor(thisNum / 256);
if (isNeg)
firstByte += 128;
return String.fromCharCode(firstByte, (thisNum % 256));
}
 
function makeNum(num) {
var thisNum = num, result = "";
if (num === null || isNaN(num))
thisNum = 0;
var isNeg = thisNum < 0;
if (isNeg)
thisNum = -thisNum;
for(var thisCount = 1; thisCount < 4; thisCount++) {
result = String.fromCharCode(thisNum % 256) + result;
thisNum = Math.floor(thisNum / 256);
}
if (isNeg)
thisNum += 128;
return String.fromCharCode(thisNum) + result;
}
function retMessage(pack, repType, clientNum, keyHash) {
var data = makeShort(pack.packetType) + makeShort(repType);
data = data + makeNum(clientNum);
data = data + makeShort(pack.numIntegers);
data = data + makeShort(pack.numStrings);
for (var count = 0; count < pack.numIntegers; count++) {
data = data + makeNum(pack.intArray[count]);
}
for (var stringNum = 0; stringNum < pack.numStrings; stringNum++) {
if (pack.stringArray[stringNum] === undefined || pack.stringArray[stringNum] === null)
data = data + makeShort(-1);
else
data = data + makeShort(pack.stringArray[stringNum].length);
}
for (var strNum = 0; strNum < pack.numStrings; strNum++) {
if (pack.stringArray[strNum] !== null) 
data = data + pack.stringArray[strNum];
}
return btoa(data + keyHash);
}
var zeroOne = 0, zeroTwo = 1, oneTwo = 2, twoTwo = 3, zeroThree = 4, twoThree = 5,
statusArray, topArray, biddersArray, favourites, reminders, numBytes, 
adviceArrayB, neededArrayB, borderArrayB,
frameWidth = 90, hadCrash = false, hammersDown = 0,
searchString = "", foundIndex = 0, foundPos = 0, foundSpan = "";
var alerts = 0;
function goneAnimationB() {
if (hammersDown === 0)
goGavelsB(zeroThree, zeroThree);
else if (hammersDown === 1 || hammersDown === 2)
goGavelsB(twoThree, zeroThree);
else if (hammersDown === 3)
goGavelsB(-1, zeroThree);
hammersDown = 0;
}
function upHammersB() {
if (hammersDown !== 0) {
if (hammersDown === 1)
goGavelsB(-1, zeroOne);
else
goGavelsB(-1, (hammersDown === 2) ? zeroTwo : zeroThree);
hammersDown = 0;
}
}
function hammersGoingB(goings) {
if (goings === 1) {
goGavelsB((hammersDown === 0) ? zeroOne : oneTwo, -1);
hammersDown = 1;
}
else if (goings === 2 || goings === 3) {
if (hammersDown === 0)
goGavelsB(zeroTwo, -1);
else
goGavelsB((hammersDown === 1) ? oneTwo : twoTwo, -1);
hammersDown = 2;
}
}
function goGavelsB(downAnim, upAnim) {
if (phoneVersion)
return;
var elem =  gebi("animate"); 
var id, frameNum = 0;
if (downAnim >= 0) {
elem.style.left = '0px'; 
displayHam(downAnim);
id = setInterval(downHam, 40);
}
else {
elem.style.left = (-4*frameWidth) + 'px'; 
displayHam(upAnim);
frameNum = 4;
id = setInterval(upHam, 60);
}
function displayHam(numDraw) {
for (var count = 0; count < 6; count++) {
gebi("gavel" + count).style.display = numDraw === count ? "block" : "none";
}
}
function downHam() {
if (frameNum >= 5) {
clearInterval(id);
if (upAnim >= 0) {
displayHam(upAnim);
frameNum = 4;
id = setInterval(upHam, 60);
}
}
else {
elem.style.left = (-frameNum*frameWidth) + 'px'; 
frameNum++; 
}
}
function upHam() {
if (frameNum < 0) {
clearInterval(id);
}
else {
elem.style.left = (-frameNum*frameWidth) + 'px'; 
frameNum--; 
}
}
}
function remindFixedB() {
remindB(fixedLotIndexC);
}
function remindB(remIndex) {
if (!loggedOnS) 
showMessageC("  ", "You need to logon", "to get an email", "reminder before this", "lot is offered.");
else {
var addMode = !reminders[remIndex];
reminders[remIndex] = addMode;
var mess = new sendPack(sendRemindM);
putString(mess, 1, myPaddleS);
putBytes(mess, 2, packAll(false));
webSocket.send(retMessage(mess, repRemindM, clientNumS, keyHashS));
if (fixedLotModeC) {
gebi("fixedEmailOff").style.display = reminders[remIndex] ? "none" : "inline";
gebi("fixedEmailOn").style.display = reminders[remIndex] ? "inline" : "none";
}
gebi("bemail" + remIndex).style.display = addMode ? "none" : "inline";
gebi("remail" + remIndex).style.display = addMode ? "inline" : "none";
}
}
function booleansToByte(isFav, startPos, endPos) {
var result = 0;
for (var count = startPos; count <= endPos; count++) {
if (isFav)
result = 2*result + (favourites[count] ? 1 : 0);
else
result = 2*result + (reminders[count] ? 1 : 0);
}
if (result > 128)
result = 384 - result;
return result;
}
function packAll(isFav) {
numBytes = Math.floor((numLots + 7.01) / 8);
var result = new Uint8Array(numBytes);
var startPos = 0, endPos = numLots % 8 - 1;
for (var byteIndex = 0; byteIndex < numBytes; byteIndex++) {
result[byteIndex] = booleansToByte(isFav, startPos, endPos);
startPos = endPos+1;
endPos = endPos + 8;
}
return result;
}
function favourFixedB(favIndex) {
favourB(fixedLotIndexC);
}
function favourB(favIndex) {
if (!loggedOnS) 
showMessageC("  ", "You need to logon", "to be able to", "mark this lot", "as a favourite.");
else {
var addMode = !favourites[favIndex];
favourites[favIndex] = addMode;
colorBorder(favIndex);
var mess = new sendPack(sendFavM);
putString(mess, 1, myPaddleS);
putBytes(mess, 2, packAll(true));
webSocket.send(retMessage(mess, repFavM, clientNumS, keyHashS));
if (fixedLotModeC) {
gebi("fixedcanvas").style.borderColor = borderArrayB[favIndex];
gebi("fixedHeartOff").style.display = favourites[favIndex] ? "none" : "inline";
gebi("fixedHeartOn").style.display = favourites[favIndex] ? "inline" : "none";
}
else {
var viewingMine = false;
if (phoneVersion)
viewingMine = (gebi("viewbutton1").value === "All Lots");
else
viewingMine = (gebi("viewbutton2").value === "View All Lots");
if (viewingMine && !addMode)
gebi("lottable" + favIndex).style.display = "none";
}
gebi("bheart" + favIndex).style.display = addMode ? "none" : "inline";
gebi("rheart" + favIndex).style.display = addMode ? "inline" : "none";
}
}
function byteToBooleans(isFav, sentByte, startPos, endPos) {
var left = sentByte;
left = (left === -128) ? 128 : left;
left = (left < 0) ? 128 - left : left;
for (var count = endPos; count >= startPos; count--) {
if (isFav)
favourites[count] = (left % 2) === 1;
else
reminders[count] = (left % 2) === 1;
left = Math.floor((left+0.1)/2);
}
}
function unpackAllB(favBytes, remindBytes) {
favourites = new Array(numLots);
reminders = new Array(numLots);
var numBytes = favBytes.length, startPos = 0;
var endPos = numLots % 8 - 1;
for (var byteIndex = 0; byteIndex < numBytes; byteIndex++) {
byteToBooleans(true, favBytes[byteIndex], startPos, endPos);
byteToBooleans(false, remindBytes[byteIndex], startPos, endPos);
startPos = endPos + 1;
endPos = endPos + 8;
}
}
function barToSpace(thisLine) {
var result = "";
for (var count = 0; count < thisLine.length; count++) {
result += (thisLine.charAt(count) === '|') ? ' ' : thisLine.charAt(count);
}
return result;
}
 
function loadArraysB() {
statusArray = new Array(numLots),
topArray = new Array(numLots),
biddersArray = new Array(numLots);
adviceArrayB = new Array(numLots);
neededArrayB = new Array(numLots);
borderArrayB = new Array(numLots);
for (var count = 0; count < numLots; count++) {
var adviceLine = document.getElementById("advice" + count).innerHTML;
if (adviceLine === "1, , ") {
statusArray[count] = 1;
topArray[count] = " ";
biddersArray[count] = " ";
}
else {
var dataStrings = adviceLine.split(",");
if (dataStrings.length >= 1)
statusArray[count] = Number(dataStrings[0]);
if (dataStrings.length >= 2)
topArray[count] = dataStrings[1];
if (dataStrings.length >= 3)
biddersArray[count] = barToSpace(dataStrings[2]);
}
adviceArrayB[count] = "";
document.getElementById("advice" + count).innerHTML = "";
document.getElementById("advice" + count).style.display = "inline";
neededArrayB[count] = "";
}
}
function updateArraysB(inPack) {
var tempNum = getNum(inPack, 1) < 0 ? -getNum(inPack, 1) : getNum(inPack, 1);
var thisStatus = Math.floor((tempNum % 64) / 2);
var thisIndex = getNum(inPack, 7);
var thisTop = getString(inPack, 4);
if (thisIndex >= 0 && thisIndex < numLots) {
statusArray[thisIndex] = thisStatus;
topArray[thisIndex] = thisTop;
if (biddersArray[thisIndex].search(" " + thisTop + " ") < 0)
biddersArray[thisIndex] = biddersArray[thisIndex] + thisTop + " ";
colorBackground(thisIndex);
colorBorder(thisIndex);
setAdviceB(thisIndex);
}
var needed = getString(inPack, 5);
var IamTop = myPaddleS === topArray[thisIndex];
if (isSoldL(thisStatus) && !IamTop)
needed = "Gone";
if (needed.length > 0) {
neededArrayB[thisIndex] = needed;
gebi("needed" + thisIndex).innerHTML = needed;
}
}
function colorBackground(lotIndex) {
if (statusArray[lotIndex] === current || statusArray[lotIndex] === selling)
document.getElementById("lottable" + lotIndex).style.backgroundColor = "rgb(210,230,255)"; //Light Blue
else if (isSoldL(statusArray[lotIndex])) 
document.getElementById("lottable" + lotIndex).style.backgroundColor = "rgb(230,230,230)"; //Light Grey
else
document.getElementById("lottable" + lotIndex).style.backgroundColor = "white";
}
function colorBorder(lotIndex) {
var borderCol = "rgb(255,255,255)";  //White
if (loggedOnS) {
gebi("bheart" + lotIndex).style.display = favourites[lotIndex] ? "none" : "inline";
gebi("rheart" + lotIndex).style.display = favourites[lotIndex] ? "inline" : "none";
if (favourites[lotIndex]) 
borderCol = "rgb(255,204,0)";  //Orange
gebi("bemail" + lotIndex).style.display = reminders[lotIndex] ? "none" : "inline";
gebi("remail" + lotIndex).style.display = reminders[lotIndex] ? "inline" : "none";
}
else {
gebi("bheart" + lotIndex).style.display = "inline";
gebi("rheart" + lotIndex).style.display = "none";
gebi("bemail" + lotIndex).style.display = "inline";
gebi("remail" + lotIndex).style.display = "none";
}
 
var IamTop = myPaddleS === topArray[lotIndex];
if (myPaddleS !== "" && biddersArray[lotIndex].search(" " + myPaddleS + " ") >= 0) {
var lotStat = statusArray[lotIndex];
if (lotStat === passedIn || lotStat === withdrawn || lotStat === notWebcast)
borderCol = "rgb(220,50,50)"; //Red
else if (lotStat === sold || lotStat === multiItemSold)
borderCol = IamTop ? "rgb(50,220,50)" :  "rgb(220,50,50)"; //Green : Red
else if (lotStat === vendor)
borderCol = IamTop ? "rgb(20,220,184)" :  "rgb(220,50,50)"; //Blue Green : Red
else {
if (!preBids && lotIndex !== currentLotIndexC)
borderCol = "rgb(50,220,50)"; //Green
else
borderCol = IamTop ? "rgb(50,220,50)" :  "rgb(220,50,50)"; //Green : Red
}
}
document.getElementById("lottable" + lotIndex).style.borderColor = borderCol;
borderArrayB[lotIndex] = borderCol;
if (fixedLotModeC && fixedLotIndexC === lotIndex) {
document.getElementById("fixedcanvas").style.borderColor = borderCol;
}
}
function numWords(thisLine) {
var result = 0;
var lastChar = ' ';
for (var count = 0; count < thisLine.length; count++) {
if (lastChar === ' ' && thisLine.charAt(count) !== ' ')
result++;
lastChar = thisLine.charAt(count);
}
return result;
}
 
function setAdviceB(lotIndex) {
if (lotIndex < 0 || lotIndex >= numLots)
return;
var advice = "    ", lotStat = statusArray[lotIndex];
var IamTop = myPaddleS === topArray[lotIndex];
var haveBid = (myPaddleS !== "" && biddersArray[lotIndex].search(" " + myPaddleS + " ") >= 0);
if (lotStat === passedIn)
advice = "Lot passed in.";
else if (lotStat === withdrawn)
advice = "Lot withdrawn from sale.";
else if (lotStat === notWebcast)
advice = "Lot not webcast.";
else if (lotStat === sold || lotStat === multiItemSold)
advice = haveBid ? (IamTop?"Sold - you have won this lot.": "You did not get this lot.") : "Lot sold.";
else if (lotStat === vendor)
advice = (haveBid && !IamTop) ? "You did not get this lot." : "Lot refered to vendor.";
else if (lotStat === current && !haveBid)
advice = "Now Auctioning";
else if (haveBid) {
if (lotStat === created && !preBids) 
advice = "You have a bid on this lot.";
else
advice = IamTop ? "You are the top bidder." :  "You are not the top bidder.";
}
else if (biddersArray[lotIndex]) {
var numBidders = numWords(biddersArray[lotIndex]);
if (numBidders === 1)
advice = "   (One bidder)";
else
advice = (numBidders > 1) ? "   (" + numBidders + " bidders)" : "    ";
}
else
advice = "    ";
adviceArrayB[lotIndex] = "&nbsp;&nbsp;&nbsp;&nbsp;" + advice;
document.getElementById("advice" + lotIndex).innerHTML = adviceArrayB[lotIndex];
}
function setBackgroundsB() {
for (var count = 0; count < numLots; count++) {
colorBackground(count);
colorBorder(count);
setAdviceB(count);
}
}
function viewMyLotsB() {
var justMine = false;
if (phoneVersion)
justMine = (gebi("viewbutton1").value === "My Lots");
else
justMine = (gebi("viewbutton2").value === "View My Lots");
if (!loggedOnS && justMine) {
alert("You need to logon to see the lots you have bid on and your favourite lots.");
return;
}
for (var count = 0; count < numLots; count++) {
if (justMine && borderArrayB[count] === "rgb(255,255,255)") //White
gebi("lotrow" + count).style.display = "none";
else 
gebi("lotrow" + count).style.display = "block";
}
if (phoneVersion)
gebi("viewbutton1").value = justMine ? "All Lots" : "My Lots";
else
gebi("viewbutton2").value = justMine ? "View All Lots" : "View My Lots";
fullWidthB();
}
function showMatchB(showNow) {
if (phoneVersion) {
gebi("finddiv").style.display = showNow ? "block" : "none";
if (showNow && gebi("phonefindfield").value === "Search...")
gebi("phonefindfield").value = "";
if (!showNow) {
gebi("phonefindfield").value = "";
repaintFindsB();
}
}
else {
gebi("findspan2").style.display = showNow ? "block" : "none";
if (showNow && gebi("bigfindfield").value === "Search...")
gebi("bigfindfield").value = "";
if (!showNow) {
gebi("bigfindfield").value = "";
repaintFindsB();
}
}
}
function findFieldValueB() {
if (phoneVersion)
return gebi("phonefindfield").value.toLowerCase();
else
return gebi("bigfindfield").value.toLowerCase();
}
function enterFindB(evt) {
if (evt.keyCode === 13) {
findStringB();
}
else {
clearFindsB();
searchString = findFieldValueB();
foundSpan = "";
showFindsB();
fullWidthB();
}
}
function fullWidthB() {
var tableWidth = gebi("cattable").offsetWidth - 11;
if (phoneVersion)
tableWidth = (tableWidth < 370) ? 370 : tableWidth;
else 
tableWidth = (tableWidth < 600) ? 600 : tableWidth;
for (var index = 0; index < numLots; index++) {
gebi("lottable" + index).style.width = tableWidth + "px";
}
}
function findStringB() {
clearFindsB();
searchString = findFieldValueB();
if (searchString.length > 0) {
findNextB();
showFindsB();
if (fixedLotModeC)
gotoLotC(gebi("lotspan" + foundIndex).innerHTML);
else
offsetScrollC(foundIndex);
}
}
function findNextB() {
var currentTitle = gebi("title" + foundIndex).innerHTML;
if (foundSpan.length > 0 && currentTitle.length > foundPos + 2) {
var nextPos = currentTitle.substring(foundPos + 1).toLowerCase().indexOf(searchString);
if (nextPos >= 0) {
foundPos += 1 + nextPos;
foundSpan = '<span class="foundspan">' + currentTitle.substring(foundPos, foundPos+searchString.length) + '</span>';
return;
}
}
var startIndex = (foundSpan.length > 0) ? (foundIndex + 1) % numLots : 0;
for (var index = startIndex; index < startIndex + numLots; index++) {
var thisTitle = gebi("title" + index%numLots).innerHTML;
var thisPos = thisTitle.toLowerCase().indexOf(searchString);
if (thisPos >= 0) {
foundIndex = index % numLots;
foundPos = thisPos;
foundSpan = '<span class="foundspan">' + thisTitle.substring(foundPos, foundPos+searchString.length) + '</span>';
return;
}
}
}
function prevStringB() {
clearFindsB();
searchString = findFieldValueB();
findPrevB();
showFindsB();
if (fixedLotModeC)
gotoLotC(gebi("lotspan" + foundIndex).innerHTML);
else
offsetScrollC(foundIndex);
}
function findPrevB() {
var currentTitle = gebi("title" + foundIndex).innerHTML;
if (foundSpan.length > 0) {
var prevPos = currentTitle.substring(0, foundPos).toLowerCase().lastIndexOf(searchString);
if (prevPos >= 0) {
foundPos = prevPos;
foundSpan = '<span class="foundspan">' + currentTitle.substring(foundPos, foundPos+searchString.length) + '</span>';
return;
}
}
var endIndex = (foundSpan.length > 0) ? foundIndex : 0;
for (var index = endIndex + numLots - 1; index >= endIndex; index--) {
var thisTitle = gebi("title" + index%numLots).innerHTML;
var thisPos = thisTitle.toLowerCase().lastIndexOf(searchString);
if (thisPos >= 0) {
foundIndex = index % numLots;
foundPos = thisPos;
foundSpan = '<span class="foundspan">' + thisTitle.substring(foundPos, foundPos+searchString.length) + '</span>';
return;
}
}
}
function repaintFindsB() {
clearFindsB();
searchString = findFieldValueB();
showFindsB();
fullWidthB();
}
function showFindsB() {
for (var index = 0; index < numLots; index++) {
var theTitle = gebi("title" + index).innerHTML;
var thisPos = theTitle.toLowerCase().indexOf(searchString);
var result = "";
var titleDone = 0;
if (searchString.length > 0 && thisPos >= 0) {
while (thisPos >= 0) {
result += theTitle.substring(0, thisPos);
if (foundSpan.length > 0 && index === foundIndex && (thisPos+titleDone) === foundPos)
result += '<span class="foundspan">';
else
result += '<span class="matchspan">';
result += theTitle.substring(thisPos, thisPos + searchString.length) + '</span>';
theTitle = theTitle.substring(thisPos + searchString.length);
titleDone += thisPos + searchString.length;
thisPos = theTitle.toLowerCase().indexOf(searchString);
}
gebi("lotrow" + index).style.display = "block";
}
else {
var showUnmatched = phoneVersion ? gebi("phonematchbox").checked : gebi("bigmatchbox").checked;
if (!showUnmatched && searchString.length > 0)
gebi("lotrow" + index).style.display = "none";
else
gebi("lotrow" + index).style.display = "block";
}
gebi("title" + index).innerHTML = result + theTitle;
}
if (fixedLotModeC && !phoneVersion) 
showFixedC(fixedLotIndexC);
}
function despan(theSpan) {
var firstPos = theSpan.indexOf(">");
var lastPos = theSpan.lastIndexOf("<");
if (firstPos > 0 && lastPos > 0 && lastPos > firstPos+1)
return theSpan.substring(firstPos+1, lastPos);
else
return "";
}
function clearFindsB() {
if (searchString.length <= 0)
return;
if (foundSpan.length > 0)
gebi("title" + foundIndex).innerHTML = gebi("title" + foundIndex).innerHTML.replace(foundSpan, despan(foundSpan));
var searchSpan = ('<span class="matchspan">' + searchString + '</span>').toLowerCase();
for (var index = 0; index < numLots; index++) {
var theTitle = gebi("title" + index).innerHTML;
var thisPos = theTitle.toLowerCase().indexOf(searchSpan);
var result = "";
while (thisPos >= 0) {
result += theTitle.substring(0, thisPos) + despan(theTitle.substring(thisPos, thisPos + searchSpan.length));
theTitle = theTitle.substring(thisPos + searchSpan.length);
thisPos = theTitle.toLowerCase().indexOf(searchSpan);
}
gebi("title" + index).innerHTML = result + theTitle;
}
}
var messageOK = 0, errorMess = 1, errorTooLate = 3, errorZeroAmount = 4,
errorNoLot = 5, errorTooLow = 6, exceededQuota = 8, errorWrongClient = 9,
nameError = 10, errorCreditCard = 13,
errorTooMany = 11, introMess = 20, justPatter = 21, goodPatter = 22;
var showLot = null, showLotNumC = "", showLotIndexC = -1, goingsC = 0,
currentLot = null, currentLotNumC = "", currentLotIndexC = -1, fixedLotIndexC,
currLimitPriceC = 0, showingIntro = false, titleTextC = "",
phoneScrollOK = true, catScrollOK = true;
var lastLotNumC = "", lastLotIndex = -1, requestedLotNum = "", followCurrent = true,      
fixedLotNumC = "", fixedLotModeC = false, prevNextC = false, numPics = 1,
picLotNum = "", picIndex = 0, auctionStatusC = 0, inPackC = null, bigPhonePicC = false,
showingMessage = false, numThreads = 0, shownPic = "", goingCurrent = false,
showingPic2 = false, drawWidth =400, drawHeight = 300,
scrollStep = 0, scrollLeft = 0, waitThread = 0, lastLocation = "";
function fastIndexC() {
var showIndex = false;
if (phoneVersion)
showIndex = gebi("indexbox1").checked;
else
showIndex = gebi("indexbox2").checked;
var fastIndex = gebi("indexlist");
if (fastIndex !== undefined && fastIndex !== null)
fastIndex.style.display = showIndex ? "block" : "none";
}
function clearStatus() {
numThreads--;
if (numThreads <= 0)
gebi("statusbox").value = "";
}
function setStatusC(messText) {
gebi("statusbox").value = messText;
numThreads++;
setTimeout(clearStatus, 4000);
}
function bidMessageC(inPack) {
if (inPack.packetType === repBidLimitM) {
bidReceivedL = true;
if (getNum(inPack, 1) === messageOK)
setStatusC("Bid received");
else if (getNum(inPack, 1) === errorTooLow)
setStatusC("Bid not high enough");
else
setStatusC("Error with bid.");
}
if (getNum(inPack, 2) > 0)
setStatusC("Bids over purchase limit.");
if (getString(inPack, 3) === showLotNumC)
myLimitL = getNum(inPack, 4) * unitCash;
if (getString(inPack, 3) === currentLotNumC)
currLimitPriceC = getNum(inPack, 4) * unitCash;
if (inPack.packetType === repBidLimitM)
numMessage(getNum(inPack, 1));
redrawLadderL();
}
function showMessageC(line1, line2, line3, line4, line5) {
showingMessage = true;
gebi("messtext").innerHTML = "<br>" + line1
+ "<br>" + line2 + "<br>" + line3
+ "<br>" + line4 + "<br>" + line5 + "<br>";
if (showingPic2)
gebi("piccanvas2").style.display = "none";
else
gebi("piccanvas1").style.display = "none";
gebi("messtext").style.display = "block";
gebi("statusbox").style.display = "none";
gebi("OKbutton").style.display = "block";
}
function numMessage(messCode) {
if (messCode === errorTooLate)
showMessageC("  ", "Bid failed", "That bid", "was a little", "too late.");
else if (messCode === errorMess)
showMessageC("  ", "Bid failed", "Problen", "connecting to", "webcaster.");
else if (messCode === errorWrongClient)
showMessageC("  ", "Client error", "Please reconnect", "and log", "back in.");
else if (messCode === errorZeroAmount)
showMessageC("  ", "Bid failed", "Zero items", "bid for.", "  ");
else if (messCode === errorTooLow)
setStatusC("Bid not high enough");
else if (messCode === errorNoLot)
setStatusC("Lot not found.");
else if (messCode === errorTooMany)
showMessageC("  ", "Bid failed", "You have already", "left the maximum", "number of bids.");
else if (messCode === exceededQuota)
showMessageC("  ", "Bid Failed", "The bid would", "exceed your", "purchase quota.");
}
function OKClickedC() {
showingMessage = false;
gebi("messtext").style.display = "none";
if (showingPic2) {
gebi("piccanvas2").innerHTML = shownPic;
gebi("piccanvas2").style.display = "block";
}
else {
gebi("piccanvas1").innerHTML = shownPic;
gebi("piccanvas1").style.display = "block";
}
gebi("statusbox").style.display = "block";
gebi("OKbutton").style.display = "none";
reloadSocketS();
}
function loadIntro(introNum) {
showingIntro = true;
if (showingPic2) 
gebi("piccanvas2").style.display = "none";
else
gebi("piccanvas1").style.display = "none";
gebi("messtext").style.display = "block";
gebi("messtext").innerHTML = gebi("intro" + introNum).innerHTML;
}
function announceRecC(inPack) {
var announceType = getNum(inPack, 1);
if (announceType === justPatter || announceType === goodPatter) {
if (!fixedLotModeC || getString(inPack, 4) === fixedLotNumC) {
setStatusC(getString(inPack, 1) 
+ " " + getString(inPack, 2) + " " + getString(inPack, 3));
}
}
else if (announceType === introMess) {
loadIntro(getString(inPack, 1));
}
else {
setStatusC(getString(inPack, 1) 
+ " " + getString(inPack, 2) + " " + getString(inPack, 3));
}
}
function goingRecC(inPack) {
if (getString(inPack, 3) !== currentLotNumC && getString(inPack, 3) !== lastLotNumC) {
var mess = new sendPack(refreshLotM);
webSocket.send(retMessage(mess, currentLotM, clientNumS, keyHashS));
return;
}
if (!fixedLotModeC || getString(inPack, 3) === fixedLotNumC) {
setStatusC(getString(inPack, 1) 
+ " " + getString(inPack, 2));
if (goingsC !== getNum(inPack, 1) && getNum(inPack, 1) !== 14)
hammersGoingB(getNum(inPack, 1));
}
goingsC = getNum(inPack, 1);
}
function soldRecC(inPack) {
showMessageC(getString(inPack, 2), getString(inPack, 3).match(/\w.*/), 
getString(inPack, 4).match(/\w.*/), getString(inPack, 5).match(/\w.*/),
getString(inPack, 6).match(/\w.*/));
}
function fastClickedC(lotIndex) {
if (fixedLotModeC) {
phoneScrollOK = false;
catScrollOK = false;
goCurrentC();
phoneScrollOK = true;
catScrollOK = true;
}
if (stepBack) {
var lotSt = gebi("lotspan" + lotIndex).innerHTML;
var currentLocation = window.location.href;
var lotLoc = window.location.href.search(/#lot/);
if (lotLoc > 0)
currentLocation = window.location.href.substring(0, lotLoc);
var ibLoc = window.location.href.search(/#ib/);
if (ibLoc > 0)
currentLocation = window.location.href.substring(0, ibLoc);
window.location.href = currentLocation + "#ib" + lotSt;
}
lastLocS = "";
offsetScrollC(lotIndex);
}
function backToCatC() {
if (stepBack) {
lastLocation = window.location.href;
window.history.back();
waitThread = setTimeout(noChange, 500);
}
else {
picInCatC();
}
}
function noChange() {
if (window.location.href === lastLocation) {
picInCatC();  
}
}
function picInCatC() {
reloadSocketS();
bigPhonePicC = false;
if (stepBack) {
var destLot = window.location.href.search(/#lot/);
if (destLot > 0)
window.location.href = window.location.href.substring(0, destLot);
}
showInCatC(picIndex);
lastLocS = window.location.href;
}
function followCatC() {
followCurrent = gebi("followbox").checked;
if (followCurrent && showLotNumC.length > 0)
showInCatC(showLotIndexC);
}
function showInCatC(lotIndex) {
if (phoneVersion)
gebi("topbuttons").style.display = 'block';
if (lotIndex === undefined)
lotIndex = showLotIndexC;
phoneScrollOK = false;
catScrollOK = false;
goCurrentC();
phoneScrollOK = true;
catScrollOK = true;
lastLocS = "";
if (0 <= fixedLotIndexC && fixedLotIndexC < numLots) 
offsetScrollC(fixedLotIndexC);
}
function lotInCatC() {
if (phoneVersion)
gebi("topbuttons").style.display = 'block';
lotIndex = showLotIndexC;
lastLocS = "";
phoneScrollOK = false;
var wasFixedMode = fixedLotModeC;
goCurrentC();
phoneScrollOK = true;
lastLocS = "";
if (wasFixedMode) {
if (0 <= fixedLotIndexC && fixedLotIndexC< numLots) 
offsetScrollC(fixedLotIndexC);
}
else {
if (0 <= showLotIndexC && showLotIndexC < numLots) 
offsetScrollC(showLotIndexC);
}
}
function gotoFieldLotC() {
var lotString = gebi("lotfield").value;
if (lotString === undefined || lotString === "")
showMessageC("Cannot goto lot as", "there is nothing", "in the lot field.",
"Please enter a", "lot number.");
else {
if (stepBack) {
var ibLocation = window.location.href.search(/#ib/);
if (ibLocation > 0)
window.location.href = window.location.href.substring(0, ibLocation) + "#lot" + gebi("lotfield").value;
else {
var existingLot = window.location.href.search(/#lot/);
if (existingLot > 0)
window.location.href = window.location.href.substring(0, existingLot) + "#lot" + gebi("lotfield").value;
else 
window.location.href = window.location.href + "#lot" + gebi("lotfield").value;
}
}
lastLocS = window.location.href;
gotoLotC(gebi("lotfield").value);
}
}
function enterGotoC(evt) {
if (evt.keyCode === 13) {
gotoFieldLotC();
}
}
function gotoBiddingScreenC() {
reloadSocketS();
bigPhonePicC = false;
gotoLotC(picLotNum);
}
function urlLotC(lotSt) {
if (stepBack) {
var ibLocation = window.location.href.search(/#ib/);
if (ibLocation > 0)
window.location.href = window.location.href.substring(0, ibLocation) + "#lot" + lotSt;
else {
var existingLot = window.location.href.search(/#lot/);
if (existingLot <= 0) 
window.location.href = window.location.href + "#lot" + lotSt;
else
window.location.href = window.location.href.substring(0, existingLot) + "#lot" + lotSt;
}
}
lastLocS = window.location.href;
gotoLotC(lotSt);
}
function gotoLotC(lotSt) {
if (!isConnectedS)
return;
if (typeof lotSt === 'number') 
lotSt = lotSt.toString();
if (phoneVersion) {
gebi("topbuttons").style.display = 'block';
}
if (phoneVersion && lotSt === currentLotNumC && !bigPhonePicC) {
goCurrentC();
return;
}
setButtons(0, numRungs-1, "Loading");
fixedLotModeC = true;
if (phoneVersion && auctionStatusC === progAuctioning)
gebi("currentbutton").style.color = "red";
else
gebi("currentbutton").style.color = "black";
if (!phoneVersion)
gebi("backbutton").style.color = "red";
requestedLotNum = lotSt;
gebi("fixedpics").innerHTML = '<img src="/resources/white.gif" width="'
+ drawWidth + 'px" height="' + drawHeight + 'px"/>';
gebi("fixedheading").innerHTML = "          ";
gebi("fixedtitle").innerHTML = "<br><br>";
var mess = new sendPack(sendShowLotM);
putNum(mess, 1, 0);
putNum(mess, 2, -1);
putString(mess, 1, lotSt);
webSocket.send(retMessage(mess, fixedLotM, clientNumS, keyHashS));
if (bigPhonePicC) 
gebi("mainclient").style.display = 'block';
gebi("widecell").style.display = phoneVersion ? "none" : "block";
if (phoneVersion) {
if (bigPhonePicC) {
gebi("cattable").style.display = 'inline-block';
gebi("fixedcanvas").style.display = "none";
gebi("phonefixedbuttons").style.display = 'none';
}
}
else {
gebi("cattable").style.display = 'none';
gebi("bigfixedbuttons").style.display = 'block';
}
window.scrollTo(0, 0);
}
function gotoNextC(isNext, jumpTen) {
prevNextC = true;
var gotoIndex = showLotIndexC;
if (showLotIndexC + isNext < 0 || showLotIndexC + isNext >= numLots) {
setStatusC("Lot not found.");
return;
}
if (isNext === 0) {
if (showLotIndexC + jumpTen >= 0 && showLotIndexC + jumpTen < numLots)
gotoIndex = showLotIndexC + jumpTen;
else {
setStatusC("Lot not found.");
return;
}
}
gebi("fixedpics").innerHTML = '<img src="/resources/white.gif" width="'
+ drawWidth + 'px" height="' + drawHeight + 'px"/>';
gebi("fixedheading").innerHTML = "          ";
gebi("fixedtitle").innerHTML = "<br><br>";
var mess = new sendPack(sendShowLotM);
putNum(mess, 1, isNext);
putNum(mess, 2, gotoIndex);
putString(mess, 1, "");
webSocket.send(retMessage(mess, fixedLotM, clientNumS, keyHashS));
}
function goCurrentC() {
fixedLotModeC = false;
if (currentLotIndexC > -1)
gebi("titlearea").innerHTML = "   ";
else
gebi("titlearea").innerHTML = titleTextC;
if (phoneVersion)
gebi("currentbutton").style.color = "black";
else
gebi("backbutton").style.color = gebi("tenbutton").style.color;
goingCurrent = true;
inPackC = currentLot;
currentLotRecC();
gebi("fixedcanvas").style.borderColor = "rgb(255,255,255)";  //White
gebi("cattable").style.display = 'inline-block';
if (!phoneVersion)
gebi("biglogo").style.display = "block";
gebi("widecell").style.display = phoneVersion ? "none" : "block";
gebi("mainclient").style.position = phoneVersion ? "static" : "fixed";
gebi("mainclient").style.display = "block";
gebi("fixedcanvas").style.display = 'none';
if (!phoneVersion)
gebi("bigfixedbuttons").style.display = 'none';
if (phoneVersion)
gebi("phonefixedbuttons").style.display = 'none';
if (currentLotIndexC < 0) {
gebi("piccanvas1").innerHTML = "";
gebi("piccanvas2").innerHTML = "";
}
if (phoneScrollOK)
window.scrollTo(0, 0);
}
function animateCat() {
window.scrollBy(0, scrollStep);
scrollLeft -= scrollStep;
if (scrollStep > 0 && scrollLeft > scrollStep || scrollStep < 0 && scrollLeft < scrollStep)
setTimeout(animateCat, 20);
else {
offsetScrollC(currentLotIndexC);
}
}
function offsetScrollC(lotIndex) {
var elementRect = gebi("lottable" + lotIndex).getBoundingClientRect();
var absoluteElementTop = elementRect.top + window.pageYOffset;
window.scrollTo(0, absoluteElementTop - 75);      
}
function remSpans(titleSt) {
var leftB = titleSt.indexOf("<");
while (leftB >= 0) {
var rightB = titleSt.indexOf(">");
if (rightB >= 0 && rightB+1 < titleSt.length)
titleSt = titleSt.substring(0, leftB) + titleSt.substring(rightB+1);
leftB = titleSt.indexOf("<");
}
return titleSt;
}
function setLotEffects(inPack) {
gebi("statusbox").value = "";
showLot = inPack;
showLotNumC = getString(inPack, 1);
if (showLotNumC === "") {
gebi("lotnumdiv").innerHTML = "Connected to auction server.";
return;
}
if (showLotNumC === currentLotNumC && loggedOnS)
gebi("mainladder").style.backgroundColor = "rgb(210,230,255)";
else
gebi("mainladder").style.backgroundColor = "white";
var limitBytes = getString(inPack, 3);
if (goingCurrent)
myLimitL = currLimitPriceC;
else
myLimitL = retNum(limitBytes, 4) * unitCash;
showLotIndexC = getNum(inPack, 6);
totalBidsL = 0;
var tSt = gebi("title" + showLotIndexC).innerHTML.replace(/<br>/g, " ");
tSt = remSpans(tSt);
gebi("lotnumdiv").innerHTML = (fixedLotModeC ? "Viewing" : "Now auctioning") + " lot: " + showLotNumC;
gebi("titlearea").innerHTML = tSt.length < 200 ? tSt : tSt.substring(0, 200) + "...";
var shortName = (houseName === "mgs" && auctionID.length > 2) ? auctionID.substring(0, auctionID.length-1) : auctionID;
var midAddress = midStart + shortName + pictureVersion + midMiddle + showLotNumC + midEnd;
if (houseName === "arooms" || houseName === "bennetts" || houseName === "fcs" || houseName === "rosss") {
var theMid = gebi("midstring" + showLotIndexC).innerHTML;
var jpgPos = theMid.search(/jpg/) + 3;
if (jpgPos < 3)
jpgPos = theMid.search(/JPG/) + 3;
var startPos = theMid.search(/https/);
if (startPos < 3)
startPos = theMid.search(/http/);
midAddress = theMid.substring(startPos, jpgPos);
}
gebi("incatbutton").value = "Lot " + showLotNumC + " in Catalogue";
shownPic = '<img src="' + midAddress + '" class="mainbox">';
if (showingPic2) {
gebi("piccanvas2").innerHTML = "";
gebi("piccanvas1").innerHTML = shownPic;
gebi("piccanvas2").style.display = "none";
gebi("piccanvas1").style.display = "block";
}
else {
gebi("piccanvas1").innerHTML = "";
gebi("piccanvas2").innerHTML = shownPic;
gebi("piccanvas1").style.display = "none";
gebi("piccanvas2").style.display = "block";
}
showingPic2 = !showingPic2;
}
function currentLotRecC() {
var inPack = inPackC;
if (currentLotIndexC > -1)
gebi("lottable" + currentLotIndexC).style.backgroundColor = "rgb(240,240,240)";
hadCrash = false;
lastLotNumC = currentLotNumC;
currentLot = inPack;
currentLotNumC = getString(inPack, 1);
currentLotIndexC = getNum(inPack, 6);
auctionStatusC = getNum(inPack, 8);
if (auctionStatusC === auctFinished)
startEndL();
if (currentLotIndexC > -1)
gebi("lottable" + currentLotIndexC).style.backgroundColor = "rgb(210,230,255)";
if (!goingCurrent) {
var limitBytes = getString(inPack, 3);
currLimitPriceC = retNum(limitBytes, 4) * unitCash;
}
if (!fixedLotModeC || currentLotNumC === fixedLotNumC) {
setLotEffects(inPack);
if (phoneVersion)
gebi("smalllotbuttons").style.display = "none";
}
if (fixedLotModeC && currentLotNumC === fixedLotNumC && playSounds) 
gebi("playnewlot").play();
if (goingCurrent) 
currentLadderRecL(currentLadderMess);
else if (getString(inPack, 2).length > 22) {
var ladderPack = new recPack(btoa(makeShort(currentLadderM) + getString(inPack, 2)));
currentLadderRecL(ladderPack);
}
else if (!fixedLotModeC)
redrawLadderL();
if (fixedLotModeC)
setStatusC("Current Lot is " + currentLotNumC);
else if (!phoneVersion && followCurrent && currentLotIndexC > -1 && catScrollOK) {
var elementRect = gebi("lottable" + currentLotIndexC).getBoundingClientRect();
scrollLeft = elementRect.top - 75;
scrollStep = scrollLeft / 50;
animateCat();
}
goingCurrent = false;
if (currentLotIndexC === 0 && loggedOnS
&& (numLots > 0 && favourites[0]
|| numLots > 1 && favourites[1]
|| numLots > 2 && favourites[2])) {
gebi("playnewlot").play();
setStatusC("Favourited lot coming up.");
}
if (currentLotIndexC + 3 < numLots && loggedOnS) {
if (favourites[currentLotIndexC + 3]) {
gebi("playnewlot").play();
setStatusC("Lot " + gebi("lotspan" + (currentLotIndexC + 3)).innerHTML + " is coming up.");
}
}
if (showingIntro) {
showingIntro = false;
gebi("messtext").style.display = "none";
if (showingPic2)
gebi("piccanvas2").style.display = "block";
else
gebi("piccanvas1").style.display = "block";
}
}
function fixedLotRecC(inPack) {
if (getString(inPack, 1).length === 0) {
setStatusC("Lot not found");
setStatusC("Redund" + "ant code");
setStatusC("Lot not found");
}
if (fixedLotModeC && (getString(inPack, 1) === requestedLotNum || prevNextC)) {
prevNextC = false;
fixedLotNumC = getString(inPack, 1);
fixedLotIndexC = getNum(inPack, 6);
confirmingBidL = false;
setLotEffects(inPack);
if (getString(inPack, 2).length > 22) {
var ladderPack = new recPack(btoa(makeShort(fixedLadderM) + getString(inPack, 2)));
fixedLadderRecL(ladderPack);
}
if (phoneVersion)
gebi("smalllotbuttons").style.display = "block";
else
gebi("lotfield").value = "";
gebi("widecell").style.display = phoneVersion ? "none" : "block";
if (phoneVersion) {
if (bigPhonePicC) {
gebi("topbuttons").style.display = 'none';
gebi("mainclient").style.display = 'none';
gebi("cattable").style.display = 'none';
showFixedC(showLotIndexC);
gebi("phonefixedbuttons").style.display = 'block';
gebi("fixedcanvas").style.display = 'block';
}
else {
if (newPhone) {
gebi("topbuttons").style.display = 'block';
gebi("mainclient").style.display = 'block';
gebi("cattable").style.display = 'none';
showFixedC(showLotIndexC);
gebi("phonefixedbuttons").style.display = 'none';
gebi("fixedcanvas").style.display = 'block';
}
else {
gebi("topbuttons").style.display = 'block';
gebi("mainclient").style.display = 'block';
gebi("cattable").style.display = 'inline-block';
gebi("phonefixedbuttons").style.display = 'none';
gebi("fixedcanvas").style.display = "none";
}
}
}
}
}
function mainPicClickedC() {
if (!fixedLotModeC && currentLotNumC.length === 0)
return;
bigPhonePicC = phoneVersion;
if (phoneVersion) {
gebi("topbuttons").style.display = 'none';
gebi("mainclient").style.display = 'none';
gebi("cattable").style.display = 'none';
gebi("phonefixedbuttons").style.display = 'block';
}
gebi("fixedcanvas").style.display = 'block';
if (fixedLotModeC)
showFixedC(showLotIndexC);
else
urlLotC(currentLotNumC);
}
function moveFixedC(moveBy) {
var seekIndex = picIndex + moveBy;
if (0 <= seekIndex && seekIndex < numLots)
showFixedC(seekIndex);
}
function showFixedC(lotIndex) {
picIndex = lotIndex;
picLotNum = gebi("lotspan" + lotIndex).innerHTML;
if (phoneVersion) 
gebi("fixedtop").innerHTML = '<br>';
else
gebi("fixedtop").innerHTML = '<br><br><br>';
var picString = '';
var mid = gebi("midpic" + lotIndex);
gebi("cattable").style.display = 'none';
gebi("fixedcanvas").style.display = 'block';
if (!phoneVersion)
gebi("biglogo").style.display = 'none';
gebi("fixedheading").innerHTML = picLotNum + '  ' + adviceArrayB[lotIndex]
+ '&nbsp;&nbsp;&nbsp;&nbsp;' + neededArrayB[lotIndex];
gebi("fixedtitle").innerHTML = gebi("title" + lotIndex).innerHTML;
if (mid.width <= 0) 
mid = gebi("midpic" + lotIndex);
if (phoneVersion) {
landWidth = screen.width-6;
portHeight = screen.width-6;
if (mid.height > mid.width)
portHeight = portHeight * mid.height / mid.width;
}
var taller = mid.height / portHeight > mid.width / landWidth;
drawHeight = taller ? portHeight : Math.floor((mid.height *  landWidth) / mid.width);
drawWidth = taller ? Math.floor((mid.width * portHeight) / mid.height) : landWidth;
var shortName = (houseName === "mgs" && auctionID.length > 2) ? auctionID.substring(0, auctionID.length-1) : auctionID;
var drawString = '';
var midAddress = midStart + shortName + pictureVersion + midMiddle + picLotNum + midEnd;
if (mid.width > 30) {
if (houseName === "arooms" || houseName === "rosss") {
var theMid = gebi("midstring" + lotIndex).innerHTML;
var jpgPos = theMid.search(/jpg/) + 3;
if (jpgPos < 3)
jpgPos = theMid.search(/JPG/) + 3;
var startPos = theMid.search(/https/);
if (startPos < 3)
startPos = theMid.search(/http/);
midAddress = theMid.substring(startPos, jpgPos);
}
drawString = '<img src="' + midAddress
+ '" width="' + drawWidth + 'px" height="' + drawHeight + 'px"/>';
}
var picAddr = gebi("bigpic" + lotIndex).innerHTML.split("|");
numPics = picAddr[0];
if (picAddr.length > 1) {
if (houseName === "abbeys" || houseName === "kearns") {
var refAddr = picAddr[1].replace("pictures", "large");
drawString +=  '<div id="bigfixedpic"><a href="' + refAddr 
+ '" target="_blank"><img src="' + picAddr[1];
if (mid.width > 30) 
drawString += '" width="' + drawWidth + 'px" height="' + drawHeight + 'px';
drawString += '"/><br><span class="titletext">Click on picture to enlarge.</span></a>';
}
else {
drawString +=  '<div id="bigfixedpic"><img src="' + picAddr[1];
if (mid.width > 30 && houseName !== "rosss") 
drawString += '" width="' + drawWidth + 'px" height="' + drawHeight + 'px';
drawString += '"/>';
}
}
picString += drawString;
if (numPics > 1) {
for (var count = 1; count < numPics; count++) {
if (houseName === "mgs") {
var shortName = (auctionID.length > 2) ? auctionID.substring(0, auctionID.length-1) : auctionID;
picString += '<br><br><img src="' + picStart + shortName + picMiddle
+ picLotNum + '&photoNumber=' + (count+1) + '&thumbnail=N"/>';
}
else if (houseName === "arooms" || houseName === "fcs") {
picString += '<br><br><img src="' + picAddr[count+1] + '"/>';
}
else if (houseName === "rosss") {
picString += '<br><br><img src="' + picAddr[count] + '"/>';
}
else if (houseName === "abbeys") {
var largeMiddle = picMiddle.replace("pictures", "large");
picString += '<br><br><a href="' + picStart + auctionID + pictureVersion + largeMiddle
+ picLotNum + '_' + count + '.jpg"><img src="' + picStart + auctionID + pictureVersion + picMiddle
+ picLotNum + '_' + count + '.jpg"/></a>';
}
else {
picString += '<br><br><img src="' + picStart + auctionID + pictureVersion + picMiddle
+ picLotNum + '_' + count + '.jpg"/>';
}
}
}
picString += '</div>';
gebi("fixedpics").innerHTML = picString;
gebi("fixedcanvas").style.borderColor = borderArrayB[lotIndex];
gebi("fixedcanvas").style.backgroundColor = gebi("lottable" + lotIndex).style.backgroundColor;
if (loggedOnS) {
gebi("fixedEmailOff").style.display = reminders[lotIndex] ? "none" : "inline";
gebi("fixedEmailOn").style.display = reminders[lotIndex] ? "inline" : "none";
gebi("fixedHeartOff").style.display = favourites[lotIndex] ? "none" : "inline";
gebi("fixedHeartOn").style.display = favourites[lotIndex] ? "inline" : "none";
}
else {
gebi("fixedEmailOff").style.display = "inline";
gebi("fixedEmailOn").style.display = "none";
gebi("fixedHeartOff").style.display = "inline";
gebi("fixedHeartOn").style.display = "none";
}
if (mid.width > 30)
gebi("bigfixedpic").style.top = "-" + drawHeight + "px";
else
gebi("bigfixedpic").style.top = "0px";
if (phoneVersion) {
gebi("phonefixedbuttons").style.width = drawWidth + "px";
gebi("fixedtitle").style.fontSize = drawWidth >= 700 ? "18pt" : "14pt";
}
else
gebi("bigfixedbuttons").style.display = 'block';
setTimeout(function(){ window.scrollTo(0, 0); }, 100);
}
var created = 1, current = 2, selling = 3,
multiItem = 4, multiLot = 5,
notWebcast = 6, withdrawn = 7, passedIn = 8,
vendor = 9, sold = 10, multiItemSold = 11;
var progStarted = 0, progAuctioning = 1, auctFinished = 2;
var numRungs = 8, maxFields = 3, rungHeight = 35, buttonGrey = "rgb(225,225,225)";
var lotStatus = 0, numFields = 0, numLines = 0, viewPrice = 0,
liveIncs = 0, fixedActive = false, startRequired = 0, extraInc = 0, extraLeft = 0,
onTheMarket = false, messageNum = 0,
showFields = 0, oldNumFields = 0;
numOffers = 0, starting = false, hadConfirm = false,
bidRung = 0, confirmBidPrice = 0, confirmBidLotNum = "",
bidType = sendAddBidLimitM, bidString = "", bidMessage = null,
confirmingBidL = false, higherBid = false, roundDown = false;
var currentLadderMess = null, fixedLadderMess = null, showLadderMess = null,
myLimitL = 0, totalBidsL = 0, oldTotalBids = 0,
animationStep = 1, topHeight = 0, ladderMessNum = 0, bidReceivedL = false; 
function isSoldL(lotStat) {
return (lotStat === notWebcast || lotStat === withdrawn 
|| lotStat === passedIn || lotStat === vendor 
|| lotStat === sold || lotStat === multiItemSold );
}
function setupScreenL() {
showLadderMess = null;
hiddenLoginS = false;
numRungs = phoneVersion ? 8 : 11;
maxFields = phoneVersion ? 3 : 4;
for (var counter = numRungs; counter < 11; counter++) {
gebi("rung" + counter).style.display = "none";
}
gebi("bottomRung").style.height = "0px";
for (var count = 0; count < numRungs; count++) {
gebi("rung" + count).style.height = rungHeight + "px";
}
if (phoneVersion)
playSounds = false;
gebi("topRung").style.height = rungHeight + "px";
if (phoneVersion) {
gebi("topbuttons").style.display = "block";
}
gebi("OKbutton").style.color = "red";
gebi("hammerpanel").style.display = phoneVersion ? "none" : "block";
gebi("widecell").style.display = phoneVersion ? "none" : "block";
gebi("catpadding").style.display = phoneVersion ? "none" : "block";
gebi("incatbutton").style.display = phoneVersion ? "block" : "none";
if (phoneVersion)
gebi("phonelogo").style.display = "block";
else {
gebi("smalllotbuttons").style.display = "none";
gebi("biglogo").style.display = "block";
gebi("bigindex").style.display = "block";
gebi("bigfixedbuttons").style.display = 'none';
goGavelsB(zeroThree, zeroThree);
}
if (phoneVersion) 
gebi("finddiv").style.display = "none";
else
gebi("findspan2").style.display = "none";
gebi("topspacer").style.height = phoneVersion ? "34px" : "0px";
gebi("mainclient").style.position = phoneVersion ? "static" : "fixed";
gebi("mainclient").style.display = "block";
gebi("fixedcanvas").style.display = 'none';
if (phoneVersion)
gebi("phonefixedbuttons").style.display = 'none';
if (gebi('videobox') !== null && gebi('videobox') !== undefined)
gebi('videobox').style.display = 'none';
gebi("showlog2").style.fontWeight = "bold";
titleTextC = gebi("titlearea").innerHTML;
if (phoneVersion) {
landWidth = 350;
portHeight = 350;
}
if (phoneVersion && screen.width > 380) {
for (var count = 0; count < numRungs; count++) {
gebi("rung" + count).style.width = "180px";
gebi("label" + count).style.fontSize = "11pt";
gebi("button" + count).style.fontSize = "11pt";
gebi("input" + count).style.fontSize = "11pt";
}
gebi("currentbutton").style.fontSize = "11pt";
gebi("showlog1").style.fontSize = "11pt";
gebi("viewbutton1").style.fontSize = "11pt";
gebi("phonefindfield").style.fontSize = "10pt";
}
if (numLots <= 50) {
gebi("bigfastbutton").style.display = 'none';
gebi("phonefastbutton").style.display = 'none';
}
}
function animateLadder() {
gebi("topRung").style.height = topHeight + "px";
gebi("bottomRung").style.height = (rungHeight-topHeight) + "px";
topHeight += animationStep;
if (topHeight <= rungHeight) 
setTimeout(function(){animateLadder();}, topHeight === animationStep ? 200 : 20);
}
function showLabel(num, labelText, forColor) {
labelText = labelText === null ? "  &nbsp;   " : labelText;
forColor = forColor === undefined ? "black" : forColor;
gebi("label" + num).innerHTML = labelText;
gebi("label" + num).style.color = forColor;
gebi("label" + num).style.display = "block";
gebi("button" + num).style.display = "none";
gebi("input" + num).style.display = "none";
}
function showButton(num, labelText, backColor) {
backColor = backColor === undefined ? buttonGrey : backColor;
gebi("button" + num).value = labelText;
gebi("button" + num).style.backgroundColor = loggedOnS ? backColor : "white";
gebi("button" + num).style.color = loggedOnS ? "black" : "rgb(120,120,120)";
gebi("label" + num).style.display = "none";
gebi("button" + num).style.display = "block";
gebi("input" + num).style.display = "none";
}
function showField(num, fieldText, backColor) {
backColor = backColor === undefined ? "white" : backColor;
gebi("input" + num).value = fieldText;
gebi("input" + num).style.backgroundColor = backColor;
gebi("label" + num).style.display = "none";
gebi("button" + num).style.display = "none";
gebi("input" + num).style.display = "block";
}
function setButtons(startPos, endPos, labelText) {
for (var count = startPos; count <= endPos; count++) {
showButton(count, labelText);
}
}
function setLabels(startPos, endPos, labelText) {
for (var count = startPos; count <= endPos; count++) {
showLabel(count, labelText);
}
}
function startEndL() {
if (auctionStatusC === progStarted) {
showLabel(numRungs-1, "&nbsp;&nbsp; When the auction");
showLabel(numRungs-2, "&nbsp;&nbsp; calls start, this is");
showLabel(numRungs-3, "&nbsp;&nbsp; where you click");
showLabel(numRungs-4, "&nbsp;&nbsp; to bid live.");
if (preBids) {
showLabel(numRungs-5, "&nbsp;&nbsp; You can also login");
showLabel(numRungs-6, "&nbsp;&nbsp; and click on a lot");
showLabel(numRungs-7, "&nbsp;&nbsp; to start bidding");
showLabel(numRungs-8, "&nbsp;&nbsp; now.");
}
else {
showLabel(numRungs-5, "&nbsp;&nbsp; You can also login");
showLabel(numRungs-6, "&nbsp;&nbsp; and click on a lot");
showLabel(numRungs-7, "&nbsp;&nbsp; to leave an");
showLabel(numRungs-8, "&nbsp;&nbsp; absentee bid limit.");
}
}
else if (auctionStatusC === auctFinished) {
showLabel(numRungs-1, "&nbsp;&nbsp;  ");
showLabel(numRungs-2, "&nbsp;&nbsp; Auction Complete");
showLabel(numRungs-3, "&nbsp;&nbsp;  ");
showLabel(numRungs-4, "&nbsp;&nbsp; Auction Complete");
showLabel(numRungs-5, "&nbsp;&nbsp;  ");
showLabel(numRungs-6, "&nbsp;&nbsp; Auction Complete");
showLabel(numRungs-7, "&nbsp;&nbsp;  ");
showLabel(numRungs-8, "&nbsp;&nbsp; Auction Complete");
}
else {
showLabel(numRungs-1, "&nbsp;&nbsp;  ");
showLabel(numRungs-2, "&nbsp;&nbsp;  ");
showLabel(numRungs-3, "&nbsp;&nbsp;  ");
showLabel(numRungs-4, "&nbsp;&nbsp;  ");
showLabel(numRungs-5, "&nbsp;&nbsp;  ");
showLabel(numRungs-6, "&nbsp;&nbsp;  ");
showLabel(numRungs-7, "&nbsp;&nbsp;  ");
showLabel(numRungs-8, "&nbsp;&nbsp;  ");
}
setLabels(0, numRungs-9, "  ");
}
function drawFields() {
var paddleLength = (myPaddleS === null) ? 0 : myPaddleS.length;
var startPos = 0;
if (numFields > maxFields)
startPos = numFields - maxFields;
for (var count = startPos; count < numFields; count++) {
var fieldString = getString(showLadderMess, count+6);
if (fieldString === "      ")
showLabel(count-startPos, "  &nbsp;   ");
else if (fieldString.length > 4+paddleLength && fieldString.substring(0, 3) === "Net") {
if (paddleLength > 0 && fieldString.substring(4, 4+paddleLength) === myPaddleS)
showField(count-startPos, fieldString, "rgb(180,180,240)"); //Deep Blue
else
showField(count-startPos, fieldString, "rgb(180,180,180)");
}
else if (fieldString.length > 5+paddleLength && fieldString.substring(0, 4) === "Book") {
if (paddleLength > 0 && fieldString.substring(5, 5+paddleLength) === myPaddleS)
showField(count-startPos, fieldString, "rgb(180,180,240)"); //Deep Blue
else
showField(count-startPos, fieldString, "rgb(180,180,180)");
}
else 
showField(count-startPos, fieldString);
}
}
function drawConfirm() {
if (roundDown) {
showLabel(numRungs-1, "&nbsp;The bid price has been");
showLabel(numRungs-2, "&nbsp;rounded down to the");
showLabel(numRungs-3, "&nbsp;nearest bid increment.");
showLabel(numRungs-4, "&nbsp;Final confirm");
showLabel(numRungs-5, "&nbsp;" + bidString);
showLabel(numRungs-6, "&nbsp;  " + confirmBidPrice, "red");
showButton(numRungs-7, "SUBMIT");
showButton(numRungs-8, "QUIT");
setLabels(0, numRungs-9, "  ");
}
else {
showButton(bidRung, "SUBMIT");
if (bidRung < 4) {
showButton(bidRung+4, "QUIT");
showLabel(bidRung+3, "Final confirm");
showLabel(bidRung+2, bidString);
showLabel(bidRung+1, "  " + confirmBidPrice, "red");
setLabels(bidRung+5, numRungs-1, "  &nbsp;   ");
setLabels(0, bidRung-1, "  &nbsp;   ");
}
else {
showLabel(bidRung-1, "Final confirm");
showLabel(bidRung-2, bidString);
showLabel(bidRung-3, "  " + confirmBidPrice, "red");
showButton(bidRung-4, "QUIT");
setLabels(bidRung+1, numRungs-1, "  &nbsp;   ");
setLabels(0, bidRung-5, "  &nbsp;   ");
}
}
}
function drawSold() {
drawFields();
var startPos = maxFields;
if (numFields < maxFields)
startPos = numFields;
for (var count = 0; count < numLines; count++) {
showLabel(startPos+count, getString(showLadderMess, count+numFields+6));
}
setLabels(startPos+numLines, numRungs-1, "  &nbsp;   ");
}
function ladderInc(price, rungNum) {
if (preBids && fixedActive && getInc(price) < liveIncs)
return incPrice(price, liveIncs, false);
else if (extraInc === 0 && extraLeft === 0) 
return incPrice(price, liveIncs, fixedActive);
else {
if (rungNum === 0 && extraInc > 0) 
return incPrice(price, extraInc, false);
else if (rungNum === 0 && extraInc === 0 && extraLeft > 0) 
return incPrice(price, extraLeft, false);
else if (rungNum === 1 && extraInc > 0 && extraLeft > 0) {
return incPrice(price, extraLeft, false);
}
else {
return incPrice(price, liveIncs, fixedActive);
}
}
}
function drawBidButtons() {
var pri = viewPrice;
if (!starting || pri === 0) {
pri = ladderInc(pri, 0);
}
if (startRequired < 0)
pri = -startRequired;
var IamTop = myPaddleS === topArray[showLotIndexC];
for (var count = showFields; count < numRungs; count++) {
if (loggedOnS && myLimitL > 0
&& (starting || myLimitL > viewPrice || (myLimitL === viewPrice && IamTop))) {
if (pri < myLimitL && count === numRungs-2 && preBids && lotStatus === created)
showButton(count, "Your limit is " + writeCash(myLimitL), "rgb(200,240,200)");
else if (pri < myLimitL)
showButton(count, "Decrease to " + writeCash(pri), "rgb(200,240,200)");
else if (myLimitL <= pri && pri < ladderInc(myLimitL, count-showFields)) {
showButton(count, "Your limit is " + writeCash(myLimitL), "rgb(200,240,200)");
}
else
showButton(count, "Increase to " + writeCash(pri));
pri = ladderInc(pri, count-showFields+1);
}
else {
if (starting && count < showFields + numOffers) {
var priceInt = incPrice(pri, liveIncs, fixedActive, count - (showFields + numOffers));
var priceSt = (loggedOnS?"Offer  ":"") + writeCash(priceInt);
if (priceInt > 0)
showButton(count, priceSt, "rgb(200,200,200)");
else
showLabel(count, "   ");
}
else {
if (pri > 0) 
showButton(count, (loggedOnS?"Bid up to ":"") + writeCash(pri));
else
showLabel(count, "   ");
pri = ladderInc(pri, count-showFields+1);
}
}
}
if (preBids && lotStatus === created)
showButton(numRungs-1, "^ Higher Bid ^");
}
function redrawLadderL() {
if (showLadderMess === null) 
startEndL();
else if (confirmingBidL) 
drawConfirm();
else if (lotStatus === selling) 
setButtons(showFields, numRungs-1, "Recording");
else if (isSoldL(lotStatus) || lotStatus === multiItem || lotStatus === multiLot) 
drawSold();
else if (!higherBid && (lotStatus === current || (lotStatus === created && preBids))) {
drawFields();
if (!preBids && viewPrice === 0)
setButtons(showFields, numRungs-1, "Starting");
else
drawBidButtons();
if (oldTotalBids > 0 && oldNumFields !== numFields && oldNumFields >= maxFields) {
topHeight = 0;
animateLadder();
}
}
else if (houseName === "phil") {
setButtons(0, numRungs-1, "No Lot");
}
else { 
if (!loggedOnS) {
setLabels(0, numRungs-1, "  &nbsp;   ");
showLabel(1, "Viewing Lot " + showLotNumC);
}
else {
if (myLimitL <= 0) {
setLabels(0, numRungs-5, "   ");
if (preBids)
showButton(numRungs-4, "QUIT");
else
showLabel(numRungs-4, "   ");
showButton(numRungs-3, "Submit Bid Limit");
}
else {
setLabels(0, numRungs-7, "   ");
if (preBids)
showButton(numRungs-6, "QUIT");
else
showLabel(numRungs-6, "   ");
showLabel(numRungs-5, "Your bid is " + writeCash(myLimitL));
if (!preBids)
showButton(numRungs-4, "Delete Bid Limit");
else
showLabel(numRungs-4, "   ");
showButton(numRungs-3, "Change Bid Limit");
showButton(numRungs-2, "QUIT");
}
showField(numRungs-2, "$ 0");
showLabel(numRungs-1, "Bid Limit");
}
}
}
function setLadderEffects(inPack) {
showLadderMess = inPack;
var firstNum = getNum(inPack, 1);
var tempNum = firstNum;
if (tempNum < 0)
tempNum = -tempNum;
tempNum = tempNum % 16384;
viewPrice = getNum(inPack, 2) * unitCash;
liveIncs = getNum(inPack, 3) * unitCash;
if (getNum(inPack, 3) < 0) 
liveIncs = -getNum(inPack, 3) * unitCash;
fixedActive = (getNum(inPack, 3) < 0);
startRequired = getNum(inPack, 4) * unitCash;
oldTotalBids = totalBidsL;
totalBidsL = Math.floor(firstNum/16348);
onTheMarket = getNum(inPack, 5) !== 0;
messageNum = getNum(inPack, 6);
extraInc = getNum(inPack, 8) * unitCash;
extraLeft = getNum(inPack, 9) * unitCash;
oldNumFields = numFields;
numFields = Math.floor(tempNum / 1024);
numLines = Math.floor((tempNum % 1024)/64);
lotStatus = Math.floor((tempNum % 64) / 2);
bidPause = (tempNum % 2 === 1);
starting = numFields === 0;
showFields = numFields;
higherBid = false;
if (showFields > maxFields)
showFields = maxFields;
if (lotStatus === current) {
if (messageNum === 0 || messageNum !== ladderMessNum) {
upHammersB();
goingsC = 0;
if (getString(inPack, 2) !== null && getString(inPack, 2) !== "   ") {
setStatusC(getString(inPack, 2) + " " + getString(inPack, 3));
}
}
}
ladderMessNum = messageNum;
numOffers = lotStatus === current ? numLines : 0;
if (isSoldL(lotStatus))
confirmingBidL = false;
redrawLadderL();
setAdviceB(showLotIndexC);
}
function currentLadderRecL(inPack) {
if (!fixedLotModeC && inPack === null) {
setLadderEffects(inPack);
return;
}
if (getString(inPack, 1) !== currentLotNumC && getString(inPack, 1) !== lastLotNumC) {
var mess = new sendPack(refreshLotM);
webSocket.send(retMessage(mess, currentLotM, clientNumS, keyHashS));
return;
}
currentLadderMess = inPack;
updateArraysB(inPack);
if (!fixedLotModeC || currentLotNumC === fixedLotNumC) {
setLadderEffects(inPack);
if (lotStatus === sold && !hadCrash) {
hadCrash = true;
goneAnimationB();
if (playSounds)
gebi("playgone").play();
}
}
if (fixedLotModeC && !hadConfirm && currentLotIndexC === 0) {
hadConfirm = true;
if (numLots > 1) {
if (confirm("The auction has started. Click OK to watch the auction."))
goCurrentC();
}
if (playSounds)
gebi("playnewlot").play();
}
if (fixedLotModeC && currentLotNumC === fixedLotNumC && !phoneVersion) 
showFixedC(fixedLotIndexC);
}
function fixedLadderRecL(inPack) {
updateArraysB(inPack);
if (getString(inPack, 1) === showLotNumC) {
fixedLadderMess = inPack;
setLadderEffects(inPack);
}
if (fixedLotModeC && getString(inPack, 1) === showLotNumC && !phoneVersion)
showFixedC(showLotIndexC);
}
function resendBid() {
if (!bidReceivedL) {
webSocket.send(bidMessage);
}
}
function overButtonL(num) {
if (loggedOnS) {
gebi("button" + num).style.textDecoration = "underline";
}
}
function exitButtonL(num) {
if (loggedOnS) {
gebi("button" + num).style.textDecoration = "none";
}
}
function bidClickedL(num) {
roundDown = false;
var bLabel = gebi("button" + num).value;
if (bLabel === "QUIT") {
confirmingBidL = false;
higherBid = false;
}
else if (bLabel === "SUBMIT") {
confirmingBidL = false;
bidReceivedL = false;
var mess = new sendPack(bidType);
putNum(mess, 1, 0);
putNum(mess, 2, 1);
putNum(mess, 3, readCash(confirmBidPrice) / unitCash);
putString(mess, 1, confirmBidLotNum);
putString(mess, 2, clientIP);
bidMessage = retMessage(mess, repBidLimitM, clientNumS, keyHashS);
webSocket.send(bidMessage);
setTimeout(resendBid, 1000);
setTimeout(resendBid, 3000);
}
else if (bLabel === "Submit Bid Limit" || bLabel === "Change Bid Limit") {
bidRung = num;
confirmBidPrice = "$" + gebi("input" + (numRungs-2)).value.replace(/[^0-9-.]/g, '');
var proposedPrice = readCash(confirmBidPrice);
var theInc = getInc(proposedPrice);
roundDown = (unTwoEight(proposedPrice, theInc) % theInc !== 0);
if (roundDown)
confirmBidPrice = writeCash(doTwoEight(Math.floor(proposedPrice / theInc) * theInc, theInc));
confirmBidLotNum = showLotNumC;
confirmingBidL = true;
bidType = (bLabel === "Change Bid Limit") ? sendChangeBidLimitM : sendAddBidLimitM;
bidString = (bLabel === "Change Bid Limit") ? "change bid limit to" : "set bid limit at";
}
else if (bLabel === "Delete Bid Limit") {
bidRung = num;
confirmBidPrice = writeCash(myLimitL);
confirmBidLotNum = showLotNumC;
confirmingBidL = true;
bidType = sendRemBidLimitM;
bidString = "delete bid limit";
}
else if (bLabel === "^ Higher Bid ^" && loggedOnS) {
higherBid = true;
}
else if (loggedOnS) {
bidRung = num;
confirmBidPrice = bLabel.match(/\$.*/)[0]; //The $ and everything after it.
confirmBidLotNum = showLotNumC;
confirmingBidL = true;
bidType = bLabel.search(/crease/) === 2 ? sendChangeBidLimitM : sendAddBidLimitM;
bidString = bLabel.search(/crease/) === 2 ? "change bid limit to" : "set bid limit at";
if (!fixedLotModeC) {
var mess = new sendPack(bidComingM);
putNum(mess, 1, 1);
webSocket.send(retMessage(mess, 0, clientNumS, keyHashS));
}
}
redrawLadderL();
}
