var isIE       = navigator.appVersion.indexOf ("MSIE") != -1;
var isIE4      = navigator.appVersion.indexOf ("MSIE 4.0") != -1;
var isIE5      = navigator.appVersion.indexOf ("MSIE 5.0") != -1;
var isIE55     = navigator.appVersion.indexOf ("MSIE 5.5") != -1;
var isIE6      = navigator.appVersion.indexOf ("MSIE 6.0") != -1;
var isOpera    = navigator.appName.indexOf ("Opera") != -1 || navigator.userAgent.indexOf ("Opera") != -1;
var isDOM      = (parseInt (navigator.appVersion) >= 5) || isIE5 || isIE55 || isIE6 || isOpera;
var isMozilla  = (navigator.appName.indexOf ("Netscape") != -1) && isDOM;
var isNetscape = ! (isIE || isOpera || isDOM);
var isIEMac    = navigator.appVersion.indexOf ("Macintosh") != -1;

if (isOpera)	// Opera 7 works perfect as Mozilla
{
	isMozilla = true;
	isIE = isIE4 = isIE5 = isIE55 = isIE6 = false;
}

////////////////////////////////////////////////////////////////////////
//	This makes sure that a page with DHTML is still working in NS if
//	the user resizes the page.

function reDo ()
{
	if (origWidth != innerWidth || origHeight != innerHeight)
		location.reload();
}

if (isNetscape)
{
	origWidth  = innerWidth;
	origHeight = innerHeight;
	onresize   = reDo;
}

function dump (object)
{
	var str = "";
	for (var i in object)
		str += i + ":" + object[i] + "\n";
	alert (str);
}

//
////////////////////////////////////////////////////////////////////////

MOUSEDOWN = isNetscape ? Event.MOUSEDOWN : 0x00001;
MOUSEUP   = isNetscape ? Event.MOUSEUP   : 0x00002;
MOUSEOVER = isNetscape ? Event.MOUSEOVER : 0x00004;
MOUSEOUT  = isNetscape ? Event.MOUSEOUT  : 0x00008;
MOUSEMOVE = isNetscape ? Event.MOUSEMOVE : 0x00010;
LOAD      = isNetscape ? Event.LOAD      : 0x80000;

////////////////////////////////////////////////////////////////////////
//
//	WindowX
//
////////////////////////////////////////////////////////////////////////

WindowX.all    = new Array ();
WindowX.add    = WindowX_add;
WindowX.lookup = WindowX_lookup;

function WindowX_add (win)
{
	for (i = 0; i < WindowX.all.length; i++)
	{
		if (WindowX.all[i].window == win.window)
			return;
	}
	WindowX.all[WindowX.all.length] = win;
}


function WindowX_lookup (win)
{
	for (i = 0; i < WindowX.all.length; i++)
	{
		if (WindowX.all[i].window == win)
		{
			// Update the document cause it may have changed
			WindowX.all[i].document = WindowX.all[i].window.document;
			return WindowX.all[i];
		}
	}
	var winX = new WindowX (win);
	WindowX.add (winX);
	return winX;
}

// PRIVATE !!!
function WindowX (aNSWindow, aIEWindow)
{
	// Declare instance methods ...
	//
	this.getScrollLeft      = getScrollLeft;
	this.getScrollTop       = getScrollTop;
	this.scrollTo           = scrollTo;
	this.getWidth           = getWidth;
	this.getHeight          = getHeight;
	this.setTimeout					= setTimeout;
	this.clearTimeout       = clearTimeout;
	this.insertLayer        = insertLayer;
	this.setBackgroundColor = setBackgroundColor;
	// Event handling functions
	// DEPRECATED: Use the eventlistener functions instead!
	this.setMouseDown       = setMouseDown;
	this.setMouseUp         = setMouseUp;
	this.setMouseOver       = setMouseOver;
	this.setMouseOut        = setMouseOut;
	this.setMouseMove       = setMouseMove;
	this.setLoad            = setLoad;
	this.setUnload          = setUnload;
	this.getMouseDown       = getMouseDown;
	this.captureEvents      = captureEvents;
	this.releaseEvents      = releaseEvents;
	//
	this.addEventListener        = addEventListener;
	this.removeEventListener     = removeEventListener;
	this.removeAllEventListeners = removeAllEventListeners;

	this.hasEventListeners = false;
	this.eventListeners = [];
	this.window = aNSWindow.document ? aNSWindow : aIEWindow;
	this.document = this.window.document;


	function getScrollLeft ()
	{
		return isIE ? this.document.body.scrollLeft : this.window.pageXOffset;
	}


	function getScrollTop ()
	{
		return isIE ? this.document.body.scrollTop : this.window.pageYOffset;
	}


	function scrollTo (posX, posY)
	{
		if (isIE)
		{
			this.document.body.scrollLeft = posX;
			this.document.body.scrollTop  = posY;
		}
		else
			this.window.scrollTo (posX, posY);
	}


	function getWidth ()
	{
		return isIE ? this.document.body.offsetWidth : (this.window.innerWidth + (isNetscape ? 4 : 0));
	}


	function getHeight ()
	{
		return isIE ? this.document.body.offsetHeight : (this.window.innerHeight + (isNetscape ? 4 : 0));
	}


	function setTimeout (command, delay)
	{
		return this.window.setTimeout (command, delay);
	}


	function clearTimeout (handle)
	{
		this.window.clearTimeout (handle);
	}


	function insertLayer (name)
	{
		var rl;
		if (isNetscape)
			rl = new Layer (200, this.window);
		else if (isMozilla)
		{
			var div = this.document.createElement ("DIV");
			div.setAttribute ("id", name);
			div.setAttribute ("style", "position:absolute;visibility:hidden;");
			this.document.body.appendChild (div);
			rl = name;
		}
		else
		{
			var str = '<div id=' + name + ' style="position:absolute;"></div>';
			this.document.body.insertAdjacentHTML ("AfterBegin", str);
			rl = this.document.all[name];
		}
		return new LayerX (rl, this.document);
	}


	function setBackgroundColor (color)
	{
		if (isNetscape || isMozilla)
			this.document.bgColor = color;
		else
			this.document.body.style.backgroundColor = color;
	}


	function setMouseDown (handler)
	{
		if (isNetscape)
			this.window.onmousedown = handler;
//		else
			this.document.onmousedown = handler;
	}


	function setMouseUp (handler)
	{
		if (isNetscape)
			this.window.onmouseup = handler;
		else
			this.document.onmouseup = handler;
	}


	function setMouseOver (handler)
	{
		if (isNetscape)
			this.window.onmouseover = handler;
		else
			this.document.onmouseover = handler;
	}


	function setMouseOut (handler)
	{
		if (isNetscape)
			this.window.onmouseout = handler;
		else
			this.document.onmouseout = handler;
	}


	function setMouseMove (handler)
	{
		if (isNetscape)
			this.window.onmousemove = handler;
		else
			this.document.onmousemove = handler;
	}


	function setLoad (handler)
	{
		if (isIE)
			this.document.body.onload = handler;
		else
			this.window.onload = handler;
	}


	function setUnload (handler)
	{
		if (isIE)
			this.document.body.onunload = handler;
		else
			this.window.onunload = handler;
	}


	function getMouseDown ()
	{
		return this.document.onmousedown;
	}


	function captureEvents (eventIds)
	{
		if (isNetscape)
			this.window.captureEvents (eventIds);
	}


	function releaseEvents (eventIds)
	{
		if (isNetscape)
			this.window.releaseEvents (eventIds);
	}


	function addEventListener (listener)
	{
		if (! this.hasEventListeners)
		{
			this.hasEventListeners = true;
			this.captureEvents (MOUSEDOWN | MOUSEUP | MOUSEMOVE | MOUSEOVER | MOUSEOUT);
			// | Event.CLICK | Event.DBLCLICK
			this.setMouseDown (notify);
			this.setMouseUp (notify);
			this.setMouseOver (notify);
			this.setMouseOut (notify);
			this.setMouseMove (notify);
			// This is not very user friendly
			if (isIE && !isIE4)
				window.oncontextmenu = function () { return false; };
		}
		for (var i in this.eventListeners)
		{
			if (this.eventListeners[i] == listener)
				return;
		}
		this.eventListeners[this.eventListeners.length] = listener;
	}
	
	
	function removeEventListener (listener)
	{
		var index = -1;
		for (var i = 0; i < this.eventListeners.length; i++)
		{
			if (this.eventListeners[i] == listener)
			{
				for (var x = i; x < this.eventListeners.length - 1; x++)
					this.eventListeners[x] = this.eventListeners[x + 1];
				this.eventListeners.length -= 1;
				break;
			}
		}
	}
	
	
	function removeAllEventListeners ()
	{
		if (! this.hasEventListeners)
			return;
		this.eventListeners = [];
		this.hasEventListeners = false;
	}
	
	
	function notify (event)
	{
		var ex = new EventX (event, window);
		var win = WindowX.lookup (window);
		var result = false;
		if (win != null)
		{
			var src = ex.getCalculatedSource ();
			for (var i = 0; i < win.eventListeners.length; i++)
			{
				r = win.eventListeners[i].notify (src, ex);
				if (r)
					result = true;
			}
		}
	
		ex.cancelBubble ();
		return result;
	}
}


////////////////////////////////////////////////////////////////////////
//
//	LayerX
//
////////////////////////////////////////////////////////////////////////

function LayerX (aNameOrLayer, aDocument)
{
	// Declare instance methods ...
	//
	this.get                = get;
	this.clip               = clip;
	this.move               = move;
	this.setVisible         = setVisible;
	this.isVisible          = isVisible;
	this.setDisplay         = setDisplay;
	this.getDisplay         = getDisplay;
	this.setColor           = setColor;
	this.setZIndex          = setZIndex;
	this.setBackgroundColor = setBackgroundColor;
	this.setBackgroundImage = setBackgroundImage;
	this.getImage           = getImage;
	this.moveAbove          = moveAbove;
	this.getPageX						= getPageX;
	this.getPageY						= getPageY;
	this.getWidth						= getWidth;
	this.getHeight					= getHeight;
	this.isInside           = isInside;
	this.replaceHtml        = replaceHtml;
	this.setCursor          = setCursor;
	this.noDragAndDrop      = noDragAndDrop;

	// Event handling functions
	// Don't use them: Use the listener functions in window instead!
	this.setMouseDown       = setMouseDown;
	this.setMouseUp         = setMouseUp;
	this.setMouseMove       = setMouseMove;
	this.setMouseOver       = setMouseOver;
	this.captureEvents      = captureEvents;
	this.releaseEvents      = releaseEvents;


	this.document = aDocument ? aDocument : document;
	this.layer = aNameOrLayer.document ? aNameOrLayer : this.get (aNameOrLayer);


	function get (name)
	{
		if (isDOM)
			return this.document.getElementById (name);
		return isNetscape ? this.document.layers [name] : this.document.all [name];
	}


	function clip (x, y, w, h)
	{
		if (isNetscape)
		{
			this.layer.clip.left   = x;
			this.layer.clip.top    = y;
			this.layer.clip.right  = x + w;
			this.layer.clip.bottom = y + h;
		}
		else
			this.layer.style.clip = "rect(" + y + " " + (x + w) + " " + (y + h) + " " + x + ")";
	}


	function move (x, y, w, h)
	{
		if (isNetscape)
		{
			this.layer.moveTo (x, y);
			if (w && h) this.layer.resizeTo (w, h);
		}
		else
		{
			this.layer.style.left = x + "px";
			this.layer.style.top  = y + "px";
			if (w) this.layer.style.width  = w + "px";
			if (h) this.layer.style.height = h + "px";
		}
	}


	function setVisible (show)
	{
		if (isNetscape)
			this.layer.visibility = show ? 'visible' : 'hidden';
		else
			this.layer.style.visibility = show ? 'visible' : 'hidden';
	}


	function isVisible ()
	{
		return isNetscape ? (this.layer.visibility == 'show') : (this.layer.style.visibility == 'visible');
	}

	
	function setDisplay (display)
	{
		if (isNetscape)
			this.layer.display = display;
		else
			this.layer.style.display = display;
	}


	function getDisplay ()
	{
		return isNetscape ? this.layer.display : this.layer.style.display;
	}


	// Does not change the layout in NS, a new write is required!
	function setColor (color)
	{
		if (isNetscape)
			this.layer.fgColor = color;
		else
			this.layer.style.color = color;
	}
	
	
	function setZIndex (zIndex)
	{
		if (isNetscape)
			this.layer.zIndex = zIndex;
		else
			this.layer.style.zIndex = zIndex;
	}


	function setBackgroundColor (color)
	{
		if (isNetscape)
			this.layer.bgColor = color;
		else
			this.layer.style.backgroundColor = color;
	}


	function setBackgroundImage (image)
	{
		if (isNetscape)
			this.layer.background.src = image;
		else
			this.layer.style.backgroundImage = "url(" + image + ")";
	}


	// To make this work with all browsers 'id' AND 'name' of <img> must be set!
	function getImage (name)
	{
		if (isDOM)
			return this.document.getElementById (name);
		return this.layer.document.images[name];
	}


	// To make this work z-index must not be set via stylesheets (except in NS)!
	function moveAbove (otherLayer)
	{
		if (isNetscape)
			this.layer.moveAbove (otherLayer.layer);
		else
			this.layer.style.zIndex = otherLayer.layer.style.zIndex + 1;
	}


	function getPageX ()
	{
		return isNetscape ? this.layer.pageX : this.layer.offsetLeft;
	}


	function getPageY ()
	{
		return isNetscape ? this.layer.pageY : this.layer.offsetTop;
	}


	function getWidth ()
	{
		return isNetscape ? this.layer.clip.width :
						 (isDOM ? this.layer.offsetWidth : this.layer.scrollWidth);
	}


	function getHeight ()
	{
		return isNetscape ? this.layer.clip.height :
						 (isDOM ? this.layer.offsetHeight : this.layer.scrollHeight);
	}


	function isInside (aX, aY)
	{
		return (this.getPageX () <= aX && aX <= this.getPageX () + this.getWidth ()) &&
					 (this.getPageY () <= aY && aY <= this.getPageY () + this.getHeight ());
	}


	function replaceHtml (htmlCode)
	{
		if (isNetscape)
		{
			this.layer.document.write (htmlCode);
			this.layer.document.close ();
		}
		else
			this.layer.innerHTML = htmlCode;
	}


	function setCursor (cursor)
	{
		if (isIE)
			this.layer.style.cursor = cursor;
	}


	function setMouseDown (handler)
	{
		this.layer.onmousedown = handler;
	}


	function setMouseUp (handler)
	{
		this.layer.onmouseup = handler;
	}


	function setMouseMove (handler)
	{
		this.layer.onmousemove = handler;
	}


	function setMouseOver (handler)
	{
		this.layer.onmouseover = handler;
	}


	function captureEvents (eventIds)
	{
		if (isNetscape)
			this.layer.captureEvents (eventIds);
	}


	function releaseEvents (eventIds)
	{
		if (isNetscape)
			this.layer.releaseEvents (eventIds);
	}
	

	function noDragAndDrop ()
	{
		if (isIE)
			this.layer.onselectstart = this.layer.ondragstart = function () { return false; };
		else if (isMozilla)
			this.layer.addEventListener ("draggesture", function (aEvent) { aEvent.cancelBubble = true; }, false);
	}
}


////////////////////////////////////////////////////////////////////////
//
//	EventX
//
////////////////////////////////////////////////////////////////////////

EventX.LEFTBUTTON   = 0;
EventX.MIDDLEBUTTON = 1;
EventX.RIGHTBUTTON  = 2;

function EventX (anNSEvent, aWindow)
{
	// Public
	//
	this.x                   = x;
	this.y                   = y;
	this.getType             = getType;
	this.getSource           = getSource;
	this.getCalculatedSource = getCalculatedSource;
	this.isLeftButtonDown    = isLeftButtonDown;
	this.whichButton         = whichButton;
	this.isAltDown           = isAltDown;
	this.cancelBubble        = cancelBubble;
	// Protected
	this.isInsideOf          = isInsideOf;

	this.event = anNSEvent ? anNSEvent : aWindow.event;
	this.window = WindowX.lookup (aWindow);

	// Relative to the document!
	function x ()
	{
		return isNetscape ? this.event.pageX : this.event.clientX + this.window.getScrollLeft ();
	}


	// Relative to the document!
	function y ()
	{
		return isNetscape ? this.event.pageY : this.event.clientY + this.window.getScrollTop ();
	}
	
	
	function getType ()
	{
		return this.event.type;
	}


	// Gives different results with DOM and Netscape use getCalculatedSource instead
	function getSource ()
	{
		return isIE ? this.event.srcElement : this.event.target;
	}
	
	
	function getCalculatedSource ()
	{
		if (this.calculatedSource)
			return this.calculatedSource;
	
		var src;
		if (isNetscape)
		{
			src = this.window.window;
			layers = this.window.window.document.layers;
			for (i = 0; i < layers.length; i++)
			{
				var layer = layers[i];
				if (! this.isInsideOf (layer))
					continue;
				if (src == this.window.window || layer.zIndex > src.zIndex)
					src = layer;
	
				while (layer.siblingAbove)
				{
					layer = layer.siblingAbove;
					if (! this.isInsideOf (layer))
						break;
					if (src == this.window.window || layer.zIndex > src.zIndex)
						src = layer;
				}
			}
		}
		else if (isMozilla)
		{
			src = this.window.window;
			var list = this.window.window.document.getElementsByTagName ("div");
			for (i = 0; i < list.length; i++)
			{
				var layer = list.item (i);
				if (! this.isInsideOf (layer))
					continue;
				// TODO: Normally z-index should be retrieved with getComputedStyle
				// but this does not work yet
				if (src == this.window.window || layer.style.zIndex > src.style.zIndex)
					src = layer;
			}
		}
		else
		{
			src = this.getSource ();
			if (src.tagName != "DIV")
			{
				var name = src.tagName;
				if (src.tagName == "IMG")
				{
					while (src.parentElement != null)
					{
						src = src.parentElement;
						if (src.tagName == "DIV")
							break;
					}
					if (src.tagName != "DIV")
						src = this.window.window;
				}
				else
					src = this.window.window;
			}
		}
		
		this.calculatedSource = src;
		return this.calculatedSource;
	}


	function isInsideOf (layer)
	{
		if (! layer.id)
			return false;
		var layerX = new LayerX (layer.id);
		return layerX.isInside (this.x (), this.y ());
	}


	function isLeftButtonDown ()
	{
		return this.whichButton (EventX.LEFTBUTTON);
	}
	
	
	function whichButton (buttonId)
	{
		// Netscape     : Left: 1, Middle: 2, Right: 3
		// Mozilla (DOM): Left: 0, Middle: 1, Right: 2
		// IE           : Left: 1, Middle: 4, Right: 2
		// IE Mac       : Left: 0
		// Opera        : Left: 1

		if (buttonId == EventX.LEFTBUTTON)
			return (isNetscape && this.event.which  == 1) ||
						 (isMozilla  && this.event.button == 0) ||
						 ((isIE || isOpera) && (this.event.button == 1 || (isIEMac && this.event.button == 0)));
		
		if (buttonId == EventX.MIDDLEBUTTON)
			return (isNetscape && this.event.which  == 2) ||
						 (isMozilla  && this.event.button == 1) ||
						 (isIE       && this.event.button == 4);
		
		if (buttonId == EventX.RIGHTBUTTON)
			return (isNetscape && this.event.which  == 3) ||
						 (isMozilla  && this.event.button == 2) ||
						 (isIE       && this.event.button == 2);
	}


	function isAltDown ()
	{
		return this.event.modifiers ? this.event.modifiers & Event.ALT_MASK : this.event.altKey;
	}


	// Does not work with Netscape, check the return parameter of routeEvent() instead
	function cancelBubble ()
	{
		if (isIE)
			this.event.cancelBubble = true;
		else if (isDOM)
			this.event.stopPropagation ();
	}
}


////////////////////////////////////////////////////////////////////////
//
//	EventListenerX
//
////////////////////////////////////////////////////////////////////////

function EventListenerX (layerOrWindowToObserve, objectToNotify)
{
	// Declare instance methods ...
	//
	this.notify = notify;
	//
	if (layerOrWindowToObserve.setTimeout)
		this.isWindow = true;
	else
		this.isWindow = false;
	this.layerOrWindow = layerOrWindowToObserve;
	this.target        = objectToNotify;


	function notify (otherLayerOrWindow, eventX)
	{
		if (this.layerOrWindow === otherLayerOrWindow)
			return this.target.onEvent (eventX);
		return false;
	}
}


////////////////////////////////////////////////////////////////////////
//
//	FontX
//
////////////////////////////////////////////////////////////////////////

function FontX (fontFamily, fontSize, fontWeight, fontStyle, textDecoration)
{
	// Declare instance methods ...
	//
	this.createCSS        = createCSS;
	this.createCSSContent = createCSSContent;
	this.setFontForClass  = setFontForClass;
	//

	this.fontFamily     = fontFamily     ? fontFamily     : "Arial,Helvetica,sans-serif";
	this.fontSize       = fontSize       ? fontSize       : "12pt";
	this.fontWeight     = fontWeight     ? fontWeight     : "normal";
	this.fontStyle      = fontStyle      ? fontStyle      : "normal";
	this.textDecoration = textDecoration ? textDecoration : "none";


	function createCSS (aTagName, aClassName, aColor)
	{
		if (aTagName && isNetscape)
		{
			// Netscape can't handle selectors
			var index = aTagName.indexOf (":");
			if (index != -1)
				aTagName = aTagName.substring (0, index);
		}

		return (aTagName ? aTagName : '') + (aClassName ? "." + aClassName : '') +
		       "{" +
		       "font-family:'" + this.fontFamily +
					 "';font-size:" + this.fontSize +
					 ";font-weight:" + this.fontWeight +
					 ";font-style:" + this.fontStyle +
					 ";text-decoration:" + this.textDecoration +
					 (aColor ? ";color: " + aColor : '') +
					 ";}\n";
	}


	function createCSSContent ()
	{
		return "font-family:" + this.fontFamily +
					 ";font-size:" + this.fontSize +
					 ";font-weight:" + this.fontWeight +
					 ";font-style:" + this.fontStyle +
					 ";text-decoration:" + this.textDecoration + ";";
	}


	function setFontForClass (anElement, aTagName, aClassName, aColor)
	{
		var aDocument = anElement.document ? anElement.document : anElement;

		if (aTagName && isNetscape)
		{
			// Netscape can't handle selectors
			var index = aTagName.indexOf (":");
			if (index != -1)
				aTagName = aTagName.substring (0, index);
		}

		if (isNetscape)
		{
			var tag = aClassName ?
									eval("aDocument.classes." + aClassName + (aTagName ? "." + aTagName : ".all")) :
									eval("aDocument.tags." + aTagName);
			tag.fontFamily     = this.fontFamily;
			tag.fontSize       = this.fontSize;
			tag.fontWeight     = this.fontWeight;
			tag.fontStyle      = this.fontStyle;
			tag.textDecoration = this.textDecoration;

			if (aColor) tag.color = aColor;
		}
		else
		{
			var style = "font-family:"     + this.fontFamily +
									";font-size:"      + this.fontSize +
									";font-weight:"     + this.fontWeight +
									";font-style:"      + this.fontStyle +
									";text-decoration:" + this.textDecoration;
			if (aColor) style += ";color:" + aColor;

			var selector = (aTagName ? aTagName.toLowerCase () : '') + (aClassName ? "." + aClassName : '');
			if (isMozilla)
			{
				if (! aDocument.createElement)
					aDocument = aDocument.ownerDocument;

				if (! aDocument.styleSheets || aDocument.styleSheets.length == 0)
				{
					var a = aDocument.createElement ('link');
					a.rel = 'StyleSheet';
					a.href = 'about:blank';
					aDocument.documentElement.firstChild.appendChild (a);
//					alert(aDocument.styleSheets.length)                            // it say 0
	//				setTimeout('alert(aDocument.styleSheets.length)',0)   // it say 1
	
//					setTimeout('document.styleSheets[0].insertRule (selector + " { " + style + " }", 0)', 0);
					return;
				}				

				var found = false;
				for (i = 0; i < aDocument.styleSheets.length; i++)
				{
					for (j = 0; j < aDocument.styleSheets[i].cssRules.length; j++)
					{
						if (aDocument.styleSheets[i].cssRules[j].selectorText == selector)
						{
							var style = aDocument.styleSheets[i].cssRules[j].style;
							style.fontFamily     = this.fontFamily;
							style.fontSize       = this.fontSize;
							style.fontWeight     = this.fontWeight;
							style.fontStyle      = this.fontStyle;
							style.textDecoration = this.textDecoration;
							if (aColor)
								style.color = aColor;
							found = true;
						}
					}
				}
				if (! found)
					aDocument.styleSheets[0].insertRule (selector + " { " + style + " }", 0);
			}
			else
			{
				if (isIEMac)
				{
//TODO					styleSheets[0].addRule (selector, style);

					var tags = aTagName ? aDocument.all.tags (aTagName) : aDocument.all;
					for (i = 0; i < tags.length; i++)
					{
						var tag = tags[i];
						if (tag.className != aClassName)
							continue;
				    tag.style.fontFamily     = this.fontFamily;
						tag.style.fontSize       = this.fontSize;
						tag.style.fontWeight     = this.fontWeight; 
						tag.style.fontStyle      = this.fontStyle; 
						tag.style.textDecoration = this.textDecoration; 
						if (aColor) tag.style.color = aColor;
					}



				}
				else
				{
					var s = aDocument.createStyleSheet ();
					s.addRule (selector, style);
				}
			}
		}
	}
}
