// JavaScript Document

//Allgemeine JS
var findx = 0;
var findy = 0;

function findPos(obj)
{	findx = 0;
	findy = 0;

	if (obj.offsetParent) {
		do {
			findx += obj.offsetLeft;
			findy += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

/* Passwortsicherheit */
function pwsContains(strText, strPattern)
{
	for (i = 0; i < strText.length; i++)
	{	if (strPattern.indexOf(strText.charAt(i)) > -1) return true;
	}
	return false;
}

function upCheckLen(input, output, minlen)
{	var ip = $("#"+input);
	var op = $("#"+output);

	var value = ip.val();
		value = $.trim(value);
		if (minlen < 0) {
			minlen = 6;
		}
	
	if (value.length > 0 && value.length < minlen) {
		//op.html('Bitte geben Sie mindestens ' +minlen+ ' Zeichen an.');
		//op.show();
		op.addClass("formerror_color");
	} else {
		//op.hide();					
		//ip.css("borderColor", "#999");
		op.removeClass("formerror_color");
	}
}

function unsCheckUser(uname, output)
{	/*	
		uname	= Inputfield mit Suchwort
		output	= Container für Statusausgabe
	*/
	
	var ip = $("#"+uname);
	var op = $("#"+output);

	var query = ip.val();
		query = $.trim(query);
		query = escape(query);
		
		//if (query != "") { alert(query); }

	//Suche starten
	$.post("livecheck.php", "q="+query,
			function(inhalt) {
				if (inhalt != "") {
					op.html(inhalt);
					//op.show();					
					//ip.css("borderColor", "#C65A5A");
				} else {
					op.html('&nbsp;');
					//op.hide();					
					//ip.css("borderColor", "#999");
				}
			}
	);
}

function pwsCheckPass(input, output)
{	var intScore   	= 0;	//Std.-Score
	var strVerdict 	= "schwach";	//Std. Text für Passwortstärke
	var bgImg 		= "/deu/_webLayout/images/psw_unsicher.png";	//Std. Background für Passwortstärke
	
	var charSpecial = "[!,@,#,$,%,^,&,*,?,_,~,-,+]";	//Derzeitig genutzte Sonderzeichen -> diese sind direkt in der jeweiligen Prüfung zu ändern/erweitern
	
	/* ***** ab hier nichts mehr ändern, falls keine Kenntnisse vorhanden ***** */
	
	var ip = $("#"+input);
	var op = $("#"+output);
		var passwd = ip.val();
			passwd = $.trim(passwd);
	
	//Passwortlänge berücksichtigen
	if (passwd.length >= 1 && passwd.length <= 4) {
		intScore = (intScore + 3)
	} else if (passwd.length >= 5 && passwd.length <= 7) {
		intScore = (intScore + 6)
	} else if (passwd.length >= 8 && passwd.length <= 13) {
		intScore = (intScore + 12)
	} else if (passwd.length >= 14) {
		intScore = (intScore + 18)
	}
	
	
	//Vorkommen von Buchstaben
		//mind. 1 Kleinbuchstabe
		if (passwd.match(/[a-z]/)) {
			intScore = (intScore+1)
		}
		//mind. 1 Großbuchstabe
		if (passwd.match(/[A-Z]/)) {
			intScore = (intScore+3)
		}
	//Vorkommen von Zahlen
		//mind. 1 Zahl
		if (passwd.match(/\d+/)) {
			intScore = (intScore+3)
		}
		//mind. 3 Zahlen
		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)) {
			intScore = (intScore+5)
		}		
	//Vorkommen von Sonderzeichen
		//mind. 1 Sonderzeichen vorhanden
		if (passwd.match(/[!,@,#,$,%,^,&,*,?,_,~,-,+]/)) {
			intScore = (intScore+5)
		}		
		//mind. 2 Sonderzeichen vorhanden
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~,-,+].*[!,@,#,$,%,^,&,*,?,_,~,-,+])/)) {
			intScore = (intScore+5)
		}

	
	//Kombinationstest
	//Groß und Kleinbuchstaben
	if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) {
		intScore = (intScore+2)
	}		
	//Buchstaben und Zahlen
	if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) {
		intScore = (intScore+3)
	} 
	//Buchstaben, Zahlen und Sonderzeichen
	if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~,-,+])|([!,@,#,$,%,^,&,*,?,_,~,-,+].*[a-zA-Z0-9])/)) {
		intScore = (intScore+4)
	}


	//Dopplungen abziehen
	//3 gleiche aufeinanderfolgende
	if (passwd.match(/(.)\1{2,}/g)) {
		intScore = (intScore-2);		
	}
	//5 gleiche aufeinanderfolgende
	if (passwd.match(/(.)\1{4,}/g)) {
		intScore = (intScore-5);		
	}
	

	//Stärketext setzen
	/*
	if (intScore <= 15) {
	   strVerdict = "sehr schwach";	   
	} else if (intScore >= 16 && intScore <= 24) {
	   strVerdict = "schwach";	   
	} else if (intScore >= 25 && intScore <= 34) {
	   strVerdict = "mittelmäßig";	   
	} else if (intScore >= 35 && intScore <= 44) {
	   strVerdict = "stark";	   
	} else {
	   strVerdict = "sehr stark";	   
	}
	*/
	if (intScore <= 24) {
	   strVerdict = "unsicher";
	   bgImg = "/deu/_webLayout/images/psw_unsicher.png";
	} else if (intScore >= 25 && intScore <= 40) {
	   strVerdict = "sicher";
	   bgImg = "/deu/_webLayout/images/psw_sicher.png";
	} else {
	   strVerdict = "sehr sicher";
	   bgImg = "/deu/_webLayout/images/psw_sehrsicher.png";
	}


	//Scoremeter berechnen - bezogen auf 100%
	if (intScore > 50) {
		intScore = 50;
	}
	//Schrittweite berechnen
	sClass = Math.round((intScore * 2) / (100 / 10));

	
	//Prüfung ausgeben
	d = document;
	//d.getElementById("login_name").value = intScore;	
	
	/*
	otId = d.getElementById("pwarrow1");
	otId.className = "pwmove" + "-" + sClass;
		otId = d.getElementById("pwarrow2");
		otId.className = "pwmove" + "-" + sClass;
		
	d.getElementById("pwqualitaet").title = "Qualität: " + (strVerdict);
	*/
	
	//BG setzen
	if (passwd.length > 0) {
		op.css("background-image", "url("+bgImg+")");
	} else {
		op.css("background-image", "none");
	}
		
	/*
	if (showtext == 1) {
		//d.getElementById("pwverdict").innerHTML = (strVerdict);
	}
	*/
}

function pwsGeneratePass(plength, field)
{	var keylist="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_+";
	var newpw = '';
	
		for (i=0; i<plength; i++)
		{	newpw += keylist.charAt(Math.floor(Math.random() * keylist.length));
		}
	
	document.getElementById(field).value = newpw;
}

//CMS JS
function checkSearch(){
  if (document.queryForm2.term.value != "")
  {
    document.queryForm2.submit();
  }
  else
  {
    alert("Sie müssen einen Suchbegriff eingeben!");
  }
}

/*
# Original Funktion #
//CMS JS
function checkSearch(){
  if(document.queryForm.term.value == ""){
	alert("Sie müssen einen Suchbegriff eingeben!");
  }
  else document.queryForm.submit();
}
*/

//CTH JS
function closeNotes()
{	var id = "topnotes";

		var obj = document.getElementById(id);
		var status = "hide";
			
		//Notes ausblenden
		obj.style.display = "none";

		//Cookies jetzt setzen
		setCookie(id, status);
}

function setCookie(id, status)
{	if (id != "" && (status == "show" || status == "hide")) {
		//Zeitstempel erstellen
		cookietime = new Date();
		cookietime.setTime(cookietime.getTime() + ((1000 * 60 * 60)));
		cookietime = cookietime.toGMTString();
	
		//Cookie setzen
		document.cookie = id + "_status" + "=" + escape(status) + "; expires=" + cookietime + "; path=/";
	} else {
		alert("unzureichende Parameter für Cookie-Verwendung (ID="+ id + " | status="+ status +")");
	}
}

function getCookie(id) 
{	var cookies = document.cookie;
	var mycoockie = cookies.indexOf(id);
		if (mycoockie == -1 || id == "") {
			return "";
		}

	var mycoockiestr = cookies.indexOf(';', mycoockie);
		if (mycoockiestr == -1) {
			mycoockiestr = cookies.length;
		}

	return unescape(cookies.substring(mycoockie + id.length + 1, mycoockiestr));
}

function checkLayerstatus(id)
{	if (id != "") {
		var cookieid = id + "_status";
			var mycookie = getCookie(cookieid);
			
				if (mycookie != "show" && mycookie != "hide") {
					//Cookie nicht vorhanden
					return false;
				} else {
					//Cookie vorhanden und gesetzt
					if (mycookie == "hide") {
						var obj = document.getElementById(id);
							
						//Notes ausblenden
						obj.style.display = "none";
					}
				}
	}
}

function setCheckBoxes(myBoxes, mySelector)
{	if (myBoxes && mySelector) {
		var myForm = mySelector.form.name;
		var myTmp = myBoxes;
		var mySelector = mySelector.name;
			var df = document.forms[myForm];
		
		var myBoxes = document.getElementsByName(myBoxes);
		
				for (var i=0; i<myBoxes.length; i++)
				{ 
					if (df.elements[mySelector].checked == true) {
						myBoxes[i].checked = true;
					} else {
						myBoxes[i].checked = false;
					}
				}
	}
}

function startMPlayer(videoID, videofile, status)
{	if (videoID > 0 && videofile != "") {
		d = document.getElementById("videoplayer" + videoID);
		
		if (status == 1) {
			//flash version
			d.innerHTML = '<object id="podcastmarginal" width="100%" height="100%" type="application/x-shockwave-flash" data="/_flowplayer/flowplayer.commercial-3.2.7.swf"><param name="movie" value="/_flowplayer/flowplayer.commercial-3.2.7.swf" /><param value="true" name="allowfullscreen"><param value="always" name="allowscriptaccess"><param value="high" name="quality"><param value="false" name="cachebusting"><param value="#000000" name="bgcolor"><param value=\'config={"clip":{"autoPlay":true,"autoBuffering":true,"scaling":"orig","url":"' + videofile + '"},"play":{"opacity":1,"replayLabel":"Erneut abspielen"},"screen":{"width":"100pct","height":"100pct","top":0,"left":0},"key":"#$0ca28aa289877685709","plugins":{"controls":{"url":"/_flowplayer/flowplayer.controls-3.2.5.swf","left":47,"all":false,"play":true,"tooltips":{"buttons":true,"play":"Abspielen"},"autohide":true,"backgroundColor":"transparent","buttonOffColor":"rgba(130,130,130,1)","bufferColor":"#a3a3a3","durationColor":"#b8d9ff","volumeSliderGradient":"none","sliderGradient":"none","progressGradient":"none","bufferGradient":"none","backgroundGradient":"none"}},"playerId":"podcastmarginal","playlist":[{"autoPlay":true,"autoBuffering":true,"scaling":"orig","url":"' + videofile + '"}]}\' name="flashvars"></object>';			
		} else if (status == 2) {
			//html5 version
			d.innerHTML = '<video width="143" height="81" controls="controls" autoplay="autoplay"><source src="$webflashfile" type="video/mp4" /><object id="podcastmarginal" width="100%" height="100%" type="application/x-shockwave-flash" data="/_flowplayer/flowplayer.commercial-3.2.7.swf"><param name="movie" value="/_flowplayer/flowplayer.commercial-3.2.7.swf" /><param value="true" name="allowfullscreen"><param value="always" name="allowscriptaccess"><param value="high" name="quality"><param value="false" name="cachebusting"><param value="#000000" name="bgcolor"><param value=\'config={"clip":{"autoPlay":true,"autoBuffering":true,"scaling":"orig","url":"' + videofile + '"},"play":{"opacity":1,"replayLabel":"Erneut abspielen"},"screen":{"width":"100pct","height":"100pct","top":0,"left":0},"key":"#$0ca28aa289877685709","plugins":{"controls":{"url":"/_flowplayer/flowplayer.controls-3.2.5.swf","left":47,"all":false,"play":true,"tooltips":{"buttons":true,"play":"Abspielen"},"autohide":true,"backgroundColor":"transparent","buttonOffColor":"rgba(130,130,130,1)","bufferColor":"#a3a3a3","durationColor":"#b8d9ff","volumeSliderGradient":"none","sliderGradient":"none","progressGradient":"none","bufferGradient":"none","backgroundGradient":"none"}},"playerId":"podcastmarginal","playlist":[{"autoPlay":true,"autoBuffering":true,"scaling":"orig","url":"' + videofile + '"}]}\' name="flashvars"></object></video>';			
		} else {
			//old player - discontinued
			d.innerHTML = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="143" height="114" id="podcast" align="middle"> <param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="/deu/_presse/wScripts/player/marginalplayer_lightbox.swf" /> <param name="FlashVars" value="videoID=' + videoID + '" /> <param name="menu" value="false" /> <param name="quality" value="autohigh" /> <param name="bgcolor" value="#ffffff" /> <embed src="/deu/_presse/wScripts/player/marginalplayer_lightbox.swf" FlashVars="videoID=' + videoID + '" menu="false" quality="autohigh" bgcolor="#ffffff" width="143" height="114" name="podcast" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> </object>';
		}		
	} else {
		return;
	}
}

function UhrzeitAnzeigen()
{
    if (!document.all && !document.getElementById) {
        return;
    }

    var Stunden = Serverzeit.getHours();
    var Minuten = Serverzeit.getMinutes();
    var Sekunden = Serverzeit.getSeconds();
	    Serverzeit.setSeconds(Sekunden+1);

    if (Stunden <= 9) {
        Stunden = "0" + Stunden;
    }
    if(Minuten <= 9) {
        Minuten = "0" + Minuten;
    }
    if(Sekunden <= 9) {
        Sekunden = "0" + Sekunden;
    }

    Uhrzeitanzeige = Stunden + ":" + Minuten + ":" + Sekunden + " Uhr MEZ";

    if(document.getElementById) {
        document.getElementById("Uhrzeit").innerHTML = Uhrzeitanzeige
    } else if(document.all) {
        Uhrzeit.innerHTML = Uhrzeitanzeige;
    }

    setTimeout("UhrzeitAnzeigen()", 1000);
}
