// Meteoblue scripts. copyright Mathias Mueller, University of Basel, Switzerland


//****************** restore frameset context of webpage ************************

function checkFrameset(mainIndexPage){
  if (parent.location.href == self.location.href) {
    if (window.location.href.replace)
        window.location.replace(mainIndexPage);
    else
        // causes problems with back button, but works
        window.location.href = mainIndexPage;
 }
 
}



//************* main navigation menu code **************************************
  
  var n_menuentries = 18; //number of clickable dots
  var n_wordentries = 5; //map soundings pictograms etc.
  var n_gridentries = 5; // resolutions
  var b = new Array(2);
  b[0] = new Image(); b[0].src = "img/mdot_inactive.gif";
  b[1] = new Image(); b[1].src = "img/mdot_active.gif";
 
   function showPage(URL1,FrameNummer,imgindex,wordindex,gridindex){  
    parent.frames[FrameNummer].location.href=URL1;

    for (var i=0; i<n_menuentries; i++){
       parent.frames[0].document.menu[i].src = b[0].src;
    }
    
    for (var i=0; i<n_wordentries; i++){
      parent.frames[0].document.getElementsByTagName("font")[i].className = "MenuFont2";
    }

    var lastgrid = n_gridentries+n_wordentries;
    for (var i=n_wordentries; i<lastgrid; i++){
      parent.frames[0].document.getElementsByTagName("font")[i].className = "MenuFont";
    }

     parent.frames[0].document.getElementsByTagName("font")[wordindex].className = "MenuFontActive";
     parent.frames[0].document.getElementsByTagName("font")[gridindex+n_wordentries].className = "MenuFontActive";
     parent.frames[0].document.menu[imgindex].src = b[1].src;
   }




//*********************  open a pictogram timeseries window  *********************


function pwin_open(name){
    window.open (name, 'newwindow', config='height=255,width=660, toolbar=no,     menubar=no,scrollbars=no,resizable=yes,location=no, directories=no, status=no');
  }





//*********************  open window to display maps  *******************************
//INPUT: name = filename
//         domain = nmm22 , nmm4 etc.

function showMap(name,domain){
  
  if(domain=="nmm22"){
   var map = window.open (name, 'newwindow', config='height=750,width=890, toolbar=no,                   menubar=no,scrollbars=yes,resizable=yes,location=no, directories=no, status=no')
;
  }

  if(domain=="nmm4"){
   var map = window.open (name, 'newwindow', config='height=750,width=924, toolbar=no,                       menubar=no,scrollbars=yes,resizable=yes,location=no, directories=no, status=no')
;
  }
  map.focus();
}



 



//***************************************************************************************
/*
==============================================================
Script:     Auto-Sizing Image Popup Window

Functions:  Use this script to launch a popup window that
            automatically loads an image and resizes itself
            to fit neatly around that image. The script also
            places a title you set in the titlebar of the 
            popup window. Any number of images can be launched
            from a single instance of the script.
            
Browsers:   NS6-7 & IE4 and later
            [Degrades functionally in NS4]

Author:     etLux, Mathias Müller
==============================================================

*/

// Script Source: CodeLifter.com
// Copyright 2003
// Do not remove this notice.
// modified Mathias Mueller
// SETUPS:
// ===============================

// Set the horizontal and vertical position for the popup

PositionX = 0;
PositionY = 0;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 900;
defaultHeight = 750;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = false;

// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=auto,resizable=yes,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=auto,width=900,resizable=yes,height=750,left='+PositionX+',top='+PositionY;
function popImage(imageURL,imageTitle){


if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
if (isIE==0 && isNN==0){imgWin=window.open('about:blank','',optNN);} //default for all browsers


imgWin.document.write('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');imgWin.document.write('<sc'+'ript>');
imgWin.document.write('var isNN,isIE;');imgWin.document.write('if (parseInt(navigator.appVersion.charAt(0))>=4){');


imgWin.document.write('isNN=(navigator.appName=="Netscape")?1:0;');imgWin.document.write('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');

imgWin.document.write('function reSizeToImage(){');

//for unknown browsers
imgWin.document.write('var iTick = 0;');
imgWin.document.write('while((iTick<15000) && (!document.images[0].complete)){');
imgWin.document.write('iTick = iTick + 1;}');
imgWin.document.write('if(document.images[0].complete){');
imgWin.document.write('window.resizeTo((document.images[0].width*1.1),(document.images[0].height*1.1));}');
// end of section for unknown browsers


imgWin.document.write('if (isIE){');
imgWin.document.write('width=100-(document.body.clientWidth-document.images[0].width-41);');
imgWin.document.write('height=100-(document.body.clientHeight-document.images[0].height);');
imgWin.document.write('window.resizeTo(width,height);}');imgWin.document.write('if (isNN){');       
imgWin.document.write('window.innerWidth=document.images["George"].width+41;');imgWin.document.write('window.innerHeight=document.images["George"].height;}}');

imgWin.document.write('function doTitle(){document.title="'+imageTitle+'";}');imgWin.document.write('</sc'+'ript>');
if (!AutoClose) imgWin.document.write('</head><body bgcolor=#FFFFFF scroll="auto"  onload="reSizeToImage();doTitle();self.focus()">')
else imgWin.document.write('</head><body bgcolor=#FFFFFF scroll="auto"  onload="reSizeToImage();doTitle();self.focus()"  onblur="self.close()">');
imgWin.document.write('<img name="George" src='+imageURL+' style="display:block"><br><br><br><br><br>&nbsp;</body></html>');
//close();		
}



//******************* detect the internet browser ***********************************************

function detect_browser(){

var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) OS = "Linux";
	else if (checkIt('x11')) OS = "Unix";
	else if (checkIt('mac')) OS = "Mac"
	else if (checkIt('win')) OS = "Windows"
	else OS = "an unknown operating system";
}


return browser;
}


function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}



//*********************  open a javascript movie player window  *********************

function win_open(name){   
  var map = window.open (name, 'newwindow', config='height=750,width=1004, toolbar=no,       menubar=no,scrollbars=yes,resizable=yes,location=no, directories=no, status=no');
map.focus();
}




//*************** switching the language ******************************************

// INPUT: newLang = the new language to switch to e.g. ".dt." ".fr."
 function toggle_lang(newLang)
  {
    
    qmpos = parent.frames[2].location.href.indexOf("????");
    if (qmpos > 0)
    {
       alert("Sorry, no translation available")
    }
    else 
    {
      hrefp0 = parent.frames[0].location.href;
      hrefp1 = parent.frames[1].location.href;
      hrefp2 = parent.frames[2].location.href;

      enpos = hrefp2.indexOf(".en.");
      dtpos = hrefp2.indexOf(".dt.");
      frpos = hrefp2.indexOf(".fr.");
      itpos = hrefp2.indexOf(".it.");

      if (enpos >= 0) { /* Seems to be english  */
        current = ".en."; 
      }

      if (dtpos >= 0) { /* Seems to be german */
        current = ".dt."; 
      }

      if (frpos >= 0) { /* Seems to be french  */
        current = ".fr."; 
      }

      if (frpos >= 0) { /* Seems to be italian */
        current = ".fr."; 
      }


        dtstr = hrefp0.split(current);
        enstr = dtstr[0];
        for (i=1;i<dtstr.length;i++) 
        {
          enstr = enstr+newLang+dtstr[i];
        }   
        href = enstr;
        parent.frames[0].location.replace(href);

        dtstr = hrefp1.split(current);
        enstr = dtstr[0];
        for (i=1;i<dtstr.length;i++) 
        {
          enstr = enstr+newLang+dtstr[i];
        }   
        href = enstr;
        parent.frames[1].location.replace(href);
           
        dtstr = hrefp2.split(current);
        enstr = dtstr[0];
        for (i=1;i<dtstr.length;i++) 
        {
          enstr = enstr+newLang+dtstr[i];
        }   
        href = enstr;
        parent.frames[2].location.replace(href);
     
   } //endelse

  } 

