/**
 * CCDES Library from Advanced DOM Scripting
 * http://advanceddomscripting.com
 *
 * This library is not compressed and is not recommended for production use in
 * its current state. The code is excessively verbose and heavily commented
 * as it was written as a teaching tool. It is recommended you edit the code for
 * better performance and smaller file size. 
 * @projectDescription CCDES library from the book "AdvancED DOM Scripting" http://advanceddomscripting.com/
 * @author Jeffrey Sambells jeff@advanceddomscripting.com
 * @copyright Jeffrey Sambells 2007 unless otherwise noted
 * @version $Id: CCDES-final-verbose.js 183 2007-07-17 20:23:30Z jsambells $
 * @see http://advanceddomscripting.com/source/documentation
 * @namespace CCDES
 *//**
* Missing getElementById.
* Example of creating a DOM replacement this isn't necessary because the
* library assume browsers that support it.
*/
if(document.all && !document.getElementById) {
    document.getElementById = function(id) {
         return document.all[id];
    }
}
/**
 * CCDES Namespace
 * This anonymous function acts as a namespace wrapper for the rest
 * of the methods. Methods are then assigned to the window object
 * using: window['CCDES']['methodName'] = methodReference;
 * @alias CCDES
 */
(function(){
/**
 * The primary namespace object
 * @type {Object}
 * @alias CCDES
 */
    function $(id) {
        return document.getElementById(id);
    }

    function alertNodeName(id) {
        alert($(id).nodeName);
    }

    window['CCDES'] = {};
    window['CCDES']['showNodeName'] = alertNodeName;
})();
function isCompatible(other) {
    // Use capability detection to check requirements
    if( other===false 
        || !Array.prototype.push
        || !Object.hasOwnProperty
        || !document.createElement
        || !document.getElementsByTagName
        ) {
        alert('TR- if you see this message isCompatible is failing incorrectly.');
        return false;
    }
    return true;
}
window['CCDES']['isCompatible'] = isCompatible;
/**
 * document.getElementById(); replacement.
 */
function $() {
    var elements = new Array();
    
    // Find all the elements supplied as arguments
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        
        // If the argument is a string assume it's an id
        if (typeof element == 'string') {
            element = document.getElementById(element);
        }
        
        // If only one argument was supplied, return the element immediately
        if (arguments.length == 1) {
            return element;
        }
        
        // Otherwise add it to the array
        elements.push(element);
    }
    
    // Return the array of multiple requested elements
    return elements;
};
window['CCDES']['$'] = $;
/**
 * Register an event listener on an element
 */
function addEvent( node, type, listener ) {
    // Check compatibility using the earlier method
    // to ensure graceful degradation
    if(!isCompatible()) { return false }
    if(!(node = $(node))) return false;
    
    if (node.addEventListener) {
        // W3C method
        node.addEventListener( type, listener, false );
        return true;
    } else if(node.attachEvent) {
        // MSIE method
        node['e'+type+listener] = listener;
        node[type+listener] = function(){node['e'+type+listener]( window.event );}
        node.attachEvent( 'on'+type, node[type+listener] );
        return true;
    }
    
    // Didn't have either so return false
    return false;
};
window['CCDES']['addEvent'] = addEvent;
/**
 * Retrieve an array of element base on a class name
 */
function getElementsByClassName(className, tag, parent){
    parent = parent || document;
    if(!(parent = $(parent))) return false;
    
    // Locate all the matching tags
    var allTags = (tag == "*" && parent.all) ? parent.all : parent.getElementsByTagName(tag);
    var matchingElements = new Array();
    
    // Create a regular expression to determine if the className is correct
    className = className.replace(/\-/g, "\\-");
    var regex = new RegExp("(^|\\s)" + className + "(\\s|$)");
    
    var element;
    // Check each element
    for(var i=0; i<allTags.length; i++){
        element = allTags[i];
        if(regex.test(element.className)){
            matchingElements.push(element);
        }
    }
    
    // Return any matching elements
    return matchingElements;
};
window['CCDES']['getElementsByClassName'] = getElementsByClassName;
/**
 * Prevents the default event in the event flow (such as following the href in an anchor).
 */
function preventDefault(eventObject) {
    eventObject = eventObject || getEventObject(eventObject);
    if(eventObject.preventDefault) {
        eventObject.preventDefault();
    } else {
        eventObject.returnValue = false;
    }
}
window['CCDES']['preventDefault'] = preventDefault;
