﻿function init()
{
    valignButtonsInTeaser.set();
    if(document.getElementById('transparentLayer')) { 
        transparentLayer.open();
    }
    if(document.getElementById('popupLayer') || document.getElementById('formWerbenNewsletter24')) {
        popupLayerShadowForIE6.set();
        popupLayer.open();
    }
    if(document.getElementById('ibeHome')) { 
        ibeHomeShadowForIE6.set();    
    }
    //initIBE ();

    
    // Add target to external links
/*
    $$('a').each(function(element){
      if (element.href && element.href.indexOf('85.22.64.171') == -1 && element.href.indexOf('www.germanwings.com') == -1 && element.target == '') element.target = '_blank';
    });
*/
    
}


var windowOpen = {
    open: function (url, name, width, height) {
        f = window.open(url, name, 'width='+width+',height='+height+',scrollbars=yes,status=yes,toolbar=no,location=no,directories=no,resizable=yes,menubar=yes');
        setTimeout('f.focus()', 200);
    }
}




/**********************************************************
Ist ein trasparenter Layer, der sich über die Seite legt.
**********************************************************/
var transparentLayer = {
    
    pageWidth: false,
    pageheight: false,
    
    init: function () {    
        scrollWidth = document.getElementsByTagName('body')[0].offsetWidth;
        scrollHeight = document.getElementsByTagName('body')[0].offsetHeight;
        documentWidth = document.getElementsByTagName('body')[0].scrollLeft;
        documentHeight = document.getElementsByTagName('body')[0].scrollTop;
        if(window.innerWidth) {
            windowWidth =  window.innerWidth;
            windowHeight = window.innerHeight;
        }
        else {
            windowWidth =  document.body.clientWidth;
            windowHeight = document.body.clientHeight;
        }
        if((documentWidth - scrollWidth) > windowWidth) {
            this.pageWidth = documentWidth - scrollWidth;
        }
        else {
            this.pageWidth = windowWidth;
        }
        if((documentHeight - scrollHeight) > windowHeight) {
            this.pageHeight = documentHeight - scrollHeight;
        }
        else {
            this.pageHeight = windowHeight;
        }        
        //this.pageWidth = '100%'; //document.getElementsByTagName('body')[0].offsetWidth - sL;
        //this.pageHeight = document.getElementsByTagName('body')[0].offsetHeight - sT;
    },
    
    open: function () {
        if(document.getElementById('transparentLayer')) {
            this.init();
            //this.debug();
            document.getElementById('transparentLayer').style.width = '100%'; //this.pageWidth + 'px'; 
            document.getElementById('transparentLayer').style.height = this.pageHeight + 'px';
            document.getElementById('transparentLayer').style.zIndex = '19999';
            document.getElementById('transparentLayer').style.visibility = 'visible';
        }
    },
    
    close: function () {
        if(document.getElementById('transparentLayer')) {
            document.getElementById('transparentLayer').style.visibility = 'hidden';
        }
    },
    
    debug: function () {
        alert(this.pageWidth + " x " + this.pageHeight);
    }
};
/**********************************************************
Popuplayer
**********************************************************/
var popupLayer = {
    close: function () {
        if(document.getElementById('popupLayer')) {
            document.getElementById('popupLayer').style.visibility = 'hidden';
        }
        else if(document.getElementById('formWerbenNewsletter24')) {
            document.getElementById('formWerbenNewsletter24').style.visibility = 'hidden';
        }
        transparentLayer.close();
    },
    open: function () {
        if(document.getElementById('popupLayer')) {
            document.getElementById('popupLayer').style.zIndex = '20000';
            document.getElementById('popupLayer').style.visibility = 'visible';
        }
        else if(document.getElementById('formWerbenNewsletter24')) {
            document.getElementById('formWerbenNewsletter24').style.zIndex = '20000';
            document.getElementById('formWerbenNewsletter24').style.visibility = 'visible';
        }
    }    
    
}
/*******************************************************
Popuplayer Spezialanpassung für den IE6
Schatten werden für den IE6 ausgetauscht bzw. Filter gesetzt.
********************************************************/
var popupLayerShadowForIE6 = {
    set: function () {    
        if (document.all && !window.opera) {        
            preffix = '';
            if(document.getElementById('formWerbenNewsletter24')) {
                preffix = 'werben_';    
            }
            var popUpLayer = 
            {    
                'top' : { 'obj' : document.getElementById('PopupLayerTop') , 'src' : 'images/structure/background/bg_' + preffix + 'popupLayer_top.png' },
                'content' : { 'obj' : document.getElementById('PopupLayerVertical') , 'src' : 'images/structure/background/bg_' + preffix + 'popupLayer_vertical.png' },
                'bottom' : { 'obj' : document.getElementById('PopupLayerBottom') , 'src' : 'images/structure/background/bg_' + preffix + 'popupLayer_bottom.png' }
            };
            
            popUpLayer['top']['obj'].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + popUpLayer['top']['src'] + ', sizingMethod="image")';
            popUpLayer['top']['obj'].style.backgroundColor = 'transparent';
            
            popUpLayer['content']['obj'].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + popUpLayer['content']['src'] + ', sizingMethod="scale")';
            popUpLayer['content']['obj'].style.backgroundColor = 'transparent';
            
            popUpLayer['bottom']['obj'].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + popUpLayer['bottom']['src'] + ', sizingMethod="image")';
            popUpLayer['bottom']['obj'].style.backgroundColor = 'transparent';
        }
    }
}

var ibeHomeShadowForIE6 = {
    set: function () {    
        if(!document.getElementById('ibeHome')) {
            return false;
        }        
        if (document.all && !window.opera) {        
            var ibeHome = 
            {    
                'top' : { 'obj' : document.getElementById('shadowTop') , 'src' : '/en/Images/bg_shadow_1_4_top.png' },
                'content' : { 'obj' : document.getElementById('shadowContent') , 'src' : '/en/Images/bg_shadow_1_4_content.png' },
                'bottom' : { 'obj' : document.getElementById('shadowBottom') , 'src' : '/en/Images/bg_shadow_1_4_bottom.gif' }
            };
            ibeHome['top']['obj'].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + ibeHome['top']['src'] + ', sizingMethod="image")';
            ibeHome['top']['obj'].style.backgroundColor = 'transparent';
            
            ibeHome['content']['obj'].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + ibeHome['content']['src'] + ', sizingMethod="scale")';
            ibeHome['content']['obj'].style.backgroundColor = 'transparent';
            
            ibeHome['bottom']['obj'].style.filter = 'progid:DXImageTransform.Microsoft.AlphaImageLoader(src=' + ibeHome['bottom']['src'] + ', sizingMethod="image")';
            ibeHome['bottom']['obj'].style.backgroundColor = 'transparent';
        }
    }
}

/*******************************************************
Setzt Links und Buttons bei allen Teasern in einer Reihe
auf eine Linie.
********************************************************/

/*
Prototype ab Version 1.5
var valignButtonsInTeaser = {
    check: function (groupAlignButton) {
        return false;
    },
    
    set: function () {   
        $$('div.alignButton').each(function(obj) {
            // CSS-Eigenschaft für Link "position" aufheben
            $(obj).getElementsBySelector('.link').each(function(link) {
                $(link).setStyle({position: 'static'});
            });
            var dimensions = $(obj).getDimensions();
            $(obj).childElements().each(function(child) {
                $(child).setStyle({height: (dimensions.height + 15) + 'px'});
                // CSS-Eigenschaft für Link "position" setzen
                c = $(child).down('.link');
                if(c) {
                    c.setStyle({position: 'absolute'});
                }
            });
        });
    }   
}
*/


var valignButtonsInTeaser = {
    check: function (groupAlignButton) {
        var divs = groupAlignButton.getElementsByTagName('div');
        for(var i= 0; i < divs.length; i++) {
            if(divs[i].className.indexOf('link')>-1 ) {
                return true;
            }
        }       
        return false;
    },
    // Workaround
    setCSSPositionLink: function (groupAlignButton, cssPosition) {
        var divs = groupAlignButton.getElementsByTagName('div');
        for(var i= 0; i < divs.length; i++) {
            if(divs[i].className.indexOf('link')>-1 ) {
                divs[i].style.position = cssPosition;
            }
        }       
    },   
    set: function () {   
       
        myDivs = document.getElementsByTagName('div');
        myAlignGroups = new Array();
        for(var i=0; i < myDivs.length; i++) {
            if(myDivs[i].className.indexOf('alignButton')>-1 ) {
                if(this.check(myDivs[i])) {
                    this.setCSSPositionLink(myDivs[i], 'static');
                    x = myDivs[i].offsetHeight;
                    this.setCSSPositionLink(myDivs[i], 'absolute');
                    var myAlignButtons = myDivs[i].getElementsByTagName('DIV');
                    for(j=0; j<myAlignButtons.length; j++) {
                        myAlignButtons[j].parentNode.style.height = x + 15 + 'px';   
                    }
                }
            }
        }
    }
}

/**************************************************
Dynamisch aufklappbare Bereiche
**************************************************/
var motion = false; 
var decrease = .9;

function slideInit (toggle, noBorder, hideLink, imageOpen, imageClose) {
    var nextSibl = toggle.parentNode.nextSibling;
    while (nextSibl.nodeType != 1) {
        nextSibl = nextSibl.nextSibling;
    } 
        
    if(!motion) {
        window['slideObj'] = nextSibl;
        slideObj.toggle = toggle;
        
        if(slideObj.className.indexOf('noCollapse')>-1) { 
            if(!slideObj.style.height) {
                slideObj.minHt = slideObj.offsetHeight - 2; 
                slideObj.style.height = slideObj.minHt + 'px';
            }
        } else {
            slideObj.minHt = 0;
            if (!slideObj.style.height) {        
                slideObj.style.height = '0px';
            }
                        
        }
        
        if(noBorder) slideObj.sideBorder = false;
        else slideObj.sideBorder = true;
        
        if(hideLink) toggle.style.visibility = 'hidden';
        else toggle.style.visibility = '';
        
        slideObj.toggleImage = toggle.getElementsByTagName('IMG')[0];
        slideObj.imageOpen = new Image();
        slideObj.imageOpen.src = imageOpen;
        slideObj.imageClose = new Image();
        slideObj.imageClose.src = imageClose;
        
        if(!slideObj.direc) slideObj.direc = 1;
        slideObj.speed = parseInt(slideObj.getElementsByTagName('DIV')[0].offsetHeight/4);
        slide();
    }
    return false;
}

function slide () {
    window.clearTimeout(motion);
    
    slideObj.speed *= decrease;
    ht = parseInt(slideObj.style.height);
    if (slideObj.direc > 0) {
        if(ht < (slideObj.getElementsByTagName('DIV')[0].offsetHeight)) {
            slideObj.style.height = ht + Math.ceil(slideObj.speed) + 'px';    
            if(slideObj.sideBorder ) slideObj.style.borderStyle = 'solid';
        } else {
            slideObj.style.height = slideObj.getElementsByTagName('DIV')[0].offsetHeight + 'px';
            slideObj.toggle.className = 'open';
            if(slideObj.toggleImage && slideObj.imageClose) {
                slideObj.toggleImage.src = slideObj.imageClose.src;
            }
            slideObj.direc *= -1;
            motion = false; 
            return;
        }
    } else {
        if(ht > slideObj.minHt) {
            var myHt = ht - Math.ceil(slideObj.speed);
            if(myHt < slideObj.minHt) myHt = slideObj.minHt; 
            slideObj.style.height = myHt + 'px';
        } else {
            slideObj.style.height = slideObj.minHt + 'px';
            if(!slideObj.minHt) slideObj.style.borderStyle = 'none';
            slideObj.toggle.className = '';
            if(slideObj.toggleImage && slideObj.imageOpen) {
                slideObj.toggleImage.src = slideObj.imageOpen.src;
            }
            slideObj.direc *= -1;
            motion = false; 
            return;
        }     
    }
    motion = window.setTimeout('slide()', 40);
}


/*Funktion um in der Auswahlliste den ausgewaehlten fett zu machen */
function changeOption(auswahl) {
    for(var i=0;i<auswahl.length;i++) {
        if (auswahl[i].selected)
            auswahl[i].style.fontWeight = "bold";
        else
            auswahl[i].style.fontWeight = "normal";
    }
}
/************ Funktion fuer den Newsletter - vorbelegung des E-Mail Feldes ********/
function newsletter_email(auswahl,text) {
    if(auswahl.value == "") {
        auswahl.style.color ="#c1c1c1";
        auswahl.value = text;
    }
}    
function newsletter_email_clear(auswahl,text) {
    if(auswahl.value == text) {
        auswahl.style.color = "#000000";
        auswahl.value = "";
    }
}
/********* Funktion fuer das Pressekontakt Nachrichtenfeld *******/
function zaehlen() {
 var max = 501;
 anz = document.pressekontakt_form.Pressekontakt_Anliegen.value.length+1;
 document.pressekontakt_form.anzeige.value = max - anz;
 uebrig = max - anz;
 if(anz >= max){
  alert("Maximum erreicht !!!");
  }
  return uebrig;
 }
 
var px = 10;//mehr=schneller
var timer;
var merker;
function scrollDiv(val){
    clearTimeout(timer);
    d=document.getElementById('ScrollArea')
    y=d.scrollTop;
    if(val==1)y-=px;
    if(val==2)y+=px;
    if(y<=d.scrollHeight-d.offsetHeight+px&&y>=0-px){
        d.scrollTop=y;
        timer=setTimeout('scrollDiv('+val+')',50);
    }
    if(y<0||y>d.scrollHeight-d.offsetHeight){
        clearTimeout(timer);
    }
} 
 
 
/* FAQ Seite - Maximale Zeichen fuer Textfeld */
function zaehlenFAQ() {
  var max = 501;
  anz = document.faq.faq_ihre_anfrage.value.length+1;
  document.faq.anzeige.value = max - anz;
  uebrig = max - anz;
  if(anz >= max) {
    alert("Maximum erreicht !!!");
  }
  return uebrig;
}

 
/* Sprachumschaltung im Header */
function switchLanguage(select)
{
  var url = select.options[select.options.selectedIndex].value;
  if (url != "") window.location.href = url;
}


/*** MaxLengthTextArea *** Germanwings Edition ***/

function gw_maxLengthTextArea( textarea, keyEvent, maxLength )
{
  // still allow some special keys
  if ( ( keyEvent.keyCode >= 37 && keyEvent.keyCode <= 40 ) || // arrow keys
         keyEvent.keyCode == 8 || // backspace
         keyEvent.keyCode == 13 || // return key
         keyEvent.keyCode == 35 || // end key
         keyEvent.keyCode == 36 || // pos1 key
         keyEvent.keyCode == 46 ) // del key
  {
    return true;
  }

  if ( textarea.value.length + 1 > maxLength )
  {
    return false;
  }
  else
  {
    return true;
  }
}

function gw_updateCounter( textarea, counter, maxLength )
{
  counter.update( maxLength - textarea.value.length );      
}


function popupSized(theURL, wname, width, height) {
  positionx = (screen.width/2)-(width/2)
  positiony = (screen.height/2)-(height/2)
  window.open(theURL, wname,"width="+ width +",height="+ height +",resizable=yes,status=no,scrollbars=yes,toolbar=no,menubar=no,left=" + positionx + ",top=" + positiony + ",screenX=" + positionx + ",screenY=" + positiony);
}


/* Slide fuer Unternehmensseite */
function slideInitUnternehmen(toggle, slider) {
    merker = toggle;
    if(!motion) {
        window['slideObj'] = document.getElementById(slider);
        slideObj.toggle = toggle;
        if(!slideObj.direc) slideObj.direc = 1;
        slideObj.speed = parseInt(slideObj.getElementsByTagName('DIV')[0].offsetHeight/4);
        slideUnternehmen();
    }
    return false;
}
function slideUnternehmen() {
    window.clearTimeout(motion);
    slideObj.speed *= decrease;
    ht = parseInt(slideObj.style.height);
    if (slideObj.direc > 0) {
        if(ht < (slideObj.getElementsByTagName('DIV')[0].offsetHeight)) {
            slideObj.style.height = ht + Math.ceil(slideObj.speed) + 'px';
        } else {
            slideObj.style.height = slideObj.getElementsByTagName('DIV')[0].offsetHeight + 'px';
            slideObj.toggle.className = 'open';
            merker.style.visibility = "hidden";
            slideObj.direc *= -1;
            motion = false; 
            return;
        }
    } else {
        if(ht > 0) {
            var myHt = ht - Math.ceil(slideObj.speed);
            if (myHt < 0) myHt = 0; 
            slideObj.style.height = myHt + 'px';
        } else {
            slideObj.style.height = "0px";
            slideObj.toggle.className = '';
            merker.style.visibility = "visible";            
            slideObj.direc *= -1;
            motion = false; 
            return;
        }     
    }
    motion = window.setTimeout('slideUnternehmen()', 40);
}
 


/** 
* functions to display images in page container on the fly
* added by Jörg Gutsche 2008-02-05 
* used by image_text_button_mouseover
*
*/
function mouseX(evt) {
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
       return evt.clientX + (document.documentElement.scrollLeft ?
       document.documentElement.scrollLeft :
       document.body.scrollLeft);
    else return null;
}


function mouseY(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
       return evt.clientY + (document.documentElement.scrollTop ?
       document.documentElement.scrollTop :
       document.body.scrollTop);
    else return null;
}

/**
* @param e event
* @param id String image src
*/
function displayImage(e,id){
            var container = document.getElementById("Container");

             try {
                var list = container.getElementsByTagName("IMG")[0];
                container.removeChild(list);
            } catch (exception) {
            }

            var newChild = document.createElement("IMG");
            newChild.src = id;
    
            container.appendChild(newChild);
            container.style.top = mouseY(e) + "px";    
            container.style.left = mouseX(e) + "px"; 
            container.style.display = "block";
        }

// removes image nodes from Container 
function emptyContainer(){
            var theContainer = document.getElementById("Container");
            var list = theContainer.getElementsByTagName("IMG")[0];
            theContainer.removeChild(list);
            theContainer.style.display = "none";
            
 }
 
//--------------------------------------------------------------------------------
// Öffnet Fenster (popup) und plaziert dieses in der Bildschirmmitte
//--------------------------------------------------------------------------------
function openContentPopup(url, winName, w, h){
var parameter = 'width='+w+',height='+h+',left='+eval((screen.width-w)/2)+',top=50,scrollbars=yes,resizable=yes,location=no,menubar=no,toolbar=no';
    a = window.open(url,winName,parameter);
    a.focus();
    return false;
}


function openRatesTable(){

    var documentUrl = location.href;
    urlArray = new Array();
    urlArray = documentUrl.split("/");
    var langName;
    if (urlArray[3].length != 2)
    { langName = "en"; }
    else 
    { langName = urlArray[3]; }
    var inUrl = "/" + langName + "/faq_rates.htm";

    var winName = "ratestable";
    var width = 700;
    var height = 800;

    openContentPopup(inUrl,winName,width, height);

}





// ===================================================================
// Author: Matt Kruse <matt@mattkruse.com>
// WWW: http://www.mattkruse.com/
//
// NOTICE: You may use this code for any purpose, commercial or
// private, without any further permission from the author. You may
// remove this notice from your final code if you wish, however it is
// appreciated by the author if at least my web site address is kept.
//
// You may *NOT* re-distribute this code in any way except through its
// use. That means, you can include it in your product, or your web
// site, or any other form where the code is actually being used. You
// may not put the plain javascript up on your site for download or
// include it in your javascript libraries for download. 
// If you wish to share this code with others, please just point them
// to the URL instead.
// Please DO NOT link directly to my .js files from your site. Copy
// the files to your server and use them there. Thank you.
// ===================================================================
var MONTH_NAMES=new Array('January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');var DAY_NAMES=new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat');
function LZ(x){return(x<0||x>9?"":"0")+x}
function isDate(val,format){var date=getDateFromFormat(val,format);if(date==0){return false;}return true;}
function compareDates(date1,dateformat1,date2,dateformat2){var d1=getDateFromFormat(date1,dateformat1);var d2=getDateFromFormat(date2,dateformat2);if(d1==0 || d2==0){return -1;}else if(d1 > d2){return 1;}return 0;}
function formatDate(date,format){format=format+"";var result="";var i_format=0;var c="";var token="";var y=date.getYear()+"";var M=date.getMonth()+1;var d=date.getDate();var E=date.getDay();var H=date.getHours();var m=date.getMinutes();var s=date.getSeconds();var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;var value=new Object();if(y.length < 4){y=""+(y-0+1900);}value["y"]=""+y;value["yyyy"]=y;value["yy"]=y.substring(2,4);value["M"]=M;value["MM"]=LZ(M);value["MMM"]=MONTH_NAMES[M-1];value["NNN"]=MONTH_NAMES[M+11];value["d"]=d;value["dd"]=LZ(d);value["E"]=DAY_NAMES[E+7];value["EE"]=DAY_NAMES[E];value["H"]=H;value["HH"]=LZ(H);if(H==0){value["h"]=12;}else if(H>12){value["h"]=H-12;}else{value["h"]=H;}value["hh"]=LZ(value["h"]);if(H>11){value["K"]=H-12;}else{value["K"]=H;}value["k"]=H+1;value["KK"]=LZ(value["K"]);value["kk"]=LZ(value["k"]);if(H > 11){value["a"]="PM";}else{value["a"]="AM";}value["m"]=m;value["mm"]=LZ(m);value["s"]=s;value["ss"]=LZ(s);while(i_format < format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c) &&(i_format < format.length)){token += format.charAt(i_format++);}if(value[token] != null){result=result + value[token];}else{result=result + token;}}return result;}
function _isInteger(val){var digits="1234567890";for(var i=0;i < val.length;i++){if(digits.indexOf(val.charAt(i))==-1){return false;}}return true;}
function _getInt(str,i,minlength,maxlength){for(var x=maxlength;x>=minlength;x--){var token=str.substring(i,i+x);if(token.length < minlength){return null;}if(_isInteger(token)){return token;}}return null;}
function getDateFromFormat(val,format){val=val+"";format=format+"";var i_val=0;var i_format=0;var c="";var token="";var token2="";var x,y;var now=new Date();var year=now.getYear();var month=now.getMonth()+1;var date=1;var hh=now.getHours();var mm=now.getMinutes();var ss=now.getSeconds();var ampm="";while(i_format < format.length){c=format.charAt(i_format);token="";while((format.charAt(i_format)==c) &&(i_format < format.length)){token += format.charAt(i_format++);}if(token=="yyyy" || token=="yy" || token=="y"){if(token=="yyyy"){x=4;y=4;}if(token=="yy"){x=2;y=2;}if(token=="y"){x=2;y=4;}year=_getInt(val,i_val,x,y);if(year==null){return 0;}i_val += year.length;if(year.length==2){if(year > 70){year=1900+(year-0);}else{year=2000+(year-0);}}}else if(token=="MMM"||token=="NNN"){month=0;for(var i=0;i<MONTH_NAMES.length;i++){var month_name=MONTH_NAMES[i];if(val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()){if(token=="MMM"||(token=="NNN"&&i>11)){month=i+1;if(month>12){month -= 12;}i_val += month_name.length;break;}}}if((month < 1)||(month>12)){return 0;}}else if(token=="EE"||token=="E"){for(var i=0;i<DAY_NAMES.length;i++){var day_name=DAY_NAMES[i];if(val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()){i_val += day_name.length;break;}}}else if(token=="MM"||token=="M"){month=_getInt(val,i_val,token.length,2);if(month==null||(month<1)||(month>12)){return 0;}i_val+=month.length;}else if(token=="dd"||token=="d"){date=_getInt(val,i_val,token.length,2);if(date==null||(date<1)||(date>31)){return 0;}i_val+=date.length;}else if(token=="hh"||token=="h"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>12)){return 0;}i_val+=hh.length;}else if(token=="HH"||token=="H"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>23)){return 0;}i_val+=hh.length;}else if(token=="KK"||token=="K"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<0)||(hh>11)){return 0;}i_val+=hh.length;}else if(token=="kk"||token=="k"){hh=_getInt(val,i_val,token.length,2);if(hh==null||(hh<1)||(hh>24)){return 0;}i_val+=hh.length;hh--;}else if(token=="mm"||token=="m"){mm=_getInt(val,i_val,token.length,2);if(mm==null||(mm<0)||(mm>59)){return 0;}i_val+=mm.length;}else if(token=="ss"||token=="s"){ss=_getInt(val,i_val,token.length,2);if(ss==null||(ss<0)||(ss>59)){return 0;}i_val+=ss.length;}else if(token=="a"){if(val.substring(i_val,i_val+2).toLowerCase()=="am"){ampm="AM";}else if(val.substring(i_val,i_val+2).toLowerCase()=="pm"){ampm="PM";}else{return 0;}i_val+=2;}else{if(val.substring(i_val,i_val+token.length)!=token){return 0;}else{i_val+=token.length;}}}if(i_val != val.length){return 0;}if(month==2){if( ((year%4==0)&&(year%100 != 0) ) ||(year%400==0) ){if(date > 29){return 0;}}else{if(date > 28){return 0;}}}if((month==4)||(month==6)||(month==9)||(month==11)){if(date > 30){return 0;}}if(hh<12 && ampm=="PM"){hh=hh-0+12;}else if(hh>11 && ampm=="AM"){hh-=12;}var newdate=new Date(year,month-1,date,hh,mm,ss);return newdate.getTime();}
function parseDate(val){var preferEuro=(arguments.length==2)?arguments[1]:false;generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');var checkList=new Array('generalFormats',preferEuro?'dateFirst':'monthFirst',preferEuro?'monthFirst':'dateFirst');var d=null;for(var i=0;i<checkList.length;i++){var l=window[checkList[i]];for(var j=0;j<l.length;j++){d=getDateFromFormat(val,l[j]);if(d!=0){return new Date(d);}}}return null;}
 
  /**
   * Funktionen fuer Destination Table Umbau 14092009
   *
   * @author Sebastian Golasch
   * @function initDestinations Facade function um die kompatibiklitaet mit der alten API aufrecht zu erhalten
   */
    
function initDestinations() {
  var classes = ['grey','white','last'];
  toggleDestinationClass('destinationsThree',3,classes);
  toggleDestinationClass('destinationsFour',4,classes);
}
  /**
   * Funktionen fuer Destination Table Umbau 16092009
   *
   * @author Sebastian Golasch
   * @function toggleDestinationClass Veraendert das class attribut der li elemente, welche
   * innerhlab der departure div container liegen ignoriert leere li elemente und mit der klassen-
   * eigenschaft "destHeadline' getaggte elemente
   */
function toggleDestinationClass (classname, modulo, classes){
    document.getElementsByClassName(classname).each(function(item){
        var elements = item.getElementsByTagName('li'), lmlngth = elements.length, color = classes[0], kids = new Array(), i, j;
        for(i=0;i<lmlngth;++i){
            Element.cleanWhitespace(elements[i]);
            if(!elements[i].children){
                kids[i] = elements[i].childNodes[0];            
            }else{
                kids[i] = elements[i].children[0];
            }
            if(kids[i] && !Element.hasClassName(kids[i], 'destHeadline') ) {
                Element.addClassName(elements[i],color);
            }
            switch (true){
                case (i+1)%modulo == 0:
                    if(kids[i] && !Element.hasClassName(kids[i], 'destHeadline') ) {
                        color = color == classes[0] ? classes[1] : classes[0];
                    }                    
                    if(!kids[i]) {
                        var is_not_undefined = false;
                        for(j=((i+1)-modulo);j<=i;j++){
                            if(kids[j] && !Element.hasClassName(kids[j], 'destHeadline')) {
                                is_not_undefined = true;
                                break;
                            }                      
                        }
                    if(is_not_undefined === true){
                        color = color == classes[0] ? classes[1] : classes[0];                    
                    }                        }
                case (i+1)%modulo == 0 || lmlngth == (i+1):
                    Element.addClassName(elements[i],classes[2]);
            }
        }
    });
}

function correctStructBackground(){
        var j, k, intgroups, intcheck, structContentLength = 0, teaserbg = {3: "/de/Images/Buchung/bg_struct_teasergroup_3_3.gif", 2: "/de/Images/Buchung/bg_struct_teasergroup_3_3_2teaser.gif", 1: "/de/Images/Buchung/bg_struct_teasergroup_3_3_1teaser.gif"};
        
        intcheck = getBgTeaserByClassName(document,'strucTeasergroup33');
        for(j = 0; j < intcheck.length; ++j){
            intgroups = getBgTeaserByClassName(intcheck[j],'group alignButton');
            for(k = 0; k < intgroups.length;++k){
                structContentLength = getBgTeaserByClassName(intgroups[k],'contentTeaserImage').length;
                switch(structContentLength %3){
                    case 0:
                        intgroups[k].style.backgroundImage = "url(" + teaserbg[3] + ")";
                        break;
                  default:
                        intgroups[k].style.backgroundImage = "url(" + teaserbg[structContentLength % 3] + ")";
                        break;
                }
            }            
        }

}

function getBgTeaserByClassName(elm, className) {
    var muster = new RegExp("(^| )" + className + "($| )");
    var alles = elm.getElementsByTagName("*");
    var gefunden = new Array();
    var i;
    for (i=0; i < alles.length; i++) {
        if (alles[i] && alles[i].className && alles[i].className != "") {
            if (alles[i].className.match(muster))
                gefunden[gefunden.length] = alles[i];
        }
    }
    return gefunden;
}


// JS fuer Searchfeld
function checkFormInput(obj,text) {
var temp = document.search.SearchQueryText.value;
//alert(temp);
if(temp == '')
   document.search.SearchQueryText.value = text;
else if(temp == text)
    document.search.SearchQueryText.value = ''; 
}


/********* Funktion fuer 2- oder 4- spaltige Teaserbox  struct_4_4_shadow_variable*******/
function alignBoxHights() {
    var myDivs = document.getElementsByTagName('DIV');
    var myAlignRows = new Array();
    for( j=0; j<myDivs.length; j++ ) {
        if( myDivs[j].className.indexOf('alignHeight') > 0 ) {
            myAlignRows.push( myDivs[j] );
        }
    }    
    for( j=0; j<myAlignRows.length; j++ ) {     
        var maxBoxHeight = 0;
        var myRowDivs = myAlignRows[j].getElementsByTagName('DIV');
        var myAlignBoxes = new Array();
        for( i=0; i<myRowDivs.length; i++ ) {
            if( myRowDivs[i].className.indexOf('alignBox') > 0 ) {
                myAlignBoxes.push( myRowDivs[i] );
            }
        }        
        for( i=0; i<myAlignBoxes.length; i++ ) {
            var myBox =  myAlignBoxes[i];
            //myBox.style.height = '';                                                                
            if( myBox.offsetHeight > maxBoxHeight ) {
                maxBoxHeight = myBox.offsetHeight;
            } 
        }
        for( i=0; i<myAlignBoxes.length; i++ ) {
            var myBox =  myAlignBoxes[i];    
            myBox.style.height = maxBoxHeight + 'px';        
        }                                                                             
    }
}
 
window.onload = function() {
    alignBoxHights();
    initializeTeaserTracking();
}
 
/**
 * Locates all structs that are whitelisted
 *
 * @class StructFinder
 * @author Sebastian Golasch <sebastian.golasch@denkwerk.com>
 * @package OmnitureTracking
 * @version 0.2.0
 * @since Class available since version 0.2.0
 */
var StructFinder = function(){
    /**
     * Whitelist of struct classes
     *
     * @param array
     */
    this.structClasses = [];
    /**
     * Found struct elements
     *
     * @param array
     */
    this.structs = [];
    /**
     * Check for StructID flag
     *
     * @param boolean
     */
     this.checkStructID = false;
    /**
     * Adds a struct class to the list
     * of structs, that should be introspected
     *
     * @param string class_name CSS class name of the structs, that should be introspected
     * @return StructFinder this Instance of StructFinder
     * @access public
     */
     this.addStructClass = function(class_name){
        this.structClasses[this.structClasses.length] = class_name;
        return this;
     };
    /**
     * Enable/disable checking for an existing StructID
     *
     * @param boolean check Enable(true)/disable(false) checking for an existing struct id
     * @return StructFinder this Instance of StructFinder
     * @access public
     */
    this.checkForStructID = function(check){
        if(check === true || check === false){
            this.checkStructID = check;
        }
        return this;
    };
    /**
     * Find all structs that are whiltelisted
     * and in this page
     *
     * @param void
     * @return array structs All found struct elements
     * @access public
     */
    this.getStructs = function(){
        var nstrct = strct = [], i, j;
        // Check if structs arent defined by now
        if(this.structs.length == 0){
            // Iterate over all assigned struct classes
            for(struct_class in this.structClasses){
                // Build up struct array
                strct = strct.concat(this._getElementsByClassName(document,this.structClasses[struct_class]));
            }
            // Check if we need to check for an StructID
            if(this.checkStructID === true){
                // Iterate over all found struct classes
                for(i=0;i<strct.length;++i){
                    // Sort out all elements with an empty StructID
                    if(strct[i].getAttribute('title') != null && strct[i].getAttribute('title') != ''){
                        nstrct.push(strct[i]);
                    }
                }
                // Overwrite strct array with the sliced one
                strct = nstrct;
            }
            // Assign structs
            this.structs = strct;
        }
        return this.structs;
    };
    /**
     * Helper function for finding elements
     * with specified classes
     *
     * @param dom.elmement scope Scope to look for
     * @param string class_name Class name to look for
     * @return array ret_obj Found elements
     * @access private
     */
    this._getElementsByClassName = function(scope, class_name){
        var all_obj,ret_obj=[],j=0;
        all_obj=scope.getElementsByTagName("*");
        for(i=0;i<all_obj.length;i++){
            if(all_obj[i].className==class_name){
                ret_obj[j]=all_obj[i];
                j++
            }
        }
        return ret_obj;
    };
}
/**
 * Locates all structs that are whitelisted
 *
 * @class StructFinder
 * @author Sebastian Golasch <sebastian.golasch@denkwerk.com>
 * @package OmnitureTracking
 * @version 0.2.0
 * @since Class available since version 0.2.0
 */
var StructFinder = function(){
    /**
     * Whitelist of struct classes
     *
     * @param array
     */
    this.structClasses = [];
    /**
     * Found struct elements
     *
     * @param array
     */
    this.structs = [];
    /**
     * Check for StructID flag
     *
     * @param boolean
     */
     this.checkStructID = false;
    /**
     * Adds a struct class to the list
     * of structs, that should be introspected
     *
     * @param string class_name CSS class name of the structs, that should be introspected
     * @return StructFinder this Instance of StructFinder
     * @access public
     */
     this.addStructClass = function(class_name){
        this.structClasses[this.structClasses.length] = class_name;
        return this;
     };
    /**
     * Enable/disable checking for an existing StructID
     *
     * @param boolean check Enable(true)/disable(false) checking for an existing struct id
     * @return StructFinder this Instance of StructFinder
     * @access public
     */
    this.checkForStructID = function(check){
        if(check === true || check === false){
            this.checkStructID = check;
        }
        return this;
    };
    /**
     * Find all structs that are whiltelisted
     * and in this page
     *
     * @param void
     * @return array structs All found struct elements
     * @access public
     */
    this.getStructs = function(){
        var nstrct = strct = [], i, j;
        // Check if structs arent defined by now
        if(this.structs.length == 0){
            // Iterate over all assigned struct classes
            for(struct_class in this.structClasses){
                // Build up struct array
                strct = strct.concat(this._getElementsByClassName(document,this.structClasses[struct_class]));
            }
            // Check if we need to check for an StructID
            if(this.checkStructID === true){
                // Iterate over all found struct classes
                for(i=0;i<strct.length;++i){
                    // Sort out all elements with an empty StructID
                    if(strct[i].getAttribute('title') != null && strct[i].getAttribute('title') != ''){
                        nstrct.push(strct[i]);
                    }
                }
                // Overwrite strct array with the sliced one
                strct = nstrct;
            }
            // Assign structs
            this.structs = strct;
        }
        return this.structs;
    };
    /**
     * Helper function for finding elements
     * with specified classes
     *
     * @param dom.elmement scope Scope to look for
     * @param string class_name Class name to look for
     * @return array ret_obj Found elements
     * @access private
     */
    this._getElementsByClassName = function(scope, class_name){
        var all_obj,ret_obj=[],j=0;
        all_obj=scope.getElementsByTagName("*");
        for(i=0;i<all_obj.length;i++){
            if(all_obj[i].className==class_name){
                ret_obj[j]=all_obj[i];
                j++
            }
        }
        return ret_obj;
    };
}
/**
 * Struct entity
 *
 * @class Struct
 * @author Sebastian Golasch <sebastian.golasch@denkwerk.com>
 * @package OmnitureTracking
 * @version 0.2.0
 * @since Class available since version 0.2.0
 */
var Struct = function(el, decorator){
    /**
     * Pure struct dom.element node
     *
     * @param dom.element
     */
    this.el = null;
    /**
     * Found teaser elements,
     * wrapped by this struct
     *
     * @param array
     */
    this.teaserElements = [];
    /**
     * Name of the struct (e.g. StructID)
     *
     * @param string
     */
    this.name = null;
    /**
     * TeaserFinder / teaser decorator instance
     *
     * @param TeaserFinder
     */
    this.teaserDecorator = null;
    /**
     * Class contructor
     * Injects element and decorator
     *
     * @param dom.element el Pure struct element
     * @param TeaserFinder decorator TeaserFinder instance
     * @return Struct this struct instance
     * @acces public
     * @constructor
     */
    this.__construct = function(el, decorator){
        this.setStruct(el);
        this.setTeaserDecorator(decorator);
        return this;
    }
    /**
     * Returns the name of the struct,
     * stored in the 'title' attribut of the
     * struct div container
     *
     * @param void
     * @return string|boolean name Name of the struct (e.g. StructID)
     * @access public
     */
    this.getName = function(){
        var name = this.el.getAttribute('title');
        if(this.name == null){
            this.name = name == null || name == '' ? false: name;
        }
        return this.name;
    };
    /**
     * Retrieves Teaser object instances,
     * for each teaser wrapped by the struct
     *
     * @param void
     * @return array teaser_elements Teaser element collection
     * @access public
     */
    this.getTeaserElements = function(){
        var decorator = this.getTeaserDecorator(), elements = [], i=0;
        // Iterate over teaser finder decorators
        for(finder in decorator.finders){
            // Check if struct classname is equal to the teaser decorator name and 'ignore property' of decorator is set to false
            if(decorator.finders[finder].isIgnored() === false){
                // Run teaser finder decorator find method to grab all available teaser elements
                elements = decorator.finders[finder].setElement(this).find();
                // Check if decorator finder came up with valid elements
                if(typeof elements != 'undefined' && elements.length > 0){
                    return elements;
                }
            }
        }
        return elements;
    };
    /**
     * Set a struct dom.element node
     *
     * @param dom.element el Struct element
     * @return Struct this
     * @access public
     */
    this.setStruct = function(el){
        this.el = el;
        return this;
    };
    /**
     * Returns the 'pure' struct element
     *
     * @param void
     * @return dom.element el Pure struct dom element
     * @access public
     */
    this.getStruct = function(){
        return this.el;
    };
    /**
     * Set teaser decorator object
     *
     * @param TeaserFinder teaser_decorator Teaser decorator collection
     * @return Struct this Struct instance
     * @access public
     */
    this.setTeaserDecorator = function(teaser_decorator){
        this.teaserDecorator = teaser_decorator;
        return this;
    };
    /**
     * Retrieve teaser decorator collection object
     *
     * @param void
     * @return TeaserFinder teaser_decorator Teaser decorator collection
     * @access public
     */
    this.getTeaserDecorator = function(){
        return this.teaserDecorator;
    };
    /**
     * Retrieves the class name of the struct
     *
     * @param void
     * @return string class_name Class name of the struct
     * @access public
     */
    this.getClassName = function(){
        return this.getStruct().className;
    }
    // Construct
    this.__construct(el, decorator);
}
/**
 * Teaser finder | Decorator collection object
 *
 * @class TeaserFinder
 * @author Sebastian Golasch <sebastian.golasch@denkwerk.com>
 * @package OmnitureTracking
 * @version 0.2.0
 * @since Class available since version 0.2.0
 */
var TeaserFinder = function() {
    /**
     * Finder decorator objects
     *
     * @param object
     */
    this.finders = {};
    /**
     * Attach a decorator to the collection
     *
     * @param string name Name of the finder
     * @param AbstractTeaserDecoratorEntity decorator TeaserDecorator instance
     * @return TeaserFinder this Current TeaserFinder instance
     * @access public
     */
    this.attach = function(name, decorator){
        // Check if finder fullfills the 'interface' needs
        if(typeof decorator.find != 'function'){
            throw 'Type of method "find" must be function!';
            return this;
        }
        if(typeof decorator.setElement != 'function'){
            throw 'Type of method "setElement" must be function!';
            return this;
        }
        if(typeof decorator.getElement != 'function'){
            throw 'Type of method "getElement" must be function!';
            return this;
        }
        if(typeof decorator.isIgnored != 'function'){
            throw 'Type of method "isIgnored" must be function!';
            return this;
        }
        if(typeof decorator.getName != 'function'){
            throw 'Type of method "getName" must be function!';
            return this;
        }
        // Attach finder/decorator
        this.finders[name] = decorator;
        return this;
    };
    /**
     * Detaches a decorator object
     *
     * @param string name Name of the finder
     * @return TeaserFinder this Current TeaserFinder instance
     * @access public
     */
    this.detach = function(name){
        var nfinders = [], ofinders = this.finders;
        // Iterate over attached finders
        for(index in ofinders){
            // Check for finders, who wont be detached
            if(index != name){
                // Add non detached finders
                nfinders[index] = ofinders[index];
            }
        }
        // Reassign finders without the detached one
        this.finders = nfinders;
        return this;
    }
}
/**
 * Represents a Teaser entity,
 * attaches onclick events to the teaser links
 *
 * @class Teaser
 * @author Sebastian Golasch <sebastian.golasch@denkwerk.com>
 * @package OmnitureTracking
 * @version 0.2.0
 * @since Class available since version 0.2.0
 */
var Teaser = function(el){
    /**
     * Pure teaser dom.element node
     *
     * @param null|dom.element
     */
    this.el = null;
    /**
     * Build tracking link
     *
     * @param null|string
     */
    this.trackingLink = null;
    /**
     * Name of the parent struct
     *
     * @param null|string
     */
    this.structName = null;
    /**
     * Position of the teaser
     *
     * @param null|integer
     */
    this.position = null;
    /**
     * Teaser headline
     *
     * @param null|string
     */
    this.headline = null;
    /**
     * Constructor method
     * Injects the teaser element
     *
     * @param dom.element el Pure teaser element node
     * @return Teaser this Current Teaser instance
     * @access public
     * @constructor
     */
    this.__construct = function(el){
        this.el = el;
        return this;
    }
    /**
     * Retrieves the teaser headline
     *
     * @param void
     * @return string headline Teaser headline
     * @access public
     */
    this.getHeadline = function(){
        return this.headline == '' || this.headline == '&nbsp;' ? 'undefined' : this.headline;
    };
    /**
     * Sets the teaser headline
     *
     * @param string hdl Teaser headline
     * @return Teaser this Current Teaser instance
     * @access public
     */
    this.setHeadline = function(hdl){
        this.headline = hdl;
        return this;
    };
    /**
     * Retrieves the teaser position
     *
     * @param void
     * @return integer position Teaser position
     * @access public
     */
    this.getPosition = function(){
        return this.position;
    };
    /**
     * Sets the teaser position
     *
     * @param integer pos Teaser position
     * @return Teaser this Current Teaser instance
     * @access public
     */
    this.setPosition = function(pos){
        this.position = pos;
        return this;
    };
    /**
     * Retrives parents struct name
     *
     * @param void
     * @return string struct_name Parents struct name
     * @access public
     */
    this.getStructName = function(){
        return this.structName;
    };
    /**
     * Sets the parent struct name
     *
     * @param string struct_name Parent struct name
     * @return Teaser this Current Teaser instance
     * @acccess public
     */
    this.setStructName = function(struct_name){
        this.structName = struct_name;
        return this;
    };
    /**
     * Retrieves the tracking link
     *
     * @param void
     * @return string tracking_link Teaser tracking link
     * @access public
     */
    this.getTrackingLink = function(){
        if(this.trackingLink == null){
            this.trackingLink = this.getStructName() + '|' + this.getPosition() + '|' + this.getHeadline();
        }
        return this.trackingLink;
    };
    /**
     * Returns the pure teaser dom.element node
     *
     * @param void
     * @return dom.element el Pure teaser dom node
     * @access public
     */
    this.getElement = function(){
        return this.el;
    };
    /**
     * Returns all links inside the
     *
     */
    this.getLinks = function(){
        return this.getElement().getElementsByTagName('a');
    };
    /**
     * Attaches the tracking event to the given link
     *
     * @param dom.element link Link to be decorated
     * @return Teaser this Current Teaser instance
     * @access public
     */
    this.attachTrackingEvent = function(link){
        link_consumer.addLink(link.href, this.getTrackingLink().replace('"',"'"));
        // Attach 'onclick' event
        Event.observe(link,'click',function(e){
            var element, tracking_link = null;
            if(Event.element(e).tagName.toLowerCase() == 'a'){
                element = Event.element(e);
            }else{
                element = Event.element(e).parentNode;
            }
            tracking_link = link_consumer.getLink(element.href);
            //console.log(tracking_link);
            var s = s_gi('germanwingscomprod');
            s.linkTrackVars = 'eVar9';
            s.linkTrackEvents = 'None';
            s.eVar9 = tracking_link;
            s.tl(this,'e','Link Name');
            //e.preventDefault();
        });
        return this;
    };
    // Construct
    this.__construct(el);
};
/**
 * Abstract base class for parsing teaser in structs
 *
 * @class AbstractTeaserDecoratorEntity
 * @author Sebastian Golasch <sebastian.golasch@denkwerk.com>
 * @package OmnitureTracking
 * @version 0.2.0
 * @since Class available since version 0.2.0
 */
var AbstractTeaserDecoratorEntity = function(){
    /**
     * Name of the parent struct class
     *
     * @param string|null
     */
    this.name = null;
    /**
     * Ignore this struct for parsing
     *
     * @param boolean
     */
    this.ignore = false;
    /**
     * Struct to be introspected
     *
     * @param Struct
     */
    this.el = null;
    /**
     * Basic abstract finder method
     *
     * @param void
     * @return array found Found teaser elements
     * @access public
     */
    this.find = function(){
        return [];
    };
    /**
     * Sets the element to be instrospected
     *
     * @param Struct el Struct to be introspected
     * @return AbstractTeaserDecoratorEntity this Current TeaserDecorator entity
     * @access public
     */
    this.setElement = function(el){
        this.el = el;
        return this;
    };
    /**
     * Retrieves the element to be instrospected
     *
     * @param void
     * @return Struct el Struct to be introspected
     * @access public
     */
    this.getElement = function(){
        return this.el;
    };
    /**
     * Returns the name of the parent struct
     *
     * @param void
     * @return string|null name Name of the parent struct
     * @access public
     */
    this.getName = function(){
        return this.name;
    };
    /**
     * Returns if parent struct should be ignored for parsing
     *
     * @param void
     * @return boolean ignore Ignore parent struct for parsing
     * @access public
     */
    this.isIgnored = function(){
        return this.ignore;
    };
}
/**
 *
 */
var LinkConsumer = function () {
    this.links = {};
    this.addLink = function(href,rel){
        this.links[href] = rel;
        return this;
    }
    this.getLink = function(href){
        return this.links[href];
    }
}
/**
 * Singleton data holder for AirportData
 *
 * @package Tracking
 * @author Sebastian Golasch <s.golasch@denkwerk.com>
 * @since Class available since version 0.2.0
 * @version 0.1.0
 */
var AirportContainer = (function() {
    /**
     * Instance of airport container
     *
     * @param null|AirportContainer
     * @access private
     */
    var instance = null;
    /**
     * Instance of airport container
     *
     * @param null|AirportContainer
     * @access private
     */
    function PrivateConstructor() {
        /**
         *
         */
        var data = null;
        /**
         *
         */
        this.setData = function(data) {
            this.data = data;
            return this;
        }
        /**
         *
         */
        this.getData = function(data) {
            return this.data;
        }
    }
    /**
     *
     */
    return new function() {
        this.getInstance = function() {
            if (instance == null) {
                instance = new PrivateConstructor();
                instance.constructor = null;
            }
            return instance;
        }
    }
})();
/**
 *
 *
 */
var Airports = function() {
    /**
     *
     */
    this.getUrl = function(){
        var protocol = document.location.toString().search('https') == 0 ? 'https' : 'http' ,base_uri = document.URL.replace(protocol,'').split('/');
        return protocol + base_uri[0] + '/flash/xml/flight_map_locations_de.xml';
    },

    /**
     *
     */
    this.setData = function(){
        new Ajax.Request(this.getUrl(),{
            method: 'get',
            onSuccess: function(transport){
                var nodes = transport.responseXML.getElementsByTagName('names')[0].childNodes, i, j=0, compare_stations = new Object(), elm = document.createElement('input');
                for(i=0;i<nodes.length;++i){
                    if(nodes[i].nodeName != '#text' && nodes[i].nodeName != '#comment'){
                        compare_stations[nodes[i].nodeName] = nodes[i].firstChild.nodeValue;
                        ++j;
                    }
                }
                AirportContainer.getInstance().setData(compare_stations);
            }
        });
    },

    /**
     *
     */
    this.getAirport = function(tlc){
        var data = AirportContainer.getInstance().getData();
        for(key in data){
            if(key.toLowerCase() == tlc.toLowerCase()){
                 return data[key];
            }
        }
        return tlc;
    }
    // Call 'setData' method as constructor
    this.setData();
}
/**
 * Initialize teaser tracking
 *
 */
function initializeTeaserTracking(){
    
    // Build struct based teaser decorator entity for 'Teasergroup44'
    var TeaserDecoratorTeasergroup44  = new AbstractTeaserDecoratorEntity();
    TeaserDecoratorTeasergroup44.name = 'strucTeasergroup44';
    TeaserDecoratorTeasergroup44.ignore = false;
    TeaserDecoratorTeasergroup44.find = function(){
        var struct = this.getElement(),teaser = all_content = [];
        // Load all div container inside the given struct
        all_content = struct.getStruct().getElementsByTagName('h5');
        // Introspect loaded div container elements and break it down into teasers
        for(var i=0;i<all_content.length;++i){
                // Init new teaser instance
                teaser[i] = new Teaser(all_content[i].parentNode);
                //Check if its an text or image headline
                headline = all_content[i].innerHTML;
                if(all_content[i].getElementsByTagName('img').length > 0){
                    headline = all_content[i].getElementsByTagName('img')[0].alt;
                    if(headline == ''){
                        headline = all_content[i].getElementsByTagName('img')[0].src;
                    }
                  }
                // Set teaser meta information
                teaser[i].setHeadline(headline)
                         .setPosition((i+1))
                         .setStructName(struct.getName());
        }
        return teaser;
    };
    // Build struct based teaser decorator entity for 'quadrupelSquare'
    var TeaserDecoratorQuadrupelSquare = new AbstractTeaserDecoratorEntity();
    TeaserDecoratorQuadrupelSquare.name = 'quadrupelSquare';
    TeaserDecoratorQuadrupelSquare.ignore = false;
    TeaserDecoratorQuadrupelSquare.airports = new Airports();
    TeaserDecoratorQuadrupelSquare.find = function(){
        var struct = this.getElement(), structs = [], raw_structs = struct.getStruct(), teaser = [], squares = [], i, j, k, l=0, temp, str, months = ['','Januar', 'Februar', 'M&auml;rz', 'April', 'Mai', 'Juni','Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'];
        raw_structs = raw_structs.getElementsByTagName('div');
        for(k=0;k<raw_structs.length;++k){
            if(raw_structs[k].className == 'quarter'){
                structs[l] = raw_structs[k];
                ++l;
            }
        }
        
        // Iterate over all single teaser elements
        for(i=0;i<structs.length;++i){
            // Read a@href and compile headline for tracking (destination airport, arrival airport, available from date)
            temp = structs[i].getElementsByTagName('a')[0].href.split('?')[1].split('&');
            squares[i] = '';
            for(j=0;j<temp.length;++j){
                str = temp[j].split('=')[1];
                squares[i] += temp[j].split('=')[1].length == 3 ? this.airports.getAirport(str) + (j == 0 ? ' -> ' : ' ab ') : j == 2 ? months[parseInt(str.split('-')[0])] + ' ' + str.split('-')[1] : str;
            }
            // Init new teaser instance
            teaser[i] = new Teaser(structs[i]);
            // Set teaser meta information
            teaser[i].setHeadline(squares[i])
                     .setPosition((i+1))
                     .setStructName(struct.getName());
        }
            
        return teaser;
    };

    // Build struct based teaser decorator entity for 'calendar24'
    var TeaserDecoratorCalendar = new AbstractTeaserDecoratorEntity();
    TeaserDecoratorCalendar.name = 'calendar24';
    TeaserDecoratorCalendar.ignore = false;
    TeaserDecoratorCalendar.find = function(){
        var struct = this.getElement().getStruct(), temp = struct.getElementsByTagName('a'), teaser = [];
            // Init new teaser instance
            teaser[0] = new Teaser(struct);
            
            // Set teaser meta information
            teaser[0].setHeadline(temp[0].getElementsByTagName('img')[0].getAttribute('alt'))
                     .setPosition(1)
                     .setStructName(this.getElement().getName());

        return teaser;
    };
    // Init global link sonsumer container
    link_consumer = new LinkConsumer();
    // Init struct finder
    struct_finder = new StructFinder();
    // Add struct classes to be introspected
    struct_finder.addStructClass('struct2colls33-2')
                 .addStructClass('struct134ShadowLeft')
                 .addStructClass('box2x24Container')
                 .addStructClass('struct224Shadow')
                 .addStructClass('struct224ShadowLeft')
                 .addStructClass('struct224ShadowRight')
                 .addStructClass('strucTeasergroup33')
                 .addStructClass('struct_4_4')
                 .addStructClass('structShadow44')
                 .addStructClass('strucTeasergroup44')
                 .addStructClass('structShadow55')
                 .addStructClass('destinationsThree')
                 .addStructClass('destinationsFour')
                 .addStructClass('folderLinkList33')
                 .addStructClass('folderText44')
                 .addStructClass('folderPressText33')
                 .addStructClass('quadrupleSquare')
                 .addStructClass('calendar24')
                 .addStructClass('structPriceTeasergroup44')
                 .addStructClass('structTeasergroup24');
    // Apply StructID e.g. div@title checking
    struct_finder.checkForStructID(true);
    // Get all structs
    structs = struct_finder.getStructs();
    // Prepare parsed structs array
    teaser_elements = parsed_structs = [];
    // Init teaser decorator/finder object
    teaser_decorator = new TeaserFinder();
    // Attach teaser decorator entities
    teaser_decorator.attach(TeaserDecoratorTeasergroup44.getName(), TeaserDecoratorTeasergroup44);
    teaser_decorator.attach(TeaserDecoratorQuadrupelSquare.getName(), TeaserDecoratorQuadrupelSquare);
    teaser_decorator.attach(TeaserDecoratorCalendar.getName(), TeaserDecoratorCalendar);
    
    // Iterate over found structs
    var run_for_cover = function(){
        for(i=0;i<structs.length;++i){
            // Creteate new Struct instance
            parsed_structs[i] = new Struct(structs[i], teaser_decorator);
            // Retrieve Teaser instances for every Teaser
            elements = parsed_structs[i].getTeaserElements();
            // Iterate over teaser elements
            for(j=0;j<elements.length;++j){
                // Grab links wrapped by the teaser
                links = elements[j].getLinks();
                // Iterate over links, wrapped by a valid teaser
                for(k=0;k<links.length;++k){
                    // Add tracking 'onclick' event to the link
                    elements[j].attachTrackingEvent(links[k]);
                }
            }
        }
    };
    setTimeout(run_for_cover,200);
}