var content_breite = 0;
var content_hoehe = 0;
var hoehe_center = 0;

var preloads = new Array();

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (new String(a[i]).indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if (!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i, j=0, nSrc=null, x, a=MM_swapImage.arguments;
  document.MM_sr=new Array;
  for (i=0; i<(a.length-1); i+=2) {
    if (typeof a[i] != 'object') x=MM_findObj(a[i]); else x=a[i];
    if (x!=null) {
        document.MM_sr[j++]=x;
        if (x.runtimeStyle && x.runtimeStyle.filter && x.runtimeStyle.filter.match(/src='(.*?)'/)) {
          var tmp = x.runtimeStyle.filter.match(/src='(.*?)'/);
            if (tmp != null && tmp.length == 2) {
                nSrc = tmp[1];
            }
        }
        if (nSrc != null && x.oSrc != nSrc) {
            x.oSrc = nSrc;
        } else if (!x.oSrc) {
            x.oSrc=x.src;
        }
        x.src=a[i+1];
    }
  }
}

function zentrieren() {
	var i, obj, breite, hoehe;
	
 	if (window.innerWidth) {
		breite = window.innerWidth;
  	} else if (document.body && document.body.offsetWidth) {
    	breite = document.body.offsetWidth;
	} else {
    	breite = 0;
	}

	if (window.innerHeight) {
		hoehe = window.innerHeight;
  	} else if (document.body && document.body.offsetHeight) {
    	hoehe = document.body.offsetHeight;
	} else {
    	hoehe = 0;
	}
	obj = document.getElementById("center_div");

	if (obj) {
		i = breite - content_breite;
		i = i / 2;
		if (i < 0) i = 0;

		j = hoehe - content_hoehe;
		j = j / 2;
		if (j < 0) j = 0;
	
		obj.style.left = i+"px";
		if (hoehe_center) {
			obj.style.top = j+"px";
		}
	}
}

function zentrierenBreite(breite) {
	var i, obj, tmpBreite;
	
	content_breite = breite;
	
 	if (window.innerWidth) {
		tmpBreite = window.innerWidth;
  	} else if (document.body && document.body.offsetWidth) {
    	tmpBreite = document.body.offsetWidth;
	} else {
    	tmpBreite = 0;
	}	
	
	i = tmpBreite - breite;
	i = i / 2;
	if (i < 0) i = 0;
	
	/*return i;*/
	document.write('<style type="text/css">');
	document.write('#center_div { position: absolute; left: '+i+'px; }');
	document.write('</style>');
}

function zentrierenHoehe(hoehe, vertikal) {
	var i, obj, tmpHoehe;

	content_hoehe = hoehe;
	hoehe_center = vertikal;

	if (window.innerHeight) {
		hoehe = window.innerHeight;
  	} else if (document.body && document.body.offsetHeight) {
    	hoehe = document.body.offsetHeight;
	} else {
    	hoehe = 0;
	}

	j = hoehe - content_hoehe;
	j = j / 2;
	if (j < 0) j = 0;
	
	if (!vertikal) {
		j = 0;
	} 
	
	/*return j;*/
	document.write('<style type="text/css">');
	document.write('#center_div { position: absolute; top: '+j+'px; }');
	document.write('</style>');
}

function preload() {
  if (preloads.length)
    MM_preloadImages(preloads)
}

function push_preloads() {
    for(var i=0; i<push_preloads.arguments.length; i++) {
        preloads.push(push_preloads.arguments[i]);
    }
}

function getSel()
{
	var txt = '';
	var foundIn = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
		foundIn = 'window.getSelection()';
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
		foundIn = 'document.getSelection()';
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
		foundIn = 'document.selection.createRange()';
	}
	else return;
	document.forms[0].selectedtext.value = 'Found in: ' + foundIn + '\n' + txt;
}

function addResizeEvent(func) {
  var old = window.onresize;
  if (typeof window.onresize != 'function') {
    window.onresize = func;
  } else {
    window.onresize = function(e) {
      old(e);
      func(e);
    }
  }
}

function addScrollEvent(func) {
  var old = window.onscroll;
  if (typeof window.onscroll != 'function') {
    window.onscroll = func;
  } else {
    window.onscroll = function(e) {
      old(e);
      func(e);
    }
  }
}

function toggle_expand(id) {
    $('div.'+id).toggle();
}

function submit_form(name) {
    $('#'+name+'message').removeClass('fehler').html('').hide();
    jQuery.ajax({
        type:       'POST',
        url:        '/cgi/'+name,
        data:       $('#'+name+'form').serialize(),
        success:    function (response) {
            $('#'+name+'message').html(response).show();
            $('#'+name+'form')[0].reset();
            window.scrollTo(0,300);
        },
        error:      function (request, status, error) {
            var msg = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie es sp&auml;ter erneut.'; 
            $('#'+name+'message').addClass('fehler').html(msg).show();
            window.scrollTo(0,300);
        }
    });
}

function getScrollerWidth() {
	var scr = null;
	var inn = null;
	var wNoScroll = 0;
	var wScroll = 0;

	// Outer scrolling div
	scr = document.createElement('div');
	scr.style.position = 'absolute';
	scr.style.top = '-1000px';
	scr.style.left = '-1000px';
	scr.style.width = '100px';
	scr.style.height = '50px';
	// Start with no scrollbar
	scr.style.overflow = 'hidden';

	// Inner content div
	inn = document.createElement('div');
	inn.style.width = '100%';
	inn.style.height = '200px';

	// Put the inner div in the scrolling div
	scr.appendChild(inn);
	// Append the scrolling div to the doc
	document.body.appendChild(scr);

	// Width of the inner div without scrollbar
	wNoScroll = inn.offsetWidth;
	// Add the scrollbar
	scr.style.overflow = 'auto';
	// Width of the inner div with scrollbar
	wScroll = inn.offsetWidth;

	// Remove the scrolling div from the doc
	document.body.removeChild(document.body.lastChild);

	// Pixel width of the scroller
	return (wNoScroll - wScroll);
}

// Get the height/width of the entire document
function getDocumentHeight() {
	var a=0,b=0;
	if (!isNaN(document.body.parentNode.scrollHeight)) a=document.body.parentNode.scrollHeight;
	if (!isNaN(window.innerHeight)) b=window.innerHeight;
	return Math.max(a,b);
}
function getDocumentWidth() {
	var a=0,b=0;
	if (!isNaN(document.body.parentNode.scrollWidth)) a=document.body.parentNode.scrollWidth;
	if (!isNaN(window.innerWidth)) b=window.innerWidth;
	var w = Math.max(a,b);
	// keine horizontalen Scrollbalken erzeugen, nur weil schon ein vertikaler da ist
	if (window.innerHeight < document.body.parentNode.scrollHeight) {
		w -= getScrollerWidth();
	}
	return w;
}

function do_onload_stuff() {
	//preload();
	if ($('div#shadowlayer')) {
		var hgt = getDocumentHeight();
		var wdt = getDocumentWidth();
		$('div#shadowlayer').css({ 'height': hgt+'px', 'width': wdt+'px' });
	}
	var url = parent.location.href;
	var ergebnis = url.search(/\/admin\/$/);
	if (ergebnis != -1) {
		url = parent.frames[3].location.href;
	}
	
	deleteCookie("akt_url","/");
	var cookie = getCookie("akt_url");
	if (cookie) {
		cookie = url + ";path=/";
	} else {
		document.cookie = "akt_url=" + url + ";path=/";
	}
}

function deleteCookie(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" + ((path) ? ";path=" + path : "") + ((domain) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function zoom_image(id,type,w,h,alt) {
	var img='<img src="/images/'+id+'/source.'+type+'" alt="'+alt+'" width="'+w+'" height="'+h+'" />';
	document.getElementById('the_zoomimage').innerHTML=img;
	$('div#shadowlayer').show().fadeTo('slow',.5);
	if (navigator.userAgent.match(/MSIE/)) {
		window.setTimeout("document.getElementById('zoomimage').style.display='block';",500);
	} else {
		var div=$('div#zoomimage');
		var dw=(getDocumentWidth() - w) / 2;
		if (dw<10) dw=10;
		var scroll = window.scrollY;
		if (document.body.scrollTop) scroll = document.body.scrollTop;
		if (document.compatMode == 'CSS1Compat') scroll = document.body.parentNode.scrollTop;
		var dh=(window.innerHeight - h) / 2 + scroll;
		if (dh<10) dh=10;
		div.css({ 'top':dh+'px', 'left':dw+'px' }).show('slow');
	}
}
function hide_image() {
	$('div#shadowlayer').fadeTo('slow',0.01,hideShadow);
	if (navigator.userAgent.match(/MSIE/)) {
		document.getElementById('zoomimage').style.display='none';
	} else {
		$('div#zoomimage').hide('slow');
	}
}
function hideShadow() {
	$('div#shadowlayer').hide();
}

function show_einfuehrungsaktion(home) {
	var cookie = getCookie("homelayer");
	if (home && !cookie) {
		$('div#shadowlayer').show().fadeTo('slow',.5);
		$('div#uropol_einfuehrungsaktion').show('slow');
		document.cookie = "homelayer=1";
	} else if (!home) {
		$('div#shadowlayer').show().fadeTo('slow',.5);
		$('div#uropol_einfuehrungsaktion').show('slow');
	}
}

function hide_einfuehrungsaktion() {
	$('div#shadowlayer').fadeTo('slow',0.01,hideShadow);
	$('div#uropol_einfuehrungsaktion').hide('slow');
}

function toggle_einfuehrungsaktion() {
	if ($('div#shadowlayer').css('display') == 'none') {
		show_einfuehrungsaktion();
	} else {
		hide_einfuehrungsaktion();
	}
}

var akt_frage = 1;
var anzahl_fragen = 5;
var frage = new Array();
var ja = 0;
frage[2] = 'Versp&uuml;ren Sie den Drang Wasser zu lassen sehr pl&ouml;tzlich?';
frage[3] = 'Wachen Sie nachts h&auml;ufiger als 2 mal auf um auf die Toilette zu gehen?';
frage[4] = 'Haben Sie Schmerzen oder empfinden Sie ein Brennen beim Wasserlassen?';
frage[5] = 'Belastet Sie einer der oben gefragten Punkte?';
var auswertung_alles_nein = 'Sie haben keine Blasenprobleme!';
var auswertung_einmal_ja = 'Sprechen Sie mit einem Arzt &ndash; vielleicht ist UROPOL<sup>&reg;</sup> ein Produkt, dass Ihnen helfen kann.';

function next_question() {
	var antwort1 = document.getElementsByName('antwort')[0];
	var antwort2 = document.getElementsByName('antwort')[1];
	if (!antwort1.checked && !antwort2.checked) {
		alert(unescape('Bitte w%E4hlen Sie eine Antwort aus.'));
	} else {
		if (antwort1.checked) {
			ja = ja + 1;
		}
		if (akt_frage < anzahl_fragen) {
			akt_frage = akt_frage + 1;
			$('#headline').html('Frage ' + akt_frage + ' von ' + anzahl_fragen);
			$('#pink_headline').html(frage[akt_frage]);
			antwort1.checked = false;
			antwort2.checked = false;
			if (akt_frage == 5) {
				$('#next_button').html('Zur Auswertung &gt;');
			}
		} else {
			$('#headline').html('Auswertung');
			$('#pink_headline').hide();
			$('#frage').hide();
			$('#auswertung_container').show();
			if (ja) {
				$('#auswertung').html(auswertung_einmal_ja);
			} else {
				$('#auswertung').html(auswertung_alles_nein);
			}
		}
	}
}

function show_auswertung() {
	//alert('auswertung');
}

function showPic(src, breite, hoehe, alt) {
	var img = "<img src=\"" + src + "\" width=\"" + breite + "\" height=\"" + hoehe + "\" alt=\"" + alt + "\">";
	$('#bild_vergroessert').html(img);
	$('#bild_gross').css({ 'width': breite+'px' });
	$('#bild_gross_container').show();
	//setTimeout("shadow(1)", 10);
	$('div#shadowlayer').show().fadeTo('slow',.5);
}

function hidePic() {
	$('#bild_gross_container').hide();
	$('div#shadowlayer').fadeTo('slow',0.01,hideShadow);
}

function shadow(mode) {
	var shadow=$('#shadowlayer');
	var h = parseInt($(document).height());
	if (mode) shadow.css({ 'height':h+'px' }).show();
	else shadow.hide();
}

var akt_seite = 1;
function show_seite(seite, seiten_gesamt) {
	if (seite == 'naechste') {
		seite = akt_seite + 1;
	}
	if (seite == 'vorherige') {
		seite = akt_seite - 1;
	}
	if (seite != akt_seite) {
		if (seite > 1) {
			$('.vorherige').show();
		} else {
			$('.vorherige').hide();
		}
		if (seite < seiten_gesamt) {
			$('.naechste').show();
		} else {
			$('.naechste').hide();
		}
		$('.tr_' + akt_seite).hide();
		$('.seite_' + akt_seite).css('color', '#525d64');
		$('.tr_' + seite).show();
		$('.seite_' + seite).css('color', '#d40059');
		akt_seite = seite;
	}
}

function show_doc_check() {
	var doc = $(document);
	var win = $(window);
	var code = getCookie("sec");
	if (code && code != "") {
		/* eingeloggt */
		$('#inhalt').css('display', '');
	} else {
		/* nicht eingeloggt */
		$('#inhalt').html('');
		$('#doc_check').show();
	}
}

function logged_in() {
	var doc = $(document);
	var win = $(window);
	var code = getCookie("sec");
	if (code && code != "") {
		return 1;
	} else {
		return 0;
	}
}

function goToDocCheckURL() {
	var cookie = getCookie("akt_url");
	if (cookie) {
		window.location.href = cookie;
	} else {
		window.location.href = "/doccheck_landingpage.html";
	}
}

function getCookie(name) {
	a = document.cookie;
	res = '';
	while(a != '' && res == '') {
		cookiename = a.substring(0,a.search('='));
		if (a.search(';') >= 0) {
			cookiewert = a.substring(a.search('=')+1,a.search(';'));
		} else {
			cookiewert = a.substring(a.search('=')+1,a.length);
		}
		
		while(cookiename.substring(0, 1) == ' ') {
			cookiename = cookiename.substring(1, cookiename.length);
		}
		
		if(name == cookiename) {res = unescape(cookiewert);}
		
		i = a.search(';')+1;
		if(i == 0) {i = a.length;}
		a = a.substring(i,a.length);
	}
	return res;
}

var player;
function playerReady(obj) {
	player = document.getElementById('movie');
	player.addModelListener("STATE","stateHandler");
	player.addViewListener("STOP","stopHandler");
};

function show_vorschau(src, width, height, url) {
	$('#movie_container').hide();
	$('#movie_container').html("<div id=\"movie\"></div>");
	var img = "<img src=\"" + src + "\" width=\"" + width + "\" height=\"" + height + "\">";
	var html = img + "<div style=\"position:absolute;top:83px;left:278px;\"><img src=\"/shared/pics/videos/play.png\" width=\"134\" height=\"134\" alt=\"Play\"></div>";
	html = "<div style=\"cursor:pointer;\" onclick=\"play_video('" + url + "')\">" + html + "</div>";
	$('#top-theming').html(html).show();
}

function stateHandler(obj) {
    if (obj.newstate == 'COMPLETED') {
    	stop_video();
    }
}

function stopHandler() {
    stop_video();
}

function stop_video() {
	$('#top-theming').show();
	$('#movie_container').hide();
	$('#movie_container').html("<div id=\"movie\"></div>");
}

function play_video(url) {
	$('#top-theming').hide();
	$('#movie_container').show();
	if (swfobject.hasFlashPlayerVersion("9")) {

//		Geht im IE7 nicht:
//		var flashvars = {
//			width: "690",
//			height: "300",
//			controlbar: "over",
//			file: url,
//			autostart: "true",
//			backcolor: "0x000000",
//			frontcolor: "0xFFFFFF",
//		};
		
		var flashvars = {};
		flashvars.width = "690";
		flashvars.height = "300";
		flashvars.controlbar = "over";
		flashvars.autostart = "true";
		flashvars.backcolor = "0x000000";
		flashvars.frontcolor = "0xFFFFFF";
		flashvars.file = url;
		
		var params = {
			allowfullscreen: "true"
		};
		var attributes = {
			id: "movie"
		};
		swfobject.embedSWF("/shared/flash/player.swf", "movie", "690", "300", "9.0.0","/shared/flash/expressInstall.swf", flashvars, params, attributes);
	} else {
		$('#movie').html('<div style="height:300px;" align="center"><div style="padding-top:100px;padding-bottom:10px;">Um dieses Video sehen zu k&ouml;nnen, ben&ouml;tigen Sie den Adobe Flash Player 9. Sie k&ouml;nnen diesen hier downloaden:</div><a href="http://www.adobe.com/go/getflashplayer" target="_blank"><img src="/shared/pics/videos/get_flash_player.png" alt="Get Adobe Flash player" border="0" /></a></div>');
	}
}

function show_subsubnavi(cat) {
	$('.subsubnavi').hide();
	$('#subsubnavi_'+cat).show();
}

function hide_subsubnavi(cat) {
	$('#subsubnavi_'+cat).hide();
}
