﻿/*************************************************************************
  dw_viewport.js  
  free code from dyn-web.com
  version date: mar 2008
*************************************************************************/  
  
var dw_Viewport = {
    getWinWidth: function () {
        this.width = 0;
        if (window.innerWidth) 
            this.width = window.innerWidth - 18;
        else if (document.documentElement && document.documentElement.clientWidth) 
            this.width = document.documentElement.clientWidth;
        else if (document.body && document.body.clientWidth) 
            this.width = document.body.clientWidth;
        return this.width;
    },
  
    getWinHeight: function () {
        this.height = 0;
        if (window.innerHeight) 
            this.height = window.innerHeight - 18;
        else if (document.documentElement && document.documentElement.clientHeight) 
            this.height = document.documentElement.clientHeight;
        else if (document.body && document.body.clientHeight) 
            this.height = document.body.clientHeight;
        return this.height;
    },
  
    getScrollX: function () {
        this.scrollX = 0;
        if (typeof window.pageXOffset == "number") 
            this.scrollX = window.pageXOffset;
        else if (document.documentElement && document.documentElement.scrollLeft)
            this.scrollX = document.documentElement.scrollLeft;
        else if (document.body && document.body.scrollLeft) 
            this.scrollX = document.body.scrollLeft; 
        else if (window.scrollX) 
            this.scrollX = window.scrollX;
        return this.scrollX;
    },
    
    getScrollY: function () {
        this.scrollY = 0;    
        if (typeof window.pageYOffset == "number") 
            this.scrollY = window.pageYOffset;
        else if (document.documentElement && document.documentElement.scrollTop)
            this.scrollY = document.documentElement.scrollTop;
        else if (document.body && document.body.scrollTop) 
            this.scrollY = document.body.scrollTop; 
        else if (window.scrollY) 
            this.scrollY = window.scrollY;
        return this.scrollY;
    },
    
    getAll: function () {
        this.getWinWidth(); this.getWinHeight();
        this.getScrollX();  this.getScrollY();
    }
  
}

function loadIframe(iframeName, url) 
{

  if ( window.frames[iframeName] ) 
  {
    window.frames[iframeName].location = url; return false;
  }
  return true;
}

function colorchange(link)
{
  
  var alllinks = link.parentNode.childNodes;
  for (var i=0;i<alllinks.length;i++)
  {
   if (alllinks[i].className)
	    alllinks[i].className="norm"; //alle Klassen zurücksetzen
  }
   
  link.className="sel"; //geklicktem Link Klasse zuweisen
  return false; //false zurückgeben, damit Linkziel nicht gefolgt wird.
}

function loadIframeParent(iframeName, url) 
{

  if ( parent.window.frames[iframeName] ) 
  {
    parent.window.frames[iframeName].location = url; 
    return false;
  }
  
  return true;
}

function calcObjWidth(id, margin, min) 
{
 if ( document.getElementById ) 
 {
   var elem = document.getElementById(id);

   if (elem) 
   {
    dw_Viewport.getWinWidth();
    if ( dw_Viewport.width > min)
    {
      elem.style.width = dw_Viewport.width - parseInt(elem.style.left,10) - margin + "px";
    
    }
    else
    {
      elem.style.width = min - parseInt(elem.style.left,10) - margin + "px";
    }
   }
 }
}

function calcObjHeight(id, offset, min) 
{
 if ( document.getElementById ) 
 {
   var elem = document.getElementById(id);

   if (elem) 
   {
    dw_Viewport.getWinHeight();
    
    if (dw_Viewport.height > min)
      elem.style.height = dw_Viewport.height - parseInt(elem.style.top,10) - offset + "px";
    else
      elem.style.height = min - parseInt(elem.style.top,10) - offset + "px";
    
   }
 }
}


function calcObjYPos(id,offset, min) 
{
 if ( document.getElementById ) 
 {
   var elem = document.getElementById(id);

   if (elem) 
   {
    dw_Viewport.getWinHeight();
    {
     if (dw_Viewport.height > min) 
       elem.style.top = dw_Viewport.height - parseInt(elem.style.height,10) - offset + "px";
     else
      elem.style.top = min - parseInt(elem.style.height,10) - offset + "px";
    
    }
   }
 }
}
function calcObjXCenter(id,offset, min) 
{
 if ( document.getElementById ) 
 {
   var elem = document.getElementById(id);

   if (elem) 
   {
    dw_Viewport.getWinWidth();
    {
     if (dw_Viewport.width > min) 
       elem.style.left = ((dw_Viewport.width) / 2) - offset + "px";
     else
      elem.style.left = (min / 2) - offset + "px";
    
    }
   }
 }
}


function checkHeight(height) 
{
    
    dw_Viewport.getWinHeight();
    if (dw_Viewport.height > height) return true;
      else return false;
 }
 

function calcCenterRelative(id_ref,id, header, footer) 
{
  
 if ( document.getElementById ) 
 {
   var elem_header = document.getElementById(header);
   var elem_footer = document.getElementById(footer);
   var elem_ref = document.getElementById(id_ref);
   var elem = document.getElementById(id);
   var diff= (parseInt(elem_ref.style.height,10) - parseInt(elem.style.height,10)) / 2;

   if (elem && elem_ref && elem_header) 
   {
    
    elem.style.top = parseInt(elem_ref.style.top,10)+ diff +"px";
    
    elem_header.style.height = diff + "px";
    elem_footer.style.height = diff + 2+"px";
    elem_footer.style.top =  parseInt(elem_ref.style.top,10) + parseInt(elem_ref.style.height,10) - diff + "px";
      
    
    
   }
  }
}







