﻿/// Hover Images (for navigation issues)
hoverImages = {
    srcDelimiter : "#",
    preloadimages : new Array(),
    preload : function(imgsrc) {
        var img = new Image();
        img.src = imgsrc;
        return this.preloadimages.push(img);
    },
    init : function() {
        regExpTest = new RegExp(this.srcDelimiter);
        regExpFind = new RegExp("(.*)" + this.srcDelimiter + "(.*)");    
        for (i = 0; i < document.images.length; i++) {
            img = document.images[i];
            if(regExpTest.test(img.getAttribute('src'))) {
                 img.setAttribute('src_reg', regExpFind.exec(img.getAttribute('src'))[1]);
                 img.setAttribute('src_ovr', regExpFind.exec(img.getAttribute('src'))[2]);
                 img.onmouseover = function(){ this.setAttribute('src', this.getAttribute('src_ovr')); };    
                 img.onmouseout = function(){ this.setAttribute('src', this.getAttribute('src_reg')); };
                 img.onmouseout();
                 this.preload(img.getAttribute('src_ovr'));
            }
        }
        inputElmnt = document.getElementById("topnavsubmit");
        inputElmnt.setAttribute('src_reg', regExpFind.exec(inputElmnt.getAttribute('src'))[1]);
        inputElmnt.setAttribute('src_ovr', regExpFind.exec(inputElmnt.getAttribute('src'))[2]);
        inputElmnt.onmouseover = function(){ this.setAttribute('src', this.getAttribute('src_ovr')); };    
        inputElmnt.onmouseout = function(){ this.setAttribute('src', this.getAttribute('src_reg')); };
        inputElmnt.onmouseout();
        this.preload(inputElmnt.getAttribute('src_ovr'));
    }
};
// Body Helper
documentViewHelper = {
    init : function() { 
        hoverImages.init();
    }
}
// CSS Helper
cssHelper = {
    setChildNodeClassNames : function(p) {
        if (p.keepLastClass) lastNode = p.rootNode.childNodes[ p.rootNode.childNodes.length - ((typeof p.rootNode.lastChild.className == 'undefined')?2:1) ];
        var childNode = p.rootNode.firstChild;
        var i = 0;
        while (childNode != null) {
            if (typeof childNode.className != 'undefined') {
                
                childNode.className = p.classeNames[i];
                if (++i >= p.classeNames.length) i = 0;
                
            }
            childNode = childNode.nextSibling;
            if (p.keepLastClass && childNode == lastNode) break;
        }
    },
    addChildNodeClassNames : function(p) {
        var childNode = p.rootNode.firstChild;
        var i = 0;
        while (childNode != null) {
            if (typeof childNode.className != 'undefined') {
                $(childNode).addClassName(p.classeNames[i]);
                if (++i >= p.classeNames.length) i = 0;
            }
            childNode = childNode.nextSibling;
        }
    },
    setClassOfChildElement : function(p) {
        //{rootnode:DOMnode,index:0,className:'active'}
        var n = $A(p.rootnode.childNodes);
        var j = p.index;
        for (var i=0; i<n.length; i++) 
            if (((n[i].nodeType!=3)?--j:j)==-1) n[i].className = p.className;
    },
    setHeightOfChildElements : function(p) {
        childElements = p.rootNode.getElementsByTagName(p.childTagName);
        if(childElements.length > 0){
            for(var i=0; i<= childElements.length-1; i++){                
                childElements[i].style.height = (p.rootNode.clientHeight-p.offset) + 'px';                                    
            }
        } else {p.rootNode.style.height = '17px';}
    },
    findLastElement : function(p) {
       elements = p.rootNode.getElementsByClassName(p.cssClass);
       elements[elements.length-1].addClassName(p.additionalClass);
    }
}
// DOM Helper
domHelper = {
    sortSelectOptions : function(p) {
        var a = new Array();
        while (p.select.options[p.start]!= null) { a.push([p.select.options[p.start].text, p.select.options[p.start].value]); p.select.options[p.start] = null; }
        a.sort(function(a, b) { return(a[0]>b[0])?1:-1; });
        $A(a).each(function(n) { p.select.options[p.select.length] = new Option(n[0], n[1], false) } )
    },
    randomSortDivs : function(p) {
        var currDivs = [];
        var formFieldsDiv = $(p.rootID).getElementsByClassName(p.cssClass);
        
        formFieldsDiv.each(function(item){
            currDivs.push(item.innerHTML)
        });
        currDivs.sort(function() {return 0.5 - Math.random();})
        var index = 0;
        formFieldsDiv.each(function(item){
            item.show();
            item.innerHTML = currDivs[index ++];
        });
    }
    
}
// PopUp Helper
popupHelper = {
    openImagePopup : function(p){ //{width:,height:,alt:,url:}
        newWindow = window.open("","","height="+(p.height+20)+",width="+(p.width+20)+",left="+((screen.width/2)-((p.width+20)/2))+",top="+((screen.height/2)-((p.height+20)/2))+",status=0");
        newWindow.document.open();
        newWindow.document.write('<'+'html'+'><'+'head'+'><'+'title'+'>'+((typeof(p.alt)=="undefined")?'':p.alt)+'</'+'title'+'></'+'head'+'><'+'body style="margin:0px;padding:10px;cursor:pointer;height:'+p.height+40+';" onclick="window.close()"><img src="'+p.url+'" alt="'+((typeof(p.alt)=="undefined")?'':p.alt)+'" align="center"></'+'body'+'></'+'html'+'>');
        newWindow.document.close();
        newWindow.focus();
        return void(0);
    },
    open360DegPopup : function(p){ //{features:,width:,height:,name:,url:}
        if(p.width > screen.width || p.height > screen.height) {
            x = y = 0; 
            p.width = screen.width-10; 
            p.height = screen.height-60;
        } else {
            x=(screen.width/2)-(p.width/2)
            y=(screen.height/2)-(p.height/2)
        }
        window.open(p.url, p.name,"width="+ p.width +",height="+ p.height +",toolbar=no,menubar=no,left=" + x + ",top=" + y + ",screenX=" + x + ",screenY=" + y +","+ p.features);
        return void(0);
    }
}


// AJAX Functions for Press Release Teasers 
function changeDateFormat(date) {
    return(date.substr(6, 2)+"."+date.substr(4, 2)+"."+date.substr(0, 4))
}
function getPressReleases(url, showPressQuantity, newsContainer) {
    new Ajax.Request(url, {
        method: 'get',
          onSuccess: function(transport) {
            
            var pressReleases = transport.responseXML.documentElement.getElementsByTagName("pressrelease");
            
            var pressTitles = transport.responseXML.documentElement.getElementsByTagName("title");
            var pressURLs = transport.responseXML.documentElement.getElementsByTagName("details_url");
            for (var i = 0; i < showPressQuantity; i++) {
                var newsItem = '<div class="newsitem">';
                newsItem += '<span>'+changeDateFormat(pressReleases[i].getAttribute("releasedate"))+'&nbsp;|&nbsp;'+pressReleases[i].getAttribute("area")+'</span>';
                newsItem += '<strong>'+pressTitles[i].firstChild.data+'</strong>';
                newsItem += '<a href="'+pressURLs[i].firstChild.data+'" title="More" class="arrow grey">More</a>';
                newsItem += '<div class="hr">&nbsp;</div></div>';
                
                //console.log(pressTitles[i].firstChild.data);
                newsContainer.insert(newsItem);
            }     
        }
    });
}


// Diverse Functions
function getActualYear() {
    var jetzt = new Date();
    document.write(jetzt.getFullYear());
}
function getActualDate() {
    var actualDate = new Date();
    document.write(actualDate.getDay()+"."+actualDate.getMonth()+"."+actualDate.getFullYear());
}
function checkIE() {
  var arVersion = navigator.appVersion.split("MSIE");
  var version = parseFloat(arVersion[1]);
  return ((version >= 5.5) && (version <= 7) );
}  
function checkIE6() {
  var arVersion = navigator.appVersion.split("MSIE");
  var version = parseFloat(arVersion[1]);
  return ((version >= 5.5) && (version < 7) );
}