var playerVisible = false;var galleryVisible = false;

createKbbPlayer = function(playerFile, playerWidth, playerHeight, autostart) {
 handleKbbPlayerVisibility(playerWidth, playerHeight); functionCall = "createKbbPlayerSwf('" + playerFile + "','" + playerWidth + "','" + playerHeight + "','" + autostart + "')"; window.setTimeout(functionCall, 900);}


createKbbPlayerSwf = function(playerFile, playerWidth, playerHeight, autostart) {
 var so = new SWFObject('media/mediaplayer.swf','kbbPlayer', playerWidth, playerHeight,'9'); so.addParam('allowfullscreen', 'true');
 so.addVariable('file', playerFile); so.addVariable('javascriptid', 'kbbPlayer');
 so.addVariable('width', playerWidth); so.addVariable('height', playerHeight); so.addVariable('displayheight', parseInt(playerHeight)-19);
 so.addVariable('screencolor', '0xE0EBD6'); so.addVariable('shownavigation', 'true'); so.addVariable('showicons', 'false'); so.addVariable('autostart', 'true');
 so.write('mediaplayerfile');}


handleKbbPlayerVisibility = function(playerWidth, playerHeight) {
 if (playerVisible) {
 hideKbbPlayer(); functionCall = "displayKbbPlayer('" + playerWidth + "','" + playerHeight + "')"; window.setTimeout(functionCall, 300); } else {
 displayKbbPlayer(playerWidth, playerHeight); }
}


displayKbbPlayer = function(playerWidth, playerHeight) {
 $('mediaplayer').style.width = playerWidth + 'px'; $('mediaplayer').style.height = playerHeight + 'px'; Effect.BlindDown('mediaplayer', {duration:0.5}); playerVisible = true;}


hideKbbPlayer = function() {
 $('mediaplayerfile').innerHTML = '<img src="img/ajax-loader.gif" />'; Effect.BlindUp('mediaplayer', {duration:0.1});}


displayKbbGallery = function() {
 if (galleryVisible == false) {
 Effect.BlindDown('gallerywrap', {duration:0.5}); galleryVisible = true; }
 return true;}


hideKbbGallery = function() {
 Effect.BlindUp('gallerywrap', {duration:0.1}); galleryVisible = false; return true;}


noSubmit = function() {
 alert("Wir sind noch ganz schön beta!\n\nIn Kürze wird aber auch unsere Suche funktionieren.\nProbiert es dann doch noch ein mal!\n\n\nEuer Wetter Retter :-)"); return false;}


checkSubmit = function(val) {
 if (val.length < 3) {
 alert("Zur Suche nach einem Begriff müsst ihr mindestens drei Buchstaben oder Zeichen eingeben!"); return false; }
 return true;}

openPrintPage = function(rubrik) {
 var contentDiv = 'ez_' + rubrik; var file = 'artikel_drucken.html?' + contentDiv;
 Fenster = window.open(file, 'Artikel');}


printPage = function() {
 if (window.print()) {
 window.print(); }
}



 
 
var detailsVisible = false;var search = '';var orte_count = 0;var cc = '';var rc = '';
checkParams = function(params) {
 var e = params; var e1 = e[1]; Object.toJSON(e1); 
 var regex = /[\&;\`'\\\|"*?~<>^\(\)\[\]\{\}\$\n\r]+/;
 if (e1.search) tmpString = e1.search; else if (e1.cc) tmpString = e1.cc; else if (e1.rc) tmpString = e1.rc; else return false; 
 if ( e.size() != 2 ||
 (e[0] != 'cc' && e[0] != 'rc' && e[0] != 'id' )
  || e1.search == ''
  || regex.test(tmpString)
 ) {
 return false; }
 
 return true;}


hideDetailSearch = function() {
 new Effect.Opacity('ajaxwrapper', { duration:0.5, from:0.9, to:0.0 }); new Effect.SlideUp('ajaxwrapper', { duration: 0.5 }); $('cc').update(); new Effect.Opacity('cc', { from:1.0, to:0.0 }); $('rc').update(); new Effect.Opacity('rc', { from:1.0, to:0.0 }); $('id').update(); new Effect.Opacity('id', { from:1.0, to:0.0 }); detailsVisible = false;}

handleSearch = function(params) {
 if (! checkParams(params)) {
 return false; }
 var updateEl = params[0]; var data = params[1]; Object.toJSON(data); 
 if($('detailnoflash')) $('detailnoflash').hide(); 
 $('progbar').show(); 
 
 
 if ($('rc').getStyle('display') == 'none' && isNaN(data.search)) {
 $('cc').setStyle({ display:'inline' }); $('rc').setStyle({ display:'inline' }); }

 if (data.rc) {
 $('id').setOpacity(0.0).update().setStyle({ visibility:'hidden' }); rc = data.rc; new Ajax.Request('/php/suggest.php',
 { method: 'get',
  parameters: { o:'a', search: search, detail: 1, cc: cc, rc: data.rc },
  onSuccess: function(transport) { updateDetail(updateEl, transport.responseText) },
  onFailure: function() { alert("Bei der Suche ist etwas schiefgegangen...\nBitte versuche es noch einmal!")}
 }); } else if (data.cc) {
 $('rc').setOpacity(0.0).update(); $('rc').setStyle({ visibility:'hidden' }); $('id').setOpacity(0.0).update(); $('id').setStyle({ visibility:'hidden' }); cc = data.cc; new Ajax.Request('/php/suggest.php',
 { method: 'get',
  parameters: { o:'a', search: search, detail: 1, cc: data.cc },
  onSuccess: function(transport) { updateDetail(updateEl, transport.responseText) },
  onFailure: function() { alert("Bei der Suche ist etwas schiefgegangen...\nBitte versuche es noch einmal!")}
 }); } else if ( data.search ) {
 $('cc').setOpacity(0.0).update(); $('cc').setStyle({ visibility:'hidden' }); $('rc').setOpacity(0.0).update(); $('rc').setStyle({ visibility:'hidden' }); $('id').setOpacity(0.0).update(); $('id').setStyle({ visibility:'hidden' }); search = data.search;
 if (isNaN(search)) {
 new Ajax.Request('/php/suggest.php',
 { method: 'get',
  parameters: { o:'a', detail: 1, search: data.search },
  onSuccess: function(transport) { updateDetail(updateEl, transport.responseText) },
  onFailure: function() { alert("Bei der Suche ist etwas schiefgegangen...\nBitte versuche es noch einmal!")}
 }); } else {
 $('cc').hide(); $('rc').hide(); new Ajax.Request('/php/suggest.php',
 { method: 'get',
  parameters: { o:'a', search: data.search },
  onSuccess: function(transport) { updateDetailPLZ('id', transport.responseText) },
  onFailure: function() { alert("Bei der Suche ist etwas schiefgegangen...\nBitte versuche es noch einmal!")}
 }); }
 } else {
 return false; }
}


updateDetail = function(el, responseText) {
 var items = null; 
 if (! detailsVisible) {
 new Effect.SlideDown('ajaxwrapper', { duration: 0.5 }); new Effect.Opacity('ajaxwrapper', { from:0.0, to:0.9 }); detailsVisible = true; }
 
 $(el).setStyle({ visibility:'visible' }); new Effect.Opacity($(el), { from:0.0, to:1.0 });
 if (el == 'cc') { items = responseText.split('#'); orte_count = 0; $('result').update(); 
 for (i = 0; i < items.length; i++) {
 temp = items[i].split('|'); var listEl = new Element('option'); 
 for (j = 0; j < temp.length; j++) {
 key_val = temp[j].split(':'); 
 if (key_val[0] == 'id') {
 var thisCC = key_val[1]; listEl.setAttribute('value', "new Array(\'rc\', { 'cc':'" + key_val[1] + "' });"); }
 if (key_val[0] == 'name') {
 listEl.appendChild(document.createTextNode(key_val[1])); }
 if (key_val[0] == 'count') {
 orte_count += parseInt(key_val[1]); }
 $(el).appendChild(listEl); }
 }
 
 ort = orte_count == 1 ? ' Ort' : ' Orte'; $('result').update(orte_count + ort + " gefunden.").show(); 
 if (items.length == 1) {
 handleSearch(new Array('rc', { 'cc':thisCC })); }
 }
 
 if (el == 'rc') { items = responseText.split('#'); 
 for (i = 0; i < items.length; i++) {
 temp = items[i].split('|'); var listEl = new Element('option'); 
 for (j = 0; j < temp.length; j++) {
 key_val = temp[j].split(':'); 
 if (key_val[0] == 'id') {
 var thisRC = key_val[1]; listEl.setAttribute('value', "new Array(\'id\', { 'rc':'" + key_val[1] + "' });"); }
 if (key_val[0] == 'name') {
 listEl.appendChild(document.createTextNode(key_val[1])); }
 }
 $(el).appendChild(listEl); }
 if (items.length == 1) {
 handleSearch(new Array('id', { 'rc':thisRC })); }
 }
 
 if (el == 'id') { items = responseText.split('#'); 
 for (i = 0; i < items.length; i++) {
 temp = items[i].split('|'); var listEl = new Element('option'); handleVal = 'window.location.href="detail_mein_wetter.php?zoom=9'; 
 for (j = 0; j < temp.length; j++) {
 key_val = temp[j].split(':'); 
 if (key_val[0] == 'name') {
 listEl.appendChild(document.createTextNode(key_val[1])); continue; }
 if (key_val[0] == 'lon') {
 handleVal += "&lon=" + key_val[1]; continue; }
 if (key_val[0] == 'lat') {
 handleVal += "&lat=" + key_val[1]; continue; }
 if (key_val[0] == 'geonameid') {
 handleVal += "&id=" + key_val[1]; continue; }
 }
 handleVal += '"'; listEl.setAttribute('value', handleVal); $(el).appendChild(listEl); }
 }
 
 if (el == 'id' || items.length > 1 || orte_count == 0) {
 $('progbar').hide(); }
}


updateDetailPLZ = function(el, responseText) {
 if (! detailsVisible) {
 new Effect.SlideDown('ajaxwrapper', { duration: 0.5 }); new Effect.Opacity('ajaxwrapper', { from:0.0, to:0.9 }); detailsVisible = true; }

 $(el).setStyle({ visibility:'visible' }); new Effect.Opacity($(el), { from:0.0, to:1.0 }); 
 if (el == 'id') { items = responseText.split('#'); orte_count = 0; $('result').update(); 
 for (i = 0; i < items.length; i++) {
 temp = items[i].split('|'); var listEl = new Element('option'); handleVal = 'window.location.href="detail_mein_wetter.php?zoom=9'; var tmpName = ''; 
 for (j = 0; j < temp.length; j++) {
 key_val = temp[j].split(':'); 
 if (key_val[0] == 'name') {
 tmpName = key_val[1]; continue; }
 if (key_val[0] == 'lon') {
 handleVal += "&lon=" + key_val[1]; continue; }
 if (key_val[0] == 'lat') {
 handleVal += "&lat=" + key_val[1]; continue; }
 if (key_val[0] == 'geonameid') {
 handleVal += "&id=" + key_val[1]; continue; }
 if (key_val[0] == 'post_code') {
 tmpName = key_val[1] + " " + tmpName; continue; }
 }
 handleVal += '"'; 
 orte_count++; ort = orte_count == 1 ? ' Ort' : ' Orte'; $('result').update(orte_count + ort + " gefunden.").show();
 listEl.setAttribute('value', handleVal); listEl.appendChild(document.createTextNode(tmpName)); $(el).appendChild(listEl); }
 }
 
 $('progbar').hide();}


function openTipp(tipp){ b = navigator.appVersion; n = navigator.userAgent; 
 if( $('tipp_contents'+tipp).style.display == 'none' ){ if(b.indexOf("MSIE") == -1 && n.indexOf('Opera') == -1) new Effect.BlindDown('tipp_contents'+tipp, {duration:0.5}); $('tipp_contents'+tipp).style.display = 'block'; $('tipp_pic'+tipp).src = 'img/x_button_tipps_18px.png'; }
 else{ if(b.indexOf("MSIE") == -1 && n.indexOf('Opera') == -1) new Effect.BlindUp('tipp_contents'+tipp, {duration:0.5}); $('tipp_contents'+tipp).style.display = 'none'; $('tipp_pic'+tipp).src = 'img/pfeil_button_tipps_18px.png'; }
 
}


function checkInput(plz){ if( plz == "") return false; else if( isNaN(plz)) return false; 
 return true;}
 
function checkRegSearch(){ if( checkInput($('plz').value) == true){ return true; }
 else{ alert("Bitte nur 5-stellige Postleitzahlen eingeben!"); return false; }
}


function getCookie(c_name){ if (document.cookie.length>0){ c_start=document.cookie.indexOf(c_name + "="); if (c_start!=-1){ c_start=c_start + c_name.length+1;  c_end=document.cookie.indexOf(";",c_start);  if (c_end==-1) c_end=document.cookie.length;  return unescape(document.cookie.substring(c_start,c_end)); } 
 }
 return "";} 

function setCookie(c_name,value,expiredays){ var exdate=new Date(); exdate.setDate(exdate.getDate()+expiredays); document.cookie=c_name+ "=" +escape(value)+
 ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());}


if(getCookie("currentUser_r") == "")
 setCookie("currentUser_r",screen.width + "x" + screen.height,10);

