function PHButton2(team, mouseKey, buttonId, primary, trim, lettering, rating) {
this.PHButtonCommon = PHButtonCommon;
this.PHButtonCommon(team, mouseKey, buttonId, primary, trim, lettering);
this.rating = rating;
}
function PHButton(team, mouseKey, buttonId, primary, trim, lettering) {
this.PHButtonCommon = PHButtonCommon;
this.PHButtonCommon(team, mouseKey, buttonId, primary, trim, lettering);
if (team !== "")
useRating = false;
}
function PHButtonCommon(team, mouseKey, buttonId, primary, trim, lettering) {
//Temporary
//this.rating = -1;
//useRating = false;
this.rating = 50;
this.primary = primary;
this.trim = trim;
this.lettering = lettering;
this.mouseKey = mouseKey;
this.actualWinner = -1;
this.teamId = -1;
this.ffeit = false;
this.cancel = false;
this.size = "";
if (buttonId < 64) {
this.round = 0;
this.teamId = buttonId;
}
else if (buttonId < 96)
this.round = 1;
else if (buttonId < 112)
this.round = 2;
else if (buttonId < 120)
this.round = 3;
else if (buttonId < 124)
this.round = 4;
else if (buttonId < 126)
this.round = 5;
else if (buttonId < 127)
this.round = 6;
else
this.round = 7;
this.round += strd;
this.team = team;
this.id = buttonId;
this.Draw = NBButtonDraw;
this.Refresh = NBRefresh;
this.BrBtn = BrBtn;
this.SetLocation = SetLocation;
this.NBPosition = NBPosition;
this.Pressed = BtnPressed;
this.ClearFwd = ClearFwd;
this.ClearPick = ClearPick;
this.GetTeamId = GetTeamId;
this.SetRiskTeam = SetRiskTeam;
this.GetRiskTeam = GetRiskTeam;
this.GetInner = GetInner;
this.StyleColor = StyleColor;
this.AddTeam = AddTeam;
this.SetAlpha = SetAlpha;
this.MouseY = MouseY;
this.MouseX = MouseX;
this.Champ = Champ;
this.Wrong = Wrong;
this.Forfeit = Forfeit;
this.Odds = Odds;
this.Cancel = Cancel;
this.SetSize = SetSize;
this.ShowVersion = ShowVersion;
}
function ShowVersion(vz) {
if (vz == 1) {
Show("#btff" + this.id);
Hide("#bt" + this.id);
}
else {
Hide("#btff" + this.id);
Show("#bt" + this.id);
}
}
function SetSize(sz) {
this.size = sz;
}
function Cancel() {
// this.cancel = true;
}
function Forfeit() {
this.ffeit = true;
}
function AddTeam(team, mkey, teamId, primary, trim, lettering, rating) {
this.team = team;
this.primary = primary;
this.trim = trim;
this.lettering = lettering;
this.mouseKey = mkey;
this.rating = rating;
this.teamId = teamId;
this.riskTeam = teamId;
this.riskPref = teamId;
this.Refresh();
}
function StyleColor(primary, trim, lettering) {
style = "color:"+ToColor(lettering)+";background-color:"+ToColor(primary)+";border-color:"+ToColor(trim)+";";
return style;
}
function GetInner(id, lr, rd, ws, nm) {
var inner = ' ';
var style = '';
var sd;
var prefix = '';
var suffix = '';
if (nm != '') {
var seed = Team2Seed(this.teamId);
var cnsz = "cn" + this.size;
if (lr == cnsz) {
if (this.teamId < 32) {
nm = ''+nm+'';
sd = ''+seed+'';
}
else {
nm = ''+nm+'';
sd = ''+seed+'';
}
var Bt = teams[id];
style += this.StyleColor(Bt.primary, Bt.trim, Bt.lettering);
if (Bt.trim == 0xffffff) {
prefix = '
';
suffix = '
';
}
}
else {
nm = ''+nm+'';
sd = ''+seed+'';
}
var wl = '';
if (resOn && (this.teamId >= 0 && (this.id - 64) >= lockCountOut) || this.cancel) {
if (this.actualWinner >= 0)
wl = '';
if (this.cancel)
wl = "cancel.png";
else if (this.actualWinner == this.teamId)
wl = "right.png";
else {
if (this.Wrong())
wl = "wrong.png";
}
if (wl != '') {
var lrs = 'rwg';
if (this.teamId < 32)
lrs = 'lwg';
if (lr=="cn")
lrs += 'c';
if (id == 126)
lrs = 'wgc';
if (this.ffeit)
wl = RightWrongFade(wl,lrs);
else
wl = RightWrong(wl,lrs);
}
}
if ((lr=="cn") && (prefix != ''))
lr = "cns";
var cls = lr+' '+bcl+' '+ws;
if (rd >= 0)
cls += ' r'+rd;
ss = StyleString(style);
inner = prefix+''+sd+nm+''+suffix+wl;
}
return inner;
}
function Odds(power) {
if (sagarin) {
var sign = 0;
var pd = this.rating - power;
if (pd < 0) {
pd = -pd;
sign = 1;
}
if (pd > 33)
pd = 33;
var pdi = Math.round(pd-0.5);
if (pdi > 32)
pdi = 32;
var idx = pdi;
var idx1 = idx + 1;
pd -= idx;
var z = Z[idx] + (Z[idx1] - Z[idx]) * pd + 0.5;
if (sign)
return 1 - z;
return z;
}
var ri = this.rating / 100;
var rj = power / 100;
var p = (ri - rj * ri) / (ri + rj - 2 * ri * rj);
return p;
}
function Wrong() {
var p = feeds[this.teamId];
while (p <= this.id) {
var t = teams[p];
if (t.actualWinner < 0)
return false;
if (t.actualWinner != this.teamId)
return true;
p = feeds[p];
}
return false;
}
function BrBtn(id, lr, rd, top, left, nm) {
var ws = 'obs';
if (rd >= 5)
ws = "obm";
var inner = this.GetInner(id, lr, rd, ws, nm);
var bb = ''+inner+"
\n";
this.Champ();
return bb;
}
function Champ() {
if (this.id == 126) {
if (this.teamId == -1)
Hide("champ");
else
Show("champ");
}
}
function GetTeamId() {
return this.teamId;
}
function ClearPick() {
this.teamId = -1;
this.team = "";
this.primary = 0;
this.trim = 0;
this.lettering = 0;
this.rating = 0;
this.Refresh();
}
function ClearFwd(teamId) {
var fed = feeds[this.id];
if (fed > 0) {
var Bt = teams[fed];
if (Bt.teamId < 0)
return;
if (Bt.teamId == teamId) {
Bt.ClearPick();
Bt.ClearFwd(teamId);
}
}
}
function BtnPressed(from) {
saved = false;
var Bf = teams[from];
if (this.teamId != Bf.teamId) {
this.ClearFwd(this.teamId);
this.teamId = Bf.teamId;
this.team = Bf.team;
this.primary = Bf.primary;
this.trim = Bf.trim;
this.lettering = Bf.lettering;
this.rating = Bf.rating;
this.Refresh();
}
}
function SetLocation(xx, yy, lr) {
this.xx = xx;
this.yy = yy;
this.lr = lr;
this.NBPosition();
}
function MouseY() {
var yy = this.yy;
if (this.id == 114 || this.id == 115 || this.id == 118 ||
this.id == 119 || this.id == 121 || this.id == 123 || this.id == 124) {
yy -= 150;
// Long veritical playin teams
if (this.teamId == 17 || this.teamId == 57)
yy -= 50;
}
else if (this.id >= 112)
yy += 50;
else
yy -= 20;
if (yy > 760)
yy = 760;
return yy;
}
function MouseX() {
if (this.id >= 124)
return this.xx - 320;
if (this.id >= 122)
return this.xx - 400;
if (this.id >= 120)
return this.xx - 200;
if (this.id >= 116)
return this.xx - 300;
if (this.id >= 112)
return this.xx - 100;
if (this.lr == 0)
return this.xx + 90;
if (this.lr == 1)
return this.xx - 565;
}
function SetRiskTeam(tm) {
this.riskTeam = tm;
}
function GetRiskTeam() {
return this.riskTeam;
}
function SetAlpha(alpha) {
this.alpha = alpha;
var e = document.getElementById("bt"+this.id);
e.style.opacity = alpha / 100;
}
function NBPosition() {
var bt = $("#bt"+this.id);
bt.css({top: this.yy, left: this.xx });
}
function NBButtonDraw() {
lr = "lf";
if (this.lr == 1)
lr = "rt";
else if (this.lr == 2)
lr = "cn";
lr += this.sz;
return this.BrBtn(this.id, lr, this.round, this.yy, this.xx, this.team);
}
function NBRefresh() {
var lr = "lf";
var ws;
if (this.lr == 1)
lr = "rt";
else if (this.lr == 2)
lr = "cn";
if (this.round < 5)
ws = "obs";
else
ws = "obm";
var inner = this.GetInner(this.id,lr,this.round,ws, this.team);
var elem = document.getElementById("bt" + this.id);
elem.innerHTML = inner;
// Duplicate final four contestants.
if (this.id >= 120 && this.id <= 123) {
elem = document.getElementById("btff" + this.id);
elem.innerHTML = inner;
}
this.Champ();
}