
var bubble = false;
var plzvalue = '';

    function mapHighlight(land) {
        document.getElementById('worldmap').src='/shared/img/filialsuche/worldmap_' + land + '.jpg'
    }
    function mapOver(land) {
        document.getElementById('worldmap').src='/shared/img/filialsuche/worldmap_' + land + '.jpg'
        over[land]  = window.setTimeout("document.getElementById('bubble" + land + "').style.display = 'block';", 1);
        document.getElementById('bubble' + LandChoice).style.display = 'none';
    }
    function mapOut(land) {
		if (over[land]) window.clearTimeout(over[land]);
        if (land != LandChoice)
        {
            document.getElementById('bubble' + land).style.display = 'none';
			document.getElementById('bubble' + LandChoice).style.display = 'block';
            document.getElementById('worldmap').src='/shared/img/filialsuche/worldmap_' + LandChoice + '.jpg'
        }
    }

    function selectMap(land) {
         LandChoice = land;
		document.getElementById('LAND').value = land;
        if (anzahl_filialen[land] >=  10) {
			document.getElementById('plz').value = plzeingabe;
            document.getElementById('plz').style.display = 'block';
			document.getElementById('show').style.display = 'block';
        }
        else {
			document.getElementById('plz').value = "";
			plzscrollpos = -1;
			document.getElementById('suggestions').style.display = 'none';
            document.getElementById('plz').style.display = 'none';
			document.getElementById('show').style.display = 'none';
		}
		plzSuche(); //document.getElementById('filialsucheergebnis').innerHTML = '';
    }

    function plzInput() {
        //if (document.getElementById('plz').value == plzeingabe) {
            document.getElementById('plz').value = '';
        //}
    }
    function plzBlur() {
		if (suggest_active == false) {
            plzscrollpos = -1;
			if (document.getElementById('plz').value == '') {
				document.getElementById('plz').value = plzeingabe;
			}
			document.getElementById('suggestions').style.display = 'none';
		}
    }
    function plzEnter(eingabe) {
		if (eingabe != 13)
		{
			var data = document.getElementById('plz').value;
			if (data.length < plzvalue.length && plzscrollpos == -1) {
				//document.getElementById('suggestions').style.display = 'none';
			}
			if (data != "" && plzscrollpos == -1) {
				filialsucherequest(data);
			}
			plzvalue = data;
		}
		else return false;
    }

	var details_on = new Array;
	var tbldisplay = navigator.userAgent.indexOf('MSIE') == -1 ? 'table-row' : 'inline';
    function showDetails(which) {
		details_on[which] = true;
        if (document.getElementById('treffershow' + which).src.indexOf('plus') != -1) {
            document.getElementById('treffershow' + which).src = '/shared/img/minus.gif';
/*
			document.getElementById('trefferplz' + which).style.borderBottom = 'none';
			document.getElementById('trefferstr' + which).style.borderBottom = 'none';
			document.getElementById('trefferspacer' + which).style.borderBottom = 'none';
			document.getElementById('trefferweg' + which).style.borderBottom = 'none';
			document.getElementById('trefferrechts' + which).style.borderBottom = 'none';
*/
			document.getElementById('filialedetail' + which).style.display = tbldisplay;

        }
        else {
            document.getElementById('treffershow' + which).src = '/shared/img/plus.gif';
			details_on[which] = false;

			document.getElementById('filialedetail' + which).style.display = 'none';

/*
			if (which != document.getElementById('anzahlFilialen').innerHTML) {
				document.getElementById('trefferplz' + which).style.borderBottom = '1px solid #e8e9ef';
				document.getElementById('trefferstr' + which).style.borderBottom = '1px solid #e8e9ef';
				document.getElementById('trefferspacer' + which).style.borderBottom = '1px solid #e8e9ef';
				document.getElementById('trefferweg' + which).style.borderBottom = '1px solid #e8e9ef';
				document.getElementById('trefferrechts' + which).style.borderBottom = '1px solid #e8e9ef';
			}
*/
        }
    }
	function filialeHover(which) {
		if (details_on[which] != true) {
			document.getElementById('filialekurz' + which).style.backgroundImage = 'url(/shared/img/filialsuche/verlauf_ergebnis.gif)';
		}
	}
	function filialeEndHover(which) {
		if (details_on[which] != true  && document.getElementById('anzahlFilialen').innerHTML != 1) {
			//document.getElementById('filialekurz' + which).style.backgroundImage = 'url(/shared/img/grau.gif)';
			//document.getElementById('filialekurz' + which).style.backgroundImage = 'url(/shared/img/grau.gif)';
			document.getElementById('filialekurz' + which).style.backgroundImage = 'none';

			//document.getElementById('filialekurz' + which).style.backgroundImage = 'none';
            //document.getElementById('filialekurz' + which).style.borderTop = '1px solid #e8e9ef';
			/*
			document.getElementById('trefferplz' + which).style.backgroundImage = 'none';
			document.getElementById('trefferstr' + which).style.backgroundImage = 'none';
			document.getElementById('trefferspacer' + which).style.backgroundImage = 'none';
			document.getElementById('trefferpdf' + which).style.backgroundImage = 'none';
			*/
		}
	}

    // globale Instanz von XMLHttpRequest
    var xmlHttp = false;

    // XMLHttpRequest-Instanz erstellen
    // ... für Internet Explorer
    try {
        xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        try {
            xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
        } catch(e) {
            xmlHttp  = false;
        }
    }
    // ... für Mozilla, Opera und Safari
    if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') {
        xmlHttp = new XMLHttpRequest();
    }


    var suggest_active = false;
	function filialsucherequest(begriff) {
      if (xmlHttp) {
         begriff = encodeURIComponent(begriff);
         xmlHttp.open('GET', '/?action=filialen::livesuche&land='+ LandChoice + '&suche=' + begriff + '&lang='+lang, true);
         xmlHttp.onreadystatechange = function () {
             if (xmlHttp.readyState == 4) {
                result = xmlHttp.responseText;
                if (result != "") {
                    document.getElementById('suggestions').style.display = 'block';
                    document.getElementById('suggestions').innerHTML = result;
                }
                else {
                    document.getElementById('suggestions').style.display = 'none';
                }
             }
         };
         xmlHttp.send(null);
      }
    }

	var plzscrollpos = -1;
	var bgHighlight = '#000000';
	var bgOff = '#ffffff';
	var cHighlight = '#ffffff';
	var cOff = '#000000'
	function plzkeydown(eingabe) {
		if (eingabe == 40 && plzscrollpos < document.getElementById('suggestions').childNodes.length -1) {
			plzscrollpos += 1;
			if (document.getElementById('suggestions').style.display == 'block') {
			    //alert(document.getElementById('suggestions').childNodes[plzscrollpos].nodeValue);
			    res = document.getElementById('suggestions').childNodes[plzscrollpos].innerHTML.replace(/^([0-9]{1,5}).*/g, "$1");
			    res = res.replace(/( \([0-9]{1,5} [\wóÜü]*\))$/, "");
				document.getElementById('plz').value = res;
				document.getElementById('suggestions').childNodes[plzscrollpos].style.color = '#ffffff';
				document.getElementById('suggestions').childNodes[plzscrollpos].style.backgroundColor = '#000000';
				if (plzscrollpos >= 1) {
					document.getElementById('suggestions').childNodes[plzscrollpos - 1].style.color = '#000000';
					document.getElementById('suggestions').childNodes[plzscrollpos - 1].style.backgroundColor = '#ffffff';
				}
			}
		}
		else if (eingabe == 38) {
			// hoch
			plzscrollpos -= 1;
			if (plzscrollpos >= 0) {
				if (document.getElementById('suggestions').style.display == 'block') {
					res = document.getElementById('suggestions').childNodes[plzscrollpos].innerHTML.replace(/^([0-9]{1,5}).*/g, "$1");
     			    res = res.replace(/( \([0-9]{1,5} [\wóÜü]*\))$/, "");
					document.getElementById('plz').value = res;
					document.getElementById('suggestions').childNodes[plzscrollpos].style.color = cHighlight;
					document.getElementById('suggestions').childNodes[plzscrollpos].style.backgroundColor = bgHighlight;
					document.getElementById('suggestions').childNodes[plzscrollpos + 1].style.color = cOff;
					document.getElementById('suggestions').childNodes[plzscrollpos + 1].style.backgroundColor = bgOff;
				}
			} else {
				document.getElementById('suggestions').childNodes[plzscrollpos + 1].style.color = cOff;
				document.getElementById('suggestions').childNodes[plzscrollpos + 1].style.backgroundColor = bgOff;
			}
		}
		else if (eingabe == 13) {
			// enter
           plzscrollpos -= 1;
			document.getElementById('suggestions').style.display = 'none';
			suggest_active = false;
			plzSuche();
			return false;
		}
	}
	function spanOn(which) {
		suggest_active = true;
		document.getElementById(which).style.color = cHighlight;
		document.getElementById(which).style.backgroundColor = bgHighlight;
	}
	function spanOff(which) {
		suggest_active = false;
		document.getElementById(which).style.color = cOff;
		document.getElementById(which).style.backgroundColor = bgOff;
	}
	function suggestPLZ(suche) {
		
		document.getElementById('plz').value = suche;
		document.getElementById('suggestions').style.display = 'none';
		suggest_active = false;
		plzscrollpos = -1;
	}

	var webtrekkurl_1 = "http://track.webtrekk.de/559909586779207/wt.pl?p=165,";
	var webtrekkurl_2 = "&amp;ov=&amp;cr=&amp;oi=&amp;ba=&amp;co=&amp;qn=&amp;ca=&amp;pi=&amp;st=&amp;cd=&amp;cg=";
    function plzSuche(seite) {
//		if ( (document.getElementById('plz').value != plzeingabe && document.getElementById('plz').value != "") || (LandChoice != "de") ) {

		  document.getElementById('contentRechtsBreit').style.display = "none";	
		  document.getElementById('contentMainSchmal').style.height = "100%";	
	
		  begriff = anzahl_filialen[LandChoice] >= 10 ? document.getElementById('plz').value : "";
		  begriff = begriff == plzeingabe ? "" : begriff;

		  LandChoice = document.getElementById('LAND').value;
		  
		  if (xmlHttp) {
			 begriff = encodeURIComponent(begriff);
			 /* alert ('/?action=filialen_uk::suche&land='+ LandChoice + '&suche=' + begriff + '&seite=' + seite + '&lang=' + lang);*/
			 xmlHttp.open('GET', '/?action=filialen::suche&land=' + LandChoice + '&suche=' + begriff + '&seite=' + seite + '&lang=' + lang, true);
			 
			 
			 //document.getElementById('webtrekkpix').src = webtrekkurl_1 + 'filialen.suche.' + LandChoice + '.' + begriff.toLowerCase() + webtrekkurl_2;
			 //alert(webtrekkurl_1 + 'filialen.suche.' + begriff.toLowerCase() + webtrekkurl_2);
			
			 xmlHttp.onreadystatechange = function () {
				 if (xmlHttp.readyState == 4) {
					result = xmlHttp.responseText;
					if (result != "") {
						document.getElementById('filialsuche').innerHTML = xmlHttp.responseText;
					}
					else {

					}
				 }
			 };
			 xmlHttp.send(null);
		  }

	}

	function zeigeFiliale(filiale, plz, land) {
		  if (xmlHttp) {
			 xmlHttp.open('GET', '/?action=filialen::suche&land='+ land + '&suche=' + plz + '&prio=' + filiale + '&lang=' + lang, true);
			 xmlHttp.onreadystatechange = function () {
				 if (xmlHttp.readyState == 4) {
					result = xmlHttp.responseText;
					if (result != "") {
						document.getElementById('filialsucheergebnis').innerHTML = xmlHttp.responseText;
					}
					else {

					}
				 }
			 };
			 xmlHttp.send(null);
		  }
	}
	function aktionenHover(which) {
		if (document.getElementById(which+ 'show').src.indexOf('plus') != -1) {
			document.getElementById(which+ 'top').style.backgroundImage = 'url(/shared/img/filialsuche/verlauf_ergebnis.gif)';
		}
	}
	function aktionenEndHover(which) {
		if (document.getElementById(which+ 'show').src.indexOf('plus') != -1) {
			document.getElementById(which+ 'top').style.backgroundImage = 'none';
			//if (which != aktionen_last) document.getElementById(which+ 'top').style.borderBottom = '1px solid rgb(232, 233, 239)';
		}
	}
	function showAktion(which) {
		if (document.getElementById(which+ 'show').src.indexOf('plus') != -1) {
			document.getElementById(which+ 'show').src = "/shared/img/minus.gif";
			document.getElementById(which+ 'top').style.backgroundImage = 'url(/shared/img/filialsuche/verlauf_ergebnis.gif)';
			//document.getElementById(which+ 'top').style.borderBottom = 'none';
			document.getElementById(which+ 'detail').style.display = tbldisplay;
		}
		else {
			document.getElementById(which+ 'show').src = "/shared/img/plus.gif";
			document.getElementById(which+ 'top').style.backgroundImage = 'none';
			//if (which != aktionen_last) document.getElementById(which+ 'top').style.borderBottom = '1px solid rgb(232, 233, 239)';
			document.getElementById(which+ 'detail').style.display = 'none';
		}
	}

	function teaseraktiv(which) {
		teaseractive = which;
		document.getElementById(which).src = '/' + lang + '/filialen/' + which + '_over.gif';
		document.getElementById('filialbild1').src = '/de/filialen/filialbilder/' + which + '1.jpg';
		document.getElementById('filialbild2').src = '/de/filialen/filialbilder/' + which + '2.jpg';
		document.getElementById('filialbild3').src = '/de/filialen/filialbilder/' + which + '3.jpg';

	}
	function teaserhover(which) {
		if (which != teaseractive)
		{
			document.getElementById(which).src = '/' + lang + '/filialen/' + which + '_over.gif';
			document.getElementById(teaseractive).src = '/' + lang + '/filialen/' + teaseractive + '.gif';
		}
	}
	function teaserout(which) {
		if (which != teaseractive)
		{
			document.getElementById(which).src = '/' + lang + '/filialen/' + which + '.gif';
			document.getElementById(teaseractive).src = '/' + lang + '/filialen/' + teaseractive + '_over.gif';
		}
	}
	function teaserpopup(nr) {
		
		mypage = "/?action=filialen::teaserpopup&stadt=" + teaseractive + "&nr=" + nr + "&lang=" + lang;


		w = 720;
		h  = 600;

		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;

		var settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';

		var tp = window.open('','Popup',settings);
        tp.focus();
		tp.location=mypage;

		/*
		document.getElementById('teaserpopupimage').src = '/de/filialen/filialbilder/' + teaseractive + '_detail_' + nr + '.jpg';
		document.getElementById('teaserpopuptext').innerHTML = teaseractive + ' ' + nr;
		document.getElementById('teaserpopup').style.display = 'block';
		*/
	}
	var urls = new Object;
	urls['hamburg'] = 'filialen,00,filialsuche,id,01,53,stadt,01,Hamburg.html';
	urls['muenchen'] = 'filialen,00,filialsuche,id,01,51,stadt,01,München.html';
	urls['dortmund'] = 'filialen,00,filialsuche,id,01,30,stadt,01,Dortmund.html';
	urls['karlsruhe'] = 'filialen,00,filialsuche,id,01,50,stadt,01,Karlsruhe.html';
	urls['wien'] = 'filialen,00,filialsuche,id,01,116,stadt,01,Wien.html';
	urls['warschau'] = 'filialen,00,filialsuche,id,01,72,stadt,01,Warszawa.html';
	urls['bratislava'] = 'filialen,00,filialsuche,id,01,209,stadt,01,Bratislava.html';
	urls['prag'] = 'filialen,00,filialsuche,id,01,205,stadt,01,Praha.html';

	function showinfo() {
		window.location.href = urls[teaseractive];
	}
	
	function showPopup(url, w, h) {

		mypage = url;

		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;

		var settings='width='+ w + ',height='+ h + ',top=' + TopPosition + ',left=' + LeftPosition + ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=no,dependent=no';

		var tp = window.open('','Popup',settings);
        tp.focus();
		tp.location=mypage;

		/*
		document.getElementById('teaserpopupimage').src = '/de/filialen/filialbilder/' + teaseractive + '_detail_' + nr + '.jpg';
		document.getElementById('teaserpopuptext').innerHTML = teaseractive + ' ' + nr;
		document.getElementById('teaserpopup').style.display = 'block';
		*/
	}
