/*************************************************************************
    This code is from dyn-web.com
    free for all uses as long as this notice retained
*************************************************************************/

/*  dw_loader.js      version date: July 2008
    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';
  //bLoadMsg = bLoadMsg || 'true';

  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;
    // If you want the whole page to scroll to the top when new content is loaded
    //window.scrollTo(0,0);
    var lyr = document.getElementById? document.getElementById(divId): null;
    //alert(lyr.innerHTML);
    if ( lyr && bLoadMsg ) { // Option to display message while retrieving data
        lyr.innerHTML = '<p>Retrieving data. Please wait ...</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';

  // hidding or unhidding banner depends on selected page
  var url=window.frames[ifrmId].location.href;
  var banner = document.getElementById? document.getElementById('banner'): null;
  if (url.indexOf('baubeschreibung') != -1 || url.indexOf('statistik') != -1) {
    banner.style.visibility = "hidden";
  } else {
    banner.style.visibility = "visible";
  }

  var display = document.getElementById? document.getElementById('display'): null;
  //alert(display.style.padding);
  if (url.indexOf('home') != -1 || url.indexOf('kontakt') != -1 || url.indexOf('idee') != -1 || url.indexOf('impressum') != -1 || url.indexOf('portrait') != -1) {
    display.style.width = 839+"px"; // padding 2x8px abgezogen
  } else {
    display.style.width = 959+"px"; // padding 2x8px abgezogen
  }

  var lyr = document.getElementById? document.getElementById(divId): null;
      lyr.style.display = 'block';
  if ( window.frames[ifrmId] && lyr ) {
      lyr.innerHTML = window.frames[ifrmId].document.body.innerHTML;
      //alert("display:\n"+lyr.innerHTML);
      lyr.style.display = 'block';
      // when using with script, may have some operations to coordinate
      // function 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();
      }
  }

    // Reinit ajax tab mechanism otherwise the tabcontainer would be empty
    if (document.getElementById('tabcontainer')) {
      var countries=new ddajaxtabs("tabs", "tabcontainer");
      countries.setpersist(true);
      countries.setselectedClassTarget("link"); //"link" or "linkparent"
      countries.init();
    }
}

// checks if portal header needs to be loaded
function checkFrameset(page) {
  //alert(page);

  // load header only if not on a mobile device
  if (navigator.platform.indexOf("Linux") != -1 ||
      navigator.platform.indexOf("Mac") != -1 ||
      navigator.platform.indexOf("Win") != -1) {

    if (parent.frames.length == 0)
    {
      // load always statistik main page
      if (page.indexOf("statistik-") == 1) {
        page = "statistik.php";
      }
      location.href="http://www.solarvista.de/?" + page;
    }
  }
}

