////////////////////////////////////////////////////////////////////////////////
//
// JAVASCRIPT ENHANCEMENTS
//
////////////////////////////////////////////////////////////////////////////////
var MSIE = (navigator.appName == "Microsoft Internet Explorer");
function AjaxObject()
{
try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch (e) { }
try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch (e) { }
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { }
try { return new XMLHttpRequest(); } catch (e) { }
return false;
}
function ArrayContains(a, i)
{
for (x = 0; x < a.length; x++)
{
if (a[x] == i)
{
return true;
}
}
return false;
}
function Obj(id)
{
return document.getElementById(id);
}
function Hide(id)
{
Obj(id).style.display = "none";
}
function Show(id)
{
Obj(id).style.display = "block";
}
function ShowIf(id, cond)
{
if (cond)
{
Show(id);
}
else
{
Hide(id);
}
}
////////////////////////////////////////////////////////////////////////////////
//
// NUMBER FORMATTING
//
////////////////////////////////////////////////////////////////////////////////
function Format(amt)
{
var a = (parseInt(amt) / 100).toFixed(2);
var l = a.substr(0, a.length - 3);
var r = a.substr(a.length - 3, 3);
var x = /(\d+)(\d{3})/;
while (x.test(l))
{
l = l.replace(x, "$1,$2");
}
return "$" + l + (r == ".00" ? "" : r);
}
////////////////////////////////////////////////////////////////////////////////
//
// RANDOMIZATION
//
////////////////////////////////////////////////////////////////////////////////
function NewDeck(size)
{
var deck = new Array(size);
for (var x = 0; x < size; x++)
{
deck[x] = x;
}
return Shuffle(deck);
}
function Shuffle(deck)
{
for (var x = deck.length - 1; x > 0; x--)
{
var r = Math.floor(Math.random() * x);
deck[x] ^= deck[r];
deck[r] ^= deck[x];
deck[x] ^= deck[r];
}
return deck;
}
////////////////////////////////////////////////////////////////////////////////
//
// ANIMATION
//
////////////////////////////////////////////////////////////////////////////////
function FlipH(id, width, initial, final, delay) // Flip Horizontally
{
setTimeout("Obj('" + id + "').className = '" + initial + "';", delay);
setTimeout("Obj('" + id + "').style.width = '" + width + "px';", delay);
for (var x = 0; x < (width >> 1); x++) { setTimeout("Obj('" + id + "').style.marginLeft = '" + x + "px'; Obj('" + id + "').style.width = '" + (width - (x << 1)) + "px';", delay); delay++; }
setTimeout("Obj('" + id + "').className = '" + final + "';", delay); delay++;
for (var x = ((width >> 1) - 1); x >= 0; x--) { setTimeout("Obj('" + id + "').style.marginLeft = '" + x + "px'; Obj('" + id + "').style.width = '" + (width - (x << 1)) + "px';", delay); delay++; }
setTimeout("Obj('" + id + "').style.width = '" + width + "px';", delay);
return delay;
}
function Move(id, to_x, to_y)
{
Obj(id).style.left = to_x + "px";
Obj(id).style.top = to_y + "px";
};
function Slide(id, from_x, from_y, to_x, to_y, fps, ms, delay)
{
var dx = to_x - from_x;
var dy = to_y - from_y;
var frames = (ms * fps / 1000);
var speed = ms / frames;
var ox = dx / frames;
var oy = dy / frames;
var o = "Obj('" + id + "')";
setTimeout(o + ".style.left = '" + from_x + "px'; " + o + ".style.top = '" + from_y + "px'; Show('" + id + "');", delay);
for (frame = 0; frame < frames; frame++)
{
delay += speed;
setTimeout(o + ".style.left = '" + parseInt(from_x + (frame * ox)) + "px'; " + o + ".style.top = '" + parseInt(from_y + (frame * oy)) + "px';", delay);
}
delay += speed;
setTimeout(o + ".style.left = '" + to_x + "px'; " + o + ".style.top = '" + to_y + "px';", delay);
return delay;
};
////////////////////////////////////////////////////////////////////////////////
//
// FONT
//
////////////////////////////////////////////////////////////////////////////////
function Font()
{
this.Class = new Array();
var symbol = " ,./<>?;':\"[]\\{}|`~!@#$%^&*()-=_+"; for (var x = 0; x < symbol.length; x++) { this.Class[symbol.substr(x, 1)] = "symbol" + (x < 10 ? "0" : "") + x; }
var digit = "0123456789"; for (var x = 0; x < digit .length; x++) { this.Class[digit .substr(x, 1)] = "digit" + x; }
var upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; for (var x = 0; x < upper .length; x++) { this.Class[upper .substr(x, 1)] = "upper" + upper.substr(x, 1).toLowerCase(); }
var lower = "abcdefghijklmnopqrstuvwxyz"; for (var x = 0; x < lower .length; x++) { this.Class[lower .substr(x, 1)] = "lower" + lower.substr(x, 1); }
this.DrawString = function(c, s) { var h = ""; var l = s.split("\n"); for (var i = 0; i < l.length; i++) { for (var x = 0; x < l[i].length; x++) { h += ""; } if (i < (l.length - 1)) { h += "
"; } } return h; };
}
////////////////////////////////////////////////////////////////////////////////
//
// HOTSPOT
//
////////////////////////////////////////////////////////////////////////////////
function HotSpot(shape, coords, over, out, down, up, click, dblclick)
{
this.Coord = coords;
this.Enabled = false;
this.IsButton = false;
this.IsCapturing = false;
this.IsHovering = false;
this.Shape = shape;
this.Click = click || function(a, c, s) { };
this.DoubleClick = dblclick || function(a, c, s) { };
this.Down = down || function(a, c, s) { };
this.Hover = over || function(a, c, s) { };
this.Leave = out || function(a, c, s) { };
this.Up = up || function(a, c, s) { };
this.Enable = function() { this.Enabled = true; }
this.EnableIf = function(c) { if (c) { this.Enable(); } else { this.Disable(); } }
this.Disable = function() { this.Enabled = false; }
this.Update = function() { this.EnableIf(this.Enabled); }
switch (this.Shape)
{
case "rect":
case "rectangle":
case "square":
{
this.Contains = function(x, y)
{
return (x >= this.Coord[0]) && (x <= this.Coord[2]) && (y >= this.Coord[1]) && (y <= this.Coord[3]);
};
break;
}
case "circ":
case "circle":
case "oval":
case "ellipse":
{
this.cx = (this.Coord[0] + this.Coord[2]) >> 1;
this.cy = (this.Coord[1] + this.Coord[3]) >> 1;
this.rx = (this.Coord[2] - this.Coord[0]) >> 1;
this.ry = (this.Coord[3] - this.Coord[1]) >> 1;
this.Contains = function(x, y)
{
var dx = x - this.cx;
var dy = y - this.cy;
return ((((dx * dx) / (this.rx * this.rx)) + ((dy * dy) / (this.ry * this.ry))) <= 1);
};
break;
}
case "poly":
case "polygon":
{
this.Points = this.Coord.length >> 1;
if (this.Points < 3)
{
this.Contains = function(x, y)
{
return false;
};
}
else
{
this.Contains = function(x, y)
{
var inside = false;
var newX, oldX, x1, x2;
var newY, oldY, y1, y2;
oldX = this.Coord[this.Coord.length - 2];
oldY = this.Coord[this.Coord.length - 1];
for (var p = 0; p < this.Points; p++)
{
newX = this.Coord[(p << 1) + 0];
newY = this.Coord[(p << 1) + 1];
if (newX > oldX)
{
x1 = oldX; x2 = newX; y1 = oldY; y2 = newY;
}
else
{
x1 = newX; x2 = oldX; y1 = newY; y2 = oldY;
}
if (((newX < x) == (x <= oldX)) && (((y - y1) * (x2 - x1)) < ((y2 - y1) * (x - x1))))
{
inside = !inside;
}
oldX = newX;
oldY = newY;
}
return inside;
};
}
break;
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// BUTTON
//
////////////////////////////////////////////////////////////////////////////////
function Button(id, shape, coords, width, height, index, click)
{
this.Coord = coords;
this.Enabled = false;
this.Height = height;
this.ID = id;
this.Index = index;
this.IsButton = true;
this.IsCapturing = false;
this.IsHovering = false;
this.Shape = shape;
this.Width = width;
this.Click = click || function(a, c, s) { };
this.DoubleClick = function(a, c, s) { if (MSIE) { this.Click(); } };
this.Hover = function(a, c, s) { Obj(this.ID).style.backgroundPosition = (this.Index * this.Width * -1) + "px " + (this.Height * -1) + "px"; };
this.Down = function(a, c, s) { Obj(this.ID).style.backgroundPosition = (this.Index * this.Width * -1) + "px " + (this.Height * -2) + "px"; };
this.Up = function(a, c, s) { Obj(this.ID).style.backgroundPosition = (this.Index * this.Width * -1) + "px " + (this.Height * -1) + "px"; };
this.Leave = function(a, c, s) { Obj(this.ID).style.backgroundPosition = (this.Index * this.Width * -1) + "px " + (this.Enabled ? 0 : (this.Height * -3) + "px"); };
this.Enable = function() { this.Enabled = true; Obj(this.ID).style.backgroundPosition = (this.Index * this.Width * -1) + "px 0"; this.Show(); }
this.EnableIf = function(c) { if (c) { this.Enable(); } else { this.Disable(); } }
this.Disable = function() { this.Enabled = false; Obj(this.ID).style.backgroundPosition = (this.Index * this.Width * -1) + "px " + (this.Height * -3) + "px"; this.Hide(); }
this.Update = function() { this.EnableIf(this.Enabled); }
this.Show = function() { Show(this.ID); }
this.ShowIf = function(c) { ShowIf(this.ID, c); }
this.Hide = function() { Hide(this.ID); }
switch (this.Shape)
{
case "rect":
case "rectangle":
case "square":
{
this.Contains = function(x, y)
{
return (x >= this.Coord[0]) && (x <= this.Coord[2]) && (y >= this.Coord[1]) && (y <= this.Coord[3]);
};
break;
}
case "circ":
case "circle":
case "oval":
case "ellipse":
{
this.cx = (this.Coord[0] + this.Coord[2]) >> 1;
this.cy = (this.Coord[1] + this.Coord[3]) >> 1;
this.rx = (this.Coord[2] - this.Coord[0]) >> 1;
this.ry = (this.Coord[3] - this.Coord[1]) >> 1;
this.Contains = function(x, y)
{
var dx = x - this.cx;
var dy = y - this.cy;
return ((((dx * dx) / (this.rx * this.rx)) + ((dy * dy) / (this.ry * this.ry))) <= 1);
};
break;
}
case "poly":
case "polygon":
{
this.Points = this.Coord.length >> 1;
if (this.Points < 3)
{
this.Contains = function(x, y)
{
return false;
};
}
else
{
this.Contains = function(x, y)
{
var inside = false;
var newX, oldX, x1, x2;
var newY, oldY, y1, y2;
oldX = this.Coord[this.Coord.length - 2];
oldY = this.Coord[this.Coord.length - 1];
for (var p = 0; p < this.Points; p++)
{
newX = this.Coord[(p << 1) + 0];
newY = this.Coord[(p << 1) + 1];
if (newX > oldX)
{
x1 = oldX; x2 = newX; y1 = oldY; y2 = newY;
}
else
{
x1 = newX; x2 = oldX; y1 = newY; y2 = oldY;
}
if (((newX < x) == (x <= oldX)) && (((y - y1) * (x2 - x1)) < ((y2 - y1) * (x - x1))))
{
inside = !inside;
}
oldX = newX;
oldY = newY;
}
return inside;
};
}
break;
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// CHIP STACK HTML
//
////////////////////////////////////////////////////////////////////////////////
function ChipStackHTML(amt)
{
var h = "";
if (amt > 0)
{
var a = amt;
var d = [10000000, 2500000, 500000, 100000, 50000, 10000, 2500, 500, 100, 50, 25, 10, 5, 1];
var t = 0;
for (var x = 0; x < d.length; x++)
{
var n = Math.floor(a / d[x]);
for (var y = 0; y < n; y++)
{
h += "