/* draeger.js */
/* Dräger specific package */
/*
* $Rev: 587 $
* Author: //e7_cbtlchha
* 091001
*/
var draeger;
var stageReady=false;
if (!draeger) {
    draeger = {}
}

if (typeof jQuery != 'undefined') {
    $.extend(draeger, {
        loadPortfolio: function(mode,deeplink){
            $('.stage').flash({
                id:"portfolio",
                name:"portfolio",
                allowfullscreen:"true",
                allowScriptAccess: "always",
                menu: "false",
                src: draeger.DOCROOT+"/static/flash/portfolio/swf/main.swf",
                width: 960,
                height: 720,
                base: ".",
                quality: "high",
                //wmode: "transparent",
                flashvars: {
                    mode: mode,
                    deeplink: deeplink,
                    environment: "environmentProduction"
                }
            },
            {
                version: "9.0.115.0"
            },
            // Insert Flash Function
            function(htmlOptions) {
                $(this).addClass('flash-replaced');
                $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
            },
            // Noflash Alternative
            function(htmlOptions) {
                var noFlash= "<img src='"+draeger.DOCROOT+"/static/img/img_fallback_big.jpg' width='960' height='400' alt='Draeger'/><div class='altFlashtext'>"+draeger.NOFLASH_HINT+" <a href='http:\/\/www.adobe.com\/go\/getflashplayer'>"+draeger.NOFLASH_LINK+"</a>.</div>";
                $(this).html(noFlash);
            }
            );
        },
        loadSystemComponent: function(src){
            $('#TB_ajaxContent').css("background","none");
            //cookie check for intro
            var systemIntro = "true" ;

            if(($.cookies.get('systemintro_flash_start')=='stop')){
                systemIntro = "false" ;
            }
            else {
                $.cookies.set('systemintro_flash_start', 'stop');
            }
            $('.systemComponentLightbox').flash({
                allowScriptAccess:"always",
                allowfullscreen: true,
                src: draeger.DOCROOT+"/static/flash/systemcomponents/main.swf",
                width: 944,
                height: 510,
                base: ".",
                quality: "high",
                //bgcolor:"#fff",
                //salign:"lt",
                flashvars: {
                    xmlPath: src,
                    showIntro:systemIntro
                }
            },
            {
                version: "9.0.115.0"
            },
            // Insert Flash Function
            function(htmlOptions) {
                $(this).addClass('flash-replaced');
                $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
            },
            // Noflash Alternative
            function(htmlOptions) {
                var noFlash= '';
                $(this).html(noFlash);
            });
            //Omniture Tracking for Components Panel
            s.tl(true,'o', src);
        },
        initSystemComponent: function(src,targetClass){
            $('.'+targetClass).click(function(){
                draeger.loadSystemComponent(src);
            });
        },
        // Open Draeger Maps with Deluxe Teaser
        initDraegerMaps: function(){
            $(".draegerMap").click(function(){
                $(".draegerMapsLightbox").html('<iframe src="'+$(this).attr("rel")+'" scrolling="no"  frameborder="0" width="925" height="440" name="MapsIFrameContext"></iframe>');
            });
        },
        loadFlashProduct: function(src){
            //altImage when flash doesn't work
            var altImage = 'productNoFlash.jpg';
            $('.lightbox-content .full').flash({
                allowScriptAccess:"always",
                allowfullscreen: true,
                src: draeger.DOCROOT+src,
                width: 546,
                height: 470,
                base: ".",
                quality: "high",
                bgcolor:"#fff",
                salign:"lt",
                flashvars: {
                    waitingPic: "/static/img/product_detail/productFlashWait.gif"
                }
            },
            {
                version: "9.0.115.0"
            },
            // Insert Flash Function
            function(htmlOptions) {
                $(this).addClass('flash-replaced');
                $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
            },
            // Noflash Alternative
            function(htmlOptions) {
                var noFlash= "<img src='"+draeger.DOCROOT+"/static/img/product_detail/"+altImage+"' width='546' height='470' alt='Product NoFlash' title='"+src+"'/>";
                $(this).html(noFlash);
            });
        },
        initLightbox: function(){
            // checks how much thumbs are set for product lightbox and sets the width of lightbox
            var thumbs = $('.m-product .lightbox-content .thumbs li').length;
            var listWidthZoom="134px";
            var listWidthRound="134px";

            if (thumbs >4){
                var zoomInitParams = $('.thickbox.zoom').attr('href');
                var roundInitParams = $('.thickbox.roundview').attr('href');
                if (zoomInitParams!=null){
                    zoomInitParams = zoomInitParams.split("&");
                    if ((zoomInitParams[0]!=null)&&(zoomInitParams[1]!=null)&&(zoomInitParams[2]!=null)&&(zoomInitParams[1].match('width=705'))){
                        if ((thumbs >= 5) && (thumbs <=8)){
                            zoomInitParams[1]='&width=850&';
                            listWidthZoom="280px";
                        } else
                        if ((thumbs >= 9) && (thumbs <=12)){
                            zoomInitParams[1]='&width=985&';
                            listWidthZoom="415px";
                        }
                        $('.thickbox.zoom').attr({
                            href: zoomInitParams[0]+zoomInitParams[1]+zoomInitParams[2]
                            });
                        $('.lightbox-content .thumbs').css({
                            width:listWidthZoom
                        });
                    }
                }
                if (roundInitParams!=null){
                    roundInitParams = roundInitParams.split("&");
                    if ((roundInitParams[0]!=null)&&(roundInitParams[1]!=null)&&(roundInitParams[2]!=null)&&(roundInitParams[1].match('width=705'))){
                        if ((thumbs >= 5) && (thumbs <=8)){
                            roundInitParams[1]='&width=850&';
                            listWidthRound="280px";
                        } else
                        if ((thumbs >= 9) && (thumbs <=12)){
                            roundInitParams[1]='&width=985&';
                            listWidthRound="415px";
                        }
                        $('.thickbox.roundview').attr({
                            href: zoomInitParams[0]+zoomInitParams[1]+zoomInitParams[2]
                            });
                        $('.lightbox-content .thumbs').css({
                            width:listWidthRound
                        });
                    }
                }
            }
            //closing lightbox
            $('.lightbox-content .close').click(tb_remove);
            // function to swap images/swf's in lightbox
            $('.lightbox-content .thumbs a,.lightbox-content .controls a').click(function(i) {
                //remove active highlight
                $('.lightbox-content .thumbs a').removeClass("active");
                // thumbnail navigation
                if ($(this).parents("ul").hasClass('thumbs')==true) {
                    //set active highlight
                    $(this).addClass("active");
                    //check src auf swf
                    if ($(this).attr('href').search(/\.swf/)!=-1){
                        draeger.loadFlashProduct($(this).attr('href'));
                    } else {
                        $('.lightbox-content .full').html('<img alt="Product Full View" src="'+$(this).attr('href')+'" />')
                    }
                    // Description gesetzt
                    $('.lightbox-content #productText').html($(this).attr('title'));
                } else if($(this).attr('id') == 'forwards' || $(this).attr('id') == 'backwards'){

                } else {
                    //check tag src of img, embed or object
                    var current_file;
                    if ($('.lightbox-content .full object').html()!=null){
                        current_file = $('.lightbox-content .full object').attr('data');
                    } else {
                        current_file = $('.lightbox-content .full').children().attr('src');
                        if (current_file.search("productNoFlash.jpg")!=-1) {
                            current_file = $('.lightbox-content .full').children().attr('title');
                        }
                    }
                    views = new Array();
                    titles = new Array();
                    $('.lightbox-content .thumbs a').each(function(i) {
                        views[i] = $(this).attr('href');
                        titles[i] = $(this).attr('title');
                    })

                    // relate current image to array of thumbnail images
                    for (var j=0;j<views.length;j++) {
                        if (current_file.search(views[j])!=-1) {
                            var current_id = j;
                        }
                    }

                    if ($(this).hasClass('backwards')==true ) {
                        if (current_id > 0) {
                            //set active highlight
                            $('.lightbox-content .thumbs li').eq(current_id-1).children('a').addClass("active");
                            //check auf swf src
                            if (views[current_id-1].search(/\.swf/)!=-1){
                                draeger.loadFlashProduct(views[current_id-1]);
                            } else {
                                $('.lightbox-content .full').html('<img alt="Product Full View" src="'+views[current_id-1]+'" />');
                            }
                            // Description gesetzt
                            $('.lightbox-content #productText').html(titles[current_id-1]);
                        } else {
                            //set active highlight
                            $('.lightbox-content .thumbs li').eq(views.length-1).children('a').addClass("active");
                            //check auf swf src
                            if (views[views.length-1].search(/\.swf/)!=-1){
                                draeger.loadFlashProduct(views[views.length-1]);
                            } else {
                                $('.lightbox-content .full').html('<img alt="Product Full View" src="'+views[views.length-1]+'" />');
                            }
                            // Description gesetzt
                            $('.lightbox-content #productText').html(titles[views.length-1]);
                        }
                    }
                    if ($(this).hasClass('forwards')==true) {
                        if (current_id < views.length-1) {
                            //set active highlight
                            $('.lightbox-content .thumbs li').eq(current_id+1).children('a').addClass("active");
                            //check auf swf src
                            if (views[current_id+1].search(/\.swf/)!=-1){
                                draeger.loadFlashProduct(views[current_id+1]);
                            } else {
                                $('.lightbox-content .full').html('<img alt="Product Full View" src="'+views[current_id+1]+'" />');
                            }
                            // Description gesetzt
                            $('.lightbox-content #productText').html(titles[current_id+1]);
                        } else {
                            //set active highlight
                            $('.lightbox-content .thumbs li').eq(0).children('a').addClass("active");
                            //check auf swf src
                            if (views[0].search(/\.swf/)!=-1){
                                draeger.loadFlashProduct(views[0]);
                            } else {
                                $('.lightbox-content .full').html('<img alt="Product Full View" src="'+views[0]+'" />');
                            }
                            // Description gesetzt
                            $('.lightbox-content #productText').html(titles[0]);
                        }
                    }
                }
                return false
            })
            // init lightbox (flash or image)
            $('.controls a.zoom, .controls a.roundview, a.imgLightbox').click(function(i) {
                var actElem="";
                //remove active highlight
                $('.lightbox-content .thumbs a').removeClass("active");
                //active Lightbox Element (clicked roundview first flashfilm will be selected)
                if ($(this).hasClass('roundview')){

                    $('.lightbox-content .thumbs a').each(function (i) {
                        if (this.href.search(/\.swf/)!=-1) {
                            actElem = $(this);
                            return false;
                        }
                    });
                    //wenn kein Flashfilm gefunden, erste Position
                    if (actElem==""){
                        actElem= $('.lightbox-content .thumbs a').eq(0);
                    }
                } else {

                    actElem= $('.lightbox-content .thumbs a').eq(0);
                }

                //set active highlight
                actElem.addClass("active");
                //check src auf swf
                if (actElem.attr('href').search(/\.swf/)!=-1){
                    draeger.loadFlashProduct(actElem.attr('href'));
                } else {
                    $('.lightbox-content .full').html('<img alt="Product Full View" src="'+actElem.attr('href')+'" />')
                }
                // Description gesetzt
                $('.lightbox-content #productText').html(actElem.attr('title'));
            })


        },
        init: function() {

            draeger.initLightbox();
            draeger.initDraegerMaps();

            // show all stuff which uses js
            $('.jsinline').css('display', 'inline')
            $('.jsblock').css('display', 'block')

            // init mainmenu
            $('.mainmenu>ul>li').hover(
                function() {
                    $(this).addClass('open')
                },
                function() {
                    $(this).removeClass('open')
                }
                )

            // init flaps
            $('.context .flaps').flaps()
            $('.m-feature .flaps').flaps({
                accordion: true
            })

            // init tabsets
            $('.m-rnav-active, .m-select1').tabset()
            $('.m-rnav-inactive').tabset({
                inactive: true
            })

            // init countries in meta
            $('.countries ul').compactLinks({
                handleContentSelector: 'b',
                handleClass: 'countries-handle',
                hoverClass: 'countries-hover'
            }
            )
            $('.simpleselect').compactLinks({
                handleClass: 'simpleselect-handle',
                hoverClass: 'simpleselect-hover'
            }
            )



            // init links to exp search
            $('.lnk-exp').each(function() {
                var a = $(this)
                var t = $(a.attr('href'))
                if (t.length) {
                    a.click(function() {
                        t.slideToggle()
                    })
                }
            })


            // init select boxes
            $('.m-select1 select, .m-select2 select').each(function() {
                var s = $(this)
                var f = s.parents('form')
                s.selectbox()
                var li = s.prev('.selectbox-wrapper ul li')
                li.click(function() {
                    f.submit()
                })

            })


            //init click on text field empties it
            $('.m-form .text, .form .text, textarea').focus(function() {
                $(this).attr('value', '');
                $(this).unbind();
            })
            // if we got a hrbackend form, the event will be removed
            $('.m-form.hrbackend .text, .form.hrbackend .text,.form.hrbackend textarea, .m-form.hrbackend textarea').unbind();


            // product fields should be links completely
            $('.products').each(function(){
                var p = $(this)
                var href = $('h3 a', p).attr('href')
                p.css('cursor', 'pointer')
                // is not called when click on clipboard, see before
                p.click(function() {
                    document.location = href
                })
            })

            // add mouseover for IE < 7
            if ($.browser.msie && parseInt($.browser.version) < 7) {

                // fix IE6 z-index <select>s
                $('.mainmenu .block, .mainmenu .no-blocks').bgiframe();

                // submit buttons
                $('.m-form input.button, .context input.button').hover(
                    function(){
                        $(this).addClass('button-over')
                    },
                    function(){
                        $(this).removeClass('button-over')
                    }
                    )
                // clipboard buttons
                $('.clipboard').hover(
                    function(){
                        $(this).addClass('clipboard-over')
                    },
                    function(){
                        $(this).removeClass('clipboard-over')
                    }
                    )
                // flaps
                $('.flaps dt').hover(
                    function(){
                        $(this).addClass('flap-over')
                    },
                    function(){
                        $(this).removeClass('flap-over')
                    }
                    )
                // product fields
                $('.products').hover(
                    function(){
                        $(this).addClass('products-over')
                    },
                    function(){
                        $(this).removeClass('products-over')
                    }
                    )
                // product fields
                $('.collect').hover(
                    function(){
                        $(this).addClass('collect-over')
                    },
                    function(){
                        $(this).removeClass('collect-over')
                    }
                    )
            }

        },
        // bookmarks a page as far as browsers allow this
        bookmark: function (){
            var title = $('title').html()
            var urlBookmark=location.href;
            //Wenn Produktselektor angezeigt, wird URL mit Parametern versehen
            if(draeger.PRODUCTSELECTOR_ACTIVE){
                // aktuell gezeigte Parameter mit Bookmark Servlet URL speichern
                urlBookmark=urlBookmark.replace(/\/[^\/]*$/,"")+"/productSelector.action?root="+root+"&cat="+sector+"&page="+page+"&lang="+draeger.LANGUAGE+"&size="+size+"&layout="+prodViewClass;
                // wenn Suchwort vorhanden, wird dieses gespeichert
                if (query!=""){
                    urlBookmark+="&query="+query;
                }
                // gewählte Kategorien werden als Parameter mitübergeben
                for (var i=0;i<selectSelected.length;i++){
                    if (selectSelected[i]!=""){
                        urlBookmark+="&selections["+i+"]="+selectSelected[i];
                    }
                }
            }
            //Wenn Stellenselektor angezeigt, wird URL mit Parametern versehen
            if(draeger.HRSELECTOR_ACTIVE){
                // aktuell gezeigte Parameter mit Bookmark Servlet URL speichern
                urlBookmark=urlBookmark.replace(/\/[^\/]*$/,"")+"/getJobOffers.action?country="+country+"&location="+loc+"&category="+cat+"&page="+page+"&lang="+draeger.LANGUAGE+"&pagesize="+size;
                // wenn Suchwort vorhanden, wird dieses gespeichert
                if (query!=""){
                    urlBookmark+="&search="+query;
                }
            }
            //Wenn Adress Selektor angezeigt, wird URL mit Parametern versehen
            if(draeger.ADDRESSSELECTOR_ACTIVE){
                // aktuell gezeigte Parameter mit Bookmark Servlet URL speichern
                urlBookmark=urlBookmark.replace(/\/[^\/]*$/,"")+"/start.action?country="+country+"&city="+loc+"&contactType="+seller+"&page="+page+"&lang="+draeger.LANGUAGE;
                // wenn Suchwort vorhanden, wird dieses gespeichert
                if (query!=""){
                    urlBookmark+="&query="+query;
                }
            }
            //Wenn Event Selektor angezeigt, wird URL mit Parametern versehen
            if(draeger.EVENTSELECTOR_ACTIVE){
                // aktuell gezeigte Parameter mit Bookmark Servlet URL speichern
                urlBookmark=urlBookmark.replace(/\/[^\/]*$/,"")+"/start.action?country="+country+"&industry="+industry+"&year="+year+"&month="+month+"&page="+page+"&pagesize="+size+"&lang="+draeger.LANGUAGE;
                // wenn Suchwort vorhanden, wird dieses gespeichert
                if (query!=""){
                    urlBookmark+="&query="+query;
                }
            }
            // Browsertest
            if(window.sidebar){ // Firefox
                //Bookmark hinzufügen
                window.sidebar.addPanel(title, urlBookmark,'');
            }else if(window.opera){ //Opera
                var a = document.createElement("A");
                a.rel = "sidebar";
                a.target = "_search";
                a.title = title;
                a.href = urlBookmark;
                //Bookmark hinzufügen
                a.click();
            } else if(document.all){ //IE
                //Bookmark hinzufügen
                window.external.AddFavorite(urlBookmark,title);
            } else {
                //Fehlermeldung bei Inkompatibilität zu Browsern
                alert(draeger.ERROR_BOOKMARK_SUPPORT)
            }
        },
        // called by stage, when its ready
        onAppLoaded: function() {
            stageReady=true;
        },

        // called by menu entries to give stage flash the chance to change itself
        // parameter over is true on mouseover, else false
        menuCallsStage: function(over) {
            if (stageReady==true){
                if (over==true){
                    document.getElementById("flashstage").setInteractive('disabled');
                } else {
                    document.getElementById("flashstage").setInteractive('enabled');
                }
            }
        },
        loadFlashCountryselect: function(wddx){
            $('.stage').flash({
                id:"countryselect",
                allowScriptAccess:"sameDomain",
                src: draeger.DOCROOT+"/static/flash/countryselect/main.swf",
                width: 965,
                height: 384,
                base: ".",
                quality: "high",
                //wmode: "transparent",
                flashvars: {
                    wddx: wddx
                }
            },
            {
                version: "9.0.115.0"
            },
            // Insert Flash Function
            function(htmlOptions) {
                $(this).addClass('flash-replaced');
                $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
            },
            // Noflash Alternative
            function(htmlOptions) {
                $('.stage .fallback').removeClass("jsdisplay");
            }
            )
            },
        loadFlashStage: function(wddx,type,lang,autoplay,soundState){
            var height=400;
            var altImage = 'img_fallback_big.jpg';
            if (type!="fullSize"){
                height=192;
                altImage = 'img_fallback_medium.jpg'
            }

            // Soundsteuerung mit Cookie
            // wenn Cookie Sound aus gesetzt, dann wird Sound auch bei CMS 'on' ausgeschaltet
            if(($.cookies.get('draeger_stageSoundOff')=='soundOff')&&(soundState!='disabled')){

                soundState='off';
            }
            // Autoplay mit Cookie
            // wenn Cookie Autoplay false gesetzt, dann wird Autoplay auch bei CMS 'true' ausgeschaltet
            if(($.cookies.get('draeger_stageAutoplayFalse')=='autoplayFalse')&&(autoplay=='true')){

                autoplay='false';
            }

            $('.stage').flash({
                id:"flashstage",
                allowScriptAccess:"sameDomain",
                src: draeger.DOCROOT+"/static/flash/stage/main.swf",
                width: 765,
                height: height,
                base: ".",
                quality: "high",
                wmode: "transparent",
                flashvars: {
                    wddx: wddx,
                    type: type,
                    language: lang,
                    autoplay: autoplay,
                    soundState: soundState
                }
            },
            {
                version: "9.0.115.0"
            },
            // Insert Flash Function
            function(htmlOptions) {
                $(this).addClass('flash-replaced');
                $(this)[0].innerHTML=$.fn.flash.transform(htmlOptions);
            },
            // Noflash Alternative
            function(htmlOptions) {
                var noFlash= "<img src='"+draeger.DOCROOT+"/static/img/"+altImage+"' width='765' height='"+height+"' alt='Draeger'/><div class='altFlashtext'>"+draeger.NOFLASH_HINT+" <a href='http:\/\/www.adobe.com\/go\/getflashplayer'>"+draeger.NOFLASH_LINK+"</a>.</div>";
                if ($('body.splash').html()==null) {
                    $(this).html(noFlash);
                }

            }
            );
            // init mainmenu calls stage flash
            $('#menu').hover(
                function(){
                    draeger.menuCallsStage(true)
                },
                function(){
                    draeger.menuCallsStage(false)
                }
                )
        },
        ipCookieControl: function(){
            // werden Cookies supportet?
            if($.cookies.test()){
                //closin country lightbox
                $('.country-confirm-content input,.country-confirm-content a').click(tb_remove);

                //select country page in meta navigation
                $(".meta .countries a, .meta .countrySelection a").click(function(){
                    // set cookie for country switch
                    $.cookies.set('draeger_switch_country_page', 'true');
                });

                // confirm default country page
                $(".country-confirm-content .saveSelectionInCookie").click(function(){
                    var confirm = "cfm=1&val=";
                    //form submitted?
                    if($(this).attr("type")=="submit"){
                        saveIpCookie=$("#country-confirm-select option:selected").attr("value");
                        // set LSY cookie
                        $.cookies.set('pref',confirm + saveIpCookie,{
                            hoursToLive:8760
                        });
                        //forward to country page
                        location.href=saveIpCookie;
                    }  else {
                        // set LSY cookie
                        $.cookies.set('pref',confirm + saveIpCookie,{
                            hoursToLive:8760
                        });
                    }
                });

                // open country lightbox : if not visited in session and no ip locator cookie set
                var pref = $.cookies.get('pref');
                if(pref){
                    var cookieFlag = pref.split("&");
                    // check if form already opened in session and cookie value is "0"
                    if (($.cookies.get('draeger_already_visited') != "true")&&(cookieFlag[0].substr(cookieFlag[0].indexOf("cfm=")+4, 1) == "0")) {
                        //set form showed cookie for session
                        $.cookies.set('draeger_already_visited', 'true');
                        window.setTimeout(function() {
                            tb_show("", "#TB_inline?height=480&amp;width=500&amp;inlineId=country-confirm-lightbox", "");
                        }, 20);
                    }
                }

                //open county lightbox small when country menu clicked and new page  loads
                if ($.cookies.get('draeger_switch_country_page') == "true") {
                    //remove cookie switch country page
                    $.cookies.del('draeger_switch_country_page');
                    window.setTimeout(function() {
                        tb_show("", "#TB_inline?height=260&amp;width=500&amp;inlineId=country-confirm-lightbox-small", "");
                    }, 20);
                }
            }
        }
    })
    /* page load */
    $().ready(function() {
        draeger.init();
    });
	
    // Stage gibt Sound und Pausen Status zurück
    function playControl(type){
        //wird in Cookie gesetzt/gelöscht
        switch (type) {
            case "videoPlay":    $.cookies.del('draeger_stageAutoplayFalse');
                break;
            case "videoPause":  $.cookies.set('draeger_stageAutoplayFalse', 'autoplayFalse');
                break;
            case "soundPlay":    $.cookies.del('draeger_stageSoundOff');
                break;
            case "soundPause":  $.cookies.set('draeger_stageSoundOff', 'soundOff');
                break;

        }
    }
}

/* toolbox.js */
/* 
 * JS Logik für Draeger Toolbox (Clipboard, Merkzettel, Downloadliste)
 * created by Christian Beyer (e7)
 */

// Namen der Cookies und Domain hier setzen
var cookieNames= new Array(draeger.COOKIE_TB_PRODUCTS,draeger.COOKIE_TB_DOWNLOADS,draeger.COOKIE_TB_PAGEREMINDER,draeger.COOKIE_TB_JOBS);
var cookieDomain=draeger.COOKIE_TB_DOMAIN;
var cookieExpire=356;

//0 -> Clipboard, 1 -> Downloads, 2 -> Merkzettel
var sendIds= new Array("","","","");
var cookieInfo= new Array("","","","");

/*
 * Cookies werden anhand von Parametern gesetzt
 */
function setCookie( name, value, expires, path, domain, secure ) {
	var today = new Date();
	today.setTime( today.getTime() );
	if ( expires )	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
	( ( path ) ? ";path=" + path : "" ) + 
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

/*
 * Cookievalues werden anhand des übergebenen Namens ausgelesen
 */
function readCookie(name) { 
        var myCookie = document.cookie; 
        if (myCookie.indexOf(name) == -1) {       
          return null; 
        }
        var start = myCookie.indexOf(name) + name.length + 1;  
        var end = myCookie.indexOf(";", start); 
        if (end == -1) { 
            end = myCookie.length; 
        }
        var length = end-start;
        var result = unescape(myCookie.substr(start,length));
        return result; 
}

/*
 * Produkt zum Clipboard hinzufügen
 */
function addClipboard(elem){
     // Werte auslesen
     var actName="";
     var actId="";
     var actImg="";
    // SeitenId, URl und Name wird aus Linkparameter gelesen
    var actLink=elem.attr("href").split("?");
    actLink= actLink[actLink.length-1];
    actLink=actLink.split("&");
    for (var i=0;i<actLink.length;i++){
        var param= actLink[i].split("=");
        if (param[0]=="name"){
            actName=param[1];
        }
        if (param[0]=="id"){
            actId=param[1];
        }               
        if (param[0]=="image"){
            actImg=param[1];
        }
    }
     // Wenn Id noch nicht eingetragen
     if (!sendIds[0].match(actId)){
        //Id für Versand  merken
        sendIds[0]+=actId+",";
        //cookie setzen mit ids
        cookieInfo[0]+=actName+";"+actId+";"+actImg+"|";
        setCookie(cookieNames[0],cookieInfo[0],0, "/", cookieDomain);
       // alert("Name: "+actName+" ImgPath: "+actImgPath+" actId: "+actId+" gespeicherte Ids: "+sendIds[0]);   
        var prodClip="<div id=ac_"+actId+" class='clearfix'><img src='"+draeger.CLIPBOARD_IMG_PATH+actImg+"' alt='' width='65' height='50' /><div><h3 class='sl'>"+actName+"</h3><a class='button removeMe' href='#' title=''>"+draeger.TEXT_DELETE+"</a></div></div>";
        $(".clipboardlist").append(prodClip);
        //Event anbringen
        $(".clipboardlist").children("div:last-child").children("div").children(".removeMe").click(function(){removeFromClipboard($(this));return false;});
     }
}

/*
 * Produkt aus Clipboard entfernen
 */
function removeFromClipboard(elem){
        elem=elem.parent();
        var actName=elem.children("h3").html();
        elem=elem.parent();
        var actImg=elem.children("img").attr("src");
        actImg=actImg.replace(/^.*\//,"");
        //original ID hergestellt
        var actId=elem.attr("id").substring(3,elem.attr("id").length);
       
        //Id entfernen
        sendIds[0]=sendIds[0].replace(actId+",","");
         //alert("Sendids: "+sendIds[0]);
        //Info aus cookie entfernen
        cookieInfo[0]=cookieInfo[0].replace(actName+";"+actId+";"+actImg+"|","");
         //alert("cookieInfo: "+cookieInfo[0]);
        setCookie(cookieNames[0],cookieInfo[0],0, "/", cookieDomain);
        //HTML entfernen
        elem.remove();
}

/*
 * Element zur Downloadliste hinzufügen 
 */
function addDownload(elem){
    var actName="";
    var actId="";
    var actUrl="";
    
    // SeitenId, URl und Name wird aus Linkparameter gelesen
    var actLink=elem.attr("href").split("?");
    actLink= actLink[actLink.length-1];
    actLink=actLink.split("&");
    for (var i=0;i<actLink.length;i++){
        var param= actLink[i].split("=");
        if (param[0]=="name"){
            actName=param[1];
        }
        if (param[0]=="id"){
            actId=param[1];
        }        
        if (param[0]=="url"){
            actUrl=param[1];
        }        
    }
    // Wenn Id noch nicht eingetragen
    if (!sendIds[1].match(actId)){
      sendIds[1]+=actId+",";
      //cookie setzen mit ids und name
      cookieInfo[1]+=actName+";"+actId+";"+actUrl+"|";
      setCookie(cookieNames[1],cookieInfo[1], cookieExpire, "/", cookieDomain);
      //HTML Rendern
      var downItem="<li id='ad_"+actId+"'><a class='remove removeMe' href='#' title=''><img alt='"+draeger.TEXT_DELETE+"' src='"+draeger.DOCROOT+"/static/img/delete.gif'/></a><a class='toolInfoElem' href="+actUrl+" >"+actName+"</a></li>";
      $(".downloadlist").append(downItem);
       // Liste sichtbar schalten
       $(".downloadlist").removeClass("jsdisplay");
      //Event anbringen
      $(".downloadlist").children("li:last-child").children(".removeMe").click(function(){removeFromDownload($(this));return false;});
    } 
}

/*
 * Element von Downloadliste entfernen
 */
function removeFromDownload(elem){
    elem=elem.parent();
    var actName=elem.children(".toolInfoElem").html();
    var actHref=elem.children(".toolInfoElem").attr("href");
    var actId=elem.attr("id").substring(3,elem.attr("id").length);
     // link check for IE
    var linkLength=actHref.length-1;
    if (actHref.substr(linkLength, 1)=="/"){
        actHref=actHref.replace(/\/$/,"");
    }
    //Id entfernen
    sendIds[1]=sendIds[1].replace(actId+",","");
    //Info aus cookie entfernen
    cookieInfo[1]=cookieInfo[1].replace(actName+";"+actId+";"+actHref+"|","");
    setCookie(cookieNames[1],cookieInfo[1],cookieExpire, "/", cookieDomain);
    //HTML entfernen
    elem.remove();
    //Sichtbarkeitseinstellungen
    if (sendIds[1]==""){
       $(".downloadlist").addClass("jsdisplay");
   }
}

function removeAllDownloads(){
    $(".downloadlist").html("");
    sendIds[1]="";
    cookieInfo[1]="";
    setCookie(cookieNames[1],cookieInfo[1],cookieExpire, "/", cookieDomain);             
    $(".downloadlist").addClass("jsdisplay");
}


/*
 * Seite zum Merkzettel hinzufügen
 */
function addMerkzettel(elem){
    var actName="";
    var actId="";
    // SeitenId und Name wird aus Linkparameter gelesen
    var actLink=elem.attr("href").split("?");
    actLink= actLink[actLink.length-1];
    actLink=actLink.split("&");
    for (var i=0;i<actLink.length;i++){
        var param= actLink[i].split("=");
        if (param[0]=="name"){
            actName=param[1];
        }
        if (param[0]=="id"){
            actId=param[1];
        }        
    }
    // Wenn Id noch nicht eingetragen
    if (!sendIds[2].match(actId)){
       sendIds[2]+=actId+",";
       //cookie setzen mit ids und name
       cookieInfo[2]+=actName+";"+actId+"|";
       setCookie(cookieNames[2],cookieInfo[2], cookieExpire, "/", cookieDomain);
       //HTML Rendern
       var actPage="<li class='find_me clearfix'><a class='remove removeMe' href='#' title=''><img src='"+draeger.DOCROOT+"/static/img/delete.gif' alt='"+draeger.TEXT_DELETE+"' /></a><a href="+actId+">"+actName+"</a></li>";
       $(".merklist").append(actPage);
       // Liste sichtbar schalten
       $(".merklist").removeClass("jsdisplay");
       
       //Event anbringen 
       $(".find_me").children(".removeMe").click(function(){removeFromMerkzettel($(this));return false;}).removeClass("find_me");
       $(".find_me").removeClass("find_me");
      
      //alert("Pagename: "+actName+" ID: "+actId); 
    }
}

/*
 * Seite vom Merkzettel entfernen
 */
function removeFromMerkzettel(elem){
    elem=elem.next("a");
    var actName=elem.html();
    var actHref=elem.attr("href");
    // link check for IE
    var linkLength=actHref.length-1;
    if (actHref.substr(linkLength, 1)=="/"){
        actHref=actHref.replace(/\/$/,"");
    }
    //Id entfernen
    sendIds[2]=sendIds[2].replace(actHref+",","");
    //Info aus cookie entfernen
    cookieInfo[2]=cookieInfo[2].replace(actName+";"+actHref+"|","");
    setCookie(cookieNames[2],cookieInfo[2],cookieExpire, "/", cookieDomain);
    //HTML entfernen
    elem.parent().remove();
    //Liste verstecken
   if (sendIds[2]==""){
       $(".merklist").addClass("jsdisplay");
   }
}

function removeMerkzettel(){
    $(".merklist").html("");
    sendIds[2]="";
    cookieInfo[2]="";
    setCookie(cookieNames[2],cookieInfo[2],cookieExpire, "/", cookieDomain); 
    //Liste sichtbar schalten
    $(".merklist").addClass("jsdisplay");
   
}


/*
 * Jobangebot zur Liste hinzufügen
 */
function addJob(elem){
     var actName="";
     var actId="";
     // SeitenId und Description wird aus Linkparameter gelesen
     var actLink=elem.attr("href").split("?");
     actLink= actLink[actLink.length-1];
     actLink=actLink.split("&");
     for (var i=0;i<actLink.length;i++){
        var param= actLink[i].split("=");
        if (param[0]=="name"){
            actName=param[1];
        }
        if (param[0]=="id"){
            actId=param[1];
        }        
     }
     // Wenn Id noch nicht eingetragen
     if (!sendIds[3].match(actId)){
        //Id für Versand  merken
        sendIds[3]+=actId+",";
        //cookie setzen mit ids
        cookieInfo[3]+=actName+";"+actId+"|";
        setCookie(cookieNames[3],cookieInfo[3],cookieExpire, "/", cookieDomain);
        var actJob="<div id=aj_"+actId+" class='clearfix'><a class='button removeMe' href='#' title=''></a><h3 class='sl'>"+actName+"</h3></div>";
        $(".joblist").append(actJob);
        //Event anbringen
        $(".joblist").children("div:last-child").children(".removeMe").click(function(){removeFromJoblist($(this));return false;});
     }
}

/*
 * Jobangebot aus Liste entfernen
 */
function removeFromJoblist(elem){
        elem=elem.parent();
        var actName=elem.children("h3").html();
        //original ID hergestellt
        var actId=elem.attr("id").substring(3,elem.attr("id").length);
        //Id entfernen
        sendIds[3]=sendIds[3].replace(actId+",","");
        //Info aus cookie entfernen
        cookieInfo[3]=cookieInfo[3].replace(actName+";"+actId+"|","");
        setCookie(cookieNames[3],cookieInfo[3],cookieExpire, "/", cookieDomain);
        //HTML entfernen
        elem.remove();
}


/*
 * Id-Liste (Clipboard,Downloads) abschicken
 */
function sendRequest(elem){
    var sendUrl="";//was draeger.SEND_PATH;
   
    // unterscheiden, ob Download oder Clipboard gesendet wird
    if (elem.hasClass("sendDownload")){
        //url mit Parameter bauen
        sendUrl+="dl/download.action?lang="+draeger.LANGUAGE+"&downloadIds="+sendIds[1].substr(0, sendIds[1].length-1);
    }
    if (elem.hasClass("sendClipboard_compare")){
        //url mit Parameter bauen
        sendUrl+="productSelector/quickCompare.action?lang="+draeger.LANGUAGE+"&productIds="+sendIds[0].substr(0, sendIds[0].length-1);
    }
    if (elem.hasClass("sendClipboard_offer")){
        //url mit Parameter bauen
        sendUrl+="productSelector/requestOffer.action?lang="+draeger.LANGUAGE+"&productIds="+sendIds[0].substr(0, sendIds[0].length-1);
    }
    if (elem.hasClass("sendJoblist")){
        //url mit Parameter bauen
        sendUrl+="hr/startMultiJobApplication.action?lang="+draeger.LANGUAGE+"&jobnumber="+sendIds[3].substr(0, sendIds[3].length-1);
    }
    if (elem.hasClass("applyJoblist")){
        //url mit Parameter bauen
        sendUrl+="hr/startMultiJobApplication.action?lang="+draeger.LANGUAGE+"&jobnumber="+sendIds[3].substr(0, sendIds[3].length-1);
    }
    // Request absenden
    window.location.href = sendUrl;
}

/* 
 * Funktionen zur Initialisierung der Toolboxlisten
 */

/*
 * Clipboardliste befüllen
 */
function initClipboard(items) {
    var elem= new Array("","","");
   //Items auslesen
   for (var i=0; i<items.length-1;i++){
      elem=items[i].split(";");
      //sendIds und cookieInfo füllen
      cookieInfo[0]+=items[i]+"|";
      sendIds[0]+=elem[1]+",";
      // Html für Element bauen
      var prodClip="<div id=ac_"+elem[1]+" class='clearfix'><img src='"+draeger.CLIPBOARD_IMG_PATH+elem[2]+"' alt='' width='65' height='50' /><div><h3 class='sl'>"+elem[0]+"</h3><a class='button removeMe' href='#' title=''>"+draeger.TEXT_DELETE+"</a></div></div>";
      // in Liste einhängen
      $(".clipboardlist").append(prodClip);   
   }
}


/*
 * Dowloadliste befüllen
 */
function initDownloads(items) {
   var elem= new Array("","","");
   //Items auslesen
   for (var i=0; i<items.length-1;i++){
      elem=items[i].split(";");
      //sendIds und cookieInfo füllen
      cookieInfo[1]+=items[i]+"|";
      sendIds[1]+=elem[1]+",";
      // Html für Element bauen
      var downItem="<li id='ad_"+elem[1]+"'><a class='remove removeMe' href='' title=''><img alt='"+draeger.TEXT_DELETE+"' src='"+draeger.DOCROOT+"/static/img/delete.gif'/></a><a class='toolInfoElem' href="+elem[2]+" >"+elem[0]+"</a></li>";
      // in Liste einhängen
      $(".downloadlist").append(downItem);     
   }
   //Liste sichtbar schalten
   if (sendIds[1]!=""){
       $(".downloadlist").removeClass("jsdisplay");
   }
}

/*
 * Merkzettel befüllen
 */
function initMerkzettel(items) {
   var elem= new Array("","");
   //Items auslesen
   for (var i=0; i<items.length-1;i++){
      elem=items[i].split(";");
      //sendIds und cookieInfo füllen
      cookieInfo[2]+=items[i]+"|";
      sendIds[2]+=elem[1]+",";
      // Html für Element bauen
      var actPage="<li class='clearfix'><a class='remove removeMe' href='#'  title=''><img src='"+draeger.DOCROOT+"/static/img/delete.gif' alt='"+draeger.TEXT_DELETE+"' /></a><a href="+elem[1]+">"+elem[0]+"</a></li>";
      // in Liste einhängen
      $(".merklist").append(actPage);   
   }
   //Liste sichtbar schalten
   if (sendIds[2]!=""){
       $(".merklist").removeClass("jsdisplay");
   }
}

/*
 * Jobliste befüllen
 */
function initJoblist(items) {
    var elem= new Array("","");
   //Items auslesen
   for (var i=0; i<items.length-1;i++){
      elem=items[i].split(";");
      //sendIds und cookieInfo füllen
      cookieInfo[3]+=items[i]+"|";
      sendIds[3]+=elem[1]+",";
      // Html für Element bauen
      var actJob="<div id=ac_"+elem[1]+" class='clearfix'><a class='button removeMe' href='' title=''></a><h3 class='sl'>"+elem[0]+"</h3></div>";
      // in Liste einhängen
      $(".joblist").append(actJob);   
   }
}


/*
 * Toolbox initialisieren
 */
function initToolbox() {
   //Wenn Liste vorhanden, sichtbar geschaltet 
   if($(".m-cpl")!=null){
      $(".m-cpl").attr("style","display:block;"); 
   }
   if($(".m-dk")!=null){
      $(".m-dk").attr("style","display:block;");
   }
   if($(".m-mz")!=null){
      $(".m-mz").attr("style","display:block;");   
   }
   if($(".m-cpj")!=null){
      $(".m-cpj").attr("style","display:block;");   
   }
   //Werte der Cookies auslesen
   for (var i=0; i<cookieNames.length;i++){
      var value= readCookie(cookieNames[i]);
      //alert("Value"+value);
      if (value!=null){
        switch (cookieNames[i]){
           case cookieNames[0]: initClipboard(value.split("|"));
                                break;
           case cookieNames[1]: initDownloads(value.split("|"));
                                break;
           case cookieNames[2]: initMerkzettel(value.split("|"));
                                break;
           case cookieNames[3]: initJoblist(value.split("|"));
                                break;                                
        }
      }
   }
}
        

/*
 * Window Onload  - Initialisierung und Events werden angestossen
 */
$().ready(function() {
    // Cookies auslesen und Frontendbereiche laden
    initToolbox(); 
    // Events setzen
    $("a.addClipboard").click(function(){addClipboard($(this));this.blur();return false;}); 
    $("a.addMerkzettel").click(function(){addMerkzettel($(this));return false;}); 
    //$("a.addDownload").click(function(){addDownload($(this));return false;}); 
    $("a.addJob").click(function(){addJob($(this));return false;}); 
   
    $(".clipboardlist a.removeMe").click(function(){removeFromClipboard($(this));return false;});
    //$(".downloadlist a.removeMe").click(function(){removeFromDownload($(this));return false;});
    $(".merklist a.removeMe").click(function(){removeFromMerkzettel($(this));return false;});
    $(".joblist a.removeMe").click(function(){removeFromJoblist($(this));return false;});
    
    //$("a.removeDownloads").click(function(){ removeAllDownloads();return false;});
    $("a.removeMerkzettel").click(function(){removeMerkzettel();return false;});
    
    //$("a.sendDownload").click(function(){if(sendIds[1]!=""){sendRequest($(this));}return false;}); 
    $("a.sendClipboard_compare").click(function(){if(sendIds[0]!=""){sendRequest($(this));}return false;}); 
    $("a.sendClipboard_offer").click(function(){if(sendIds[0]!=""){sendRequest($(this));}return false;}); 
    $("a.sendJoblist").click(function(){if(sendIds[3]!=""){sendRequest($(this));}return false;});
    $("a.applyJoblist").click(function(){if(sendIds[3]!=""){sendRequest($(this));}return false;}); 
    
    // Bookmarkingfunktion
    $(".bookmark").click(function(){draeger.bookmark();return false;});    
});




