﻿/*################################
### Standard Div Functions     ###
################################*/

function isObject(o) {
    var sofar = true;
    if (typeof (o) != "object")
        sofar = false;
    if (o == null)
        sofar = false;
    if (o == undefined)
        sofar = false;

    return sofar;
}


function isNumeric(x) {
    // I usually use the this function like this: if (isNumeric(myVar)) { } 
    // regular expression that validates a value is numeric
    var RegExp = /^(-)?(\d*)(\.?)(\d*)$/;
    // Note: this WILL allow a number that ends in a decimal: -452.
    // compare the argument to the RegEx
    // the 'match' function returns 0 if the value didn't match
    var result = RegExp.test(x);
    return result;
}

function objController(obj) {

    this.input = obj;

    this.Load = function(obj) {
        if (!isObject(obj)) {
            //alert(this.input);
            obj = document.getElementById(obj);
        }

        if (!isObject(obj))
            return false;

        this.Object = obj;

        return true;
    }

    this.Hide = function() {
        if (!isObject(this.Object))
            return false;

        //alert(isObject(this.Object));
        //alert(this.input);

        //alert(this.Object.id);
        this.Object.style.visibility = 'hidden';
        this.Object.style.position = 'absolute';
        this.Object.style.display = 'none';

        return true;
    }

    this.Show = function(pos) {

        if (!isObject(this.Object))
            return false;
        //alert(this.Object.style.left);
        if (pos != 'absolute')
            pos = 'static';
        //alert(this.Object.style.left);
        this.Object.style.visibility = 'visible';
        this.Object.style.position = pos;
        this.Object.style.display = 'inline';
        //alert(this.Object.style.left);

        return true;
    }

    this.GetLeft = function() {
        var curleft = 0;

        if (!isObject(this.Object))
            return curleft;

        var obj = this.Object;

        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curleft += obj.offsetLeft;
                obj = obj.offsetParent;
            }
        }
        else if (obj.x)
            curleft += obj.x;

        return curleft;
    }

    this.GetTop = function() {
        var curtop = 0;

        if (!isObject(this.Object))
            return curtop;

        var obj = this.Object;

        if (obj.offsetParent) {
            while (obj.offsetParent) {
                curtop += obj.offsetTop
                obj = obj.offsetParent;
            }
        }
        else if (obj.y)
            curtop += obj.y;

        return curtop;
    }


    this.OpacityTransition = function(intOpacBegin, intOpacEnd, intMilliseconds) {

        // Speed for each frame
        var speed = Math.round(intMilliseconds / 100);
        var timer = 0;

        // Determine the direction for the blending, if start and end are the same nothing happens
        if (intOpacBegin > intOpacEnd) {
            for (i = intOpacBegin; i >= intOpacEnd; i--) {
                if (isNumeric(i) == true && i >= 0)
                    setTimeout("SetObjectOpacity(" + i + ", '" + this.Object.id + "')", (timer * speed));
                timer++;
            }
        }
        else if (intOpacBegin < intOpacEnd) {
            for (i = intOpacBegin; i <= intOpacEnd; i++) {
                if (isNumeric(i) == true && i >= 0)
                    setTimeout("SetObjectOpacity(" + i + ", '" + this.Object.id + "')", (timer * speed));
                timer++;
            }
        }

        return true;

    }

    this.GetOpacity = function() {
        if (!isObject(this.Object))
            return 0;

        var Opac = 0;

        if (isNumeric(this.Object.style.opacity))
            Opac = (this.Object.style.opacity * 100);

        return Opac;
    }

    this.SetOpacity = function(intOpacity) {
        //alert(intOpacity);
        //intOpacity = intOpacity / 100
        //alert(this.Object.id + ' to ' + intOpacity);
        SetObjectOpacity(intOpacity, this.Object.id);
        return;
        if (!isObject(this.Object)) {
            if (isObject(strID))
                this.Object = document.getElementById(strID);

            if (!isObject(this.Object))
                return false;
        }

        alert(this.Object.id);
        this.Object.opacity = (intOpacity / 100);
        this.Object.MozOpacity = (intOpacity / 100);
        this.Object.KhtmlOpacity = (intOpacity / 100);
        this.Object.filter = 'alpha(opacity=' + intOpacity + ')';

        return true;
    }

    this.FadeIn = function(timeout) {
        this.OpacityTransition(this.GetOpacity(), 100, timeout);
    }

    this.FadeOut = function(timeout) {
        this.OpacityTransition(this.GetOpacity(), 0, timeout);
    }

    //if (!isObject(obj))
    this.Load(obj);

    //if (!isObject(this.input) && this.input != this.Objectg

    return this;

}
