﻿//methods to handle floating item containers
function RadFloatingContent(controlID, iwindowID) {
    this.controlID = controlID;
    this.containerID = "FloatingItemContainer" + controlID;  //floating item container
    this.iwindow = iwindowID;
    this.oWd = null;

    this.width = 600;
    this.height = 400;
    this.title = '';
    this.flag = 0;
    this.fixXY = false;
}

RadFloatingContent.prototype.showRadContent = function (_title, _url, _width, _height, elm) {
    this.showRadContentFix(_title, _url, _width, _height, false, elm);
}

RadFloatingContent.prototype.showRadContentFix = function (_title, _url, _width, _height, _fixXY, elm) {
    this.oWd = radopen(_url, "'" + this.iwindow + "'");
    this.width = _width;
    this.height = _height;
    this.title = _title;

    this.oWd.set_title(this.title);
    this.oWd.set_width(this.width);
    this.oWd.set_height(this.height);

    this.fixXY = _fixXY;

    this.oWd.center();

    var bounds = this.oWd.getWindowBounds();

//    if (elm != null && elm != 'undefined') {

//        var top = 35;

//        top = this.findPosY(elm);

//        var position = top - 200;

//        if (35 > position) {
//            position = top;
//        }

//        this.oWd.moveTo(bounds.x, position);
    //    }

  

}

RadFloatingContent.prototype.startRadLoadingProgress = function () {
    document.getElementById("progress" + this.controlID).style.display = "inline";
}

RadFloatingContent.prototype.stopRadLoadingProgress = function () {
    document.getElementById("progress" + this.controlID).style.display = "none";
}

RadFloatingContent.prototype.refreshRadContainerSize = function () {

    this.oWd.set_title(this.title);

    if (this.fixXY == false) {
        var docoffsetwidth = this.oWd.get_contentFrame().contentWindow.document.body.offsetWidth;
        var docoffsetheight = this.oWd.get_contentFrame().contentWindow.document.body.offsetHeight;

        var docscrollwidth = this.oWd.get_contentFrame().contentWindow.document.body.scrollWidth;
        var docscrollheight = this.oWd.get_contentFrame().contentWindow.document.body.scrollHeight;

        if (this.flag == 0) {
            this.oWd.set_width(docscrollwidth + 60);

            if (docscrollheight + 60 > 500) {
                this.oWd.set_height(500)
            }
            else {
                this.oWd.set_height(docscrollheight + 60);
            }
            
            this.flag = 1;
        }
    }
    else {
        this.oWd.set_width(this.width);
        this.oWd.set_height(this.height);
    }

    var left = (screen.width / 2) - (this.width / 2);
    var top = (screen.height / 2) - (this.height / 2);

    //this.oWd.moveTo(left, top);

}

RadFloatingContent.prototype.findPosX = function (obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x)
        curleft += obj.x;
    return curleft;
}

RadFloatingContent.prototype.findPosY = function (obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y)
        curtop += obj.y;
    return curtop;
}
