mcd.util = function () {
    
    var D = mcd.dom;
    var E = mcd.event;
    
    return {
        /**
         * Generic rollover callback
         * 
         * @param {Event} event
         * @param {String} suffix The filename suffix for over states
         */
        rollOver : function (event, suffix) {
            var target  = E.getTarget(event),
                matches = target.src.match(/\.[a-zA-Z]+$/),
                suffix  = suffix || '-on';
            
            target.src = target.src.replace(matches[0], '-on' + matches[0]);
        },
        
        /**
         * Generic rollout callback
         * 
         * @param {Event} event
         * @param {String} suffix The filename suffix for over states
         */
        rollOut : function (event, suffix) {
            var target  = E.getTarget(event),
                suffix  = suffix || '-on.',
                matches = target.src.match(
                	new RegExp('^(.)*(' + suffix + ')\.[a-zA-Z]+$')
                );
			
            target.src = target.src.replace(matches[2], '.');
        },
        
        /**
         * Check if object is empty
         * 
         * @param {Object} The object to check for emptiness
         * @return {boolean} 
         */
         
		objectEmpty : function (o) {
			for (var i in o) {
				return false;
			}
			return true;
		},
		
		/**
		 * Scan page for any print-trigger classes and add events
		 * to them calling the print window
		 * 
		 * @param {String} An optional additional string that should be used
		 * 		  to call the print window other than the default print-trigger
		 */
		 
		printTriggers : function (optionalClass) {
			var triggerList = mcd.dom.getElementsByAttribute('class', 'print-trigger', document.body, 'a', true);
				
			for (var i = 0; i < triggerList.length; i++) {
				mcd.event.add(triggerList[i], 'click', mcd.util.printWindow);
			}
			if (optionalClass) { // If we have an optional class name
				var triggerList = mcd.dom.getElementsByAttribute('class', optionalClass, document.body, 'a', true);
				
				for (var i = 0; i < triggerList.length; i++) {
					mcd.event.add(triggerList[i], 'click', mcd.util.printWindow);
				}
			}
		},
		
		/**
		 * A wrapper function for the print window command so that print window
		 * can be used as a callback function
		 * 
		 */
		printWindow : function (event) {
			if (mcd.event.getTarget(event).nodeName === 'A') {
				mcd.event.preventDefault(event);
			}
			
			window.print();
		},
		
		/**
		 * Catches any links that have a relationship of "external" and opens them
		 * in new windows
		 */
		externalLinkHandler : function () {
			var triggerList = mcd.dom.getElementsByAttribute('rel', 'external', document.body, 'a');
			
			for (var i = 0; i < triggerList.length; i++) {
				mcd.event.add(triggerList[i], 'click', function (event) {
					mcd.event.preventDefault(event);
					window.open(this.getAttribute('href'), '_blank');
				});
			}
		},
		
		/**
		 * Sorts array removing any undefined (deleted) values
		 * 
		 * @param {Array} 
		 * @author Michael T. Smith (msmith@mcdpartners.com)
		 */
		resortArray : function (dirtyArray) {
			var cleanArray = [];

			for ( var i = 0; i < dirtyArray.length; i++ ) {
			    if (dirtyArray[i] === undefined) {
			    }
			    else if (dirtyArray[i] === null) {
			    }
			    else {
					cleanArray.push(dirtyArray[i]);
			    }
			}
			
			return cleanArray;
		},
		
		/**
		 * Returns the length of an array
		 * 
		 * @param {Object} 
		 * @author Michael T. Smith (msmith@mcdpartners.com)
		 */
		objectLength : function (object) {
			var iterator = 0;
			for (property in object) {
				iterator = iterator + 1;
			}
			return iterator;
		},
		
		/**
		 * Toggles the disabled property of inputes
		 * 
		 * @param {HTMLElement} id
		 * @author Miguel Julio (mjulio@mcdpartners.com)
		 */
		toggleDisabled : function (id) {
			mcd.dom.getElement(id).disabled = !mcd.dom.getElement(id).disabled;
		},
		
		identicalArray : function (arrayA, arrayB) {
			if (arrayA.length !== arrayB.length) {
				return false;
			}
			else {
				for (var i = 0; i < arrayA.length; i++) {
					if (arrayA[i] !== arrayB[i]) {
						return false;
					}
				}
				return true;
			}
		}
    };
}();