﻿// JScript-Datei

// getPageSize()
// getHTTPObject()
// showPreview(link)
// hidePreview(link)
// rz()                     resize

function getPageSize()
{
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) 
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} 
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} 
	else 
	{
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) 
	{
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight) 
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} 
	else 
	{ 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	} 
	else 
	{
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}


function getHTTPObject()
{
  var xmlhttp;

  try {
      /*@cc_on

      @if (@_jscript_version >= 5)
        try {
          xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
          try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          } catch (E) {
            xmlhttp = false;
          }
        }
      @else
      xmlhttp = false;
      @end @*/

      if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
        try {
          xmlhttp = new XMLHttpRequest();
        } catch (e) {
          xmlhttp = false;
        }
      }
  } catch(e2) {
    xmlhttp = false;
  } finally {}
  
  return xmlhttp;
}

function currentLanguage()
{
    return document.body.lang;
}

function showPreview(link)
{
    if (!document.getElementById)
        return;

    var id;
    id = link.id;
        
    var obj;
    obj = document.getElementById('Preview');
    
    var obj2;
    obj2 = document.getElementById('TitlePreview');

    
    // obj.innerHTML = link.title;
    
    var xmlHttp = getHTTPObject(); // We create the HTTP Object

    if (xmlHttp)
    {
        var pageParam;
        pageParam = id.substring(4);
        obj.className = pageParam;
        obj2.className = pageParam;
        
        try {
            xmlHttp.open("GET", "SiteService.aspx?xpath=//Node[@id='" + pageParam + "-" + currentLanguage() + "']/Title/node()", true);
            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4) {
                    obj.innerHTML = xmlHttp.responseText;
                    link.title = xmlHttp.responseText;
                    obj2.style.display = 'inline';
                }
            }
            
            xmlHttp.send(null);
       } catch(e3) 
       { }
       finally { }
    }

}

function hidePreview(link)
{
    if (!document.getElementById)
        return;
 
    var id;
    id = link.id;
                    
    var obj;
    obj = document.getElementById('TitlePreview');
    
    obj.style.display = 'none';
}


// http://www.sitepoint.com/article/standards-compliant-world/3

function externalLinks(sessionDisabled) { 
 if (!document.getElementsByTagName) return; 
 var anchors = document.getElementsByTagName("a"); 
 for (var i=0; i<anchors.length; i++) { 
   var anchor = anchors[i]; 
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("rel").indexOf("external") >= 0) {
     anchor.target = "_blank"; 
     anchor.className = "externalLink";
   }
   if (anchor.getAttribute("href") && 
       anchor.getAttribute("href").indexOf("mailto:") == 0) {
     anchor.className = "mailLink";
   }
   
   if (sessionDisabled && anchor.getAttribute("href") && 
           anchor.getAttribute("href").indexOf(".cms") > 0) {
        var hashPos;
        hashPos = anchor.href.indexOf("#");
        if (hashPos < 0)
            anchor.href = anchor.href + "?sd=1";
        else
            anchor.href = anchor.href.substring(0, hashPos) + "?sd=1" + anchor.href.substring(hashPos);
   }
 } 
} 


function modifyInternalLinks()
{   
    if (!document.getElementsByTagName) return; 
    
    var anchors = document.getElementsByTagName("a"); 
    for (var i=0; i<anchors.length; i++) { 
        var anchor = anchors[i]; 

        if (anchor.getAttribute("href") && 
           anchor.getAttribute("href").indexOf(".cms") > 0) {
           
         anchor.href = anchor.href + "?sd=1";
        }
    } 
}


function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  alert('Query Variable ' + variable + ' not found');
}


// Handle box animation

var boxTimer;
var callCnt = 0;

function doBoxes(ctrl)
{
    if (callCnt > 0 && ctrl)
        return;

    if (callCnt == 0 && !ctrl) {
        var divCtrl = document.getElementById("Boxes");
        if (!divCtrl)
            return;
            
        endBoxes(divCtrl);
        
        return;
    }

    if (callCnt == 0 && ctrl)
    {
        callCnt = 30;
    }
    
        
    var divCtrl = document.getElementById("Boxes");
    if (!divCtrl)
        return;



    var i;
    
    for (i = 0; i < divCtrl.childNodes.length; ++i)
    {
       divCtrl.childNodes[i].childNodes[0].innerHTML = Math.random() < 0.5 ? "0" : "1";
    }
    
    if (callCnt > 0)
        --callCnt;
        
    boxTimer = setTimeout("doBoxes()", 100);
}
    
    
function endBoxes(divCtrl)
{
    if (boxTimer)
        clearTimeout(boxTimer);
    
    var i;
    
    if (divCtrl)
    {
        divCtrl.childNodes[0].childNodes[0].innerHTML = "0";
        divCtrl.childNodes[1].childNodes[0].innerHTML = "1";
        
        for (i = 2; i < divCtrl.childNodes.length; ++i)
        {
           divCtrl.childNodes[i].childNodes[0].innerHTML = "";
        }
    }
    
    callCnt = 0;
    boxTimer = null;
}


function startBoxes()
{
    var divCtrl = document.getElementById("Boxes");
    doBoxes(divCtrl);
}   

function getPageId()
{
    var href = window.location.href;
    if (href.lastIndexOf('.cms') < 0)
        return "default-de";
        
    var page = href.substring(href.lastIndexOf('/')+1, href.lastIndexOf('.'));
    
    return page;
}

function boxAnimation()
{
    var page = getPageId();
    if (page && (page.indexOf("default") >= 0 || page.indexOf("carecom-") >= 0 || page.indexOf("computerscientist-") >= 0))
    {
        boxTimer = setTimeout("startBoxes()", 3000);
    }
}


function onloadHandler()
{
    externalLinks(false);
    boxAnimation();
    

}

// when state is disabled (but javascript not)
function onloadHandlerSD()
{
    externalLinks(true);
    boxAnimation();
}


function rz_base()
{
    try {
      
      var pageId = getPageId();
      var pageName = pageId + ".cms";
      if (pageId.indexOf("default-de") == 0)
        pageName = "";
      
      location.href = './' + pageName + '?sets=1';
      
    }
    catch(e4) {}
    finally {
    }
}


// No frames! 
if (window != window.top) top.location.replace(location.href);



window.onload = onloadHandler;

