﻿// JavaScript File

// set the main object if not already set
if(Axial == null) var Axial = function(){};

// set the Document object
Axial.Document = function(){};

// gets an array of elements based on the provided Object
// The object (args) represents a name-value pair
// Ex.: {id:'the_id',class:'the_class', tag:'div'}
// if no element is found, getElements(args) returns null
Axial.Document.getElements =
function(args)
{
    var ret_val = Array();
    try
    {
        if(args.id)
        {
            ret_val.push(document.getElementById(args.id));
        }
        else if(args.tag)
        {
            ret_val = document.getElementsByTagName(args.tag);
        }

        for(o in args)
        {
            for(var i=0;i<ret_val.length;++i)
            {
                if( ! ret_val[i][o])
                {
                    ret_val.splice(i,1);
                }
            }
        }

        if(ret_val.length == 1 && ret_val[0] == null) ret_val = null;
    }
    catch(ex)
    {
        if(location.search.indexOf('js_debug')>-1)
        {
            alert(ex);
        }
        ret_val = null;
    }
    return ret_val;    
};

// gets an element based on the provided Object
// The object (args) represents a name-value pair
// Ex.: {id:'the_id',class:'the_class', tag:'div'}
// if args is a string, it is considered the id
// if no element is found, getElement(args) returns null
Axial.Document.getElement =
function(args)
{
    if(typeof(args) == 'string') args = {id:args};
    var ret_val = this.getElements(args);
    if(ret_val != null) ret_val = ret_val[0];
    return ret_val;
};

// shows an element
// if the argument is a string, it is considered the id of the element to show
Axial.Document.showElement =
function(obj)
{
    if(typeof(obj) == 'string')obj = this.getElement(obj);
    obj.style.display = 'block';
}

// hides an element
// if the argument is a string, it is considered the id of the element to hide
Axial.Document.hideElement =
function(obj)
{
    if(typeof(obj) == 'string') obj = this.getElement(obj);
    obj.style.display = 'none';
}

Axial.Document.findPosition =
function(obj)
{
    var curleft = curtop = 0;
    if (obj.offsetParent)
    {
        do
        {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
		while (obj = obj.offsetParent);
    }
		return [curleft, curtop];
}

// 
