﻿/*
    This file provides some basic functions that are useful across libraries.
 */

var General = new function()
{
    this.IsExplorer = function()
    {
        return (document.all);
    }; // IsExplorer()

    this.GetLeftPosition = function(obj)
    {
        var cp = 0;
        while(obj.offsetParent)
        {
            cp += obj.offsetLeft;
            obj = obj.offsetParent;
        }
        return cp;
    }; // GetLeftPosition(obj)
    this.GetTopPosition = function(obj)
    {
        var cp = 0;
        while(obj.offsetParent)
        {
            cp += obj.offsetTop;
            obj = obj.offsetParent;
        }
        return cp;
    }; // GetTopPosition(obj)
    
    this.FilterResults = function(n_win, n_docel, n_body)
    {
	    var n_result = n_win ? n_win : 0;
	    if (n_docel && (!n_result || (n_result > n_docel))) { n_result = n_docel; }
	    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
    }; // FilterResults(window, documentElement, body)

    
    this.GetWindowWidth = function()
    {
        return this.FilterResults(window.innerWidth ? window.innerWidth : 0, document.documentElement ? document.documentElement.clientWidth : 0, document.body ? document.body.clientWidth : 0);
    }; // GetWindowWidth()
    this.GetWindowHeight = function()
    {
        if (typeof(window.innerWidth) == 'number') { return window.innerHeight; } // Non-IE
        else if (document.documentElement && document.documentElement.clientHeight) { return document.documentElement.clientHeight; } // IE 6+ in 'standards compliant mode'
        else if (document.body && document.body.clientHeight) { return document.body.clientHeight; } // IE 4 compatible

        return 0;
    }; // GetWindowHeight()
    this.GetWindowDimensions = function()
    {
        return [this.GetWindowWidth(), this.GetWindowHeight()];
    }; // GetWindowDimensions()
    this.GetScrollPositions = function()
    {
        if (typeof(window.pageYOffset) == 'number') { return [window.pageXOffset, window.pageYOffset]; } // Netscape compliant
        else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) { return [document.body.scrollLeft, document.body.scrollTop]; } // DOM compliant
        else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) { return [document.documentElement.scrollLeft, document.documentElement.scrollTop]; } // IE6 standards compliant mode
        
        return [0, 0];
    }; // GetScrollPositions()
};
