

// Copyright (c) NimbleCat, 2008

/*
* this object wraps a DOM element
* 
* */
// make sure that the required includes are there
 if (typeof NC.util == 'undefined') {
       alert("dom.js requires the NC JavaScript framework");
 }


/*
 * DOM utilities
*/
	/* ===============BEGIN BSD LICENSED PORTION============= */
	/*
	Copyright (c) 2007, Yahoo! Inc. All rights reserved.
	Code licensed under the BSD License:
	http://developer.yahoo.net/yui/license.txt
	version: 2.2.0
	*/
	/*
 	* this has been modified to reflect NimbleCat's needs but originated verbatim from YUI
 	*/
(function() {

    var getStyle,           // for load time browser branching
        setStyle,           // ditto
        propertyCache = {}, // for faster hyphen converts
        reClassNameCache = {},          // cache regexes for className
        document = window.document;     // cache for faster lookups
    // brower detection
   	var isOpera = NC.env.ua.opera,
       	isSafari = NC.env.ua.webkit, 
       	isGecko = NC.env.ua.gecko,
       	isIE = NC.env.ua.ie; 
    // regex cache
    var patterns = {
        HYPHEN: /(-[a-z])/i, // to normalize get/setStyle
        ROOT_TAG: /^body|html$/i // body for quirks mode, html for standards
    };

    var getClassRegEx = function(className) {
        var re = reClassNameCache[className];
        if (!re) {
            re = new RegExp('(?:^|\\s+)' + className + '(?:\\s+|$)');
            reClassNameCache[className] = re;
        }
        return re;
    };

    var toCamel = function(property) {
        if ( !patterns.HYPHEN.test(property) ) {
            return property; // no hyphens
        }
        
        if (propertyCache[property]) { // already converted
            return propertyCache[property];
        }
       
        var converted = property;
 
        while( patterns.HYPHEN.exec(converted) ) {
            converted = converted.replace(RegExp.$1,
                    RegExp.$1.substr(1).toUpperCase());
        }
        
        propertyCache[property] = converted;
        return converted;
        //return property.replace(/-([a-z])/gi, function(m0, m1) {return m1.toUpperCase()}) // cant use function as 2nd arg yet due to safari bug
    };

    // branching at load instead of runtime
    if (document.defaultView && document.defaultView.getComputedStyle) { // W3C DOM method
        getStyle = function(el, property) {
            var value = null;
            
            if (property == 'float') { // fix reserved word
                property = 'cssFloat';
            }

            var computed = document.defaultView.getComputedStyle(el, '');
            if (computed) { // test computed before touching for safari
                value = computed[toCamel(property)];
            }
            
            return el.style[property] || value;
        };
    } else if (document.documentElement.currentStyle && isIE) { // IE method
        getStyle = function(el, property) {                         
            switch( toCamel(property) ) {
                case 'opacity' :// IE opacity uses filter
                    var val = 100;
                    try { // will error if no DXImageTransform
                        val = el.filters['DXImageTransform.Microsoft.Alpha'].opacity;

                    } catch(e) {
                        try { // make sure its in the document
                            val = el.filters('alpha').opacity;
                        } catch(e) {
                        }
                    }
                    return val / 100;
                case 'float': // fix reserved word
                    property = 'styleFloat'; // fall through
                default: 
                    // test currentStyle before touching
                    var value = el.currentStyle ? el.currentStyle[property] : null;
                    return ( el.style[property] || value );
            }
        };
    } else { // default to inline only
        getStyle = function(el, property) { return el.style[property]; };
    }
    
    if (isIE) {
        setStyle = function(el, property, val) {
            switch (property) {
                case 'opacity':
                    if ( YAHOO.lang.isString(el.style.filter) ) { // in case not appended
                        el.style.filter = 'alpha(opacity=' + val * 100 + ')';
                        
                        if (!el.currentStyle || !el.currentStyle.hasLayout) {
                            el.style.zoom = 1; // when no layout or cant tell
                        }
                    }
                    break;
                case 'float':
                    property = 'styleFloat';
                default:
                el.style[property] = val;
            }
        };
    } else {
        setStyle = function(el, property, val) {
            if (property == 'float') {
                property = 'cssFloat';
            }
            el.style[property] = val;
        };
    }
	
	NC.util.Dom = {
		/*
		 * Dom access methods. These methods take a HTMLElement as the first argument. If the variable FaceBook is defined, a different path will be taken
		 */
		 
		 setClassName: function( el, newClassName) {
		 	if (NC.env.FaceBook == 1) {
		 		// do the facebook thing
		 		el.setClassName( newClassName);
		 	}
		 	else { // default
		 		el.className = newClassName;
		 	}
		 },
		 
		 getClassName: function( el) {
		 	if (NC.env.FaceBook == 1) {
		 		// do the facebook thing
		 		return el.getClassName( );
		 	}
		 	else { // default
		 		return el.className;
		 	}
		 },
		 
        /**
         * Determines whether an HTMLElement has the given className.
         * @method hasClass
         * @param {String | HTMLElement | Array} el The element or collection to test
         * @param {String} className the class name to search for
         * @return {Boolean | Array} A boolean value or array of boolean values
         */
        hasClass: function(el, className) {
            var re = getClassRegEx(className);
            return re.test(this.getClassName(el));
        },
    
        /**
         * Adds a class name to a given element or collection of elements.
         * @method addClass         
         * @param {String | HTMLElement | Array} el The element or collection to add the class to
         * @param {String} className the class name to add to the class attribute
         * @return {Boolean | Array} A pass/fail boolean or array of booleans
         */
        addClass: function(el, className) {
                if (this.hasClass(el, className)) {
                    return false; // already present
                }
                this.setClassName( el, NC.lang.trim([this.getClassName(el), className].join(' ')));
                return true;
        },
    
        /**
         * Removes a class name from a given element .
         * @method removeClass         
         * @param {String | HTMLElement | Array} el The element or collection to remove the class from
         * @param {String} className the class name to remove from the class attribute
         * @return {Boolean | Array} A pass/fail boolean or array of booleans
         */
        removeClass: function(el, className) {
            var re = getClassRegEx(className);
            
                if (!className || !this.hasClass(el, className)) {
                    return false; // not present
                }                 

                
                var c = this.getClassName(el);
                this.setClassName(el, c.replace(re, ' '));
                if ( this.hasClass(el, className) ) { // in case of multiple adjacent
                    this.removeClass(el, className);
                }

                this.setClassName(el, NC.lang.trim(this.getClassName(el))); // remove any trailing spaces
                return true;
        },
        
        /**
         * Replace a class with another class for a given element or collection of elements.
         * If no oldClassName is present, the newClassName is simply added.
         * @method replaceClass  
         * @param {String | HTMLElement | Array} el The element or collection to remove the class from
         * @param {String} oldClassName the class name to be replaced
         * @param {String} newClassName the class name that will be replacing the old class name
         * @return {Boolean | Array} A pass/fail boolean or array of booleans
         */
        replaceClass: function(el, oldClassName, newClassName) {
            if (!newClassName || oldClassName === newClassName) { // avoid infinite loop
                return false;
            }
            
            var re = getClassRegEx(oldClassName);
            
                if ( !this.hasClass(el, oldClassName) ) {
                    this.addClass(el, newClassName); // just add it if nothing to replace
                    return true; // NOTE: return
                }
            
                this.setClassName( el, this.getClassName(el).replace(re, ' ' + newClassName + ' '));

                if ( this.hasClass(el, oldClassName) ) { // in case of multiple adjacent
                    this.replaceClass(el, oldClassName, newClassName);
                }

                this.setClassName( el, NC.lang.trim(this.getClassName( el))); // remove any trailing spaces
                return true;
        },
		 
		
		
        /**
         * Normalizes currentStyle and ComputedStyle.
         * @method getStyle
         * @param {String | HTMLElement |Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
         * @param {String} property The style property whose value is returned.
         * @return {String | Array} The current value of the style property for the element(s).
         */
        getStyle: function(el, property) {
            property = toCamel(property);
            return getStyle(el, property);
        },
    
        /**
         * Wrapper for setting style properties of HTMLElements.  Normalizes "opacity" across modern browsers.
         * @method setStyle
         * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements.
         * @param {String} property The style property to be set.
         * @param {String} val The value to apply to the given property.
         */
        setStyle: function(el, property, val) {
            property = toCamel(property);
            setStyle(el, property, val);
        },
        
        /**
         * Returns the left scroll value of the document 
         * @method getDocumentScrollLeft
         * @param {HTMLDocument} document (optional) The document to get the scroll value of
         * @return {Int}  The amount that the document is scrolled to the left
         */
        getDocumentScrollLeft: function(doc) {
            doc = doc || document;
            return Math.max(doc.documentElement.scrollLeft, doc.body.scrollLeft);
        }, 

        /**
         * Returns the top scroll value of the document 
         * @method getDocumentScrollTop
         * @param {HTMLDocument} document (optional) The document to get the scroll value of
         * @return {Int}  The amount that the document is scrolled to the top
         */
        getDocumentScrollTop: function(doc) {
            doc = doc || document;
            return Math.max(doc.documentElement.scrollTop, doc.body.scrollTop);
        },
	
    	getAbsoluteXY: function( element) {
			var XYfn = function() {
	        if (document.documentElement.getBoundingClientRect) { // IE
	            return function(el) {
	                var box = el.getBoundingClientRect();
	
	                var rootNode = el.ownerDocument;
	                return [box.left + NC.util.Dom.getDocumentScrollLeft(rootNode), box.top +
	                        NC.util.Dom.getDocumentScrollTop(rootNode)];
	            };
	        } else {
	            return function(el) { // manually calculate by crawling up offsetParents
	                var pos = [el.offsetLeft, el.offsetTop];
	                var parentNode = el.offsetParent;
	
	                // safari: subtract body offsets if el is abs (or any offsetParent), unless body is offsetParent
	                var accountForBody = (isSafari &&
	                        NC.util.Dom.getStyle(el, 'position') == 'absolute' &&
	                        el.offsetParent == el.ownerDocument.body);
	
	                if (parentNode != el) {
	                    while (parentNode) {
	                        pos[0] += parentNode.offsetLeft;
	                        pos[1] += parentNode.offsetTop;
	                        if (!accountForBody && isSafari && 
	                                NC.util.Dom.getStyle(parentNode,'position') == 'absolute' ) { 
	                            accountForBody = true;
	                        }
	                        parentNode = parentNode.offsetParent;
	                    }
	                }
	
	                if (accountForBody) { //safari doubles in this case
	                    pos[0] -= el.ownerDocument.body.offsetLeft;
	                    pos[1] -= el.ownerDocument.body.offsetTop;
	                } 
	                parentNode = el.parentNode;
	
	                // account for any scrolled ancestors
	                while ( parentNode.tagName && !patterns.ROOT_TAG.test(parentNode.tagName) ) 
	                {
	                   // work around opera inline/table scrollLeft/Top bug
	                   if (NC.util.Dom.getStyle(parentNode, 'display').search(/^inline|table-row.*$/i)) { 
	                        pos[0] -= parentNode.scrollLeft;
	                        pos[1] -= parentNode.scrollTop;
	                    }
	                    
	                    parentNode = parentNode.parentNode; 
	                }
	
	                return pos;
	            };
	        }
	    };
    	return XYfn()( element);
    },
    
        /**
         * Set the position of an html element in page coordinates, regardless of how the element is positioned.
         * The element(s) must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
         * @method setXY
         * @param {String | HTMLElement | Array} el Accepts a string to use as an ID, an actual DOM reference, or an Array of IDs and/or HTMLElements
         * @param {Array} pos Contains X & Y values for new position (coordinates are page-based)
         * @param {Boolean} noRetry By default we try and set the position a second time if the first fails
         */
        setAbsoluteXY: function(el, pos, noRetry) {
            var f = function(el) {
                var style_pos = NC.util.Dom.getStyle(el, 'position');
                if (style_pos == 'static') { // default to relative
                    NC.util.Dom.setStyle(el, 'position', 'relative');
                    style_pos = 'relative';
                }

                var pageXY = NC.util.Dom.getAbsoluteXY(el);
                if (pageXY === false) { // has to be part of doc to have pageXY
                    return false; 
                }
                
                var delta = [ // assuming pixels; if not we will have to retry
                    parseInt( NC.util.Dom.getStyle(el, 'left'), 10 ),
                    parseInt( NC.util.Dom.getStyle(el, 'top'), 10 )
                ];
            
                if ( isNaN(delta[0]) ) {// in case of 'auto'
                    delta[0] = (style_pos == 'relative') ? 0 : el.offsetLeft;
                } 
                if ( isNaN(delta[1]) ) { // in case of 'auto'
                    delta[1] = (style_pos == 'relative') ? 0 : el.offsetTop;
                } 
        
                if (pos[0] !== null) { el.style.left = pos[0] - pageXY[0] + delta[0] + 'px'; }
                if (pos[1] !== null) { el.style.top = pos[1] - pageXY[1] + delta[1] + 'px'; }
              
                if (!noRetry) {
                    var newXY = NC.util.Dom.getAbsoluteXY(el);

                    // if retry is true, try one more time if we miss 
                   if ( (pos[0] !== null && newXY[0] != pos[0]) || 
                        (pos[1] !== null && newXY[1] != pos[1]) ) {
                       NC.util.Dom.setAbsoluteXY(el, pos, true);
                   }
                }        
        
            };
            
//            Y.Dom.batch(el, f, Y.Dom, true);
			f(el);
        },
        /**
         * Returns an HTMLElement reference.
         * @method get
         * @param {String | HTMLElement |Array} el Accepts a string to use as an ID for getting a DOM reference, an actual DOM reference, or an Array of IDs and/or HTMLElements.
         * @return {HTMLElement | Array} A DOM reference to an HTML element or an array of HTMLElements.
         */
        get: function(el) {
            if (el && (el.nodeType || el.item)) { // Node, or NodeList
                return el;
            }

            if (NC.lang.isString(el) || !el) { // id or null
                return document.getElementById(el);
            }
            
            if (el.length !== undefined) { // array-like 
                var c = [];
                for (var i = 0, len = el.length; i < len; ++i) {
                    c[c.length] = NC.util.Dom.get(el[i]);
                }
                
                return c;
            }

            return el; // some other object, just pass it back
        },
        
        /**
         * Returns a array of HTMLElements with the given class.
         * For optimized performance, include a tag and/or root node when possible.
         * @method getElementsByClassName
         * @param {String} className The class name to match against
         * @param {String} tag (optional) The tag name of the elements being collected
         * @param {String | HTMLElement} root (optional) The HTMLElement or an ID to use as the starting point 
         * @param {Function} apply (optional) A function to apply to each element when found 
         * @return {Array} An array of elements that have the given class name
         */
        getElementsByClassName: function(className, tag, root, apply) {
            tag = tag || '*';
            root = (root) ? NC.util.Dom.get(root) : null || document; 
            if (!root) {
                return [];
            }

            var nodes = [],
                elements = root.getElementsByTagName(tag),
                re = getClassRegEx(className);

            for (var i = 0, len = elements.length; i < len; ++i) {
                if ( re.test(elements[i].className) ) {
                    nodes[nodes.length] = elements[i];
                    if (apply) {
                        apply.call(elements[i], elements[i]);
                    }
                }
            }
            
            return nodes;
        },
    
    	getParentByType: function(el, parentType) {
    		var parent = el;
    		for (;;) {
    			if (parent == null) {
    				return null;
    			}
    			parent = parent.parentNode;
    			if (parent == document)  { // went too far
    				return null;
    			}
    			if (parent.tagName.toLowerCase() === parentType.toLowerCase()) {
    				return parent;
    			}
    		}
    	},
/**
         * Returns the current height of the viewport.
         * @method getViewportHeight
         * @return {Int} The height of the viewable area of the page (excludes scrollbars).
         */
        getViewportHeight: function() {
            var height = self.innerHeight; // Safari, Opera
            var mode = document.compatMode;
        
            if ( (mode || isIE) && !isOpera ) { // IE, Gecko
                height = (mode == 'CSS1Compat') ?
                        document.documentElement.clientHeight : // Standards
                        document.body.clientHeight; // Quirks
            }
        
            return height;
        },
        
        /**
         * Returns the current width of the viewport.
         * @method getViewportWidth
         * @return {Int} The width of the viewable area of the page (excludes scrollbars).
         */
        
        getViewportWidth: function() {
            var width = self.innerWidth;  // Safari
            var mode = document.compatMode;
            
            if (mode || isIE) { // IE, Gecko, Opera
                width = (mode == 'CSS1Compat') ?
                        document.documentElement.clientWidth : // Standards
                        document.body.clientWidth; // Quirks
            }
            return width;
        },
    	
		extractEncodedField: function( docRoot, fieldName)
		{
			var value = '';
			var valueList = docRoot.getElementsByTagName(fieldName);
			if (valueList != null && valueList.getLength() > 0) {
				if (valueList.item(0).getFirstChild() != null) {
					value = decode64( valueList.item(0).getFirstChild().getNodeValue());
				}
			}
			return value;
		},
		
		extractField: function( docRoot, fieldName)
		{
			var value = '';
			var valueList = docRoot.getElementsByTagName(fieldName);
			if (valueList != null && valueList.getLength() > 0) {
				if (valueList.item(0).getFirstChild() != null) {
					value = valueList.item(0).getFirstChild().getNodeValue();
				}
			}
			return value;
		},
		
		updateField: function( domDocument, fieldName, value)
		{
			var docRoot = domDocument.getDocumentElement();
			var valueList = docRoot.getElementsByTagName(fieldName);
			if (valueList != null && valueList.getLength() > 0) {
				if (valueList.item(0).getFirstChild() != null) {
					valueList.item(0).getFirstChild().setNodeValue( value);
				}
				else {
					var newNode = domDocument.createTextNode( value);
					valueList.item(0).appendChild( newNode);
				}
			}
			else {
//				alert( "updateField failed: " + fieldName + ", " + value + ' :valueList is null');
			}
			return value;
		},
		
		updateEncodedField: function( domDocument, fieldName, value)
		{
			var encodedValue = encode64(value);
			return this.updateField( domDocument, fieldName, encodedValue);
		},
		
		enumerateElementProperties: function( el) {
			var output = '';
			for (var key in el) {  
					output += key + " = " + el[key] + " ---- ";
			}	
			return output;
		},
		
		// search the input elements in this form and return the element with the name provided
		getFormElement: function( form, elementName)
		{
		   	for (var i = 0; i < form.elements.length; i++) {
		   		var element = form.elements[i];
		   		if (element.name == elementName) {
		  			return element;
		   		}
		   	}
		   	return null;
		},
		
		showElementValue: function ( formName, elementName)
		{
		    var form = document.forms[formName];
		   	for (var i = 0; i < form.elements.length; i++) {
		   		var element = form.elements[i];
		   		if (element.name == elementName) {
		   			alert( formName + '.' + element.name + '=' + element.value);
		   		}
		   	}
		},

		getElementValue: function ( formName, elementName)
		{
		    var form = document.forms[formName];
		   	for (var i = 0; i < form.elements.length; i++) {
		   		var element = form.elements[i];
		   		if (element.name == elementName) {
		   		    switch(element.type) {
		   				case 'select-multiple':
		   					value = '';
		    				for (j = 0; j < element.length; j++) {
		    					if (element.options[j].selected) {
		    						if (value.length > 0) {
		    							value += ',';
		    						}
		    						value += element.options[j].value;
		    					}
		    				}
		    				return value;
		   			     
			   		    default:
				   			value = element.value;
				   			if (value == 0) {
				   				value = '';
				   			}
				   			return element.value;
				   	}
		   		}
		   	}
		   	return null;
		},

		getCheckBoxState: function ( formName, elementName)
		{
		    var form = document.forms[formName];
		   	for (var i = 0; i < form.elements.length; i++) {
		   		var element = form.elements[i];
		   		if (element.name == elementName) {
		   			if (element.type == 'checkbox') {
		   				return element.checked;
		   			}
		   			else {
		   				return null;
		   			}
		   		}
		   	}
		   	return null;
		},

		setElementValue: function ( formName, elementName, elementValue)
		{
		    var form = document.forms[formName];
		   	for (var i = 0; i < form.elements.length; i++) {
		   		var element = form.elements[i];
		   		if (element.name == elementName) {
		   			element.value = elementValue;
		   		}
		   	}
		},
		
		getValue: function( element) {
   		    switch(element.type) {
				case 'select-one': 
					var index = element.selectedIndex;
					return index >= 0 ? element.options[index].value : null;
					
   				case 'select-multiple':
   					value = '';
    				for (j = 0; j < element.length; j++) {
    					if (element.options[j].selected) {
    						if (value.length > 0) {
    							value += ',';
    						}
    						value += element.options[j].value;
    					}
    				}
    				return value;
 
      			case 'checkbox':
      			case 'radio':
    				var value = element.checked ? element.value : null;
        			return value;
   			     
	   		    default:
		   			var value = element.value;
		   			if (value == 0) {
		   				value = '';
		   			}
		   			return value;
		   	}
		},

		serializeForm: function( form) {
			var postData = '';
			if (form != null) {
	   			for (var i = 0; i < form.elements.length; i++) {
	   			  var element = form.elements[i];
	   			  if (!element.disabled) {
		   			if (postData.length > 0 && postData.charAt(postData.length -1) != '&') {
		   				postData += '&';
		   			}
	   		      	switch(element.type) {
	   		      	case 'hidden':
	   		      	case 'text':
	   		      	case 'password':
	   		      	case 'textarea':
	   		      		var evalue = escape(element.value);
	   			      	postData += element.name + '=' + evalue;
	   			      	break;
	   		      	
	   			      case 'checkbox':
	   			      	if (element.checked) {
	   			      		postData += element.name + '=' + element.value;
	   			      	}
	   			      	break;
	   		      
	   			      case 'radio':
	   			      	if (element.checked) {
	   			      		postData += element.name + '=' + element.value;
	   			      	}
	   			      	break;
	   		      	
	   			      case 'select-one':
	   			      	postData += element.name + '=' + element.value;
	   			      	break;
	   		      	
	   			      case 'select-multiple':
	    				for (j = 0; j < element.length; j++) {
	    					if (element.options[j].selected) {
	    						if (postData.length > 0 && postData.charAt(postData.length -1) != '&') { // more than one selected value
	    							postData += "&";
	    						}
	    						postData += element.name + "[]=" + element.options[j].value;
	    					}
	    				}
	   			      	break;
	   		      	
	   			      default:
//	   			      	alert( 'unknown ' + element.type + ' ' + element.name);
	   			      }
	   		      }
	   		    }
			}
   		    return postData;
		},

		checkEmail: function ( email)
		{
			var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
			return (filter.test(email)) 
		},
		
		descendants: function( node) {
			return node.getElementsByTagName('*');
		},
		
		disable: function(element) {
		    element.disabled = true;
		    return element;
		},

		enable: function(element) {
		  element.blur();
		  element.disabled = false;
		  return element;
		},
		
		getFormDescendant: function( elementName, formName) {
	 		var element = document.getElementById(elementName);
	 		var descendants = NC.util.Dom.descendants(element);
	 		for (var i = 0; i < descendants.length; ++i) {   
	 			var item = descendants[i];   
				if (item.name == formName) {
						return item;
				}
	 		}
		}

    }
}
)();

/**
 * A region is a representation of an object on a grid.  It is defined
 * by the top, right, bottom, left extents, so is rectangular by default.  If 
 * other shapes are required, this class could be extended to support it.
 * @namespace NC.util
 * @class Region
 * @param {Int} t the top extent
 * @param {Int} r the right extent
 * @param {Int} b the bottom extent
 * @param {Int} l the left extent
 * @constructor
 */
NC.util.Region = function(t, r, b, l) {

    /**
     * The region's top extent
     * @property top
     * @type Int
     */
    this.top = t;
    
    /**
     * The region's top extent as index, for symmetry with set/getXY
     * @property 1
     * @type Int
     */
    this[1] = t;

    /**
     * The region's right extent
     * @property right
     * @type int
     */
    this.right = r;

    /**
     * The region's bottom extent
     * @property bottom
     * @type Int
     */
    this.bottom = b;

    /**
     * The region's left extent
     * @property left
     * @type Int
     */
    this.left = l;
    
    /**
     * The region's left extent as index, for symmetry with set/getXY
     * @property 0
     * @type Int
     */
    this[0] = l;
};

/**
 * toString
 * @method toString
 * @return string the region properties
 */
NC.util.Region.prototype.toString = function() {
    return ( "Region {"    +
             "top: "       + this.top    + 
             ", right: "   + this.right  + 
             ", bottom: "  + this.bottom + 
             ", left: "    + this.left   + 
             "}" );
};

/**
 * Returns a region that is occupied by the DOM element
 * @method getRegion
 * @param  {HTMLElement} el The element
 * @return {Region}         The region that the element occupies
 * @static
 */
NC.util.Region.getRegion = function(el) {
    var p = NC.util.Dom.getAbsoluteXY(el);

    var t = p[1];
    var r = p[0] + el.offsetWidth;
    var b = p[1] + el.offsetHeight;
    var l = p[0];

    return new NC.util.Region(t, r, b, l);
};



    /* ===============END BSD LICENSED PORTION============= */

 