// the source attirbute is to avoid a IE error message about non secure content on https connections
document.write('<div id="_fpPopinFrameContainer" style="z-index:10;padding:0 4px 4px 0;position:absolute;left:0px;top:0px;width:0px;height:0px;visibility:hidden;overflow:hidden;filter:shadow(color:gray, strength:4, direction:135)"><iframe name="_fpPopinFrame" id="_fpPopinFrame" src="/blank.htm" width="100%" height="100%" hspace="0" scrolling="auto" frameborder="0" marginwidth="0" marginheight="0" class="dlgWindow" style="padding:0px;border-top:1px solid silver;border-left:1px solid silver;');
if (YAHOO.widget.Module.prototype.browser.indexOf('ie') != 0) {
    document.write('border:1px solid silver');
}
document.write('"></iframe></div>');


//This one is iframe based and hides the popin when user clicks elsewhere on the page.
function PopinFrame() {
    this.contDivId = "_fpPopinFrameContainer";
    this.frameId = "_fpPopinFrame";    
    this.clickHandler = this.clickHandlerFn.bind(this);
}

PopinFrame.prototype.show = function(src, x, y, height, width) {
    //debug(x,y);
    var frm = $(this.contDivId);
    var IFrameObj = $(this.frameId);
    if (IFrameObj.src != src) {
        //replace iframe src. (can't simply change src property as that will add it to 
        //history as well and make frustrating back button experience. Instead try
        //location.replace
        //Still need to test this on Safari and Opera
        if (IFrameObj.contentDocument) {
            // For NS6
            IFrameDoc = IFrameObj.contentDocument; 
        } else if (IFrameObj.contentWindow) {
            // For IE5.5 and IE6
            IFrameDoc = IFrameObj.contentWindow.document;
        } else if (IFrameObj.document) {
        // For IE5
            IFrameDoc = IFrameObj.document;
        } else {
            IFrameDoc = null;
        }
        if (IFrameDoc != null) {
            IFrameDoc.location.replace(src);
        }
        else {
            IFrameObj.src = src;
        }
    }

    if (height == undefined) {
        height = 300;
    }
    
    if (width == undefined) {
        width = 425;
    }
    frm.style.width = width + 'px';
    frm.style.height = height + 'px';
    displayPopinFrame(this.contDivId, true, x, y);

    var e = YAHOO.util.Event.getEvent();
    if (e) {
        if (e.type == 'click') {
            Event.stop(e); //stop click event as otherwise it will hide the popin frame rigt away during bubbling phase.
        }
    }    
    Event.observe(document, "click", this.clickHandler, false);
}

PopinFrame.prototype.hide = function() {
    displayPopinFrame(this.contDivId, false);
}

PopinFrame.prototype.moveBy = function(x, y) {
    $(this.contDivId).style.left = ($(this.contDivId).offsetLeft + x) + "px";
    $(this.contDivId).style.top = ($(this.contDivId).offsetTop + y) + "px";
}

PopinFrame.prototype.clickHandlerFn = function() {
    //Hide popin
    displayPopinFrame(this.contDivId, false);
    var frm = $(this.frameId);
    frm.src = "";
    //stop observing event
    Event.stopObserving(document,'click', this.clickHandler, false);
}

gPopinFrame = new PopinFrame();
/* --- End Popin frame --- */

function callbackClose() {
    gPopinFrame.clickHandlerFn();
}
