

function onLoad( func )
{
        if (typeof window.addEventListener != 'undefined')
                window.addEventListener("load", func, false);
        else
                window.attachEvent("onload", func);
}


    /////////////////////////
    // Text Box Formatting //
    /////////////////////////

var _KEYCODE_ESC = 27;
var _KEYCODE_RETURN = 13;
var _KEYCODE_BACKSPACE = 8;
var _KEYCODE_DEL = 46;
var _KEYCODE_INS = 45;
var _KEYCODE_SPACE = 32;
var _KEYCODE_TAB = 9;
var _KEYCODE_SHIFT = 16;
var _KEYCODE_CTRL = 17;

var _KEYCODE_PAGEUP = 33;
var _KEYCODE_PAGEDOWN = 34;
var _KEYCODE_END = 35;
var _KEYCODE_HOME = 36;

var _KEYCODE_ARROW_LEFT = 37;
var _KEYCODE_ARROW_RIGHT = 39;
var _KEYCODE_ARROW_UP = 38;
var _KEYCODE_ARROW_DOWN = 40;

var _KEYCODE_NUMBERS = 48; // starting with "0"
var _KEYCODE_0 = 48;
var _KEYCODE_9 = _KEYCODE_0+9;

var _KEYCODE_A = 65;
var _KEYCODE_C = 67;
var _KEYCODE_G = 71;
var _KEYCODE_I = 73;
var _KEYCODE_J = 74;
var _KEYCODE_S = 83;
var _KEYCODE_T = 84;
var _KEYCODE_V = 86;
var _KEYCODE_X = 88;
var _KEYCODE_Z = 90;

var _KEYCODE_MINUS = 189;
var _KEYCODE_COMMA = 188;
var _KEYCODE_EQUAL = 187;
var _KEYCODE_TILDA = 192;
var _KEYCODE_FSLASH = 191;
var _KEYCODE_PERIOD = 190;
var _KEYCODE_BSLASH = 220;
var _KEYCODE_SEMICOLON = 186;
var _KEYCODE_APOS = 222;
var _KEYCODE_LBRACE = 219;
var _KEYCODE_RBRACE = 221;

function KeyCodeToChar()
{
  var key = event.keyCode;

  switch (key)
  {
    case _KEYCODE_ESC:
    case _KEYCODE_RETURN:
    case _KEYCODE_BACKSPACE:
    case _KEYCODE_DEL:
    case _KEYCODE_INS:
    case _KEYCODE_SHIFT:
    case _KEYCODE_CTRL:

    case _KEYCODE_PAGEUP:
    case _KEYCODE_PAGEDOWN:
    case _KEYCODE_END:
    case _KEYCODE_HOME:

    case _KEYCODE_ARROW_LEFT:
    case _KEYCODE_ARROW_RIGHT:
    case _KEYCODE_ARROW_UP:
    case _KEYCODE_ARROW_DOWN:
        return null;
  }

  var c = String.fromCharCode(key);
  if ( _KEYCODE_A <= key && key <= _KEYCODE_Z )
  {
    if (!event.shiftKey)
        c = c.toLowerCase();
  }
  else if ( _KEYCODE_0 <= key && key <= _KEYCODE_9 )
  {
    if (event.shiftKey)
    {
        switch ( key-_KEYCODE_0 )
        {
            case 0:  c = ")"; break;
            case 1:  c = "!"; break;
            case 2:  c = "@"; break;
            case 3:  c = "#"; break;
            case 4:  c = "$"; break;
            case 5:  c = "%"; break;
            case 6:  c = "^"; break;
            case 7:  c = "&"; break;
            case 8:  c = "*"; break;
            case 9:  c = "("; break;
        }
    }
  }
  else
  {
    switch ( key )
    {
      case _KEYCODE_MINUS:     c = (event.shiftKey?"_":"-"); break;
      case _KEYCODE_COMMA:     c = (event.shiftKey?",":","); break;
      case _KEYCODE_EQUAL:     c = (event.shiftKey?"+":"="); break;
      case _KEYCODE_TILDA:     c = (event.shiftKey?"~":"`"); break;
      case _KEYCODE_FSLASH:    c = (event.shiftKey?"?":"/"); break;
      case _KEYCODE_PERIOD:    c = (event.shiftKey?">":"."); break;
      case _KEYCODE_BSLASH:    c = (event.shiftKey?"|":"\\"); break;
      case _KEYCODE_SEMICOLON: c = (event.shiftKey?":":";"); break;
      case _KEYCODE_APOS:      c = (event.shiftKey?"\"":"'"); break;
      case _KEYCODE_LBRACE:    c = (event.shiftKey?"{":"["); break;
      case _KEYCODE_RBRACE:    c = (event.shiftKey?"}":"]"); break;
      default:                 c = null; break;
    }
  }
  
  return c;
}

function OnEsc( func )
{
    if (event.keyCode == _KEYCODE_ESC) 
    {
        func();

        event.keyCode = _KEYCODE_BACKSPACE;
        event.cancelBubble = true;
        event.returnValue = false;
        return false;
    }
}
function OnEnter( func )
{
    if (event.keyCode == _KEYCODE_RETURN) 
    {
        func();

        event.keyCode = _KEYCODE_BACKSPACE;
        event.cancelBubble = true;
        event.returnValue = false;
        return false;
    }
    else
        return true;
}
function AllowOnly( reMask )
{
  var c = KeyCodeToChar();
  if (c == null)
    return;

  if (reMask.test(c) == false)
  {
    event.keyCode = 0;
    event.cancelBubble = true;
    event.returnValue = false;
    return false;
  }
  else
    return true;
}

function CancelBubble()
{
    event.cancelBubble = true;
    return false;
}



function GetCaretWord()
{
    var range = document.selection.createRange().duplicate();

    var len = range.text.length;
    range.moveStart('character', -1);
    while ( _isTableChar( range.text.charAt(0) ) && len != range.text.length)
    {
        len = range.text.length;
        range.moveStart('character', -1);
    }
    if (len != range.text.length)
        range.moveStart('character', 1);


    var len = range.text.length;
    range.moveEnd('character', 1);
    while ( _isTableChar( range.text.charAt(range.text.length-1) ) && len != range.text.length)
    {
        len = range.text.length;
        range.moveEnd('character', 1);
    }
    if (len != range.text.length)
        range.moveEnd('character', -1);
    return range.text;
}
    function _isTableChar( c )
    {
        return c.match(_re_tableChar);
    }
    var _re_tableChar = /[a-zA-Z0-9_]/;



function convertUpperCase(keyItem) 
{
	setTimeout(function()
	    {
	        keyItem.value = keyItem.value.toUpperCase();
	    }, 
	    1);
}
function uppercaseOnFly()
{
	var key = GetKeyCode();
	if ((key > 0x60) && (key < 0x7B))
		SetKeyCode(key-0x20);
}

function GetKeyCode()
{
	var g=(document.layers)?h.which:event.keyCode;
	return g;
}

// Non-IE browsers define keyCode as being read-only 
// so we need to change the value in the target instead
function SetKeyCode( keyCode )
{
	//if IE simply assign the keyCode, ignore if keycode is 8 (backspace)
    if (event.keyCode)
    {
        event.keyCode = keyCode;
    }
    else
    {
		var newText = String.fromCharCode(keyCode);
		// cancel the key event and insert the newKey for the current selection
		if (event.preventDefault)
			event.preventDefault();
		
		if(key != 0)
		{
			//if we don't get the end and start we will be changing the key at position 0 all the time
			var oldSelectionStart = event.target.selectionStart;
			var oldSelectionEnd = event.target.selectionEnd;

			//assign the new key as the value
			event.target.value = event.target.value.substring(0, oldSelectionStart) + newText + event.target.value.substring(oldSelectionEnd);

			//set cursor to the end of the text
			event.target.setSelectionRange(oldSelectionStart + newText.length, oldSelectionStart + newText.length);
		}

    }
}

function cancelBubble(e)
{
  if (window.event)
    window.event.cancelBubble = true;
  if (e && e.stopPropagation)
    e.stopPropagation();
}

function cancelDefault(e)
{
  if (window.event && window.event.returnValue)
    window.event.returnValue = false;
  if (e && e.preventDefault)
    e.preventDefault();
}

function cancelAll(e)
{
  cancelBubble(e);
  cancelDefault(e);
}

function checkForClickableActiveElements(target,tagName)
{
    if(tagName == "input")
    {
        if(target.type == "button" ||
           target.type == "image" ||
           target.type == "submit" ||
           target.type == "reset")
        {
           return true;
        }
        return false;
    }
    if(tagName == "a" || tagName == "img" || tagName == "button" || tagName == "textarea")
        return true;
    return false;
}



    ////////////////////
    // Other Controls //

function GetRadioValue( radioInputs )
{
    var inx;
    for (inx = 0; inx < radioInputs.length; inx++)
    {
        var rb = radioInputs[inx];
        if ( rb.checked )
            return rb.value;
    }
    return null;
}
function SetRadioValue( radioInputs, newValue )
{
    var inx;
    for (inx = 0; inx < radioInputs.length; inx++)
    {
        var rb = radioInputs[inx];
        if ( rb.value == newValue )
            rb.checked = true;
    }
    return null;
}

function CheckboxClickEventHandler( div )
{
    return function()
    {
        if (event.srcElement.nodeName == "INPUT")
            return;
        var chckBox = div.childNodes[0];
        chckBox.checked = !chckBox.checked;
    };
}


    /////////////////////
    // Styles & Layout //

function ColorDensity( percentOfMax, rPercentage, gPercentage, bPercentage )
{
    var maxValue = (16*16)-1; // or 255
    var color = maxValue * percentOfMax;
    var luminosity = (maxValue/1.2) * (1-percentOfMax);
    var r = ToHex2( luminosity + (color*rPercentage) );
    var g = ToHex2( luminosity + (color*gPercentage));
    var b = ToHex2( luminosity + (color*bPercentage) );
    return "#"+r+g+b;
}

function ColorDensity2(val, max, zeroColor, rPercentage, gPercentage, bPercentage)
{
    var flooredVal = (val > max) ? max : val;
    var percentOfMax = flooredVal / max;
    
    var color;
    if ( val == 0 )
        color = zeroColor;
    else
        color = ColorDensity( percentOfMax, rPercentage, gPercentage, bPercentage );

    return color;
}

function getPixels( px )
{
    return parseInt(px.substr(0, px.indexOf("px")));
}
function addPixels( px, add )
{
    return ( getPixels(px) + add ) + "px";
}




    //////////
    // Tabs //

function MenuTabs( tabs )
{
    this.tabs = tabs;
    this.currentTab = null;

    this.Init();
}

MenuTabs.prototype.Init = function()
{
    var inx;
    for (inx = 0; inx < this.tabs.length; inx++)
    {
        var tab = this.tabs[inx];
        tab.inx = inx;

        if ( tab.tr )
        {
            while ( tab.tr.cells.length > 0 )
                tab.tr.deleteCell();
        }
        else
        {
            var t = document.createElement("TABLE");
            t.cellPadding = "0";
            t.cellSpacing = "0";

            var mainTD = document.getElementById( tab.id );
            mainTD.insertBefore( t, mainTD.firstChild );

            tab.tr = t.insertRow();
        }

        tab.otherTDsByInx = [];

        var jnx;
        for (jnx = 0; jnx < this.tabs.length; jnx++)
        {
            var otherTab = this.tabs[jnx];

            var td = tab.tr.insertCell();
            td.noWrap = true;
            td.innerHTML = "&nbsp;"+otherTab.title+"&nbsp;";
            if (inx == jnx)
                this._makeSelectedTd( td );
            else
                this._makeUnselectedTd( td, jnx );

            // If there are two consecutive tabs, not selected.
            if ( jnx+1 < this.tabs.length && jnx != inx && jnx+1 != inx )
                // Then but a divider between them
                td.style.borderRight = "ridge 1px black";

            tab.otherTDsByInx[ jnx ] = td;
        }

        var td = tab.tr.insertCell();
        td.width = "100%";
        td.innerHTML = "&nbsp;";
        td.style.borderBottom = "ridge 1px black";
    }
}

MenuTabs.prototype._makeSelectedTd = function( td )
{
    td.style.backgroundColor = "lightsteelblue";
    td.style.borderBottom = "ridge 0px black";
    td.style.borderLeft = "ridge 1px black";
    td.style.borderTop = "ridge 1px black";
    td.style.borderRight = "ridge 1px black";

    td.onmouseover = null;
    td.onmouseout = null;
    td.onclick = null;

}
MenuTabs.prototype._makeUnselectedTd = function( td, selectedInx )
{
    td.style.backgroundColor = "";
    td.style.borderBottom = "ridge 1px black";
    td.style.borderLeft = "ridge 0px black";
    td.style.borderTop = "ridge 0px black";
    td.style.borderRight = "ridge 0px black";

    td.onmouseover = MouseOver( td );
    td.onmouseout = MouseOut( td );
    
    var _this = this;
    td.onclick = function ()
                 {
                    _this.Select( selectedInx );
                 };
}

MenuTabs.prototype.Select = function(selectedInx)
{
    this.currentTab = this.tabs[selectedInx];
    
    if ( this.currentTab.intervalID )
        this.StopFlash( this.currentTab );

    var inx;
    for (inx = 0; inx < this.tabs.length; inx++)
    {
        var tab = this.tabs[inx];
        var td = document.getElementById(tab.id);
        td.style.display = (inx == selectedInx) ? "block" : "none";
    }
}

MenuTabs.prototype.AddTab = function( menuTab )
{
    var selectedTabInx = (this.currentTab) ? this.currentTab.inx : 0;

    this.tabs.push( menuTab );
    this.Init();

    this.Select(selectedTabInx);

    return menuTab;
}

MenuTabs.prototype.FlashTab = function(selectedInx)
{
    var tab = this.tabs[selectedInx];
    if (tab.intervalID > -1)
        return; // already flashing

    tab.flashColor = "";

    var _this = this;
    tab.intervalID = setInterval( function()
    {
        tab.flashColor = (tab.flashColor=="") ? "red" : "";
        var inx;
        for (inx = 0; inx < _this.tabs.length; inx++)
        {
            var otherTab = _this.tabs[inx];
            if ( otherTab === tab )
                continue;

            var td = otherTab.otherTDsByInx[ selectedInx ];
            td.style.backgroundColor = tab.flashColor;
        }
    }, 500);
}
MenuTabs.prototype.StopFlash = function( tab )
{
    clearInterval( tab.intervalID );
    tab.intervalID = -1;

    var inx;
    for (inx = 0; inx < this.tabs.length; inx++)
    {
        var otherTab = this.tabs[inx];
            if ( otherTab === tab )
                continue;

        var td = otherTab.otherTDsByInx[ tab.inx ];
        td.style.backgroundColor = "";
    }
}




function MouseOver( cell )
{
    return function()
    {
        cell.style.textDecoration = "underline";
        cell.style.cursor = "pointer";
        cell.style.color = "blue";
    };
}
function MouseOut( cell )
{
    return function()
    {
        cell.style.textDecoration = "none";
        cell.style.cursor = "auto";
        cell.style.color = "black";
    };
}






    ////////////
    // Pop-Up //

function PopUp( args )
{
    var w = ( args.width ) ? args.width : 400;
    var h = ( args.height ) ? args.height : 400;
    var color = ( args.color ) ? args.color : "#FAF2FF"; // "#DEEEEF";
    var opacity = ( args.opacity ) ? args.opacity : 92;
    this.onOpen = ( args.onOpen )?args.onOpen:function(){};
    this.onBeforeClose = ( args.onBeforeClose )?args.onBeforeClose:function(){return true;};
    this.onClose = ( args.onClose )?args.onClose:function(){};
    
    var div = document.createElement("DIV");
    this.div = div;

    div.style.position = "absolute";
    div.style.display = "none";

    var t = document.createElement("TABLE");
    this.t = t;
    div.appendChild(t);
    t.cellPadding = "0px";
    t.cellSpacing = "0px";
    t.border = "0px";
    t.width = w+"px";
    
    // Title & Close Button
    var tr = t.insertRow();
    var td = tr.insertCell();
    var b = document.createElement("B");
    this.b = b;
    td.appendChild(b);
    b.style.backgroundColor = color ;
    b.style.filter = "alpha(opacity="+opacity+")";

    var td = tr.insertCell();
    td.align="right";
    td.vAlign="bottom";
    if ( !args.noCloseButton )
    {
        var span = document.createElement("SPAN");
        td.appendChild(span);
        span.innerHTML = "&nbsp;X&nbsp;";
        span.style.cursor = "hand";
        span.onclick = (function(pUp){
        	    return function()
        	    {
        	        pUp.Close();
        	    }
	    })(this);
        span.style.backgroundColor = color ;
        span.style.filter = "alpha(opacity="+opacity+")";
    }

    // Middle Row - left/right border and contents
    var tr = t.insertRow();
    
    var td = tr.insertCell();
    td.colSpan=2;
    td.style.verticalAlign = "top";
    td.width="100%";
    var div2 = document.createElement("DIV");
    td.appendChild(div2);
    div2.style.height=h+"pt";
    this.contentArea = div2;
    td.style.backgroundColor = color ;
    td.style.filter = "alpha(opacity="+opacity+")";

    document.body.appendChild(this.div);
}


PopUp.prototype.SetPosition = function (pp)
{
    this.div.style.left = pp.x+"px";
    this.div.style.top = pp.y+"px";
}
PopUp.prototype.SetTitle = function (title)
{
    this.b.innerHTML = "&nbsp;&nbsp;"+title+"&nbsp;&nbsp;";
}
PopUp.prototype.SetBody = function (body)
{
    this.contentArea.innerHTML = body;
}
PopUp.prototype.IsOpen = function ()
{
    return (this.div.style.display != "none");
}

PopUp.prototype.Open = function ()
{
    this.inx = popupStack.length;
    popupStack.push( this );
    this.div.style.display = "block";
    MakeModal( this.div );
    this.onOpen();
}
PopUp.prototype.Close = function ()
{
    if ( !this.IsOpen() )
        return;

    if ( !this.onBeforeClose() )
        return;

    popupStack.splice( this.inx, 1 );
    if ( popupStack.length == 0 )
        UndoModal();
    this.div.style.display = "none";
    this.onClose();
}

var popupStack = new Array();

function CurrentPopup()
{
    if (popupStack.length == 0)
        return null;
    return popupStack[popupStack.length-1];
}




    ///////////////////////
    // X & Y Positioning //

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function GetCellWidth( cell )
{
	var t = document.createElement("TABLE");
	document.body.appendChild( t );

	var tr = t.insertRow();

	var cCopy = tr.insertCell();
	cCopy.innerHTML = cell.innerHTML;
	cCopy.className = cell.className;

	var other = tr.insertCell();
	var greatestWidth = other.offsetLeft;

	// Put it back under its original parent at the same index.
	document.body.removeChild( t );

	return greatestWidth;
}

function PagePosition()
{
    this.x = 0;
    this.y = 0;
}
PagePosition.Relative = function ( e, xOffset, yOffset )
{
    if (!e)
        e = event.srcElement;

    var pp = new PagePosition();
    pp.x = findPosX(e);
    pp.y = findPosY(e);

    if (typeof(xOffset) != "undefined")
        pp.x += xOffset;
    if (typeof(yOffset) != "undefined")
        pp.y += yOffset;

    return pp;
}
PagePosition.Absolute = function ( x, y )
{
    var pp = new PagePosition();
    pp.x = x;
    pp.y = y;

    return pp;
}

PagePosition.GetCaretPosition = function ()
{
    var range = document.selection.createRange().duplicate();
    return PagePosition.Absolute( range.offsetLeft, range.offsetTop+15 );
}


// Gets the full width/height because it's different for most browsers.
function getViewportHeight() 
{
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}
function getViewportWidth() 
{
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}

// Gets the real scroll top
function getScrollTop() 
{
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() 
{
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}






	/////////////////////
	// Screen Scraping //

function CleanHTML( url, data )
{
    var cleanHTML = "";
    var rest = data;

    if ( rest.match( /<body[^>]*>/i ) )
        rest = rest.substr(RegExp.lastIndex);


    while (rest && rest.match(/<([^>]+?)>/m))
    {
        var pre = rest.substr(0, RegExp.index);
        var tag = RegExp.$1 ;
        rest = rest.substr(RegExp.lastIndex);

        cleanHTML += pre;

        var isCloser = false;
        if (tag.charAt(0) == '/')
        {
	        tag = tag.substr(1);
	        isCloser = true;
        }

        if (!tag.match(/^([a-zA-Z]+)(.*)$/m))
	        continue;

        var nodeName = RegExp.$1.toUpperCase();
        var nodeRest = RegExp.$2;

        if (nodeName == "A")
        {
	        if ( isCloser )
		        cleanHTML += "</a>";
	        else if ( nodeRest.match(/href="([^"]+)"/i) || nodeRest.match(/href='([^']+)'/i)  )
	        {
	            var href = RegExp.$1;
	            if (href.match(/^ *javascript:/i))
		    {
		    }
    		    else
    		    {
    		        var baseUrl;
    		        var folderUrl;
		            if (url.match("(.+?://.+?/)(.*)"))
		            {
    		            baseUrl = RegExp.$1;
    		            folderUrl = RegExp.$2;

    		            if (folderUrl.charAt(folderUrl.length-1) != '/')
    		            {
    		                var inx = folderUrl.lastIndexOf('/');
    		                folderUrl = folderUrl.substr(0, inx);
    		            }
    		            folderUrl = baseUrl+folderUrl;
    		        }
    		        else
    		        {
    		            baseUrl = url+"/";
    		            folderUrl = baseUrl;
                    }

    		        if (href.charAt(0) == '/')
    		            href = baseUrl+href;
    		        else
    		            href = folderUrl+"/"+href;
	            }

		        cleanHTML += "<a href="+HtmlStringLiteral(href)+" target='_blank'>";
		    }
        }
        else
	        cleanHTML += (isCloser) ? "</"+nodeName+">" : "<"+nodeName+" "+nodeRest+">";
    }

    return cleanHTML+rest;
}



    ///////////
    // Modal //

function MakeModal( e )
{
    _InitModal();

    _modalElement = e;

	disableTabIndexes();

    _modalElement.style.zIndex = 201;
	_ModalMask.style.display = "block";

    // Set the Mask Size - use either the scroll's H/W or viewport's H/W.
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	var theBody = document.getElementsByTagName("BODY")[0];
	var popHeight = Math.max(fullHeight, theBody.scrollHeight);
	var popWidth = Math.max(fullWidth, theBody.scrollWidth);
	_ModalMask.style.height = popHeight + "px";
	_ModalMask.style.width = popWidth + "px";

	if (_HideSelects)
		hideSelectBoxes();
}

function UndoModal() 
{
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "";

	restoreTabIndexes();

    _modalElement.zIndex = 1;
	_ModalMask.style.display = "none";

	// display all select boxes
	if (_HideSelects)
		displaySelectBoxes();
}


    var _modalElement;

    // If using Mozilla or Firefox, use Tab-key trap.
    if (!document.all)
	    document.onkeypress = 
            function (e) 
            {   // iff in modal mode and key was [TAB], suppress it.
                if (_inModalMode() && e.keyCode == 9)  return false;
            };

    function _InitModal() 
    {
        if (_ModalMask)
            return;
            
	    // Add the HTML to the body
	    var theBody = document.getElementsByTagName('BODY')[0];

	    _ModalMask = document.createElement('div');
	    theBody.appendChild(_ModalMask);
	    _ModalMask.style.position = "absolute";
	    _ModalMask.style.zIndex = 200;
	    _ModalMask.style.top = "0px";
	    _ModalMask.style.left = "0px";
	    _ModalMask.style.width = "100%";
	    _ModalMask.style.height = "100%";
	    _ModalMask.style.opacity = ".4";
	    _ModalMask.style.filter = "alpha(opacity=65)";
	    _ModalMask.style.backgroundColor = "#999999";
	    _ModalMask.style.display = "none";

	    _HideSelects = (window.navigator.userAgent.indexOf("MSIE") > -1)
    }
    var _ModalMask = null;
    var _HideSelects;

    function _inModalMode()
    {
        return _ModalMask.style.display == "block";
    }

    // Pre-defined list of tags we want to disable/enable tabbing into
    var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	
    var gTabIndexes = new Array();

    // For IE.  Go through predefined tags and disable tabbing into them.
    function disableTabIndexes() {
	    if (document.all) {
		    var i = 0;
		    for (var j = 0; j < gTabbableTags.length; j++) {
			    var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			    for (var k = 0 ; k < tagElements.length; k++) {
				    gTabIndexes[i] = tagElements[k].tabIndex;
				    tagElements[k].tabIndex="-1";
				    i++;
			    }
		    }
	    }
    }

    // For IE. Restore tab-indexes.
    function restoreTabIndexes() {
	    if (document.all) {
		    var i = 0;
		    for (var j = 0; j < gTabbableTags.length; j++) {
			    var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			    for (var k = 0 ; k < tagElements.length; k++) {
				    tagElements[k].tabIndex = gTabIndexes[i];
				    tagElements[k].tabEnabled = true;
				    i++;
			    }
		    }
	    }
    }


    function hideSelectBoxes() 
    {
	    var tagElements = document.getElementsByTagName("SELECT");
	    for(var inx = 0; inx < tagElements.length; inx++)
	    {
	        var e = tagElements[inx];

            // Do not hide SELECT's that are in the pop-up.
            var skipIt = false;
	        var p = e.parentNode;
	        while ( p != null )
	        {
	            if (p == _modalElement)
	            {
	                skipIt = true;
	                break;
	            }
		        p = p.parentNode;
		    }
	        if (skipIt)
	            continue;

            // Remember the original visibility value, so that we do not show SELECT's in UndoModal that were initially hidden.
		    e.style._origVisibility=tagElements[inx].style.visibility;

            // Hide the SELECT.
		    e.style.visibility="hidden";
		}
    }

    function displaySelectBoxes() 
    {
	    var tagElements = document.getElementsByTagName("SELECT");
	    for(var inx = 0; inx < tagElements.length; inx++)
	    {
	        var e = tagElements[inx];
		    e.style.visibility=e.style._origVisibility;
		}
    }

