 // Because pre-IE5.5 arrays don't come with Stack & Queue operations, I created my own.

OStackQueue = function()
{
    var RetVal = [];
    if (!RetVal.push)
        RetVal.push = function(elem)
        {
	    var i;
	    for(i = this.length; i > 0; i--)
	        this[i] = this[i - 1];
	    this[i] = elem;
	};
    if (!RetVal.pop)
        RetVal.pop = function()
        {
	    if (this.length < 1) return null;
	    var RetVal = this[0];
	    var i;
	    for(i = 0; i < this.length - 1; i++)
	        this[i] = this[i + 1];
	    this.length--;
	    return RetVal;
	};
    if (!RetVal.shift)
        RetVal.shift = function(elem)
        {
	    this[this.length] = elem;
	};
    if (!RetVal.unshift)
        RetVal.unshift = function()
        {
	    if (this.length < 1) return null;
	    var RetVal = this[this.length - 1];
	    this.length--;
	    return RetVal;
	};

    if (!RetVal.Delete)
        RetVal.Delete = function(dx)  // delete is a reserved word.
        {
	    if (this.length < 1) return null;
	    var RetVal = this[dx];
	    var i;
	    for(i = dx; i < this.length - 1; i++)
                this[i] = this[i + 1];
	    this.length--;
	    return RetVal;
	};
    return RetVal;
};


function GetElement(Identifier, Fragment)
{
	if(document.iframe)
	{
		//alert("We have layers support");
	}
    var Pane;
    var Index;
    var RetVal;
    if (!Fragment)
	{
        Fragment = document;
	}
    if ((Pane = Identifier.indexOf("?")) > 0 && parent.frames.length)
    {
		//alert("I'm Here");
        Fragment = parent.frames[Identifier.substring(Pane + 1)].document;
        Identifier = Identifier.substring(0, Pane);
    }
    if(!(RetVal = Fragment[Identifier]) && Fragment.all)
	{
		//alert("I'm Here2");
        RetVal = Fragment.all[Identifier];
	}
    if (Fragment && Fragment.forms)
    {
		//alert("I'm Here3");
        for(Index = 0; Index < Fragment.forms.length; Index++)
		{
			if (Fragment.forms[Index].Identifier)
			{
				RetVal = Fragment.forms[Index].Identifier;
				break;
			}
			else
			{
            	RetVal = Fragment.forms[Index][Identifier];				
			}
		}
    }
    for(Index = 0; !RetVal && Fragment.layers && Index < Fragment.layers.length; Index++)
	{
		//alert("I'm Here4");
        RetVal = GetElement(Identifier, Fragment.layers[Index].document);
	}
    if (Fragment.getElementById)
	{
		//alert("I'm Here5");
        RetVal = Fragment.getElementById(Identifier);
	}
	if(!RetVal)
	{
		//alert("I'm Here6");
	}
    return RetVal;
}

function GetFrame(strFrame)
{
    if (document.layers)
	{
		return document.layers[strFrame];
	}
    var oDoc = GetElement(strFrame) ? GetElement(strFrame).contentDocument  ? GetElement(strFrame).contentDocument.document : null : null; 
    if (!oDoc)
	{
      oDoc = window.frames[strFrame] ? window.frames[strFrame].document : null;
	}
    if (!oDoc && document && document.frames)
	{
      oDoc = document.frames[strFrame] ? document.frames[strFrame].document : null;
	}
    return oDoc;
}

function MakeFrame(l_left, l_top, l_width, l_height, l_strId, l_className, l_parent)
{
	var l_oFrame;
    if (document.layers)
	{
        l_oFrame = document.layers[l_strId] = new Layer(l_width, l_parent ? l_parent : window);
	}
    else
    {
        l_oFrame = document.createElement('iFrame');
        l_oFrame.id           = l_strId;
        l_oFrame.name         = l_strId;
        l_oFrame.frameBorder  = 0;
        if (l_parent && l_parent.appendChild)
		{
            l_parent.appendChild(l_oFrame);
		}
        else
		{
            document.body.appendChild(l_oFrame);
		}
    }
    SetPos(l_left, l_top, l_width, l_height, l_oFrame);
    l_oFrame.className    = l_className ? l_className : 'CtlPge';
    return l_oFrame;
}

function MakeDiv(strId, strClass, parent)
{
    var oDiv;
    if (document.createElement)
    {
	oDiv = document.createElement("div");
        oDiv.id = strId;
    }
    else if (typeof HTMLElement != 'undefined' && !HTMLElement.prototype.insertAdjacentElement)
    {
        var booga = document.createRange();
        booga.setStartAfter(document.body);
        oDiv = booga.createContextualFragment("<div id='" + strId + "' class='" + strClass + "'></div>");
    }
    else if (document.layers)
    {
	if (!parent)
	{
	    parent = window;
	}
	oDiv = document.layers[strId] = new Layer(0, parent);
	oDiv.className = strClass;
	return oDiv;
    }
    else
    {
	return false;
    }
    oDiv.className = strClass;
    if (!parent)
	{
		parent = document.body;
	}
    if (parent.appendChild)
    {
	    parent.appendChild(oDiv);
    }
	else
    {
	    document.body.appendChild(oDiv);
    }
	return oDiv;
}

function MakeHREF(l, t, w, h, strId, strHREF, strInnerHTML, strClass, strTitle, fOver, fOut, parent)
{
    var oDiv;
    if (document.createElement)
    {
		oDiv = document.createElement("a");
		oDiv.id = strId;
		oDiv.className = strClass;
		oDiv.innerHTML = strInnerHTML;
		oDiv.title = strTitle;
		oDiv.onmouseover = fOver;
		oDiv.onmouseout = fOut;
		if (parent && parent.appendChild)
		{
		  parent.appendChild(oDiv);
		}
		else
		{
		  document.body.appendChild(oDiv);
		}
    }
    else if (typeof HTMLElement != 'undefined' && !HTMLElement.prototype.inserAdjacentElement)
    {
        var oTemp = document.createRange();
	oTemp.setStartAfter(parent ? parent : document.body);
	oDiv = oTemp.createContextualFragment("<a id='" + strId + "' class='" + strClass + "' title='" + strTitle + "' href='" + strHREF + "' onmouseover='" + fOver + "', onmouseout='" + fOut + "'>" + strInnerHTML + "</a>");
    }
    else
    {
	    return false;
	}
    SetPos(l, t, w, h, oDiv);
    return oDiv;
}

function MakeImage(l, t, w, h, strId, urlImg, strClass, parent)
{
    var oImg;
    if (document.createElement)
    {
        oImg = document.createElement("img");
	oImg.id = strId;
	oImg.className   = strClass;
	oImg.src         = urlImg;
    }
    else if (typeof HTMLElement != 'undefined' && !HTMLElement.prototype.inserAdjacentElement)
    {
        var oTemp = document.createRange();
	oTemp.setStartAfter(parent ? parent : document.body);
	oImg = oTemp.createContextualFragment("<img id='" + strId + "' class='" + strClass + "' src='" + urlImg + "' />");
    }
    else if (document.layers)
    {
      if (parent)
	  {
		oDiv = parent.images[strId] = new Image();
      }
	  else
	  {
	  	oDiv = document.images[strId] = new Image();
	  }
    }
    else
    {
	    return false;
	}
    SetPos(l, t, w, h, oImg);
    return oImg;
}

function getDivWidth(oDiv)
{
    if (oDiv.offsetWidth)                    {return oDiv.offsetWidth;}
    if (oDiv.style && oDiv.style.pixelWidth) {return oDiv.style.pixelWidth;}
    if (oDiv.clip && oDiv.clip.width)        {return oDiv.clip.width;}
    return 0;
}

function IntegerOnly(e)
{
    if ((e.keyCode < 48 || e.keyCode >  57) &&
        (e.keyCode < 96  || e.keyCode > 105) &&
        e.keyCode != 10  && e.keyCode != 13 && e.keyCode != 9 &&
        e.keyCode != 8   && e.keyCode != 46 &&
        e.keyCode != 37  && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40)
		{
          e.returnValue = false;
		}
}

function GetStyleRef(o)
{
	return o && o.style ? o.style : o;
}

function SetPos(l, t, w, h, o)
{
    if (l == null)
	{
		return;
	}
    var r = GetStyleRef(o);
    r.left   = l + "px";
    r.top    = t + "px";
    r.width  = w + "px";
    r.height = h + "px";
}

function GetPos(o)
{
  var o1 = GetStyleRef(o);
  var r = Object;
  r.left = o1.left;
  r.top  = o1.top;
  r.width = o1.width;
  r.height = o1.height;
  r.right = o1.left + o1.width;
  r.bottom = o1.top + o1.height;
  r.toString = function () { return "left = " + this.left + ", top = " + this.top + ", width = " + this.width + ", height = " + this.height; };
  return r;
}

function SetLeft(o, l)
{
    GetStyleRef(o).left = l;
}

function SetTop(o, t)
{
    GetStyleRef(o).top = t;
}

function SetWidth(o, w)
{
    GetStyleRef(o).width = w;
}

function SetHeight(o, h)
{
    GetStyleRef(o).height = h;
}

function SetBKColor(o, c)
{
    o = GetStyleRef(o);
    o.backgroundColor = c;
    o.background = c;
    o.bgColor = c;
}

function GetBKColor(o)
{
    o = GetStyleRef(o);
    if (o.backgroundColor)
	{
		return o.backgroundColor;
    }
	if (o.background)
	{
		return o.background;
	}
    return o.bgColor;
}

function SetVisible(o, bVisible)
{
    if (!o)
    {
	    return;
	}
    if (o.style)
    {
		if (bVisible === true)
		{
		    o.style.visibility = 'visible';
		}
		else
		{
		    o.style.visibility = 'hidden';
		}
	}
    else if (o.visibility)
    {
		if (bVisible === true)
		{
		    o.visibility = 'show';
		}
		else
		{
		    o.visibility = 'hide';
		}
    }
}

// These are just temporary functions for debugging purposes.
function RegisterTimer(strFunc, iSeconds, strCaller)
{
    var oTimer = setInterval(strFunc, iSeconds);
    return oTimer;
}

function UnregisterTimer(oTimer, strCaller)
{
    clearTimeout(oTimer);
}

function disable_right_click(e)
{
    window.status='';
    if (e && e.which && (e.which == 2 || e.which == 3))  {return false;}
    if (document.layers)  {return true;}
    if (window.event && window.event.button && (window.event.button == 2 || window.event.button == 3))  {return false;}
    return true;
}
function check_mousekey()
{
    var mouse_key = 93;
    var keycode = event.keyCode;
    if ( keycode == mouse_key )
    {
	    return false;
	}
	return;
}
function trap_page_mouse_key_events()
{
    document.onmousedown = disable_right_click;
	document.onkeydown = check_mousekey;
}

document.oncontextmenu = function() {return false; };

function GetShoppingElement(strElem)
{
	var x = window.top.document.forms[0];
	for (var i = 0; i < x.elements.length; i++)
	{
		if(x.elements[i].name === strElem)
		{
			return x.elements[i];
		}
	}
}

