/*************************************************************************
    This code is from Dynamic Web Coding at dyn-web.com
    Copyright 2008-10 by Sharon Paine 
    See Terms of Use at www.dyn-web.com/business/terms.php
    regarding conditions under which you may use this code.
    This notice must be retained in the code as is!
*************************************************************************/

/*  dw_loader.js      version date: May 2010
    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
*/

var dw_Loader = {
    loadMsg: 'Retrieving data ...',
    displayID: 'demo',
    iframeID: 'buffer',
    bReplace: true, // to use location.replace if you do not want back button to load previous iframe url 
    bScrollToTop: false, // page scroll to top when new content is loaded?
    
    load: function (url, iframeID, displayID, loadMsg) {
        var _this = dw_Loader;
        // can pass arg's or use defaults
        iframeID = iframeID || _this.iframeID; 
        displayID = displayID || _this.displayID;
        loadMsg = loadMsg || _this.loadMsg;
        if ( window.frames[iframeID] ) {
            if ( !_this.bReplace ) {
                window.frames[iframeID].location = url;
            } else {
                window.frames[iframeID].location.replace(url);
            }
            if ( _this.bScrollToTop ) {
                window.scrollTo(0,0);
            }
            var el = document.getElementById(displayID);
            if ( el && loadMsg ) { // Option to display message while retrieving data 
                el.innerHTML = loadMsg;
                el.style.display = 'block'; 
            }
            return false;
        } 
        return true; // to follow link 
    },
    
    // called onload of iframe (using iframe's onload attribute or onload in iframed documents)
    // displays body content of iframed doc in div
    // when using in iframe onload attribute, can include function pointer as 3rd arg
    display: function (iframeID, displayID, fp) {
        var _this = dw_Loader;
        iframeID = iframeID || _this.iframeID; 
        displayID = displayID || _this.displayID;
        var el = document.getElementById(displayID);
        if ( window.frames[iframeID] && el ) {
            el.innerHTML = window.frames[iframeID].document.body.innerHTML;
            el.style.display = 'block'; 
            if ( typeof fp == 'function' ) {
                fp();
            }
        }
    }
}


