//var fBestellpreis = 0;

function addEventsNaturparke() {
	var a,i,o;
	
	if ( o = fkt.gE( "map" ) ) { 
		setTimeout("initialize();",1000);
		window.onunload = function() { GUnload(); };
	}
	
	if ( o = fkt.gE('loginForm_member') ) { o.onsubmit = checkLogin; }
	
	if ( o = fkt.gE('headerbilder') ) {
	
		a = o.getElementsByTagName('span');
		if ( a.length > 0 ) {
			fadingHeader(o,a);
		}
	}
	
	if ( o = fkt.gE('logo')  ) {
		o.onclick = function() { 
			if ( fkt.gE('header_oben').className.indexOf( "_en" ) == -1 ) 
				document.location.href=this.href; 
			else 
				document.location.href=this.href+'/en'; 
			return false; 
		}
	}
	
	a = document.getElementsByTagName( "a" );
	for (i=0; i<a.length; i++) {
		if ( a[i].rel == "external" ) {
				a[i].onclick = openExternal;
		}
	}
	
	if ( o = fkt.gE('navigation') ) {
		a = o.getElementsByTagName('a');
		for ( i=0; i<a.length; i++ ) {
			addMenueFunc( a[i] );
		}
	}
	
	if ( o = fkt.gE( 't_neuigkeiten' ) ) {
		a = o.getElementsByTagName('div');
		for ( i=0; i<a.length; i++ ) {
			if ( o = a[i].getAttribute('js_url') && o != '' ) {
				a[i].onclick = function () { document.location.href='/'+this.getAttribute('js_url'); }
			}
		}
	}
	
	if ( o = fkt.gE( 'publikationenuebersicht' ) ) {
		a = o.getElementsByTagName('div');
		for ( i=0; i<a.length; i++ ) {
			if ( o = a[i].getAttribute('js_url') && o != '' ) {
				a[i].onclick = function () { document.location.href='/'+this.getAttribute('js_url'); }
			}
		}
	}

	
	if ( o = fkt.gE( 't_termine' ) ) {
		a = o.getElementsByTagName('div');
		for ( i=0; i<a.length; i++ ) {
			if ( o = a[i].getAttribute('js_url') && o != '' ) {
				a[i].onclick = function () { document.location.href='/'+this.getAttribute('js_url'); }
			}
		}
	}
	
	if ( o = fkt.gE( 'neuigkeiten_overview' ) ) {
		a = o.getElementsByTagName('div');
		for ( i=0; i<a.length; i++ ) {
			if ( o = a[i].getAttribute('js_url') && o != '' ) {
				a[i].onclick = function () { document.location.href='/'+this.getAttribute('js_url'); }
			}
		}
	}	
	
	o = fkt.gE('navigation');
	if ( o && config.isIE ) {
		//var uls = new Array();
		a = o.getElementsByTagName('ul');
		for ( i=0; i<a.length; i++ ) {
			x = a[i].getElementsByTagName('a');
			for ( j=0; j<x.length; j++ ) {
				width_ul = parseInt( x[j].parentNode.parentNode.getAttribute('js_width') );
				if ( isNaN( width_ul ) ) width_ul = 0;
				if ( config.isIE && x[j].parentNode.getElementsByTagName('ul').length > 0 ) {
					x[j].parentNode.style.marginBottom = '-3px';
				}
				if ( (width_ul < x[j].clientWidth) ) x[j].parentNode.parentNode.setAttribute('js_width', x[j].clientWidth ); //x[j].parentNode.parentNode.style.width = x[j].clientWidth + 'px';
			}
		}
		for ( i=0; i<a.length; i++ ) {
			a[i].style.width = a[i].getAttribute('js_width') + 'px';
		}
	} 
}

function addEventsAJAX() {
	//fkt.addStdMouseOver();

}


function closeAllMenues( o ) {
	var a, i;
	window.clearInterval( config.cInt['navi'] );
	if ( o == false ) o = fkt.gE('navigation');
	a = o.getElementsByTagName( 'ul' );
	for (i=0;i<a.length;i++) {
		if ( config.isIE ) {
			if ( a[i].parentNode.parentNode.id == 'navigation' ) {
				closeAllMenues( a[i] );
			}
		}
		//a[i].style.display = 'none';
		a[i].style.visibility = 'hidden';
	}
	a = o.getElementsByTagName( 'a' );
	for (i=0;i<a.length;i++) {
		a[i].className = '';
	}
}

function showMenue( a ) {
	var li = a.parentNode;
	var a = li.getElementsByTagName( 'a' );
	a[0].className = 'overaktiv';
	var ul = li.parentNode;
	if ( ul.id != 'navigation' ) {
		//ul.style.display = 'block';
		ul.style.visibility = 'visible';
		showMenue( ul );
	}
}

function addMenueFunc( a ) {
	
	a.onmouseover = function() { 
		window.clearInterval( config.cInt['navi'] );
		closeAllMenues(false);
		showMenue( this );
		var ul = this.parentNode.getElementsByTagName('ul');
		if ( ul.length > 0 ) { 
			if ( this.parentNode.parentNode.id != 'navigation') ul[0].style.left = this.offsetWidth+'px';
			//ul[0].style.display = 'block';
			ul[0].style.visibility = 'visible';
		}
	}

	a.onmouseout = function() {
		config.cInt['navi'] = window.setInterval( 'closeAllMenues(false);', 300 );
	}
	
}

function changeOpacity(o,op) {
	if ( isIE ) {
		o.style.filter = 'alpha(opacity='+(Math.round(op*100))+')';
	} else {
		o.style.opacity = op;
	}
}

var aHeaderPix = new Array(), fadeCount = 0, iAktuell = 0;
function fadingHeader(o,a) {
	var img, ax = new Array();
	for (var i=0; i<a.length; i++ ) {
		aHeaderPix[aHeaderPix.length] = a[i].innerHTML;
	}
	o.innerHTML = '<img src="'+a[0].innerHTML+'" id="headerbild2" />' + o.innerHTML;
	img = o.getElementsByTagName( 'img' );
	aHeaderPix[aHeaderPix.length] = img[1].src;
	img[1].id = 'headerbild1';
	config.cInt['header'] = window.setInterval( 'fadeHeader()', 50 ); 
}

function fadeHeader() {
	fadeCount -= 5;
	if ( fadeCount > 0 ) {
		changeOpacity( fkt.gE('headerbild1'), fadeCount/200 );
	} else if ( fadeCount == 0 ) {
		fkt.gE('headerbild1').src = fkt.gE('headerbild2').src;
		iAktuell++;
		if ( iAktuell >= aHeaderPix.length ) iAktuell = 0;
		setTimeout("changeOpacity( fkt.gE('headerbild1'), 1 );",500 );
		setTimeout("fkt.gE('headerbild2').src = aHeaderPix[ "+iAktuell+" ]",2000 );
	} else if ( fadeCount < -400 ) {
		fadeCount = 200;
	}
}


var importJS = {"urls": ["/scripts/config_frontend.js","/scripts/classes/fkt.js","/scripts/main.js","/scripts/mootools-release-1.11.js", "/scripts/slimbox.js","/scripts/Base.js","/scripts/Async.js","/scripts/classes/cAjaxJson.js"]};
for (var i=0;i<importJS.urls.length;i++) document.write('<script type="text\/javascript" src="'+importJS.urls[i]+'"><\/script>');

function checkSearch( f ) {
	
		if ( f.searchString.value != "" ) return true;
		f.searchString.focus();
		return false;
}


function openExternal() {
	window.open( this.href, "", "" );
	return false;
}

function checkLogin() {
	var j = {"nick":this.elements['username_member'].value, "password":this.elements['password_member'].value};
	cAjaxJson.ajaxRequest("login_member",j,'Logindaten werden &uuml;berpr&uuml;ft.<br />Bitte haben Sie etwas Geduld.');
	return false;
}

function login_member(d) {
		var div, o;
		if (d.error) {
			cAjaxJson.xmlhttperror( d.error );
		}	else {
			createHTMLBox( true, config.standardAjaxMsgTitle, 'Sie werden automatisch weitergeleitet.', config.standardAjaxMsgWidth, config.standardAjaxMsgHeight, false, false, false, true );
  		document.location.href = '/de/Mitglieder/' + d.url;
		}
}

function logout() {
		cAjaxJson.confirmBox( 'Wollen Sie wirklich ausloggen?', 'confirmJaLogout' );
		return false;
}

function confirmJaLogout() {
	document.location.href = 'logout.php';
}

function checkAnmeldungSend( f ) {
	if ( (f.personen.value * 1) > 100 || isNaN( f.personen.value * 1 ) || f.land.value.length < 3 || f.telefon.value.length < 3 ||  f.ort.value.length < 3 || f.plz.value.length < 3 || f.adresse.value.length < 3 || f.vorname.value.length < 3 || f.nachname.value.length < 3 || f.email.value.length < 7 || f.email.value.indexOf("@") == -1 ) {
		alert( "Bitte füllen Sie alle Pflichtfelder aus." );
		return false;
	} 
	return true;
}


function checkBestellungSend( f ) {
	if ( (f.stueckzahl.value * 1) > 100 || isNaN( f.stueckzahl.value * 1 ) || f.land.value.length < 3 || f.telefon.value.length < 3 ||  f.ort.value.length < 3 || f.plz.value.length < 3 || f.adresse.value.length < 3 || f.vorname.value.length < 3 || f.nachname.value.length < 3 || f.email.value.length < 7 || f.email.value.indexOf("@") == -1 ) {
		alert( "Bitte füllen Sie alle Pflichtfelder aus." );
		return false;
	} 
	return true;
}
