var browser;
var isaMac;

if (navigator.userAgent.indexOf("Mac") != -1) {isaMac="true";} 
var styleTmp = " ";

	if (((navigator.appName.indexOf("Netscape") != -1)) && (parseInt(navigator.appVersion) < 5))
	{
		browser = 'NS4';
	}
	else if (navigator.appName.indexOf("Microsoft") != -1)
	{
		browser = 'IE';
	}
	else if (((navigator.appName.indexOf("Netscape") != -1)) && (parseInt(navigator.appVersion) >= 5))
	{
		browser = 'Mozilla';
	}
	else if (navigator.appName.indexOf("Konqueror") != -1)
	{
		browser = 'Mozilla';
	}
	var agt=navigator.userAgent.toLowerCase();
	var isIE4 = (agt.indexOf("msie 5")==-1) 

function makeStyle(id,left,width,height,top,fontsize,bottomBorder,topBorder,rightBorder,leftBorder,padding)
{

	//left for DivEl	  (menuParent,window,(ID),body,arrow)	
        /*
         * this produces a stylesheet into the current document in the format of:
         *
         * <STYLE TYPE="text/css">
         * {
         * # dynamicElementone
         *   position: absolute;
         *   left: 14;
         *   width: 100; 
         *   top: 30;   
         * }
         * </STYLE>
         *
         * for each oject called to it (note that style sheets must be included in the head)
	*/
	var d = window.document;
        styleTmp = '#' + id + ' {position:absolute;';
	styleTmp = styleTmp + 'visibility: hide; visibility: hidden;';
	//
	// ADDED FOR IE ON MAC... MAC misinterprets 0 position as false so make it string
	//
	if(!(top)){ top='0'; }
        if (left) { styleTmp = styleTmp + 'left:' + left + ';'; }
        if (width) styleTmp = styleTmp + 'width:' + width + ';';
        if (top) styleTmp = styleTmp + 'top:' + top + ';';

	styleTmp = styleTmp + 'z-Index: 5;';
        styleTmp = styleTmp + 'font-family: Arial, Helvetica, sans-serif;';
        if (fontsize) styleTmp = styleTmp + 'font-size: ' + fontsize + ';';

        if ((padding)&&(!(browser=="NS4"))&&((!(isaMac=="true"))||(!(isIE4))) )
	{ 
		styleTmp = styleTmp + 'padding-top: ' + padding + 'px; padding-bottom: ' + padding + 'px;'
	}
	else  
	{ 
		styleTmp = styleTmp + 'padding-top: ' + padding + 'px;'

		// THIS IS FOR IE 4 ON MAC
 		if((isaMac=="true") && (isIE4)) 
		{
			styleTmp = styleTmp + 'height: ' + (height-3) + 'px;';
		}
	}
	if((!(padding))&&(browser=="Mozilla")){ styleTmp = styleTmp + 'padding-bottom: ' + 3 + 'px;'}

        if (bottomBorder)
        {
                        //there is a problem with Netscape4... its unable to display bottom borden sans top...
                        styleTmp = styleTmp + 'border-bottom-width: 1px;';
                        styleTmp = styleTmp + 'border-bottom: 1px solid black;';
        } 
        if (rightBorder)
        {  
                        styleTmp = styleTmp + 'border-right-width:1px;';
                        styleTmp = styleTmp + 'border-right: 1px solid black;';
        }
        if (leftBorder)
        {
                        styleTmp = styleTmp + 'border-left-width:1px;';
                        styleTmp = styleTmp + 'border-left: 1px solid black;';
        }
        if (topBorder)
        {
                        styleTmp = styleTmp + 'border-top-width:1px;';
                        styleTmp = styleTmp + 'border-top: 1px solid black;';
        }
        styleTmp = styleTmp + '}';

        {

                d.writeln(styleTmp);
                styleTmp = "";
        }
}


function DivEl(menuParent,window,id,body,arrow)
{

	this.menuParent = menuParent;
	this.window = window;
	this.id = id;
	this.body = body;
	this.arrow = arrow;

	DivEl.prototype.output = function() 
	{

		var d = this.window.document;  //Shortcut variable
		
		/* print out the actual element in this format:
		 * <DIV ID="windowone">this is a prototype window</DIV>
		 */
		
		d.write('<DIV ID="' + this.id + '">');
		if(this.arrow == 1) 
		{
			d.write('&nbsp;&nbsp;&nbsp;<img src="../../images/navigation/transarrow.gif" border="0" width="4" height="7">&nbsp;');
		}
		d.write(this.body);
		//d.write('<br>.');
		d.write('</DIV>');

		switch (browser)
		{
			case "NS4" :
				this.layer = d[this.id]; //another reference shortcut
				this.layer.visibility = "hide";  //hide
			break
                	case "IE" :
				this.element = d.all[this.id];
				this.style = this.element.style;
				this.style.visibility = "hidden"; //hidden
			break
        	        case "Mozilla" :
				this.element = d.getElementById(this.id);
				this.style = this.element.style;
				this.style.visibility = "hidden"; //hidden
			break
		}
	}

	if (browser=="NS4")
	{

		DivEl.prototype.moveTo = function(x,y) { this.layer.moveTo(x,y); }
		DivEl.prototype.moveBy = function(x,y) { this.layer.moveBy(x,y); }
		DivEl.prototype.show = function() { this.layer.visibility = "show"; }
		DivEl.prototype.hide = function() { this.layer.visibility = "hide"; }
		DivEl.prototype.setStackingOrder = function(z) { this.layer.zIndex = z; }
		DivEl.prototype.setBgColor = function(color) { this.layer.bgColor = color; }
		DivEl.prototype.setBgImage = function(image) { this.layer.background.src = image; }
		DivEl.prototype.setCursor = function(cursor) { }

		DivEl.prototype.getX = function() { return this.layer.left; }
		DivEl.prototype.getY = function() { return this.layer.top; }
		DivEl.prototype.getWidth = function() { return this.layer.width; }
		DivEl.prototype.getHeight = function() { return this.layer.height; }
		DivEl.prototype.getStackingOrder = function() { return this.layer.zIndex; }
		DivEl.prototype.isVisible = function() { return this.layer.visibility=="show" ; }

		/* 
		 * this is a cool one... it will cycle through the arguments you send it and
		 * treat those arguments as text to be tossed into body of <DIV>
		 * if you do not close the document the borswer does not think you have finished 
		 * and will not stop the "document loading" animation it displays and the 
		 * borwser may keep the write statement in buffer indefinately
		 */

		DivEl.prototype.setBody = function() 
		{
			for(var i=0; i < arguments.length; i++)
				this.layer.document.write(arguments[i]);
			this.layer.document.close();
		}

		/* this function returns events to the handler function called in the html doc
		 * for further processing it then assigns that functions return value to the event
		 * handler
		 */ 	

		DivEl.prototype.addEventHandler = function(eventname, handler)
		{
			this.layer.captureEvents(DivEl._eventmasks[eventname]);
			var dynel = this;
			this.layer[eventname] = function(event) 
			{
			return handler(dynel, event.type, event.x, event.y,
				event.which, event.which, 
				((event.modifiers & Event.SHIFT_MASK) !=0),
				((event.modifiers & Event.CTRL_MASK) !=0),
				((event.modifiers & Event.ALT_MASK) !=0));
			}
		}						
			
		// This unregisters named event handler above... 
	
		DivEl.prototype.removeEventHandler = function(eventname)
		{
			this.layer.releaseEvents(DivEl._eventmasks[eventname]);
			delete this.layer[eventname];
		}

		// Creates a hash/map between common name and forth generation event model names	

		DivEl._eventmasks = {
		onabort:Event.ABORT, onblur:Event.BLUR, onchange:Event.CHANGE,
		onclick:Event.CLICK, ondblclick:Event.DBLCLICK,
		ondraganddrop:Event.DRAGDROP, onerror:Event.ERROR,
		onfocus:Event.FOCUS, onkeydown:Event.KEYDOWN, onkeypress:Event.KEYPRESS,
		onkeyup:Event.KEYUP, onload:Event.LOAD, onmousedown:Event.MOUSEDOWN,
		onmouseover:Event.MOUSEOVER, onmouseup:Event.MOUSEUP, onmove:Event.MOVE, 
		onreset:Event.RESET, onresize:Event.RESIZE, onselect:Event.SELECT, 
		onsubmit:Event.SUBMIT, onunload:Event.UNLOAD
		};


	} // end if NS4


	// START INTERNET EXPLORER

	if((browser=="IE"))
	{

		//methods to move object
		DivEl.prototype.moveTo = function(x,y)
		{
			this.style.pixelLeft = x;
			this.style.pixelTop = y;
		}
		DivEl.prototype.moveBy = function(x,y)
		{
			this.style.pixelLeft += x;
			this.style.pixelTop += y;
		}

	
		DivEl.prototype.show = function() { this.style.visibility = "visible"; }
		DivEl.prototype.hide = function() { this.style.visibility = "hidden"; }
		DivEl.prototype.setStackingOrder = function(z) { this.style.zIndex = z; }
		DivEl.prototype.setBgColor = function(color) { this.style.backgroundColor = color; }
		DivEl.prototype.setBgImage = function(image) { this.style.backgroundImage = 'url(' + image + ')'; }
		DivEl.prototype.setCursor = function(cursor) { this.style.cursor = cursor; }
	
		//methods to quesry the dynamic object
		DivEl.prototype.getX = function() { return this.style.pixelLeft; }
		DivEl.prototype.getY = function() { return this.style.pixelTop; }
		DivEl.prototype.getWidth = function() { return this.style.width; }
		DivEl.prototype.getHeight = function() { return this.style.height; }
		DivEl.prototype.getStackingOrder = function() { return this.style.zIndex; }
		DivEl.prototype.isVisible = function() { return this.style.visibility == "visible"; }	
	        DivEl.prototype.getCursor = function() { return this.style.cursor; }
	
		DivEl.prototype.setBody = function() 
		{
			var body = "";
			for(var i =0; i < arguments.length; i++) {
				body += arguments[i] + "\n";
			}

		// this is an interesting difference
	
			this.element.innerHTML = body;
		}	
	
		DivEl.prototype.addEventHandler = function(eventname, handler)
		{
			var dynel = this;
	
			this.element[eventname] = function()
			{
			var e = dynel.window.event;
			e.cancelBubble = true;
			return handler(dynel, e.type, e.x, e.y, e.button, e.keyCode, e.shiftKey, e.ctrlKey, e.altKey);
			}
		}

		// remove event handler
		DivEl.prototype.removeEventHandler = function(eventname) 
		{		
			this.element[eventname] = null;
		}

	} // end if IE


	// START MOZILLA-note Netscape 6.0 has an AWFUL bug which causes the browser to crash after repeated event calls

	if(browser=="Mozilla")
	{
	
		//methods to move object
		DivEl.prototype.moveTo = function(x,y)
		{
			this.style.left = x;
			this.style.top = y;
		}
		DivEl.prototype.moveBy = function(x,y)
		{
			this.style.left += x;
			this.style.top += y; 
		}

	
		DivEl.prototype.show = function() { this.style.visibility = "visible"; }
		DivEl.prototype.hide = function() { this.style.visibility = "hidden"; }
		DivEl.prototype.setStackingOrder = function(z) { this.style.zIndex = z; }
		DivEl.prototype.setBgColor = function(color) { this.style.backgroundColor = color; }
		DivEl.prototype.setBgImage = function(image) { this.style.backgroundImage = 'url(' + image + ')'; }
		DivEl.prototype.setCursor = 
					function(cursor) 
					{ 
					if (cursor=="hand") { cursor = "pointer";}
					this.style.cursor = cursor; 
					}

		//methods to query the dynamic object
		DivEl.prototype.getX = function() { return this.style.pixelLeft; }
		DivEl.prototype.getY = function() { return this.style.pixelTop; }
		DivEl.prototype.getWidth = function() { return this.style.width; }
		DivEl.prototype.getHeight = function() { return this.style.height; }
		DivEl.prototype.getStackingOrder = function() { return this.style.zIndex; }
		DivEl.prototype.isVisible = function() { return this.style.visibility == "visible"; }
	
		DivEl.prototype.setBody = function() 
		{
			var body = "";
			for(var i =0; i < arguments.length; i++) {
				body += arguments[i] + "\n";
			}
	
		// this is an interesting difference

			this.element.innerHTML = body;
		}	
	
		DivEl.prototype.addEventHandler= function(event, handler, otherparm, secondparm, thirdparm)
		{
			var DivEl = this;
			eventname = event.replace(/on/i, "");
			handler._ieEmuEventHandler = function(e) 
				{
				window.event = e;
				return handler(DivEl, e.type, e.clientX, e.clientY, e.button, e.keyCode, e.shiftKey, e.ctrlKey, e.altKey, otherparm, secondparm, thirdparm);
				}
			this.element.addEventListener( eventname, handler._ieEmuEventHandler, false);


		}


		DivEl.prototype.removeEventHandler = function(event) 
		{
			eventname = event.replace(/on/i, "");
			this.element.removeEventListener(eventname);
		
		}


	} // end if Mozilla






}

