/*
 * File: DOMUtils.js
 *
 * 
 * DOM Utils library  v0.1 
 * Development Started at: 5.10.2005
 *
 * <script SRC="js/JSUtils/DOMUtils.js"></script>
 *   
 * 
 *
 */


/**
 * DOMUtils class used just as namespace
 * 
 */
//var DOMUtils = function() {}


/* 
 * This function loads the XML document from the specified URL and, when
 * it is fully loaded, passes that document and the URL to the specified 
 * handler function. This function works with any XML document.
 *
 * @param url string 		- url from witch to load the XML document.
 * @param handler function 	- handler function to be envoced when XML document fully loads.
 */
function loadXML(url, handler) {
    // Use the standard DOM Level 2 technique, if it is supported
    if (document.implementation && document.implementation.createDocument) {				
        // Create a new Document object
        var xmldoc = document.implementation.createDocument("", "", null);								
        xmldoc.onload = function() { handler(xmldoc, url); }
        xmldoc.load(url);
    }
    // Otherwise, use Microsoft's proprietary API for Internet Explorer
    else if (window.ActiveXObject) { 
        var xmldoc = new ActiveXObject("Microsoft.XMLDOM");   // Create doc
        xmldoc.onreadystatechange = function(  ) {              // Specify onload
            if (xmldoc.readyState == 4) handler(xmldoc, url);
        }
        xmldoc.load(url);                                     // Start loading!
    }
}
/**
 * Get DOM reference of the element whether specified by ID or directly by reference
 * 
 * @param element reference|string
 *		reference of the element or its ID
 * @return reference
 *		reference of the element or false on failure
 * @throws Error in case that browser dose not support DOM
 */
function GetElement(element)
{
	if (!( document.getElementById) && (document.createTextNode )) {
		throw new Error("There is no proper DOM support for this borwser");
		return false;
	}
	if ( typeof(element) === "string" ) {
		element = document.getElementById(element);
	}
	return element;
}
/**
 * Get's element's style. 
 * 
 * @param element reference|string 
 *		Reference or ID of element
 * @param IEStyleAttr string
 * 		name of the IE style attribute ( "paddingLeft" )
 * @param CSSStyleAttr string
 *		name of the CSS style attribute ( "padding-left" )
 *
 * @return string
 *		value of the style attribute 
 */
function GetElementStyleAttr(element, IEStyleAttr, CSSStyleAttr) {		
    var elem = GetElement(element);		

    if (elem.currentStyle) {
        return elem.currentStyle[IEStyleAttr];
    } else if (window.getComputedStyle) {				
        var compStyle = window.getComputedStyle(elem, "");	
				//debug.Dump(compStyle);
        return compStyle.getPropertyValue(CSSStyleAttr);
    }
    return "";
}
/**
 * Get's elements style object, whether with DOM or IE.
 *
 * @element reference|string 
 *		reference or ID of the element
 *
 * @return object|boolean 
 * 		style of the element or false on failure . Note: style object differs for DOM and IE
 */
function GetElementStyle(element)
{
		element = GetElement(element);

		if (element.currentStyle) {
        return element.currentStyle;				
    } else if (window.getComputedStyle) {				
        return window.getComputedStyle(element, "");	
    }	
		else 
			return false;
}

