/*
 * This javascript class contains DOM helper functions.
 */
function SofiaDOM() {

}

SofiaDOM.prototype.getElementsByHavingAttribute = getElementsByHavingAttribute;
/*
* Gives back the nodes, which ones have the 'attributeName' attribute.
* @param node root of searching in DOM.
* @param attributeName the name of attribute.
* @return Array of finded node, which ones have the attribute.
*/
function getElementsByHavingAttribute(node, attributeName) {
    var result = new Array();
    if (node.nodeType.valueOf() == 1) {
        if (node.attributes.getNamedItem(attributeName) != null) {
            result[result.length] = node;
        } else {
            for (var x = 0; x < node.childNodes.length; x++) {
                var subResult = getElementsByHavingAttribute(node.childNodes[x], attributeName);
                for (var j = 0; j < subResult.length; j++) {
                    result[result.length] = subResult[j];
                }
            }
        }
    }
    return result;
}
/*
* Drops all child node excluding ATTRIBUTE_NODE child of node.
* @param The clearing node, which type is ELEMENT_NODE.
*/
SofiaDOM.prototype.clearElementNode = function(node) {
    if (node.nodeType.valueOf() == 1) {
        for (var n = 0; n < node.childNodes.length; n++) {
            if (node.nodeType.valueOf() != 2) {
               node.removeChild(node.childNodes[n]);
            }
        }
    } else {
        //throw ...
    }
}
