

var requiredVersion = 5;
var useRedirect = false;
var flash2Installed = false;
var flash3Installed = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var maxVersion = 7;
var actualVersion = 0;
var hasRightVersion = false;
var jsVersion = 1.0;


var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

jsVersion = 1.1;

if(isIE && isWin){
	document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
	document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
	document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
	document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
	document.write('</SCR' + 'IPT\> \n');
}


function detectFlash(){

	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;
			var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
			flash2Installed = flashVersion == 2;
			flash3Installed = flashVersion == 3;
			flash4Installed = flashVersion == 4;
			flash5Installed = flashVersion == 5;
			flash6Installed = flashVersion == 6;
			flash7Installed = flashVersion == 7;
		}
	}

	for (var i = 2; i <= maxVersion; i++) {
		if (eval("flash" + i + "Installed") == true) {
			actualVersion = i;
		}
	}

	if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 2;

	if (actualVersion >= requiredVersion) {
		hasRightVersion = true;
		if (useRedirect) {
			if(jsVersion > 1.0) {
				window.location.replace(flashPage);
			} else {
				window.location = flashPage;
			}
		}
	} else {

		if (useRedirect) {
			if(jsVersion > 1.0) {
				window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
			} else {
				window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
			}
		}
	}
}


detectFlash();
function func_fpi_swap() {
	if (!useRedirect) {
		if(hasRightVersion) {
			var oeTags = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
			+ 'WIDTH="140" HEIGHT="82"'
			+ 'CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
			+ '<PARAM NAME="MOVIE" VALUE="http://www.heute.de/ZDFheute/img/topnav/zdf_clock.swf">'
			+ '<PARAM NAME="PLAY" VALUE="true">'
			+ '<PARAM NAME="LOOP" VALUE="false">'
			+ '<PARAM NAME="QUALITY" VALUE="high">'
			+ '<PARAM NAME="MENU" VALUE="false">'
			+ '<EMBED SRC="http://www.heute.de/ZDFheute/img/topnav/zdf_clock.swf"'
			+ 'WIDTH="140" HEIGHT="82"'
			+ 'PLAY="true"'
			+ 'LOOP="false"'
			+ 'QUALITY="high"'
			+ 'MENU="false"'
			+ 'TYPE="application/x-shockwave-flash"'
			+ 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
			+ '</EMBED>'
			+ '</OBJECT>';

			document.write(oeTags);
		} else {
			var alternateContent = '<IMG SRC="http://www.heute.de/ZDFheute/img/topnav/uhr_ersatz.gif" WIDTH="140" HEIGHT="82">';
			document.write(alternateContent);
		}
	}
}

// function for inserting flash to article text
// placement: 	used to determine the size of the flash
//				(main (476 x 236), flash-applikation (476 x 635), default (298 x 235), mediathek-popup (780 x 410)
// version: 	the ch_version field from table animation - used for checking the correct version
function func_call_animation_body(URL1, URL2, placement, version) {
	if (!useRedirect) {

		//checking which version is needed - default to the requiredVersion var
		if ( typeof(version) == 'undefined' ) {
			version = '';
		}

		switch (version) {
			case ('5.x'):
				neededVersion = 5;
				break;
			case ('6.x'):
				neededVersion = 6;
				break;
			case ('7.x'):
				neededVersion = 7;
				break;
			default:
				neededVersion = requiredVersion;
				break;
		}


		if ( actualVersion >= neededVersion ) {
			var oeTags = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
			if (placement=="main") {
				var oeTags = oeTags + 'WIDTH="476" HEIGHT="236" ';
			} else if (placement=="flash-applikation") {
				var oeTags = oeTags + 'WIDTH="476" HEIGHT="635" ';
			} else if (placement=="mediathek-popup") {
				var oeTags = oeTags + 'WIDTH="780" HEIGHT="410" ';
			} else {
				var oeTags = oeTags + 'WIDTH="298" HEIGHT="235" ';
			}
			var oeTags = oeTags
			+ 'CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
			+ '<PARAM NAME="MOVIE" VALUE="' + URL1 + '">'
			+ '<PARAM NAME="PLAY" VALUE="true">'
			+ '<PARAM NAME="LOOP" VALUE="false">'
			+ '<PARAM NAME="QUALITY" VALUE="high">'
			+ '<PARAM NAME="MENU" VALUE="false">'
			+ '<EMBED SRC="' + URL1 + '"';
			if (placement=="main") {
				var oeTags = oeTags + 'WIDTH="476" HEIGHT="236"';
			} else if (placement=="flash-applikation") {
				var oeTags = oeTags + 'WIDTH="476" HEIGHT="635" ';
			} else if (placement=="mediathek-popup") {
				var oeTags = oeTags + 'WIDTH="780" HEIGHT="410" ';
			} else {
				var oeTags = oeTags + 'WIDTH="298" HEIGHT="235"';
			}
			var oeTags = oeTags + 'PLAY="true"'
			+ 'LOOP="false"'
			+ 'QUALITY="high"'
			+ 'MENU="false"'
			+ 'TYPE="application/x-shockwave-flash"'
			+ 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">'
			+ '</EMBED>'
			+ '</OBJECT>';

			document.write(oeTags);
		} else {
			if (placement=="main") {
				var alternateContent = '<IMG SRC="' + URL2 + '" WIDTH="476" HEIGHT="236" BORDER="0">';
			} else if (placement=="flash-applikation") {
				var alternateContent = '<IMG SRC="' + URL2 + '" WIDTH="476" HEIGHT="635" BORDER="0">';
			} else if (placement=="mediathek-popup") {
				var alternateContent = '<IMG SRC="' + URL2 + '" WIDTH="780" HEIGHT="410" BORDER="0">';
			} else {
				var alternateContent = '<IMG SRC="' + URL2 + '" WIDTH="298" HEIGHT="235" BORDER="0">';
			}
			document.write(alternateContent);
		}
	}
}


	// Browser-Detection
	function getBrowser()
	{
		if(document.layers)
		{
			strBrowserName = "ns";
		}

		if(document.all)
		{
			strBrowserName = "ie";
		}

		if(navigator.platform.indexOf('Win') >= 0)
		{
			strPlatform = "win";
		}
		else
		{
			strPlatform = "mac";
		}

		strBrowserVersion = navigator.appVersion.substr(0,1);
	}
	getBrowser();

	function openPortrait(strSource)
	{
		portraitWin = window.open(strSource,"portrait","width=460,height=500,scrollbars=0,menubar=0,toolbar=0,location=0,status=0,resizable=0");
	}

	function openHelp(strSource)
	{
		helpWin = window.open(strSource,"hilfe","width=628,height=500,scrollbars=0,menubar=0,toolbar=0,location=0,status=0,resizable=0");
	}

	function openSendArticle(strSource)
	{
		artikelSendWin = window.open(strSource,"wetter","width=460,height=500,scrollbars=0,menubar=0,toolbar=0,location=0,status=0,resizable=0");
	}

	function openWeatherBig(strSource)
	{
		wetterWin = window.open(strSource,"wetter","width=585,height=583,scrollbars=0,menubar=0,toolbar=0,location=0,status=0,resizable=0");
	}

	function openWeather(strSource)
	{
		wetterWin = window.open(strSource,"wetter","width=499,height=583,scrollbars=0,menubar=0,toolbar=0,location=0,status=0,resizable=0");
	}

	function openBoerse(strSource)
	{
		boerseWin = window.open(strSource,"boerse","width=590,height=507,scrollbars=0,menubar=0,toolbar=0,location=0,status=1,resizable=1");
	}

	function openArtikelPrint(strSource)
	{
		artikelPrintWin = window.open(strSource,"artikel","width=780,height=600,scrollbars=1,status=0,menubar=1,resizable=1");
	}

	//same function in ZDFde_function and m_common_js!!!
	function openMedia(strSource) {
		//bug 6322 - resizable=0 changed
		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 openMediaSized(strSource) {

		if(zappelTeaserPopupHeight != ''){
			var height = zappelTeaserPopupHeight;
		}else{
			var height = 524;
		}

		if(zappelTeaserPopupWidth != ''){
			var width = zappelTeaserPopupWidth;
		}else{
			var width = 780;
		}
		
		if (mediaAssetDoType == "VI") {
			var userSettings = loadUserSettingsFromCookie();
			if (userSettings != "") {
				var pos = alternativURL.indexOf('wm_modem');
				strSource = alternativURL.substring(0,pos) + userSettings + alternativURL.substring(pos+8,alternativURL.length);
			}		
		}
		mediathekwin = window.open(strSource,"mediathek","width="+width+",height="+height+",location=0,menubar=0,status=1,toolbar=0,scrollbars=0,resizable=1");
		mediathekwin.focus();
	}


	function openLinkInOpener(strSource)
	{
		//if the opener is available it opens the strSource link in this window
		if (top.opener) {
			top.opener.location.href = strSource;
			//return false --> so the normal href should not be followed
			return false;
		} else {
			//return true --> so the normal href should be followed
			return true;
		}
	}

	function openElection(strSource)
	{
		electionwin = window.open(strSource,"Wahlen","width=608,height=493,location=0,menubar=0,status=0,toolbar=0,scrollbars=0,resizable=0");
		electionwin.focus();
	}

	function openVoteResult(strSource, width, height)
	{
		voteResultWin = window.open(strSource,"voteresult","width="+width+",height="+height+",location=0,menubar=0,status=0,toolbar=0,scrollbars=0,resizable=0");
	}

	function openVoting(strSource)
	{
		/*votingWin = window.open(strSource,"voting","width=469,height=530,location=0,menubar=0,statusbar=0,scrollbars=0,resizable=0");*/
		votingWin = window.open(strSource,"voting","width=598,height=534,location=0,menubar=0,statusbar=0,scrollbars=0,resizable=0");
	}

	function openTablePopup(strSource, width, height)
	{
		tablepopup = window.open(strSource,"tabelle","width=" + width + ",height=" + height + ",location=0,menubar=0,status=0,toolbar=0,scrollbars=1,resizable=0");
		tablepopup.focus();
	}

	function openHtmlPopup(strSource, width, height)
	{
		htmlpopup = window.open(strSource,"tabelle","width=" + width + ",height=" + height + ",location=0,menubar=0,status=0,toolbar=0,scrollbars=1,resizable=0");
		htmlpopup.focus();
	}

	function openHtmlPopupNamed(strSource, width, height, name)
	{
		htmlpopup = window.open(strSource,name,"width=" + width + ",height=" + height + ",location=0,menubar=0,status=0,toolbar=0,scrollbars=1,resizable=0");
		htmlpopup.focus();
	}

	var actImg = "";
	function setStatus(imgName)
	{
		if(actImg != "")
		{
			srcName = document.images[actImg].src;
			srcType = srcName.substr(srcName.length - 3, 3);

			newSrcName = srcName.substr(0,srcName.length - 5);
			newSrcName += "l." + srcType;
			document.images[actImg].src = newSrcName;
		}

		srcName = document.images[imgName].src;
		srcType = srcName.substr(srcName.length - 3, 3);

		newSrcName = srcName.substr(0,srcName.length - 5);
		newSrcName += "a." + srcType;
		document.images[imgName].src = newSrcName;
		actImg = imgName;
	}

	function swapImg(imgName, status)
	{
		if(document.images && actImg != imgName)
		{
			srcName = document.images[imgName].src;
			srcType = srcName.substr(srcName.length - 3, 3);

			newSrcName = srcName.substr(0,srcName.length - 5);
			newSrcName += status + "." + srcType;
			document.images[imgName].src = newSrcName;

		}
	}

	//Preload of left navigation images
	var leftNav = new Array("titelseite","politik","wirtschaft","sport","magazin","computer","infoservices","mediathek","wetter","boerse","archiv");
	var leftNavImg = new Array();
	for(i=0;i<leftNav.length;i++)
	{
		leftNavImg[i] = new Image();
		leftNavImg[i].src = "/ZDFheute/img/leftnav/main_" + leftNav[i] + "_h.gif";
		if(leftNav[i]!="mediathek"&&leftNav[i]!="wetter"&&leftNav[i]!="boerse")
		{
			leftNavImg[i].src = "/ZDFheute/img/leftnav/main_" + leftNav[i] + "_b.gif";
		}
	}


	function getSelectedRadioValue(buttonArray) {
		//gives the value of the currently selected radio button in an button array back
		aktValue = '';
		for (i=0; i<buttonArray.length; i++) {
			if (buttonArray[i].checked == true)
				aktValue = buttonArray[i].value;
		}
		return aktValue;
	}

	function checkMediaWindowSize() {
		//checks the size of the mediathek window and resizes if needed
		if ( isIE ) {
			if ( typeof(window.opener) == 'undefined' ) {
				window.resizeTo(638,695);
			}
		} else if ( window.opener == null ) {
			window.resizeTo(638,630);
			window.innerHeight = 520;
		}
	}


	function getWeather(wSelect){
		var currentValue = wSelect.options[wSelect.selectedIndex].value;
		var currentCity = wSelect.options[wSelect.selectedIndex].text;

		var notRealParams = currentValue.split('notRealParams')[1];

		if(notRealParams == "=dataNotFound"){
			var weatherNoDataMessageDiv = document.getElementById('weatherNoDataMessageDiv');
			var weatherDataTable = document.getElementById('weatherDataTable');
			weatherDataTable.style.display = 'none';
			weatherNoDataMessageDiv.style.display = 'block';
			var cityName = replaceUmlauts(currentCity);
			setCookie('lastVisitedWeatherCity', cityName, 30);
		}else{

			var weatherNoDataMessageDiv = document.getElementById('weatherNoDataMessageDiv');
			var weatherDataTable = document.getElementById('weatherDataTable');
			weatherDataTable.style.display = 'inline';
			weatherNoDataMessageDiv.style.display = 'none';

			var minTemper = notRealParams.split('|')[0].split('=')[1].split('°')[0];
			var maxTemper = notRealParams.split('|')[1].split('°')[0];
			var weatherText = notRealParams.split('|')[2];
			var windStrength = notRealParams.split('|')[3];
			var pmap = notRealParams.split('|')[4];
			var plusminus = notRealParams.split('|')[5];

			var maxTD = document.getElementById('maxTemperTD');
			var minTD = document.getElementById('minTemperTD');
			var weatherTextTD = document.getElementById('weatherTextTD');
			var windStrengthTD = document.getElementById('windStrengthTD');
			var weatherSunImage = document.getElementById('weatherSunImage');
			var weatherTemperImage = document.getElementById('weatherTemperImage');


			minTD.innerHTML = '&nbsp;'+minTemper+'&deg;'
			maxTD.innerHTML = '&nbsp;'+maxTemper+'&deg;'
			weatherTextTD.innerHTML = weatherText;
			windStrengthTD.innerHTML = 'Windst.&nbsp;'+windStrength;

			var imgSun = new Image();
			imgSun.src = 'http://www.zdf.de/ZDFde/img/weather/icons/weather_'+pmap+'.gif';
			weatherSunImage.src = imgSun.src;

			var imgTemper = new Image();
			imgTemper.src = 'http://www.zdf.de/ZDFde/img/weather/icon_temperatur_'+plusminus+'.gif';
			weatherTemperImage.src = imgTemper.src;

			var cityName = replaceUmlauts(currentCity);
			setCookie('lastVisitedWeatherCity', cityName, 30);
		}

	}


	function replaceUmlauts (str){
		var re = /[öüßÖÜ]/gi;
		var outString = str.replace(re, '_');
		return outString;
	}

function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	sorryGlobalExpire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	sorryGlobalExpire.setTime(today.getTime() + 3600000*24*nDays);
	sorryGlobalCookieName = cookieName;
	sorryGlobalCookieValue = cookieValue;

		//hack to avoid IE whole page repaint on cookie set..
	window.setTimeout("innerSetKuki();", 500);
}

function setWeather(){
	var lastVisitedCity = getCookie('lastVisitedWeatherCity');
	var mySelect = document.getElementById('citySelect');
	if(lastVisitedCity != ''){
		for(var i=0;i<mySelect.options.length;i++){
			if(lastVisitedCity == replaceUmlauts(mySelect.options[i].text)){
				mySelect.options[i].selected = true;
				getWeather(mySelect);
				return;
			}
		}
	}
	getWeather(mySelect);
	return;
}


function innerSetKuki(){
	document.cookie = sorryGlobalCookieName+'='+escape(sorryGlobalCookieValue) + ';expires='+sorryGlobalExpire.toGMTString()+';path=/';
}

function getCookie(name) {
         //Without this, it will return the first value
         //in document.cookie when name is the empty string.
         if(name == '')
            return('');

         name_index = document.cookie.indexOf(name + '=');

         if(name_index == -1)
            return('');

         cookie_value =  document.cookie.substr(name_index + name.length + 1,
                                                document.cookie.length);

         //All cookie name-value pairs end with a semi-colon, except the last one.
         end_of_cookie = cookie_value.indexOf(';');
         if(end_of_cookie != -1)
            cookie_value = cookie_value.substr(0, end_of_cookie);

         //Restores all the blank spaces.
         space = cookie_value.indexOf('+');
         while(space != -1)
              {
              cookie_value = cookie_value.substr(0, space) + ' ' +
              cookie_value.substr(space + 1, cookie_value.length);

              space = cookie_value.indexOf('+');
              }

         return(cookie_value);
}

function loadUserSettingsFromCookie() {
	var userSettings = getCookie("userSettings");
	if (userSettings == null) userSettings = "";
	return userSettings;
}

function openMediathekURLReplacedForVideo(url, alternativUrl,doType) {
	if (doType == "VI") {
		var userSettings = loadUserSettingsFromCookie();
		if (userSettings != "") {
			var pos = alternativUrl.indexOf('wm_modem');
			url = alternativUrl.substring(0,pos) + userSettings + alternativUrl.substring(pos+8,alternativUrl.length);
		}		
	}
	openMedia(url);
}

//-->

