var nav_active = 0;
var nav_hideTime = 0;
var nav_timeout = 500;
var btn = 0;

function navig(button, subnavig) {
	var subnavig = document.getElementById(subnavig);
	var button = document.getElementById(button);
	
	if((button == 0) || (subnavig == 0)) { return }
		
	button.active = function(subnavig) {
		var pos = position(this);
		if(pos.top == 0) { //IE5MAC_FIX
			pos.top = -10;
		}
		
		subnavig.style.display = 'inline';
		nav_active = subnavig;
		btn = this;
		
		if (btn.className == 'normal') this.className = 'over';
	}
	
	button.onmouseover = function() {
		if (btn == 0) btn = this;
		if (btn.className != 'active') btn.className = 'normal';
		if (nav_active) nav_active.style.display = 'none';

		this.active(subnavig);
	
		if(nav_hideTime == 0) { return }
	
		clearTimeout(nav_hideTime);
	}
	
	subnavig.onmouseover = function() {
		if(nav_hideTime == 0)	{ return }
		clearTimeout(nav_hideTime);
	}

	button.onmouseout = function() {
		nav_hideTime = setTimeout('hide()', nav_timeout);
	}
	
	subnavig.onmouseout = function() {
		nav_hideTime = setTimeout('hide()', nav_timeout);
	}
}

function hide() {
	if(nav_active) {
		if (btn.className == 'over') btn.className = 'normal';
		nav_active.style.display = 'none';
	}
}

function position(element) {
	var left = -4;
	var top = 5;
	while(element != null) {
		left += element.offsetLeft;
		top  += element.offsetTop;
		element = element.offsetParent;
	}
	return { left:left,top:top }
}




var nav_active1 = 0;
var nav_hideTime1 = 0;
var nav_timeout1 = 100;
function navig1(subnavig1, subnavig2) {
	var subnavig1 = document.getElementById(subnavig1);
	var subnavig2 = document.getElementById(subnavig2);

	if((subnavig1 == 0) || (subnavig2 == 0)) { return }
	
	subnavig1.active = function(subnavig2) {
		var pos = position(this);
		if(pos.top == 0) { //IE5MAC_FIX
			pos.top = -10;
		}
		if(navigator.userAgent.toLowerCase().indexOf("gecko") > -1) {
			subnavig2.style.display = 'inline';
			nav_active1 = subnavig2;
		}
		else {
			subnavig2.style.display = 'inline';
			nav_active1 = subnavig2;
		}
	}
	
	subnavig1.onmouseover = function() {
		if (nav_active1) {
			nav_active1.style.display = 'none';
		}
		
		this.active(subnavig2);
	
		if(nav_hideTime1 == 0) { return }
	
		clearTimeout(nav_hideTime1);
	}
	
	subnavig2.onmouseover = function() {
		if(nav_hideTime1 == 0)	{ return }
		clearTimeout(nav_hideTime1);
	}

	subnavig1.onmouseout = function() {
		nav_hideTime1 = setTimeout('hide1()', nav_timeout1);
	}
	
	subnavig2.onmouseout = function() {
		nav_hideTime1 = setTimeout('hide1()', nav_timeout1);
	}
}

function hide1() {
	if(nav_active1) {
		nav_active1.style.display = 'none';
	}
}



var nav_activeLang = 0;
var nav_hideTimeLang = 0;

function navigLang(btnSprache, subSprache) {
	var btnSprache = document.getElementById(btnSprache);
	var subSprache = document.getElementById(subSprache);
	
	if ((btnSprache == 0) || (subSprache == 0)) return;
		
	btnSprache.active = function(subSprache) {
		var pos = position(this);
		if (pos.top == 0) pos.top = -10; //IE5MAC_FIX
		
		subSprache.style.display = 'inline';
		nav_activeLang = subSprache;
	}
	
	btnSprache.onclick = function() {
		if (subSprache.style.display == '' || subSprache.style.display == 'none') {
			if (nav_activeLang) nav_activeLang.style.display = 'none';
			this.active(subSprache);
			if (nav_hideTimeLang == 0) return;
			clearTimeout(nav_hideTimeLang);
		}
		else {
			nav_hideTimeLang = setTimeout('hideLang()', 0);	
		}
	}
	
	btnSprache.onmouseover = function() {
		if (nav_hideTimeLang == 0)	return;
		clearTimeout(nav_hideTimeLang);
	}

	subSprache.onmouseover = function() {
		if (nav_hideTimeLang == 0)	return;
		clearTimeout(nav_hideTimeLang);
	}

	btnSprache.onmouseout = function() {
		nav_hideTimeLang = setTimeout('hideLang()', 500);
	}
	
	subSprache.onmouseout = function() {
		nav_hideTimeLang = setTimeout('hideLang()', 500);
	}
}

function hideLang() {
	if (nav_activeLang) nav_activeLang.style.display = 'none';
}




var win = null;
function fenster(mypage, myname, w, h, scroll, pos) {
	if (pos == "random") {
		LeftPosition = (screen.width)  ? Math.floor(Math.random() * (screen.width-w)):100; 
		TopPosition  = (screen.height) ? Math.floor(Math.random() * ((screen.height-h)-75)) : 100;
	}
	if (pos=="center") {
		LeftPosition = (screen.width)  ? (screen.width-w)/2 : 100;
		TopPosition  = (screen.height) ? (screen.height-h)/2 : 100;
	}
	else if ((pos != "center" && pos != "random") || pos==null) {
		LeftPosition = 0;
		TopPosition  = 20
	}
	settings = 'width=' + w + ',height=' + h + ',top=' + TopPosition + ',left=' + LeftPosition + ', scrollbars=' + scroll + ',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win = window.open(mypage,myname,settings);
	if(win.focus){win.focus();
	}
}

function screen_open(prod,w,h) {
	fenster('img/screenshots/' + prod + '/','screen',w,h,'yes','center');
}


function calcPrices() {
	var url = "bestellung_calculate-prices.html";
	var len = document.bestellform.elements.length;
	var vars = "";

	for (var i=0; i<len; i++) {
		var e = document.bestellform.elements[i];
		
		if (e.name != "submit") {
			if (vars != "") {
				vars += "&";
			}
			vars += e.name;
			vars += "=";
			vars += e.value;
		}
	}

	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} 
	else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		alert("Fehler bei Request!");
	}

	if (req) {
		req.onreadystatechange = calcPricesRet;
		req.open("POST", url);
		req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		req.send(vars);
	}
}


function calcPricesRet() {
	if (req.readyState == 4) {
		if (req.status == 200) {
			var erg = req.responseText.split('&&&');
			var mengen = erg[1].split('___');
			var preise = erg[2].split('___');
			var praemie = erg[3].split('___');
			
			
			for (var i=0; i<mengen.length; i++) {
				var feld = mengen[i].split('=');
				document.getElementById(feld[0]).value = feld[1];
			}
			
			for (var j=0; j<preise.length; j++) {
				var feld = preise[j].split('=');
				document.getElementById(feld[0]).innerHTML = feld[1];
			}
			
			// ÄNDERUNG LOADER ANZEIGEN VOR GUTSCHEINWERT
			//document.getElementById('gutscheinwert').innerHTML = praemie;
			
			if (document.getElementById('nobonus').checked) {
				document.getElementById('gutscheinwert').innerHTML = '0,00 EUR';
			} else {
				document.getElementById('gutscheinwert').innerHTML = '<img src="img/loading.gif" alt="" height="17px" />';
				window.setTimeout(function xy() { showPraemie(praemie);}, 800);
			}
						
			//Eventuell Meldung anzeigen
			if (erg[0] != "") {
				alert(erg[0]);
			}
			return true;
		} 
		else return false;
	}
}

function showPraemie(praemie) {
	document.getElementById('gutscheinwert').innerHTML = praemie;	
}

function checkMenge() {
	if (document.getElementById('menge_fpkont').value >= 100) {
		document.getElementById('bestellerror').innerHTML = '';
	}
	else if (document.getElementById('menge_bakont').value >= 100) {
		document.getElementById('bestellerror').innerHTML = '';
	}
}

function getFlashMovie(movieName) { 
	var isIE = navigator.appName.indexOf("Microsoft") != -1; 
	return (isIE) ? window[movieName] : document[movieName]; 
}


function showFrame(w) {
	document.getElementById('inner').style.width = w + 'px';
	document.getElementById('htmlFrame').style.display = 'block';
}


function hideFrame() {
	getFlashMovie('app').hideBack();
	document.getElementById('html').src = '';
	document.getElementById('htmlFrame').style.display = 'none';
}

// ******************************************** //
// GOOGLE MAPS KARTENDARSTELLUNG
// ******************************************** //
function showMap(file, user) {
	
	// Variablen setzen
	var client = 'gme-databytegmbh';
	var sensor = 'false';
	var apiKey = '';
	  	
	// HTML-Text für MapContainer
	var htmlText = '<div id="map" name="map">'
							 + '	<object id="googleMapsApp" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="100%" height="100%">'
							 + '		<param name="movie" value="../swf/karte/karte.swf" />'
							 + '		<param name="quality" value="high" />'
							 + '		<param name="flashvars" value="client=' + client + '&sensor=' + sensor + '&apiKey=' + apiKey + '&user=' + user + '&file=' + file + '" />'      																								 
							 + '		<embed width="100%" height="100%" src="../swf/karte/karte.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" flashvars="client=' + client + '&sensor=' + sensor + '&apiKey=' + apiKey + '&user=' + user + '&file=' + file + '">'
							 + '		</embed>'
							 + '	</object>'
							 + '</div>'; 	
	
	// HTML-Container laden
	document.getElementById('mapFrame').style.display = 'block';
	
	// Google Karte laden
  document.getElementById('map_container').innerHTML = htmlText;	
}

function hideMap() {
	getFlashMovie('app').hideBack();
	document.getElementById('mapFrame').style.display = 'none';
}