﻿function Dom(){};

function Dom.show(element)
{
    element.style.visibility = "visible";
}
function Dom.hide(element)
{
    element.style.visibility = "hidden";
}
function Dom.showR(element)
{
    element.style.display = "";
}
function Dom.hideR(element)
{
    element.style.display = "none";
}

function Dom.create(elementInfo,parent,params)
{
    var newElement = document.createElement(elementInfo);
    if(!parent) parent = document.body;
    parent.appendChild(newElement);
    Event.pack(newElement);
    if(params.className) newElement.className = params.className;
    if(params.cssText) newElement.style.cssText = params.cssText;
    return newElement;
}

function Dom.getWH(element)
{
	var wh = 
	{
		"width":element.offsetWidth,
		"height":element.offsetHeight
	};
	return wh;
}

function Dom.getOffsetRect(element)
{
    var rect = 
    {
        "left":element.offsetLeft,
        "top":element.offsetTop,
        "width":element.offsetWidth,
        "height":element.offsetHeight,
        "right":element.offsetLeft + element.offsetWidth,
        "bottom":element.offsetTop + element.offsetHeight
    };
    return rect;
}

function Dom.getAbsoluteRect(element)
{
    var rect = 
    {
        "left":element.offsetLeft,
        "top":element.offsetTop,
        "width":element.offsetWidth,
        "height":element.offsetHeight,
        "right":0,
        "bottom":0
    };
    
    while(element = element.offsetParent)
    {
        rect.left += element.offsetLeft;
        rect.top += element.offsetTop;
    }
    
    rect.right = rect.left + rect.width;
    rect.bottom = rect.top + rect.height;
    
    return rect;
}

function Dom.getDocumentRect()
{
    var left = document.documentElement.scrollLeft;
    var top = document.documentElement.scrollTop;
    var width = document.documentElement.clientWidth;
    var height = document.documentElement.clientHeight;
    var right = left + width;
    var bottom = top + height;
    
    var rect = 
    {
        "left":left,
        "top":top,
        "width":width,
        "height":height,
        "right":right,
        "bottom":bottom
    };
    
    return rect;
}

function Dom.setPosition(element,position)
{
    element.style.left = position.left + "px";
    element.style.top = position.top + "px";
}

function Dom.setDisplay(element,isShow)
{
    if(isShow) element.style.display = "";
    else element.style.display = "none";
}

function Dom.toInt(srcValue,defaultValue)
{
    var returnValue = 0;
    if(defaultValue) returnValue = defaultValue;
    if(typeof(srcValue) != "undefined")
    {
        try
        {
            returnValue = parseInt(srcValue);
            if(returnValue == NaN) returnValue = defaultValue;
        }
        catch(e)
        {
            returnValue = defaultValue;
        }
    }
    else
    {
        returnValue = defaultValue;
    }
    return returnValue;
}