//-------------------------
//-- START OF EVENT CODE --
//-------------------------
function Event(evt)
{
    this.event = GetEvent(evt);
    this.eventElement = GetEventElement(evt);
    this.eventElementPosition = GetEventElementPosition(evt);
    this.eventElementDimensions = GetEventElementDimensions(evt);
    this.windowDimensions = GetWindowDimensions();
}

function GetEvent(evt)
{
    if(window.event)
    {
        return window.event;
    }
    else
    {
        return evt;
    }
}

function GetEventElement(evt)
{
    var e = GetEvent(evt);

    var elm;
    if(e.srcElement)
    {
        elm = e.srcElement;
    }
    else
    {
        elm = e.target;
    }
    
    return elm;
}

function GetEventElementPosition(evt)
{
    var obj = GetEventElement(evt);
    
	var curleft = 0;
	var curtop = 0;
	
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
        {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return [curleft, curtop];
}

function GetEventElementDimensions(evt)
{
    var obj = GetEventElement(evt);
    
	var innerWidth = 0;
	var innerHeight = 0;
	
    if(obj.offsetWidth)
    {   
        innerWidth = obj.offsetWidth;
        innerHeight = obj.offsetHeight;
    }
    else
    {
        innerWidth = obj.clientWidth;
        innerHeight = obj.clientHeight;
    }
    
	return [innerWidth, innerHeight];
}

function GetElementPosition(obj)
{
	var curleft = 0;
	var curtop = 0;
	
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent)
        {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	
	return [curleft, curtop];
}

function GetElementDimensions(obj)
{
	var innerWidth = 0;
	var innerHeight = 0;
	
    if(obj.offsetWidth)
    {   
        innerWidth = obj.offsetWidth;
        innerHeight = obj.offsetHeight;
    }
    else
    {
        innerWidth = obj.clientWidth;
        innerHeight = obj.clientHeight;
    }
    
	return [innerWidth, innerHeight];
}

function GetWindowDimensions()
{
    if (window.innerWidth)
    {
        return [window.innerWidth, window.innerHeight];
    }
    else if(document.body.clientWidth != 0)
    {
        return [document.documentElement.clientWidth, document.documentElement.clientHeight];
    }
    else if (document.documentElement.clientHeight != 0)
    {
        return [document.body.clientWidth, document.body.clientHeight];
    }
    else
    {
        return [0, 0];
    }
}

//function GetWindowDimensions()
//{
//    if (window.innerWidth)
//    {
//        return [window.innerWidth, window.innerHeight];
//    }
// 
//    if (document.documentElement.clientWidth)
//    {
//        return [document.documentElement.clientWidth, document.documentElement.clientHeight];
//    }
//    
//    if (document.body.clientWidth)
//    {
//        return [document.body.clientWidth, document.body.clientHeight];
//    }
//    
//    return [0, 0];
//}

function GetWindowScrollDimensions()
{
    if (window.innerWidth)
    {
        return [window.innerWidth, window.innerHeight];
    }
 
    if (document.documentElement.scrollWidth)
    {
        return [document.documentElement.scrollWidth, document.documentElement.scrollHeight];
    }
    
    if (document.body.scrollWidth)
    {
        return [document.body.scrollWidth, document.body.scrollHeight];
    }
    
    return [0, 0];
}

//function GetIFrameWindowDimensions(iframe)
//{
//    if (iframe.contentWindow.innerWidth)
//    {
//        return [iframe.contentWindow.innerWidth, iframe.contentWindow.innerHeight];
//    }
//    
//    if (iframe.contentWindow.document.body.clientWidth)
//    {
//        return [iframe.contentWindow.document.body.clientWidth, iframe.contentWindow.document.body.clientHeight];
//    }
//    
//    return [0, 0];
//}

function GetIFrameWindowDimensions(iframe)
{
    if (iframe.contentWindow.document.body.clientWidth)
    {
        return [iframe.contentWindow.document.body.clientWidth, iframe.contentWindow.document.body.clientHeight];
    }
    
    if (iframe.contentDocument.width)
    {
        return [iframe.contentDocument.width, iframe.contentDocument.height];
    }
    
    return [0, 0];
}

function GetMouseOverElement(evt, elm)
{
    var e = GetEvent(evt);
    var pos = GetMousePosition(e);
    var elmPos = GetElementPosition(elm);
    var elmDim = GetElementDimensions(elm);
    
    if(pos[0] >= elmPos[0] && pos[0] <= (elmPos[0] + elmDim[0]) && pos[1] >= elmPos[1] && pos[1] <= (elmPos[1] + elmDim[1]))
    {   
        return true;
    }
    else
    {
	    return false;
	}
}

function GetMousePosition(evt)
{
    var e = GetEvent(evt);
    return [e.clientX, e.clientY];
}

//-----------------------
//-- END OF EVENT CODE --
//-----------------------