function init(e) {
	
	/* Contenthöhe anpassen (falls rechte Spalte über Contentbereich hinausgeht) */
	var cBereich = document.getElementById('contentBereich');
	var cRight =   document.getElementById('contentRight');
	var cLeft =   document.getElementById('contentLeft');
	
	var cBereichHeight = YAHOO.util.Dom.getRegion(cBereich).bottom - YAHOO.util.Dom.getRegion(cBereich).top;
	var cRightHeight =   YAHOO.util.Dom.getRegion(cRight).bottom - YAHOO.util.Dom.getRegion(cRight).top;
	var cLeftHeight =   YAHOO.util.Dom.getRegion(cLeft).bottom - YAHOO.util.Dom.getRegion(cLeft).top;
	
	if (cRightHeight >= cLeftHeight){
		if (cRightHeight >= cBereichHeight) {
			cBereichHeight = cRightHeight + 24;
			document.getElementById('contentBereich').style.height = cBereichHeight+"px";			
		}
	}
	else 
	{
		if (cLeftHeight >= cBereichHeight) {
			cBereichHeight = cLeftHeight + 24;
			document.getElementById('contentBereich').style.height = cBereichHeight+"px";			
		}	
	}
	
	
	
	// nötig für Detail-Einblendungen
	// blendet Details-Link ein/aus
	var accOLink = YAHOO.util.Dom.getElementsByClassName("accOpener","a");	
	YAHOO.util.Event.addListener(accOLink,"click",hideOpener);
	
	var accCLink = YAHOO.util.Dom.getElementsByClassName("accCloser","a");	
	YAHOO.util.Event.addListener(accCLink,"click",showOpener);

	function hideOpener(){
		this.style.display="none";
	}
	
	function showOpener(){
		var curaccOLink = YAHOO.util.Dom.getElementsByClassName("accOpener","a",this.parentNode.parentNode.parentNode);	
		var curOpener = curaccOLink[0];
		curOpener.style.display="block";
	}
	
	/* Address Search Prefill Start*/
	YAHOO.util.Event.addListener('searchterm',"click", clearInput);
	
	YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('radioSearch'),"click", changeInput);
	
	function clearInput(){
		YAHOO.util.Dom.removeClass(this, 'fresh');
		this.value = "";
	}
	
	function changeInput(){
		YAHOO.util.Dom.get('searchtermLabel').innerHTML = YAHOO.util.Dom.getFirstChild(this).alt ;
	}	
	/* Address Search Prefill End*/
	
	
	showCalendar();
	showToolTip();
	dealerLocatorPreset();
	//Yuibox initialisieren/öffnen
	YAHOO.namespace("kittelberger.yuibox");
	/*
 YAHOO.util.Event.addListener(window, 'scroll',  
     function(){  
        fixAS();  
       }  
	);
	*/ 	
}

function fixAS(){
    // Get the document scroll TOP position  
    var sfS = YAHOO.util.Dom.getDocumentScrollTop();  
    // Get the document ViewPort size - subtract the footer size then add the scroll top position  
    var sfH = YAHOO.util.Dom.getViewportHeight() - 37 + sfS;  
    // Note if you are dealing with an element that is smaller than 100% of the document viewport  
    // add calculations for the getViewportWidth() for horizonal scrolling detection  

    // Here we set the style properties of the footer  
    //YAHOO.util.Dom.setStyle('contentRight','top',sfS+'px');  

    var attributes = {
        top: { to: sfS }
    };

    var anim = new YAHOO.util.Anim('contentRight', attributes, 0.5, YAHOO.util.Easing.easeOut); 

    anim.animate(); 
     
}


function openYuiBox(frameSrc)
{
	var globalWidth = "600px";
	var globalHeight = "480px";
	
	var suche = globalHeight.indexOf("px");
	globalHeight=globalHeight.substring(0, suche);
	z=Number(globalHeight);

	//iefix
	if (navigator.appName=="Microsoft Internet Explorer")z+=3;
	
	globalHeight=""+z+"px";

	YAHOO.kittelberger.yuibox.box = new YAHOO.widget.Panel("yuiBox",
										{
											width: globalWidth,
											height: globalHeight,
											fixedcenter: true,
											close: false,
											draggable: false,
											zindex:999,
											modal: true,
											visible: false
										}
									);

		YAHOO.kittelberger.yuibox.box.setBody("<iframe frameborder='0' name='yuiBox' id='yuiBox' src='"+frameSrc+"' style='width:"+globalWidth+";height:"+globalHeight+";border:0px none;'></iframe><div id='schliessen'><a href='javascript:closeYB()'>close</a></div>");
		YAHOO.kittelberger.yuibox.box.render(document.body);
		YAHOO.kittelberger.yuibox.box.show();

		// Thickbox schließt auch, wenn man in die Maske klickt
		var bgMask = document.getElementById("yuiBox_mask");
		YAHOO.util.Event.addListener(bgMask,"click",closeYB);	
		
		
		
		// Größe der Thickbox-Maske und des Bodys anpassen, wenn sich die Browsergröße ändert
		YAHOO.util.Event.on(window,'resize',aktBodySize);
}


//Yuibox schließen
function closeYB(reloadPage)
{
	if(reloadPage) window.location.reload();
	else{
		YAHOO.kittelberger.yuibox.box.hide();
		YAHOO.kittelberger.yuibox.box.destroy();
	}
}




// verhindert, dass der Browser Scrollbalken anzeigt, wenn eine Thickbox geöffnet ist und die Browsergröße verändert wird
function aktBodySize(){
	
	var myBody = document.getElementsByTagName('body')[0];
	var ybMask = document.getElementById("yuiBox_mask");
	
	myBody.style.width = YAHOO.util.Dom.getViewportWidth(); 
	myBody.style.height = YAHOO.util.Dom.getViewportHeight();
	
	if(ybMask){
		ybMask.style.width = YAHOO.util.Dom.getViewportWidth(); 
		ybMask.style.height = YAHOO.util.Dom.getViewportHeight();
	}
}

function switchTo(tab){
	var DivsTab1 = YAHOO.util.Dom.getElementsByClassName('tab1');
	var DivsTab2 = YAHOO.util.Dom.getElementsByClassName('tab2');
	
	if(tab == 'tab2'){
		YAHOO.util.Dom.setStyle(DivsTab2, 'display', 'block');
		YAHOO.util.Dom.setStyle(DivsTab1, 'display', 'none');  
		YAHOO.util.Dom.replaceClass('tab2', 'inactive','active');
		YAHOO.util.Dom.replaceClass('tab1', 'active','inactive');
	}else{
		YAHOO.util.Dom.setStyle(DivsTab2, 'display', 'none');
		YAHOO.util.Dom.setStyle(DivsTab1, 'display', 'block');
		YAHOO.util.Dom.replaceClass('tab1', 'inactive','active');
		YAHOO.util.Dom.replaceClass('tab2', 'active','inactive');		
		}
	 
	}

/*
function reuseData(el1,el2,el3){
    document.getElementById(el1+'_workshop').value = document.getElementById(el1).value;
    document.getElementById(el2+'_workshop').value = document.getElementById(el2).value;
    document.getElementById(el3+'_workshop').value = document.getElementById(el3).value;
}
*/

function reuseData( adress, zip, city, country, service, lang )
{
    var cityValue      = document.mail.city.value;
    var adressValue  = document.mail.adress.value;
    var zipValue      = document.mail.zip.value;
       
    var searchIn = ( zipValue.length > 2 ? 'ZIP' : 'CITY' );
    var searchPhrase = ( searchIn == 'ZIP' ? zipValue : cityValue );

    var popup = window.open( '/bosch/aa/garagelocator/index.cfm/search/map/quick?baw=1&group=CAR_SERVICE&searchIn=' + searchIn + '&searchPhrase=' + searchPhrase + '&locale=' + lang +'_' + country, "book_a_ws_address", "width=900,height=593,left=100,top=200" );
        popup.focus();
}




function showCalendar(){
    var Event = YAHOO.util.Event,
    Dom = YAHOO.util.Dom,
    dialog,
    calendar;
    if(typeof(calDaysToDate) == 'undefined'){
        calDaysToDate = 1;
    }
    var date = new Date();
    dateInMS = date.getTime();
    newStartDate = parseInt(dateInMS) + parseInt(calDaysToDate * 86400000)
    date.setTime(newStartDate);
    var year = date.getFullYear();
    var month = date.getMonth()+1;
    var day = date.getDate();
    newMinDate = month+"/"+day+"/"+year;
    newMaxDate = month+"/"+day+"/"+(year+parseInt(1));
    //var showBtn = Dom.get("calender");openCal
    var showBtn = Dom.get("openCal");

    Event.on(showBtn, "click", function() {
        // Lazy Dialog Creation - Wait to create the Dialog, and setup document click listeners, until the first time the button is clicked.
        if (!dialog) {

            // Hide Calendar if we click anywhere in the document other than the calendar
            Event.on(document, "click", function(e) {
                var el = Event.getTarget(e);
                var dialogEl = dialog.element;
                if (el != dialogEl && !Dom.isAncestor(dialogEl, el) && el != showBtn && !Dom.isAncestor(showBtn, el)) {
                    dialog.hide();
                }
            });
            function resetHandler() {   
                // Reset the current calendar page to the select date, or
                // to today if nothing is selected.
                var selDates = calendar.getSelectedDates();
                var resetDate;

                if (selDates.length > 0) {
                    resetDate = selDates[0];
                } else {
                    resetDate = calendar.today;
                }

                calendar.cfg.setProperty("pagedate", resetDate);
                calendar.render();
            }
            function closeHandler() {
                dialog.hide();
            }
            dialog = new YAHOO.widget.Dialog("container", {
                                                            visible:false,
                                                            context:["calender", "tl", "tr"],
                                                            buttons:[ {text:"Reset", 
                                                                        handler: resetHandler, 
                                                                        isDefault:true
                                                                      }, 
                                                                      {text:"Close", handler: closeHandler}
                                                                    ],
                                                            draggable:false,
                                                            close:true
            });
            //dialog.setHeader(calDate);
            dialog.setBody('<div id="cal"></div>');
            dialog.render(document.body);
            dialog.showEvent.subscribe(function() {
                if (YAHOO.env.ua.ie) {
                    // Since we're hiding the table using yui-overlay-hidden, we
                    // want to let the dialog know that the content size has changed, when
                    // shown
                    dialog.fireEvent("changeContent");
                }
            });
        }
        // Lazy Calendar Creation - Wait to create the Calendar until the first time the button is clicked.
        if (!calendar) {
            // Enable navigator with a custom configuration
            var navConfig = {
                             monthFormat: YAHOO.widget.Calendar.LONG,
                             LOCALE_WEEKDAYS:"short",
                             initialFocus: "year"
            };
            calendar = new YAHOO.widget.Calendar("cal", {
                iframe:false,          // Turn iframe off, since container has iframe support.
                navigator: navConfig,
                mindate: newMinDate,
                maxdate: newMaxDate,
                hide_blank_weeks:true  // Enable, to demonstrate how we handle changing height, using changeContent
            });
            //calendar.cfg.setProperty("MONTHS_LONG",    [calJan, calFeb, calMar, calApr, calMay, calJun, calJul, calAug, calSep, calOct, calNov, calDec]);
            //calendar.cfg.setProperty("WEEKDAYS_SHORT", [calSu, calMo, calTu, calWe, calTh, calFr, calSa]);
            calendar.render();
            calendar.selectEvent.subscribe(function() {
                if (calendar.getSelectedDates().length > 0) {
                    var selDate = calendar.getSelectedDates()[0];
                    // Pretty Date Output, using Calendar's Locale values: Friday, 8 February 2008
                    //var wStr = calendar.cfg.getProperty("WEEKDAYS_LONG")[selDate.getDay()];
                    var dStr = selDate.getDate();
                    var mStr = selDate.getMonth()+1;
                    var yStr = selDate.getFullYear();
                    //Datum muss immer 2stellig sein, damit es in der DB gespeichert wird.
                    if(dStr < 10){
                        dStr = '0' + dStr;
                    }
                    if(mStr < 10){
                        mStr = '0' + mStr;
                    }
                    Dom.get("calenderInput").value =dStr + "." + mStr + "." + yStr;
                } else {
                    Dom.get("calenderInput").value = "";
                }
                dialog.hide();
            });
            calendar.renderEvent.subscribe(function() {
                // Tell Dialog it's contents have changed, which allows
                // container to redraw the underlay (for IE6/Safari2)
                dialog.fireEvent("changeContent");
            });
        }
        var seldate = calendar.getSelectedDates();
        if (seldate.length > 0) {
            // Set the pagedate to show the selected date if it exists
            calendar.cfg.setProperty("pagedate", seldate[0]);
            calendar.render();
        }

        dialog.show();
    });
}

function showToolTip(){
	//Tooltip Start
    // Obtain an array of the links in Group B
    var groupBIds = YAHOO.util.Dom.getElementsByClassName('tooltip');
    // For links in group B, we'll set the tooltip text dynamically,
    // right before the tooltip is triggered, using the id of the triggering context.
    var ttB = new YAHOO.widget.Tooltip("ttB", {
        context:groupBIds,
		hidedelay: 5000,		
		effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.20}
	
    });
	
    // Set the text for the tooltip just before we display it.
    ttB.contextTriggerEvent.subscribe(
		function(type, args) {
			var posXY = this.cfg.getProperty("xy");
			var height = this.cfg.getProperty("height");
			
			//neue Position 25px nach links und 20px nach oben, damit der Pfeil auf dem Link liegt
			this.cfg.setProperty('xy',[YAHOO.util.Dom.getX(args)-220, posXY[1]-40]);

            var context = args[0];
			var text = YAHOO.util.Dom.getNextSibling(context).innerHTML; 

            this.cfg.setProperty("text", text);
			//Funktion für die Links im Tooltip:
			YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('garageSelectors'),"click", showToolTip);
			YAHOO.util.Event.addListener(YAHOO.util.Dom.getElementsByClassName('garageSelectors'),"click", submitGarage);
        }
    );
	//Tooltip End
}

function submitGarage(){

	YAHOO.util.Dom.get('selectedType').innerHTML = this.innerHTML;
	YAHOO.util.Dom.get('group').value = this.rel;
}

function dealerLocatorPreset(){
	var meta = document.getElementsByTagName("META");
	for(i=0; i< meta.length; i++){
		/* Liest anhand der MetaInformationen der Seite die aktuelle Unit aus und setzt diese in das Suchformular ein. */
		if(meta[i].name == 'DCSext.wtg_bu'){
			var buLong;
			var buShort;
			var wtg_bu = meta[i].content;
			
			switch (wtg_bu) {
			  case "BOS":
				buLong = 'Select all';
				buShort = 'ALL';
				break;
			  case "BCS":
				buLong = 'Bosch Car Service';
				buShort = 'CAR_SERVICE';
				break;
			  case "BDS":
				buLong = 'Bosch Diesel Service';
				buShort = 'DIESEL_SERVICE';
				break;
			  case "BDC":
				buLong = 'Bosch Diesel Center';
				buShort = 'DIESEL_CENTER';
				break;
			  default:
				buLong = 'Select all';
				buShort = 'ALL';
				break;
			}
			if(YAHOO.util.Dom.inDocument('bsSearch')){
				YAHOO.util.Dom.get('selectedType').innerHTML = buLong;
				YAHOO.util.Dom.get('group').value = buShort;			
			}
		}
	}
}

function openSearch(e){
	window.open( "about:blank", "popup", "toolbar=no,width=900,height=593,resizable=yes,top=40,scrollbars=no" );
	document.getElementById(e).target= "popup";				
	return true;
}

/**
*******************************************************************************
**
**  die Breite auf 900 geaendert, wegen dreispaltiges "Search our Services"
**
*******************************************************************************
*/

function openExtSearch(e){
	window.open( e.href, "popup", "toolbar=no,width=900,height=593,resizable=yes,top=40,scrollbars=no" );
	return false;
}	


YAHOO.util.Event.onContentReady("footerBereich",init);

