/*
window.onload = function(){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			getSizes();
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
		 	//getSizesIE();
		}
	}
}
*/

window.onresize = function(){
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") {
			getSizes();
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
		 	getSizesIE();
		}
	}
}

var startHeight;

function getSizes(){
	windowHeight = window.innerHeight;
	contentEl = document.getElementById("content");
	startHeight =  startHeight== null ? contentEl.offsetHeight: startHeight;
	
	//alert ((startHeight+210)+" "+windowHeight);
	if (windowHeight - (startHeight+210) > 0){
		contentEl.style.height = (windowHeight-210)+"px";
	}
	
	
	/*
	if (startHeight < window.innerHeight){
		myBody.style.height = (window.innerHeight-10)+"px";
		myNav = document.getElementById("navigationContainer");
		//navStartHeight = navStartHeight == null ? myNav.offsetHeight : navStartHeight;
		myNav.style.height = (window.innerHeight-140)+"px";
		document.getElementById("contact").style.bottom = "0";
	}
	else {
		myBody.style.height = (startHeight-10)+"px";
		myNav = document.getElementById("navigationContainer");
		//navStartHeight = window.innerHeight-140;
		myNav.style.height = (startHeight-140)+"px";
		document.getElementById("contact").style.bottom = "0";
	}*/
	
}


function checkCookie(){
	return navigator.cookieEnabled;
}

function setCookie(uuid){
	if (checkCookie()){
		if (confirm("Wollen Sie Auswahl als Cookie abspeichern\num bei Ihrem n"+unescape("%E4")+"chsten Besuch direkt zur\nausgew"+unescape("%E4")+"hlten Seite zu gelangen?") == true){
			var now = new Date();
			var year = now.getTime() + (365 * 24 * 60 * 60 * 1000);
			now.setTime(year);
			document.cookie = "npData="+uuid+"; expires="+now.toGMTString();
			return true;
		}
		else{
			return true;
		}
	}
}

function checkNumber(el){
	el.value = trim(el.value);
	checkZero(el);
	if (isNaN(el.value)){
		while (isNaN(el.value)){
			el.value = el.value.substring(0, el.value.length-1);
		}
		el.focus();
		return false;
	}
	return true;
}

function checkZero(el){
	if (el.value.length > 1){
		if (el.value.substring(0,1) == 0){
			if (!isNaN(el.value.substring(1,2))){
				el.value = el.value.substring(1,el.value.length);
				while(el.value.substring(1,2) == 0 && el.value.length > 1){
					el.value = el.value.substring(1,el.value.length);
				}
			}
		}
	}
}

function trim(string){
	while (string.substring(0,1) == ' '){
		string = string.substring(1,string.length);
	}
	while (string.substring(string.length-1,string.length) == ' '){
		string = string.substring(0,string.length-1);
	}
	return string;
}



function convert(){
	if (document.getElementById("convertinput")){
		if (checkNumber(document.getElementById("convertinput"))){
			var value = 0;
			var factor = 0;
			value = document.getElementById("convertinput").value;
			factor = document.getElementById("convertselect").value;
			if (!isNaN(factor)){
				var result=parseFloat(eval(value*factor));
			}
			else{
				if (factor == 'c'){
					if (value < -273.15){
						var result = "Ulknudel";
					}
					else{
						var result=parseFloat((value*9/5)+32);
					}
				}
				else if (factor == 'f')
					if (value < -459.67){
						var result = "Ulknudel";
					}
					else{
						var result=parseFloat((value-32)*5/9);
					}
			}
			document.getElementById("resultContainer").innerHTML = Math.round(result*1000)/1000;
		}
	}
}


function calculateWaterConservation(){
		
		faktor1=document.getElementById("count").value;
		faktor2=document.getElementById("time").value;
		faktor3=365;
		wpreis=document.getElementById("price").value;
		std_faktor=13.5;
		
		if (document.getElementById("cascade0").checked)
			cascade_faktor=document.getElementById("cascade0").value;
		
		if (document.getElementById("cascade1").checked)
			cascade_faktor=document.getElementById("cascade1").value;
		
		var std_verbrauch=faktor1*faktor2*faktor3*std_faktor;
		var std_kosten=std_verbrauch*wpreis/1000;
		
		var cascade_verbrauch=faktor1*faktor2*faktor3*cascade_faktor;
		var cascade_kosten=cascade_verbrauch*wpreis/1000;
		
		var erspart=std_kosten-cascade_kosten;
		
		document.getElementById("stdLiter").innerHTML=Math.round(std_verbrauch*100)/100;
		document.getElementById("stdMoney").innerHTML=Math.round(std_kosten*100)/100;
		
		document.getElementById("wsLiter").innerHTML=Math.round(cascade_verbrauch*100)/100;
		document.getElementById("wsMoney").innerHTML=Math.round(cascade_kosten*100)/100;
		document.getElementById("saved").innerHTML=Math.round((Math.round(std_kosten*100)/100 - Math.round(cascade_kosten*100)/100)*100)/100;
		setzeWaehrung();
}

function setzeWaehrung()
{
    var waehrung = document.getElementById('waehrung').value;
    document.getElementById('smoney0').innerHTML = waehrung;
    document.getElementById('smoney1').innerHTML = waehrung;
    document.getElementById('smoney2').innerHTML = waehrung;
}

var activePoint = null;
var activeDescription = null;
var activeNav = null;

function showNode(id){
	if (activePoint != null)
		activePoint.src= '/docroot/neoperl/imgs/grau.gif';
	if (activeDescription != null)
		activeDescription.style.display = 'none';
	if (activeNav != null)
		activeNav.className = "";

	newPoint = document.getElementById('jch-'+id);
	activePoint = newPoint;
	newPoint.src = '/docroot/neoperl/imgs/rot.gif';
	
	newDescription = document.getElementById('desc-'+id);
	activeDescription = newDescription;
	newDescription.style.display="block";
	
	newNav = document.getElementById('nav-'+id);
	activeNav = newNav;
	newNav.className="active";
}
