
// JavaScript Document
//<!--

        // Function that retrieves the remote HTML and puts it into
        // the <div> with an id of 'html-content'.

var IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var tempX = 0
var tempY = 0
var tooltips = [];
var ACT_VALUE = "temperatur_aktuell";

var rekorde=new Array();
rekorde[0] = "temperatur:max";
rekorde[1] = "temperatur:min";
rekorde[2] = "wind_geschwindigkeit:max";
var currentRekord = 0;
var actKarte = "";
ACT_REKORD = rekorde[0];

		function checkTagNachtKarte(){
				zeit = new Date();
				h = zeit.getHours();
				if(h > 5 && h < 21){
					if(actKarte != "tag"){
						document.getElementById('livewetter').style.backgroundImage = 'url(../pics/wetterkarte/vlbg_karte_tag.png)';
						actKarte = "tag";
					}
				} else {
					if(actKarte != "nacht"){
						document.getElementById('livewetter').style.backgroundImage = 'url(../pics/wetterkarte/vlbg_karte_nacht.png)';
						actKarte = "nacht";
					}
				}
				setTimeout("checkTagNachtKarte()", 60000);
		}
		checkTagNachtKarte();

		function set_ACT_VALUE(value){
			ACT_VALUE = value;
			switch(value){
				case "temperatur_aktuell":{document.getElementById('aktuelle_auswahl').innerHTML = "Temperatur aktuell (C°)";break;}
				case "temperatur_tag_max":{document.getElementById('aktuelle_auswahl').innerHTML = "Temperatur Tag max (C°)";break;}
				case "temperatur_tag_min":{document.getElementById('aktuelle_auswahl').innerHTML = "Temperatur Tag min(C°)";break;}
				case "temperatur_monat_max":{document.getElementById('aktuelle_auswahl').innerHTML = "Temperatur Monat max (C°)";break;}
				case "temperatur_monat_min":{document.getElementById('aktuelle_auswahl').innerHTML = "Temperatur Monat min (C°)";break;}
				case "temperatur_jahr_max":{document.getElementById('aktuelle_auswahl').innerHTML = "Temperatur Jahr max (C°)";break;}
				case "temperatur_jahr_min":{document.getElementById('aktuelle_auswahl').innerHTML = "Temperatur Jahr min (C°)";break;}
				case "luftdruck_aktuell":{document.getElementById('aktuelle_auswahl').innerHTML = "Luftdruck aktuell (hPa)";break;}
				case "luftdruck_tag_max":{document.getElementById('aktuelle_auswahl').innerHTML = "Luftdruck Tag max (hPa)";break;}
				case "luftdruck_tag_min":{document.getElementById('aktuelle_auswahl').innerHTML = "Luftdruck Tag min (hPa)";break;}
				case "luftfeuchtigkeit_aktuell":{document.getElementById('aktuelle_auswahl').innerHTML = "Luftfeuchte aktuell (%)";break;}
				case "luftfeuchtigkeit_tag_max":{document.getElementById('aktuelle_auswahl').innerHTML = "Luftfeuchte Tag max (%)";break;}
				case "luftfeuchtigkeit_tag_min":{document.getElementById('aktuelle_auswahl').innerHTML = "Luftfeuchte Tag min (%)";break;}
				case "regen_rate":{document.getElementById('aktuelle_auswahl').innerHTML = "Nied. Rate aktuell (mm/h)";break;}
				case "regen_tag":{document.getElementById('aktuelle_auswahl').innerHTML = "Nied. Menge Tag (mm)";break;}
				case "regen_monat":{document.getElementById('aktuelle_auswahl').innerHTML = "Nied. Menge Monat (mm)";break;}
				case "regen_jahr":{document.getElementById('aktuelle_auswahl').innerHTML = "Nied. Menge Jahr (mm)";break;}
				case "wind_geschwindigkeit_durchschnitt":{document.getElementById('aktuelle_auswahl').innerHTML = "Windgeschw. aktuell (km/h)";break;}
				case "wind_richtung":{document.getElementById('aktuelle_auswahl').innerHTML = "aktuelle Windrichtung";break;}
				case "wind_geschwindigkeit_tag_max":{document.getElementById('aktuelle_auswahl').innerHTML = "Windgeschw. Tag (km/h)";break;}
				case "wind_geschwindigkeit_monat_max":{document.getElementById('aktuelle_auswahl').innerHTML = "Windgeschw. Monat (km/h)";break;}
				case "wind_geschwindigkeit_jahr_max":{document.getElementById('aktuelle_auswahl').innerHTML = "Windgeschwind. Jahr (km/h)";break;}
				case "sonne_watt":{document.getElementById('aktuelle_auswahl').innerHTML = "Solarstrahlung (w/m²)";break;}
				case "schneehoehe":{document.getElementById('aktuelle_auswahl').innerHTML = "Schneeh&ouml;he (cm)";break;}
			}
			getStations();
		}

		var getStationsReady = true;
        function getStations() {
			
			if(getStationsReady == true){
				getStationsReady = false;
				dojo.xhrGet ({
					// Location of the HTML content we want to grab
					url: '../businessLogic/ajax/getStations.php?val=' + ACT_VALUE,
					useCache: false, 
					preventCache: true ,
			
					// Called when the page loaded successfully
					load: function (data) { 
						if(dojo.byId('wetterkarte') != null){
							dojo.byId('wetterkarte').innerHTML = data;
							getStationAlarm();
							getRekorde();
							for(var i = 0; i < tooltips.length; i++){
								tooltips[i] = null;	
							}
							getStationsReady = true;
						}
					},
			
					// Called if there was an error (such as a 404 response)
					error: function (data) { }
				});
				setTimeout("getStations()", 30000);
			}
		}
		// JavaScript Document

	var countdown = 30;
	function getStationCountDown(){
			if(countdown > 1){
				countdown--;
			} else {
				countdown = 30;
				if(getStationsReady == true){
				   getStations();
				}
			}
			document.getElementById('wetterkarte_loading').innerHTML = countdown;
			setTimeout("getStationCountDown()", 1000);
	}
	getStations();
	getStationCountDown();


function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return true
}

function getToolTip(id){
			posX = tempX;
			posY = tempY;
			stId = id;
			
				dojo.xhrGet ({
					// Location of the HTML content we want to grab
					url:  '../businessLogic/ajax/getTooltip.php?id=' + id,
					useCache: false, 
					preventCache: true,
			
					// Called when the page loaded successfully
					load: function (data) {
							if( (tempX - posX < 20) && (tempX - posX > -20) && (tempY - posY < 20) && (tempY - posY > -20)){
								showTip(data);
							} else {
								UnTip();	
							}
					},
			
					// Called if there was an error (such as a 404 response)
					error: function (data) { 
					
					}
				});
			
		}
		
//-->

function showTip(text){
	Tip(text, BALLOON, true, ABOVE, true, OFFSETX, -17, TEXTALIGN, 'justify', PADDING, 8);
}

// JavaScript Document

  function getStationAlarm() {
            dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/getStationAlarm.php',
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
					if(dojo.byId('widget_warnung') != null){
						dojo.byId('widget_warnung').innerHTML = data;
					}
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
        }
	
	 function getRekorde() {
            dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/getRekorde.php?rekord=' + ACT_REKORD,
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
					if(dojo.byId('rekorde_inhalt') != null){
						dojo.byId('rekorde_inhalt').innerHTML = data;
					}
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
        }
		
		function next_rekord(){
			if(currentRekord + 1 < rekorde.length){
				currentRekord++;	
			} else {
				currentRekord = 0;
			}
			ACT_REKORD = rekorde[currentRekord];
			getRekorde();
		}
		
		function previous_rekord(){
			if(currentRekord -1 > -1){
				currentRekord--;
			} else {
				currentRekord = rekorde.length - 1;
			}
			ACT_REKORD = rekorde[currentRekord];
			getRekorde();
		}
		
		
		function openModalBox(header, source, href){
			dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/getWebcamPopup.php?href=' + href + '&source=' + source + "&header=" + header,
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
					$.modal(data);
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
		}
		
		function openStationPopup(id){
			    if(id && id != 0){
					dojo.xhrGet ({
                	// Location of the HTML content we want to grab
                	url: '../businessLogic/ajax/getStationPopup.php?id=' + id,
					useCache: false, 
       				preventCache: true ,
        
                	// Called when the page loaded successfully
                	load: function (data) { 
						$.modal(data);
					},
        
                	// Called if there was an error (such as a 404 response)
                	error: function (data) { }
            	});
			}
		}
		
		function showLegende(){
			dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/getLegendePopup.php',
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
					$.modal(data);
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
		}
		
		function showRadar(){
			dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/getRadar.php',
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
					$.modal(data);
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
		}
		
		function showBlitzRadar(){
			dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/getBlitzRadar.php',
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
					$.modal(data);
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
		}
		
		function showSat() {
			dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/getSat.php',
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
					$.modal(data);
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
		}
	
		var berichte = "";
		var getBaederberichtReady = true;
	    function getBaederbericht() {
			if(getBaederberichtReady == true){
				getBaederberichtReady = false;
				dojo.xhrGet ({
					// Location of the HTML content we want to grab
					url: '../businessLogic/ajax/getBaederbericht.php?berichte=' + berichte,
					useCache: false, 
					preventCache: true ,
			
					// Called when the page loaded successfully
					load: function (data) { 
						if(dojo.byId('baederbericht') != null){
							var data_splt = data.split("#");
							if(data_splt[0]  != ""){
								berichte = data_splt[0];
							}
							dojo.byId('baederbericht').innerHTML = data_splt[1];
							getBaederberichtReady = true;
						}
					},
			
					// Called if there was an error (such as a 404 response)
					error: function (data) { }
				});
			}
			setTimeout("getBaederbericht()", 9000);
        }
		getBaederbericht();
		
		/*var berichte = "";
		var getPistenberichtReady = true;
	    function getPistenbericht() {
			if(getPistenberichtReady == true){
				getPistenberichtReady = false;
				dojo.xhrGet ({
					// Location of the HTML content we want to grab
					url: '../businessLogic/ajax/getPBericht.php',
					useCache: false, 
					preventCache: true ,
			
					// Called when the page loaded successfully
					load: function (data) { 
						if(dojo.byId('pistenbericht') != null){
							dojo.byId('pistenbericht').innerHTML = data;
							getPistenberichtReady = true;
                            berichtScrollAnim();
						}
					},
			
					// Called if there was an error (such as a 404 response)
					error: function (data) { }
				});
			}
        }
		getPistenbericht();*/

var stop = -20;
var dir = 'd';
function berichtScrollAnim(){
    stop++;
    if(stop >= dojo.byId('pbericht').scrollHeight-100){
        stop = -20;
    }
    dojo.byId('pbericht').scrollTop = stop;
    setTimeout("berichtScrollAnim()", 150);
}

		 var legende = "false";
		 var getNowcastReady = true;
		 function getNowcast() {
			if(getNowcastReady == true){
				getNowcastReady = false;
				dojo.xhrGet ({
					// Location of the HTML content we want to grab
					url: '../businessLogic/ajax/getNowcast.php?legende=' + legende,
					useCache: false, 
					preventCache: true ,
			
					// Called when the page loaded successfully
					load: function (data) { 
						if(dojo.byId('widget_nowcast') != null){
							dojo.byId('widget_nowcast').innerHTML = data;
							getNowcastReady = true;
						}
					},
			
					// Called if there was an error (such as a 404 response)
					error: function (data) { }
				});
			}
			setTimeout("getNowcast()", 60000);
        }
		getNowcast();
	
		function setNowcastLegende(){
			legende = "true";
			getNowcast();
		}
		
		function setNowcast(){
			legende = "false";
			getNowcast();
		}
		
	   var getBodenseeInfoReady = true;
	   function getBodenseeInfo() {
		   	if(getBodenseeInfoReady == true){
				getBodenseeInfoReady = false;
				dojo.xhrGet ({
					// Location of the HTML content we want to grab
					url: '../businessLogic/ajax/getBodenseeInfo.php',
					useCache: false, 
					preventCache: true ,
			
					// Called when the page loaded successfully
					load: function (data) { 
						if(dojo.byId('widget_bodenseeinfo') != null){
							dojo.byId('widget_bodenseeinfo').innerHTML = data;
							getBodenseeInfoReady = true;
						}
					},
			
					// Called if there was an error (such as a 404 response)
					error: function (data) { }
				});
			}
			setTimeout("getBodenseeInfo()", 180000);
        }
		getBodenseeInfo();
		
	  var getNewsTickerReady = true;
	   function getNewsTicker() {
		   	if(getNewsTickerReady == true){
				getNewsTickerReady = false;
				dojo.xhrGet ({
					// Location of the HTML content we want to grab
					url: '../businessLogic/ajax/getNewsTicker.php',
					useCache: false, 
					preventCache: true ,
			
					// Called when the page loaded successfully
					load: function (data) { 
						if(dojo.byId('widget_news') != null){
							dojo.byId('widget_news').innerHTML = data;
							getNewsTickerReady = true;
						}
					},
			
					// Called if there was an error (such as a 404 response)
					error: function (data) { }
				});
			}
			setTimeout("getNewsTicker()", 180000);
        }
		getNewsTicker();
		
		 var getIPrognoseReady = true;
		 function getIPrognose() {
			if(getIPrognoseReady == true){
				getIPrognoseReady = false;	
				dojo.xhrGet ({
					// Location of the HTML content we want to grab
					url: '../businessLogic/ajax/getIPrognose.php',
					useCache: false, 
					preventCache: true ,
			
					// Called when the page loaded successfully
					load: function (data) { 
						if(dojo.byId('widget_iprognose') != null){
							dojo.byId('widget_iprognose').innerHTML = data;
							getIPrognoseReady = true;
						}
					},
			
					// Called if there was an error (such as a 404 response)
					error: function (data) { }
				});
			}
			setTimeout("getIPrognose()", 180000);
        }
		getIPrognose();
		
		function checkPincode(pin){
			  dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/checkPincode.php?pin=' + pin,
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
					if(data == "true"){
						sendComment();
					} else {
						getWettermelderRegister();
					}
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
		}
		
		function getWettermelderRegister(){
			  dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/getWettermelderRegister.php',
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
						$.modal(data);
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
		}

		function checkWettermelderRegister(email, pincode){
				 dojo.xhrGet ({
                // Location of the HTML content we want to grab
                url: '../businessLogic/ajax/checkWettermelderRegister.php?email=' + email + "&pincode=" + pincode,
				useCache: false, 
       			preventCache: true ,
        
                // Called when the page loaded successfully
                load: function (data) { 
						dojo.byId('wettermelder_register').innerHTML = data;
				},
        
                // Called if there was an error (such as a 404 response)
                error: function (data) { }
            });
		}
		
		/*var getUserOnlineReady = true;
		function getUserOnline() {
			if(getUserOnlineReady == true){
				getUserOnlineReady = false;
				dojo.xhrGet ({
					// Location of the HTML content we want to grab
					url: '../businessLogic/ajax/getUserOnline.php',
					useCache: false, 
					preventCache: true ,
			
					// Called when the page loaded successfully
					load: function (data) { 
						if(dojo.byId('widget_useronline') != null){
							dojo.byId('widget_useronline').innerHTML = data;
							getUserOnlineReady = true;
						}
					},
			
					// Called if there was an error (such as a 404 response)
					error: function (data) { }
				});
			}
			setTimeout("getUserOnline()", 120000);
        }
		getUserOnline();*/


