/*******************************
*
* DhtmlAPI.js
* 
* Element Control class
* Ver = 1.3
*
* Author: John Hutcheson, control.option
* References: DHTMLapi.js by Danny Goodman (http://www.dannyg.com) Release 2.0.
*
*******************************/

// DhtmlAPI constructor function
function DhtmlAPI() {
	if (document.images) {
		this.isWin = (navigator.platform=="Win32") ? true : false;
		this.isMac = (navigator.platform=="MacPPC") ? true : false;
		this.isCSS = (document.body && document.body.style) ? true : false;
        this.isW3C = (this.isCSS && document.getElementById) ? true : false;
		this.isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
        this.isIE6CSS = (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) ? true : false;
		this.isIE7 = (document.documentElement && typeof document.documentElement.style.maxHeight!="undefined" && document.all) ? true : false;
    }
	
}


// Convert object name string or object reference
// into a valid element object reference
DhtmlAPI.prototype.getRawObj = function(objId) {
	var theObj;
    if (typeof objId == "string") {
		theObj = document.getElementById(objId);
    } else {
		// pass through object reference
		theObj = objId;
    }
    return theObj;
}

DhtmlAPI.prototype.getObj = function(objId) {
	var theObj = this.getRawObj(objId);
	if (theObj) {
		theObj = theObj.style;
    }
	return theObj;
}

// Position an object at a specific pixel coordinate
DhtmlAPI.prototype.shiftTo = function(objId, x, y) {
    var theObj = this.getObj(objId);
    if (theObj) {
        // equalize incorrect numeric value type
		var units = (typeof theObj.left == "string") ? "px" : 0;
		theObj.left = x + units;
		theObj.top = y + units;
    }
}

// Move an object by x and/or y pixels
DhtmlAPI.prototype.shiftBy = function(objId, deltaX, deltaY) {
    var theObj = this.getObj(objId);
	if (theObj) {
		// equalize incorrect numeric value type
		var units = (typeof theObj.left == "string") ? "px" : 0;
		theObj.left = this.getObjLeft(objId) + deltaX + units;
		theObj.top = this.getObjTop(objId) + deltaY + units;
   }
}

// Set the z-order of an object
DhtmlAPI.prototype.setZIndex = function(objId, zOrder) {
    var theObj = this.getObj(objId);
    if (theObj) {
        theObj.zIndex = zOrder;
    }
}

// Set the background color of an object
DhtmlAPI.prototype.setBGColor = function(objId, color) {
    var theObj = this.getObj(objId);
    if (theObj) {
        theObj.backgroundColor = color;
    }
}

// Set the css_class of an object
DhtmlAPI.prototype.setCssClass = function(objId, cssClass) {
	var theObj = this.getRawObj(objId);
    if (theObj) {
		theObj.className = cssClass;
    }
}

// Set the visibility of an object to visible
DhtmlAPI.prototype.show = function(objId) {
	var theObj = this.getObj(objId);
    if (theObj) {
        theObj.visibility = "visible";
    }
}

// Set the visibility of an object to hidden
DhtmlAPI.prototype.hide = function(objId) {
    var theObj = this.getObj(objId);
    if (theObj) {
        theObj.visibility = "hidden";
    }
}

// Set the display of an object to none
DhtmlAPI.prototype.displayNone = function(objId) {
	var theObj = this.getObj(objId);
    if (theObj) {
        theObj.display = "none";
    }
}

// Set the display of an object to block
DhtmlAPI.prototype.displayBlock = function(objId) {
	var theObj = this.getObj(objId);
    if (theObj) {
        theObj.display = "block";
    }
}

// Set the display of an object to inline
DhtmlAPI.prototype.displayInline = function(objId) {
	var theObj = this.getObj(objId);
    if (theObj) {
        theObj.display = "inline";
    }
}

// Retrieve the x coordinate of a positionable object
DhtmlAPI.prototype.getObjLeft = function(objId)  {
    var elem = this.getRawObj(objId);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("left");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.left;
    } else if (elem.style) {
        result = elem.style.left;
    }
    return parseInt(result);
}

// Retrieve the y coordinate of a positionable object
DhtmlAPI.prototype.getObjTop = function(objId)  {
    var elem = this.getRawObj(objId);
    var result = 0;
    if (document.defaultView) {
        var style = document.defaultView;
        var cssDecl = style.getComputedStyle(elem, "");
        result = cssDecl.getPropertyValue("top");
    } else if (elem.currentStyle) {
        result = elem.currentStyle.top;
    } else if (elem.style) {
        result = elem.style.top;
    }
    return parseInt(result);
}

// Retrieve the rendered width of an element
DhtmlAPI.prototype.getObjWidth = function(objId)  {
    var elem = this.getRawObj(objId);
    var result = 0;
    if (elem.offsetWidth) {
//        if (elem.scrollWidth && (elem.offsetWidth != elem.scrollWidth)) {
//            result = elem.scrollWidth;
//        } else {
            result = elem.offsetWidth;
//        }
    } else if (elem.clip && elem.clip.width) {
        result = elem.clip.width;
    } else if (elem.style && elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    return parseInt(result);
}

// Retrieve the rendered height of an element
DhtmlAPI.prototype.getObjHeight = function(objId)  {
    var elem = this.getRawObj(objId);
    var result = 0;
    if (elem.offsetHeight) {
        result = elem.offsetHeight;
    } else if (elem.clip && elem.clip.height) {
        result = elem.clip.height;
    } else if (elem.style && elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    return parseInt(result);
}


// Return the available content width space in browser window
DhtmlAPI.prototype.getInsideWindowWidth = function() {
    if (window.innerWidth) {
        return window.innerWidth;
    } else if (this.isIE6CSS) {
        // measure the html element's clientWidth
        return document.body.parentElement.clientWidth;
    } else if (document.body && document.body.clientWidth) {
        return document.body.clientWidth;
    }
    return 0;
}
// Return the available content height space in browser window
DhtmlAPI.prototype.getInsideWindowHeight = function() {
    if (window.innerHeight) {
        return window.innerHeight;
    } else if (this.isIE6CSS) {
        // measure the html element's clientHeight
        return document.body.parentElement.clientHeight;
    } else if (document.body && document.body.clientHeight) {
        return document.body.clientHeight;
    }
    return 0;
}