var goldenrod
if (!goldenrod) goldenrod = {}



goldenrod.Dom = new function() {

	var self = this;
	self.NAME = "goldenrod.Dom";
	
	
	/**************************************************************************************************
	*Point - A class constructor - for holding x and y coordinates
	*
	*x - The horizontal coordinate
	*y - The vertical coordinate
	**************************************************************************************************/
	self.Point = function(x,y) {
		if(x == null) this.x = 0; else this.Left = x;
		if(y == null )this.y = 0; else this.y = y;
		
	}
	
	self.Point.prototype.getPointX = function() {
		return this.x
	}
	
	self.Point.prototype.getPointY = function() {
		return this.y
	}
	
		
	self.Point.prototype.setPointX = function(x) {
		this.x = x
	}
	
	self.Point.prototype.setPointY = function(y) {
		this.y = y
	}
	
	self.Viewport = new self.Point()

	
	
	/**************************************************************************************************
	*Rectangle - A class constructor - All parameters are optional. The default value is the string "auto"
	*
	*Left - The left coordinate 
	*Top - The top coordinate
	*Width - The width
	*Height - The height
	**************************************************************************************************/
	self.Rectangle = function(x,y,w,h) {
		if(x == null) this.Left = self.auto; else this.Left = x;
		if(y == null )this.Top = self.auto; else this.Top = y;
		if(w == null) this.Width = self.auto; else this.Width = w;
		if(h == null) this.Height = self.auto; else this.Height = h;
		this.adjustRB();
	
	}
	

	
	self.Rectangle.prototype.adjustWH = function(){
		this.Width = self.auto; this.Height = self.auto
		if ((this.Right != self.auto) && (this.Left != self.auto)) this.Width = this.Right - this.Left;
		if ((this.Bottom != self.auto) && (this.Top != self.auto)) this.Height = this.Bottom - this.Top;
	}

	self.Rectangle.prototype.adjustRB = function(){
		this.Right = self.auto; this.Bottom = self.auto
		if ((this.Left != self.auto) && (this.Width != self.auto)) this.Right = this.Left + this.Width;
		if ((this.Top != self.auto) && (this.Height != self.auto)) this.Bottom = this.Top + this.Height;
	}
	self.Rectangle.ZERO = new self.Rectangle(0,0,0,0);
	self.Rectangle.AUTO = new self.Rectangle();

	self.Rectangle.prototype.copy = function(rectangle) {
		this.Left = rectangle.Left;
		this.Top = rectangle.Top;
		this.Width = rectangle.Width;
		this.Height = rectangle.Height;
		this.Right = rectangle.Right;
		this.Bottom = rectangle.Bottom;
	}
	
	self.Rectangle.prototype.add = function(rectangle) {
		if( (typeof this.Left == "number") && (typeof rectangle.Left == "number") )
			this.Left += rectangle.Left;
		if( (typeof this.Top == "number") && (typeof rectangle.Top== "number") )
			this.Top += rectangle.Top;
		if( (typeof this.Width == "number") && (typeof rectangle.Width == "number") )
			this.Width += rectangle.Width;
		if( (typeof this.Height == "number") && (typeof rectangle.Height == "number") )
			this.Height += rectangle.Height;
		if( (typeof this.Right == "number") && (typeof rectangle.Right == "number") )
			this.Right += rectangle.Right;
		if( (typeof this.Bottom == "number") && (typeof rectangle.Bottom == "number") )
			this.Bottom += rectangle.Bottom;
	}
	
	self.Rectangle.prototype.isIn = function(xy) {
		var returnValue = true;
		var x = xy[0], y=xy[1];
		if( (x < this.Left) || (x >= this.Right) || (y < this.Top) || y >= this.Bottom)
			returnValue = false;
		return returnValue;
	}

	
	/**************************
	goldenrod.Dom.ELEMENT_NODE = 1;
	goldenrod.Dom.TEXT_NODE = 3;
	goldenrod.Dom.DOCUMENT_NODE = 9;
	goldenrod.Dom.COMMENT_NODE = 8;
	goldenrod.Dom.DOCUMENT_FRAGMENT_NODE = 11;
	goldenrod.Dom.ATTRIBUTE_NODE = 2;
	***********************************/

	self.DPI_X;
	self.DPI_Y;
	self.bodyMarginAdjust_X;
	self.bodyMarginAdjust_Y;
	self.toPixelRatio;
	self.toPointRatio;
	self.unit_search_pattern = /px|in|pt/;
	self.scroll_bar_size = .25;
	self.scroll_bar_pixel;
	
	
	self.featureTEST = function(){
		var body = document.getElementsByTagName('body')[0];
		var style = self.getStyle(body);
		var bodyMarginSave = [style.marginLeft, style.marginTop];
		body.style.marginLeft = "8px";
		body.style.marginTop = "8px";
		
		 
		var dpi = document.createElement("div");
		dpi.style.position = "absolute"
		dpi.style.left = "0px";
		dpi.style.top = "0px";
		dpi.style.width = "72pt";
		dpi.style.height = "72pt";
		document.body.appendChild(dpi);
		self.DPI_Y = dpi.offsetHeight;
		self.DPI_X = dpi.offsetWidth;
		
		//This test if the browser include the body' borser in the offset of elements of not.
		self.bodyMarginAdjust_X = (8 - dpi.offsetLeft) ? true : false;
		self.bodyMarginAdjust_Y = (8 - dpi.offsetTop) ? true : false;
	
		
		
		self.toPixelRatio = self.DPI_X/72;
		self.toPointRatio = 7200/self.DPI_X;
		self.scroll_bar_pixel = Math.round(self.DPI_X * self.scroll_bar_size);
		
		/***********************************************************************************
			"dpi.offsetLeft = " + dpi.offsetLeft + " dpi.offsetTop = " + dpi.offsetTop + 
			"\nself.bodyMarginAdjust_X = " + self.bodyMarginAdjust_X + 
			" self.bodyMarginAdjust_Y = " + self.bodyMarginAdjust_Y +
			"\n\nbody Margin Left Save = " + bodyMarginSave[0] + " body Margin Top Save = " + bodyMarginSave[1]);
		*************************************************************************************/
		body.style.marginLeft = bodyMarginSave[0];
		body.style.marginTop = bodyMarginSave[1];
		document.body.removeChild(dpi);
		return;
	}
	
	

	self.getPixel = function(s){
	
		if(s == self.auto) return NaN;
	
		var x = parseFloat(s);
		if(isNaN(x)) {
			alert("goldenrod.Dom.getPixel encountered a string that does not start with a number. " + s);
			return NaN;
		}
		
		var unit = s.slice(s.search(self.unit_search_pattern))
	
			switch(unit) {
				case "px" : 
				break;
		
				case "pt":
				x = x*self.toPixelRatio;
				break;
		
				case "in": 
				x = x*self.DPI_X
				break;
			}
		return x;
	}
	
	self.getPoint = function(s){
		if(s == self.auto) return NaN;
	
		var x = parseFloat(s);
		if(isNaN(x)) {
			alert("goldenrod.Dom.getPoint encountered a string that does not start with a number." + s);
			return NaN;
		}
		var unit = s.slice(s.search(self.unit_search_pattern))
	
			switch(unit) {
				case "px" : 
				x = self.toPoint(x);
				break;
		
				case "pt": 
				break;
		
				case "in": 
				x = self.toPoint(x*self.DPI_X);
				break;
			}
		return x;
	}
	
	self.toPoint = function(x) {
		return Math.round( x*self.toPointRatio ) / 100
	}
	/*********************************************************************************************
	*Dom.setDimension - Always set the style property to a point value.

	x - A number which is the value to be set
	elt - An HTML element or the "id" string of an element
	dim - The string of the style property to be set
	unit - a flag that tells the function what units is the value x
			if this parameter is omited pixels are assumed.
	**********************************************************************************************/

	self.setDimension = function(x, elt, dim,  unit){
	
		var value;
		if(unit == null) unit = self.setDimension.pixel
		if(typeof elt == "string") elt = document.getElementById(elt);
	
		switch(unit) {
			case self.setDimension.pixel : 
			value = self.toPoint(x);
			break;
		
			case self.setDimension.point : 
			value = x;
			break;
		
			case self.setDimension.inch : 
			value = self.toPoint(x*self.DPI_X);
			break;
		}
	
	
	
		elt.style[dim] = value + "pt"
	}
	
	self.setDimension.pixel = 0;
	self.setDimension.point = 1;
	self.setDimension.inch = 2;

	
	/*********************************************************************************************
	*Dom: - Shift Key down Constants Masks
	**********************************************************************************************/
	self.NoKey = 0;
	self.Shift = 1;		//Shift = 1st bit
	self.Control = 2;	//Control = 2nd bit
	self.Alt = 4;		//Alt = 3rd bit


	self.shiftkeyState;

	/****************************************************************************************
	*Dom.set_shiftkeyState() -  is passed an event Object.
	*
	*
	*****************************************************************************************/
	self.set_shiftkeyState = function(e) {
		
		self.shiftkeyState = 0;
		if(e.shiftKey) self.shiftkeyState = (self.shiftkeyState | self.Shift);
		if(e.ctrlKey)  self.shiftkeyState = (self.shiftkeyState | self.Control);
		if(e.altKey)  self.shiftkeyState = (self.shiftkeyState | self.Alt);
	}

	
	/****************************************************************************************
	*Dom.getTarget() is passed an event Object.
	*
	*Internet Explorer has is own interface. To get the element on which the event occured use
	*the scrElement property of the event Object.
	*
	*Otherwise the W3C standard uses the target property.
	*****************************************************************************************/
	self.getTarget = function(e) {
		if(e.target) return e.target;  //This is the W3 way to get the target
		else if(e.srcElement) return e.srcElement; //This is the IE way to get the target
		else {myAlert("No way to determine the target node"); return undefined;}
	}
		
	self.getcurrentTarget = function(e) {
		if(e.currentTarget) return e.currentTarget;
	}

		
	/****************************************************************************************
	Dom.getStyle(node) is passed a node Object (also work with an element object)
	*
	*If nodeType does not equal 1 (Element Node) the function returns "undefined".
	*
	*In Internet Explorer - we can get the style using the "currentStyle" property of the "node" Object.
	*
	*In other browsers we use the "getComputedStyle" method of the "window" Object. 
	*
	*I realize that we do not
	*need am element node to have an "id" because and elementnode is also an element!
	*
	*
	*If both node.currentStyle and window.getComputedStyle are undefined we issue an alert and 
	*return "undefined"
	*****************************************************************************************/		
	self.getStyle = function(node, /*optional*/ parameter) {
		//dump_properties("node ", node);
		var style = undefined;
		var id, elt;
				
		if(node.nodeType == 1) {
			if( node.currentStyle) {
				style = node.currentStyle;
			}
			else if(window.getComputedStyle ) {
				style = window.getComputedStyle(node, null);
			}
			else myAlert("goldenrod.Dom.getStyle: No way to get style information on the target node");
		}
		else myAlert("goldenrod.Dom.getStyle: This node is not an Element node.");
		
		if(parameter) return style.parameter
		else return style;
	}

	/****************************************************************************************
	Dom.getStyleOpacity(style) is passed a style Object.
	*
	*If no opacity is found we return "undefined"
	*
	*IE - Has nothing set of opacity unless a value has been explicitly written. Otherwise the filter property
	is defined but is a zero length string - "".
	*****************************************************************************************/		
	self.getStyleOpacity = function(style) {
		//dump_properties("node ", node);
		var opacity = undefined;
		var name = "";
		if(style.opacity !== undefined) {
			opacity = (style.opacity * 100); name = "opacity";
		}
		else if (style.MozOpacity !== undefined) {
			opacity = (style.MozOpacity * 100);
			name = "MozOpacity"
		}
		else if (style.KhtmlOpacity !== undefined) {
			opacity = (style.KhtmlOpacity * 100);
			name = "KhtmlOpacity"
		}
		else if (style.filter !== undefined) {
			if(style.filter == "" ) opacity = 100;
			else {
				opacity = myString.parseInt(style.filter);
				if(opacity == NaN) opacity = undefined;
			}
												
		}//parse filter string for a number
		return opacity;
	}


	/****************************************************************************************
	Dom.setStyleOpacity(style, opacity) is passed an interger between 1 and 100.
	*
	*If no opacity is found we return "undefined"
	*****************************************************************************************/		
	self.setStyleOpacity = function(elt, opacity) {
		var object = elt.style;
		opacity = Math.round(opacity);
		object.opacity = (opacity / 100); 
    	object.MozOpacity = (opacity / 100); 
    	object.KhtmlOpacity = (opacity / 100); 
    	object.filter = "alpha(opacity=" + opacity + ")";
		
		/***********Maybe some code for IE******************
		if(elt.filters)
		elt.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity;
		object['-ms-filter'] = "'progid:DXImageTransform.Microsoft.Alpha(opacity='" + opacity + "')'";
		************/
		return true;
	}

	/****************************************************************************************
	Dom.getStyleClipFull(style, box) 
	*
	*box  - A rectangle Object 
	*returns a rectangle that will reveal the whole element - in points
	*****************************************************************************************/		
	self.getStyleClipFull = function(style, box) {
	
		//Initialize Current Element Clip Box to what "auto" means (may have to be adjusted)
		box.Left = 0;
		box.Top = 0;
	
		//Note: In IE the border width must be set explicitly for the default value is a text string - "medium"
		box.Width = self.getPoint(style.width) + self.getPoint(style.borderLeftWidth) + 
					self.getPoint(style.borderRightWidth) + self.getPoint(style.paddingLeft) + 
					self.getPoint(style.paddingRight);; 
		box.Height = self.getPoint(style.height) + self.getPoint(style.borderTopWidth) + 
					 self.getPoint(style.borderBottomWidth) +
					 self.getPoint(style.paddingTop) + self.getPoint(style.paddingBottom);
	
				 
		box.Right = box.Width;
		box.Bottom = box.Height;
	
	}
	



	/****************************************************************************************
	Dom.getStyleClip(style, box) 
	*
	*box  - A rectangle Object with point values
	*****************************************************************************************/		
	self.getStyleClip = function(style, box) {
		var returnvalue = true;
		//Initialize Current Element Clip Box to what "auto" means (may have to be adjusted)
		self.getStyleClipFull(style, box);
	
		if(self.isIE) {
			if( (style.clipTop) && (style.clipTop != self.auto) ) box.Top = self.getPoint(style.clipTop);
			if( (style.clipRight) && (style.clipRight != self.auto) ) box.Right = self.getPoint(style.clipRight);
			if( (style.clipLeft) && (style.clipLeft != self.auto) ) box.Left = self.getPoint(style.clipLeft);
			if( (style.clipBottom) && (style.clipBottom != self.auto) ) box.Bottom = self.getPoint(style.clipBottom);
		}
		
		
		//Save Current Element Clip Box we assume clip box values are in pixels "px"
		else if( (style.clip != self.auto) && (style.clip != "rect(0pt, 0pt, 0pt, 0pt)") ) {
			self.pattern.lastIndex = 0; i=0;
			//alert("We are about to parse this string: " + style.clip);
			while( ((m = self.pattern.exec(style.clip)) != null) ) {
				//alert("m[0] = " + m[0]);
				n = self.getPoint(m[0]);
				if( !isNaN(n) ) {
			
					switch (i) {
						case 0: {
							box.Top = n;
							break;
						}
					
						case 1: {
							box.Right = n;
							break;
						}

						case 2: {
							box.Bottom = n;
							break;
						}
					
						case 3: {
							box.Left = n;
							break;
						}
						
					}
					i++;				
				}
				else {alert("goldenrod.Dom.getStyleClip - parameter is Nan")}
	
			}
		}	
		
		box.adjustWH();	
		//dump_properties("clip box = ", box)	
		return returnvalue;
	}

	/****************************************************************************************
	Dom.setStyleClip(elt, box) 
	*
	*box  - A rectangle Object 
	*****************************************************************************************/		
	self.setStyleClip = function(elt, box) {
		var returnvalue = true, j, i, value;
		var inlinestyle, styles_list, clipString, top, right, bottom, left;
		if( (top = box.Top) != self.auto  ) top = top + "pt ";
		if( (right = box.Right) != self.auto  ) right = right + "pt ";
		if( (bottom = box.Bottom) != self.auto  ) bottom = bottom + "pt ";
		if( (left = box.Left) != self.auto  ) left = left + "pt";
		clipString = "rect(" + top + " " + right + " " + bottom + " " + left + ")";
		//alert("goldenrod.Dom.setStyleClip: clipString = " + clipString);
		//alert("goldenrod.Dom.isIS = " + self.isIE)
		if(self.isIE){	//This does not work - must set the style attribute
			inlinestyle = elt.getAttribute("style");
			styles_list = inlinestyle.split(";");
		
			for(i=0; i < styles_list.length; i++) {
				j = styles_list[i].indexOf(":");
				value = styles_list[i].slice(0,j).toUpperCase();
				if (value == "CLIP")
					break;
			}
			//i will equal the index of the Clip value or will point to the end of the array if no Clip value
			//	was found
			styles_list[i] = "clip:" + clipString;	//Add a new clip value
			inlinestyle = styles_list.join("; ");
			elt.setAttribute("style", inlinestyle);
		}
		
		else {
			for(clip in elt.style) elt.style.clip = clipString;
		}
		
		return returnvalue;
	}
	
	/****************************************************************************************
	Dom.getColor - colorvalue is the browers encoding of a color value - can be "#FFFFFF" or "#FFF" or rgb(255, 255, 255)
					This function will convert this value or an interger.
	*****************************************************************************************/	
	self.getColor = function(colorvalue) {
	
	}
	
	/****************************************************************************************
	Dom.setColor - n is an interger and this will be convert to the string "#FFFFFF"
	*****************************************************************************************/	
	self.setColor = function(n) {
		
	}


	/****************************************************************************************
	Dom.getViewportHeight - Height of browser viewport 
	*****************************************************************************************/	
	self.getViewportHeight = function() {
			
    	var height = window.innerHeight; // Safari, Opera
        var mode = window.document['compatMode'];
        
        if ( (mode || self.isIE) && !self.isOpera ) { // IE, Gecko
        	height = (mode == 'CSS1Compat') ?
            	document.documentElement.clientHeight : // Standards
                document.body.clientHeight; // Quirks
     	}
		return height;
	}
		
	/****************************************************************************************
	Dom.getViewportWidth - Width of browser viewport 
	*****************************************************************************************/	
	self.getViewportWidth = function() {
    	var width = window.innerWidth;  // Safari
        var mode = window.document['compatMode'];
            
        if (mode || self.isIE) { // IE, Gecko, Opera
        	width = (mode == 'CSS1Compat') ?
            	document.documentElement.clientWidth : // Standards
                document.body.clientWidth; // Quirks
      	}
        return width;
	}
	
	/****************************************************************************************
	Dom.getVerticalScroll - Document coordinate in upper part of viewport 
							We try all three methods and take the one that yields a non zero value.
	*****************************************************************************************/	
	self.getVerticalScroll = function() {
	
		var a=0, b=0, c=0;
		
		if(document.documentElement && 
				( document.documentElement.clientHeight !== undefined) ) {
					
			a = document.documentElement.scrollTop;		
		}
		if(document.body.clientHeight !== undefined) {
			b = document.body.scrollTop;
		}
		if(window.innerHeight !== undefined) {
			c = window.pageYOffset;
		}
		
		if(a < b) a=b;
    	if(a < c) a=c;
		return a;
	}
		
	/****************************************************************************************
	Dom.getHorizontalScroll - Document coordinate in left part of viewport
							  We try all three methods and take the one that yields a non zero value.
	*****************************************************************************************/	
	self.getHorizontalScroll = function() {
		
		var a=0, b=0, c=0;
		
		if(document.documentElement && 
				( document.documentElement.clientWidth !== undefined) ) {
					
			a = document.documentElement.scrollLeft;		
		}
		if(document.body.clientWidth !== undefined) {
			b = document.body.scrollLeft;
		}
		if(window.innerWidth !== undefined) {
			c = window.pageXOffset
		}
		if(a < b) a=b;
    	if(a < c) a=c;
		return a;
    	
	}
	
	/****************************************************************************************
	Dom.getDocumentCoord - Given an element we calculate the location of its visible upper left 
						   corner relative to the upper left corner of the <body> elt.
						   If the display value is none we return false otherwise we return
						   an array: 1st entry is X 2nd entry is Y.
	*****************************************************************************************/	
	self.getDocumentCoord = function(elt) {
		var point = [0,0], e=elt;
		
		if(goldenrod.Dom.getStyle(elt).display == 'none') return false;
		
		while(e) {
			point[0] += e.offsetLeft;
			point[1] += e.offsetTop;
			e = e.offsetParent
		}
		
		for (e = elt.parentNode; e && (e != document.body); e = e.parentNode ) {
			if(e.scrollLeft) point[0] -= e.scrollLeft;
			if(e.scrollTop) point[1] -= e.scrollTop;
		}
		point[0] = Math.floor(point[0]);
		point[1] = Math.floor(point[1]);
		return point;
	}
	
	/****************************************************************************************
	Dom.getWindowCoord - Given an element we calculate the location of its visible upper left 
						   relative to the upper left corner of the viewport(browser window).
	*****************************************************************************************/	
	self.getWindowCoord = function(elt) {
		var point = self.getDocumentCoord(elt);
		var body = document.getElementsByTagName('body')[0];
		var style = self.getStyle(body);
		if(self.bodyMarginAdjust_X) point[0]+=goldenrod.Dom.getPixel(style.marginLeft);
		if(self.bodyMarginAdjust_Y) point[1]+=goldenrod.Dom.getPixel(style.marginTop);
				
		return point;
	}
	
	/****************************************************************************************
	Dom.isIn - We calculate if a point relative to the viewPort is in the visible boundaries of 
					and element
	*****************************************************************************************/	
	self.isIn = function(xy, elt) {
		
		var returnValue = undefined;
		var point = [];
		var box;
		if((elt.offsetHeight !== undefined) || (elt.offsetWidth !== undefined) ) {
			point = self.getWindowCoord(elt);
			point[0] -= self.getHorizontalScroll();
			point[1] -= self.getVerticalScroll();
			box = new self.Rectangle(point[0], point[1], elt.offsetWidth, elt.offsetHeight);
			returnValue = box.isIn(xy)
				
		}
		return returnValue;
		
		return point;
	}
	
	
	/*********************************************************************************************
	*Constants
	*
	*The DOM constants are set so that:
	*	If goldenrod.Dom.browser is 0 - we are in the old model
	*	If goldenrod.Dom.browser is 1 - we are in IE
	*	If goldenrod.Dom/browser is greater than 1 - we have addlistener capability.
	**********************************************************************************************/
	self.OLD = 0;	
	self.IE = 1;
	self.DOM = 2;
	self.MOZ = 3;
	self.Opera = 4;
	self.Google = 5;
	self.Safari = 6;
	self.isIE = false;
	self.Win64 = false;
	self.isOpera = false;
	self.browser;
	self.leftButton = 0;
	self.auto = "auto";
	//self.pattern = /auto|[0-9]+|-[0-9]+/g;

	self.pattern = /auto|-?[0-9]+\.?[0-9]*(px|in|pt)/g; //auto or zero or one minus sign followed by one or more 
													//digits followed by an optional decimal point followed
													//by zero or more digits followed by px or in or pt

	/*********************************************************************************************
	*Dom.set_handler() - This function uses the appropriate method for registering an event handler
	**********************************************************************************************/
	self.set_handler = function( eventname, elt, handler, capture){

		var capturestate;

		if( capture == null ) capturestate = true; else capturestate = false;

		switch (self.browser) {
	
			case self.IE: {  elt.attachEvent("on" + eventname, handler);
				if (capturestate) {
					if(elt == document) {
						elt.body.setCapture();
					}
					else {
						elt.setCapture(); 
						myAlert("goldenrod.Dom.set_hanlder: setCapture() on " + elt.tagName + ".");
					}	
				}
				break;
			}
			
			case self.OLD: {
				break;
			}
			
			default : {
				elt.addEventListener(eventname, handler, capturestate);
				break;
			}
		}
	}

	/*********************************************************************************************
	*Dom.propagationHandler() - This function uses the appropriate method for both stopping event
	* propagation and preventing the default action.
	**********************************************************************************************/
	self.propagationHandler = function(e) {

		switch (self.browser) {
	
			case self.IE: {
				e.cancelbubble = true;
				e.returnValue = false;
				break;
			}
			
			case self.OLD: {
				break;
			}
			
			default : {
				e.stopPropagation();
				e.preventDefault();
				break;
			}
		}
	}
	
	/*********************************************************************************************
	*Dom.currentTarget(e) - This function returns the currrent target and adapts to the difference in IE
	**********************************************************************************************/
	self.currentTarget = function(e) {
		var r;
		switch (self.browser) {
	
			case self.IE: {
				r = e.srcElement;
				break;
			}
			
			case self.OLD: {
				r = undefined;
			}
			
			default : {
				r = e.currentTarget;
				break;
			}
		}
		return r;
	}

	/*********************************************************************************************
	*Dom.clickHandler() - This is a generic click handler which will do nothing if a shift key is depressed
	**********************************************************************************************/
	self.clickHandler = function(e) {
	
		if(self.isIE) e = window.event;
		self.set_shiftkeyState(e);
		if(self.shiftkeyState) {
			return false;
		}
		window.location = this.href;
	}

	var _hasClass = function(elt, classname) {
		
		if(typeof elt == "string") elt = document.getElementById(elt);
		var pattern = new RegExp("\\b" + classname + "\\b");	//The slash b matches a word boundary
		return (elt.className.search(pattern) != -1 );
	};
	
	self.CSSClass = {
		
		/****
		hasClass : function(elt, classname) {
	
				if(typeof elt == "string") elt = document.getElementById(elt);
				var pattern = new RegExp("\\b" + classname + "\\b")
				return (elt.className.search(pattern) != -1 );
			},
		****/
		hasClass : _hasClass,
		
		addClass : function(elt, classname) {
	
				if(typeof elt == "string") elt = document.getElementById(elt);
				if(_hasClass(elt, classname) ) return
				classname = " " + classname;
				elt.className += classname; 
			},
	
		removeClass : function(elt, classname) {
	
				if(typeof elt == "string") elt = document.getElementById(elt);
				if(!_hasClass(elt, classname)) return;
				separator = /\b/;
				
				var i, a = elt.className.split(separator);
	
				for(i=0; i<a.length; i++) {
					if(a[i] == classname) {
						a.splice(i,1);
						i--;		
					}
				}
	
				separator = " ";
				elt.className = a.join(separator);
				return;
			}
	
	};
	
	/*********************************************************************************************
	*Dom.browserCheck() - This function initializes the "browser" flag. and the "leftButton" value.
	*						It is implemented as the code body of this constructor function.
	**********************************************************************************************/
	self.Init = function() {
		//alert("Inside goldenrod.Dom.browserCheck")
		self.browser = self.OLD;
		
		if (document.addEventListener) {
			self.browser = self.DOM;
			self.leftButton = 0;
		}
		else if(document.attachEvent) {
			self.browser = self.IE;
			self.isIE = true;
			self.leftButton = 1;
			if( navigator && (navigator['appName'] == "Microsoft Internet Explorer") && (navigator['platform'] == "Win64") ) {
				self.Win64 = true;
			}
		}
		
		if(navigator && (navigator['appName'] == "Opera")) {
			self.browser = self.Opera;
			self.isOpera = true;
		}
		else if(navigator && (navigator['appCodeName'] == "Mozilla") && (!self.isIE) ){
			self.browser = self.MOZ;
		}
		
		
		
	}();
	
};

