
function openWebsiteLink(url){
	if(window.opener){
		window.opener.document.location.href = url;
	}else{
		var newWin = window.open(url);
	}
}



function dateValid(strDate){
			//can be empty
		if(strDate == ''){
			return true;
		}

		var dtArray = strDate.split('.');

		var day = dtArray[0];
		var month = dtArray[1];
		var year = dtArray[2];

		var date = new Date(year, month-1, day);

			//Microsoft 98,99,2000,2001 - Firfox 98,99,100,101
		if(navigator.appName.indexOf('Microsoft') != -1){
			if(eval(year) > 1999){
				var yearsEquals = (date.getYear() == year);
			} else {
				var yearsEquals = (date.getYear() == eval(year-1900));
			}
		} else {
			var yearsEquals = (date.getYear() == eval(year - 1900));
		}

		if(yearsEquals && date.getMonth() == eval(month-1) && date.getDate() == day ){
			return true;
		}else{
			return false;
		}
}

function clearText(lObj){
	if (lObj.defaultValue==lObj.value) {
		lObj.value = "";
	}
}

function restoreText(lObj){
	if (lObj.value == "") {
		lObj.value = lObj.defaultValue;
	}
}

function textLimiter(lObj, maxlimit) {
	if (lObj.value.length > maxlimit) {
		lObj.value = lObj.value.substring(0, maxlimit);
	}
}

//same function in ZDFde_function and functions!!!
function openMedia(strSource) {
	var topPix = (screen.availHeight - 524)/2;
	var leftPix = (screen.availWidth - 780)/2;
	mediathekwin = window.open(strSource,"mediathek","top=" + topPix + ",left=" + leftPix + ",width=780,height=524,location=0,menubar=0,status=1,toolbar=0,scrollbars=0,resizable=1");
	mediathekwin.focus();
}


function openPopup(url, width, height){
	var ow = window.open(url, "d", "width="+width+",height="+height+",location=no,menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
	return false;
}

//-*-O-*-----------------------------------------------------------------------------------
//-*-O-*- at the videolive page shows and hides the blocks, and also deals with the markers
//-*-O-*-----------------------------------------------------------------------------------
function showHide(showThisDay) {
	var days = new Array("montag", "dienstag", "mittwoch", "donnerstag", "freitag", "samstag", "sonntag");
	for (var i = 0; i < days.length; i++) {
		var blockElement = document.getElementById(days[i] + '-block');
		if (days[i] == showThisDay) {
			if (blockElement) blockElement.style.display = 'block';
		} else {
			if (blockElement) blockElement.style.display = 'none';
		}

		var markerElement = document.getElementById(days[i] + '-marker');
		if (days[i] == showThisDay) {
			if (markerElement) markerElement.className = 'livestream-karteireiter-' + days[i] + '-aktiv';
		} else {
			if (markerElement) markerElement.className = 'livestream-karteireiter-' + days[i] + '-inaktiv';
		}
	}
	return false;
}


//------------------------------------------------------------------------------------------------------------------
//---- checks whether the required version is avaialble on the browser
//------------------------------------------------------------------------------------------------------------------
function isFlashVersionAvailable(version){
	var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
	var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

	flashVersionInstalled = false;
	if(version != ''){
		if(isIE && isWin){
			document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
			document.write('on error resume next \n');
			document.write('flashVersionInstalled = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.'+version+'"))) \n');
			document.write('</SCR' + 'IPT\> \n');
		}

		if (navigator.plugins){
			if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){
				var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
				var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
				flashVersionInstalled = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));

				if(version == 2) {
					flashVersionInstalled = (isVersion2 != '');
				}else{
					flashVersionInstalled = (flashVersionInstalled >= version);
				}
			}
		}
	}else{
		flashVersionInstalled = false;
	}
	return flashVersionInstalled;

}


//----------------------------------------------------------------------------------------------------------
//---- the flash html creator..pass parameters, checks the availability of the requred version,
//---- show replacement img. if needed
//----------------------------------------------------------------------------------------------------------
function callFlash(flashUrl, replImageUrl, width, height, version, paramsXML) {

	if(typeof(version) == 'undefined') {
		version = 6;
	}else{
			//to accept '6.x' format too
		var version = version.split('.')[0];
	}

	var paramsObjectFormat = '';
	var paramsEmbedFormat = '';
	var params = xList(paramsXML, 'parameter');
	for(var i=0;i<params.length;i++){
		var key = xGet(params[i], 'key');
		var value = xGet(params[i], 'value');
		paramsObjectFormat += ' <PARAM NAME="'+key+'" VALUE="'+value+'"> ';
		paramsEmbedFormat += ' '+key+'="'+value+'" ';
	}
//alert(paramsEmbedFormat);

	if(isFlashVersionAvailable(version)){
		var flashHtml = ''+
			'<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
			'	WIDTH="'+width+'" HEIGHT="'+height+'" '+
			'	CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'+
			'		<PARAM NAME="MOVIE" VALUE="' + flashUrl + '">'+
			'		<PARAM NAME="PLAY" VALUE="true">'+
			'		<PARAM NAME="LOOP" VALUE="false">'+
			'		<PARAM NAME="QUALITY" VALUE="high">'+
			'		<PARAM NAME="MENU" VALUE="false">'+paramsObjectFormat+
			'		<EMBED SRC="' + flashUrl + '"'+
			'			WIDTH="'+width+'" HEIGHT="'+height+'"'+
			'			PLAY="true"'+
			'			LOOP="false"'+
			'			QUALITY="high"'+
			'			MENU="false"'+
			'			TYPE="application/x-shockwave-flash"'+paramsEmbedFormat+
			'			PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'+
			'		</EMBED>'+
			'</OBJECT>';
	}else{
		//if the version is too old, we show the replacement image
		var flashHtml = '<img src="' + replImageUrl + '" width="'+width+'" height="'+height+'" border="0" />';
	}

	document.write(flashHtml);
	return;
}


function getExpiryDate (nDays) {
	var today = new Date();
	var expire = new Date();
	expire.setTime(today.getTime() + 3600000*24*nDays);
	return expire.toGMTString();
}


function setCookie(name, value, expiresInDays, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expiresInDays) ? "; expires=" + getExpiryDate(expiresInDays) : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

function getCookie(name) {
	var dc = document.cookie;
	var prefix = name + "=";
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) {
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} else {
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1) end = dc.length;
	return unescape(dc.substring(begin + prefix.length, end));
}

function testIsValidObject(objToTest) {
	if (null == objToTest) {
		return false;
	}
	if ("undefined" == typeof(objToTest) ) {
		return false;
	}
	return true;
}


function backButtonDisplayer_orig(){
	var refUrl = '';
	if(document.referrer != ""){
		refUrl = document.referrer;
		setCookie('refUrl', refUrl, null, '/ZDFmediathek/inhalt');
	}else{
		refUrl = getCookie('refUrl');
		if (refUrl == null) refUrl = "";
	}

	var histB = document.getElementById('histback');

	if (testIsValidObject(histB) && history.length != 0 && refUrl.indexOf('ZDFmediathek/inhalt') > 0){
		histB.style.display = 'block';
	}
}


function backButtonDisplayer(){

	loadHist();

	var histB = document.getElementById('histback');
	var histPos = getCookie('histPos');
	if (testIsValidObject(histB) && histPos > 0){
		histB.style.display = 'block';
	}

}


function loadHist(){
			//on normal SS loc.replace, we dont have to do anything..only updating the current cookie
		if(getCookie('wasLocReplace') == '1'){
			setCookie('wasLocReplace', 0, null, '/ZDFmediathek/inhalt');

			var histPos = getCookie('histPos');
			setCookie('hist_'+histPos, getId(top.document.location.href), null, '/ZDFmediathek/inhalt');

			return;
		}

		if( getCookie('histPos') == null ||
		  (navigator.appName.indexOf('Microsoft') != -1 && history.length == 0) ||
		  (navigator.appName.indexOf('Microsoft') == -1 && top.document.referrer.indexOf('ZDFmediathek') == -1) ){
				//reinitiate the cookies on window opening
			setCookie('histPos', 0, null, '/ZDFmediathek/inhalt');
			setCookie('hist_0', getId(top.document.location.href), null, '/ZDFmediathek/inhalt');
		} else {

			var histPos = getCookie('histPos');
			var actItem = getCookie('hist_'+histPos);

			if(actItem != getId(top.document.location.href)){
				if(histPos*1 >= 0){
					var lastIndex = histPos*1-1;
					var lastItem = getCookie('hist_'+lastIndex);

					if(getId(top.document.location.href) == lastItem){
						histPos = histPos*1 - 1;
					}else{
						histPos = histPos*1 + 1;
						setCookie('hist_'+histPos, getId(top.document.location.href), null, '/ZDFmediathek/inhalt');
					}
					setCookie('histPos', histPos, null, '/ZDFmediathek/inhalt');
				}
			}

		}

}


function getId(url){
	return url.split(',')[2];
}



function medLocReplace(href){
	setCookie('wasLocReplace', 1, null, '/ZDFmediathek/inhalt');
	location.replace(href);
}

//Medienforschung -Anfang--------------------------------------------

   var MFprozent_aufrufe = 5;
   var MFcookiename      = "ZDF_Medienforschung";
   var MFcookieexpire    = "Sun,1 Apr 2007 10:00:00 UTC";
   var MFumfrage_url     = "http://mfopst.zdf.de/uc/mediathek";

   
    var MFpopup_height		= "600";
    var MFpopup_width		= "638";
    var MFpopup_toolbar		= "no";
    var MFpopup_scrollbar		= "yes";
    var MFpopup_location  	= "no";
    var MFpopup_directories	= "no";


function checkMFpopup()
 {
  //Zufallszahl würfeln, hier wird jeder 2te zur Umfrage eingeladen
  if (Math.random() <= (MFprozent_aufrufe / 100))
  {
    if (document.cookie.indexOf(MFcookiename+"=true") == -1)
    {
       document.cookie=MFcookiename+"=true;path=/;Expires="+MFcookieexpire;
       MFpopup();
     }
  }
 }

function MFpopup()
 {
 if(document.cookie.indexOf(MFcookiename+"=true") > -1)
  {
	window.open(MFumfrage_url,"Mediathek_Umfrage","height="+MFpopup_height+",width="+MFpopup_width+",toolbar="+MFpopup_toolbar+",scrollbars="+MFpopup_scrollbar+",location="+MFpopup_location+",directories="+MFpopup_directories+"")
  }
 }
 
function getMFCookie(name) {
	var MFdc = document.cookie;
	var MFprefix = name + "=";
	var MFbegin = MFdc.indexOf("; " + MFprefix);
	if (MFbegin == -1) {
		MFbegin = MFdc.indexOf(MFprefix);
		if (MFbegin != 0) return null;
	} else {
		MFbegin += 2;
	}
	var MFend = document.cookie.indexOf(";", MFbegin);
	if (MFend == -1) MFend = MFdc.length;
	return unescape(MFdc.substring(MFbegin + MFprefix.length, MFend));
}

function loadUserSettingsFromMFCookie() {
	var MFuserSettings = getMFCookie("userSettings");
	if (MFuserSettings == null) MFuserSettings = "";
	return MFuserSettings;
}

//Medienforschung -Ende--------------------------------------------








