/*
	JavasScript fuer www.bielefeld.de
*/

/* jQuery Funktionen */


		var tQ;
		var isIE6 = false;
		var isBB = false; // BlackBerry
		if ($.browser.msie && $.browser.version=="6.0") isIE6 = true;
		if (navigator.userAgent.toLowerCase().search("blackberry") > -1) isBB = true;

		
		function showQuickfinder() {
			clearTimeout(tQ);
			$("#quickfinder").show();
			$("#quickfinderlink").addClass("aktiv");
			// $("#quickfinder a:first").focus();
			var rmpos = $("#rightmenu").position();
			$("#quickfinder").css( { 
				'position': 'fixed',
                'left': (rmpos.left - $('#quickfinder').width() - 20), 
                'top': rmpos.top
            } );
			//if (isIE6) {
			//	alert("qf-pos: " + (rmpos.left - $('#quickfinder').width()) + ", " + rmpos.top);
			//}
		}
		function hideQuickfinder() {
			clearTimeout(tQ);
			$("#quickfinder").hide();
			$("#quickfinderlink").removeClass("aktiv");
			// $("#quickfinderlink a:first").focus();
		}
		function delayQuickfinder() {
			tQ = setTimeout(function(){ hideQuickfinder(); }, 2000); // adjust your time here			
		}
		
		function showKopfblock(kopfblockname) {
			var block = $("#"+kopfblockname);
			var rmpos = $("#rightmenu").position();
			block.css( { 
                left: rmpos.left, 
                top: rmpos.top
            } );
			block.show();
			// alert( "left: " + position.left + ", top: " + position.top );
		}
		
		$(document).ready(function() {

			/* PNG-Fix fuer alten IE */
			$(document).pngFix(); 
		
			/* 	Kalender-Popup fuer Datumsfelder 
			*	http://docs.jquery.com/UI/API/1.8/Datepicker */
			$.datepicker.setDefaults( $.datepicker.regional[ "'.$lang.'" ] );
			// $( "#datepicker" ).datepicker( $.datepicker.regional[ "de" ] );
			$("input.datepicker").datepicker({
				dateFormat: "dd.mm.yy",
				buttonImage: "/images/btn_kalender.png",
				buttonImageOnly: true,
				buttonText: "Kalender",
				showOn: "both"
			});

			/*  Schriftgroesse auf Seite einstellen 
			*	http://cubed.paperplanesdesign.com/Font-Resizer/fontResizer.html */	
			// $(".content, .resizeMe, .resizeSpan").fontResizer({sizeType:'%',minFont:80,maxFont:140,increment:20});
			$(".content, .textblock").fontResizer({sizeType:'px',minFont:13.3,maxFont:18,increment:1});
			
			/* Inhalt der Seite min. auf Hoehe des Fensters erweitern */
			if (! isIE6 && ! isBB) {
				$('#left').css({'min-height':( ($(window).height()) - ($('#footer').height()) - 5 )+'px'});
			}
			// $('#container').css({'height':( ($(window).height()) - 5 )+'px'});

			// alert(';-)');
			
			//if ($.browser.msie && $.browser.version=="6.0") { // Hoehenangabe bei IE 6 per "height"
			//	$('#left').css({'height':( ($(window).height()) - ($('#footer').height()) - 5 )+'px'});
			//}
						
			/* Links in der App-Navigation entfernen, wenn JS aktiv */
			$('.kopfblocklink').attr('href', 'javascript:void(0)');
			
			
			// $('.kopfblock').show(function () { $(this).focus(); });
			
			
			/* offene Kopfbloecke schliessen, wenn anderer Kopfblock-Link geklickt wird. */
			$('.kopfblocklink').mousedown(function(){ $('.kopfblock').hide(); hideQuickfinder(); });
			
			/* Kopfblock-Bereiche schliessen, wenn ausserhalb geklickt wird */
			mouse_is_inside_kopfblock = false; 
			$('.kopfblock, .ui-datepicker, .kopfblocklink').hover(function(){ 
				mouse_is_inside_kopfblock=true; 
			}, function(){ 
				mouse_is_inside_kopfblock=false; 
			});
			if (! $.browser.msie) {  // IE schliesst sonst bei Auswahl aus Select-List den Block?!
				$('html').mouseup(function(){ 				
					if(! mouse_is_inside_kopfblock) {
						$('.kopfblock').hide();
						hideQuickfinder();
					}
				});
			}
			
			$('html').keypress(function(event) {  // per Escape-Taste auch schliessen
				// alert ("key " + event.keyCode);
				if (event.keyCode == '27') { 	
					$('.kopfblock').hide(); 
					hideQuickfinder();
				}
			});

			/* Quickfinder (Schnellsuche) ein-/ausblenden */
            // $("#quickfinder, #quickfinderlink").mouseout( function() { delayQuickfinder(); 	});
            $(" #quickfinderlink, #quickfinder").mouseleave( function() { delayQuickfinder(); 	});
			// $("#quickfinderlink").mouseover( function() { showQuickfinder();   });
            $("#quickfinderlink").click( function() { showQuickfinder();   });
            $("#quickfinder, #quickfinderlink a").mouseenter( function(){ showQuickfinder(); });
			
			// $("body").css( {	paddingRight: '220px'	});
		});

		$(window).resize(function() {						
			/* Position Kopfblock korrigieren */
			var block = $(".kopfblock");
			var rmpos = $("#rightmenu").position();
			block.css( { 
                left: rmpos.left, 
                top: rmpos.top
            } );
			
			/* Inhalt der Seite min. auf Hohe des Fensters erweitern */
			if (! isIE6 && ! isBB) {
				$('#left').css({'min-height':( ($(window).height()) - ($('#footer').height()) - 5 )+'px'});
			}

		});


// Bilder fuer Webcams neu laden (mit Zeitstempel als Parameter, damit der Cache nicht aktiv werden kann)
function bildneuladen(bildid ) {
	src = String($(bildid).attr('src'));
	if (src.indexOf('?') > 0) {
		src = src.substring(0, (src.indexOf('?')));
	}
	$(bildid).attr('src', src + '?' + (new Date()).getTime());
}		
		
		
// Fenstername (zum Aufrufen aus der Sitemap)
window.name = 'Bielefeld';

function openNewWin(URL) {
      msgWindow=window.open(URL, 'sitemap','toolbar= 0,location= 0,directories= 0,status= 0,menubar= 0,scrollbars= 1,resizable=yes,copyhistory= 0,width=215,height=400,screenX=1,screenY=1');
}

// Werbung Immobiliensuche (Content Regional) in neuem Fenster
function openWinImmo() {
      msgWindow=window.open('http://content-regional.de/portal/immobilien/?id=1855', 'NewWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=800,height=500');
}


// Fenster fuer Online-Ticket-Service bei Stadthalle Bielefeld
function openWinVeranstSHB() {
      msgWindow=window.open('', 'SHB','toolbar=yes,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=700,height=600');
			msgWindow.focus();
}

// Fenster fuer Hotel-Buchung bei Ophelia
function openWinHotel() {
      msgWindow=window.open('', 'hotelres','location=1,directories=0,menubar=0,resizable=1,toolbar=1,status=0,scrollbars=1,width=600,height='+Math.min(screen.availHeight-30, 700)+'');
			msgWindow.focus();
}

// Fenster fuer Detailstadtplan
function openWinDetailplan() {
      msgWindow=window.open('', 'detailplan','location=0,directories=0,menubar=0,resizable=1,toolbar=0,status=0,scrollbars=1,width=760,height='+Math.min(screen.availHeight-30, 700)+',top=0,left=0');
			msgWindow.focus();
}


// Fenster zum Anzeigen eines grossen Bildes
function openWinBild(width, height) {
			// ggf. Vorbelegen, wenn nicht als Parameter
			if ( ! width ) { width = '600'; }
			if ( ! height ) { height = '600'; }
			// Rahmen um Bild fuer Fenstergroesse beruecksichtigen
			width  = Math.min(screen.availWidth-20, width+50);
			height = Math.min(screen.availHeight-40, height+70);
			msgWindow=window.open('/blank.html', 'bild','toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=yes,copyhistory=0,width='+width+',height='+height);
}

// PDF-Dokument in neuem Fenster oeffnen
function openWinPDF(url, width, height) {
			// if ( ! width ) { width = '500'; }
			// if ( ! height ) { height = '500'; }
			msgWindow=window.open(url, 'dokument','toolbar=1,location=0,directories=0,status=0,menubar=1,scrollbars=1,resizable=yes,copyhistory=0,width='+width+',height='+height);
}


// Kopfbild austauschen (zur einfacheren Auswahl von Motiven)
function setKopfbild(bild) {
	document.getElementById('headarea').style.backgroundImage="url(/ftp/kopfbilder/"+bild+")";
}




var timeout;
// Quickfinder
function showObj(obj, doTimeout) {
	if (timeout) { window.clearTimeout(timeout); }
	if(document.all) {  // IE
			document.all[obj].style.display="";
			// document.all[obj].focus();
	} else if (document.layers) {
			document.layers[obj].visibility = "show";
	}//else (Netscape 4)
	else if (document.getElementById) { // NS 6
			document.getElementById(obj).style.display="";
			// document.getElementById('qfmenufirst').focus();
	}//elsif (Netscpae 6)
	if (  doTimeout != 'noTimeout' ) {
	// if ( ! document.all  ||  ! doTimeout ||  doTimeout != 'noTimeout' ) {
		timeout = window.setTimeout("hideObj('"+obj+"')", 4000);
	}
}//showObj


function hideObj(obj) {
	if(document.all) {  // IE
		if (timeout) { window.clearTimeout(timeout); }
		document.all[obj].style.display="none";
	} else if (document.layers){
		document.layers[obj].visibility = "hide";
	}//else (Netscape 4)
	else if (document.getElementById) { // NS 6
		//alert('Feieraben.');
		document.getElementById(obj).style.display="none";
	}//elsif (Netscpae 6)
}//hideObj



function setAdditionalStyleSheet( ) {
//	gibt den Link auf ein zus. Style Sheet zurueck, wenn ein entspr.
//	Cookie gesetzt ist.
 	if(document.cookie) {
  	var Wertstart = document.cookie.indexOf("=") + 1;
  	var Wertende = document.cookie.indexOf(";");
  	if (Wertende == -1)	Wertende = document.cookie.length;
  	Wert = document.cookie.substring(Wertstart,Wertende);
		document.writeln('<link rel="stylesheet" type="text/css" href="/' + Wert + '" media="screen">');
	}//if (cookie)
}// setAdditionalStyleSheet


var style_invers = "style_invers.css";

function setStyleSheetCookie(stylesheetname) {
// setzt ein Cookie mit dem Namen eines zus. StyleSheet
		var verfall = 1000*3600*24*30;  // ein Monat
		if ( ! stylesheetname || stylesheetname == '' ) {
			verfall *= -1; // Vergangenheit, Cookie wird geloescht
		}
	 	var jetzt = new Date();
 		var Auszeit = new Date(jetzt.getTime() + verfall);
 		document.cookie = "AdditionalStyleSheet="+stylesheetname+"; expires="+ Auszeit.toGMTString() + "; path=/";
		location.reload();
}// setStyleSheetCookie


//
// Reiter (Tabs) fuer Kompaktsuchen (rechte Spalte) umschalten
//
function setReiter(r1, r2, r3) {
	document.getElementById(r1).style.display='block';
	document.getElementById('tab'+r1).className = '';
	document.getElementById(r2).style.display='none';
	document.getElementById('tab'+r2).className = 'inactive';
	document.getElementById(r3).style.display='none';
	document.getElementById('tab'+r3).className = 'inactive';	
	// alert(document.getElementById('tab'+r3).className);
	// document.getElementById('CALBUTTONDPC_calendar3TICKETS').style.display='block';
}// setReiter




//
// Webcam: Bild neu laden
// (spezielle Anpassungen fuer eine Seite mit 3 Webcam-Bildern; rkn 14.07.2004)
//
var timeoutwebcam1;
var timeoutwebcam2;
var timeoutwebcam3;
var timeoutwebcam4;

function reloadImg(bild) {
	// laed das uebergebene Bild (img) neu
	// Zufallszahl als Parameter, damit nicht aus Cache
		var uniq = "?"+Math.random();
    var newImage = bild.src;
    var index = newImage.indexOf("?", 0);
    if (index > 0)  {  newImage = newImage.substr(0, index);  }
    bild.src = newImage+uniq;
}

function autoReloadWebcamImg( ) {  // wird per 'onload'-Event beim Bild aufgerufen
	if ( document.getElementById("webcamimg1") ) { // wenn es das Bild 'webcamimg1' gibt
		if (timeoutwebcam1) { window.clearTimeout(timeoutwebcam1); }
		timeoutwebcam1 = window.setTimeout("reloadImg(webcamimg1)", 15000);  // Achtung: Name des Bildes muss 'webcamimg1' sein
	}
	if ( document.getElementById("webcamimg2") != null ) { // wenn es das Bild 'webcamimg2' gibt
		if (timeoutwebcam2) { window.clearTimeout(timeoutwebcam2); }
		timeoutwebcam2 = window.setTimeout("reloadImg(webcamimg2)", 15000);  // Achtung: Name des Bildes muss 'webcamimg2' sein
	}
	if ( document.getElementById("webcamimg3") != null ) { // wenn es das Bild 'webcamimg3' gibt
		if (timeoutwebcam3) { window.clearTimeout(timeoutwebcam3); }
		timeoutwebcam3 = window.setTimeout("reloadImg(webcamimg3)", 15000);  // Achtung: Name des Bildes muss 'webcamimg3' sein
	}
	if ( document.getElementById("webcamimg4") != null ) { // wenn es das Bild 'webcamimg4' gibt
		if (timeoutwebcam4) { window.clearTimeout(timeoutwebcam4); }
		timeoutwebcam4 = window.setTimeout("reloadImg(webcamimg4)", 15000);  // Achtung: Name des Bildes muss 'webcamimg4' sein
	}
}  // autoReloadWebcamImg



//
// Ausschreibungungsunterlagen anfordern (Merkfunktion)
//
var submi_path = '/de/rv/bgn/sus/';

function merkerAddSubmi(idsubmi) {
// setzt ein Cookie mit der ID einer Submission, bzw. fuegt die Submi einer bestehenden Liste hinzu
		var submiliste = readCookie('SubmiIDs');
		if ( submiliste == null ) { submiliste=idsubmi; }
		else {
			var Liste = submiliste.split('|');
			Liste.push(idsubmi);
			submiliste = Liste.join('|');
		}
		createCookie('SubmiIDs', submiliste);
		// alert("Neue Submiliste: "+submiliste);
}// merkerAddSubmi


function merkerRemoveSubmi(idsubmi) {
// entfernt die ID aus dem (sofern vorhandenen) Cookie
		var submiliste = readCookie('SubmiIDs');
		if(submiliste) {
			var Liste = submiliste.split('|');
			var Liste2 = new Array();
			for (var i = 0; i < Liste.length; i++) { if (Liste[i] != idsubmi) Liste2.push(Liste[i]); }
			submiliste = Liste2.join('|');
			createCookie('SubmiIDs', submiliste);
		}
		// alert("Neue Submiliste: "+submiliste);
}// merkerRemoveSubmi


//
// allgemeine Cookie-Funktionen
//
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		// date.setTime(date.getTime()+(days*24*60*60*1000));
		date.setDate(1 + date.getDate());
		var expires = "; expires=" + date.toGMTString();
	} else var expires = "";
	var val = name+"="+value+expires+"; path=/"; //; domain=entwicklung.bielefeld07.rz-betrieb.de; secure";
	// var val = name+"="+value; // +"; path=/; domain=entwicklung.bielefeld07.rz-betrieb.de; secure";
	// alert ("create Cookie: " + val);
	document.cookie = val;
	// alert(document.cookie);
}

//function setCookie(visits) {
//      var expireDate = new Date();
//      var today = new Date();
//      expireDate.setDate(365 + expireDate.getDate());
//      document.cookie = "Visits=" + visits + ";
//      expires=" + expireDate.toGMTString() + ";";
//      document.cookie = "LastVisit=" + escape (today.toGMTString()) + ";
//      expires=" + expireDate.toGMTString() + ";";
//    }

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	// alert ("read Cookie: " + document.cookie);
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		// alert ( i + ": " + c );
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}



/*
 * Einstellungen LinguaTec Sprachausgabe (RKN 28.08.2008)
 */
vrweb_iconvar = 'bielefeld';
vrweb_icon = '01';
vrweb_iconcolor = 'red';
vrweb_guilang = 'de';
vrweb_lang = 'de-de';
vrweb_srctype = 'html';
vrweb_readcontent = 'elements';
vrweb_srccharset = 'iso-8859-1';
vrweb_sitetopic = '';
vrweb_simpleparse = '0';
vrweb_readelementsname = '';
vrweb_readelementsclass = 'mitterechts';
vrweb_exclelementsname = '';
vrweb_exclelementsclass = 'noread';
vrweb_customerid = '11142';
vrweb_cache = '0';
vrweb_sndtype = '1';
vrweb_sndquality = '4';
vrweb_sndspeed = '100';
vrweb_sndpitch = '100';
vrweb_sndgender = 'W';


