var z = 1;
var ldstat;
var ht = null;
var htvt = null;
var htPost = null;
var text1;

function init() {
	ldImg();
	document.getElementById('wetter').style.display = 'block';
	mkHyph();
}

function prStart() {
	mkHyph();
	setTimeout( 'self.print()', 2000 );
}

function ldImg() {
	var ah = new Image(); ah.src = 'grafiken/_ahover.gif';
	var bh = new Image(); bh.src = 'grafiken/_bhover.gif';
	var ch = new Image(); ch.src = 'grafiken/_chover.gif';
	var dh = new Image(); dh.src = 'grafiken/_dhover.gif';
	var eh = new Image(); eh.src = 'grafiken/_ehover.gif';
	var fh = new Image(); fh.src = 'grafiken/_fhover.png';
	var mh = new Image(); mh.src = 'grafiken/_mhover.gif';
	var ph = new Image(); ph.src = 'grafiken/_phover.gif';
	var p2 = new Image(); p2.src = 'grafiken/drucker_h.gif';
	var c2 = new Image(); c2.src = 'grafiken/xh.gif';
	var ka = new Image(); ka.src = 'grafiken/klapp_auf_h.gif';
	var kz = new Image(); kz.src = 'grafiken/klapp_zu_h.gif';
	var sp = new Image(); sp.src = 'grafiken/post_h.gif';
}

function mkHyph() {
	var ua = navigator.userAgent.toLowerCase();
	if( document.createElement && ua.indexOf('firefox/2') == -1 && ua.indexOf('firefox/1') == -1 && ua.indexOf('firefox/0') == -1 ) {
		var head = document.getElementsByTagName('head').item(0);
		var script = document.createElement('script');
		script.type = 'text/javascript';
		script.src = 'hyph.js';
		head.appendChild(script);

		ld = setInterval( function() {
			try {
				throw ldstat;
			} catch(e) {
				if( e == 'ok' ) {
					Hyphenator.hyphenateDocument( 4, '­' );
					clearInterval(ld);
				}
			}
		}, 100 );
	}
}

function zaehler( sw ) {
	document.getElementById( 'zaehler' ).style.display = sw > 0 ? 'none' : 'block';
	document.getElementById( 'besucher' ).style.display = sw > 0 ? 'block' : 'none';
}

function bild( pic, breite, hoehe ) {
	var links = parseInt(( screen.availWidth - breite ) / 5 );
	var oben = parseInt(( screen.availHeight - hoehe ) / 5 );
	if( open( '../bild.php?pic=' + pic, 'Bild' + pic.replace( /\./, '' ), 'width=' + breite + ',height=' + hoehe + ',left=' + links + ',top=' + oben + ',resizable' )) return false;
	else return true;
}

function og( nr ) {
	return popup( 'ortsgruppen/portrait.php?ogid=' + nr, 'portrait' + nr, 700, 480 );
}

function special( sp, og ) {
	return popup( 'special.php?sp=' + sp + '&og=' + og, 'special', 760, 480 );
}

function popup( url, name, breite, hoehe ) {
	var links = parseInt(( screen.availWidth - breite ) / 2 );
	if( links < 0 ) links = 0;
	var oben = parseInt(( screen.availHeight - hoehe - 60 ) / 2 );
	if( oben < 0 ) oben = 0;
	if( open( url, name, 'width=' + breite + ',height=' + hoehe + ',left=' + links + ',top=' + oben + ',resizable,scrollbars' )) return false;
	return true;
}

function mkTipp( vt ) {
	if( window.XMLHttpRequest ) htvt = new XMLHttpRequest();
	else if( window.ActiveXObject ) htvt = new ActiveXObject( "Microsoft.XMLHTTP" );

	if( htvt != null ) {
		htvt.open( 'post', 'tipps.php', true );
		htvt.setRequestHeader( 'content-type', 'application/x-www-form-urlencoded' );
		htvt.onreadystatechange = function() {
			if( htvt.readyState == 4 ) {
				document.getElementById( 'vt_auf' + vt ).style.display = 'none';
				document.getElementById( 'vt_zu' + vt ).style.display = 'block';
				document.getElementById( 'vt_pr' + vt ).style.display = 'inline';
				document.getElementById( 'vt_text' + vt ).style.display = 'block';
				document.getElementById( 'vt_text' + vt ).innerHTML = htvt.responseText;
				if( ldstat == 'ok' ) Hyphenator.hyphenateDocument( 4, '­' );
			};
		}
		htvt.send( 'vtid=' + vt );
		return false;
	}
	return true;
}

function shPost( id ) {
	var pa = document.getElementById( 'post' + id );
	var shpa = document.getElementById( 'shpost' + id );

	if( pa.innerHTML != '' ) {
		pa.innerHTML = '';
		pa.style.display = 'none';
		shpa.title = 'Postanschrift anzeigen';
	} else {
		if( window.XMLHttpRequest ) htPost = new XMLHttpRequest();
		else if( window.ActiveXObject ) htPost = new ActiveXObject( "Microsoft.XMLHTTP" );

		if( htPost != null ) {
			htPost.open( 'post', 'adressen/post.php', true );
			htPost.setRequestHeader( 'content-type', 'application/x-www-form-urlencoded' );
			htPost.onreadystatechange = function() {
				if( htPost.readyState == 4 ) {
					pa.innerHTML = htPost.responseText;
					pa.style.display = 'block';
					shpa.title = 'Postanschrift verbergen';
				};
			}
			htPost.send( 'ppx=' + id );
		}
	}
}

function rmTipp( vt ) {
	document.getElementById( 'vt_auf' + vt ).style.display = 'block';
	document.getElementById( 'vt_zu' + vt ).style.display = 'none';
	document.getElementById( 'vt_pr' + vt ).style.display = 'none';
	document.getElementById( 'vt_text' + vt ).style.display = 'none';
	document.getElementById( 'vt_text' + vt ).innerHTML = '';
	return false;
}

function prTipp( vt ) {
	return popup( 'vtprint.php?vtid=' + vt, 'vt' + vt, 640, 480 );
}

function blaettern( name, x, max ) {
	z += x;
	if( z > max ) z = 1;
	if( z < 1 ) z = max;
	document.pics.src = name + z + '.jpg';
}

function drucken( inc ) {
	text1 = document.getElementById('inhalt').innerHTML;
	var text2 = text1.replace( /»/g, '&bdquo;' );
	text2 = text2.replace( /«/g, '&ldquo;' );
	document.getElementById('inhalt').innerHTML = text2;
	self.print();
	if( inc != 3 && inc != 12 ) setTimeout( 'gedruckt()', 3000 );
}

function gedruckt() {
	document.getElementById('inhalt').innerHTML = text1;
}