/* Bottomnavbar Script for Globaler-Wandel including Impetus	*/
/* written by M. Mengel for					*/
/*        www.uni-koeln.de/nath-nat-fak/geomet/meteo		*/
/* Letzte Aenderung: 30.03.2001	Version 1.1			*/

//BUGS:
  //URL in loc.bar is not always right!
//TODO: Schaufensterschutz

//MAGIC VALUEs
var FRAME  = "http://www.uni-koeln.de/math-nat-fak/geomet/meteo/navbar.html";
var HOME   = "http://www.uni-koeln.de/math-nat-fak/geomet/meteo/main.html";
var FS_Td = "IGM Köln - Willkommen am Meteorologischen Bereich der Uni Köln";
var FS_Te = "IGM Cologne - Welcome to the University of Cologne's Meteorological Section"; // FrameSet_Titel 

var SERV_DIR = "index.html"	// what does your server add if i request 
				// http://www.domain.com/path/to/
//FUNCTIONs OnLoad
CUR_URL = Get_Url();

//Use from HTML: LLink(link), ubers(), Home(), Navbar() & Check_Lang() 

function Write_Frameset(FRAME, CUR_URL, FS_T)  {   // MODIFY IF NECESSARY:
    document.close();
    document.open("text/html");
    document.writeln('<HTML><HEAD><TITLE>' + FS_T + '</TITLE></HEAD>');
    document.writeln('<FRAMESET COLS=150,* FRAMEBORDER=0 BORDER=0>');
    document.writeln('<FRAME SRC=' + FRAME + ' NAME=navbar scrolling=auto>');
    document.writeln('<FRAME SRC=' + CUR_URL + ' NAME=main MARGINWIDTH=8 MARGINHEIGHT=3 SCROLLING=AUTO NORESIZE=NORESIZE>');
    document.writeln("</FRAMESET>");
    document.writeln("<NOFRAMES><BODY>Ihr Browser unterst&uuml;tzt keine Frames.</BODY>");
    document.writeln("</HTML>");
    document.close();

    if(document.all)  {
//   alert("Aha, Microsoft!"); 
	parent.frames[1].location.href=CUR_URL;
	}
}

// NO CHANGES BELOW
function Home()  {
    HOME = Adopt_URL(HOME);
    if(top.frames.length > 0)  {  
	parent.frames[1].location.href=HOME;
	FRAME = Adopt_URL(FRAME);
	parent.frames[0].location.href=FRAME;
    }
    else  {parent.location.href=HOME;}
}


function Navbar()  {
    if(top.frames.length > 0) /* ist aktueller Frame einziger Frame ?*/
	{  	parent.location.href=self.location }
    else {
	FRAME = Adopt_URL (FRAME);
	// change the current url in navigator to frameset index !!!!
	// wrong URL!!!!!
	lang = Check_Lang()
	if (lang== "d") { FS_T = FS_Td ;}
	if (lang== "e") { FS_T = FS_Te ;}
 	Write_Frameset(FRAME, CUR_URL, FS_T)
	}
}


function ubers(Ziel) {
    CUR_URL = Get_Url()
    Ergebnis = CUR_URL.match(/.htm$/g);
    if(Ergebnis == ".htm")  {
	alert("Dieses Dokument hat die *.htm Bezeichnung! Die übersetzungsfunktion funktioniert daher möglicherweise nicht! Bitte mailen Sie die angewählte Adresse dem Webmaster. Danke\n This Ducument has a confusing name (*.htm)! Owing to this problem the translating function may refuse to work. Please read the help page and/or inform the webmaster. Thank You!\n");
    }

    /*CALCULATE NewUrl */
    Check_Lang()	
    if (lang== "d" && Ziel == 0) {NewUrl = CUR_URL;}
    if (lang== "d" && Ziel == 1) {NewUrl = CUR_URL.replace (/.html/, "-e.html");}
    if (lang== "d" && Ziel == 2) {NewUrl = CUR_URL.replace (/.html/, "-fr.html");}
    if (lang== "e" && Ziel == 0) {NewUrl = CUR_URL.replace (/-e.html/, ".html");}
    if (lang== "e" && Ziel == 1) {NewUrl = CUR_URL;}
    if (lang== "e" && Ziel == 2) {NewUrl = CUR_URL.replace (/-e.html/, "-fr.html");}
    if (lang== "fr" && Ziel == 0){NewUrl = CUR_URL.replace (/-fr.html/, ".html");}
    if (lang== "fr" && Ziel == 1){NewUrl = CUR_URL.replace (/-fr.html/, "-e.html");}
    if (lang== "fr" && Ziel == 2){NewUrl = CUR_URL;}
    window.location.href = NewUrl;

    // Falls navbar, die auch uebersetzen:
    if(top.frames.length > 0)  { 
    	var CUR_URL = document.URL;
	if(Ziel == 1)  {framesrc = FRAME.replace (/.html/, "-e.html");}
	else  {if(Ziel == 2)  {
		framesrc = FRAME.replace (/.html/, "-fr.html");}
	       else  {framesrc = FRAME;}	
	}
    parent.frames[0].location.href=framesrc; // Skript f.2Frames gleichzeitig
    }
}


function LLink (URL, Anker)  {
// normal link which changes the language of navbar if necessary
    window.location.href = URL;

    // Falls navbar:
    if(top.frames.length > 0)  {
	Ergebnis = URL.match(/-e.htm/g);
	if(Ergebnis == "-e.htm")
		{aiml = "e";}
	else {
		Ergebnis = URL.match(/-fr.htm/g);
		if(Ergebnis == "-fr.htm")
			{aiml = "fr";}
		else  {aiml = "d";}	
	}
    FRAME = Adopt_URL(FRAME,aiml);
    parent.frames[0].location.href=FRAME;
    }
}


function Get_Url () {
    var CUR_URL = document.URL;
    CUR_URL = CUR_URL.replace (/\/$/, "/" + SERV_DIR);
    CUR_URL = CUR_URL.replace (/\/.$/, "/" + SERV_DIR);
    CUR_URL = CUR_URL.replace (/\/#/, "/" + SERV_DIR + "#");
    //alert ("Modified CUR_URL: " + CUR_URL);
    return CUR_URL;
}


function Check_Lang()  {// In welcher Sprache ist das Dokument? 
			// (nicht immer FRAME 1)
    Ergebnis = CUR_URL.match(/-e.htm/g);
    if(Ergebnis == "-e.htm")  { lang = "e" }
	else  {
	    Ergebnis = CUR_URL.match(/-fr.htm/g);
	    if(Ergebnis == "-fr.htm") { lang = "fr" }
	else  {lang = "d"}	
	}
    return lang;
}


function Adopt_URL(URL,aiml)  {
// translates URL in the language of Mainframe or lang in aiml
    if (!aiml)       { Check_Lang() }
    else	     { lang = aiml  }
    if(lang == "e")  { URL = URL.replace (/.html/, "-e.html")  }
    if(lang == "fr") { URL = URL.replace (/.html/, "-fr.html") }
    return URL;
}

