/**
 * short call
 * @param id
 */
function $(id) {
    return document.getElementById(id);
}
/**
 * returns TRUE if supported
 */
function isDOMsupported() {
    var returnValue = false;
    if (document.getElementById && document.getElementsByTagName && document.createTextNode) {
        returnValue = true;
    }
    return returnValue;
}
/**
 parseUri 1.2.1
 (c) 2007 Steven Levithan <stevenlevithan.com>
 MIT License
 to get access to fields use the call URI = parseUri(location.href) and then fileName = URI['file']
 * @param str
 */
function parseUri(str) {
    var o = parseUri.options,
            m = o.parser[o.strictMode ? "strict" : "loose"].exec(str),
            uri = {},
            i = 14;

    while (i--) uri[o.key[i]] = m[i] || "";

    uri[o.q.name] = {};
    uri[o.key[12]].replace(o.q.parser, function ($0, $1, $2) {
        if ($1) uri[o.q.name][$1] = $2;
    });

    return uri;
}
;

parseUri.options = {
    strictMode: false,
    key: ["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],
    q:   {
        name:   "queryKey",
        parser: /(?:^|&)([^&=]*)=?([^&]*)/g
    },
    parser: {
        strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,
        loose:  /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
    }
};
/**
 * get element top position
 * @param el
 */
function getTop(el) {
    if (!el) return 0;
    return el.offsetTop + getTop(el.offsetParent);
}
/**
 * get element left position
 * @param el
 */
function getLeft(el) {
    if (!el) return 0;
    return el.offsetLeft + getLeft(el.offsetParent);
}
/**
 * cross-browser add event listener function
 * @param instance
 * @param eventName
 * @param listener
 */
/*function setEventListener(instance, eventName, listener) {
    var listenerFunc = listener;
    if (instance.addEventListener) {
        instance.addEventListener(eventName, listenerFunc, false);
    } else if (instance.attachEvent) {
        listenerFunc = function() {
            listener(window.event);
        };
        instance.attachEvent("on" + eventName, listenerFunc);
    } else {
        throw new Error("Event registration is not supported");
    }
    return {
        instance: instance,
        name: eventName,
        listener: listenerFunc
    };
}*/
/**
 * Cancels the event if it is cancelable, without stopping further propagation of the event
 * @param e
 */
function cancelEvent(e) {
    e = e || window.event;
    if (e.preventDefault()) {
        e.preventDefault();
    }
    else {
        e.returnValue = false;
    }
}
/**
 * remove child
 * @param node
 */
function removeNode(node) {
    if (node && node.parentNode) {
        node.parentNode.removeChild(node);
    }
}
/**
 * returns the reference on the object
 * @param parentNode
 * @param tag
 */
function addChild(parentNode, tag) {
    var el = document.createElement(tag);
    el.style.padding = "0";
    el.style.margin = "0";
    el.style.border = "none";
    if (parentNode) {
        parentNode.appendChild(el);
    }
    return el;
}
/**
 * cross-browser set opacity function
 * @param el
 * @param opacity
 */
function setOpacity(el, opacity) {
    if (/MSIE 6/.test(navigator.userAgent)) el.style.filter = "alpha(opacity=" + Math.round(opacity * 100) + ")";
    else el.style.opacity = opacity;
}
/**
 * get position of an element
 * syntax: element.style.top = ScrollPos().y + "px";
 */
function ScrollPos() {
    if (self.pageYOffset !== undefined) {
        return {
            x: self.pageXOffset,
            y: self.pageYOffset
        };
    }
    var el = document.documentElement;
    return {
        x: el.scrollLeft,
        y: el.scrollTop
    };
}
/**
 * element.style.position = getPositionMethod().position;
   element.style.top = getPositionMethod().top + "px";
 */
function positionFixed() {
    if (/MSIE/.test(navigator.userAgent)) {
        return {position: "absolute", top: ScrollPos().y};
    }
    return {position: "fixed", top: this.style.top};
}
