// Loads url in iframe, transfers body content into div.
// Provides defaults for iframe and display div ID's,
// also supports use with multiple iframes and divs.
// Optional message for loading in display div. 
// Supports functions to be called once the div has been populated with new content. 
// Function in iframed document can be invoked should some operations need to be performed from there. 

function dw_loadExternal(url, ifrmId, divId, bLoadMsg) {
    // Defaults for iframe, display div.
    ifrmId = ifrmId || 'buffer'; divId = divId || 'display'; 
    if ( window.frames[ifrmId] ) {
        // Could use location.replace method if you do not want back button to load previous iframe url.
        //window.frames[ifrmId].location.replace(url);
        window.frames[ifrmId].location = url;
        var lyr = document.getElementById? document.getElementById(divId): null;
        if ( lyr && bLoadMsg ) { // Option to display message while retrieving data.
            lyr.innerHTML = '<p>Retrieving data.....</p>';
            lyr.style.display = 'block'; 
        }
        return false;
    } 
    return true; // Other browsers follow link.
}

// Called onload of iframe. 
// Displays body content of iframed doc in div.
// Checks for and invokes optional functions in both current document and iframed document.
function dw_displayExternal(ifrmId, divId, fp) {
    // Defaults for iframe, display div.
    ifrmId = ifrmId || 'buffer'; divId = divId || 'display'; 
    
    var lyr = document.getElementById? document.getElementById(divId): null;
    if ( window.frames[ifrmId] && lyr ) {
        lyr.innerHTML = window.frames[ifrmId].document.body.innerHTML;
        lyr.style.display = 'block'; 

        // When using with script, may have some operations to coordinate.
        // Ffunction in current doc or iframed doc (doOnIframedLoad).
        if ( typeof fp == 'function' ) {
            fp();
        }
        
        // Demonstrated in tooltip demo.
        if ( typeof window.frames[ifrmId].doOnIframedLoad == 'function' ) {
            window.frames[ifrmId].doOnIframedLoad();
        }
    }
}

