function getww(){
  if(window.innerWidth) wx=window.innerWidth;
  else if(document.body && document.body.offsetWidth) wx=document.body.offsetWidth;
}
 
function getwh(){
  if(window.innerHeight) wy=window.innerHeight;
  else if(document.body && document.body.offsetHeight) wy=document.body.offsetHeight;
}

function appendScript(link)
{
  var skript = document.createElement("script");
  skript.src = link;
  document.getElementsByTagName("body")[0].appendChild(skript);
}

function setAttributes(els, x, y, w, h)
{
  els.width = w + "px";
  els.height = h + "px";
  els.left = x + "px";
  els.top = y + "px";
}

function getYPosition(element)
{
  var elem=element,tagname="",y=0;

  while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined"))
  {
    y+=elem.offsetTop;
    tagname=elem.tagName.toUpperCase();
    if (tagname=="BODY" || tagname=="HTML")
    {
      return y;
    }
    if (typeof(elem)=="object")
      if (typeof(elem.offsetParent)=="object")
        elem=elem.offsetParent;
  }
  return y;
}

// ----------------- TURN PAGE FUNCTIONS SECTION -------------------

function movePages(dir, xPixels)
{
  // bd.style.overflow = "hidden";
  moveDx = xPixels;
  if(dir==-1) backPagesAction(0);
  else forwardPagesAction(blaetterBreite); 
}

function forwardPagesAction(a)
{
  a-= moveDx;
  if (a <= 0 )
  {
    positionPages(par0, par1, 0);
    endProcedures();
  }
  else
  {
    positionPages(par0, par1, a);
    setTimeout("forwardPagesAction(" + a + ")", 50);
  }
  return;
}

function backPagesAction(a)
{
  a+=moveDx;
  if (a >= blaetterBreite )
  {
    positionPages(par1, par0, blaetterBreite);
    // bd.style.overflow = "auto";
    endProcedures();
  }
  else
  {
    positionPages(par1, par0, a);
    setTimeout("backPagesAction(" + a + ")", 50);
  }
  return;
}

function positionPages(li, re, x)
{
  lis = li.style;
  res = re.style;
  lis.left = baseLeft + x - blaetterBreite + "px";
  res.left = baseLeft + x + "px";
  setClip(lis, blaetterBreite - x, 0, blaetterBreite, li.offsetHeight);
  setClip(res, 0, 0, blaetterBreite - x, re.offsetHeight);
}

// --------------- END TURN PAGE FUNCTIONS SECTION -----------------

// ------------------- MORPH FUNCTIONS SECTION ---------------------

function initMorph(steps, stepTime)
{
  morphSteps = steps;
  morphStep = 1/steps;
  morphSumSteps = 0;
  morphTimeout = stepTime;
  if(typeof morphFromArr != "undefined")
  {
    delete morphFromArr;
    delete morphToArr;
    delete morphPrevArr;
    delete morphPostArr;
    delete morphChangeArr;
    delete morphChangeStorArr;
  }
  morphNo = 0;
  morphFromArr =  new Array();
  morphToArr = new Array();
  morphPrevArr =  new Array();
  morphPostArr =  new Array();
  morphChangeArr = new Array(steps);
  morphChangeStorArr = new Array();
}

function addMorphEl(el0, w0, h0, l0, t0, el1, w1, h1, l1, t1)
{
  var el0s = el0.style;
  var el1s = el1.style;
  setAttributes(el0s, l0, t0, w0, h0);
  setAttributes(el1s, l1, t1, w1, h1);
  el0s.overflow = "hidden";
  el1s.overflow = "hidden";
  morphFromArr[morphNo]    = el0;
  morphToArr[morphNo]      = el1;
  morphPrevArr[morphNo]    = new Array(w0, h0, l0, t0);
  morphPostArr[morphNo]    = new Array(w1, h1, l1, t1);
  morphChangeArr[morphNo] = new Array((w1-w0)/morphSteps, (h1-h0)/morphSteps, (l1-l0)/morphSteps, (t1-t0)/morphSteps);
  morphChangeStorArr[morphNo]   = new Array(w0, h0, l0, t0);
  morphNo++;
}

function morphOver(a)
{
  if(a < morphSteps)
  {
    morphSumSteps+= morphStep;
    for(i in morphFromArr)
    {
      for (j=0; j<4; j++)
      {
        morphChangeStorArr[i][j]+= morphChangeArr[i][j];
      }
      for (j=0; j<2; j++)
      {
        var el = (j==0) ? morphFromArr[i] : morphToArr[i];
        var els = el.style;
        els.width  = morphChangeStorArr[i][0] + "px";
        els.height = morphChangeStorArr[i][1] + "px";
        els.left   = morphChangeStorArr[i][2] + "px";
        els.top    = morphChangeStorArr[i][3] + "px";
      }
      setOpacity(morphFromArr[i].style, 1-morphSumSteps);
      setOpacity(morphToArr[i].style, morphSumSteps);
    }
    morphSumSteps+= morphStep;
    a++;
    setTimeout("morphOver(" + a + ")", morphTimeout);
  }
  else
  {
    for (i in morphFromArr)
    {
      var el = morphToArr[i];
      var els = el.style;
      els.width  = morphPostArr[i][0] + "px";
      els.height = morphPostArr[i][1] + "px";
      els.left   = morphPostArr[i][2] + "px";
      els.top    = morphPostArr[i][3] + "px";
      setOpacity(morphFromArr[i].style, 0);
      setOpacity(morphToArr[i].style, 1);
    }
    morphOverEndProcedures();
  }
}

// ----------------- END MORPH FUNCTIONS SECTION -------------------

// ------------------ PROMPT FUNCTIONS SECTION ---------------------

function createErrorDivs(w, h, html, bgcolor, border)
{
  if (typeof el != "undefined") return;
  mArray = new Array(0.4, 0.475, 0.55, 0.625, 0.7, 0.775, 0.85, 0.925, 1, 1.14, 1.07, 1, 0.96, 0.92, 0.95, 0.97, 1);
  mArrayAnz = mArray.length;
  mitteX = Math.floor(wx / 2);
  mitteY = Math.floor(wy / 2);
  leftPos = Math.floor(mitteX - w / 2);
  topPos = Math.floor(mitteY - h / 2);
  el = document.createElement("div");
  els = el.style;
  els.border = border; // "3px solid #cc0000";
  els.backgroundColor = bgcolor;
  moveSetAttributes(els, w, h, leftPos, topPos);
  els.overflow = "hidden";
  document.getElementsByTagName("body")[0].appendChild(el);
  iEl = document.createElement("div");
  iEl.innerHTML = html; // "<div align=center style='color:black;font-family:arial;font-size:12pt;padding:15px'><img src='img/warning_icon.png' width=84 height=70 border=0 style='float:left'><?=$this->fehler?></div>";
  iEls = iEl.style;
  moveSetAttributes(iEls, w, h, 0, 0);
  iEls.display = "none";
  el.appendChild(iEl);
  moveErrorDivs(w ,h , 0);
}

function moveErrorDivs(w, h, a)
{
  els.display = "block";
  var x1 = Math.floor(mArray[a] * w);
  var y1 = Math.floor(mArray[a] * h);
  els.width = x1 + "px";
  els.height = y1 + "px";
  els.left = leftPos + Math.floor((w - x1) / 2) + "px";
  els.top = topPos + Math.floor((h - y1) / 2) + "px";
  if(a >= 9)
  {
    iEls.display = "block";
    iEls.left = -Math.floor((w - x1) / 2) + "px";
    setTimeout("closeError()", 2000);
  }
  if(++a < mArrayAnz)
  {
    setTimeout("moveErrorDivs(" + w + "," + h + "," + a + ");", 30);
  }
}

function moveSetAttributes(els, w, h, l, t)
{
  els.position = "absolute";
  els.width = w + "px";
  els.height = h + "px";
  els.left = l + "px";
  els.top  = t + "px";
}

function closeError()
{
  document.getElementsByTagName("body")[0].removeChild(el);
  delete(el);
}

// ---------------- END PROMPT FUNCTIONS SECTION -------------------


// ---------------------- SCROLL UP SECTION ------------------------

function createArticleDivs(text, titel, thema, datum, farbe, logged_in)
{
  loggedIn = logged_in;
  if(typeof div1 != "undefined") return;
  getwh();
  baseTop = 100;
  div0 = document.getElementById("par0");
  html = "<table width=815 cellspacing=0 cellpadding=0 border=0><tr><td height=10></td></tr><tr><td width=100% height=80 align=center valign=middle bgcolor=" + farbe + "><table width=95% cellspacing=0 cellpadding=0 border=0><tr><td width=100% bgcolor=#ffffff valign=middle class='menu1' style='border-top:1px solid #000000;border-left:1px solid #000000;border-bottom:1px solid #000000;padding-left:15px;padding-top:7px;padding-bottom:7px;padding-right:15px'><div style='line-height:25px;font-family:verdana,arial;font-size:14pt'>" + titel + "</div><div style='font-family:verdana,arial;font-size:8pt;'><i>Jesus-Christus.de, " + datum + "</i></div></td><td width=20% bgcolor=#aadddd align=center valign=middle style='font-family:verdana,arial;font-size:24pt;color:#ffffff;border:1px solid #000000;padding:7px'>" + thema + "</td></tr></table></td></tr><tr><td height=10></td></tr></table>" + text;
  div1 = createDiv("100%", "100%", "0px", wy + "px", html);
  //document.getElementsByTagName("body")[0].style.overflow = "hidden";
  scrollUp(wy);
}

function createScrollUpDiv(w, h, l, t)
{
  div1 = document.createElement("div");
  els = div1.style;
  els.position = "absolute";
  els.marginLeft = "10px";
  els.width = w;
  els.top = t;
  els.left = l;
  els.backgroundColor = "white";
  els.textAlign = "center";
  scrollh = Math.floor((wy - baseTop) / 5);
  div1.innerHTML = "<div class=menu1 align=justify style='width:815px'>" + html + "</div>";
  document.getElementsByTagName("body")[0].appendChild(div1);
  return div1;
}

function scrollUp(a)
{
  a-=scrollh;
  if(a > baseTop)
  {
    div1.style.top = a + "px"; 
    setTimeout("scrollUp(" + a + ")", 50);
  }
  else
  {
    div1.style.top = baseTop + "px";
    if (loggedIn)
    {
      document.getElementsByTagName("body")[0].removeChild(div0);
    }else{
      document.getElementsByTagName("form")[0].removeChild(div0);
    }
    div1.setAttribute("id", "par0");
    div0 = div1;
    delete div1;
    //document.getElementsByTagName("body")[0].style.overflow = "auto";
  }
}

// ------------------- END SCROLL UP SECTION -----------------------

function setOpacity(els, val)
{
  if(val > 1) val = 1;
  els.opacity = val;
  els.filter = "alpha(opacity=" + Math.floor(val*100) + ")";
}

function zoomIn(a)
{
  setClip(comment.style, 0, 0, divWidth, a);
  setClip(thread.style, 0, 0, divWidth, a);
  a+=25;
  if (a < comHoehe) setTimeout("zoomIn(" + a + ")", 30);
  else
  {
    setClip(comment.style, 0, 0, divWidth, comHoehe);
    setClip(thread.style, 0, 0, divWidth, comHoehe);
    endShowThread();
  }
}

function setClip(es, x0, y0, x1, y1)
{
  es.clip="rect(" + y0 + "px," + x1 + "px," + y1 + "px," + x0 + "px)";
}

function endProcedures()
{
  var par = par0.parentNode;
  par.removeChild(par0);
  par0 = par1;
}

