// JS für die Skalierung von "deine-reiseversicherung.de"

function Fensterweite() {
	var x;
	
	if ( Firefox_erkennen() ) {
		x = document.body.clientWidth;
	} else {
		if (self.innerWidth) // all except Explorer
		{ x = self.innerWidth; } else if (document.documentElement && document.documentElement.clientHeight)
		// Explorer 6 Strict Mode
		{ x = document.documentElement.clientWidth; } else if (document.body) // other Explorers
		{ x = document.body.clientWidth; }
	}
	return x;
}

function Fensterhoehe() {
	var y;
	
	if (self.innerHeight) // all except Explorer
	{ y = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{ y = document.documentElement.clientHeight; } else if (document.body) // other Explorers
	{ y = document.body.clientHeight; }

	return y;
}

function neuAufbau() {

	// var blTest1 = true;
	var blTest1 = false;
	
	var WeiteMin = 800;
	var HoeheMin = 700;
	var HoeheMin_2 = 0;
	
	var BreiteSpalten = 440;
	
	var MonitorKlein_w = 1024;
	var MonitorGross_w = 1024;
	
	var MonitorKlein_h = 768;
	var MonitorGross_h = 850;
	
	Weite = Fensterweite(); // Global
	Hoehe = Fensterhoehe(); // Global
	
	// EIGENSCHAFTEN WERDEN NUR GELESEN:
	var Kopf = document.getElementById("Kopf");
	
	// EIGENSCHAFTEN WERDEN VERÄNDERT:
	var Haupt = document.getElementById("Haupt");
	var Links = document.getElementById("Links");
	var Mitte = document.getElementById("Mitte");
	var Rechts = document.getElementById("Rechts");
	var Unten = document.getElementById("Unten");
	
	var Linkleiste = document.getElementById("Linkleiste");
	
	var html = document.getElementsByTagName("html")[0];
	
	// Für MSIE 6:
	Haupt.style.position = "absolute";
	Haupt.style.margin = "0px";
	Haupt.style.left = "0px";
	
	Haupt.style.width = "auto";
	Haupt.style.height = "auto";
	Haupt.style.overflow = "auto";
	Mitte.style.height = "auto";
	Mitte.style.overflow = "auto";
	Links.style.height = "auto";
	Rechts.style.height = "auto";
	
	// Skalierung - Breite:
	
	if ( Hoehe > MonitorGross_h ) {
		var Abstand = Math.floor((Hoehe - MonitorGross_h) / 2);
		if ( Abstand > 40 ) {
			Abstand = 40;
		}
	}
	
	
	if ( Weite > WeiteMin ) {
		// Wenn Bildschirm > 19"
		if ( Weite > MonitorGross_w ) {
			// Haupt.style.overflow = "hidden";
			Haupt.style.left = (Weite - MonitorGross_w) / 2 + "px";
			Haupt.style.width = MonitorGross_w - 2 + "px";
			Unten.style.width = Haupt.offsetWidth - Links.offsetWidth - 34 + "px";
if (blTest1) {
alert("W 1");
}
		} else {
			Haupt.style.left = "0px";
			// Wenn Bildschirm > 17"
			if ( Weite > MonitorKlein_w ) {
				Haupt.style.width = Weite - 2 + "px";
				Unten.style.width = Haupt.offsetWidth - Links.offsetWidth - 34 + "px";
if (blTest1) {
alert("W 2");
}
			} else {
				// Wenn Bildschirm < 17"
				// if ( Weite > WeiteMin ) {
					Haupt.style.width = Weite - 2 + "px";
					Unten.style.width = Haupt.offsetWidth - Links.offsetWidth - 34 + "px";
if (blTest1) {
alert("W 3");
}
				// }
			}
		}
	}
	// --------------------
	
	// Skalierung - Höhe:
	if ( Hoehe > MonitorGross_h ) {
		// Wenn Bildschirm > 19"
		Haupt.style.overflow = "hidden";
		var HauptHoehe = Hoehe - (Abstand * 2) - 2;
		Haupt.style.top = Abstand + "px";
		Haupt.style.height = HauptHoehe + "px";
		Links.style.height = HauptHoehe - Kopf.offsetHeight + "px";
		Mitte.style.height = Links.offsetHeight - Unten.offsetHeight + "px";
		Rechts.style.height = Mitte.style.height;
if (blTest1) {
alert("H 1");
}
	} else {
		Haupt.style.top = "0px";
		if ( Hoehe > MonitorKlein_h && Hoehe > HoeheMin ) {
			// Wenn Bildschirm > 17"
			var HauptHoehe = Hoehe - 2;
			Haupt.style.height = HauptHoehe + "px";
			Links.style.height = HauptHoehe - Kopf.offsetHeight + "px";
			Mitte.style.height = Links.offsetHeight - Unten.offsetHeight + "px";
			Rechts.style.height = Mitte.style.height;
if (blTest1) {
alert("H 2");
}
		} else {
			if ( Hoehe > HoeheMin ) {
				// Wenn Bildschirm < 17"
				var HauptHoehe = Hoehe - 2;
				Haupt.style.height = HauptHoehe + "px";
				Links.style.height = HauptHoehe - Kopf.offsetHeight + "px";
				Mitte.style.height = Links.offsetHeight - Unten.offsetHeight + "px";
				Rechts.style.height = Mitte.style.height;
if (blTest1) {
alert("H 3");
}
			}
		}
	}
	// ------------------
	
	// Wenn Bildschirm (Breite & Hoehe) < Minimum
	if ( Weite <= WeiteMin ) {
		html.style.overflow = "auto";
		Haupt.style.width = WeiteMin + "px";
		Haupt.style.height = "auto";
		Haupt.style.overflow = "visible";
		Mitte.style.height = "auto";
		Mitte.style.overflow = "visible";
		Unten.style.width = Haupt.offsetWidth - Links.offsetWidth - 34 + "px";
if (blTest1) {
alert("W 4");
}
	}
	
	Haupt.style.overflow = "hidden";
	Mitte.style.width = Haupt.offsetWidth - BreiteSpalten + "px";
	
	if ( Hoehe <= HoeheMin ) {
		html.style.overflow = "auto";
		Haupt.style.height = "auto";
		Haupt.style.overflow = "visible";
		Mitte.style.height = "auto";
		Mitte.style.overflow = "visible";
		
		HoeheMin_2 = Math.max( Mitte.offsetHeight + Kopf.offsetHeight, HoeheMin );
		Links.style.height = HoeheMin_2 - Kopf.offsetHeight - 2 + "px";
		Mitte.style.height = Links.offsetHeight - Unten.offsetHeight + "px";
		Rechts.style.height = Mitte.style.height;
if (blTest1) {
alert("H 4");
}
	}
	
	if(Hoehe > HoeheMin && Weite > WeiteMin){
		html.style.overflow = "hidden";
	}else{
		html.style.overflow = "auto";
	}
}

function neuLaden() {
	if ( !Firefox_erkennen() ) {
		if ( Weite != Fensterweite() || Hoehe != Fensterhoehe() ) {
			neuAufbau();
		}
	} else {
		neuAufbau();
	}
	// Hier wird sichergestellt, dass der MSIE korrekt mit Ankern umgeht:
	var Anker = document.location.hash;
	if ( Anker != "" ) {
		location.hash = Anker;
	}
}

/* Überwachung von Netscape initialisieren */
if (!window.Weite && window.innerWidth) {
	
	var Weite;
	var Hoehe;
	
	window.onresize = neuLaden;
}

/* Überwachung von Internet Explorer initialisieren */
if (!window.Weite && document.body && document.body.offsetWidth) {
	
	var Weite;
	var Hoehe;
	
	window.onresize = neuLaden;
}

/* Zusätzliche Funktionen: */

function MSIE6_erkennen() {
	var Ausdruck = /MSIE 6/;
	var test1 = Ausdruck.test( navigator.userAgent );
	return test1;
}

function MSIE_Safari() {
	var Ausdruck = /(MSIE)|(Apple)/;
	var test1 = Ausdruck.test( navigator.userAgent );
	return test1;
}

function Firefox_erkennen() {
	var Ausdruck = /Gecko/;
	var test1 = Ausdruck.test( navigator.userAgent );
	return test1;
}

window.onresize = neuAufbau;
