function V8HasAttribute(node, attrName)
{
    var a = node.getAttribute(attrName);
    if (a == null)
        return false;
    return a == 0 || a != "";
}

function GetAbsolutePosX(el)
{
    x = el.offsetLeft;
    var elem = el.offsetParent;
    if (elem && el.parentNode && elem != el.parentNode && el.parentNode.tagName == "DIV")
        if (el.parentNode.style.overflow == "scroll" || el.parentNode.style.overflow == "auto" ||
            el.parentNode.style.overflowX == "scroll" || el.parentNode.style.overflowX == "auto")
        {
            elem = el.parentNode;
        }
    
	if (elem != null)
	{
        x -= el.scrollLeft;
		x += GetAbsolutePosX(elem);
	}
	return x;
}

function GetAbsolutePosY(el)
{
    y = el.offsetTop;
    var elem = el.offsetParent;
    if (elem && el.parentNode && elem != el.parentNode && el.parentNode.tagName == "DIV")
        if (el.parentNode.style.overflow == "scroll" || el.parentNode.style.overflow == "auto" ||
            el.parentNode.style.overflowY == "scroll" || el.parentNode.style.overflowY == "auto")
        {
            elem = el.parentNode;
        }

	if (elem != null)
	{
        y -= el.scrollTop;
		y += GetAbsolutePosY(elem);
	}
	return y;
}

function GetDocumentWidth()
{
    if (window.innerWidth) 
        return window.innerWidth;
    else if (document.body && document.body.offsetWidth) 
        return document.body.offsetWidth;
    else return 0;
}

function GetDocumentHeight()
{
    if (window.innerHeight) 
        return window.innerHeight;
    else if (document.body && document.body.offsetHeight) 
        return document.body.offsetHeight;
    else return 0;
}

function ResizeWindow(w, h)
{
    window.resizeTo(w, h);
    var dx = 0, dy = 0;
    var scrollWidth = document.body.scrollWidth + 20;
    if (scrollWidth > window.screen.availWidth - window.screenLeft)
        scrollWidth = window.screen.availWidth - window.screenLeft;
    var scrollHeight = document.body.scrollHeight + 20;
    if (scrollHeight > window.screen.availHeight - window.screenTop)
        scrollHeight = window.screen.availHeight - window.screenTop;
    if (scrollWidth - GetDocumentWidth() > 2)
        dx = scrollWidth - GetDocumentWidth();
    if (scrollHeight - GetDocumentHeight() > 2)
        dy = scrollHeight - GetDocumentHeight();
    if (dx != 0 || dy != 0)
        window.resizeBy(dx, dy);
}

function OpenWindow(url, target)
{
    var windowOptions = "directories=no,location=no,menubar=no,status=yes,resizable=yes,scrollbars=yes";
    windowOptions += ",width=500,height=350";

    if (target == null)
        target = "_blank";
    return window.open(url, target, windowOptions);
}

function OpenWindowNoSize(url, target)
{
    var windowOptions = "directories=no,location=no,menubar=no,status=yes,resizable=yes,scrollbars=yes";

    if (target == null)
        target = "_blank";
    return window.open(url, target, windowOptions);
}

function HtmlEncode(str)
{
    str = str.replace(/&/gm, "&amp;")
    str = str.replace(/</gm, "&lt;")
    str = str.replace(/>/gm, "&gt;")
    str = str.replace(/"/gm, "&quot;")
    return str;
}

